protected void openNewFile() throws Exception { if (is instanceof CountingInputStream) br = (CountingInputStream) is; else br = new CountingInputStream(is); }
/** * A constructor that reads only the document in the specificed * InputStream. Also reads a list of blacklisted document numbers, specified by the * property <tt>trec.blacklist.docids</tt> and opens the * first collection file to process. */ public TRECCollection(InputStream input) { super(input instanceof CountingInputStream ? (CountingInputStream)input : new CountingInputStream(input)); loadDocumentClass(); setTags(TagSet.TREC_DOC_TAGS); readDocumentBlacklist(ApplicationSetup.makeAbsolute( ApplicationSetup.getProperty("trec.blacklist.docids", ""), ApplicationSetup.TERRIER_ETC)); documentsInThisFile = 0; } /**
/** Test that constructor offsets work */ @Test public void testConstructor() throws Exception { CountingInputStream cis; cis = new CountingInputStream(NULL_INPUTSTREAM, 5l); assertEquals(5l, cis.getPos()); cis.close(); cis = new CountingInputStream(NULL_INPUTSTREAM, 500000000000l); assertEquals(500000000000l, cis.getPos()); cis.close(); }
/** Test that single byte reads have the desired effect on counting */ @Test public void testSingleByteReads() throws Exception { ByteArrayInputStream bais = new ByteArrayInputStream(TEST_ARRAY); CountingInputStream cis = new CountingInputStream(bais); assertEquals((long)0, cis.getPos()); for(long i=0;i < TEST_ARRAY.length;i++) { assertEquals(i, cis.getPos()); int b = cis.read(); assertEquals((byte)b, TEST_ARRAY[(int)i]); assertEquals(i+1, cis.getPos()); } assertEquals(TEST_ARRAY.length, cis.getPos()); assertEquals(-1, cis.read()); assertEquals(TEST_ARRAY.length, cis.getPos()); cis.close(); }
/** Test that reads using array offsets work as expected */ @Test public void testOffsetByteReads() throws Exception { ByteArrayInputStream bais = new ByteArrayInputStream(TEST_ARRAY); CountingInputStream cis = new CountingInputStream(bais); assertEquals((long)0, cis.getPos()); for(long i=0;i < TEST_ARRAY.length / 2;i++) { assertEquals(i*2, cis.getPos()); final byte[] read = new byte[2]; final int rtr = cis.read(read, 0, read.length); assertEquals(rtr, read.length); assertEquals(read[0], TEST_ARRAY[(int)i*2]); assertEquals(read[1], TEST_ARRAY[(int)(i*2)+1]); assertEquals("offset after read i="+i+"; ", (i*2)+read.length, cis.getPos()); } assertEquals(TEST_ARRAY.length, cis.getPos()); assertEquals(-1, cis.read()); assertEquals(TEST_ARRAY.length, cis.getPos()); cis.close(); }
/** Test that two byte reads have the desired effect on counting */ @Test public void testTwoByteReads() throws Exception { ByteArrayInputStream bais = new ByteArrayInputStream(TEST_ARRAY); CountingInputStream cis = new CountingInputStream(bais); assertEquals((long)0, cis.getPos()); for(long i=0;i < TEST_ARRAY.length / 2;i++) { assertEquals(i*2, cis.getPos()); final byte[] read = new byte[2]; final int rtr = cis.read(read); assertEquals(rtr, read.length); assertEquals(read[0], TEST_ARRAY[(int)i*2]); assertEquals(read[1], TEST_ARRAY[(int)(i*2)+1]); assertEquals("offset after read i="+i+"; ", (i*2)+read.length, cis.getPos()); } assertEquals(TEST_ARRAY.length, cis.getPos()); assertEquals(-1, cis.read()); assertEquals(TEST_ARRAY.length, cis.getPos()); cis.close(); }