Package java.nio.charset

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


    String msg = cs.decode(appBuffer).toString();
    if (!msg.equals(TEST_MESSAGE))
      throw new SSLException("message decode failed");

    appBuffer.clear();
    enc.encode(CharBuffer.wrap(msg), appBuffer, true);
    appBuffer.flip();
    result = serverEngine.wrap(appBuffer, snetBuffer);
    if (result.getStatus() != Status.OK)
      throw new SSLException("unexpected status: " + result.getStatus());
    snetBuffer.flip();
View Full Code Here


      try
      {
         CharBuffer cb = CharBuffer.wrap(source.toCharArray());
         Charset cs = Charset.forName(charSetName);
         CharsetEncoder cse = cs.newEncoder();
         ByteBuffer encoded = cse.encode(cb);
         return new String(encoded.array()).trim(); // Trim is very important!!!
      }
      catch (IllegalStateException e)
      {
         return null;
View Full Code Here

                }
                // 1 char -> UTF8
                buf.put(0,c);
                buf.rewind();
                try {
                    ByteBuffer bytes = enc.encode(buf);
                    while (bytes.hasRemaining()) {
                        byte b = bytes.get();
                        out.append('%');
                        out.append(toDigit((b >> 4) & 0xF));
                        out.append(toDigit(b & 0xF));
View Full Code Here

        CharsetEncoder outEncoder = outCharset.newEncoder();

        CharBuffer cb = inDecoder.decode(byteMapper);
        ByteBuffer outBuffer = null;
        try {
            outBuffer = outEncoder.encode(cb);

            RandomAccessFile outRandom = null;
            FileChannel outChannel = null;
            if (outFile != null) {
                try {
View Full Code Here

    {
        final CharsetEncoder encoder = getEncoder(charset);
        final ByteBuffer dst = ByteBuffer.allocate(
                (int) ((double) src.remaining() * encoder.maxBytesPerChar()));
        try {
            CoderResult cr = encoder.encode(src, dst, true);
            if (!cr.isUnderflow()) {
                cr.throwException();
            }
            cr = encoder.flush(dst);
            if (!cr.isUnderflow()) {
View Full Code Here

    if (replace) {
      encoder.onMalformedInput(CodingErrorAction.REPLACE);
      encoder.onUnmappableCharacter(CodingErrorAction.REPLACE);
    }
    ByteBuffer bytes =
      encoder.encode(CharBuffer.wrap(string.toCharArray()));
    if (replace) {
      encoder.onMalformedInput(CodingErrorAction.REPORT);
      encoder.onUnmappableCharacter(CodingErrorAction.REPORT);
    }
    return bytes;
View Full Code Here

    {
        checkWritable();
        try
        {
            CharsetEncoder encoder = Charset.forName("UTF-8").newEncoder();
            java.nio.ByteBuffer encodedString = encoder.encode(CharBuffer.wrap(string));
           
            _data.putShort((short)encodedString.limit());
            _data.put(encodedString);
            _changedData = true;
            //_data.putString(string, Charset.forName("UTF-8").newEncoder());
View Full Code Here

    if ( n == 0 && in.remaining() == 0 )
      return out;

    encoder.reset();
    while ( true ) {
      CoderResult cr = in.hasRemaining() ? encoder.encode(in, out, true) : CoderResult.UNDERFLOW;
      if ( cr.isUnderflow() )
        cr = encoder.flush(out);

      if ( cr.isUnderflow() )
        break;
View Full Code Here

    }

    private static ByteBuffer getUTF8BufferFromString(String s) {
  CharsetEncoder encoder = Charset.forName("UTF-8").newEncoder();
  try {
      return encoder.encode(CharBuffer.wrap(s));
  } catch (CharacterCodingException e) {
      return null;
  }
    }
View Full Code Here

      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

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.