Package java.nio.charset

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


      Properties properties = new Properties();

      if (sProperties != null)
      {
         Charset charset = Charset.forName(IOUtil.ENCODING);
         ByteBuffer byteBuffer = charset.encode(sProperties);
         ByteArrayInputStream is = new ByteArrayInputStream(byteBuffer.array(), 0, byteBuffer.limit());
  
         properties.load(is);
      }
View Full Code Here


  /*
   * Test the method encode(CharBuffer) with an unmappable char.
   */
  public void testEncode_CharBuffer_Unmappable() throws Exception {
    Charset c1 = Charset.forName("iso8859-1");
    ByteBuffer bb = c1.encode(CharBuffer.wrap("abcd\u5D14efg"));
    assertEquals(new String(bb.array(), "iso8859-1"), "abcd"
        + new String(c1.newEncoder().replacement(), "iso8859-1")
        + "efg");
  }

View Full Code Here

  /*
   * Test the method encode(String) with an unmappable char.
   */
  public void testEncode_String_Unmappable() throws Exception {
    Charset c1 = Charset.forName("iso8859-1");
    ByteBuffer bb = c1.encode("abcd\u5D14efg");
    assertEquals(new String(bb.array(), "iso8859-1"), "abcd"
        + new String(c1.newEncoder().replacement(), "iso8859-1")
        + "efg");
  }

View Full Code Here

  /*
   * Test the method encode(CharBuffer) with an unmappable char.
   */
  public void testEncode_CharBuffer_Unmappable() throws Exception {
    Charset c1 = Charset.forName("iso8859-1");
    ByteBuffer bb = c1.encode(CharBuffer.wrap("abcd\u5D14efg"));
    assertEquals(new String(bb.array(), "iso8859-1"), "abcd"
        + new String(c1.newEncoder().replacement(), "iso8859-1")
        + "efg");
  }

View Full Code Here

  /*
   * Test the method encode(String) with an unmappable char.
   */
  public void testEncode_String_Unmappable() throws Exception {
    Charset c1 = Charset.forName("iso8859-1");
    ByteBuffer bb = c1.encode("abcd\u5D14efg");
    assertEquals(new String(bb.array(), "iso8859-1"), "abcd"
        + new String(c1.newEncoder().replacement(), "iso8859-1")
        + "efg");
  }

View Full Code Here

        assertEquals(content, out.toByteArray());
    }
   
    private void check(String content, String expected) throws Exception {
        Charset ascii = CharsetUtil.US_ASCII;
        check(ascii.encode(content).array(), ascii.encode(expected).array());
    }

   
    private void check(byte[] content, byte[] expected) throws Exception {
        ByteArrayInputStream in = new ByteArrayInputStream(content);
View Full Code Here

        assertEquals(content, out.toByteArray());
    }
   
    private void check(String content, String expected) throws Exception {
        Charset ascii = CharsetUtil.US_ASCII;
        check(ascii.encode(content).array(), ascii.encode(expected).array());
    }

   
    private void check(byte[] content, byte[] expected) throws Exception {
        ByteArrayInputStream in = new ByteArrayInputStream(content);
View Full Code Here

    Charset cs = findCharset(encoding);

    // can't simply .array() this to get the bytes
    // especially with variable-length charsets the
    // buffer is sometimes larger than the actual encoded data
    ByteBuffer buf = cs.encode(value);
   
    int encodedLen = buf.limit();
    byte[] asBytes = new byte[encodedLen];
    buf.get(asBytes, 0, encodedLen);
   
View Full Code Here

 
  public static byte[] getBytes(String value) {
    try {
      Charset cs = findCharset(platformEncoding);
     
      ByteBuffer buf = cs.encode(value);
     
      int encodedLen = buf.limit();
      byte[] asBytes = new byte[encodedLen];
      buf.get(asBytes, 0, encodedLen);
     
View Full Code Here

            MessageDigest digest = MessageDigest.getInstance("MD5");
            Charset utf8 = Charset.forName("UTF-8");
            CharBuffer cbuffer = CharBuffer.allocate(2048);
            while (reader.read(cbuffer) >= 0) {
                cbuffer.flip();
                ByteBuffer bytes = utf8.encode(cbuffer);
                digest.update(bytes);
                cbuffer.clear();
            }
            setHash(digest.digest());
        } catch (NoSuchAlgorithmException e) {
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.