java.lang.String#getBytes ( )源码实例Demo

下面列出了java.lang.String#getBytes ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: rtmp-rtsp-stream-client-java   文件: AmfString.java
public static void writeStringTo(OutputStream out, String string, boolean isKey)
    throws IOException {
  // Strings are ASCII encoded
  byte[] byteValue = string.getBytes("ASCII");
  // Write the STRING data type definition (except if this String is used as a key)
  if (!isKey) {
    out.write(AmfType.STRING.getValue());
  }
  // Write 2 bytes indicating string length
  Util.writeUnsignedInt16(out, byteValue.length);
  // Write string
  out.write(byteValue);
}
 
源代码2 项目: rtmp-rtsp-stream-client-java   文件: AmfString.java
/** @return the byte size of the resulting AMF string of the specified value */
public static int sizeOf(String string, boolean isKey) {
  try {
    int size = (isKey ? 0 : 1) + 2 + string.getBytes("ASCII").length;
    return size;
  } catch (UnsupportedEncodingException ex) {
    Log.e(TAG, "AmfString.SizeOf(): caught exception", ex);
    throw new RuntimeException(ex);
  }
}