Package java.nio

Examples of java.nio.CharBuffer


        final StringBuilder builder = new StringBuilder();
        final FileInputStream input = new FileInputStream(new File(dataDirectory, filename));
        try {
            final InputStreamReader reader = new InputStreamReader(input);
            final BufferedReader bufferedReader = new BufferedReader(reader);
            final CharBuffer buf = CharBuffer.allocate(1024);
            while (bufferedReader.read(buf) != -1) {
                buf.flip();
                builder.append(buf);
                buf.clear();
            }
        } finally {
            input.close();
        }
        return builder.toString();
View Full Code Here


        assert status != null;
        LOG.warn(status.toString());
    }

    private int getNextCharacter() throws IOException {
        CharBuffer buf = readerBuffer;
        if (buf.remaining() == 0) {
            buf.clear();
            int read = reader.read(buf);
            buf.flip();
            assert read != 0;
            if (read < 0) {
                return EOF;
            }
        }
        return buf.get();
    }
View Full Code Here

        }
        return buf.get();
    }

    private void rewindCharacter() {
        CharBuffer buf = readerBuffer;
        assert buf.position() > 0;
        buf.position(buf.position() - 1);
    }
View Full Code Here

        buf.position(buf.position() - 1);
    }

    private void emit(int c) throws IOException {
        assert c >= 0;
        CharBuffer buf = lineBuffer;
        if (buf.remaining() == 0) {
            if (buf.capacity() == BUFFER_LIMIT) {
                throw new IOException(MessageFormat.format(
                        "Line is too large (near {0}:{1}, size={2}, record-number={3})",
                        path,
                        currentPhysicalHeadLine,
                        BUFFER_LIMIT,
                        currentRecordNumber));
            }
            CharBuffer newBuf = CharBuffer.allocate(Math.min(buf.capacity() * 2, BUFFER_LIMIT));
            newBuf.clear();
            buf.flip();
            newBuf.put(buf);
            buf = newBuf;
            lineBuffer = newBuf;
        }
        buf.put((char) c);
    }
View Full Code Here

        if (value == null || String.valueOf(value).isEmpty()) {
            return null;
        }
        if (value instanceof Clob) {
            final StringBuilder sb = new StringBuilder(1024);
            final CharBuffer cbuf = CharBuffer.allocate(1024);
            try {
                final Reader rdr = ((Clob) value).getCharacterStream();
                while (rdr.read(cbuf) >= 0) {
                    cbuf.rewind();
                    sb.append(cbuf);
                    cbuf.rewind();
                }
            } catch (IOException e) {
                throw new ConversionException("Error reading from clob", e);
            } catch (SQLException e) {
                throw new ConversionException("Error reading from clob", e);
View Full Code Here

      return null;
    }
    FileReader fr = null;
    try {
      fr = new FileReader(lastMessage);
      CharBuffer cb = CharBuffer.allocate(Internals.ltoi(lastMessage.length()));
      fr.read(cb);
      return cb.flip().toString();
    } catch (IOException ex) {
      throw new HgInvalidControlFileException("Can't retrieve message of last commit attempt", ex, lastMessage);
    } finally {
      new FileUtils(getSessionContext().getLog(), this).closeQuietly(fr, lastMessage);
    }
View Full Code Here

    }
    Process p = pb.start();
    InputStreamReader stdOut = new InputStreamReader(p.getInputStream());
    LinkedList<CharBuffer> l = new LinkedList<CharBuffer>();
    int r = -1;
    CharBuffer b = null;
    do {
      if (b == null || b.remaining() < b.capacity() / 3) {
        b = CharBuffer.allocate(512);
        l.add(b);
      }
      r = stdOut.read(b);
    } while (r != -1);
    int total = 0;
    for (CharBuffer cb : l) {
      total += cb.position();
      cb.flip();
    }
    CharBuffer res = CharBuffer.allocate(total);
    for (CharBuffer cb : l) {
      res.put(cb);
    }
    res.flip();
    p.waitFor();
    exitValue = p.exitValue();
    return res;
  }
View Full Code Here

    byte[] binary = new byte[]
      { (byte)0x23, (byte)0x98, (byte)0x13, (byte)0xE4, (byte)0x76, (byte)0x41,
        (byte)0xB2, (byte)0xC9, (byte)0x7F, (byte)0x0A, (byte)0xA6, (byte)0xD8 };

    ByteBuffer binaryBuf = ByteBuffer.wrap(binary);
    CharBuffer encoded = IndexableBinaryStringTools.encode(binaryBuf);
    ByteBuffer decoded = IndexableBinaryStringTools.decode(encoded);
    assertEquals("Round trip decode/decode returned different results:"
                 + System.getProperty("line.separator")
                 + "original: " + binaryDumpNIO(binaryBuf)
                 + System.getProperty("line.separator")
View Full Code Here

  @Deprecated
  public void testEncodedSortabilityNIO() {
    byte[] originalArray1 = new byte[MAX_RANDOM_BINARY_LENGTH];
    ByteBuffer originalBuf1 = ByteBuffer.wrap(originalArray1);
    char[] originalString1 = new char[MAX_RANDOM_BINARY_LENGTH];
    CharBuffer originalStringBuf1 = CharBuffer.wrap(originalString1);
    char[] encoded1 = new char[IndexableBinaryStringTools.getEncodedLength(originalBuf1)];
    CharBuffer encodedBuf1 = CharBuffer.wrap(encoded1);
    byte[] original2 = new byte[MAX_RANDOM_BINARY_LENGTH];
    ByteBuffer originalBuf2 = ByteBuffer.wrap(original2);
    char[] originalString2 = new char[MAX_RANDOM_BINARY_LENGTH];
    CharBuffer originalStringBuf2 = CharBuffer.wrap(originalString2);
    char[] encoded2 = new char[IndexableBinaryStringTools.getEncodedLength(originalBuf2)];
    CharBuffer encodedBuf2 = CharBuffer.wrap(encoded2);
    for (int testNum = 0 ; testNum < NUM_RANDOM_TESTS ; ++testNum) {
      int numBytes1 = random.nextInt(MAX_RANDOM_BINARY_LENGTH - 1) + 1; // Min == 1
      originalBuf1.limit(numBytes1);
      originalStringBuf1.limit(numBytes1);
     
View Full Code Here

  /** @deprecated remove this test for Lucene 4.0 */
  @Deprecated
  public void testEmptyInputNIO() {
    byte[] binary = new byte[0];
    CharBuffer encoded = IndexableBinaryStringTools.encode(ByteBuffer.wrap(binary));
    ByteBuffer decoded = IndexableBinaryStringTools.decode(encoded);
    assertNotNull("decode() returned null", decoded);
    assertEquals("decoded empty input was not empty", decoded.limit(), 0);
  }
View Full Code Here

TOP

Related Classes of java.nio.CharBuffer

Copyright © 2018 www.massapicom. 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.