List of usage examples for org.apache.commons.compress.parallel InputStreamSupplier InputStreamSupplier
InputStreamSupplier
From source file:org.codehaus.plexus.archiver.zip.AbstractZipArchiver.java
/** * Method that gets called when adding from java.io.File instances. * <p/>//from www . j a v a 2 s .co m * <p>This implementation delegates to the six-arg version.</p> * @param entry the file to add to the archive * @param zOut the stream to write to * @param vPath the name this entry shall have in the archive */ @SuppressWarnings({ "JavaDoc" }) protected void zipFile(final ArchiveEntry entry, ConcurrentJarCreator zOut, String vPath) throws IOException, ArchiverException { final PlexusIoResource resource = entry.getResource(); if (ResourceUtils.isSame(resource, getDestFile())) { throw new ArchiverException("A zip file cannot include itself"); } final boolean b = entry.getResource() instanceof SymlinkDestinationSupplier; String symlinkTarget = b ? ((SymlinkDestinationSupplier) entry.getResource()).getSymlinkDestination() : null; InputStreamSupplier in = new InputStreamSupplier() { @Override public InputStream get() { try { return entry.getInputStream(); } catch (IOException e) { throw new RuntimeException(e); } } }; try { zipFile(in, zOut, vPath, resource.getLastModified(), null, entry.getMode(), symlinkTarget); } catch (IOException e) { throw new ArchiverException("IOException when zipping r" + entry.getName() + ": " + e.getMessage(), e); } }
From source file:org.codehaus.plexus.archiver.zip.AbstractZipArchiver.java
private InputStreamSupplier wrappedRecompressor(final ZipArchiveEntry ze, final InputStreamSupplier other) { return new InputStreamSupplier() { public InputStream get() { InputStream is = other.get(); byte[] header = new byte[4]; try { int read = is.read(header); boolean compressThis = doCompress; if (!recompressAddedZips && isZipHeader(header)) { compressThis = false; }//w w w . ja va 2 s. co m ze.setMethod(compressThis ? ZipArchiveEntry.DEFLATED : ZipArchiveEntry.STORED); return maybeSequence(header, read, is); } catch (IOException e) { throw new RuntimeException(e); } } }; }
From source file:org.codehaus.plexus.archiver.zip.AbstractZipArchiver.java
protected InputStreamSupplier createInputStreamSupplier(final InputStream inputStream) { return new InputStreamSupplier() { public InputStream get() { return inputStream; }/*from ww w . ja v a 2s . c om*/ }; }
From source file:org.codehaus.plexus.archiver.zip.ConcurrentJarCreator.java
private InputStreamSupplier createInputStreamSupplier(final InputStream payload) { return new InputStreamSupplier() { public InputStream get() { return payload; }//from w w w . ja v a 2 s .c om }; }
From source file:org.sead.nds.repository.BagGenerator.java
private void createDir(final String name) throws IOException, ExecutionException, InterruptedException { ZipArchiveEntry archiveEntry = new ZipArchiveEntry(name); archiveEntry.setMethod(ZipEntry.DEFLATED); InputStreamSupplier supp = new InputStreamSupplier() { public InputStream get() { return new ByteArrayInputStream(("").getBytes()); }//from ww w . j a va 2 s .c o m }; addEntry(archiveEntry, supp); }
From source file:org.sead.nds.repository.BagGenerator.java
private void createFileFromString(final String name, final String content) throws IOException, ExecutionException, InterruptedException { ZipArchiveEntry archiveEntry = new ZipArchiveEntry(name); archiveEntry.setMethod(ZipEntry.DEFLATED); InputStreamSupplier supp = new InputStreamSupplier() { public InputStream get() { try { return new ByteArrayInputStream(content.getBytes("UTF-8")); } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace();/* ww w. j a va 2 s. c om*/ } return null; } }; addEntry(archiveEntry, supp); }
From source file:org.sead.nds.repository.C3PRPubRequestFacade.java
InputStreamSupplier getInputStreamSupplier(final String uri) { return new InputStreamSupplier() { public InputStream get() { int tries = 0; while (tries < 5) { try { HttpGet getMap = createNewGetRequest(new URI(uri), null); log.trace("Retrieving " + tries + ": " + uri); CloseableHttpResponse response; response = client.execute(getMap, getLocalContext()); if (response.getStatusLine().getStatusCode() == 200) { log.trace("Retrieved: " + uri); return response.getEntity().getContent(); }//from w w w. j a v a2s. c o m log.debug("Status: " + response.getStatusLine().getStatusCode()); tries++; } catch (ClientProtocolException e) { tries += 5; // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // Retry if this is a potentially temporary error such // as a timeout tries++; log.warn("Attempt# " + tries + " : Unable to retrieve file: " + uri, e); if (tries == 5) { log.error("Final attempt failed for " + uri); } e.printStackTrace(); } catch (URISyntaxException e) { tries += 5; // TODO Auto-generated catch block e.printStackTrace(); } } log.error("Could not read: " + uri); return null; } }; }