java.nio.charset.CoderResult.isUnderflow()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(9.1k)|赞(0)|评价(0)|浏览(130)

本文整理了Java中java.nio.charset.CoderResult.isUnderflow()方法的一些代码示例,展示了CoderResult.isUnderflow()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。CoderResult.isUnderflow()方法的具体详情如下:
包路径:java.nio.charset.CoderResult
类名称:CoderResult
方法名:isUnderflow

CoderResult.isUnderflow介绍

[英]Returns true if this result is an underflow condition.
[中]如果此结果为下溢条件,则返回true。

代码示例

代码示例来源:origin: AsyncHttpClient/async-http-client

private static void decode(CharsetDecoder decoder, ByteBuffer src, CharBuffer dst) {
 try {
  CoderResult cr = decoder.decode(src, dst, true);
  if (!cr.isUnderflow()) {
   cr.throwException();
  }
  cr = decoder.flush(dst);
  if (!cr.isUnderflow()) {
   cr.throwException();
  }
 } catch (CharacterCodingException x) {
  throw new IllegalStateException(x);
 }
}

代码示例来源:origin: commons-io/commons-io

/**
 * Decode the contents of the input ByteBuffer into a CharBuffer.
 *
 * @param endOfInput indicates end of input
 * @throws IOException if an I/O error occurs
 */
private void processInput(final boolean endOfInput) throws IOException {
  // Prepare decoderIn for reading
  decoderIn.flip();
  CoderResult coderResult;
  while (true) {
    coderResult = decoder.decode(decoderIn, decoderOut, endOfInput);
    if (coderResult.isOverflow()) {
      flushOutput();
    } else if (coderResult.isUnderflow()) {
      break;
    } else {
      // The decoder is configured to replace malformed input and unmappable characters,
      // so we should not get here.
      throw new IOException("Unexpected coder result");
    }
  }
  // Discard the bytes that have been read
  decoderIn.compact();
}

代码示例来源:origin: commons-io/commons-io

/**
 * Fills the internal char buffer from the reader.
 *
 * @throws IOException
 *             If an I/O error occurs
 */
private void fillBuffer() throws IOException {
  if (!endOfInput && (lastCoderResult == null || lastCoderResult.isUnderflow())) {
    encoderIn.compact();
    final int position = encoderIn.position();
    // We don't use Reader#read(CharBuffer) here because it is more efficient
    // to write directly to the underlying char array (the default implementation
    // copies data to a temporary char array).
    final int c = reader.read(encoderIn.array(), position, encoderIn.remaining());
    if (c == EOF) {
      endOfInput = true;
    } else {
      encoderIn.position(position+c);
    }
    encoderIn.flip();
  }
  encoderOut.compact();
  lastCoderResult = encoder.encode(encoderIn, encoderOut, endOfInput);
  encoderOut.flip();
}

代码示例来源:origin: google/guava

result = encoder.flush(byteBuffer);
} else {
 result = encoder.encode(charBuffer, byteBuffer, endOfInput);
if (result.isOverflow()) {
} else if (result.isUnderflow()) {
 result.throwException();
 return 0; // Not called.

代码示例来源:origin: jfinal/jfinal

public int encode(char[] chars, int offset, int len, byte[] bytes) {
    ce.reset();
    ByteBuffer bb = ByteBuffer.wrap(bytes);
    CharBuffer cb = CharBuffer.wrap(chars, offset, len);
    try {
      CoderResult cr = ce.encode(cb, bb, true);
      if (!cr.isUnderflow())
        cr.throwException();
      cr = ce.flush(bb);
      if (!cr.isUnderflow())
        cr.throwException();
      return bb.position();
    } catch (CharacterCodingException x) {
      // Substitution is always enabled,
      // so this shouldn't happen
      throw new RuntimeException("Encode error: " + x.getMessage(), x);
    }
  }
}

代码示例来源:origin: spring-projects/spring-framework

while (true) {
  CoderResult cr = (inBuffer.hasRemaining() ?
      charsetEncoder.encode(inBuffer, outBuffer, true) : CoderResult.UNDERFLOW);
  if (cr.isUnderflow()) {
    cr = charsetEncoder.flush(outBuffer);
  if (cr.isUnderflow()) {
    break;
  if (cr.isOverflow()) {
    writePosition(outBuffer.position());
    int maximumSize = (int) (inBuffer.remaining() * charsetEncoder.maxBytesPerChar());

代码示例来源:origin: wildfly/wildfly

while (byteBuffer.hasRemaining()) {
  while (charBuffer.hasRemaining()) {
    final CoderResult result = encoder.encode(charBuffer, byteBuffer, false);
    if (result.isOverflow()) {
      return true;
    if (result.isUnderflow()) {
      filled = true;
      break;
    charBuffer.flip();

代码示例来源:origin: apache/incubator-druid

private Map<String, Object> buildStringKeyMap(ByteBuffer input)
{
 int payloadSize = input.remaining();
 if (chars == null || chars.remaining() < payloadSize) {
  chars = CharBuffer.allocate(payloadSize);
 }
 final CoderResult coderResult = charset.newDecoder()
                     .onMalformedInput(CodingErrorAction.REPLACE)
                     .onUnmappableCharacter(CodingErrorAction.REPLACE)
                     .decode(input, chars, true);
 Map<String, Object> theMap;
 if (coderResult.isUnderflow()) {
  chars.flip();
  try {
   theMap = parseString(chars.toString());
  }
  finally {
   chars.clear();
  }
 } else {
  throw new ParseException("Failed with CoderResult[%s]", coderResult);
 }
 return theMap;
}

代码示例来源:origin: jline/jline

result = decoder.decode(bytes, out, false);
if (result.isUnderflow()) {
result = decoder.decode(bytes, out, true);
decoder.flush(out);
decoder.reset();

代码示例来源:origin: org.owasp.encoder/encoder

@Override
public CoderResult encode(CharBuffer input, CharBuffer output, boolean endOfInput) {
  for (;;) {
    CoderResult cr1 = _first.encode(input, _buffer, endOfInput);
    _buffer.flip();
    CoderResult cr2 = _last.encode(_buffer, output, endOfInput && cr1.isUnderflow());
    _buffer.compact();
    if (cr2.isOverflow()) {
      // no more room in output, even if we still have buffered input.
      return cr2;
    }
    if (cr1.isUnderflow()) {
      // we've consumed everything from input
      return cr2;
    }
  }
}

代码示例来源:origin: AsyncHttpClient/async-http-client

protected void decodePartial(ByteBuffer nioBuffer, boolean endOfInput) {
 // deal with pending splitCharBuffer
 if (splitCharBuffer.position() > 0 && nioBuffer.hasRemaining()) {
  handlePendingSplitCharBuffer(nioBuffer, endOfInput);
 }
 // decode remaining buffer
 if (nioBuffer.hasRemaining()) {
  CoderResult res = decoder.decode(nioBuffer, charBuffer, endOfInput);
  if (res.isUnderflow()) {
   if (nioBuffer.remaining() > 0) {
    splitCharBuffer.put(nioBuffer);
   }
  }
 }
}

代码示例来源:origin: org.jline/jline

private void encodeBytes(CharsetEncoder encoder, ByteBuffer output) throws IOException {
  CoderResult result = encoder.encode(readBuffer, output, false);
  if (rewindReadBuffer() && result.isUnderflow()) {
    encoder.encode(readBuffer, output, false);
    rewindReadBuffer();
  }
}

代码示例来源:origin: org.teiid/teiid-common-core

private void checkResult(CoderResult cr) throws IOException {
  if (cr.isOverflow()) {
    wasOverflow = true;
    assert bb.position() > 0;
  } else if (!cr.isUnderflow()) {
    try {
      cr.throwException();
    } catch (CharacterCodingException e) {
      throw new IOException(CorePlugin.Util.gs(CorePlugin.Event.TEIID10083, encoder.charset().displayName()), e);
    }
  } else {
    wasOverflow = false;
  }
}

代码示例来源:origin: org.teiid/teiid-common-core

private void checkResult(CoderResult cr) throws IOException {
  if (!cr.isUnderflow() && cr.isError()) {
    if (cr.isMalformed() || cr.isUnmappable()) {
      try {
        cr.throwException();
      } catch (CharacterCodingException e) {
        throw new IOException(CorePlugin.Util.gs(CorePlugin.Event.TEIID10082, cd.charset().displayName(), bytesProcessed + bb.position() + 1), e);
      }
    }
    cr.throwException();
  }
}

代码示例来源:origin: wildfly/wildfly

private static void decodeString(CharsetDecoder decoder, ByteBuffer src, CharBuffer dst) {
  try {
    CoderResult cr = decoder.decode(src, dst, true);
    if (!cr.isUnderflow()) {
      cr.throwException();
    }
    cr = decoder.flush(dst);
    if (!cr.isUnderflow()) {
      cr.throwException();
    }
  } catch (CharacterCodingException x) {
    throw new IllegalStateException(x);
  }
}

代码示例来源:origin: robovm/robovm

private void drainEncoder() throws IOException {
  // Strictly speaking, I think it's part of the CharsetEncoder contract that you call
  // encode with endOfInput true before flushing. Our ICU-based implementations don't
  // actually need this, and you'd hope that any reasonable implementation wouldn't either.
  // CharsetEncoder.encode doesn't actually pass the boolean through to encodeLoop anyway!
  CharBuffer chars = CharBuffer.allocate(0);
  while (true) {
    CoderResult result = encoder.encode(chars, bytes, true);
    if (result.isError()) {
      result.throwException();
    } else if (result.isOverflow()) {
      flushBytes(false);
      continue;
    }
    break;
  }
  // Some encoders (such as ISO-2022-JP) have stuff to write out after all the
  // characters (such as shifting back into a default state). In our implementation,
  // this is actually the first time ICU is told that we've run out of input.
  CoderResult result = encoder.flush(bytes);
  while (!result.isUnderflow()) {
    if (result.isOverflow()) {
      flushBytes(false);
      result = encoder.flush(bytes);
    } else {
      result.throwException();
    }
  }
}

代码示例来源:origin: netty/netty

final ByteBuffer dstBuf = dst.internalNioBuffer(dst.readerIndex(), length);
final int pos = dstBuf.position();
CoderResult cr = encoder.encode(src, dstBuf, true);
if (!cr.isUnderflow()) {
  cr.throwException();
if (!cr.isUnderflow()) {
  cr.throwException();

代码示例来源:origin: wildfly/wildfly

try {
  while (byteBuffer.hasRemaining()) {
    final CoderResult result = decoder.decode(byteBuffer, charBuffer, eof);
    if (result.isOverflow()) {
      writer.write(chars, 0, charBuffer.position());
      charBuffer.clear();
      continue;
    if (result.isUnderflow()) {
      final int p = charBuffer.position();
      if (p > 0) {

代码示例来源:origin: Atmosphere/atmosphere

/**
 * Fills the internal char buffer from the reader.
 *
 * @throws java.io.IOException If an I/O error occurs
 */
private void fillBuffer() throws IOException {
  if (!endOfInput && (lastCoderResult == null || lastCoderResult.isUnderflow())) {
    encoderIn.compact();
    int position = encoderIn.position();
    // We don't use Reader#read(CharBuffer) here because it is more efficient
    // to write directly to the underlying char array (the default implementation
    // copies data to a temporary char array).
    int c = reader.read(encoderIn.array(), position, encoderIn.remaining());
    if (c == -1) {
      endOfInput = true;
    } else {
      encoderIn.position(position + c);
    }
    encoderIn.flip();
  }
  encoderOut.compact();
  lastCoderResult = encoder.encode(encoderIn, encoderOut, endOfInput);
  encoderOut.flip();
}

代码示例来源:origin: org.springframework/spring-core

while (true) {
  CoderResult cr = (inBuffer.hasRemaining() ?
      charsetEncoder.encode(inBuffer, outBuffer, true) : CoderResult.UNDERFLOW);
  if (cr.isUnderflow()) {
    cr = charsetEncoder.flush(outBuffer);
  if (cr.isUnderflow()) {
    break;
  if (cr.isOverflow()) {
    writePosition(outBuffer.position());
    int maximumSize = (int) (inBuffer.remaining() * charsetEncoder.maxBytesPerChar());

相关文章