Preconditions.checkState(!decompressed.exists(),
"Decompressed file: " + decompressed.toString() +
" unexpectedly exists.");
BufferedInputStream in = null;
SnappyInputStream snappyIn = null;
FileOutputStream out = null;
try {
in = new BufferedInputStream(new FileInputStream(compressed));
snappyIn = new SnappyInputStream(in);
out = new FileOutputStream(decompressed);
byte[] buf = new byte[FILE_BUFFER_SIZE];
while(true) {
int read = snappyIn.read(buf);
if (read == -1) {
break;
}
out.write(buf, 0, read);
}
out.getFD().sync();
return true;
} catch (Exception ex) {
LOG.error("Error while attempting to compress " +
compressed.toString() + " to " + decompressed.toString() +
".", ex);
Throwables.propagate(ex);
} finally {
Throwable th = null;
try {
if (in != null) {
in.close();
}
} catch (Throwable ex) {
LOG.error("Error while closing input file.", ex);
th = ex;
}
try {
if (snappyIn != null) {
snappyIn.close();
}
} catch (IOException ex) {
LOG.error("Error while closing output file.", ex);
Throwables.propagate(ex);
}