Example usage for org.apache.commons.io IOUtils copyLarge

List of usage examples for org.apache.commons.io IOUtils copyLarge

Introduction

In this page you can find the example usage for org.apache.commons.io IOUtils copyLarge.

Prototype

public static long copyLarge(Reader input, Writer output) throws IOException 

Source Link

Document

Copy chars from a large (over 2GB) Reader to a Writer.

Usage

From source file:com.gantzgulch.sharing.controller.SharedFileDownloadController.java

@RequestMapping(method = RequestMethod.GET)
public void showUploadForm(@RequestParam(required = true) String id, final HttpServletResponse response,
        final HttpServletRequest request) {

    SharedFile sharedFile = sharedFileManager.findById(id);

    InputStream is = null;/*from  w w w  . j  av  a 2  s  . c o  m*/
    OutputStream os = null;

    try {
        is = sharedFileManager.download(id, userManager.getCurrentUser());
        os = response.getOutputStream();

        response.setHeader("Content-Disposition", "attachment; filename=\"" + sharedFile.getFilename() + "\"");
        response.setHeader("Content-Type", "application/force-download");

        if (sharedFile.getSize() < Integer.MAX_VALUE) {
            response.setContentLength((int) sharedFile.getSize());
        }

        IOUtils.copyLarge(is, os);

        os.flush();
    } catch (IOException ioe) {
        throw new RuntimeException(ioe);
    } finally {
        IOUtils.closeQuietly(is);
    }
}

From source file:com.intel.cosbench.driver.operator.Reader.java

private Sample doRead(OutputStream out, String conName, String objName, Config config, Session session) {
    if (Thread.interrupted())
        throw new AbortedException();

    InputStream in = null;/*from   ww  w.ja v a2 s. co m*/
    CountingOutputStream cout = new CountingOutputStream(out);

    long start = System.currentTimeMillis();

    try {
        in = session.getApi().getObject(conName, objName, config);
        if (!hashCheck)
            IOUtils.copyLarge(in, cout);
        else if (!validateChecksum(conName, objName, session, in, cout))
            return new Sample(new Date(), OP_TYPE, false);
    } catch (StorageInterruptedException sie) {
        throw new AbortedException();
    } catch (Exception e) {
        doLogErr(session.getLogger(), "fail to perform read operation", e);
        return new Sample(new Date(), OP_TYPE, false);
    } finally {
        IOUtils.closeQuietly(in);
        IOUtils.closeQuietly(cout);
    }

    long end = System.currentTimeMillis();

    Date now = new Date(end);
    return new Sample(now, OP_TYPE, true, end - start, cout.getByteCount());
}

From source file:com.zuehlke.sbdfx.dataimport.SourceFilesFetcher.java

private void downloadLink(final WebLink webLink) throws IOException {
    final String urlString = webLink.getURLString();
    OutputStream output = null;//w ww  . j a va2  s  .c  o m
    InputStream input = null;
    try {
        if (isLinkToDownload(urlString)) {
            final File targetFile = new File(targetFolder, urlString);
            if (targetFile.exists()) {
                FileUtils.forceDelete(targetFile);
            }
            final File tempFile = new File(targetFolder, "currentDownload");
            if (tempFile.exists()) {
                FileUtils.forceDelete(tempFile);
            }
            LOGGER.info("Downloading {} to {}", urlString, targetFile.getAbsolutePath());
            URL srcUrl = new URL(new URL(SOURCE_FOLDER), urlString);
            input = srcUrl.openStream();
            output = new FileOutputStream(tempFile);
            IOUtils.copyLarge(input, output);
            output.close();
            FileUtils.moveFile(tempFile, targetFile);
        } else {
            LOGGER.info("NOT Downloading {}", urlString);
        }
    } finally {
        IOUtils.closeQuietly(output);
        IOUtils.closeQuietly(input);
    }
}

From source file:com.vmware.photon.controller.api.frontend.lib.VsphereIsoStore.java

private long uploadFile(NfcClient nfcClient, String filePath, InputStream inputStream) throws IOException {
    logger.info("write to {}", filePath);
    long size = 0;

    try (OutputStream outputStream = nfcClient.putFileAutoClose(filePath, RESERVED_DS_SPACE)) {
        IOUtils.copyLarge(inputStream, outputStream);
    } catch (IOException e) {
        logger.error("Failed to upload ISO file", e);
        throw new RuntimeException(e);
    } finally {//from   w w w. j  a  v a2s . c  om
        if (inputStream != null) {
            inputStream.close();
        }
    }

    return size;
}

From source file:com.vmware.photon.controller.apife.lib.VsphereIsoStore.java

private long uploadFile(NfcClient nfcClient, String filePath, InputStream inputStream) {
    logger.info("write to {}", filePath);
    OutputStream outputStream = null;
    long size = 0;
    try {/*from   ww w  .ja v a  2 s. c  o  m*/
        outputStream = nfcClient.putFileAutoClose(filePath, RESERVED_DS_SPACE);
        IOUtils.copyLarge(inputStream, outputStream);
    } catch (IOException e) {
        logger.error("Failed to upload ISO file", e);
        throw new RuntimeException(e);
    } finally {
        try {
            inputStream.close();
            outputStream.close();
        } catch (IOException e) {
            logger.warn("Unable to close streaming for iso '{}' after {}: ", filePath, Long.toString(size), e);
            throw new RuntimeException(e);
        }
    }

    return size;
}

From source file:com.github.horrorho.inflatabledonkey.chunk.store.disk.DiskChunk.java

@Override
public long copyTo(OutputStream output) throws UncheckedIOException {
    try (InputStream input = Files.newInputStream(file, READ)) {
        long bytes = IOUtils.copyLarge(input, output);

        logger.debug("-- copyTo() - written (bytes): {}", bytes);
        return bytes;

    } catch (IOException ex) {
        throw new UncheckedIOException(ex);
    }//  w ww .  ja v  a 2 s  .co  m
}

From source file:com.kolich.curacao.embedded.mappers.ClasspathFileReturnMapper.java

@Override
public final void render(final AsyncContext context, final HttpServletResponse response,
        final @Nonnull File entity) throws Exception {
    // Get the path, and remove the leading slash.
    final String path = entity.getAbsolutePath().substring(1);
    final ClassLoader loader = Thread.currentThread().getContextClassLoader();
    final URL resource = loader.getResource(path);
    if (resource == null) {
        logger__.warn("Resource not found: {}", path);
        response.setStatus(HttpServletResponse.SC_NOT_FOUND);
    } else {//from   ww  w.  ja  va 2 s .c o  m
        logger__.debug("Serving resource from classpath: {}", path);
        try (final InputStream in = loader.getResourceAsStream(path);
                final OutputStream out = response.getOutputStream()) {
            IOUtils.copyLarge(in, out);
        }
    }
}

From source file:com.themodernway.server.core.io.IO.java

public static final long copy(final InputStream input, final OutputStream output) throws IOException {
    return IOUtils.copyLarge(input, output);
}

From source file:at.tfr.securefs.ws.FileServiceBean.java

@MTOM(enabled = true, threshold = 10240)
@WebMethod// w w w.  j ava2s. c o m
@Override
public void write(@WebParam(name = "relativePath") String relPath, @WebParam(name = "bytes") byte[] b)
        throws IOException {

    log.debug("write File: " + relPath);
    try {
        String tmpFileName = Paths.get(relPath).getFileName().toString() + System.currentTimeMillis();
        Path tmpPath = Files.createFile(configuration.getTmpPath().resolve(tmpFileName));
        try {
            try (OutputStream os = Files.newOutputStream(tmpPath)) {
                IOUtils.write(b, os);
            }
            preProcessor.preProcess(tmpPath);
            log.debug("preprocessed File: " + relPath);
        } finally {
            Files.deleteIfExists(tmpPath);
        }
    } catch (ModuleException me) {
        String message = "preProcessing of relPath failed: " + me.getMessage();
        if (log.isDebugEnabled()) {
            log.debug(message, me);
        }
        log.info(message);
        throw new IOException(message);
    }

    Path path = SecureFileSystemBean.resolvePath(relPath, configuration.getBasePath(),
            configuration.isRestrictedToBasePath());
    log.debug("write File: " + relPath + " to " + path);
    Path parent = path.getParent();
    Files.createDirectories(parent); // create parent directories unconditionally
    OutputStream encrypter = crypterProvider.getEncrypter(path);
    try {
        IOUtils.copyLarge(new ByteArrayInputStream(b), encrypter);
    } finally {
        encrypter.close();
    }
    logInfo("written File: " + path, null);
}

From source file:com.hs.mail.imap.processor.AppendProcessor.java

private void writeMessage(ChannelBuffer buffer, File dst) throws IOException {
    ChannelBufferInputStream is = new ChannelBufferInputStream(buffer);
    OutputStream os = null;//from w w w  .j  av  a 2s. c  o m
    try {
        os = new FileOutputStream(dst);
        IOUtils.copyLarge(is, os);
    } finally {
        IOUtils.closeQuietly(os);
    }
}