Package java.nio.charset

Examples of java.nio.charset.CharsetEncoder


                             Object value) throws IOException {
    if (value != null) {
      writer.write(key);
      writer.write("=");   
      String s = value.toString();
      CharsetEncoder encoder = Charset.forName("ISO-8859-1").newEncoder();
      for (int i = 0; i < s.length(); i++) {
        char c = s.charAt(i);     
        switch (c) {
          case '\\':
            writer.write('\\');
            writer.write('\\');
            break;
          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


        String message= "Unsupported encoding '" + encoding + "'.";
        IStatus s= new Status(IStatus.ERROR, Plugin.PLUGIN_ID, IStatus.OK, message, ex);
        throw new CoreException(s);
      }

      CharsetEncoder encoder= charset.newEncoder();
      encoder.onMalformedInput(CodingErrorAction.REPLACE);
      encoder.onUnmappableCharacter(CodingErrorAction.REPORT);

      InputStream stream;

      try {
        byte[] bytes;
        ByteBuffer byteBuffer= encoder.encode(CharBuffer.wrap(document.get()));
        if (byteBuffer.hasArray())
          bytes= byteBuffer.array();
        else {
          bytes= new byte[byteBuffer.limit()];
          byteBuffer.get(bytes);
View Full Code Here

   * @return A List of character encodings
   */
  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

    private static String createString(int code) {
        return "<char code=\"#" + Integer.toString(code, 16) + "\"/>";
    }

    private String createString(String string) {
        CharsetEncoder encoder = Charset.forName(encoding).newEncoder();

        StringBuilder sb = new StringBuilder();
        sb.append("<string>");
        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 static ByteBuffer getAsByteBuffer() {
    try {
      Charset charset = Charset.forName("ISO-8859-1");
        CharsetEncoder encoder = charset.newEncoder();
        ByteBuffer buf = encoder.encode(CharBuffer.wrap(testMail.toCharArray()));
        return buf;
    } catch (Exception e) {
      throw new RuntimeException(e.toString());
    }
  }
View Full Code Here

 
 
  public static ByteBuffer getAsByteBuffer() {
    try {
      Charset charset = Charset.forName("ISO-8859-1");
        CharsetEncoder encoder = charset.newEncoder();
        ByteBuffer buf = encoder.encode(CharBuffer.wrap(testMail.toCharArray()));
        return buf;
    } catch (Exception e) {
      throw new RuntimeException(e.toString());
    }
  }
View Full Code Here

 
 
  public static ByteBuffer getAsByteBuffer() {
    try {
      Charset charset = Charset.forName("ISO-8859-1");
        CharsetEncoder encoder = charset.newEncoder();
        ByteBuffer buf = encoder.encode(CharBuffer.wrap(testMail.toCharArray()));
        return buf;
    } catch (Exception e) {
      throw new RuntimeException(e.toString());
    }
  }
View Full Code Here

 
 
  public static ByteBuffer getAsByteBuffer() {
    try {
      Charset charset = Charset.forName("ISO-8859-1");
        CharsetEncoder encoder = charset.newEncoder();
        ByteBuffer buf = encoder.encode(CharBuffer.wrap(testMail.toCharArray()));
        return buf;
    } catch (Exception e) {
      throw new RuntimeException(e.toString());
    }
  }
View Full Code Here

 
 
  public static ByteBuffer getAsByteBuffer() {
    try {
      Charset charset = Charset.forName("ISO-8859-1");
        CharsetEncoder encoder = charset.newEncoder();
        ByteBuffer buf = encoder.encode(CharBuffer.wrap(testMail.toCharArray()));
        return buf;
    } catch (Exception e) {
      throw new RuntimeException(e.toString());
    }
  }
View Full Code Here

   
    private static IRubyObject convert(ThreadContext context, String decodeCharset,
            String encodeCharset, IRubyObject str) {
        Ruby runtime = context.getRuntime();
        CharsetDecoder decoder;
        CharsetEncoder encoder;
        try {
            decoder = Charset.forName(decodeCharset).newDecoder();
            encoder = Charset.forName(encodeCharset).newEncoder();
        } catch (UnsupportedCharsetException e) {
            throw runtime.newArgumentError("invalid encoding");
        }
       
        ByteList bytes = str.convertToString().getByteList();
        ByteBuffer buf = ByteBuffer.wrap(bytes.unsafeBytes(), bytes.begin(), bytes.length());
        try {
            CharBuffer cbuf = decoder.decode(buf);
            buf = encoder.encode(cbuf);
        } catch (CharacterCodingException e) {
            throw runtime.newArgumentError("invalid encoding");
        }
        byte[] arr = buf.array();
       
View Full Code Here

TOP

Related Classes of java.nio.charset.CharsetEncoder

Copyright © 2018 www.massapicom. 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.