本文整理汇总了Java中java.nio.charset.CharacterCodingException.printStackTrace方法的典型用法代码示例。如果您正苦于以下问题:Java CharacterCodingException.printStackTrace方法的具体用法?Java CharacterCodingException.printStackTrace怎么用?Java CharacterCodingException.printStackTrace使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.nio.charset.CharacterCodingException
的用法示例。
在下文中一共展示了CharacterCodingException.printStackTrace方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: decode
import java.nio.charset.CharacterCodingException; //导入方法依赖的package包/类
public static String decode(ByteBuffer buffer) {
//buffer.flip();
// FIXME: Setting the charset somewhere
CharsetDecoder decoder = charset.newDecoder();
CharBuffer charBuffer;
try {
charBuffer = decoder.decode(buffer);
String message = charBuffer.toString();
message = message.split("\n")[0];
message = message.split("\r")[0];
return message;
}
catch(CharacterCodingException cce) {
cce.printStackTrace();
}
return "";
}
示例2: find
import java.nio.charset.CharacterCodingException; //导入方法依赖的package包/类
/**
* Finds any occurrence of <code>what</code> in the backing
* buffer, starting as position <code>start</code>. The starting
* position is measured in bytes and the return value is in
* terms of byte position in the buffer. The backing buffer is
* not converted to a string for this operation.
* @return byte position of the first occurrence of the search
* string in the UTF-8 buffer or -1 if not found
*/
public int find(String what, int start) {
try {
ByteBuffer src = ByteBuffer.wrap(this.bytes,0,this.length);
ByteBuffer tgt = encode(what);
byte b = tgt.get();
src.position(start);
while (src.hasRemaining()) {
if (b == src.get()) { // matching first byte
src.mark(); // save position in loop
tgt.mark(); // save position in target
boolean found = true;
int pos = src.position()-1;
while (tgt.hasRemaining()) {
if (!src.hasRemaining()) { // src expired first
tgt.reset();
src.reset();
found = false;
break;
}
if (!(tgt.get() == src.get())) {
tgt.reset();
src.reset();
found = false;
break; // no match
}
}
if (found) return pos;
}
}
return -1; // not found
} catch (CharacterCodingException e) {
// can't get here
e.printStackTrace();
return -1;
}
}
示例3: encode
import java.nio.charset.CharacterCodingException; //导入方法依赖的package包/类
public static ByteBuffer encode(String message) {
try {
ByteBuffer ret = encoder.encode(CharBuffer.wrap(message));
ret.position(ret.limit());
return ret;
}
catch(CharacterCodingException cce) {
cce.printStackTrace();
return null;
}
}
示例4: find
import java.nio.charset.CharacterCodingException; //导入方法依赖的package包/类
/**
* Finds any occurence of <code>what</code> in the backing
* buffer, starting as position <code>start</code>. The starting
* position is measured in bytes and the return value is in
* terms of byte position in the buffer. The backing buffer is
* not converted to a string for this operation.
* @return byte position of the first occurence of the search
* string in the UTF-8 buffer or -1 if not found
*/
public int find(String what, int start) {
try {
ByteBuffer src = ByteBuffer.wrap(this.bytes,0,this.length);
ByteBuffer tgt = encode(what);
byte b = tgt.get();
src.position(start);
while (src.hasRemaining()) {
if (b == src.get()) { // matching first byte
src.mark(); // save position in loop
tgt.mark(); // save position in target
boolean found = true;
int pos = src.position()-1;
while (tgt.hasRemaining()) {
if (!src.hasRemaining()) { // src expired first
tgt.reset();
src.reset();
found = false;
break;
}
if (!(tgt.get() == src.get())) {
tgt.reset();
src.reset();
found = false;
break; // no match
}
}
if (found) return pos;
}
}
return -1; // not found
} catch (CharacterCodingException e) {
// can't get here
e.printStackTrace();
return -1;
}
}