"Compressed file: " + compressed.toString() + " unexpectedly " +
"exists.");
BufferedInputStream in = null;
FileOutputStream out = null;
SnappyOutputStream snappyOut = null;
try {
in = new BufferedInputStream(new FileInputStream(uncompressed));
out = new FileOutputStream(compressed);
snappyOut = new SnappyOutputStream(out);
byte[] buf = new byte[FILE_BUFFER_SIZE];
while(true) {
int read = in.read(buf);
if (read == -1) {
break;
}
snappyOut.write(buf, 0, read);
}
out.getFD().sync();
return true;
} catch (Exception ex) {
LOG.error("Error while attempting to compress " +
uncompressed.toString() + " to " + compressed.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 (snappyOut != null) {
snappyOut.close();
}
} catch (IOException ex) {
LOG.error("Error while closing output file.", ex);
Throwables.propagate(ex);
}