本文整理汇总了Java中java.nio.charset.CharsetDecoder.reset方法的典型用法代码示例。如果您正苦于以下问题:Java CharsetDecoder.reset方法的具体用法?Java CharsetDecoder.reset怎么用?Java CharsetDecoder.reset使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.nio.charset.CharsetDecoder
的用法示例。
在下文中一共展示了CharsetDecoder.reset方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: parseObject
import java.nio.charset.CharsetDecoder; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public static <T> T parseObject(byte[] input, //
int off, //
int len, //
CharsetDecoder charsetDecoder, //
Type clazz, //
Feature... features) {
charsetDecoder.reset();
int scaleLength = (int) (len * (double) charsetDecoder.maxCharsPerByte());
char[] chars = allocateChars(scaleLength);
ByteBuffer byteBuf = ByteBuffer.wrap(input, off, len);
CharBuffer charByte = CharBuffer.wrap(chars);
IOUtils.decode(charsetDecoder, byteBuf, charByte);
int position = charByte.position();
return (T) parseObject(chars, position, clazz, features);
}
示例2: parseObject
import java.nio.charset.CharsetDecoder; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public static final <T> T parseObject(byte[] input, int off, int len, CharsetDecoder charsetDecoder, Type clazz,
Feature... features) {
charsetDecoder.reset();
int scaleLength = (int) (len * (double) charsetDecoder.maxCharsPerByte());
char[] chars = ThreadLocalCache.getChars(scaleLength);
ByteBuffer byteBuf = ByteBuffer.wrap(input, off, len);
CharBuffer charByte = CharBuffer.wrap(chars);
IOUtils.decode(charsetDecoder, byteBuf, charByte);
int position = charByte.position();
return (T) parseObject(chars, position, clazz, features);
}
示例3: decodeString
import java.nio.charset.CharsetDecoder; //导入方法依赖的package包/类
private static String decodeString(ByteBuffer src) throws CharacterCodingException
{
// the decoder needs to be reset every time we use it, hence the copy per thread
CharsetDecoder theDecoder = TL_UTF8_DECODER.get();
theDecoder.reset();
CharBuffer dst = TL_CHAR_BUFFER.get();
int capacity = (int) ((double) src.remaining() * theDecoder.maxCharsPerByte());
if (dst == null)
{
capacity = Math.max(capacity, 4096);
dst = CharBuffer.allocate(capacity);
TL_CHAR_BUFFER.set(dst);
}
else
{
dst.clear();
if (dst.capacity() < capacity)
{
dst = CharBuffer.allocate(capacity);
TL_CHAR_BUFFER.set(dst);
}
}
CoderResult cr = theDecoder.decode(src, dst, true);
if (!cr.isUnderflow())
cr.throwException();
return dst.flip().toString();
}
示例4: createCharsetDecoder
import java.nio.charset.CharsetDecoder; //导入方法依赖的package包/类
/**
* Creates an CharsetDecoder which tests the encoding
*
* @return CharsetDecoder
*/
private static CharsetDecoder createCharsetDecoder() {
Charset charset = Charset.forName(encoding);
CharsetDecoder decoder = charset.newDecoder();
decoder.reset();
return decoder;
}
示例5: loadSynonyms
import java.nio.charset.CharsetDecoder; //导入方法依赖的package包/类
/**
* Load synonyms with the given {@link SynonymMap.Parser} class.
*/
private SynonymMap loadSynonyms(ResourceLoader loader, String cname, boolean dedup, Analyzer analyzer) throws IOException, ParseException {
CharsetDecoder decoder = Charset.forName("UTF-8").newDecoder()
.onMalformedInput(CodingErrorAction.REPORT)
.onUnmappableCharacter(CodingErrorAction.REPORT);
SynonymMap.Parser parser;
Class<? extends SynonymMap.Parser> clazz = loader.findClass(cname, SynonymMap.Parser.class);
try {
parser = clazz.getConstructor(boolean.class, boolean.class, Analyzer.class).newInstance(dedup, expand, analyzer);
} catch (Exception e) {
throw new RuntimeException(e);
}
File synonymFile = new File(synonyms);
if (synonymFile.exists()) {
decoder.reset();
parser.parse(new InputStreamReader(loader.openResource(synonyms), decoder));
} else {
List<String> files = splitFileNames(synonyms);
for (String file : files) {
decoder.reset();
parser.parse(new InputStreamReader(loader.openResource(file), decoder));
}
}
return parser.build();
}
示例6: getCorrectDecoder
import java.nio.charset.CharsetDecoder; //导入方法依赖的package包/类
/**
* If they have specified UTF-16 then decoder works out by looking at BOM
* but if missing we have to make an educated guess otherwise just use
* specified decoder
*
* @param inBuffer
* @return
*/
protected CharsetDecoder getCorrectDecoder(ByteBuffer inBuffer)
{
CharsetDecoder decoder=null;
if(inBuffer.remaining()<=2)
{
decoder = getTextEncodingCharSet().newDecoder();
decoder.reset();
return decoder;
}
if(getTextEncodingCharSet()== StandardCharsets.UTF_16)
{
if(inBuffer.getChar(0)==0xfffe || inBuffer.getChar(0)==0xfeff)
{
//Get the Specified Decoder
decoder = getTextEncodingCharSet().newDecoder();
decoder.reset();
}
else
{
if(inBuffer.get(0)==0)
{
decoder = StandardCharsets.UTF_16BE.newDecoder();
decoder.reset();
}
else
{
decoder = StandardCharsets.UTF_16LE.newDecoder();
decoder.reset();
}
}
}
else
{
decoder = getTextEncodingCharSet().newDecoder();
decoder.reset();
}
return decoder;
}
示例7: parse
import java.nio.charset.CharsetDecoder; //导入方法依赖的package包/类
public static final Object parse(byte[] input, int off, int len, CharsetDecoder charsetDecoder, int features) {
charsetDecoder.reset();
char[] chars = ThreadLocalCache.getChars((int) (((double) len) * ((double) charsetDecoder.maxCharsPerByte())));
ByteBuffer byteBuf = ByteBuffer.wrap(input, off, len);
CharBuffer charBuf = CharBuffer.wrap(chars);
IOUtils.decode(charsetDecoder, byteBuf, charBuf);
DefaultJSONParser parser = new DefaultJSONParser(chars, charBuf.position(), ParserConfig.getGlobalInstance(), features);
Object value = parser.parse();
parser.handleResovleTask(value);
parser.close();
return value;
}
示例8: parseObject
import java.nio.charset.CharsetDecoder; //导入方法依赖的package包/类
public static final <T> T parseObject(byte[] input, int off, int len, CharsetDecoder charsetDecoder, Type clazz, Feature... features) {
charsetDecoder.reset();
char[] chars = ThreadLocalCache.getChars((int) (((double) len) * ((double) charsetDecoder.maxCharsPerByte())));
ByteBuffer byteBuf = ByteBuffer.wrap(input, off, len);
CharBuffer charByte = CharBuffer.wrap(chars);
IOUtils.decode(charsetDecoder, byteBuf, charByte);
return parseObject(chars, charByte.position(), clazz, features);
}
示例9: parse
import java.nio.charset.CharsetDecoder; //导入方法依赖的package包/类
public static Object parse(byte[] input, int off, int len, CharsetDecoder charsetDecoder, int features) {
charsetDecoder.reset();
int scaleLength = (int) (len * (double) charsetDecoder.maxCharsPerByte());
char[] chars = allocateChars(scaleLength);
ByteBuffer byteBuf = ByteBuffer.wrap(input, off, len);
CharBuffer charBuf = CharBuffer.wrap(chars);
IOUtils.decode(charsetDecoder, byteBuf, charBuf);
int position = charBuf.position();
DefaultJSONParser parser = new DefaultJSONParser(chars, position, ParserConfig.getGlobalInstance(), features);
Object value = parser.parse();
parser.handleResovleTask(value);
parser.close();
return value;
}
示例10: getPrefixedString
import java.nio.charset.CharsetDecoder; //导入方法依赖的package包/类
/**
* Reads a string which has a length field before the actual
* encoded string, using the specified <code>decoder</code> and returns it.
*
* @param prefixLength the length of the length field (1, 2, or 4)
* @param decoder the decoder to use for decoding the string
* @return the prefixed string
* @throws CharacterCodingException when decoding fails
* @throws BufferUnderflowException when there is not enough data available
*/
@Override
public String getPrefixedString(int prefixLength, CharsetDecoder decoder) throws CharacterCodingException {
if (!prefixedDataAvailable(prefixLength)) {
throw new BufferUnderflowException();
}
int fieldSize = 0;
switch (prefixLength) {
case 1:
fieldSize = getUnsigned();
break;
case 2:
fieldSize = getUnsignedShort();
break;
case 4:
fieldSize = getInt();
break;
}
if (fieldSize == 0) {
return "";
}
boolean utf16 = decoder.charset().name().startsWith("UTF-16");
if (utf16 && (fieldSize & 1) != 0) {
throw new BufferDataException("fieldSize is not even for a UTF-16 string.");
}
int oldLimit = limit();
int end = position() + fieldSize;
if (oldLimit < end) {
throw new BufferUnderflowException();
}
limit(end);
decoder.reset();
int expectedLength = (int) (remaining() * decoder.averageCharsPerByte()) + 1;
CharBuffer out = CharBuffer.allocate(expectedLength);
for (;;) {
CoderResult cr;
if (hasRemaining()) {
cr = decoder.decode(buf(), out, true);
} else {
cr = decoder.flush(out);
}
if (cr.isUnderflow()) {
break;
}
if (cr.isOverflow()) {
CharBuffer o = CharBuffer.allocate(out.capacity() + expectedLength);
out.flip();
o.put(out);
out = o;
continue;
}
cr.throwException();
}
limit(oldLimit);
position(end);
return out.flip().toString();
}
示例11: parse
import java.nio.charset.CharsetDecoder; //导入方法依赖的package包/类
public static final Object parse(byte[] input, int off, int len, CharsetDecoder charsetDecoder, int features) {
charsetDecoder.reset();
int scaleLength = (int) (len * (double) charsetDecoder.maxCharsPerByte());
char[] chars = ThreadLocalCache.getChars(scaleLength);
ByteBuffer byteBuf = ByteBuffer.wrap(input, off, len);
CharBuffer charBuf = CharBuffer.wrap(chars);
IOUtils.decode(charsetDecoder, byteBuf, charBuf);
int position = charBuf.position();
DefaultJSONParser parser = new DefaultJSONParser(chars, position, ParserConfig.getGlobalInstance(), features);
Object value = parser.parse();
parser.handleResovleTask(value);
parser.close();
return value;
}