本文整理汇总了Java中java.nio.BufferOverflowException.printStackTrace方法的典型用法代码示例。如果您正苦于以下问题:Java BufferOverflowException.printStackTrace方法的具体用法?Java BufferOverflowException.printStackTrace怎么用?Java BufferOverflowException.printStackTrace使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.nio.BufferOverflowException
的用法示例。
在下文中一共展示了BufferOverflowException.printStackTrace方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: writeString
import java.nio.BufferOverflowException; //导入方法依赖的package包/类
public static void writeString( String s, ChannelBuffer buffer ) throws IOException {
if (s == null) {
// Write that it's 0.
buffer.put((byte)0);
return;
}
byte[] stringBytes = s.getBytes("UTF-8");
int bufferLength = stringBytes.length;
try {
if (bufferLength <= Byte.MAX_VALUE) {
buffer.put((byte)1);
buffer.put((byte)bufferLength);
} else if (bufferLength <= Short.MAX_VALUE) {
buffer.put((byte)2);
buffer.putShort((short)bufferLength);
} else {
buffer.put((byte)3);
buffer.putInt(bufferLength);
}
buffer.put(stringBytes);
}
catch (BufferOverflowException e) {
e.printStackTrace();
}
}
示例2: writeObject
import java.nio.BufferOverflowException; //导入方法依赖的package包/类
public void writeObject(ByteBuffer buffer, Object object) throws IOException {
String string = (String)object;
if (string == null) {
// Write that it's 0.
buffer.put((byte)0);
return;
}
byte[] stringBytes = string.getBytes("UTF-8");
int bufferLength = stringBytes.length;
try {
if (bufferLength <= Byte.MAX_VALUE) {
buffer.put((byte)1);
buffer.put((byte)bufferLength);
} else if (bufferLength <= Short.MAX_VALUE) {
buffer.put((byte)2);
buffer.putShort((short)bufferLength);
} else {
buffer.put((byte)3);
buffer.putInt(bufferLength);
}
buffer.put(stringBytes);
}
catch (BufferOverflowException e) {
e.printStackTrace();
}
}