本文整理匯總了Java中java.nio.CharBuffer.limit方法的典型用法代碼示例。如果您正苦於以下問題:Java CharBuffer.limit方法的具體用法?Java CharBuffer.limit怎麽用?Java CharBuffer.limit使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.nio.CharBuffer
的用法示例。
在下文中一共展示了CharBuffer.limit方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getComputedChars
import java.nio.CharBuffer; //導入方法依賴的package包/類
/**
* Returns a UTF8 decoded <code>char[]</code> representation of the
* <code>byte[]</code> used to create this buffer.
*
* @return A char[]
*/
private char[] getComputedChars()
{
if ( computedChars == null )
{
CharBuffer charBuffer = UTF8.decode(
ByteBuffer.wrap( originalBytes, 0, originalBytes.length ) );
computedChars = new char[charBuffer.remaining()];
charBuffer.get( computedChars );
// clear out the temporary bytebuffer
charBuffer.flip();
char[] nullifier = new char[charBuffer.limit()];
Arrays.fill( nullifier, ( char ) 0 );
charBuffer.put( nullifier );
}
return computedChars;
}
示例2: decodeBytesForTests
import java.nio.CharBuffer; //導入方法依賴的package包/類
char[] decodeBytesForTests(final byte[] bytes) throws CharacterCodingException {
CharBuffer resultBuf = decode(ByteBuffer.wrap(bytes));
char[] resultBufArray = resultBuf.array();
int resultBufPos = resultBuf.limit();
if (resultBufPos == resultBufArray.length) {
return resultBufArray;
} else {
char[] result = new char[resultBufPos];
System.arraycopy(resultBufArray, 0, result, 0, resultBufPos);
return result;
}
}
示例3: grow
import java.nio.CharBuffer; //導入方法依賴的package包/類
/** Returns a new CharBuffer identical to buf, except twice the capacity. */
private static CharBuffer grow(CharBuffer buf) {
char[] copy = Arrays.copyOf(buf.array(), buf.capacity() * 2);
CharBuffer bigger = CharBuffer.wrap(copy);
bigger.position(buf.position());
bigger.limit(buf.limit());
return bigger;
}
示例4: 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;
}
int b1 = sa[sp] & 0xFF | 0x80;
int b2 = sa[sp + 1] & 0xFF | 0x80;
char c = decodeDouble(b1, b2);
if (c == UNMAPPABLE_DECODING) {
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());
}
}
示例5: randomizeRange
import java.nio.CharBuffer; //導入方法依賴的package包/類
/**
* Randomize the char buffer's position and limit.
*/
static CharBuffer randomizeRange(CharBuffer cb) {
int mid = cb.capacity() >>> 1;
int start = RAND.nextInt(mid);
int end = mid + RAND.nextInt(mid);
cb.position(start);
cb.limit(end);
return cb;
}
示例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();
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());
}
}
示例7: 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();
char[] da = dst.array();
int dp = dst.arrayOffset() + dst.position();
int dl = dst.arrayOffset() + dst.limit();
try {
while (sp < sl) {
if ( sl - sp < 2) {
return CoderResult.UNDERFLOW;
}
int b1 = (sa[sp] & 0xff) | 0x80;
int b2 = (sa[sp + 1] & 0xff) | 0x80;
char[] cc = toUnicode(b1, b2, plane);
// plane3 has non-bmp characters(added), x11cnsp3
// however does not support them
if (cc == null || cc.length == 2)
return CoderResult.unmappableForLength(2);
if (dl - dp < 1)
return CoderResult.OVERFLOW;
da[dp++] = cc[0];
sp +=2;
}
return CoderResult.UNDERFLOW;
} finally {
src.position(sp - src.arrayOffset());
dst.position(dp - dst.arrayOffset());
}
}
示例8: 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());
}
}
示例9: 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 (dp >= dl)
return CoderResult.OVERFLOW;
da[dp++] = (char)(b & 0xff);
sp++;
}
return CoderResult.UNDERFLOW;
} finally {
src.position(sp - src.arrayOffset());
dst.position(dp - dst.arrayOffset());
}
}
示例10: 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'&& c < '\uFFFE') {
int nb = toEUC(c, bb);
if (nb != -1) {
int p = 0;
if (nb == 4)
p = (bb[1] & 0xff) - 0xa0;
if (p == plane) {
if (dl - dp < 2)
return CoderResult.OVERFLOW;
if (nb == 2) {
da[dp++] = (byte)(bb[0] & 0x7f);
da[dp++] = (byte)(bb[1] & 0x7f);
} else {
da[dp++] = (byte)(bb[2] & 0x7f);
da[dp++] = (byte)(bb[3] & 0x7f);
}
sp++;
continue;
}
}
}
return CoderResult.unmappableForLength(1);
}
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();
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 byte1, byte2;
int inputSize = 1;
char outputChar = '\uFFFD';
byte1 = sa[sp] & 0xff;
if ( byte1 <= 0x9f ) { // < 0x9f has its own table (G0)
if (byte1 == SS2 || byte1 == SS3 ) {
// No support provided for G2/G3 at this time.
return CoderResult.malformedForLength(1);
}
outputChar = byteToCharTable.charAt(byte1);
} else if (byte1 < 0xa1 || byte1 > 0xfe) { // invalid range?
return CoderResult.malformedForLength(1);
} else { // (G1)
if (sl - sp < 2) {
return CoderResult.UNDERFLOW;
}
byte2 = sa[sp + 1] & 0xff;
inputSize++;
if ( byte2 < 0xa1 || byte2 > 0xfe) {
return CoderResult.malformedForLength(2);
}
outputChar = mappingTableG1.charAt(((byte1 - 0xa1) * 94) + byte2 - 0xa1);
}
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());
}
}
示例12: encodeArrayLoop
import java.nio.CharBuffer; //導入方法依賴的package包/類
private CoderResult encodeArrayLoop(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);
int outputSize = 0;
byte[] outputByte;
int inputSize = 0; // Size of input
byte[] tmpBuf = new byte[3];
try {
while (sp < sl) {
outputByte = tmpBuf;
char c = sa[sp];
if (Character.isSurrogate(c)) {
if (sgp.parse(c, sa, sp, sl) < 0)
return sgp.error();
return sgp.unmappableResult();
}
outputSize = encodeSingle(c, outputByte);
if (outputSize == 0) { // DoubleByte
int ncode = encodeDouble(c);
if (ncode != UNMAPPABLE_ENCODING) {
if ((ncode & 0xFF0000) == 0) {
outputByte[0] = (byte) ((ncode & 0xff00) >> 8);
outputByte[1] = (byte) (ncode & 0xff);
outputSize = 2;
} else {
outputByte[0] = (byte) 0x8f;
outputByte[1] = (byte) ((ncode & 0xff00) >> 8);
outputByte[2] = (byte) (ncode & 0xff);
outputSize = 3;
}
} else {
return CoderResult.unmappableForLength(1);
}
}
if (dl - dp < outputSize)
return CoderResult.OVERFLOW;
// Put the byte in the output buffer
for (int i = 0; i < outputSize; i++) {
da[dp++] = outputByte[i];
}
sp++;
}
return CoderResult.UNDERFLOW;
} finally {
src.position(sp - src.arrayOffset());
dst.position(dp - dst.arrayOffset());
}
}
示例13: 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 byte1, byte2;
int inputSize = 1;
char outputChar = '\uFFFD';
byte1 = sa[sp] & 0xff;
if (byte1 == SS2) {
if (sl - sp < 4) {
return CoderResult.UNDERFLOW;
}
byte1 = sa[sp + 1] & 0xff;
inputSize = 2;
if ( byte1 == 0xa2)
mappingTableG2 = mappingTableG2a2;
else if ( byte1 == 0xac)
mappingTableG2 = mappingTableG2ac;
else if ( byte1 == 0xad)
mappingTableG2 = mappingTableG2ad;
else
return CoderResult.malformedForLength(2);
byte1 = sa[sp + 2] & 0xff;
if ( byte1 < 0xa1 || byte1 > 0xfe) {
return CoderResult.malformedForLength(3);
}
byte2 = sa[sp + 3] & 0xff;
if ( byte2 < 0xa1 || byte2 > 0xfe) {
return CoderResult.malformedForLength(4);
}
inputSize = 4;
outputChar = mappingTableG2.charAt(((byte1 - 0xa1) * 94) + byte2 - 0xa1);
} else if(byte1 == SS3 ) {
return CoderResult.malformedForLength(1);
} 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 (sl - sp < 2) {
return CoderResult.UNDERFLOW;
}
byte2 = sa[sp + 1] & 0xff;
inputSize = 2;
if ( byte2 < 0xa1 || byte2 > 0xfe) {
return CoderResult.malformedForLength(2);
}
outputChar = mappingTableG1.charAt(((byte1 - 0xa1) * 94) + byte2 - 0xa1);
}
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());
}
}
示例14: encodeArrayLoop
import java.nio.CharBuffer; //導入方法依賴的package包/類
private CoderResult encodeArrayLoop(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();
int dlASCII = dp + Math.min(sl - sp, dl - dp);
// ASCII only loop
while (dp < dlASCII && sa[sp] < '\u0080')
da[dp++] = (byte) sa[sp++];
while (sp < sl) {
char c = sa[sp];
if (c < 0x80) {
// Have at most seven bits
if (dp >= dl)
return overflow(src, sp, dst, dp);
da[dp++] = (byte)c;
} else if (c < 0x800) {
// 2 bytes, 11 bits
if (dl - dp < 2)
return overflow(src, sp, dst, dp);
da[dp++] = (byte)(0xc0 | (c >> 6));
da[dp++] = (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, sa, sp, sl);
if (uc < 0) {
updatePositions(src, sp, dst, dp);
return sgp.error();
}
if (dl - dp < 4)
return overflow(src, sp, dst, dp);
da[dp++] = (byte)(0xf0 | ((uc >> 18)));
da[dp++] = (byte)(0x80 | ((uc >> 12) & 0x3f));
da[dp++] = (byte)(0x80 | ((uc >> 6) & 0x3f));
da[dp++] = (byte)(0x80 | (uc & 0x3f));
sp++; // 2 chars
} else {
// 3 bytes, 16 bits
if (dl - dp < 3)
return overflow(src, sp, dst, dp);
da[dp++] = (byte)(0xe0 | ((c >> 12)));
da[dp++] = (byte)(0x80 | ((c >> 6) & 0x3f));
da[dp++] = (byte)(0x80 | (c & 0x3f));
}
sp++;
}
updatePositions(src, sp, dst, dp);
return CoderResult.UNDERFLOW;
}
示例15: encodeArrayLoop
import java.nio.CharBuffer; //導入方法依賴的package包/類
private CoderResult encodeArrayLoop(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();
int outputSize = 0; // size of output
try {
while (sp < sl) {
int index;
int theBytes;
char c = sa[sp];
if (Surrogate.is(c)) {
if (sgp.parse(c, sa, sp, sl) < 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 (dl - dp < 1)
return CoderResult.OVERFLOW;
da[dp++] = (byte) b2;
} else {
if (dl - dp < 2)
return CoderResult.OVERFLOW;
da[dp++] = (byte) b1;
da[dp++] = (byte) b2;
}
sp++;
}
return CoderResult.UNDERFLOW;
} finally {
src.position(sp - src.arrayOffset());
dst.position(dp - dst.arrayOffset());
}
}