Package java.nio.charset

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


  public static byte[] getBytes (char[] chars) {
    Charset cs = Charset.forName ("UTF-8");
    CharBuffer cb = CharBuffer.allocate (chars.length);
    cb.put (chars);
                cb.flip ();
    ByteBuffer bb = cs.encode (cb);
   
    return bb.array();
        }
  public static char[] getChars (byte[] bytes) {
View Full Code Here


    prepd = prepd.replaceAll(" *$", "");
    // remove genre id numbers, ugh (followed by a space or nothing)
    prepd = prepd.replaceAll("^\\([0-9]+\\)( |) *", "");
    // make sure its in the native encoding, or it'll lokos screwy on the web
    Charset cs = Charset.defaultCharset();
    prepd = new String(cs.encode(prepd).array());
    // take out all non-printable characters, make the 'chooser' fail miserables.
    // prepd = prepd.replaceAll("[^\\p{Print}]", "");
    try {
      prepd = new String(prepd.getBytes(), "UTF-8");
    } catch (UnsupportedEncodingException ueE) {
View Full Code Here

      String recstr = formatRecord();

        // convert to desired charset
      // recbuf position is zero, limit is byte count - ready to send
      Charset cs = Charset.forName("UTF-8");
      ByteBuffer recbuf = cs.encode(recstr.toString());
        String strlen = Integer.toHexString(recbuf.limit());
      // String strlen = String.format("%04X", recbuf.limit());
     
      // replace fake length ("0000") with real length
      // String: "HDR:0000:..."
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

            fireException(new IllegalArgumentException("input == null"));
            return null;
        }

        Charset cs = UTF8();
        ByteBuffer bb = cs.encode(input);
        ByteArrayInputStream baInputStream = new ByteArrayInputStream(bb.array(), 0, bb.limit());
       
        Object res = readXMLBeanFrom(baInputStream,owner);

        try {
View Full Code Here

            fireException(new IllegalArgumentException("input == null"));
            return null;
        }

        Charset cs = UTF8();
        ByteBuffer bb = cs.encode(input);
        ByteArrayInputStream baInputStream = new ByteArrayInputStream(bb.array(), 0, bb.limit());
       
        Object res = readXMLBeanFrom(baInputStream,owner);

        try {
View Full Code Here

            Charset charset = Charset.defaultCharset();

            if (ParameterFlags.isIn(inout)) {
                for (int i = 0; i < strings.length; ++i) {
                    if (strings[i] != null) {
                        ByteBuffer buf = charset.encode(CharBuffer.wrap(strings[i]));
                        DirectMemoryIO ptr = TransientNativeMemory.allocate(NativeRuntime.getInstance(), buf.remaining() + 1, 1, false);
                        ptr.putZeroTerminatedByteArray(0, buf.array(), buf.arrayOffset() + buf.position(), buf.remaining());
                        pointers[i] = ptr;

                    } else {
View Full Code Here

            String charsetName = getCharsetName(rec.platformID,
                rec.platformSpecificID);
            Charset charset = Charset.forName(charsetName);
           
            // encode
            ByteBuffer strBuf = charset.encode(value);
            short strLen = (short) (strBuf.remaining() & 0xFFFF);
           
            // write the IDs
            buf.putShort(rec.platformID);
            buf.putShort(rec.platformSpecificID);
View Full Code Here

            String charsetName = getCharsetName(rec.platformID,
                rec.platformSpecificID);
            Charset charset = Charset.forName(charsetName);
           
            // encode
            ByteBuffer buf = charset.encode(value);
               
            // add the size of the coded buffer
            length += buf.remaining();
        }
       
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.