Package java.nio.charset

Examples of java.nio.charset.Charset.decode()


  /*
   * Test the method decode(ByteBuffer) with a malformed input.
   */
  public void testDecode_Malformed() throws Exception {
    Charset c1 = Charset.forName("iso8859-1");
    CharBuffer cb = c1.decode(ByteBuffer.wrap("abcd\u5D14efg"
        .getBytes("iso8859-1")));
    byte[] replacement = c1.newEncoder().replacement();
    assertEquals(new String(cb.array()).trim(), "abcd" + new String(replacement, "iso8859-1")
        + "efg");
  }
View Full Code Here


             * XML parse.
             */
            Charset contentCharset = Charset.forName(contentEncoding);
            byte[] contentBytes = baos.toByteArray();
            CharBuffer contentChars =
                contentCharset.decode(ByteBuffer.wrap(contentBytes)); // not the most efficient way.
            responseText = contentChars.toString();
            LOG.fine(responseText);
           
            if (responseBytes.length > 0
                && ("text/xml".equals(contentType)
View Full Code Here

   */
    @SuppressWarnings("nls")
    public void test_ConstructorLjava_io_Reader() throws IOException {
        Charset charset = Charset.forName("ISO-8859-1");
        String content = "p1=one\nfeature=good_feature";
        CharBuffer cbuffer = charset.decode(ByteBuffer.wrap(content
                .getBytes("ISO-8859-1")));
        char[] chars = new char[cbuffer.limit()];
        cbuffer.get(chars);

        prb = new PropertyResourceBundle(new CharArrayReader(chars));
View Full Code Here

        assertEquals(2, prb.keySet().size());
        assertEquals("one", prb.getString("p1"));
        assertEquals("good_feature", prb.getString("feature"));

        charset = Charset.forName("UTF-8");
        cbuffer = charset.decode(ByteBuffer.wrap(content.getBytes("UTF-8")));
        chars = new char[cbuffer.limit()];
        cbuffer.get(chars);

        prb = new PropertyResourceBundle(new CharArrayReader(chars));
        assertEquals(2, prb.keySet().size());
View Full Code Here

                if (c != '%') {
                    break;
                }
            }
            bb.flip();
            sb.append(utf8.decode(bb));
        }

        return sb.toString();
    }
View Full Code Here

        contentSource = null;
      } else if (document != null) {
        content = HtmlSerialization.serialize(document);
      } else if (contentBytes != null) {
        Charset useEncoding = contentEncoding != null ? contentEncoding : Charsets.UTF_8;
        content = useEncoding.decode(ByteBuffer.wrap(contentBytes)).toString();
      }
    }
    return content;
  }
View Full Code Here

 
  public static String toString(byte[] value, int offset, int length,
      String encoding) throws UnsupportedEncodingException {
    Charset cs = findCharset(encoding);

    return cs.decode(ByteBuffer.wrap(value, offset, length)).toString();
  }

  public static String toString(byte[] value, String encoding)
      throws UnsupportedEncodingException {
    Charset cs = findCharset(encoding);
View Full Code Here

  public static String toString(byte[] value, String encoding)
      throws UnsupportedEncodingException {
    Charset cs = findCharset(encoding);

    return cs.decode(ByteBuffer.wrap(value)).toString();
  }

  public static String toString(byte[] value, int offset, int length) {
    try {
      Charset cs = findCharset(platformEncoding);
View Full Code Here

  public static String toString(byte[] value, int offset, int length) {
    try {
      Charset cs = findCharset(platformEncoding);
     
      return cs.decode(ByteBuffer.wrap(value, offset, length)).toString();
    } catch (UnsupportedEncodingException e) {
      // can't happen, emulating new String(byte[])
    }
   
    return null;
View Full Code Here

  public static String toString(byte[] value) {
    try {
      Charset cs = findCharset(platformEncoding);
     
      return cs.decode(ByteBuffer.wrap(value)).toString();
    } catch (UnsupportedEncodingException e) {
      // can't happen, emulating new String(byte[])
    }
   
    return null;
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.