Package java.nio.charset

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


      try {
        Charset charset = Charset.forName(charsetName);
        TransferEncoding encoding = TransferEncoding.headerWordEncoding(encodingName);
        byte[] encodedBytes = data.getBytes("US-ASCII");
        ByteBuffer decodedBytes = encoding.decode(ByteBuffer.wrap(encodedBytes));
        result.append(charset.decode(decodedBytes));
      }
      catch (Exception e) {
        result.append(matcher.group());
      }
View Full Code Here


    }

    try {
      TransferEncoding encoding = TransferEncoding.bodyEncoding(encodingName);
      ByteBuffer decodedBytes = encoding.decode(bytes);
      text = bodyCharset.decode(decodedBytes).toString();
    }
    catch (Exception e) {
      text = bodyCharset.decode(bytes).toString();
    }
View Full Code Here

      TransferEncoding encoding = TransferEncoding.bodyEncoding(encodingName);
      ByteBuffer decodedBytes = encoding.decode(bytes);
      text = bodyCharset.decode(decodedBytes).toString();
    }
    catch (Exception e) {
      text = bodyCharset.decode(bytes).toString();
    }

    this.text = parseNNTPQuotesToBBCode(this.text);
  }
View Full Code Here

    headBytes = bytes.slice();

    // First try decoding headers as UTF-8.

    Charset utf8 = Charset.forName("UTF-8");
    String headUTF8 = utf8.decode(headBytes).toString();
    String[] headLines = headUTF8.split("\r?\n");

    // Read Newsgroups, Followup-To, and References headers
    String newsgroupsHeader = getHeader(headLines, "newsgroups");
    String followupToHeader = getHeader(headLines, "followup-to");
View Full Code Here

    catch (IllegalArgumentException e) {
      bodyCharset = Charset.forName("UTF-8");
    }

    headBytes.rewind();
    String head = bodyCharset.decode(headBytes).toString();
    headLines = head.split("\r?\n");

    // Read From and Subject headers using the body charset
    String fromHeader = getHeader(headLines, "from");
    String subjectHeader = getHeader(headLines, "subject");
View Full Code Here

           
            Charset utf8 = Charset.forName("UTF-8");

            printStatusLine("200 Welcome to Freetalk");
            while (!mSocket.isClosed()) {
                final String line = utf8.decode(readLineBytes(is)).toString();
               
                if(logDEBUG) Logger.debug(this, "Received NNTP command: " + line);
               
                synchronized(this) {
                  if (beginCommand(line)) {
View Full Code Here

            }
           
            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);
           
            // For a one-way message or whatever, there may not be a content type.
            // throw away any encoding modifier.
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

        // start + length could overflow, start/length maybe MaxInt
        if (start >= 0 && 0 <= length && length <= data.length - start) {
            offset = 0;
            Charset charset = defaultCharset();
            int result;
            CharBuffer cb = charset
                    .decode(ByteBuffer.wrap(data, start, length));
            if ((result = cb.length()) > 0) {
                value = cb.array();
                count = result;
            } else {
View Full Code Here

            Charset charset = getCharset(encoding);

            int result;
          CharBuffer cb;
            try {
              cb = charset.decode(ByteBuffer.wrap(data, start, length));
            } catch (Exception e) {
              // do nothing. according to spec:
              // behavior is unspecified for invalid array
              cb = CharBuffer.wrap("\u003f".toCharArray()); //$NON-NLS-1$
            }
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.