Search in sources :

Example 6 with CountingOutputStream

use of com.google.common.io.CountingOutputStream in project druid by druid-io.

the class VSizeIndexedWriter method open.

public void open() throws IOException {
    headerOut = new CountingOutputStream(ioPeon.makeOutputStream(headerFileName));
    valuesOut = new CountingOutputStream(ioPeon.makeOutputStream(valuesFileName));
}
Also used : CountingOutputStream(com.google.common.io.CountingOutputStream)

Example 7 with CountingOutputStream

use of com.google.common.io.CountingOutputStream in project hadoop by apache.

the class OfflineImageReconstructor method run.

/**
   * Run the OfflineImageReconstructor.
   *
   * @param inputPath         The input path to use.
   * @param outputPath        The output path to use.
   *
   * @throws Exception        On error.
   */
public static void run(String inputPath, String outputPath) throws Exception {
    MessageDigest digester = MD5Hash.getDigester();
    FileOutputStream fout = null;
    File foutHash = new File(outputPath + ".md5");
    // delete any .md5 file that exists
    Files.deleteIfExists(foutHash.toPath());
    CountingOutputStream out = null;
    FileInputStream fis = null;
    InputStreamReader reader = null;
    try {
        Files.deleteIfExists(Paths.get(outputPath));
        fout = new FileOutputStream(outputPath);
        fis = new FileInputStream(inputPath);
        reader = new InputStreamReader(fis, Charset.forName("UTF-8"));
        out = new CountingOutputStream(new DigestOutputStream(new BufferedOutputStream(fout), digester));
        OfflineImageReconstructor oir = new OfflineImageReconstructor(out, reader);
        oir.processXml();
    } finally {
        IOUtils.cleanup(LOG, reader, fis, out, fout);
    }
    // Write the md5 file
    MD5FileUtils.saveMD5File(new File(outputPath), new MD5Hash(digester.digest()));
}
Also used : CountingOutputStream(com.google.common.io.CountingOutputStream) InputStreamReader(java.io.InputStreamReader) DigestOutputStream(java.security.DigestOutputStream) FileOutputStream(java.io.FileOutputStream) MD5Hash(org.apache.hadoop.io.MD5Hash) MessageDigest(java.security.MessageDigest) File(java.io.File) BufferedOutputStream(java.io.BufferedOutputStream) FileInputStream(java.io.FileInputStream)

Example 8 with CountingOutputStream

use of com.google.common.io.CountingOutputStream in project ddf by codice.

the class ReliableResourceInputStreamTest method setup.

@Before
public void setup() {
    fbos = new FileBackedOutputStream(THRESHOLD);
    countingFbos = new CountingOutputStream(fbos);
    downloadState = mock(DownloadManagerState.class);
    when(downloadState.getDownloadState()).thenReturn(DownloadManagerState.DownloadState.COMPLETED);
    reliableResourceCallable = mock(ReliableResourceCallable.class);
    downloadFuture = mock(Future.class);
    downloadIdentifier = UUID.randomUUID().toString();
    resourceResponse = mock(ResourceResponse.class);
}
Also used : CountingOutputStream(com.google.common.io.CountingOutputStream) ResourceResponse(ddf.catalog.operation.ResourceResponse) Future(java.util.concurrent.Future) FileBackedOutputStream(com.google.common.io.FileBackedOutputStream) Before(org.junit.Before)

Example 9 with CountingOutputStream

use of com.google.common.io.CountingOutputStream in project gradle by gradle.

the class LocalFileStandInExternalResource method put.

@Override
public ExternalResourceWriteResult put(ReadableContent location) {
    try {
        if (!localFile.canWrite()) {
            localFile.delete();
        }
        Files.createParentDirs(localFile);
        InputStream input = location.open();
        try {
            CountingOutputStream output = new CountingOutputStream(new FileOutputStream(localFile));
            try {
                IOUtils.copyLarge(input, output);
            } finally {
                output.close();
            }
            return new ExternalResourceWriteResult(output.getCount());
        } finally {
            input.close();
        }
    } catch (IOException e) {
        throw ResourceExceptions.putFailed(getURI(), e);
    }
}
Also used : CountingOutputStream(com.google.common.io.CountingOutputStream) BufferedInputStream(java.io.BufferedInputStream) FileInputStream(java.io.FileInputStream) CountingInputStream(com.google.common.io.CountingInputStream) InputStream(java.io.InputStream) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) ExternalResourceWriteResult(org.gradle.internal.resource.ExternalResourceWriteResult)

Example 10 with CountingOutputStream

use of com.google.common.io.CountingOutputStream in project inbot-utils by Inbot.

the class IOUtils method byteCount.

/**
 * Calculate the serialized object size in bytes. This is a good indication of how much memory the object roughly takes.
 * Note that this is typically not exactly the same for many objects.
 * @param object any  object that implements {@link Serializable}
 * @return number of bytes of the serialized object.
 */
public long byteCount(Object object) {
    try {
        CountingOutputStream cos = new CountingOutputStream(new OutputStream() {

            @Override
            public void write(int b) throws IOException {
            // do nothing
            }
        });
        ObjectOutputStream os = new ObjectOutputStream(cos);
        os.writeObject(object);
        os.flush();
        os.close();
        return cos.getCount();
    } catch (IOException e) {
        throw new IllegalStateException("error serializing object: " + e.getMessage(), e);
    }
}
Also used : CountingOutputStream(com.google.common.io.CountingOutputStream) OutputStream(java.io.OutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) CountingOutputStream(com.google.common.io.CountingOutputStream) FileOutputStream(java.io.FileOutputStream) ObjectOutputStream(java.io.ObjectOutputStream) GZIPOutputStream(java.util.zip.GZIPOutputStream) IOException(java.io.IOException) ObjectOutputStream(java.io.ObjectOutputStream)

Aggregations

CountingOutputStream (com.google.common.io.CountingOutputStream)35 IOException (java.io.IOException)10 OutputStream (java.io.OutputStream)5 File (java.io.File)4 FileOutputStream (java.io.FileOutputStream)4 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 FileInputStream (java.io.FileInputStream)3 Path (java.nio.file.Path)3 Test (org.junit.Test)3 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)2 ObjectWriter (com.fasterxml.jackson.databind.ObjectWriter)2 FileBackedOutputStream (com.google.common.io.FileBackedOutputStream)2 ResourceResponse (ddf.catalog.operation.ResourceResponse)2 BufferedOutputStream (java.io.BufferedOutputStream)2 DataOutputStream (java.io.DataOutputStream)2 InputStream (java.io.InputStream)2 GZIPOutputStream (java.util.zip.GZIPOutputStream)2 Consumes (javax.ws.rs.Consumes)2 POST (javax.ws.rs.POST)2 Produces (javax.ws.rs.Produces)2