Package java.nio.charset

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


        while (i < len && data[i] != '\'') i++;
        i++;
      } while (i < len && data[i] != ','); // word must end with "',"
     
      if (i >= len) break; // EOF
      String word = charset.decode(ByteBuffer.wrap(data, start, i-start-1)).toString();
//      String word = new String(data, 0, start, i-start-1); // ASCII
     
      /*
       * Part B: ignore phrases (with spaces and hyphens) and
       * non-alphabetic words, and let user customize word (e.g. do some
View Full Code Here


  /*
   * 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)
        + "efg");
  }
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

        // 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

   */
    @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

             */

            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 ("text/xml".equals(contentType)
View Full Code Here

      Charset charset = encodingToCharset.get(encoding);
      if (charset == null) {
        charset = Charset.forName(encoding);
        encodingToCharset.put(encoding, charset);
      }
      responseString = charset.decode(ByteBuffer.wrap(responseBytes)).toString();

      // Strip BOM if present
      if (responseString.length() > 0 && responseString.codePointAt(0) == 0xFEFF) {
        responseString = responseString.substring(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.