@Override public void close() throws IOException { closed = true; if (lzma != null) { lzma.close(); } in.close(); } }
@Test public void testZeroLength1() throws Exception { final ByteArrayInputStream bais = new ByteArrayInputStream(new byte[0]); final CountingInputStream cis = new CountingInputStream(bais); final int found = cis.read(); assertEquals(-1, found); assertEquals(0, cis.getCount()); cis.close(); }
@Test public void testZeroLength2() throws Exception { final ByteArrayInputStream bais = new ByteArrayInputStream(new byte[0]); final CountingInputStream cis = new CountingInputStream(bais); final byte[] result = new byte[10]; final int found = cis.read(result); assertEquals(-1, found); assertEquals(0, cis.getCount()); cis.close(); }
@Test public void testZeroLength3() throws Exception { final ByteArrayInputStream bais = new ByteArrayInputStream(new byte[0]); final CountingInputStream cis = new CountingInputStream(bais); final byte[] result = new byte[10]; final int found = cis.read(result, 0, 5); assertEquals(-1, found); assertEquals(0, cis.getCount()); cis.close(); }
@Test public void testEOF2() throws Exception { final ByteArrayInputStream bais = new ByteArrayInputStream(new byte[2]); final CountingInputStream cis = new CountingInputStream(bais); final byte[] result = new byte[10]; final int found = cis.read(result); assertEquals(2, found); assertEquals(2, cis.getCount()); cis.close(); }
@Test public void testEOF3() throws Exception { final ByteArrayInputStream bais = new ByteArrayInputStream(new byte[2]); final CountingInputStream cis = new CountingInputStream(bais); final byte[] result = new byte[10]; final int found = cis.read(result, 0, 5); assertEquals(2, found); assertEquals(2, cis.getCount()); cis.close(); }
@Test public void testSkipping() throws IOException { final String text = "Hello World!"; final byte[] bytes = text.getBytes(); final ByteArrayInputStream bais = new ByteArrayInputStream(bytes); final CountingInputStream cis = new CountingInputStream(bais); assertEquals(6,cis.skip(6)); assertEquals(6,cis.getCount()); final byte[] result = new byte[6]; cis.read(result); assertEquals("World!",new String(result)); assertEquals(12,cis.getCount()); cis.close(); }
@Test public void testResetting() throws Exception { final String text = "A piece of text"; final byte[] bytes = text.getBytes(); final ByteArrayInputStream bais = new ByteArrayInputStream(bytes); final CountingInputStream cis = new CountingInputStream(bais); final byte[] result = new byte[bytes.length]; int found = cis.read(result, 0, 5); assertEquals( found, cis.getCount() ); final int count = cis.resetCount(); found = cis.read(result, 6, 5); assertEquals( found, count ); cis.close(); }
@Test public void testCounting() throws Exception { final String text = "A piece of text"; final byte[] bytes = text.getBytes(); final ByteArrayInputStream bais = new ByteArrayInputStream(bytes); final CountingInputStream cis = new CountingInputStream(bais); // have to declare this larger as we're going to read // off the end of the stream and input stream seems // to do bounds checking final byte[] result = new byte[21]; final byte[] ba = new byte[5]; int found = cis.read(ba); System.arraycopy(ba, 0, result, 0, 5); assertEquals( found, cis.getCount() ); final int value = cis.read(); found++; result[5] = (byte)value; assertEquals( found, cis.getCount() ); found += cis.read(result, 6, 5); assertEquals( found, cis.getCount() ); found += cis.read(result, 11, 10); // off the end assertEquals( found, cis.getCount() ); // trim to get rid of the 6 empty values final String textResult = new String(result).trim(); assertEquals(textResult, text); cis.close(); }
@Test public void testEOF1() throws Exception { final ByteArrayInputStream bais = new ByteArrayInputStream(new byte[2]); final CountingInputStream cis = new CountingInputStream(bais); int found = cis.read(); assertEquals(0, found); assertEquals(1, cis.getCount()); found = cis.read(); assertEquals(0, found); assertEquals(2, cis.getCount()); found = cis.read(); assertEquals(-1, found); assertEquals(2, cis.getCount()); cis.close(); }
private InputStream dataInputStream(long offset, long size) throws IOException { InputStream is; // use LZMA stream if the bundle is compressed if (bundle.header().compressed()) { // create initial input stream if required if (lzma == null) { lzma = lzmaInputStream(); } // recreate stream if the offset is behind long lzmaOffset = lzma.getByteCount(); if (lzmaOffset > offset) { lzma.close(); lzma = lzmaInputStream(); } // skip forward if required if (lzmaOffset < offset) { lzma.skip(offset - lzmaOffset); } is = lzma; } else { in.position(bundle.header().headerSize() + offset); is = in.stream(); } return new BoundedInputStream(is, size); }
@Override public void close() throws IOException { fsin.close(); }
@Override public void close() throws IOException { fsin.close(); }
public void close() throws IOException { countingIs.close(); }
@Override public void close() throws IOException { reader.close(); countingInputStream.close(); }
cin.close(); } catch (IOException e) { httpUrlConn.disconnect();
cin.close(); } catch (IOException e) { httpUrlConn.disconnect();
cin.close(); } catch (IOException e) { httpUrlConn.disconnect();
public void close() throws IOException { downloader.setVisible(false); downloader.dispose(); is.close(); }
in.close(); out.close();