本文整理汇总了Java中java.nio.charset.CoderResult.isOverflow方法的典型用法代码示例。如果您正苦于以下问题:Java CoderResult.isOverflow方法的具体用法?Java CoderResult.isOverflow怎么用?Java CoderResult.isOverflow使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.nio.charset.CoderResult
的用法示例。
在下文中一共展示了CoderResult.isOverflow方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: processInput
import java.nio.charset.CoderResult; //导入方法依赖的package包/类
/**
* 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(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();
}
示例2: flush
import java.nio.charset.CoderResult; //导入方法依赖的package包/类
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;
}
}
示例3: Close
import java.nio.charset.CoderResult; //导入方法依赖的package包/类
Close(int statusCode, CharSequence reason) {
ByteBuffer payload = ByteBuffer.allocate(125)
.putChar((char) statusCode);
CoderResult result = UTF_8.newEncoder()
.encode(CharBuffer.wrap(reason),
payload,
true);
if (result.isOverflow()) {
throw new IllegalArgumentException("Long reason");
} else if (result.isError()) {
try {
result.throwException();
} catch (CharacterCodingException e) {
throw new IllegalArgumentException(
"Malformed UTF-8 reason", e);
}
}
payload.flip();
frame = getControlMessageBuffers(CLOSE, payload);
}
示例4: processInput
import java.nio.charset.CoderResult; //导入方法依赖的package包/类
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"); //NOI18N
}
}
// Discard the bytes that have been read
decoderIn.compact();
}
示例5: flushHead
import java.nio.charset.CoderResult; //导入方法依赖的package包/类
private CoderResult flushHead (CharBuffer in , ByteBuffer out) {
buffer.flip();
CoderResult r = encoder.encode(buffer,out, in==null);
if (r.isOverflow()) {
remainder = buffer;
buffer = null;
return r;
}
else {
buffer = null;
if (in == null) {
return r;
}
return encoder.encode(in, out, false);
}
}
示例6: flushHead
import java.nio.charset.CoderResult; //导入方法依赖的package包/类
private CoderResult flushHead (CharBuffer in , ByteBuffer out) {
buffer.flip();
CoderResult r = encoder.encode(buffer,out, in==null);
if (r.isOverflow()) {
cont = true;
return r;
}
buffer = null;
if (in == null) {
return r;
}
return encoder.encode(in, out, false);
}
示例7: convert
import java.nio.charset.CoderResult; //导入方法依赖的package包/类
/**
* Convert the given characters to bytes.
*
* @param cc char input
* @param bc byte output
*/
public void convert(CharChunk cc, ByteChunk bc)
throws IOException {
if ((bb == null) || (bb.array() != bc.getBuffer())) {
// Create a new byte buffer if anything changed
bb = ByteBuffer.wrap(bc.getBuffer(), bc.getEnd(),
bc.getBuffer().length - bc.getEnd());
} else {
// Initialize the byte buffer
bb.position(bc.getEnd());
bb.limit(bc.getBuffer().length);
}
if ((cb == null) || (cb.array() != cc.getBuffer())) {
// Create a new char buffer if anything changed
cb = CharBuffer.wrap(cc.getBuffer(), cc.getStart(),
cc.getLength());
} else {
// Initialize the char buffer
cb.position(cc.getStart());
cb.limit(cc.getEnd());
}
// Do the decoding and get the results into the byte chunk and the char chunk
CoderResult result = encoder.encode(cb, bb, false);
if (result.isError() || result.isMalformed()) {
result.throwException();
} else if (result.isOverflow()) {
// Propagate current positions to the byte chunk and char chunk
bc.setEnd(bb.position());
cc.setOffset(cb.position());
} else if (result.isUnderflow()) {
// Propagate current positions to the byte chunk and char chunk
bc.setEnd(bb.position());
cc.setOffset(cb.position());
}
}
示例8: write
import java.nio.charset.CoderResult; //导入方法依赖的package包/类
public void write() {
buffer.clear();
CoderResult cr = encoder.encode(message, buffer, true);
if (cr.isError()) {
throw new IllegalArgumentException(cr.toString());
}
isDone = !cr.isOverflow();
buffer.flip();
endpoint.startMessage(Constants.OPCODE_TEXT, buffer, isDone && isLast, this);
}
示例9: flushLocked
import java.nio.charset.CoderResult; //导入方法依赖的package包/类
private void flushLocked() 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()) {
flushBytesLocked();
result = mCharset.encode(charBuffer, mBytes, true);
continue;
}
break;
}
flushBytesLocked();
mOutputStream.flush();
} else if (mWriter != null) {
mWriter.write(mText, 0, mPos);
mWriter.flush();
} else {
int nonEolOff = 0;
final int sepLen = mSeparator.length();
final int len = sepLen < mPos ? sepLen : mPos;
while (nonEolOff < len && mText[mPos - 1 - nonEolOff]
== mSeparator.charAt(mSeparator.length() - 1 - nonEolOff)) {
nonEolOff++;
}
if (nonEolOff >= mPos) {
mPrinter.println("");
} else {
mPrinter.println(new String(mText, 0, mPos - nonEolOff));
}
}
mPos = 0;
}
}
示例10: write
import java.nio.charset.CoderResult; //导入方法依赖的package包/类
public void write() {
buffer.clear();
CoderResult cr = encoder.encode(message, buffer, true);
if (cr.isError()) {
throw new IllegalArgumentException(cr.toString());
}
isDone = !cr.isOverflow();
buffer.flip();
endpoint.startMessage(Constants.OPCODE_TEXT, buffer,
isDone && isLast, this);
}
示例11: read
import java.nio.charset.CoderResult; //导入方法依赖的package包/类
@Override
public int read(byte[] b, int off, int len) throws IOException {
// Obey InputStream contract.
checkPositionIndexes(off, off + len, b.length);
if (len == 0) {
return 0;
}
// The rest of this method implements the process described by the CharsetEncoder javadoc.
int totalBytesRead = 0;
boolean doneEncoding = endOfInput;
DRAINING:
while (true) {
// We stay in draining mode until there are no bytes left in the output buffer. Then we go
// back to encoding/flushing.
if (draining) {
totalBytesRead += drain(b, off + totalBytesRead, len - totalBytesRead);
if (totalBytesRead == len || doneFlushing) {
return (totalBytesRead > 0) ? totalBytesRead : -1;
}
draining = false;
byteBuffer.clear();
}
while (true) {
// We call encode until there is no more input. The last call to encode will have endOfInput
// == true. Then there is a final call to flush.
CoderResult result;
if (doneFlushing) {
result = CoderResult.UNDERFLOW;
} else if (doneEncoding) {
result = encoder.flush(byteBuffer);
} else {
result = encoder.encode(charBuffer, byteBuffer, endOfInput);
}
if (result.isOverflow()) {
// Not enough room in output buffer--drain it, creating a bigger buffer if necessary.
startDraining(true);
continue DRAINING;
} else if (result.isUnderflow()) {
// If encoder underflows, it means either:
// a) the final flush() succeeded; next drain (then done)
// b) we encoded all of the input; next flush
// c) we ran of out input to encode; next read more input
if (doneEncoding) { // (a)
doneFlushing = true;
startDraining(false);
continue DRAINING;
} else if (endOfInput) { // (b)
doneEncoding = true;
} else { // (c)
readMoreChars();
}
} else if (result.isError()) {
// Only reach here if a CharsetEncoder with non-REPLACE settings is used.
result.throwException();
return 0; // Not called.
}
}
}
}
示例12: shiftBufferStandard
import java.nio.charset.CoderResult; //导入方法依赖的package包/类
private boolean shiftBufferStandard() throws IllegalStateException,
IOException {
if (byteBuffer == null || byteBuffer.remaining() == 0) {
if (byteBuffer != null) {
MatcherUtils.unmap(byteBuffer);
}
long size = Math.min(SIZE_LIMIT, fileSize - decodedBytes);
byteBuffer = fileChannel.map(
FileChannel.MapMode.READ_ONLY,
decodedBytes,
size);
maps++;
}
long origByteBufPosition = byteBuffer.position();
int origCharBufLimit = charBufferStartsAt == -1
? 0
: charBuffer.limit();
charBuffer.clear();
CoderResult res;
res = decoder.decode(byteBuffer, charBuffer, false);
charBufferStartsAt = charBufferStartsAt == -1
? 0
: charBufferStartsAt + origCharBufLimit;
decodedBytes += byteBuffer.position() - origByteBufPosition;
if (res.isOverflow()) {
/*
* To much bytes for char buffer, will read from the same buffer
* the next time again.
*/
if (origByteBufPosition == byteBuffer.position()) {
throw new IllegalStateException("Neverending loop?");
}
charBuffer.flip();
return true;
} else if (decodedBytes < fileSize) {
/*
* Not at the end of file, will need new byte buffer.
*/
charBuffer.flip();
MatcherUtils.unmap(byteBuffer);
byteBuffer = null;
return true;
} else {
/*
* All bytes decoded, end and flush decoder.
*/
state = State.ENDING;
return shiftBufferEnding();
}
}
示例13: convert
import java.nio.charset.CoderResult; //导入方法依赖的package包/类
/**
* Convert the given bytes to characters.
*
* @param bc byte input
* @param cc char output
*/
public void convert(ByteChunk bc, CharChunk cc)
throws IOException {
if ((bb == null) || (bb.array() != bc.getBuffer())) {
// Create a new byte buffer if anything changed
bb = ByteBuffer.wrap(bc.getBuffer(), bc.getStart(), bc.getLength());
} else {
// Initialize the byte buffer
bb.position(bc.getStart());
bb.limit(bc.getEnd());
}
if ((cb == null) || (cb.array() != cc.getBuffer())) {
// Create a new char buffer if anything changed
cb = CharBuffer.wrap(cc.getBuffer(), cc.getEnd(),
cc.getBuffer().length - cc.getEnd());
} else {
// Initialize the char buffer
cb.position(cc.getEnd());
cb.limit(cc.getBuffer().length);
}
CoderResult result = null;
// Parse leftover if any are present
if (leftovers.position() > 0) {
int pos = cb.position();
// Loop until one char is decoded or there is a decoder error
do {
leftovers.put(bc.substractB());
leftovers.flip();
result = decoder.decode(leftovers, cb, false);
leftovers.position(leftovers.limit());
leftovers.limit(leftovers.array().length);
} while (result.isUnderflow() && (cb.position() == pos));
if (result.isError() || result.isMalformed()) {
result.throwException();
}
bb.position(bc.getStart());
leftovers.position(0);
}
// Do the decoding and get the results into the byte chunk and the char chunk
result = decoder.decode(bb, cb, false);
if (result.isError() || result.isMalformed()) {
result.throwException();
} else if (result.isOverflow()) {
// Propagate current positions to the byte chunk and char chunk, if this
// continues the char buffer will get resized
bc.setOffset(bb.position());
cc.setEnd(cb.position());
} else if (result.isUnderflow()) {
// Propagate current positions to the byte chunk and char chunk
bc.setOffset(bb.position());
cc.setEnd(cb.position());
// Put leftovers in the leftovers byte buffer
if (bc.getLength() > 0) {
leftovers.position(bc.getLength());
leftovers.limit(leftovers.array().length);
bc.substract(leftovers.array(), 0, bc.getLength());
}
}
}
示例14: close
import java.nio.charset.CoderResult; //导入方法依赖的package包/类
public void close() {
if (outputStream.getServletRequestContext().getOriginalRequest().getDispatcherType() == DispatcherType.INCLUDE) {
return;
}
if (closed) {
return;
}
closed = true;
try {
boolean done = false;
CharBuffer buffer;
if (underflow == null) {
buffer = CharBuffer.wrap(EMPTY_CHAR);
} else {
buffer = CharBuffer.wrap(underflow);
underflow = null;
}
if (charsetEncoder != null) {
do {
ByteBuffer out = outputStream.underlyingBuffer();
if (out == null) {
//servlet output stream has already been closed
error = true;
return;
}
CoderResult result = charsetEncoder.encode(buffer, out, true);
if (result.isOverflow()) {
outputStream.flushInternal();
if (out.remaining() == 0) {
outputStream.close();
error = true;
return;
}
} else {
done = true;
}
} while (!done);
}
outputStream.close();
} catch (IOException e) {
error = true;
}
}
示例15: convert
import java.nio.charset.CoderResult; //导入方法依赖的package包/类
/**
* Convert the given characters to bytes.
*
* @param cc
* char input
* @param bc
* byte output
*/
public void convert(CharChunk cc, ByteChunk bc) throws IOException {
if ((bb == null) || (bb.array() != bc.getBuffer())) {
// Create a new byte buffer if anything changed
bb = ByteBuffer.wrap(bc.getBuffer(), bc.getEnd(), bc.getBuffer().length - bc.getEnd());
} else {
// Initialize the byte buffer
bb.limit(bc.getBuffer().length);
bb.position(bc.getEnd());
}
if ((cb == null) || (cb.array() != cc.getBuffer())) {
// Create a new char buffer if anything changed
cb = CharBuffer.wrap(cc.getBuffer(), cc.getStart(), cc.getLength());
} else {
// Initialize the char buffer
cb.limit(cc.getEnd());
cb.position(cc.getStart());
}
CoderResult result = null;
// Parse leftover if any are present
if (leftovers.position() > 0) {
int pos = bb.position();
// Loop until one char is encoded or there is a encoder error
do {
leftovers.put((char) cc.substract());
leftovers.flip();
result = encoder.encode(leftovers, bb, false);
leftovers.position(leftovers.limit());
leftovers.limit(leftovers.array().length);
} while (result.isUnderflow() && (bb.position() == pos));
if (result.isError() || result.isMalformed()) {
result.throwException();
}
cb.position(cc.getStart());
leftovers.position(0);
}
// Do the decoding and get the results into the byte chunk and the char
// chunk
result = encoder.encode(cb, bb, false);
if (result.isError() || result.isMalformed()) {
result.throwException();
} else if (result.isOverflow()) {
// Propagate current positions to the byte chunk and char chunk
bc.setEnd(bb.position());
cc.setOffset(cb.position());
} else if (result.isUnderflow()) {
// Propagate current positions to the byte chunk and char chunk
bc.setEnd(bb.position());
cc.setOffset(cb.position());
// Put leftovers in the leftovers char buffer
if (cc.getLength() > 0) {
leftovers.limit(leftovers.array().length);
leftovers.position(cc.getLength());
cc.substract(leftovers.array(), 0, cc.getLength());
}
}
}