Package java.nio.charset

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


        CharsetEncoder encoder = charset.newEncoder();
        int[] buffer = new int[1];

        for (int index = 0, i = 0; i < 0x10FFFF; ++i) {
            buffer[0] = i;
            if (encoder.canEncode(new String(buffer, 0, 1))) {
                String message = String.format("The %d'th character in %s should be %06x", index, charset.name(), i);
                assertEquals(message, i, points.at(index));
                ++index;
            }
        }
View Full Code Here


        int index = 0;
        while (index < string.length()) {
            int point = string.codePointAt(index);
            int count = Character.charCount(point);

            if (isValidCharCode(point) && encoder.canEncode(string.substring(index, index + count))) {
                String value = quoteCharCode(point);
                if (value != null) {
                    sb.append(value);
                } else {
                    sb.appendCodePoint(point);
View Full Code Here

    private String sanitize(String title) {
        StringBuilder sb = new StringBuilder();
        char[] cs = title.toCharArray();
        CharsetEncoder asciiEncoder = Charset.forName("US-ASCII").newEncoder();
        for (char c : cs) {
            if (!valid(c) || !asciiEncoder.canEncode(c)) {
                c = unaccent(c);
            }
            sb.append(c);

        }
View Full Code Here

        }
    }

    private boolean canAsciiEncode(String string) {
        CharsetEncoder asciiEncoder = Charset.forName("US-ASCII").newEncoder();
        return asciiEncoder.canEncode(string);
    }
}
View Full Code Here

    public boolean canEncode(String name) {
        CharsetEncoder enc = this.charset.newEncoder();
        enc.onMalformedInput(CodingErrorAction.REPORT);
        enc.onUnmappableCharacter(CodingErrorAction.REPORT);

        return enc.canEncode(name);
    }

    /**
     * @see
     * org.apache.tools.zip.ZipEncoding#encode(java.lang.String)
 
View Full Code Here

       // add all encodable characters to the buffer
        int count = 0;
//        for (int i = 0; i < 65536; ++i) {
        for (int i = 0; i < 65536; ++i) {
            Character ch = (char)i;
            if (encoder.canEncode(ch)) {
                allChars.append(ch);
                ++count;
            }
        }
        if (debug) System.out.print(charsetName + " has " + count + " encodable characters");
View Full Code Here

        StringBuffer result = new StringBuffer();
        int i;
        for (i = 0; i < s.length(); i++)
        {
            char c = s.charAt(i);
            if (!cEncoder.canEncode(c))
                break;
        }
        for (; i < s.length(); i++)
        {
            char c = s.charAt(i);
View Full Code Here

                break;
        }
        for (; i < s.length(); i++)
        {
            char c = s.charAt(i);
            if (cEncoder.canEncode(c))
                result.append(c);
            else
            {
                String hexValue = Integer.toHexString((int) c);
                switch (hexValue.length())
View Full Code Here

    public boolean canEncode(String name) {
        CharsetEncoder enc = this.charset.newEncoder();
        enc.onMalformedInput(CodingErrorAction.REPORT);
        enc.onUnmappableCharacter(CodingErrorAction.REPORT);

        return enc.canEncode(name);
    }

    /**
     * @see
     * org.apache.commons.compress.archivers.zip.ZipEncoding#encode(java.lang.String)
 
View Full Code Here

        }
    }

    private boolean canAsciiEncode(String string) {
        CharsetEncoder asciiEncoder = Charset.forName("US-ASCII").newEncoder();
        return asciiEncoder.canEncode(string);
    }
}
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.