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.thoughtworks.go.server.service.SystemService.java

public void streamToFile(InputStream stream, File dest) throws IOException {
    dest.getParentFile().mkdirs();// w  w w . j  a  v a  2 s  .  com
    FileOutputStream out = new FileOutputStream(dest, true);
    try {
        IOUtils.copyLarge(stream, out);
    } finally {
        IOUtils.closeQuietly(out);
    }

}

From source file:com.haulmont.cuba.core.sys.logging.LogArchiver.java

public static void writeArchivedLogToStream(File logFile, OutputStream outputStream) throws IOException {
    if (!logFile.exists()) {
        throw new FileNotFoundException();
    }//from   w  ww  .  ja v  a  2  s  . c o  m

    File tempFile = File.createTempFile(FilenameUtils.getBaseName(logFile.getName()) + "_log_", ".zip");

    ZipArchiveOutputStream zipOutputStream = new ZipArchiveOutputStream(tempFile);
    zipOutputStream.setMethod(ZipArchiveOutputStream.DEFLATED);
    zipOutputStream.setEncoding(ZIP_ENCODING);

    ArchiveEntry archiveEntry = newArchive(logFile);
    zipOutputStream.putArchiveEntry(archiveEntry);

    FileInputStream logFileInput = new FileInputStream(logFile);
    IOUtils.copyLarge(logFileInput, zipOutputStream);

    logFileInput.close();

    zipOutputStream.closeArchiveEntry();
    zipOutputStream.close();

    FileInputStream tempFileInput = new FileInputStream(tempFile);
    IOUtils.copyLarge(tempFileInput, outputStream);

    tempFileInput.close();

    FileUtils.deleteQuietly(tempFile);
}

From source file:com.android.emailcommon.mail.Base64Body.java

/**
 * This method consumes the input stream, so can only be called once
 * @param out Stream to write to//from   w  w w  . ja  v a  2 s. c o  m
 * @throws IllegalStateException If called more than once
 * @throws IOException
 * @throws MessagingException
 */
@Override
public void writeTo(OutputStream out) throws IllegalStateException, IOException, MessagingException {
    if (mAlreadyWritten) {
        throw new IllegalStateException("Base64Body can only be written once");
    }
    mAlreadyWritten = true;
    try {
        final Base64OutputStream b64out = new Base64OutputStream(out, Base64.DEFAULT);
        IOUtils.copyLarge(mSource, b64out);
    } finally {
        mSource.close();
    }
}

From source file:com.kolich.common.util.io.GZIPCompressor.java

/**
 * Given an uncompressed InputStream, compress it and return the
 * result as new byte array.//from w  w w .j a va  2  s .co  m
 * @return
 */
public static final byte[] compress(final InputStream is, final int outputBufferSize) {
    GZIPOutputStream gzos = null;
    try {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        gzos = new GZIPOutputStream(baos, outputBufferSize) {
            // Ugly anonymous constructor hack to set the compression
            // level on the underlying Deflater to "max compression".
            {
                def.setLevel(Deflater.BEST_COMPRESSION);
            }
        };
        IOUtils.copyLarge(is, gzos);
        gzos.finish();
        return baos.toByteArray();
    } catch (Exception e) {
        throw new GZIPCompressorException(e);
    } finally {
        closeQuietly(gzos);
    }
}

From source file:com.hs.mail.util.FileUtils.java

public static void uncompress(File srcFile, File destFile) throws IOException {
    InputStream input = null;//from   w  w w  .  j  a  v  a 2 s.co  m
    OutputStream output = null;
    try {
        input = new GZIPInputStream(new FileInputStream(srcFile));
        output = new BufferedOutputStream(new FileOutputStream(destFile));
        IOUtils.copyLarge(input, output);
    } finally {
        IOUtils.closeQuietly(output);
        IOUtils.closeQuietly(input);
    }
}

From source file:com.rapleaf.hank.storage.curly.CurlyMerger.java

@Override
public long[] merge(final CurlyFilePath base, final List<String> deltaRemoteFiles,
        final PartitionRemoteFileOps partitionRemoteFileOps) throws IOException {
    long[] offsetAdjustments = new long[deltaRemoteFiles.size() + 1];
    offsetAdjustments[0] = 0;//from  w  w  w .j  a va  2s. co  m

    // Open the base in append mode
    File baseFile = new File(base.getPath());
    FileOutputStream baseFileOutputStream = new FileOutputStream(baseFile, true);
    OutputStream baseOutputStream = new BufferedOutputStream(baseFileOutputStream);
    try {
        // Loop over deltas and append them to the base in order, keeping track of offset adjustments
        long totalOffset = baseFile.length();
        int i = 1;
        for (String deltaRemoteFile : deltaRemoteFiles) {
            offsetAdjustments[i] = totalOffset;
            InputStream deltaRemoteInputStream = partitionRemoteFileOps.getInputStream(deltaRemoteFile);
            try {
                LOG.info("Merging remote file " + deltaRemoteFile + " into file " + base.getPath());
                long bytesCopied = IOUtils.copyLarge(deltaRemoteInputStream, baseOutputStream);
                totalOffset += bytesCopied;
            } finally {
                deltaRemoteInputStream.close();
            }
            i++;
        }
    } finally {
        // Close base streams
        baseOutputStream.close();
        baseFileOutputStream.close();
    }
    return offsetAdjustments;
}

From source file:com.dianping.phoenix.dev.core.tools.wms.AgentWorkspaceServiceImpl.java

public String getFromUrl(String url, File baseDir, OutputStream out) throws Exception {
    if (StringUtils.isBlank(url)) {
        return null;
    }//from   w  ww  .ja v a2  s . c o  m
    String fileName = extractFileName(url);
    BufferedInputStream is = null;
    BufferedOutputStream os = null;
    try {
        is = new BufferedInputStream(new URL(url).openStream());
        os = new BufferedOutputStream(new FileOutputStream(new File(baseDir, fileName)));
        IOUtils.copyLarge(is, os);
    } finally {
        IOUtils.closeQuietly(is);
        IOUtils.closeQuietly(os);
    }

    ZipUtil.explode(new File(baseDir, fileName));

    return fileName;
}

From source file:com.github.horrorho.inflatabledonkey.pcs.xfile.FileAssembler.java

static void copy(Path file, List<Chunk> chunkData, Optional<byte[]> key) throws UncheckedIOException {
    try (OutputStream output = Files.newOutputStream(file, CREATE, WRITE, TRUNCATE_EXISTING);
            InputStream input = inputStream(chunkData, key)) {

        IOUtils.copyLarge(input, output);

    } catch (IOException ex) {
        throw new UncheckedIOException(ex);
    }/*from  w  w w  .j  av  a2 s  . co  m*/
}

From source file:com.gantzgulch.sharing.service.impl.StorageManagerImpl.java

@Override
public void storeFile(SharedFile sharedFile, InputStream inputStream) throws IOException {

    String onDiskFilename = StringUtils.defaultIfEmpty(sharedFile.getOnDiskFilename(),
            "sf_" + System.currentTimeMillis() + ".dat");
    sharedFile.setOnDiskFilename(onDiskFilename);

    File file = new File(filesStorageLocation, onDiskFilename);
    OutputStream outputStream = null;
    try {/*from  w  w w . j a  v a 2  s . c om*/
        outputStream = new FileOutputStream(file);
        IOUtils.copyLarge(inputStream, outputStream);
    } finally {
        IOUtils.closeQuietly(outputStream);
        IOUtils.closeQuietly(inputStream);
    }
}

From source file:com.msopentech.odatajclient.testservice.utils.XmlElement.java

public void setContent(final InputStream content) throws IOException {
    this.content.reset();
    IOUtils.copyLarge(content, this.content);
    content.close();/*from  w  w w . ja  v a  2s . c  o m*/
}