Package java.nio

Examples of java.nio.CharBuffer.flip()


        if ( r.isOverflow() )
            throw new InternalErrorException("fromByteBuffer: decode overflow (1)") ;
        r = dec.flush(cBuff) ;
        if ( r.isOverflow() )
            throw new InternalErrorException("fromByteBuffer: decode overflow (2)") ;
        cBuff.flip();
        return cBuff.toString() ;
    }

    /** Return a hex string representing the bytes, zero padded to length of byte array. */
    public static String asHex(byte[] bytes)
View Full Code Here


    Filter... filters)
      throws IOException {
    StringBuilder sb = new StringBuilder();
    CharBuffer chars = CharBuffer.allocate(1024);
    while (readable.read(chars) > -1) {
      chars.flip();
      processChars(sb, chars, enc, filters);
    }
    return sb.toString();
  }
 
View Full Code Here

            dec.reset();
            CoderResult cr = dec.decode(bb, cb, true);
            assert cr.isUnderflow();
            cr = dec.flush(cb);
            assert cr.isUnderflow();
            sb.append(cb.flip().toString());
        }

        return sb.toString();
    }
View Full Code Here

     *          If an encoding operation is already in progress
     */
    public boolean canEncode(char c) {
  CharBuffer cb = CharBuffer.allocate(1);
  cb.put(c);
  cb.flip();
  return canEncode(cb);
    }

    /**
     * Tells whether or not this encoder can encode the given character
View Full Code Here

     */
    public static void copy(Reader reader, boolean closeIn, Appendable out) throws IOException {
        try {
            CharBuffer buffer = CharBuffer.allocate(4096);
            while (reader.read(buffer) > 0) {
                buffer.flip();
                buffer.rewind();
                out.append(buffer);
            }
        } finally {
            if (closeIn) IOUtils.closeQuietly(reader);
View Full Code Here

                    result, true) : decoder.flush(result);
            if (cr.isUnderflow()) {
                break;
            } else if (cr.isOverflow()) {
                n *= 2;
                result.flip();
                result = CharBuffer.allocate(n).put(result);
                continue;
            }
        }
        result.flip();
View Full Code Here

                result.flip();
                result = CharBuffer.allocate(n).put(result);
                continue;
            }
        }
        result.flip();
        return result.toString();
    }

    /**
     * charset cache.
View Full Code Here

      if (cr.isError())
      {
        throw new SerializationException("Error when decoding: " + cr);
      }
    }
    cb.flip();
    char[] res = new char[cb.limit()];
    cb.get(res);
    return new String(res);
  }
View Full Code Here

     *          If an encoding operation is already in progress
     */
    public boolean canEncode(char c) {
        CharBuffer cb = CharBuffer.allocate(1);
        cb.put(c);
        cb.flip();
        return canEncode(cb);
    }

    /**
     * Tells whether or not this encoder can encode the given character
View Full Code Here

         */
        private void upsizeCharBuffer() {
            final int oldCapacity = charBuffer.capacity();
            CharBuffer oldBuffer = charBuffer;
            charBuffer = CharBuffer.allocate(oldCapacity + QUOTED_BUFFER_INITIAL_CAPACITY);
            oldBuffer.flip();
            charBuffer.put(oldBuffer);
        }
    }

}
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.