if (compress) {
int inputLength = 0;
File resultFile = new File(filename+SUFFIX);
InputStream in = new FileInputStream(src);
OutputStream out = new LZFFileOutputStream(resultFile);
byte[] buffer = new byte[8192];
int bytesRead;
while ((bytesRead = in.read(buffer, 0, buffer.length)) != -1) {
inputLength += bytesRead;
out.write(buffer, 0, bytesRead);
}
in.close();
out.flush();
out.close();
System.out.printf("Compressed '%s' into '%s' (%d->%d bytes)\n",
src.getPath(), resultFile.getPath(),
inputLength, resultFile.length());
} else {
OutputStream out;
LZFFileInputStream in = new LZFFileInputStream(src);
File resultFile = null;
if (toSystemOutput) {
out = System.out;
} else {
resultFile = new File(filename.substring(0, filename.length() - SUFFIX.length()));
out = new FileOutputStream(resultFile);
}
int uncompLen = in.readAndWrite(out);
in.close();
out.flush();
out.close();
if (resultFile != null) {
System.out.printf("Uncompressed '%s' into '%s' (%d->%d bytes)\n",
src.getPath(), resultFile.getPath(),
src.length(), uncompLen);
}