Examples of averageBytesPerChar()


Examples of java.nio.charset.CharsetEncoder.averageBytesPerChar()

     */
    public static ByteBuffer stringToBuffer(String str, Charset cs)
    {
        CharsetEncoder enc = Charsets.get().getEncoder(cs);
        CharBuffer chars = CharBuffer.wrap(str);
        int bufLen = (int)(chars.remaining() * enc.averageBytesPerChar());
        ByteBuffer writeBuf =  ByteBuffer.allocate(bufLen);

        CoderResult result;
        do {
            result = enc.encode(chars, writeBuf, true);
View Full Code Here

Examples of java.nio.charset.CharsetEncoder.averageBytesPerChar()

        assert requiredBytes > 0;
        // We rely on the encoder to choose the number of bytes to read but
        // it does not have to be actually accurate, it only matters
        // performance wise but this is not a performance critical code.
        CharsetEncoder encoder = encoding.newEncoder();
        int toRead = (int)((float)requiredBytes / encoder.averageBytesPerChar()) + 1;
        toRead = Math.max(toRead, requiredBytes);
        char[] readChars = new char[toRead];
        int readCount = reader.read(readChars);
        if (readCount <= 0) {
            // readCount should never be zero but if reader returns zero
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.