Java Code Examples for java.nio.CharBuffer#limit()
The following examples show how to use
java.nio.CharBuffer#limit() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SingleByteDecoder.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 5 votes |
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()); } }
Example 2
Source File: DoubleByte.java From jdk8u_jdk with GNU General Public License v2.0 | 5 votes |
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 && dp < dl) { // inline the decodeSingle/Double() for better performance int inSize = 1; int b1 = sa[sp] & 0xff; char c = b2cSB[b1]; if (c == UNMAPPABLE_DECODING) { if (sl - sp < 2) return crMalformedOrUnderFlow(b1); int b2 = sa[sp + 1] & 0xff; if (b2 < b2Min || b2 > b2Max || (c = b2c[b1][b2 - b2Min]) == UNMAPPABLE_DECODING) { return crMalformedOrUnmappable(b1, b2); } inSize++; } da[dp++] = c; sp += inSize; } return (sp >= sl) ? CoderResult.UNDERFLOW : CoderResult.OVERFLOW; } finally { src.position(sp - src.arrayOffset()); dst.position(dp - dst.arrayOffset()); } }
Example 3
Source File: US_ASCII.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
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()); } }
Example 4
Source File: DiagnosticSource.java From hottub with GNU General Public License v2.0 | 5 votes |
protected char[] initBuf(JavaFileObject fileObject) throws IOException { char[] buf; CharSequence cs = fileObject.getCharContent(true); if (cs instanceof CharBuffer) { CharBuffer cb = (CharBuffer) cs; buf = JavacFileManager.toArray(cb); bufLen = cb.limit(); } else { buf = cs.toString().toCharArray(); bufLen = buf.length; } refBuf = new SoftReference<char[]>(buf); return buf; }
Example 5
Source File: X11KSC5601.java From openjdk-jdk9 with GNU General Public License v2.0 | 5 votes |
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()); } }
Example 6
Source File: X11GB2312_OLD.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
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()); } }
Example 7
Source File: DoubleByteDecoder.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 4 votes |
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()); } }
Example 8
Source File: DoubleByte.java From openjdk-8 with GNU General Public License v2.0 | 4 votes |
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 { // don't check dp/dl together here, it's possible to // decdoe a SO/SI without space in output buffer. while (sp < sl) { int b1 = sa[sp] & 0xff; int inSize = 1; if (b1 == SO) { // Shift out if (currentState != SBCS) return CoderResult.malformedForLength(1); else currentState = DBCS; } else if (b1 == SI) { if (currentState != DBCS) return CoderResult.malformedForLength(1); else currentState = SBCS; } else { char c = UNMAPPABLE_DECODING; if (currentState == SBCS) { c = b2cSB[b1]; if (c == UNMAPPABLE_DECODING) return CoderResult.unmappableForLength(1); } else { if (sl - sp < 2) return CoderResult.UNDERFLOW; int b2 = sa[sp + 1] & 0xff; if (b2 < b2Min || b2 > b2Max || (c = b2c[b1][b2 - b2Min]) == UNMAPPABLE_DECODING) { if (!isDoubleByte(b1, b2)) return CoderResult.malformedForLength(2); return CoderResult.unmappableForLength(2); } inSize++; } if (dl - dp < 1) return CoderResult.OVERFLOW; da[dp++] = c; } sp += inSize; } return CoderResult.UNDERFLOW; } finally { src.position(sp - src.arrayOffset()); dst.position(dp - dst.arrayOffset()); } }
Example 9
Source File: DoubleByte.java From dragonwell8_jdk with GNU General Public License v2.0 | 4 votes |
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()); } }
Example 10
Source File: EUC_TW.java From openjdk-8 with GNU General Public License v2.0 | 4 votes |
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 inSize; int outSize; try { while (sp < sl) { char c = sa[sp]; inSize = 1; if (c < 0x80) { // ASCII bb[0] = (byte)c; outSize = 1; } else { outSize = toEUC(c, bb); if (outSize == -1) { // to check surrogates only after BMP failed // has the benefit of improving the BMP encoding // 10% faster, with the price of the slowdown of // supplementary character encoding. given the use // of supplementary characters is really rare, this // is something worth doing. if (Character.isHighSurrogate(c)) { if ((sp + 1) == sl) return CoderResult.UNDERFLOW; if (!Character.isLowSurrogate(sa[sp + 1])) return CoderResult.malformedForLength(1); outSize = toEUC(c, sa[sp+1], bb); inSize = 2; } else if (Character.isLowSurrogate(c)) { return CoderResult.malformedForLength(1); } } } if (outSize == -1) return CoderResult.unmappableForLength(inSize); if ( dl - dp < outSize) return CoderResult.OVERFLOW; for (int i = 0; i < outSize; i++) da[dp++] = bb[i]; sp += inSize; } return CoderResult.UNDERFLOW; } finally { src.position(sp - src.arrayOffset()); dst.position(dp - dst.arrayOffset()); } }
Example 11
Source File: UTF_8.java From jdk8u-jdk with GNU General Public License v2.0 | 4 votes |
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; }
Example 12
Source File: X11CNS11643.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 4 votes |
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()); } }
Example 13
Source File: CESU_8.java From openjdk-jdk8u with GNU General Public License v2.0 | 4 votes |
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; }
Example 14
Source File: SJIS_0213.java From openjdk-8-source with GNU General Public License v2.0 | 4 votes |
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()); } }
Example 15
Source File: EUC_JP.java From jdk8u_jdk with GNU General Public License v2.0 | 4 votes |
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()); } }
Example 16
Source File: SJIS_0213.java From openjdk-8-source with GNU General Public License v2.0 | 4 votes |
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()); } }
Example 17
Source File: DBCS_IBM_ASCII_Encoder.java From openjdk-jdk8u with GNU General Public License v2.0 | 4 votes |
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()); } }
Example 18
Source File: HKSCS.java From TencentKona-8 with GNU General Public License v2.0 | 4 votes |
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()); } }
Example 19
Source File: EUC_JP_OLD.java From hottub with GNU General Public License v2.0 | 4 votes |
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()); } }
Example 20
Source File: DoubleByteEncoder.java From openjdk-8-source with GNU General Public License v2.0 | 4 votes |
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(); try { while (sp < sl) { char c = sa[sp]; if (Character.isSurrogate(c)) { if (sgp.parse(c, sa, sp, sl) < 0) return sgp.error(); if (sl - sp < 2) return CoderResult.UNDERFLOW; char c2 = sa[sp + 1]; byte[] outputBytes = new byte[2]; outputBytes = encodeSurrogate(c, c2); if (outputBytes == null) { return sgp.unmappableResult(); } else { if (dl - dp < 2) return CoderResult.OVERFLOW; da[dp++] = outputBytes[0]; da[dp++] = outputBytes[1]; sp += 2; continue; } } if (c >= '\uFFFE') return CoderResult.unmappableForLength(1); int b = encodeSingle(c); if (b != -1) { // Single Byte if (dl - dp < 1) return CoderResult.OVERFLOW; da[dp++] = (byte)b; sp++; continue; } int ncode = encodeDouble(c); if (ncode != 0 && c != '\u0000' ) { if (dl - dp < 2) return CoderResult.OVERFLOW; da[dp++] = (byte) ((ncode & 0xff00) >> 8); da[dp++] = (byte) (ncode & 0xff); sp++; continue; } return CoderResult.unmappableForLength(1); } return CoderResult.UNDERFLOW; } finally { src.position(sp - src.arrayOffset()); dst.position(dp - dst.arrayOffset()); } }