Package java.nio.charset

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


          case '\t':
            writer.write('\\');
            writer.write('t');
            break;
          default:
            if (encoder.canEncode(c)) {
              writer.write(c);
            } else {
              writer.write('\\');
              writer.write('u');
              writer.write(Integer.toHexString((c >> 12) & 0xF));
View Full Code Here


   */
  public static List<String> findEncodingsForString(String characters) {
    List<String> encodings = new ArrayList<String>();
    for (int i = 0; i < Globals.ENCODINGS.length; i++) {
      CharsetEncoder encoder = Charset.forName(Globals.ENCODINGS[i]).newEncoder();
      if (encoder.canEncode(characters))
        encodings.add(Globals.ENCODINGS[i]);
    }
    return encodings;
  }

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

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

        return enc.canEncode(name);
    }

    /**
     * @see
     * com.alimama.mdrill.utils.zip.ZipEncoding#encode(java.lang.String)
 
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

      final char[] chars = result.toCharArray();
      final StringBuffer b = new StringBuffer(chars.length);
      for (int i = 0; i < chars.length; i++)
      {
        final char c = chars[i];
        if (charsetEncoder.canEncode(c))
        {
          b.append(c);
        }
      }
      return b.toString();
View Full Code Here

  }

  public void test(TestHarness harness) {
    // Regression test for PR 29178.
    CharsetEncoder enc = Charset.forName("US-ASCII").newEncoder();
    harness.check(!enc.canEncode('\u00e4'));
  }
}
View Full Code Here

    for (int i = 0; i < s.length(); i++) {
      char c = s.charAt(i);
      int n = ((int) c) & 0xFFFF;
     
      if (n > 127) {
        if (ce != null && ce.canEncode(c)) {
          sb.append(c);
        } else {
          String ent = NUMBER_TO_ENTITY.getProperty(Integer.toString(c));
         
          if (ent == null) {
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

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.