protected EitherSide(InputStream is, OutputStream os) { cis = new CountingInputStream(is); flightRecorder = new FlightRecorderInputStream(cis); dis = new DataInputStream(flightRecorder); dos = new DataOutputStream(os); }
@Override public Void invoke(File dir, VirtualChannel channel) throws IOException, InterruptedException { try (InputStream in = archive.openStream()) { CountingInputStream cis = new CountingInputStream(in); try { if (archive.toExternalForm().endsWith(".zip")) { unzip(dir, cis); } else { readFromTar("input stream", dir, GZIP.extract(cis)); } } catch (IOException x) { throw new IOException(String.format("Failed to unpack %s (%d bytes read)", archive, cis.getByteCount()), x); } } return null; } }
private ARSCDecoder(InputStream arscStream, ResTable resTable, boolean storeFlagsOffsets, boolean keepBroken) { arscStream = mCountIn = new CountingInputStream(arscStream); if (storeFlagsOffsets) { mFlagsOffsets = new ArrayList<FlagsOffset>(); } else { mFlagsOffsets = null; } // We need to explicitly cast to DataInput as otherwise the constructor is ambiguous. // We choose DataInput instead of InputStream as ExtDataInput wraps an InputStream in // a DataInputStream which is big-endian and ignores the little-endian behavior. mIn = new ExtDataInput((DataInput) new LittleEndianDataInputStream(arscStream)); mResTable = resTable; mKeepBroken = keepBroken; }
sha512 != null ? new DigestOutputStream(_out, sha512) : _out, sha256) : _out, sha1) : _out; InputStream in = con.getInputStream(); CountingInputStream cin = new CountingInputStream(in)) { while ((len = cin.read(buf)) >= 0) { out.write(buf,0,len);
CountingInputStream cis = new CountingInputStream(in); try { if(archive.toExternalForm().endsWith(".zip"))
private CountingInputStream lzmaInputStream() throws IOException { in.position(bundle.header().headerSize()); return new CountingInputStream(new LzmaInputStream(in.stream())); }
@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 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 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 testLargeFiles_IO84() throws Exception { final long size = (long)Integer.MAX_VALUE + (long)1; final NullInputStream mock = new NullInputStream(size); final CountingInputStream cis = new CountingInputStream(mock); final OutputStream out = new NullOutputStream(); // Test integer methods IOUtils.copyLarge(cis, out); try { cis.getCount(); fail("Expected getCount() to throw an ArithmeticException"); } catch (final ArithmeticException ae) { // expected result } try { cis.resetCount(); fail("Expected resetCount() to throw an ArithmeticException"); } catch (final ArithmeticException ae) { // expected result } mock.close(); // Test long methods IOUtils.copyLarge(cis, out); assertEquals("getByteCount()", size, cis.getByteCount()); assertEquals("resetByteCount()", size, cis.resetByteCount()); }
@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(); }
new CountingInputStream(new LzmaInputStream(headerIn)));
WordlistZipReader( final InputStream inputStream ) throws PwmUnrecoverableException { checksumInputStream = new ChecksumInputStream( AbstractWordlist.CHECKSUM_HASH_ALG, inputStream ); countingInputStream = new CountingInputStream( checksumInputStream ); zipStream = new ZipInputStream( countingInputStream ); nextZipEntry(); if ( zipEntry == null ) { throw new IllegalStateException( "input stream does not contain any zip file entries" ); } }
protected void setupReader(InputStream is) { countingInputStream = new CountingInputStream(is); reader = new JsonReader(new InputStreamReader(countingInputStream)); reader.setLenient(true); setupIterator(reader); }
public PEFile parseExecutable(InputStream inputStream) throws IOException { try (CountingInputStream executableInputStream = new CountingInputStream(inputStream)) { final ImageDOSHeader imageDOSHeader = readDosHeader(executableInputStream); final byte[] realModeStubProgram = readRealModeStubProgram(executableInputStream, imageDOSHeader); final ImageNTHeaders imageNTHeaders = readImageNTHeaders(executableInputStream); final SectionHeader[] sectionHeaders = readSectionHeaders(executableInputStream, imageNTHeaders); final RsrcSection resourceSection = readResourceSection(executableInputStream, sectionHeaders); return new PEFile(imageDOSHeader, realModeStubProgram, imageNTHeaders, sectionHeaders, resourceSection); } }