List of usage examples for org.apache.commons.io.input CountingInputStream CountingInputStream
public CountingInputStream(InputStream in)
From source file:com.playonlinux.win32.pe.PEReader.java
public static 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); }/*ww w.j a v a2 s .co m*/ }
From source file:fm.last.moji.impl.FileDownloadInputStream.java
FileDownloadInputStream(InputStream delegate, Lock readLock) { this.readLock = readLock; this.delegate = new CountingInputStream(delegate); }
From source file:com.netflix.aegisthus.io.sstable.IndexDatabaseScanner.java
public IndexDatabaseScanner(@Nonnull InputStream is) { this.countingInputStream = new CountingInputStream(is); this.input = new DataInputStream(this.countingInputStream); }
From source file:com.guye.baffle.decoder.ArscData.java
public static ArscData decode(File file) throws IOException { FileInputStream arscStream = new FileInputStream(file); CountingInputStream countIn;//from www . ja va 2s . c o m countIn = new CountingInputStream(arscStream); ExtDataInput in = new ExtDataInput(new LEDataInputStream(countIn)); ArscData arscData = readTable(file, countIn, in); countIn.close(); arscStream.close(); return arscData; }
From source file:com.cloudera.sqoop.io.FixedLengthInputStream.java
public FixedLengthInputStream(InputStream stream, long maxLen) { super(new CountingInputStream(new CloseShieldInputStream(stream))); // Save a correctly-typed reference to the underlying stream. this.countingIn = (CountingInputStream) this.in; this.maxBytes = maxLen; }
From source file:com.google.code.jahath.common.io.SwappableInputStreamTest.java
@Test public void test() throws Throwable { final SwappableInputStream swappableInputStream = new SwappableInputStream("test"); final CRC actualCRC = new CRC(); final AtomicReference<Throwable> thrown = new AtomicReference<Throwable>(); Thread thread = new Thread(new Runnable() { public void run() { try { actualCRC.update(swappableInputStream); } catch (Throwable ex) { thrown.set(ex);//from w w w . j a v a2s . co m } } }); thread.start(); Random random = new Random(); CRC expectedCRC = new CRC(); for (int i = 0; i < 100; i++) { int len = 2048 + random.nextInt(4096); byte[] data = new byte[len]; random.nextBytes(data); expectedCRC.update(data); CountingInputStream in = new CountingInputStream(new ByteArrayInputStream(data)); swappableInputStream.swap(in); // Check that the stream has been consumed entirely Assert.assertEquals(len, in.getCount()); } swappableInputStream.sendEndOfStream(); thread.join(); if (thrown.get() != null) { throw thrown.get(); } Assert.assertEquals(expectedCRC.getValue(), actualCRC.getValue()); }
From source file:com.izforge.izpack.installer.web.LoggedInputStream.java
public LoggedInputStream(InputStream is, WebAccessor webAccessor) { if (is == null) { throw new RuntimeException("Unable to connect"); }/* w w w.jav a 2 s . c o m*/ this.is = new CountingInputStream(is); String sizeStr; if (webAccessor.getContentLength() > 0) { sizeStr = "(" + Pack.toByteUnitsString(webAccessor.getContentLength()) + ")"; } else { sizeStr = ""; } downloader = new DownloadPanel(this); downloader.setTitle("Downloading"); downloader.setFileLabel(webAccessor.getUrl() + " " + sizeStr); downloader.setLocationRelativeTo(null); downloader.setVisible(true); if (webAccessor.getContentLength() > 0) { downloader.setProgressMax(webAccessor.getContentLength()); downloader.setProgressCurrent(0); } }
From source file:brut.androlib.res.decoder.ARSCDecoder.java
private ARSCDecoder(InputStream arscStream, ResTable resTable, boolean storeFlagsOffsets, boolean keepBroken) { if (storeFlagsOffsets) { arscStream = mCountIn = new CountingInputStream(arscStream); mFlagsOffsets = new ArrayList<FlagsOffset>(); } else {// w w w . j a v a 2 s .c o m mCountIn = null; mFlagsOffsets = null; } mIn = new ExtDataInput(new LEDataInputStream(arscStream)); mResTable = resTable; mKeepBroken = keepBroken; }
From source file:com.liferay.sync.engine.document.library.handler.DownloadFilesHandler.java
@Override protected void doHandleResponse(HttpResponse httpResponse) throws Exception { long syncAccountId = getSyncAccountId(); final Session session = SessionManager.getSession(syncAccountId); Header header = httpResponse.getFirstHeader("Sync-JWT"); if (header != null) { session.addHeader("Sync-JWT", header.getValue()); }//w w w . j a va 2s . co m Map<String, DownloadFileHandler> handlers = (Map<String, DownloadFileHandler>) getParameterValue( "handlers"); InputStream inputStream = null; try { HttpEntity httpEntity = httpResponse.getEntity(); inputStream = new CountingInputStream(httpEntity.getContent()) { @Override protected synchronized void afterRead(int n) { session.incrementDownloadedBytes(n); super.afterRead(n); } }; inputStream = new RateLimitedInputStream(inputStream, syncAccountId); ZipInputStream zipInputStream = new ZipInputStream(inputStream); ZipEntry zipEntry = null; while ((zipEntry = zipInputStream.getNextEntry()) != null) { String zipEntryName = zipEntry.getName(); if (zipEntryName.equals("errors.json")) { JsonNode rootJsonNode = JSONUtil.readTree(new CloseShieldInputStream(zipInputStream)); Iterator<Map.Entry<String, JsonNode>> fields = rootJsonNode.fields(); while (fields.hasNext()) { Map.Entry<String, JsonNode> field = fields.next(); Handler<Void> handler = handlers.remove(field.getKey()); JsonNode valueJsonNode = field.getValue(); JsonNode exceptionJsonNode = valueJsonNode.get("exception"); handler.handlePortalException(exceptionJsonNode.textValue()); } break; } DownloadFileHandler downloadFileHandler = handlers.get(zipEntryName); if (downloadFileHandler == null) { continue; } SyncFile syncFile = (SyncFile) downloadFileHandler.getParameterValue("syncFile"); if (downloadFileHandler.isUnsynced(syncFile)) { handlers.remove(zipEntryName); continue; } if (_logger.isTraceEnabled()) { _logger.trace("Handling response {} file path {}", DownloadFileHandler.class.getSimpleName(), syncFile.getFilePathName()); } try { downloadFileHandler.copyFile(syncFile, Paths.get(syncFile.getFilePathName()), new CloseShieldInputStream(zipInputStream), false); } catch (Exception e) { if (!isEventCancelled()) { _logger.error(e.getMessage(), e); downloadFileHandler.removeEvent(); FileEventUtil.downloadFile(getSyncAccountId(), syncFile, false); } } finally { handlers.remove(zipEntryName); downloadFileHandler.removeEvent(); } } } catch (Exception e) { if (!isEventCancelled()) { _logger.error(e.getMessage(), e); retryEvent(); } } finally { StreamUtil.cleanUp(inputStream); } }
From source file:eu.delving.sip.files.FileImporter.java
@Override public void run() { int fileBlocks = (int) (inputFile.length() / BLOCK_SIZE); progressListener.prepareFor(fileBlocks); try {/*from w w w . java 2 s . c o m*/ OutputStream outputStream = new GZIPOutputStream(new FileOutputStream(dataSet.importedOutput())); InputStream inputStream = new FileInputStream(inputFile); inputStream = countingInputStream = new CountingInputStream(inputStream); try { String name = inputFile.getName(); if (name.endsWith(".csv")) { consumeCSVFile(inputStream, outputStream); } else if (name.endsWith(".xml.zip")) { consumeXMLZipFile(inputStream, outputStream); } else if (name.endsWith(".xml") || name.endsWith(".xml.gz")) { if (name.endsWith(".xml.gz")) inputStream = new GZIPInputStream(inputStream); consumeXMLFile(inputStream, outputStream); } else { throw new IllegalArgumentException("Unrecognized file extension: " + name); } } finally { IOUtils.closeQuietly(outputStream); IOUtils.closeQuietly(inputStream); } delete(statsFile(dataSet.importedOutput().getParentFile(), false, null)); if (finished != null) finished.run(); } catch (CancelException e) { delete(dataSet.importedOutput()); progressListener.getFeedback().alert("Cancelled", e); } catch (IOException e) { delete(dataSet.importedOutput()); progressListener.getFeedback().alert("Unable to import: " + e.getMessage(), e); } }