Search in sources :

Example 1 with CountingOutputStream

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

the class BlockLayoutLongSupplierSerializer method close.

@Override
public void close() throws IOException {
    if (endBuffer != null) {
        writer.flush();
        endBuffer.limit(endBuffer.position());
        endBuffer.rewind();
        flattener.write(StupidResourceHolder.create(endBuffer));
    }
    endBuffer = null;
    flattener.close();
    try (CountingOutputStream metaOut = new CountingOutputStream(ioPeon.makeOutputStream(metaFile))) {
        metaOut.write(CompressedLongsIndexedSupplier.version);
        metaOut.write(Ints.toByteArray(numInserted));
        metaOut.write(Ints.toByteArray(sizePer));
        writer.putMeta(metaOut, compression);
        metaOut.close();
        metaCount = metaOut.getCount();
    }
}
Also used : CountingOutputStream(com.google.common.io.CountingOutputStream)

Example 2 with CountingOutputStream

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

the class EntireLayoutFloatSupplierSerializer method close.

@Override
public void close() throws IOException {
    valuesOut.close();
    try (CountingOutputStream metaOut = new CountingOutputStream(ioPeon.makeOutputStream(metaFile))) {
        metaOut.write(CompressedFloatsIndexedSupplier.version);
        metaOut.write(Ints.toByteArray(numInserted));
        metaOut.write(Ints.toByteArray(0));
        metaOut.write(CompressedObjectStrategy.CompressionStrategy.NONE.getId());
        metaOut.close();
        metaCount = metaOut.getCount();
    }
}
Also used : CountingOutputStream(com.google.common.io.CountingOutputStream)

Example 3 with CountingOutputStream

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

the class EntireLayoutLongSupplierSerializer method open.

@Override
public void open() throws IOException {
    valuesOut = new CountingOutputStream(ioPeon.makeOutputStream(valueFile));
    writer.setOutputStream(valuesOut);
}
Also used : CountingOutputStream(com.google.common.io.CountingOutputStream)

Example 4 with CountingOutputStream

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

the class GenericIndexedWriter method open.

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

Example 5 with CountingOutputStream

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

the class GenericIndexedWriter method writeHeaderLong.

private void writeHeaderLong(FileSmoosher smoosher, RandomAccessFile headerFile, int bagSizePower, byte[] buffer) throws IOException {
    ByteBuffer helperBuffer = ByteBuffer.allocate(Ints.BYTES).order(ByteOrder.nativeOrder());
    try (CountingOutputStream finalHeaderOut = new CountingOutputStream(ioPeon.makeOutputStream(makeFilename("header_final")))) {
        int numberOfElementsPerValueFile = 1 << bagSizePower;
        long currentNumBytes = 0;
        long relativeRefBytes = 0;
        long relativeNumBytes;
        headerFile.seek(0);
        // following block converts long header indexes into int header indexes.
        for (int pos = 0; pos < numWritten; pos++) {
            // to current offset.
            if ((pos & (numberOfElementsPerValueFile - 1)) == 0) {
                relativeRefBytes = currentNumBytes;
            }
            currentNumBytes = Long.reverseBytes(headerFile.readLong());
            relativeNumBytes = currentNumBytes - relativeRefBytes;
            writeIntValueToOutputStream(helperBuffer, Ints.checkedCast(relativeNumBytes), finalHeaderOut);
        }
        long numBytesToPutInFile = finalHeaderOut.getCount();
        finalHeaderOut.close();
        try (InputStream is = new FileInputStream(ioPeon.getFile(makeFilename("header_final")))) {
            try (SmooshedWriter smooshChannel = smoosher.addWithSmooshedWriter(generateHeaderFileName(filenameBase), numBytesToPutInFile)) {
                writeBytesIntoSmooshedChannel(numBytesToPutInFile, buffer, smooshChannel, is);
            }
        }
    }
}
Also used : SmooshedWriter(io.druid.java.util.common.io.smoosh.SmooshedWriter) CountingOutputStream(com.google.common.io.CountingOutputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) ByteBuffer(java.nio.ByteBuffer) FileInputStream(java.io.FileInputStream)

Aggregations

CountingOutputStream (com.google.common.io.CountingOutputStream)35 IOException (java.io.IOException)10 FileOutputStream (java.io.FileOutputStream)5 OutputStream (java.io.OutputStream)5 File (java.io.File)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