本文整理了Java中java.nio.charset.CoderResult.throwException()
方法的一些代码示例,展示了CoderResult.throwException()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。CoderResult.throwException()
方法的具体详情如下:
包路径:java.nio.charset.CoderResult
类名称:CoderResult
方法名:throwException
[英]Throws an exception corresponding to this coder result.
[中]引发与此编码器结果对应的异常。
代码示例来源: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: org.postgresql/postgresql
private void checkEncodeResult(CoderResult result) throws CharacterCodingException {
if (result.isError()) {
result.throwException();
}
}
代码示例来源: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: 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: 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: killme2008/xmemcached
CoderResult cr;
if (hasRemaining()) {
cr = decoder.decode(buf(), out, true);
} else {
cr = decoder.flush(out);
if (cr.isUnderflow()) {
break;
if (cr.isError()) {
cr.throwException();
代码示例来源:origin: jenkinsci/jenkins
/**
* Decodes the contents of {@link #buf} as much as possible to {@link #out}.
* If necessary {@link #out} is further sent to {@link #writer}.
*
* <p>
* When this method returns, the {@link #buf} is back to the 'accumulation'
* mode.
*
* @param last
* if true, tell the decoder that all the input bytes are ready.
*/
private void decode(boolean last) throws IOException {
buf.flip();
while(true) {
CoderResult r = decoder.decode(buf, out, last);
if(r==CoderResult.OVERFLOW) {
flushOutput();
continue;
}
if(r==CoderResult.UNDERFLOW) {
buf.compact();
return;
}
// otherwise treat it as an error
r.throwException();
}
}
代码示例来源:origin: org.antlr/antlr4-runtime
endOfInput = (bytesRead == -1);
utf8BytesIn.flip();
CoderResult result = decoder.decode(
utf8BytesIn,
utf16CodeUnitsOut,
endOfInput);
if (result.isError() && decodingErrorAction.equals(CodingErrorAction.REPORT)) {
result.throwException();
if (flushResult.isError() && decodingErrorAction.equals(CodingErrorAction.REPORT)) {
flushResult.throwException();
代码示例来源:origin: real-logic/aeron
private void write(final ByteBuffer buffer, final FileChannel fileChannel)
{
try
{
buffer.clear();
encoder.reset();
final CoderResult coderResult = encoder.encode(CharBuffer.wrap(builder), buffer, false);
if (CoderResult.UNDERFLOW != coderResult)
{
coderResult.throwException();
}
buffer.flip();
do
{
fileChannel.write(buffer);
}
while (buffer.remaining() > 0);
}
catch (final Exception ex)
{
LangUtil.rethrowUnchecked(ex);
}
}
}
代码示例来源: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 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: 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: google/guava
result = encoder.flush(byteBuffer);
} else {
result = encoder.encode(charBuffer, byteBuffer, endOfInput);
} else if (result.isUnderflow()) {
readMoreChars();
} else if (result.isError()) {
result.throwException();
return 0; // Not called.
代码示例来源:origin: killme2008/xmemcached
CoderResult cr;
if (hasRemaining()) {
cr = decoder.decode(buf(), out, true);
} else {
cr = decoder.flush(out);
if (cr.isUnderflow()) {
break;
if (cr.isError()) {
cr.throwException();
代码示例来源:origin: org.apache.httpcomponents.core5/httpcore5
private void checkResult(final CoderResult result) throws IOException {
if (result.isError()) {
result.throwException();
}
}
代码示例来源:origin: apache/flume
CoderResult res = decoder.decode(buf, charBuf, isEndOfInput);
if (res.isMalformed() || res.isUnmappable()) {
res.throwException();
res = decoder.decode(buf, charBuf, isEndOfInput);
if (res.isMalformed() || res.isUnmappable()) {
res.throwException();
代码示例来源:origin: teiid/teiid
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: prestodb/presto
@SuppressWarnings("ObjectToString")
public static String decodeString(ByteBuffer src, Charset charset)
{
CharsetDecoder decoder = getDecoder(charset);
CharBuffer dst = CharBuffer.allocate((int) ((double) src.remaining() * decoder.maxCharsPerByte()));
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);
}
return dst.flip().toString();
}
代码示例来源:origin: org.apache.james/apache-mime4j-core
private void fillBuffer() throws CharacterCodingException {
this.bbuf.compact();
CoderResult result = this.encoder.encode(this.cbuf, this.bbuf, true);
if (result.isError()) {
result.throwException();
}
this.bbuf.flip();
}
内容来源于网络,如有侵权,请联系作者删除!