Java Code Examples for java.nio.CharBuffer#put()
The following examples show how to use
java.nio.CharBuffer#put() .
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: DoubleByte.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
protected CoderResult decodeBufferLoop(ByteBuffer src, CharBuffer dst) { int mark = src.position(); try { while (src.hasRemaining() && dst.hasRemaining()) { int b1 = src.get() & 0xff; char c = b2cSB[b1]; int inSize = 1; if (c == UNMAPPABLE_DECODING) { if (src.remaining() < 1) return crMalformedOrUnderFlow(b1); int b2 = src.get() & 0xff; if (b2 < b2Min || b2 > b2Max || (c = b2c[b1][b2 - b2Min]) == UNMAPPABLE_DECODING) return crMalformedOrUnmappable(b1, b2); inSize++; } dst.put(c); mark += inSize; } return src.hasRemaining()? CoderResult.OVERFLOW : CoderResult.UNDERFLOW; } finally { src.position(mark); } }
Example 2
Source File: MessageInbound.java From tomcatsrc with Apache License 2.0 | 6 votes |
private void resizeCharBuffer() throws IOException { int maxSize = getCharBufferMaxSize(); if (cb.limit() >= maxSize) { throw new IOException(sm.getString("message.bufferTooSmall")); } long newSize = cb.limit() * 2; if (newSize > maxSize) { newSize = maxSize; } // Cast is safe. newSize < maxSize and maxSize is an int CharBuffer newBuffer = CharBuffer.allocate((int) newSize); cb.rewind(); newBuffer.put(cb); cb = newBuffer; }
Example 3
Source File: SingleByte.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
private CoderResult decodeBufferLoop(ByteBuffer src, CharBuffer dst) { int mark = src.position(); try { while (src.hasRemaining()) { char c = decode(src.get()); if (c == UNMAPPABLE_DECODING) return CoderResult.unmappableForLength(1); if (!dst.hasRemaining()) return CoderResult.OVERFLOW; dst.put(c); mark++; } return CoderResult.UNDERFLOW; } finally { src.position(mark); } }
Example 4
Source File: PerforceShiftJISCharset.java From p4ic4idea with Apache License 2.0 | 6 votes |
/** * Apply Perforce specific updates. */ private void update(CharBuffer cb) { if (UNICODE_MAPPING) { for (int pos = cb.position(); pos < cb.limit(); pos++) { char c = cb.get(pos); switch (c) { case '\\': cb.put(pos, '\u00A5'); break; case '\u007E': cb.put(pos, '\u203E'); break; default: } } } }
Example 5
Source File: ISO_8859_1.java From openjdk-8 with GNU General Public License v2.0 | 6 votes |
private CoderResult decodeBufferLoop(ByteBuffer src, CharBuffer dst) { int mark = src.position(); try { while (src.hasRemaining()) { byte b = src.get(); if (!dst.hasRemaining()) return CoderResult.OVERFLOW; dst.put((char)(b & 0xff)); mark++; } return CoderResult.UNDERFLOW; } finally { src.position(mark); } }
Example 6
Source File: Surrogate.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
/** * Generates one or two UTF-16 characters to represent the given UCS-4 * character. * * @param uc The UCS-4 character * @param len The number of input bytes from which the UCS-4 value * was constructed (used when creating result objects) * @param dst The destination buffer, to which one or two UTF-16 * characters will be written * * @return Either a positive count of the number of UTF-16 characters * written to the destination buffer, or -1, in which case * error() will return a descriptive result object */ public int generate(int uc, int len, CharBuffer dst) { if (uc <= 0xffff) { if (is(uc)) { error = CoderResult.malformedForLength(len); return -1; } if (dst.remaining() < 1) { error = CoderResult.OVERFLOW; return -1; } dst.put((char)uc); error = null; return 1; } if (uc < UCS4_MIN) { error = CoderResult.malformedForLength(len); return -1; } if (uc <= UCS4_MAX) { if (dst.remaining() < 2) { error = CoderResult.OVERFLOW; return -1; } dst.put(high(uc)); dst.put(low(uc)); error = null; return 2; } error = CoderResult.unmappableForLength(len); return -1; }
Example 7
Source File: SJIS_0213.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
private CoderResult decodeBufferLoop(ByteBuffer src, CharBuffer dst) { int mark = src.position(); try { while (src.hasRemaining()) { char[] cc = null; int b1 = src.get() & 0xff; char c = decodeSingle(b1); int inSize = 1, outSize = 1; if (c == UNMAPPABLE) { if (src.remaining() < 1) return CoderResult.UNDERFLOW; int b2 = src.get() & 0xff; inSize++; c = decodeDouble(b1, b2); 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 (dst.remaining() < outSize) return CoderResult.OVERFLOW; if (outSize == 2) { dst.put(cc[0]); dst.put(cc[1]); } else { dst.put(c); } mark += inSize; } return CoderResult.UNDERFLOW; } finally { src.position(mark); } }
Example 8
Source File: GetCommand.java From gemfirexd-oss with Apache License 2.0 | 5 votes |
private ByteBuffer composeReply(Map<Object, ValueWrapper> results, boolean isGets) { Iterator<Entry<Object, ValueWrapper>> it = results.entrySet().iterator(); ByteBuffer buffer = getReplyBuffer(); while (it.hasNext()) { Entry<Object, ValueWrapper> e = it.next(); if (getLogger().fineEnabled()) { getLogger().fine("get compose reply:"+e); } ValueWrapper valWrapper = e.getValue(); if (valWrapper != null) { byte[] v = valWrapper.getValue(); CharBuffer reply = getLineBuffer(); reply.put(VALUE).put(W_SPACE); reply.put(e.getKey().toString()).put(W_SPACE); reply.put(Integer.toString(valWrapper.getFlags())).put(W_SPACE); // flags String valBytes = v == null ? Integer.toString(0) : Integer.toString(v.length); reply.put(valBytes); if (isGets) { // send the version for gets command reply.put(W_SPACE); reply.put(Long.toString(valWrapper.getVersion())); } reply.put(RN); reply.flip(); getAsciiEncoder().encode(reply, buffer, false); // put the actual value buffer.put(v); RN_BUF.rewind(); buffer.put(RN_BUF); } } END_BUF.rewind(); buffer.put(END_BUF); buffer.flip(); return buffer; }
Example 9
Source File: COMPOUND_TEXT_Decoder.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 5 votes |
private CoderResult nonStandardBytes(short newByte, CharBuffer cb) { CoderResult cr = CoderResult.UNDERFLOW; if (nonStandardDecoder != null) { //byteBuf[0] = (byte)newByte; inBB.put((byte)newByte); inBB.flip(); cr = nonStandardDecoder.decode(inBB, cb, false); if (!inBB.hasRemaining()) { inBB.clear(); } else { int pos = inBB.limit(); inBB.clear(); inBB.position(pos); } } else if (cb.remaining() < replacement().length()) { cb.put(replacement()); } else { return CoderResult.OVERFLOW; } ext_offset++; if (ext_offset >= ext_count) { ext_offset = ext_count = 0; state = NORMAL_BYTES; cr = flushDecoder(nonStandardDecoder, cb); nonStandardDecoder = null; } return cr; }
Example 10
Source File: ISCII91.java From hottub with GNU General Public License v2.0 | 5 votes |
protected CoderResult implFlush(CharBuffer out) { if(needFlushing) { if (out.remaining() < 1) { return CoderResult.OVERFLOW; } else { out.put(contextChar); } } contextChar = INVALID_CHAR; needFlushing = false; return CoderResult.UNDERFLOW; }
Example 11
Source File: FSA.java From vespa with Apache License 2.0 | 5 votes |
public void delta(char chr){ CharBuffer chrbuf = CharBuffer.allocate(1); chrbuf.put(0,chr); ByteBuffer buf = fsa.encode(chrbuf); Maps m = fsa.map(); while(state >0 && buf.position()<buf.limit()){ delta(m, buf.get()); } }
Example 12
Source File: ISCII91.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
protected CoderResult implFlush(CharBuffer out) { if(needFlushing) { if (out.remaining() < 1) { return CoderResult.OVERFLOW; } else { out.put(contextChar); } } contextChar = INVALID_CHAR; needFlushing = false; return CoderResult.UNDERFLOW; }
Example 13
Source File: ISCII91.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
protected CoderResult implFlush(CharBuffer out) { if(needFlushing) { if (out.remaining() < 1) { return CoderResult.OVERFLOW; } else { out.put(contextChar); } } contextChar = INVALID_CHAR; needFlushing = false; return CoderResult.UNDERFLOW; }
Example 14
Source File: EUC_JP_OLD.java From jdk8u_jdk with GNU General Public License v2.0 | 4 votes |
private CoderResult decodeBufferLoop(ByteBuffer src, CharBuffer dst) { int mark = src.position(); int b1 = 0, b2 = 0; int inputSize = 0; char outputChar = REPLACE_CHAR; // U+FFFD; try { while (src.hasRemaining()) { b1 = src.get() & 0xff; inputSize = 1; if ((b1 & 0x80) == 0) { outputChar = (char)b1; } else { // Multibyte char if ((b1 & 0xff) == 0x8f) { // JIS0212 if (src.remaining() < 2) return CoderResult.UNDERFLOW; b1 = src.get() & 0xff; b2 = src.get() & 0xff; inputSize += 2; outputChar = decode0212(b1-0x80, b2-0x80); } else { // JIS0208 if (src.remaining() < 1) return CoderResult.UNDERFLOW; b2 = src.get() & 0xff; inputSize++; outputChar = decodeDouble(b1, b2); } } if (outputChar == REPLACE_CHAR) { return CoderResult.unmappableForLength(inputSize); } if (dst.remaining() < 1) return CoderResult.OVERFLOW; dst.put(outputChar); mark += inputSize; } return CoderResult.UNDERFLOW; } finally { src.position(mark); } }
Example 15
Source File: DoubleByteDecoder.java From dragonwell8_jdk with GNU General Public License v2.0 | 4 votes |
private CoderResult decodeBufferLoop(ByteBuffer src, CharBuffer dst) { int mark = src.position(); int inputSize = 0; int outputSize = 0; try { while (src.hasRemaining()) { int b1 = src.get(); inputSize = 1; outputSize = 1; highSurrogate = lowSurrogate = 0; char c = decodeSingle(b1); if (c == REPLACE_CHAR) { if (src.remaining() < 1) return CoderResult.UNDERFLOW; b1 &= 0xff; int b2 = src.get() & 0xff; inputSize = 2; c = decodeDouble(b1, b2); if (c == REPLACE_CHAR) return CoderResult.unmappableForLength(2); outputSize = (highSurrogate > 0) ? 2: 1; } if (dst.remaining() < outputSize) return CoderResult.OVERFLOW; mark += inputSize; if (outputSize == 2) { dst.put(highSurrogate); dst.put(lowSurrogate); } else { dst.put(c); } } return CoderResult.UNDERFLOW; } finally { src.position(mark); } }
Example 16
Source File: HKSCS.java From openjdk-8-source with GNU General Public License v2.0 | 4 votes |
protected CoderResult decodeBufferLoop(ByteBuffer src, CharBuffer dst) { int mark = src.position(); try { while (src.hasRemaining()) { char[] cc = null; int b1 = src.get() & 0xff; int inSize = 1, outSize = 1; char c = decodeSingle(b1); if (c == UNMAPPABLE_DECODING) { if (src.remaining() < 1) return CoderResult.UNDERFLOW; int b2 = src.get() & 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 { outSize = 2; } } } if (dst.remaining() < outSize) return CoderResult.OVERFLOW; if (outSize == 2) { dst.put(Surrogate.high(0x20000 + c)); dst.put(Surrogate.low(0x20000 + c)); } else { dst.put(c); } mark += inSize; } return CoderResult.UNDERFLOW; } finally { src.position(mark); } }
Example 17
Source File: DoubleByteDecoder.java From jdk8u_jdk with GNU General Public License v2.0 | 4 votes |
private CoderResult decodeBufferLoop(ByteBuffer src, CharBuffer dst) { int mark = src.position(); int inputSize = 0; int outputSize = 0; try { while (src.hasRemaining()) { int b1 = src.get(); inputSize = 1; outputSize = 1; highSurrogate = lowSurrogate = 0; char c = decodeSingle(b1); if (c == REPLACE_CHAR) { if (src.remaining() < 1) return CoderResult.UNDERFLOW; b1 &= 0xff; int b2 = src.get() & 0xff; inputSize = 2; c = decodeDouble(b1, b2); if (c == REPLACE_CHAR) return CoderResult.unmappableForLength(2); outputSize = (highSurrogate > 0) ? 2: 1; } if (dst.remaining() < outputSize) return CoderResult.OVERFLOW; mark += inputSize; if (outputSize == 2) { dst.put(highSurrogate); dst.put(lowSurrogate); } else { dst.put(c); } } return CoderResult.UNDERFLOW; } finally { src.position(mark); } }
Example 18
Source File: DBCS_IBM_EBCDIC_Decoder.java From openjdk-8-source with GNU General Public License v2.0 | 4 votes |
private CoderResult decodeBufferLoop(ByteBuffer src, CharBuffer dst) { int mark = src.position(); try { while (src.hasRemaining()) { int b1, b2; int v = 0; b1 = src.get(); int inputSize = 1; 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 (src.remaining() < 1) return CoderResult.UNDERFLOW; b2 = src.get(); 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 == REPLACE_CHAR) return CoderResult.unmappableForLength(inputSize); if (!dst.hasRemaining()) return CoderResult.OVERFLOW; dst.put(outputChar); } mark += inputSize; } return CoderResult.UNDERFLOW; } finally { src.position(mark); } }
Example 19
Source File: UTF_32Coder.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 4 votes |
protected CoderResult decodeLoop(ByteBuffer src, CharBuffer dst) { if (src.remaining() < 4) return CoderResult.UNDERFLOW; int mark = src.position(); int cp; try { if (currentBO == NONE) { cp = ((src.get() & 0xff) << 24) | ((src.get() & 0xff) << 16) | ((src.get() & 0xff) << 8) | (src.get() & 0xff); if (cp == BOM_BIG && expectedBO != LITTLE) { currentBO = BIG; mark += 4; } else if (cp == BOM_LITTLE && expectedBO != BIG) { currentBO = LITTLE; mark += 4; } else { if (expectedBO == NONE) currentBO = BIG; else currentBO = expectedBO; src.position(mark); } } while (src.remaining() >= 4) { cp = getCP(src); if (Character.isBmpCodePoint(cp)) { if (!dst.hasRemaining()) return CoderResult.OVERFLOW; mark += 4; dst.put((char) cp); } else if (Character.isValidCodePoint(cp)) { if (dst.remaining() < 2) return CoderResult.OVERFLOW; mark += 4; dst.put(Character.highSurrogate(cp)); dst.put(Character.lowSurrogate(cp)); } else { return CoderResult.malformedForLength(4); } } return CoderResult.UNDERFLOW; } finally { src.position(mark); } }
Example 20
Source File: DBCS_IBM_ASCII_Decoder.java From openjdk-jdk9 with GNU General Public License v2.0 | 4 votes |
private CoderResult decodeBufferLoop(ByteBuffer src, CharBuffer dst) { int mark = src.position(); try { while (src.hasRemaining()) { char outputChar = REPLACE_CHAR; int inputSize = 1; int b1, b2; int v = 0; b1 = src.get(); if (b1 < 0) b1 += 256; if (!leadByte[b1]) { outputChar = singleByteToChar.charAt(b1); } else { if (src.remaining() < 1) return CoderResult.UNDERFLOW; b2 = src.get(); 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 == REPLACE_CHAR) return CoderResult.unmappableForLength(inputSize); if (!dst.hasRemaining()) return CoderResult.OVERFLOW; mark += inputSize; dst.put(outputChar); } return CoderResult.UNDERFLOW; } finally { src.position(mark); } }