StringBuilder string = new StringBuilder(); while (readerState < taglength) { if ((c = br.read()) == -1) { if (openNextFile()) { logger.warn("Forced a skip (1: looking for open "+new String(startTag)+" tag) - is the collection corrupt or do the property tags exist?"); if ((c = br.read()) == -1) { if (openNextFile()) { logger.warn("Forced a skip (2: looking for end of "+new String(startTag)+" tag) - is the collection corrupt?");
if ((c = br.read()) == -1) {
/** 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(); }