本文整理匯總了Java中java.nio.CharBuffer.array方法的典型用法代碼示例。如果您正苦於以下問題:Java CharBuffer.array方法的具體用法?Java CharBuffer.array怎麽用?Java CharBuffer.array使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.nio.CharBuffer
的用法示例。
在下文中一共展示了CharBuffer.array方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: 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());
}
}
示例2: 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());
}
}
示例3: 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);
}
}
示例4: 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());
}
示例5: 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 b = sa[sp];
char c = decode(b);
if (c == '\uFFFD')
return CoderResult.unmappableForLength(1);
if (dl - dp < 1)
return CoderResult.OVERFLOW;
da[dp++] = c;
sp++;
}
return CoderResult.UNDERFLOW;
} finally {
src.position(sp - src.arrayOffset());
dst.position(dp - dst.arrayOffset());
}
}
示例6: 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 len = Math.min(dl - dp, sl - sp);
while (len-- > 0) {
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(sp < sl ? CoderResult.OVERFLOW : CoderResult.UNDERFLOW,
src, sp, dst, dp);
}
示例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();
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());
}
}
示例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) {
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());
}
}
示例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);
int b1 = 0, b2 = 0;
int inputSize = 0;
char outputChar = UNMAPPABLE_DECODING;
try {
while (sp < sl) {
b1 = sa[sp] & 0xff;
inputSize = 1;
if ((b1 & 0x80) == 0) {
outputChar = (char)b1;
} else { // Multibyte char
if (b1 == 0x8f) { // JIS0212
if (sp + 3 > sl)
return CoderResult.UNDERFLOW;
b1 = sa[sp + 1] & 0xff;
b2 = sa[sp + 2] & 0xff;
inputSize += 2;
if (dec0212 == null) // JIS02012 not supported
return CoderResult.unmappableForLength(inputSize);
outputChar = dec0212.decodeDouble(b1-0x80, b2-0x80);
} else { // JIS0201, JIS0208
if (sp + 2 > sl)
return CoderResult.UNDERFLOW;
b2 = sa[sp + 1] & 0xff;
inputSize++;
outputChar = decodeDouble(b1, b2);
}
}
if (outputChar == UNMAPPABLE_DECODING) { // can't be decoded
return CoderResult.unmappableForLength(inputSize);
}
if (dp + 1 > dl)
return CoderResult.OVERFLOW;
da[dp++] = outputChar;
sp += inputSize;
}
return CoderResult.UNDERFLOW;
} finally {
src.position(sp - src.arrayOffset());
dst.position(dp - dst.arrayOffset());
}
}
示例10: decodeArrayLoop
import java.nio.CharBuffer; //導入方法依賴的package包/類
protected 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_DECODING) {
if (sl - sp < 2)
return CoderResult.UNDERFLOW;
int b2 = sa[sp + 1] & 0xff;
inSize++;
if (b2 < b2Min || b2 > b2Max)
return CoderResult.unmappableForLength(2);
c = decodeDouble(b1, b2); //bmp
if (c == UNMAPPABLE_DECODING) {
c = decodeDoubleEx(b1, b2); //supp
if (c == UNMAPPABLE_DECODING) {
c = decodeBig5(b1, b2); //big5
if (c == UNMAPPABLE_DECODING)
return CoderResult.unmappableForLength(2);
} else {
// supplementary character in u+2xxxx area
outSize = 2;
}
}
}
if (dl - dp < outSize)
return CoderResult.OVERFLOW;
if (outSize == 2) {
// supplementary characters
da[dp++] = Surrogate.high(0x20000 + c);
da[dp++] = Surrogate.low(0x20000 + c);
} else {
da[dp++] = c;
}
sp += inSize;
}
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 outputSize = 0; // size of output
int spaceNeeded;
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 (currentState == DBCS && b1 == 0x00) {
if (dl - dp < 1)
return CoderResult.OVERFLOW;
currentState = SBCS;
da[dp++] = SI;
} else if (currentState == SBCS && b1 != 0x00) {
if (dl - dp < 1)
return CoderResult.OVERFLOW;
currentState = DBCS;
da[dp++] = SO;
}
if (currentState == DBCS)
spaceNeeded = 2;
else
spaceNeeded = 1;
if (dl - dp < spaceNeeded)
return CoderResult.OVERFLOW;
if (currentState == SBCS)
da[dp++] = b2;
else {
da[dp++] = b1;
da[dp++] = b2;
}
sp++;
}
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 v = 0;
char outputChar = REPLACE_CHAR;
if (b1 < 0)
b1 += 256;
if (!leadByte[b1])
{
outputChar = singleByteToChar.charAt(b1);
} else {
if (sl - sp < 2)
return CoderResult.UNDERFLOW;
b2 = sa[sp + 1];
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 == '\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: 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);
int b1 = 0, b2 = 0;
int inputSize = 0;
char outputChar = REPLACE_CHAR; // U+FFFD;
try {
while (sp < sl) {
b1 = sa[sp] & 0xff;
inputSize = 1;
if ((b1 & 0x80) == 0) {
outputChar = (char)b1;
}
else { // Multibyte char
if ((b1 & 0xff) == 0x8f) { // JIS0212
if (sp + 3 > sl)
return CoderResult.UNDERFLOW;
b1 = sa[sp + 1] & 0xff;
b2 = sa[sp + 2] & 0xff;
inputSize += 2;
outputChar = decode0212(b1-0x80, b2-0x80);
} else {
// JIS0208
if (sp + 2 > sl)
return CoderResult.UNDERFLOW;
b2 = sa[sp + 1] & 0xff;
inputSize++;
outputChar = decodeDouble(b1, b2);
}
}
if (outputChar == REPLACE_CHAR) { // can't be decoded
return CoderResult.unmappableForLength(inputSize);
}
if (dp + 1 > dl)
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 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包/類
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 < 6)
return overflow(src, sp, dst, dp);
to3Bytes(da, dp, Character.highSurrogate(uc));
dp += 3;
to3Bytes(da, dp, Character.lowSurrogate(uc));
dp += 3;
sp++; // 2 chars
} else {
// 3 bytes, 16 bits
if (dl - dp < 3)
return overflow(src, sp, dst, dp);
to3Bytes(da, dp, c);
dp += 3;
}
sp++;
}
updatePositions(src, sp, dst, dp);
return CoderResult.UNDERFLOW;
}