当前位置: 首页>>代码示例>>Java>>正文


Java CharacterCodingException.printStackTrace方法代码示例

本文整理汇总了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 "";
}
 
开发者ID:roscisz,项目名称:KernelHive,代码行数:20,代码来源:Decoder.java

示例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;
  }
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:47,代码来源:Text.java

示例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;
	}
}
 
开发者ID:roscisz,项目名称:KernelHive,代码行数:12,代码来源:Decoder.java

示例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;
  }
}
 
开发者ID:spafka,项目名称:spark_deep,代码行数:47,代码来源:Text.java


注:本文中的java.nio.charset.CharacterCodingException.printStackTrace方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。