Package java.nio

Examples of java.nio.CharBuffer


  /** @deprecated remove this test for Lucene 4.0 */
  @Deprecated
  public void testAllNullInputNIO() {
    byte[] binary = new byte[] { 0, 0, 0, 0, 0, 0, 0, 0, 0 };
    ByteBuffer binaryBuf = ByteBuffer.wrap(binary);
    CharBuffer encoded = IndexableBinaryStringTools.encode(binaryBuf);
    assertNotNull("encode() returned null", encoded);
    ByteBuffer decodedBuf = IndexableBinaryStringTools.decode(encoded);
    assertNotNull("decode() returned null", decodedBuf);
    assertEquals("Round trip decode/decode returned different results:"
                 + System.getProperty("line.separator")
View Full Code Here


  @Deprecated
  public void testRandomBinaryRoundTripNIO() {
    byte[] binary = new byte[MAX_RANDOM_BINARY_LENGTH];
    ByteBuffer binaryBuf = ByteBuffer.wrap(binary);
    char[] encoded = new char[IndexableBinaryStringTools.getEncodedLength(binaryBuf)];
    CharBuffer encodedBuf = CharBuffer.wrap(encoded);
    byte[] decoded = new byte[MAX_RANDOM_BINARY_LENGTH];
    ByteBuffer decodedBuf = ByteBuffer.wrap(decoded);
    for (int testNum = 0 ; testNum < NUM_RANDOM_TESTS ; ++testNum) {
      int numBytes = random.nextInt(MAX_RANDOM_BINARY_LENGTH - 1) + 1 ; // Min == 1
      binaryBuf.limit(numBytes);
View Full Code Here

      assertEquals(s1.compareTo(s2) < 0, comp.compare(b1, b2) < 0);
    }
  }

  private String getRandomString(Random r) {
    CharBuffer chars = CharBuffer.allocate(10);
    while (chars.hasRemaining()) {
      chars.append((char) r.nextInt());
    } // Round-triping the data so as to transform out any invalid sequences
    return UTF_8.decode(UTF_8.encode(chars)).toString();
  }
View Full Code Here

    throws IOException
    {
      Reader reader = null;
      try {
          StringBuilder sb = new StringBuilder();
          CharBuffer buffer = CharBuffer.allocate(65535);
        reader = new InputStreamReader(new FileInputStream(aFile), aEncoding);
        while (reader.ready()) {
          reader.read(buffer);
          buffer.flip();
          sb.append(buffer.toString());
        }
        return sb.toString();
      }
      finally {
        close(reader);
View Full Code Here

    public void write( byte[] buf, int off, int len )
        throws IOException
    {
        if ( !Charset.defaultCharset().equals( UTF8 ) )
        {
            CharBuffer decodedFromDefaultCharset = Charset.defaultCharset().decode( ByteBuffer.wrap( buf, off, len ) );
            ByteBuffer utf8Encoded = UTF8.encode( decodedFromDefaultCharset );

            if ( utf8Encoded.hasArray() )
            {
                byte[] convertedBytes = utf8Encoded.array();
View Full Code Here

        StringBuilder stringBuilder = context.getBuffer();

        while (buffer.hasRemaining()) {
          boolean hasEnded = filterUntilEndNode();

          CharBuffer decoded = decoder.decode(filteredBuffer);
          logger.trace("Reading: \n" + decoded);
          stringBuilder.append(decoded);
          if (hasEnded) {
            endNode(stringBuilder, context);
          }
View Full Code Here

   * @param to the object to write to
   * @return the number of characters copied
   * @throws IOException if an I/O error occurs
   */
  public static long copy(Readable from, Appendable to) throws IOException {
    CharBuffer buf = CharBuffer.allocate(BUF_SIZE);
    long total = 0;
    while (true) {
      int r = from.read(buf);
      if (r == -1) {
        break;
      }
      buf.flip();
      to.append(buf, 0, r);
      total += r;
    }
    return total;
  }
View Full Code Here

            runPerfTest(repeat, x++, config, pb);
            System.out.printf(" took %.1f seconds%n", (System.nanoTime() - t1)
                    / (1000.0 * 1000.0 * 1000.0));

            FileReader reader = new FileReader(config._temp);
            CharBuffer buffer = CharBuffer.allocate(256 * 1024);
            reader.read(buffer);
            reader.close();
            config._temp.delete();
            buffer.flip();

            String raw = buffer.toString();
            System.out.print(raw);
            Stats stats = new Stats(raw);
            System.out.println(stats);
            System.out.println("-----");
            config._stats = stats;
View Full Code Here

                        // It's in the range, so process the file
                        RandomAccessFile raf = new RandomAccessFile(logFiles[i], "r");
                        FileChannel fc = raf.getChannel();
                        MappedByteBuffer bb = fc.map(FileChannel.MapMode.READ_ONLY, 0, fc.size());
                        CharBuffer cb = Charset.forName("US-ASCII").decode(bb); //todo: does Tomcat use a different charset on a foreign PC?
                        Matcher lines = FULL_LINE_PATTERN.matcher(cb);
                        Matcher target = ACCESS_LOG_PATTERN.matcher("");
                        SimpleDateFormat format = (start == 0 && end == 0) ? null : new SimpleDateFormat(ACCESS_LOG_DATE_FORMAT);
                        int max = maxResults == null ? MAX_SEARCH_RESULTS : Math.min(maxResults.intValue(), MAX_SEARCH_RESULTS);

                        while(lines.find()) {
                            ++lineCount;
                            ++fileLineCount;
                            if(capped) {
                                continue;
                            }
                            CharSequence line = cb.subSequence(lines.start(), lines.end());
                            target.reset(line);
                            if(target.find()) {
                                if(host != null && !host.equals(target.group(GROUP_HOST))) {
                                    continue;
                                }
View Full Code Here

        int lineCount = 0;
        try {
            RandomAccessFile raf = new RandomAccessFile(file, "r");
            FileChannel fc = raf.getChannel();
            MappedByteBuffer bb = fc.map(FileChannel.MapMode.READ_ONLY, 0, fc.size());
            CharBuffer cb = Charset.forName("US-ASCII").decode(bb); //todo: does Log4J use a different charset on a foreign PC?
            Matcher target = null;
            Matcher any = null;
            Matcher lines = FULL_LINE_PATTERN.matcher(cb);
            Matcher text = textSearch == null ? null : textSearch.matcher("");
            boolean hit = false;
            max = Math.min(max, MAX_SEARCH_RESULTS);
            while(lines.find()) {
                ++lineCount;
                if(target == null) {
                    if(DEFAULT_ANY_START.matcher(cb.subSequence(lines.start(), lines.end())).find()) {
                        target = getDefaultPatternForLevel(targetLevel).matcher("");
                        any = DEFAULT_ANY_START.matcher("");
                    } else {
                        target = getUnknownPatternForLevel(targetLevel).matcher("");
                        any = UNKNOWN_ANY_START.matcher("");
                    }
                }
                if(start != null && start.intValue() > lineCount) {
                    continue;
                }
                if(stop != null && stop.intValue() < lineCount) {
                    continue;
                }
                CharSequence line = cb.subSequence(lines.start(), lines.end());
                target.reset(line);
                if(target.find()) {
                    if(text != null) {
                        text.reset(line);
                        if(!text.find()) {
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.