本文整理匯總了Java中java.nio.CharBuffer.hasRemaining方法的典型用法代碼示例。如果您正苦於以下問題:Java CharBuffer.hasRemaining方法的具體用法?Java CharBuffer.hasRemaining怎麽用?Java CharBuffer.hasRemaining使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.nio.CharBuffer
的用法示例。
在下文中一共展示了CharBuffer.hasRemaining方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: decodeBufferLoop
import java.nio.CharBuffer; //導入方法依賴的package包/類
protected CoderResult decodeBufferLoop(ByteBuffer src, CharBuffer dst) {
int mark = src.position();
try {
while (src.hasRemaining() && dst.hasRemaining()) {
int b1 = src.get() & 0xff;
char c = b2cSB[b1];
int inSize = 1;
if (c == UNMAPPABLE_DECODING) {
if (src.remaining() < 1)
return crMalformedOrUnderFlow(b1);
int b2 = src.get() & 0xff;
if (b2 < b2Min || b2 > b2Max ||
(c = b2c[b1][b2 - b2Min]) == UNMAPPABLE_DECODING)
return crMalformedOrUnmappable(b1, b2);
inSize++;
}
dst.put(c);
mark += inSize;
}
return src.hasRemaining()? CoderResult.OVERFLOW
: CoderResult.UNDERFLOW;
} finally {
src.position(mark);
}
}
示例2: decodeBufferLoop
import java.nio.CharBuffer; //導入方法依賴的package包/類
private CoderResult decodeBufferLoop(ByteBuffer src,
CharBuffer dst)
{
int mark = src.position();
try {
while (src.hasRemaining()) {
byte b = src.get();
if (!dst.hasRemaining())
return CoderResult.OVERFLOW;
dst.put((char)(b & 0xff));
mark++;
}
return CoderResult.UNDERFLOW;
} finally {
src.position(mark);
}
}
示例3: decodeBufferLoop
import java.nio.CharBuffer; //導入方法依賴的package包/類
private CoderResult decodeBufferLoop(ByteBuffer src,
CharBuffer dst)
{
int mark = src.position();
try {
while (src.hasRemaining()) {
byte b = src.get();
if (b >= 0) {
if (!dst.hasRemaining())
return CoderResult.OVERFLOW;
dst.put((char)b);
mark++;
continue;
}
return CoderResult.malformedForLength(1);
}
return CoderResult.UNDERFLOW;
} finally {
src.position(mark);
}
}
示例4: doWriteText
import java.nio.CharBuffer; //導入方法依賴的package包/類
private void doWriteText(CharBuffer buffer, boolean finalFragment)
throws IOException {
CharsetEncoder encoder = B2CConverter.UTF_8.newEncoder();
do {
CoderResult cr = encoder.encode(buffer, bb, true);
if (cr.isError()) {
cr.throwException();
}
bb.flip();
if (buffer.hasRemaining()) {
doWriteBytes(bb, false);
} else {
doWriteBytes(bb, finalFragment);
}
} while (buffer.hasRemaining());
// Reset - bb will be cleared in doWriteBytes()
cb.clear();
}
示例5: decodeBufferLoop
import java.nio.CharBuffer; //導入方法依賴的package包/類
private CoderResult decodeBufferLoop(ByteBuffer src, CharBuffer dst) {
int mark = src.position();
try {
while (src.remaining() > 1) {
int b1 = src.get() & 0xff;
int b2 = src.get() & 0xff;
if (!isValidDoubleByte(b1, b2)) {
return CoderResult.malformedForLength(2);
}
// Lookup in the two level index
int v = b1 * 256 + b2;
char outputChar = index2.charAt(index1[((v & mask1) >> shift)]
+ (v & mask2));
if (outputChar == REPLACE_CHAR)
return CoderResult.unmappableForLength(2);
if (!dst.hasRemaining())
return CoderResult.OVERFLOW;
dst.put(outputChar);
mark += 2;
}
return CoderResult.UNDERFLOW;
} finally {
src.position(mark);
}
}
示例6: encodeBufferLoop
import java.nio.CharBuffer; //導入方法依賴的package包/類
protected CoderResult encodeBufferLoop(CharBuffer src, ByteBuffer dst) {
int mark = src.position();
try {
while (src.hasRemaining()) {
int inSize = 1;
char c = src.get();
int bb = encodeChar(c);
if (bb == UNMAPPABLE_ENCODING) {
if (Character.isSurrogate(c)) {
int cp;
if ((cp = sgp().parse(c, src)) < 0)
return sgp.error();
bb = encodeSupp(cp);
if (bb == UNMAPPABLE_ENCODING)
return CoderResult.unmappableForLength(2);
inSize = 2;
} else {
return CoderResult.unmappableForLength(1);
}
}
if (bb > MAX_SINGLEBYTE) { // DoubleByte
if (dst.remaining() < 2)
return CoderResult.OVERFLOW;
dst.put((byte)(bb >> 8));
dst.put((byte)(bb));
} else {
if (dst.remaining() < 1)
return CoderResult.OVERFLOW;
dst.put((byte)bb);
}
mark += inSize;
}
return CoderResult.UNDERFLOW;
} finally {
src.position(mark);
}
}
示例7: encodeLoop
import java.nio.CharBuffer; //導入方法依賴的package包/類
protected CoderResult encodeLoop(CharBuffer src, ByteBuffer dst) {
int mark = src.position();
if (!doneBOM && src.hasRemaining()) {
if (dst.remaining() < 4)
return CoderResult.OVERFLOW;
put(BOM_BIG, dst);
doneBOM = true;
}
try {
while (src.hasRemaining()) {
char c = src.get();
if (!Character.isSurrogate(c)) {
if (dst.remaining() < 4)
return CoderResult.OVERFLOW;
mark++;
put(c, dst);
} else if (Character.isHighSurrogate(c)) {
if (!src.hasRemaining())
return CoderResult.UNDERFLOW;
char low = src.get();
if (Character.isLowSurrogate(low)) {
if (dst.remaining() < 4)
return CoderResult.OVERFLOW;
mark += 2;
put(Character.toCodePoint(c, low), dst);
} else {
return CoderResult.malformedForLength(1);
}
} else {
// assert Character.isLowSurrogate(c);
return CoderResult.malformedForLength(1);
}
}
return CoderResult.UNDERFLOW;
} finally {
src.position(mark);
}
}
示例8: encodeBufferLoop
import java.nio.CharBuffer; //導入方法依賴的package包/類
private CoderResult encodeBufferLoop(CharBuffer src, ByteBuffer dst) {
int mark = src.position();
int outputSize = 0; // size of output
try {
while (src.hasRemaining()) {
int index;
int theBytes;
char c = src.get();
if (Surrogate.is(c)) {
if (sgp.parse(c, src) < 0)
return sgp.error();
return sgp.unmappableResult();
}
if (c >= '\uFFFE')
return CoderResult.unmappableForLength(1);
index = index1[((c & mask1) >> shift)]
+ (c & mask2);
if (index < 15000)
theBytes = (int)(index2.charAt(index));
else
theBytes = (int)(index2a.charAt(index-15000));
b1 = (byte)((theBytes & 0x0000ff00)>>8);
b2 = (byte)(theBytes & 0x000000ff);
if (b1 == 0x00 && b2 == 0x00
&& c != '\u0000') {
return CoderResult.unmappableForLength(1);
}
if (b1 == 0) {
if (dst.remaining() < 1)
return CoderResult.OVERFLOW;
dst.put((byte) b2);
} else {
if (dst.remaining() < 2)
return CoderResult.OVERFLOW;
dst.put((byte) b1);
dst.put((byte) b2);
}
mark++;
}
return CoderResult.UNDERFLOW;
} finally {
src.position(mark);
}
}
示例9: decodeBufferLoop
import java.nio.CharBuffer; //導入方法依賴的package包/類
private CoderResult decodeBufferLoop(ByteBuffer src, CharBuffer dst) {
int mark = src.position();
try {
while (src.hasRemaining()) {
char outputChar = REPLACE_CHAR;
int inputSize = 1;
int b1, b2;
int v = 0;
b1 = src.get();
if (b1 < 0)
b1 += 256;
if (!leadByte[b1])
{
outputChar = singleByteToChar.charAt(b1);
} else {
if (src.remaining() < 1)
return CoderResult.UNDERFLOW;
b2 = src.get();
if (b2 < 0)
b2 += 256;
inputSize++;
// Lookup in the two level index
v = b1 * 256 + b2;
outputChar = index2.charAt(index1[((v & mask1) >> shift)]
+ (v & mask2));
}
if (outputChar == REPLACE_CHAR)
return CoderResult.unmappableForLength(inputSize);
if (!dst.hasRemaining())
return CoderResult.OVERFLOW;
mark += inputSize;
dst.put(outputChar);
}
return CoderResult.UNDERFLOW;
} finally {
src.position(mark);
}
}
示例10: decodeBufferLoop
import java.nio.CharBuffer; //導入方法依賴的package包/類
private CoderResult decodeBufferLoop(ByteBuffer src, CharBuffer dst) {
int mark = src.position();
try {
while (src.hasRemaining()) {
int byte1, byte2;
int inputSize = 1;
char outputChar = '\uFFFD';
byte1 = src.get() & 0xff;
if (byte1 == SS2) {
if (!src.hasRemaining())
return CoderResult.UNDERFLOW;
byte1 = src.get() & 0xff;
inputSize = 2;
if ( byte1 < 0xa1 || byte1 > 0xfe) { //valid first byte for G2
return CoderResult.malformedForLength(2);
}
outputChar = mappingTableG2.charAt(byte1 - 0xa1);
} else if (byte1 == SS3 ) { //G3
if (src.remaining() < 2)
return CoderResult.UNDERFLOW;
byte1 = src.get() & 0xff;
if ( byte1 < 0xa1 || byte1 > 0xfe) {
return CoderResult.malformedForLength(2);
}
byte2 = src.get() & 0xff;
if ( byte2 < 0xa1 || byte2 > 0xfe) {
return CoderResult.malformedForLength(3);
}
inputSize = 3;
outputChar = mappingTableG3.charAt(((byte1 - 0xa1) * 94) + byte2 - 0xa1);
} else if ( byte1 <= 0x9f ) { // valid single byte
outputChar = byteToCharTable.charAt(byte1);
} else if (byte1 < 0xa1 || byte1 > 0xfe) { // invalid range?
return CoderResult.malformedForLength(1);
} else { // G1
if (src.remaining() < 1)
return CoderResult.UNDERFLOW;
byte2 = src.get() & 0xff;
if ( byte2 < 0xa1 || byte2 > 0xfe) {
return CoderResult.malformedForLength(2);
}
inputSize = 2;
outputChar = mappingTableG1.charAt(((byte1 - 0xa1) * 94) + byte2 - 0xa1);
}
if (outputChar == '\uFFFD')
return CoderResult.unmappableForLength(inputSize);
if (!dst.hasRemaining())
return CoderResult.OVERFLOW;
dst.put(outputChar);
mark += inputSize;
}
return CoderResult.UNDERFLOW;
} finally {
src.position(mark);
}
}
示例11: encodeBufferLoop
import java.nio.CharBuffer; //導入方法依賴的package包/類
private CoderResult encodeBufferLoop(CharBuffer src,
ByteBuffer dst)
{
int mark = src.position();
while (src.hasRemaining()) {
char c = src.get();
if (c < 0x80) {
// Have at most seven bits
if (!dst.hasRemaining())
return overflow(src, mark);
dst.put((byte)c);
} else if (c < 0x800) {
// 2 bytes, 11 bits
if (dst.remaining() < 2)
return overflow(src, mark);
dst.put((byte)(0xc0 | (c >> 6)));
dst.put((byte)(0x80 | (c & 0x3f)));
} else if (Character.isSurrogate(c)) {
// Have a surrogate pair
if (sgp == null)
sgp = new Surrogate.Parser();
int uc = sgp.parse(c, src);
if (uc < 0) {
src.position(mark);
return sgp.error();
}
if (dst.remaining() < 6)
return overflow(src, mark);
to3Bytes(dst, Character.highSurrogate(uc));
to3Bytes(dst, Character.lowSurrogate(uc));
mark++; // 2 chars
} else {
// 3 bytes, 16 bits
if (dst.remaining() < 3)
return overflow(src, mark);
to3Bytes(dst, c);
}
mark++;
}
src.position(mark);
return CoderResult.UNDERFLOW;
}
示例12: encodeBufferLoop
import java.nio.CharBuffer; //導入方法依賴的package包/類
private CoderResult encodeBufferLoop(CharBuffer src,
ByteBuffer dst)
{
int mark = src.position();
try {
char inputChar;
while (src.hasRemaining()) {
int index = Integer.MIN_VALUE;
inputChar = src.get();
if (inputChar >= 0x0000 && inputChar <= 0x007f) {
if (dst.remaining() < 1)
return CoderResult.OVERFLOW;
dst.put((byte) inputChar);
mark++;
continue;
}
// if inputChar == ZWJ replace it with halant
// if inputChar == ZWNJ replace it with Nukta
if (inputChar == 0x200c) {
inputChar = HALANT_CHAR;
}
else if (inputChar == 0x200d) {
inputChar = NUKTA_CHAR;
}
if (inputChar >= 0x0900 && inputChar <= 0x097f) {
index = ((int)(inputChar) - 0x0900)*2;
}
if (Character.isSurrogate(inputChar)) {
if (sgp.parse(inputChar, src) < 0)
return sgp.error();
return sgp.unmappableResult();
}
if (index == Integer.MIN_VALUE ||
encoderMappingTable[index] == NO_CHAR) {
return CoderResult.unmappableForLength(1);
} else {
if(encoderMappingTable[index + 1] == NO_CHAR) {
if(dst.remaining() < 1)
return CoderResult.OVERFLOW;
dst.put(encoderMappingTable[index]);
} else {
if(dst.remaining() < 2)
return CoderResult.OVERFLOW;
dst.put(encoderMappingTable[index]);
dst.put(encoderMappingTable[index + 1]);
}
}
mark++;
}
return CoderResult.UNDERFLOW;
} finally {
src.position(mark);
}
}
示例13: encodeBufferLoop
import java.nio.CharBuffer; //導入方法依賴的package包/類
private CoderResult encodeBufferLoop(CharBuffer src, ByteBuffer dst) {
int index;
int spaceNeeded;
int i;
int mark = src.position();
try {
while (src.hasRemaining()) {
char inputChar = src.get();
boolean allZeroes = true;
if (Character.isSurrogate(inputChar)) {
if (sgp.parse(inputChar, src) < 0)
return sgp.error();
return sgp.unmappableResult();
}
if (inputChar >= '\uFFFE')
return CoderResult.unmappableForLength(1);
String theChars;
char aChar;
// We have a valid character, get the bytes for it
index = index1[((inputChar & mask1) >> shift)] + (inputChar & mask2);
if (index < 7500)
theChars = index2;
else if (index < 15000) {
index = index - 7500;
theChars = index2a;
} else if (index < 22500){
index = index - 15000;
theChars = index2b;
}
else {
index = index - 22500;
theChars = index2c;
}
aChar = theChars.charAt(2*index);
outputByte[0] = (byte)((aChar & 0xff00)>>8);
outputByte[1] = (byte)(aChar & 0x00ff);
aChar = theChars.charAt(2*index + 1);
outputByte[2] = (byte)((aChar & 0xff00)>>8);
outputByte[3] = (byte)(aChar & 0x00ff);
for (i = 0; i < outputByte.length; i++) {
if (outputByte[i] != 0x00) {
allZeroes = false;
break;
}
}
if (allZeroes && inputChar != '\u0000') {
return CoderResult.unmappableForLength(1);
}
int oindex = 0;
for (spaceNeeded = outputByte.length;
spaceNeeded > 1; spaceNeeded--){
if (outputByte[oindex++] != 0x00 )
break;
}
if (dst.remaining() < spaceNeeded)
return CoderResult.OVERFLOW;
for (i = outputByte.length - spaceNeeded;
i < outputByte.length; i++) {
dst.put(outputByte[i]);
}
mark++;
}
return CoderResult.UNDERFLOW;
} finally {
src.position(mark);
}
}
示例14: encodeBufferLoop
import java.nio.CharBuffer; //導入方法依賴的package包/類
private CoderResult encodeBufferLoop(CharBuffer src,
ByteBuffer dst)
{
int mark = src.position();
while (src.hasRemaining()) {
char c = src.get();
if (c < 0x80) {
// Have at most seven bits
if (!dst.hasRemaining())
return overflow(src, mark);
dst.put((byte)c);
} else if (c < 0x800) {
// 2 bytes, 11 bits
if (dst.remaining() < 2)
return overflow(src, mark);
dst.put((byte)(0xc0 | (c >> 6)));
dst.put((byte)(0x80 | (c & 0x3f)));
} else if (Character.isSurrogate(c)) {
// Have a surrogate pair
if (sgp == null)
sgp = new Surrogate.Parser();
int uc = sgp.parse(c, src);
if (uc < 0) {
src.position(mark);
return sgp.error();
}
if (dst.remaining() < 4)
return overflow(src, mark);
dst.put((byte)(0xf0 | ((uc >> 18))));
dst.put((byte)(0x80 | ((uc >> 12) & 0x3f)));
dst.put((byte)(0x80 | ((uc >> 6) & 0x3f)));
dst.put((byte)(0x80 | (uc & 0x3f)));
mark++; // 2 chars
} else {
// 3 bytes, 16 bits
if (dst.remaining() < 3)
return overflow(src, mark);
dst.put((byte)(0xe0 | ((c >> 12))));
dst.put((byte)(0x80 | ((c >> 6) & 0x3f)));
dst.put((byte)(0x80 | (c & 0x3f)));
}
mark++;
}
src.position(mark);
return CoderResult.UNDERFLOW;
}
示例15: flushEncodingCharBuffer
import java.nio.CharBuffer; //導入方法依賴的package包/類
private static void flushEncodingCharBuffer(
StringBuilder builder,
CharsetEncoder encoder,
CharBuffer cBuffer) {
if (cBuffer.position() == 0) {
return;
}
// We are reading from the buffer now.
cBuffer.flip();
ByteBuffer byteBuffer = ByteBuffer.allocate(
cBuffer.remaining() * (int) Math.ceil(encoder.maxBytesPerChar()));
byteBuffer.position(0);
CoderResult result = encoder.encode(cBuffer, byteBuffer, true /* endOfInput */);
// According to the {@code CharsetEncoder#encode} spec, the method returns underflow
// and leaves an empty output when all bytes were processed correctly.
if (result != CoderResult.UNDERFLOW) {
throw new IllegalArgumentException(
"Error encoding, unexpected result ["
+ result.toString()
+ "] using encoder for ["
+ encoder.charset().name()
+ "]");
}
if (cBuffer.hasRemaining()) {
throw new IllegalArgumentException(
"Encoder for [" + encoder.charset().name() + "] failed with underflow with "
+ "remaining input [" + cBuffer + "]");
}
// Need to flush in case the encoder saves internal state.
encoder.flush(byteBuffer);
if (result != CoderResult.UNDERFLOW) {
throw new IllegalArgumentException(
"Error encoding, unexpected result ["
+ result.toString()
+ "] flushing encoder for ["
+ encoder.charset().name()
+ "]");
}
encoder.reset();
byteBuffer.flip();
// Write the encoded bytes.
while(byteBuffer.hasRemaining()) {
byte b = byteBuffer.get();
builder.append('%');
builder.append(intToHexDigit((b & 0xf0) >>> 4));
builder.append(intToHexDigit(b & 0x0f));
}
// Use the character buffer to write again.
cBuffer.flip();
cBuffer.limit(cBuffer.capacity());
}