Package org.apache.lucene.document.Field

Examples of org.apache.lucene.document.Field.ReusableStringReader


      // expected
    }
  }
 
  public void testReusableStringReader() throws Exception {
    ReusableStringReader reader = new ReusableStringReader();
    assertEquals(-1, reader.read());
    assertEquals(-1, reader.read(new char[1]));
    assertEquals(-1, reader.read(new char[2], 1, 1));
    assertEquals(-1, reader.read(CharBuffer.wrap(new char[2])));
   
    reader.setValue("foobar");
    char[] buf = new char[4];
    assertEquals(4, reader.read(buf));
    assertEquals("foob", new String(buf));
    assertEquals(2, reader.read(buf));
    assertEquals("ar", new String(buf, 0, 2));
    assertEquals(-1, reader.read(buf));
    reader.close();

    reader.setValue("foobar");
    assertEquals(0, reader.read(buf, 1, 0));
    assertEquals(3, reader.read(buf, 1, 3));
    assertEquals("foo", new String(buf, 1, 3));
    assertEquals(2, reader.read(CharBuffer.wrap(buf, 2, 2)));
    assertEquals("ba", new String(buf, 2, 2));
    assertEquals('r', (char) reader.read());
    assertEquals(-1, reader.read(buf));
    reader.close();

    reader.setValue("foobar");
    StringBuilder sb = new StringBuilder();
    int ch;
    while ((ch = reader.read()) != -1) {
      sb.append((char) ch);
    }
    reader.close();
    assertEquals("foobar", sb.toString());   
  }
View Full Code Here

TOP

Related Classes of org.apache.lucene.document.Field.ReusableStringReader

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.