本文整理匯總了Java中java.nio.CharBuffer.arrayOffset方法的典型用法代碼示例。如果您正苦於以下問題:Java CharBuffer.arrayOffset方法的具體用法?Java CharBuffer.arrayOffset怎麽用?Java CharBuffer.arrayOffset使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.nio.CharBuffer
的用法示例。
在下文中一共展示了CharBuffer.arrayOffset方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: toStringInternal
import java.nio.CharBuffer; //導入方法依賴的package包/類
public String toStringInternal() {
if (charset == null) {
charset = DEFAULT_CHARSET;
}
// new String(byte[], int, int, Charset) takes a defensive copy of the
// entire byte array. This is expensive if only a small subset of the
// bytes will be used. The code below is from Apache Harmony.
CharBuffer cb;
cb = charset.decode(ByteBuffer.wrap(buff, start, end-start));
return new String(cb.array(), cb.arrayOffset(), cb.length());
}
示例2: 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);
try {
while (sp < sl) {
char c = sa[sp];
if (c < 0x80) {
if (dp >= dl)
return CoderResult.OVERFLOW;
da[dp] = (byte)c;
sp++; dp++;
continue;
}
if (sgp.parse(c, sa, sp, sl) < 0)
return sgp.error();
return sgp.unmappableResult();
}
return CoderResult.UNDERFLOW;
} finally {
src.position(sp - src.arrayOffset());
dst.position(dp - dst.arrayOffset());
}
}
示例3: 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();
CoderResult cr = CoderResult.UNDERFLOW;
if ((dl - dp) < (sl - sp)) {
sl = sp + (dl - dp);
cr = CoderResult.OVERFLOW;
}
while (sp < sl) {
char c = sa[sp];
int b = encode(c);
if (b == UNMAPPABLE_ENCODING) {
if (Character.isSurrogate(c)) {
if (sgp == null)
sgp = new Surrogate.Parser();
if (sgp.parse(c, sa, sp, sl) < 0)
return withResult(sgp.error(), src, sp, dst, dp);
return withResult(sgp.unmappableResult(), src, sp, dst, dp);
}
return withResult(CoderResult.unmappableForLength(1),
src, sp, dst, dp);
}
da[dp++] = (byte)b;
sp++;
}
return withResult(cr, src, sp, dst, dp);
}
示例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'&& 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());
}
}
示例5: encodeArrayLoop
import java.nio.CharBuffer; //導入方法依賴的package包/類
private CoderResult encodeArrayLoop(CharBuffer src,
ByteBuffer dst)
{
char[] sa = src.array();
int soff = src.arrayOffset();
int sp = soff + src.position();
int sl = soff + src.limit();
assert (sp <= sl);
sp = (sp <= sl ? sp : sl);
byte[] da = dst.array();
int doff = dst.arrayOffset();
int dp = doff + dst.position();
int dl = doff + dst.limit();
assert (dp <= dl);
dp = (dp <= dl ? dp : dl);
int dlen = dl - dp;
int slen = sl - sp;
int len = (dlen < slen) ? dlen : slen;
try {
int ret = encodeISOArray(sa, sp, da, dp, len);
sp = sp + ret;
dp = dp + ret;
if (ret != len) {
if (sgp.parse(sa[sp], sa, sp, sl) < 0)
return sgp.error();
return sgp.unmappableResult();
}
if (len < slen)
return CoderResult.OVERFLOW;
return CoderResult.UNDERFLOW;
} finally {
src.position(sp - soff);
dst.position(dp - doff);
}
}
示例6: 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());
}
}
示例7: 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());
}
}
示例8: 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 >= 0x2761){
da[dp++] = table[c - 0x2761]; // table lookup
} else {
da[dp++] = (byte)(c + 0x20 - 0x2700); // direct map
}
}
return CoderResult.UNDERFLOW;
} finally {
src.position(sp - src.arrayOffset());
dst.position(dp - dst.arrayOffset());
}
}
示例9: 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());
}
}
示例10: encodeArrayLoop
import java.nio.CharBuffer; //導入方法依賴的package包/類
protected 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();
try {
while (sp < sl) {
char c = sa[sp];
int bb = encodeChar(c);
if (bb == UNMAPPABLE_ENCODING) {
if (Character.isSurrogate(c)) {
if (sgp().parse(c, sa, sp, sl) < 0)
return sgp.error();
return sgp.unmappableResult();
}
return CoderResult.unmappableForLength(1);
}
if (bb > MAX_SINGLEBYTE) { // DoubleByte
if (currentState == SBCS) {
if (dl - dp < 1)
return CoderResult.OVERFLOW;
currentState = DBCS;
da[dp++] = SO;
}
if (dl - dp < 2)
return CoderResult.OVERFLOW;
da[dp++] = (byte)(bb >> 8);
da[dp++] = (byte)bb;
} else { // SingleByte
if (currentState == DBCS) {
if (dl - dp < 1)
return CoderResult.OVERFLOW;
currentState = SBCS;
da[dp++] = SI;
}
if (dl - dp < 1)
return CoderResult.OVERFLOW;
da[dp++] = (byte)bb;
}
sp++;
}
return CoderResult.UNDERFLOW;
} finally {
src.position(sp - src.arrayOffset());
dst.position(dp - dst.arrayOffset());
}
}
示例11: 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;
}
示例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 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());
}
}
示例13: encodeArrayLoop
import java.nio.CharBuffer; //導入方法依賴的package包/類
protected 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();
try {
while (sp < sl) {
char c = sa[sp];
int bb = encodeChar(c);
if (bb == UNMAPPABLE_ENCODING) {
if (Character.isSurrogate(c)) {
if (sgp().parse(c, sa, sp, sl) < 0)
return sgp.error();
return sgp.unmappableResult();
}
return CoderResult.unmappableForLength(1);
}
if (bb > MAX_SINGLEBYTE) { // DoubleByte
if (dl - dp < 2)
return CoderResult.OVERFLOW;
da[dp++] = (byte)(bb >> 8);
da[dp++] = (byte)bb;
} else { // SingleByte
if (dl - dp < 1)
return CoderResult.OVERFLOW;
da[dp++] = (byte)bb;
}
sp++;
}
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 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());
}
}
示例15: encodeArrayLoop
import java.nio.CharBuffer; //導入方法依賴的package包/類
protected 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();
try {
while (sp < sl) {
int db;
char c = sa[sp];
if (leftoverBase != 0) {
boolean isComp = false;
db = encodeComposite(leftoverBase, c);
if (db == UNMAPPABLE)
db = encodeChar(leftoverBase);
else
isComp = true;
if (dl - dp < 2)
return CoderResult.OVERFLOW;
da[dp++] = (byte)(db >> 8);
da[dp++] = (byte)db;
leftoverBase = 0;
if (isComp) {
sp++;
continue;
}
}
if (isCompositeBase(c)) {
leftoverBase = c;
} else {
db = encodeChar(c);
if (db <= MAX_SINGLEBYTE) { // SingleByte
if (dl <= dp)
return CoderResult.OVERFLOW;
da[dp++] = (byte)db;
} else if (db != UNMAPPABLE) { // DoubleByte
if (dl - dp < 2)
return CoderResult.OVERFLOW;
da[dp++] = (byte)(db >> 8);
da[dp++] = (byte)db;
} else if (Character.isHighSurrogate(c)) {
if ((sp + 1) == sl)
return CoderResult.UNDERFLOW;
char c2 = sa[sp + 1];
if (!Character.isLowSurrogate(c2))
return CoderResult.malformedForLength(1);
db = encodeSurrogate(c, c2);
if (db == UNMAPPABLE)
return CoderResult.unmappableForLength(2);
if (dl - dp < 2)
return CoderResult.OVERFLOW;
da[dp++] = (byte)(db >> 8);
da[dp++] = (byte)db;
sp++;
} else if (Character.isLowSurrogate(c)) {
return CoderResult.malformedForLength(1);
} else {
return CoderResult.unmappableForLength(1);
}
}
sp++;
}
return CoderResult.UNDERFLOW;
} finally {
src.position(sp - src.arrayOffset());
dst.position(dp - dst.arrayOffset());
}
}