本文整理匯總了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();
}
}