List of usage examples for org.apache.commons.io IOUtils copyLarge
public static long copyLarge(Reader input, Writer output) throws IOException
Reader
to a Writer
. From source file:it.openutils.mgnlaws.magnolia.datastore.CachedS3DataRecord.java
public CachedS3DataRecord(S3DataRecord record, File cacheDirectory) throws DataStoreException, IOException { super(record.getIdentifier()); this.length = record.getLength(); this.lastModified = record.getLastModified(); fileToStream = File.createTempFile(this.getIdentifier().toString() + "-", null, cacheDirectory); fileToStreamAbsolutePath = fileToStream.getAbsolutePath(); FileOutputStream fos = new FileOutputStream(fileToStream); try {/*from ww w. j a v a2 s.c om*/ IOUtils.copyLarge(record.getStream(), fos); } finally { IOUtils.closeQuietly(record.getStream()); IOUtils.closeQuietly(fos); } }
From source file:edu.umn.msi.tropix.common.io.IOUtilsImpl.java
public long copyLarge(final InputStream input, final OutputStream output) { try {/*from www .j a v a 2s . com*/ return IOUtils.copyLarge(input, output); } catch (final IOException e) { throw new IORuntimeException(e); } }
From source file:at.uni_salzburg.cs.ros.viewer.services.BigraphImageRendererTestCase.java
@Test public void shouldRenderCorectBigraphsCorrectly() throws IOException { for (String[] bigraph : bigraphTests) { BigraphImageRenderer renderer = new BigraphImageRendererImpl(); byte[] actuals = renderer.convertBgmToPng(bigraph[0]); assertNotNull(actuals);/*from w w w .ja v a 2 s . com*/ InputStream is = getClass().getResourceAsStream(bigraph[1]); ByteArrayOutputStream os = new ByteArrayOutputStream(); IOUtils.copyLarge(is, os); is.close(); os.close(); byte[] expecteds = os.toByteArray(); assertArrayEquals("Rendered bigraph image differs from expected image " + bigraph[1], expecteds, actuals); } }
From source file:eu.planets_project.services.datatypes.Content.java
/** * Create (streamed) content by reference, from an input stream. * @param inputStream The InputStream containing the value for the content. * @return A content instance with the specified value *//*from ww w. j av a2 s .com*/ public static DigitalObjectContent byReference(final InputStream inputStream) { try { File tempFile = File.createTempFile("tempContent", "tmp"); tempFile.deleteOnExit(); // TODO do we really want this here? FileOutputStream out = new FileOutputStream(tempFile); IOUtils.copyLarge(inputStream, out); out.close(); return new ImmutableContent(tempFile); } catch (IOException e) { e.printStackTrace(); } throw new IllegalStateException("Could not create content for input stream: " + inputStream); }
From source file:com.vmware.photon.controller.api.frontend.lib.LocalImageStoreImage.java
@Override public long addFile(String fileName, InputStream inputStream, long fileSize) throws IOException, NameTakenException, InternalException { // Create file File target = toFile(fileName); logger.debug("create file %s/%s", target.getName()); if (target.exists()) { throw new NameTakenException("image", imageId); }//from w w w.j av a 2s . co m // Write to file. try (OutputStream outputStream = new FileOutputStream(target)) { return IOUtils.copyLarge(inputStream, outputStream); } catch (IOException e) { throw new InternalException(e); } }
From source file:com.talis.storage.http.ItemResource.java
@GET public Response get(@PathParam("id") final String id) { URI tmbURI = makeInternalURI(id); try {//from w ww . j ava 2s. c om final StoredItem item = myStore.read(tmbURI); LOG.debug(String.format("StoredThing has media type : %s", item.getMediaType())); StreamingOutput output = new StreamingOutput() { @Override public void write(OutputStream output) throws IOException { try { IOUtils.copyLarge(item.getEntity(), output); } catch (Exception e) { LOG.error("Error fetching chunk", e); } finally { LOG.info("Closing output"); output.flush(); output.close(); } } }; return Response.ok(output, item.getMediaType()).header("etag", item.getEtag()) .header("last-modified", item.getLastModified()).header("cache-control", "max-age=7200") .build(); } catch (InvalidKeyException e) { throw new WebApplicationException(e, 400); } catch (IOException e) { throw new WebApplicationException(e, 500); } catch (ItemNotFoundException e) { throw new WebApplicationException(e, 404); } }
From source file:com.hs.mail.imap.message.MailMessage.java
public void save(InputStream is) throws IOException { File dest = Config.getDataFile(getInternalDate(), getPhysMessageID()); OutputStream os = null;/* www .j av a2s . com*/ try { os = new FileOutputStream(dest); IOUtils.copyLarge(is, os); } finally { IOUtils.closeQuietly(os); IOUtils.closeQuietly(is); } }
From source file:edu.umn.msi.tropix.common.io.IOUtilsImpl.java
public long copyLarge(final Reader input, final Writer output) { try {/*from w ww . j av a2s . c om*/ return IOUtils.copyLarge(input, output); } catch (final IOException e) { throw new IORuntimeException(e); } }
From source file:dk.deck.remoteconsole.proxy.LocalExecutor.java
public void execute(String command, String[] arguments, final PrintStream out, final PrintStream error) throws IOException, InterruptedException { List<String> args = new ArrayList<String>(); args.add(command);//w w w . j a v a 2s.c o m args.addAll(Arrays.asList(arguments)); ProcessBuilder builder = new ProcessBuilder(args); // Map<String, String> env = builder.environment(); // System.out.println("Env:"); // for (Map.Entry<String, String> entry : env.entrySet()) { // System.out.println(entry.getKey() + "=" + entry.getValue()); // } final Process p = builder.start(); Runnable copyOutput = new Runnable() { @Override public void run() { try { IOUtils.copyLarge(p.getInputStream(), out); } catch (IOException ex) { ex.printStackTrace(); } } }; Runnable copyError = new Runnable() { @Override public void run() { try { IOUtils.copyLarge(p.getErrorStream(), error); } catch (IOException ex) { ex.printStackTrace(); } } }; new Thread(copyOutput).start(); new Thread(copyError).start(); int exitValue = p.waitFor(); if (exitValue != 0) { throw new IllegalStateException("Exit value for dump was " + exitValue); } }
From source file:com.thoughtworks.go.domain.FileHandler.java
public void handle(InputStream stream) throws IOException { FileOutputStream fileOutputStream = null; try {/* w w w.j av a 2s . c o m*/ fileOutputStream = FileUtils.openOutputStream(artifact); LOG.info("[Artifact File Download] [{}] Download of artifact {} started", new Date(), artifact.getName()); IOUtils.copyLarge(stream, fileOutputStream); LOG.info("[Artifact File Download] [{}] Download of artifact {} ended", new Date(), artifact.getName()); } finally { IOUtils.closeQuietly(fileOutputStream); } FileInputStream inputStream = null; try { inputStream = new FileInputStream(artifact); LOG.info("[Artifact File Download] [{}] Checksum computation of artifact {} started", new Date(), artifact.getName()); String artifactMD5 = md5Hex(inputStream); new ChecksumValidator(artifactMd5Checksums).validate(srcFile, artifactMD5, checksumValidationPublisher); LOG.info("[Artifact File Download] [{}] Checksum computation of artifact {} ended", new Date(), artifact.getName()); } finally { IOUtils.closeQuietly(inputStream); } }