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();
}
}
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();
}
}
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);
}
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")));
}
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);
}
}
}
}
Aggregations