下面列出了java.lang.String#getBytes ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
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);
}
/** @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);
}
}