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

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

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

CoderResult.isError介绍

[英]Returns true if this result represents a malformed-input error or an unmappable-character error.
[中]

代码示例

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

/**
 * Fills the byte output buffer from the input char buffer.
 *
 * @throws CharacterCodingException
 *             an error encoding data
 */
private void fillBuffer() throws CharacterCodingException {
  this.bbuf.compact();
  final CoderResult result = this.encoder.encode(this.cbuf, this.bbuf, true);
  if (result.isError()) {
    result.throwException();
  }
  this.bbuf.flip();
}

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

private void convert(CharBuffer chars) throws IOException {
  while (true) {
    CoderResult result = encoder.encode(chars, bytes, false);
    if (result.isOverflow()) {
      // Make room and try again.
      flushBytes(false);
      continue;
    } else if (result.isError()) {
      result.throwException();
    }
    break;
  }
}

代码示例来源:origin: android-hacker/VirtualXposed

public void flush() throws IOException {
  //Log.i("PackageManager", "flush mPos=" + mPos);
  if (mPos > 0) {
    if (mOutputStream != null) {
      CharBuffer charBuffer = CharBuffer.wrap(mText, 0, mPos);
      CoderResult result = mCharset.encode(charBuffer, mBytes, true);
      while (true) {
        if (result.isError()) {
          throw new IOException(result.toString());
        } else if (result.isOverflow()) {
          flushBytes();
          result = mCharset.encode(charBuffer, mBytes, true);
          continue;
        }
        break;
      }
      flushBytes();
      mOutputStream.flush();
    } else {
      mWriter.write(mText, 0, mPos);
      mWriter.flush();
    }
    mPos = 0;
  }
}

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

private void checkEncodeResult(CoderResult result) throws CharacterCodingException {
 if (result.isError()) {
  result.throwException();
 }
}

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

if (result.isOverflow()) {
  readMoreChars();
} else if (result.isError()) {
 result.throwException();
 return 0; // Not called.

代码示例来源:origin: evernote/android-job

public void flush() throws IOException {
  //Log.i("PackageManager", "flush mPos=" + mPos);
  if (mPos > 0) {
    if (mOutputStream != null) {
      CharBuffer charBuffer = CharBuffer.wrap(mText, 0, mPos);
      CoderResult result = mCharset.encode(charBuffer, mBytes, true);
      while (true) {
        if (result.isError()) {
          throw new IOException(result.toString());
        } else if (result.isOverflow()) {
          flushBytes();
          result = mCharset.encode(charBuffer, mBytes, true);
          continue;
        }
        break;
      }
      flushBytes();
      mOutputStream.flush();
    } else {
      mWriter.write(mText, 0, mPos);
      mWriter.flush();
    }
    mPos = 0;
  }
}

代码示例来源:origin: com.liferay.portal/com.liferay.portal.kernel

private void _flushEncoder() throws IOException {
  _encodeLeftoverChar(_EMPTY_CHAR_BUFFER, true);
  // Ensure encoder transit to END state before flushing, in case the
  // encoder was never used and still in RESET state.
  _charsetEncoder.encode(_EMPTY_CHAR_BUFFER, _outputByteBuffer, true);
  while (true) {
    CoderResult coderResult = _charsetEncoder.flush(_outputByteBuffer);
    if (coderResult.isError()) {
      coderResult.throwException();
    }
    if (coderResult.isUnderflow()) {
      break;
    }
    // Must be overflow, no need to check
    _flushBuffer();
  }
}

代码示例来源: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: wildfly/wildfly

while (byteBuffer.hasRemaining()) {
  final CoderResult result = decoder.decode(byteBuffer, charBuffer, eof);
  if (result.isOverflow()) {
    writer.write(chars, 0, charBuffer.position());
    charBuffer.clear();
  if (result.isError()) {
    if (result.isMalformed()) {
      throw msg.malformedInput();

代码示例来源:origin: com.liferay.portal/com.liferay.portal.kernel

private void _encodeLoop(CharBuffer inputCharBuffer, boolean endOfInput)
  throws IOException {
  while (inputCharBuffer.hasRemaining()) {
    CoderResult coderResult = _charsetEncoder.encode(
      inputCharBuffer, _outputByteBuffer, endOfInput);
    if (coderResult.isError()) {
      coderResult.throwException();
    }
    if (coderResult.isUnderflow()) {
      if (_autoFlush) {
        _flushBuffer();
      }
      if ((_inputCharBuffer != inputCharBuffer) &&
        inputCharBuffer.hasRemaining()) {
        _inputCharBuffer.put(inputCharBuffer.get());
      }
      break;
    }
    // Must be overflow, no need to check
    _flushBuffer();
  }
}

代码示例来源:origin: prestodb/presto

if (result.isOverflow()) {
  readMoreChars();
} else if (result.isError()) {
 result.throwException();
 return 0; // Not called.

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

while (charBuffer.hasRemaining()) {
  final CoderResult result = encoder.encode(charBuffer, byteBuffer, false);
  if (result.isOverflow()) {
    return true;
    break;
  if (result.isError()) {
    if (result.isMalformed()) {
      throw msg.malformedInput();

代码示例来源:origin: org.antlr/antlr4-runtime

utf16CodeUnitsOut,
    endOfInput);
  if (result.isError() && decodingErrorAction.equals(CodingErrorAction.REPORT)) {
    result.throwException();
if (flushResult.isError() && decodingErrorAction.equals(CodingErrorAction.REPORT)) {
  flushResult.throwException();

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

if (result.isOverflow()) {
  readMoreChars();
} else if (result.isError()) {
 result.throwException();
 return 0; // Not called.

代码示例来源:origin: nu.zoom.svansprogram/svansprogram-tail

private void logErrors(CoderResult coderResult) {
  if (coderResult.isOverflow()) {
    log.error("Buffer overflow, the character buffer is not large enough to decode the characters, some information may be lost");
  } else if (coderResult.isError()) {
    log.warn("There was some error in decoding the file given the current charset");
  }
}

代码示例来源:origin: org.apache.httpcomponents.core5/httpcore5

private void checkResult(final CoderResult result) throws IOException {
  if (result.isError()) {
    result.throwException();
  }
}

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

if (result.isOverflow()) {
  readMoreChars();
} else if (result.isError()) {
 result.throwException();
 return 0; // Not called.

代码示例来源:origin: org.jruby/jruby-complete

private void byte2char(ByteBuffer bytes, CharBuffer chars) throws IOException {
    decoder.reset();
    chars.clear();
    CoderResult result = decoder.decode(bytes, chars, true);
    if (result.isError() || result.isOverflow()) {
      throw new IOException(result.toString());
    } else if (result.isUnderflow()) {
      chars.flip();
    }
  }
}

代码示例来源:origin: apache/httpcomponents-core

private void checkResult(final CoderResult result) throws IOException {
  if (result.isError()) {
    result.throwException();
  }
}

代码示例来源:origin: killme2008/xmemcached

if (cr.isOverflow()) {
 CharBuffer o = CharBuffer.allocate(out.capacity() + expectedLength);
 out.flip();
if (cr.isError()) {
 cr.throwException();

相关文章