Package java.nio

Examples of java.nio.CharBuffer.array()


  // convert byte array to char array, assuming UTF-8 encoding

  static protected char[] convertByteToCharUTF(byte[] byteArray) {
    Charset c = Charset.forName("UTF-8");
    CharBuffer output = c.decode(ByteBuffer.wrap(byteArray));
    return output.array();
  }

  // convert char array to byte array, assuming UTF-8 encoding
  static protected byte[] convertCharToByteUTF(char[] from) {
    Charset c = Charset.forName("UTF-8");
View Full Code Here


                        buf.flip();
                        buf.limit(buf.limit() - matchCount);

                        CharsetDecoder decoder = ctx.getDecoder();
                        CharBuffer buffer = decoder.decode(buf);
                        decoded = new String(buffer.array());
                    } else {
                        int overflowPosition = ctx.getOverflowLength();
                        throw new IllegalStateException("Line is too long: " + overflowPosition);
                    }
                } catch (CharacterCodingException cce) {
View Full Code Here

                            buf.flip();
                            buf.limit(buf.limit() - matchCount);

                            CharsetDecoder decoder = ctx.getDecoder();
                            CharBuffer buffer = decoder.decode(buf);
                            decoded = new String(buffer.array());
                        } else {
                            int overflowLength = ctx.getOverflowLength();
                            throw new IllegalStateException("Line is too long: " + overflowLength);
                        }
                    } catch (CharacterCodingException cce) {
View Full Code Here

                continue;
            char[] ch = Character.toChars(i);
            for (char c : ch)
                cb.append(c);
        }
        String s = new String(cb.array());
        byte[] arr = s.getBytes("UTF8");
        ByteBuffer buf = ByteBuffer.wrap(arr);
        UTF8Type.instance.validate(buf);
       
        // some you might not expect.
View Full Code Here

    this(bytes,Charset.forName(charset));
  }
 
  public ByteArrayCodepointIterator(byte[] bytes, Charset charset) {
    CharBuffer cb = charset.decode(ByteBuffer.wrap(bytes));
    buffer = cb.array();
    position = cb.position();
    limit = cb.limit();
  }

}
View Full Code Here

        if(extraChars.indexOf(def) != -1)
          throw new IllegalArgumentException("What do you want me to use instead of spaces???");
      }
    }

    for(char c : buffer.array()) { // Note that this will add extra whitespace to the end, which we will trim later.
     
      if(extraChars.indexOf(c) != -1) {
        sb.append(def);
        continue;
      }
View Full Code Here

        // that every file in existance is re-encoded.
        final Charset cs = Charset.forName("UTF-8");
        while (fc.read(buf) != -1) {
            buf.rewind();
            final CharBuffer chbuf = cs.decode(buf);
            sb.append(chbuf.array());
            buf.clear();
        }

        in.close();
        return sb.toString();
View Full Code Here

        // new String(byte[], int, int, Charset) takes a defensive copy of the
        // entire byte array. This is expensive if only a small subset of the
        // bytes will be used. The code below is from Apache Harmony.
        CharBuffer cb;
        cb = charset.decode(ByteBuffer.wrap(buff, start, end-start));
        return new String(cb.array(), cb.arrayOffset(), cb.length());
    }

    public int getInt()
    {
        return Ascii.parseInt(buff, start,end-start);
View Full Code Here

                }
                outputBuffer.flip();
                try {
                    boolean ok = false;
                    try {
                        writer.write(outputBuffer.array(), outputBuffer.arrayOffset(), outputBuffer.remaining());
                        ok = true;
                    } finally {
                        if (! ok) {
                            inputBuffer.clear();
                        }
View Full Code Here

        ((StringBuilder) csq).getChars(start, end, termBuffer, termLength);
      } else if (csq instanceof CharTermAttribute) {
        System.arraycopy(((CharTermAttribute) csq).buffer(), start, termBuffer, termLength, len);
      } else if (csq instanceof CharBuffer && ((CharBuffer) csq).hasArray()) {
        final CharBuffer cb = (CharBuffer) csq;
        System.arraycopy(cb.array(), cb.arrayOffset() + cb.position() + start, termBuffer, termLength, len);
      } else if (csq instanceof StringBuffer) {
        ((StringBuffer) csq).getChars(start, end, termBuffer, termLength);
      } else {
        while (start < end)
          termBuffer[termLength++] = csq.charAt(start++);
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.