Package java.nio.charset

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


                            accum.append(""");
                        else
                            accum.append(c);
                        break;
                    default:
                        if (encoder.canEncode(c))
                            accum.append(c);
                        else if (map.containsKey(c))
                            accum.append('&').append(map.get(c)).append(';');
                        else
                            accum.append("&#x").append(Integer.toHexString(codePoint)).append(';');
View Full Code Here


                        else
                            accum.append("&#x").append(Integer.toHexString(codePoint)).append(';');
                }
            } else {
                final String c = new String(Character.toChars(codePoint));
                if (encoder.canEncode(c))
                    accum.append(c);
                else
                    accum.append("&#x").append(Integer.toHexString(codePoint)).append(';');
            }
        }
View Full Code Here

        }
    }

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

    protected boolean canEncode(String s) {
        final CharsetEncoder encoder =
            Charset.forName(System.getProperty("file.encoding")).newEncoder();
        char[] chars = s.toCharArray();
        for (int i=0; i<chars.length; i++) {
            if(!encoder.canEncode(chars[i])) {
                return false;
            }
        }
        return true;
    }
View Full Code Here

    public static LogicalPredicate<Character> in(Charset charset) {
        final CharsetEncoder encoder = charset.newEncoder();
        return new LogicalPredicate<Character>() {
            @Override
            public boolean matches(Character other) {
                return encoder.canEncode(other);
            }
        };
    }

    public static LogicalPredicate<Character> in(final String characters) {
View Full Code Here

            int count = new Random().nextInt(128) + 128;
            while (count != 0) {
                char c = (char) new Random().nextInt(Character.MAX_VALUE);

                if (charsetEncoder.canEncode(c)) {
                    baos.write(charsetEncoder.encode(CharBuffer.wrap(new char[] { c })).array());
                    count--;
                }
            }
View Full Code Here

     * If the description cannot be encoded using the current encoding change the encoder
     */
    public void write(ByteArrayOutputStream tagBuffer) {
        CharsetEncoder encoder = Charset.forName(TextEncoding.CHARSET_ISO_8859_1).newEncoder();
        String origUrl = getUrlLink();
        if (!encoder.canEncode(origUrl)) {
            //ALL W Frames only support ISO-8859-1 for the url itself, if unable to encode let us assume
            //the link just needs url encoding
            setUrlLink(encodeURL(origUrl));

            //We still cant convert so just set log error and set to blank to allow save to continue
View Full Code Here

            //ALL W Frames only support ISO-8859-1 for the url itself, if unable to encode let us assume
            //the link just needs url encoding
            setUrlLink(encodeURL(origUrl));

            //We still cant convert so just set log error and set to blank to allow save to continue
            if (!encoder.canEncode(getUrlLink())) {
                //logger.warning(ErrorMessage.MP3_UNABLE_TO_ENCODE_URL.getMsg(origUrl));
                setUrlLink("");
            }
            //it was ok, just note the modification made
            else {
View Full Code Here

        //need to worry about LE,BE at this point it makes no difference)
        byte textEncoding = this.getBody().getTextEncoding();
        String charSetName = TextEncoding.getInstanceOf().getValueForId(textEncoding);
        CharsetEncoder encoder = Charset.forName(charSetName).newEncoder();

        if (encoder.canEncode((String) value)) {
            return true;
        } else {
//            logger.finest("Failed Trying to decode" + value + "with" + encoder.toString());
            return false;
        }
View Full Code Here

    protected boolean canEncode(String s) {
        final CharsetEncoder encoder =
            Charset.forName(System.getProperty("file.encoding")).newEncoder();
        char[] chars = s.toCharArray();
        for (int i=0; i<chars.length; i++) {
            if(!encoder.canEncode(chars[i])) {
                return false;
            }
        }
        return true;
    }
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.