List of usage examples for org.apache.commons.io.input CountingInputStream close
public void close() throws IOException
close()
method. From source file:com.guye.baffle.decoder.ArscData.java
public static ArscData decode(File file) throws IOException { FileInputStream arscStream = new FileInputStream(file); CountingInputStream countIn; countIn = new CountingInputStream(arscStream); ExtDataInput in = new ExtDataInput(new LEDataInputStream(countIn)); ArscData arscData = readTable(file, countIn, in); countIn.close(); arscStream.close();// ww w.ja v a2 s. co m return arscData; }
From source file:ch.cyberduck.core.dav.DAVReadFeatureTest.java
@Test public void testReadCloseReleaseEntity() throws Exception { final Host host = new Host(new DAVSSLProtocol(), "svn.cyberduck.ch", new Credentials(PreferencesFactory.get().getProperty("connection.login.anon.name"), null)); final DAVSession session = new DAVSession(host); session.open(new DisabledHostKeyCallback()); session.login(new DisabledPasswordStore(), new DisabledLoginCallback(), new DisabledCancelCallback()); final TransferStatus status = new TransferStatus(); final Path test = new Path("/trunk/LICENSE.txt", EnumSet.of(Path.Type.file)); final CountingInputStream in = new CountingInputStream( new DAVReadFeature(session).read(test, status, new DisabledConnectionCallback())); in.close(); assertEquals(0L, in.getByteCount(), 0L); session.close();/* w ww . j a v a 2 s .co m*/ }
From source file:ch.cyberduck.core.sds.SDSReadFeatureTest.java
@Test public void testReadCloseReleaseEntity() throws Exception { final Host host = new Host(new SDSProtocol(), "duck.ssp-europe.eu", new Credentials( System.getProperties().getProperty("sds.user"), System.getProperties().getProperty("sds.key"))); final SDSSession session = new SDSSession(host, new DisabledX509TrustManager(), new DefaultX509KeyManager()); session.open(new DisabledHostKeyCallback()); session.login(new DisabledPasswordStore(), new DisabledLoginCallback(), new DisabledCancelCallback()); final TransferStatus status = new TransferStatus(); final byte[] content = RandomUtils.nextBytes(32769); final TransferStatus writeStatus = new TransferStatus(); writeStatus.setLength(content.length); final Path room = new SDSDirectoryFeature(session) .mkdir(new Path(new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory, Path.Type.volume)), null, new TransferStatus()); final Path test = new Path(room, UUID.randomUUID().toString(), EnumSet.of(Path.Type.file)); final SDSWriteFeature writer = new SDSWriteFeature(session); final HttpResponseOutputStream<VersionId> out = writer.write(test, writeStatus, new DisabledConnectionCallback()); assertNotNull(out);/*from ww w . ja v a 2s .co m*/ new StreamCopier(writeStatus, writeStatus).transfer(new ByteArrayInputStream(content), out); final CountingInputStream in = new CountingInputStream( new SDSReadFeature(session).read(test, status, new DisabledConnectionCallback())); in.close(); assertEquals(0L, in.getByteCount(), 0L); new SDSDeleteFeature(session).delete(Collections.singletonList(room), new DisabledLoginCallback(), new Delete.DisabledCallback()); session.close(); }
From source file:net.sf.jsignpdf.crl.CRLInfo.java
/** * Initialize CRLs (load URLs from certificates and download the CRLs). *///from w w w. j a v a 2 s. c o m private void initCrls() { if (!options.isCrlEnabledX() || crls != null) { return; } LOGGER.info(RES.get("console.readingCRLs")); final Set<String> urls = new HashSet<String>(); for (Certificate cert : certChain) { if (cert instanceof X509Certificate) { urls.addAll(getCrlUrls((X509Certificate) cert)); } } final Set<CRL> crlSet = new HashSet<CRL>(); for (final String urlStr : urls) { try { LOGGER.info(RES.get("console.crlinfo.loadCrl", urlStr)); final URL tmpUrl = new URL(urlStr); final CountingInputStream inStream = new CountingInputStream( tmpUrl.openConnection(options.createProxy()).getInputStream()); final CertificateFactory cf = CertificateFactory.getInstance(Constants.CERT_TYPE_X509); final CRL crl = cf.generateCRL(inStream); final long tmpBytesRead = inStream.getByteCount(); LOGGER.info(RES.get("console.crlinfo.crlSize", String.valueOf(tmpBytesRead))); if (!crlSet.contains(crl)) { byteCount += tmpBytesRead; crlSet.add(crl); } else { LOGGER.info(RES.get("console.crlinfo.alreadyLoaded")); } inStream.close(); } catch (MalformedURLException e) { LOGGER.warn("", e); } catch (IOException e) { LOGGER.warn("", e); } catch (CertificateException e) { LOGGER.warn("", e); } catch (CRLException e) { LOGGER.warn("", e); } } crls = crlSet.toArray(new CRL[crlSet.size()]); }
From source file:eu.annocultor.reports.parts.ReportCounter.java
@SuppressWarnings("unchecked") @Override//from ww w. j a va 2 s . c om public void load() throws IOException { XStream xStream = new XStream(); //BufferedReader reader = new BufferedReader(new FileReader(getFile())); CountingInputStream cis = new CountingInputStream(new FileInputStream(getFile())); ObjectInputStream in = xStream.createObjectInputStream(cis); try { int mb = 1; // how ugly but it should throw exception at the end while (true) { ObjectCountPair<T> ocp = (ObjectCountPair<T>) in.readObject(); inc(ocp.getObject(), ocp.getCount()); if (cis.getByteCount() > FileUtils.ONE_MB * 100 * mb) { log.info("Passed " + (cis.getByteCount() / FileUtils.ONE_MB) + " MB"); mb++; } } } catch (EOFException e) { // normal end of file } catch (ClassNotFoundException e) { throw new IOException(e); } finally { in.close(); cis.close(); } }