本文整理匯總了Java中java.nio.CharBuffer.position方法的典型用法代碼示例。如果您正苦於以下問題:Java CharBuffer.position方法的具體用法?Java CharBuffer.position怎麽用?Java CharBuffer.position使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.nio.CharBuffer
的用法示例。
在下文中一共展示了CharBuffer.position方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: decodeArrayLoop
import java.nio.CharBuffer; //導入方法依賴的package包/類
private CoderResult decodeArrayLoop(ByteBuffer src, CharBuffer dst) {
byte[] sa = src.array();
int sp = src.arrayOffset() + src.position();
int sl = src.arrayOffset() + src.limit();
char[] da = dst.array();
int dp = dst.arrayOffset() + dst.position();
int dl = dst.arrayOffset() + dst.limit();
CoderResult cr = CoderResult.UNDERFLOW;
if ((dl - dp) < (sl - sp)) {
sl = sp + (dl - dp);
cr = CoderResult.OVERFLOW;
}
while (sp < sl) {
char c = decode(sa[sp]);
if (c == UNMAPPABLE_DECODING) {
return withResult(CoderResult.unmappableForLength(1),
src, sp, dst, dp);
}
da[dp++] = c;
sp++;
}
return withResult(cr, src, sp, dst, dp);
}
示例2: 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);
}
}
示例3: encodeLoop
import java.nio.CharBuffer; //導入方法依賴的package包/類
protected CoderResult encodeLoop(CharBuffer src, ByteBuffer dst) {
char[] sa = src.array();
int sp = src.arrayOffset() + src.position();
int sl = src.arrayOffset() + src.limit();
byte[] da = dst.array();
int dp = dst.arrayOffset() + dst.position();
int dl = dst.arrayOffset() + dst.limit();
try {
while (sp < sl) {
char c = sa[sp];
if (c <= '\u007f')
return CoderResult.unmappableForLength(1);
int ncode = encodeDouble(c);
if (ncode != 0 && c != '\u0000' ) {
da[dp++] = (byte) ((ncode >> 8) & 0x7f);
da[dp++] = (byte) (ncode & 0x7f);
sp++;
continue;
}
return CoderResult.unmappableForLength(1);
}
return CoderResult.UNDERFLOW;
} finally {
src.position(sp - src.arrayOffset());
dst.position(dp - dst.arrayOffset());
}
}
示例4: encodeLoop
import java.nio.CharBuffer; //導入方法依賴的package包/類
protected CoderResult encodeLoop(CharBuffer src, ByteBuffer dst) {
char[] sa = src.array();
int sp = src.arrayOffset() + src.position();
int sl = src.arrayOffset() + src.limit();
byte[] da = dst.array();
int dp = dst.arrayOffset() + dst.position();
int dl = dst.arrayOffset() + dst.limit();
try {
while (sp < sl) {
char c = sa[sp];
if (c <= '\u007f')
return CoderResult.unmappableForLength(1);
int ncode = encodeDouble(c);
if (ncode != 0 && c != '\u0000' ) {
da[dp++] = (byte) ((ncode >> 8) & 0x7f);
da[dp++] = (byte) (ncode & 0x7f);
sp++;
continue;
}
return CoderResult.unmappableForLength(1);
}
return CoderResult.UNDERFLOW;
} finally {
src.position(sp - src.arrayOffset());
dst.position(dp - dst.arrayOffset());
}
}
示例5: parse
import java.nio.CharBuffer; //導入方法依賴的package包/類
public static final Object parse(byte[] input, int off, int len, CharsetDecoder charsetDecoder, int features) {
charsetDecoder.reset();
char[] chars = ThreadLocalCache.getChars((int) (((double) len) * ((double) charsetDecoder.maxCharsPerByte())));
ByteBuffer byteBuf = ByteBuffer.wrap(input, off, len);
CharBuffer charBuf = CharBuffer.wrap(chars);
IOUtils.decode(charsetDecoder, byteBuf, charBuf);
DefaultJSONParser parser = new DefaultJSONParser(chars, charBuf.position(), ParserConfig.getGlobalInstance(), features);
Object value = parser.parse();
parser.handleResovleTask(value);
parser.close();
return value;
}
示例6: encodeLoop
import java.nio.CharBuffer; //導入方法依賴的package包/類
protected CoderResult encodeLoop(CharBuffer src, ByteBuffer dst) {
char[] sa = src.array();
int sp = src.arrayOffset() + src.position();
int sl = src.arrayOffset() + src.limit();
assert (sp <= sl);
sp = (sp <= sl ? sp : sl);
byte[] da = dst.array();
int dp = dst.arrayOffset() + dst.position();
int dl = dst.arrayOffset() + dst.limit();
assert (dp <= dl);
dp = (dp <= dl ? dp : dl);
try {
while (sp < sl) {
char c = sa[sp];
if (dl - dp < 1)
return CoderResult.OVERFLOW;
if (!canEncode(c))
return CoderResult.unmappableForLength(1);
sp++;
if (c >= 0x2200 && c <= 0x22ef){
da[dp++] = table_math[c - 0x2200];
} else if (c >= 0x0391 && c <= 0x03d6) {
da[dp++]= table_greek[c - 0x0391];
}
}
return CoderResult.UNDERFLOW;
} finally {
src.position(sp - src.arrayOffset());
dst.position(dp - dst.arrayOffset());
}
}
示例7: decodeArrayLoop
import java.nio.CharBuffer; //導入方法依賴的package包/類
private CoderResult decodeArrayLoop(ByteBuffer src,
CharBuffer dst)
{
byte[] sa = src.array();
int sp = src.arrayOffset() + src.position();
int sl = src.arrayOffset() + src.limit();
assert (sp <= sl);
sp = (sp <= sl ? sp : sl);
char[] da = dst.array();
int dp = dst.arrayOffset() + dst.position();
int dl = dst.arrayOffset() + dst.limit();
assert (dp <= dl);
dp = (dp <= dl ? dp : dl);
try {
while (sp < sl) {
byte b = sa[sp];
if (b >= 0) {
if (dp >= dl)
return CoderResult.OVERFLOW;
da[dp++] = (char)b;
sp++;
continue;
}
return CoderResult.malformedForLength(1);
}
return CoderResult.UNDERFLOW;
} finally {
src.position(sp - src.arrayOffset());
dst.position(dp - dst.arrayOffset());
}
}
示例8: overflow
import java.nio.CharBuffer; //導入方法依賴的package包/類
private static CoderResult overflow(CharBuffer src, int mark) {
src.position(mark);
return CoderResult.OVERFLOW;
}
示例9: 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);
}
}
示例10: decodeArrayLoop
import java.nio.CharBuffer; //導入方法依賴的package包/類
private CoderResult decodeArrayLoop(ByteBuffer src, CharBuffer dst) {
byte[] sa = src.array();
int sp = src.arrayOffset() + src.position();
int sl = src.arrayOffset() + src.limit();
assert (sp <= sl);
sp = (sp <= sl ? sp : sl);
char[] da = dst.array();
int dp = dst.arrayOffset() + dst.position();
int dl = dst.arrayOffset() + dst.limit();
assert (dp <= dl);
dp = (dp <= dl ? dp : dl);
try {
while (sp < sl) {
int b1, b2;
b1 = sa[sp];
int inputSize = 1;
int v = 0;
char outputChar = REPLACE_CHAR;
if (b1 < 0)
b1 += 256;
if (b1 == SO) { // Shift out
// For SO characters - simply validate the state and if OK
// update the state and go to the next byte
if (currentState != SBCS)
return CoderResult.malformedForLength(1);
else
currentState = DBCS;
} else if (b1 == SI) {
// For SI characters - simply validate the state and if OK
// update the state and go to the next byte
if (currentState != DBCS) {
return CoderResult.malformedForLength(1);
} else {
currentState = SBCS;
}
} else {
if (currentState == SBCS) {
outputChar = singleByteToChar.charAt(b1);
} else {
if (sl - sp < 2)
return CoderResult.UNDERFLOW;
b2 = sa[sp + 1];
if (b2 < 0)
b2 += 256;
inputSize++;
// Check validity of dbcs ebcdic byte pair values
if ((b1 != 0x40 || b2 != 0x40) &&
(b2 < 0x41 || b2 > 0xfe)) {
return CoderResult.malformedForLength(2);
}
// Lookup in the two level index
v = b1 * 256 + b2;
outputChar = index2.charAt(index1[((v & mask1) >> shift)]
+ (v & mask2));
}
if (outputChar == '\uFFFD')
return CoderResult.unmappableForLength(inputSize);
if (dl - dp < 1)
return CoderResult.OVERFLOW;
da[dp++] = outputChar;
}
sp += inputSize;
}
return CoderResult.UNDERFLOW;
} finally {
src.position(sp - src.arrayOffset());
dst.position(dp - dst.arrayOffset());
}
}
示例11: decodeArrayLoop
import java.nio.CharBuffer; //導入方法依賴的package包/類
private CoderResult decodeArrayLoop(ByteBuffer src, CharBuffer dst) {
byte[] sa = src.array();
int sp = src.arrayOffset() + src.position();
int sl = src.arrayOffset() + src.limit();
char[] da = dst.array();
int dp = dst.arrayOffset() + dst.position();
int dl = dst.arrayOffset() + dst.limit();
try {
while (sp < sl) {
int b1 = sa[sp] & 0xff;
char c = decodeSingle(b1);
int inSize = 1, outSize = 1;
char[] cc = null;
if (c == UNMAPPABLE) {
if (sl - sp < 2)
return CoderResult.UNDERFLOW;
int b2 = sa[sp + 1] & 0xff;
c = decodeDouble(b1, b2);
inSize++;
if (c == UNMAPPABLE) {
cc = decodeDoubleEx(b1, b2);
if (cc == null) {
if (decodeSingle(b2) == UNMAPPABLE)
return CoderResult.unmappableForLength(2);
else
return CoderResult.unmappableForLength(1);
}
outSize++;
}
}
if (dl - dp < outSize)
return CoderResult.OVERFLOW;
if (outSize == 2) {
da[dp++] = cc[0];
da[dp++] = cc[1];
} else {
da[dp++] = c;
}
sp += inSize;
}
return CoderResult.UNDERFLOW;
} finally {
src.position(sp - src.arrayOffset());
dst.position(dp - dst.arrayOffset());
}
}
示例12: decodeArrayLoop
import java.nio.CharBuffer; //導入方法依賴的package包/類
private CoderResult decodeArrayLoop(ByteBuffer src, CharBuffer dst) {
byte[] sa = src.array();
int sp = src.arrayOffset() + src.position();
int sl = src.arrayOffset() + src.limit();
assert (sp <= sl);
sp = (sp <= sl ? sp : sl);
char[] da = dst.array();
int dp = dst.arrayOffset() + dst.position();
int dl = dst.arrayOffset() + dst.limit();
assert (dp <= dl);
dp = (dp <= dl ? dp : dl);
try {
while (sp < sl) {
int b1, b2;
b1 = sa[sp];
int inputSize = 1;
int outputSize = 1;
highSurrogate = lowSurrogate = 0;
char c = decodeSingle(b1);
if (c == REPLACE_CHAR) {
b1 &= 0xff;
if (sl - sp < 2)
return CoderResult.UNDERFLOW;
b2 = sa[sp + 1] & 0xff;
c = decodeDouble(b1, b2);
inputSize = 2;
if (c == REPLACE_CHAR)
return CoderResult.unmappableForLength(inputSize);
outputSize = (highSurrogate > 0) ? 2: 1;
}
if (dl - dp < outputSize)
return CoderResult.OVERFLOW;
if (outputSize == 2) {
da[dp++] = highSurrogate;
da[dp++] = lowSurrogate;
} else {
da[dp++] = c;
}
sp += inputSize;
}
return CoderResult.UNDERFLOW;
} finally {
src.position(sp - src.arrayOffset());
dst.position(dp - dst.arrayOffset());
}
}
示例13: 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);
}
}
示例14: parse
import java.nio.CharBuffer; //導入方法依賴的package包/類
public static final Object parse(byte[] input, int off, int len, CharsetDecoder charsetDecoder, int features) {
charsetDecoder.reset();
int scaleLength = (int) (len * (double) charsetDecoder.maxCharsPerByte());
char[] chars = ThreadLocalCache.getChars(scaleLength);
ByteBuffer byteBuf = ByteBuffer.wrap(input, off, len);
CharBuffer charBuf = CharBuffer.wrap(chars);
IOUtils.decode(charsetDecoder, byteBuf, charBuf);
int position = charBuf.position();
DefaultJSONParser parser = new DefaultJSONParser(chars, position, ParserConfig.getGlobalInstance(), features);
Object value = parser.parse();
parser.handleResovleTask(value);
parser.close();
return value;
}
示例15: decodeLoop
import java.nio.CharBuffer; //導入方法依賴的package包/類
protected CoderResult decodeLoop(ByteBuffer src, CharBuffer dst) {
byte[] sa = src.array();
int sp = src.arrayOffset() + src.position();
int sl = src.arrayOffset() + src.limit();
assert (sp <= sl);
sp = (sp <= sl ? sp : sl);
char[] da = dst.array();
int dp = dst.arrayOffset() + dst.position();
int dl = dst.arrayOffset() + dst.limit();
assert (dp <= dl);
dp = (dp <= dl ? dp : dl);
try {
while (sp < sl) {
if ( sl - sp < 2) {
return CoderResult.UNDERFLOW;
}
byte b1 = sa[sp];
byte b2 = sa[sp + 1];
char c = replacement().charAt(0);
if (table == unicodeCNS3) {
char[] cc = convToSurrogate((byte)(b1 | 0x80),
(byte)(b2 | 0x80),
table);
if (cc != null && cc[0] == '\u0000')
c = cc[1];
} else {
c = convToUnicode((byte)(b1 | 0x80),
(byte)(b2 | 0x80),
table);
}
if (c == replacement().charAt(0)
//to keep the compatibility with b2cX11CNS11643
/*|| c == '\u0000'*/) {
return CoderResult.unmappableForLength(2);
}
if (dl - dp < 1)
return CoderResult.OVERFLOW;
da[dp++] = c;
sp +=2;
}
return CoderResult.UNDERFLOW;
} finally {
src.position(sp - src.arrayOffset());
dst.position(dp - dst.arrayOffset());
}
}