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