/**
* compress file
*
* @param in
* @param out
* @param compressionAlgorithm
* @param calucateCompressedMd5
* @param listener
* @return
* @throws TemplateServiceException
*/
String compressionAlgorithm,
boolean calucateCompressedMd5,
FileHandleListener listener) throws TemplateServiceException {
try {
return compress(fis, fos, compressionAlgorithm,
calucateCompressedMd5, listener);
throw new TemplateServiceException(
TemplateServiceException.FILE_NOT_EXIST_ERROR,
new String[] { in.
getPath() });
}
}
String compressionAlgorithm,
boolean calucateCompressedMd5,
FileHandleListener listener) throws TemplateServiceException {
try {
if (calucateCompressedMd5) {
}
CompressorStreamFactory csf = new CompressorStreamFactory();
out = csf.createCompressorOutputStream(
toCompressorAlgorithm(compressionAlgorithm), out);
if (listener != null) {
out = new FileHandleOutputStream(out, listener);
}
FileCopyUtils.copy(in, out, null);
if (calucateCompressedMd5) {
byte[] md5Bytes = md.digest();
String md5
= OutputFormatter.
binaryToHex(md5Bytes
);
return md5;
}
return null;
throw new TemplateServiceException(
TemplateServiceException.UNKNOWN_ERROR);
} catch (CompressorException e) {
throw new TemplateServiceException(
TemplateServiceException.UNKNOWN_ERROR);
}
}
/**
* uncompress file
*
* @param in
* @param out
* @param compressionAlgorithm
* @param calucateUncompressedMd5
* @param listener
* @return
* @throws TemplateServiceException
*/
String compressionAlgorithm,
boolean calucateUncompressedMd5,
FileHandleListener listener) throws TemplateServiceException {
try {
return uncompress(fis, fos, compressionAlgorithm,
calucateUncompressedMd5, listener);
throw new TemplateServiceException(
TemplateServiceException.FILE_NOT_EXIST_ERROR,
new String[] { in.
getPath() });
}
}
String compressionAlgorithm,
boolean calucateUncompressedMd5,
FileHandleListener listener) throws TemplateServiceException {
try {
if (calucateUncompressedMd5) {
}
CompressorStreamFactory csf = new CompressorStreamFactory();
in = csf.createCompressorInputStream(
toCompressorAlgorithm(compressionAlgorithm), in);
if (listener != null) {
out = new FileHandleOutputStream(out, listener);
}
FileCopyUtils.copy(in, out, null);
if (calucateUncompressedMd5) {
byte[] md5Bytes = md.digest();
String md5
= OutputFormatter.
binaryToHex(md5Bytes
);
return md5;
}
return null;
throw new TemplateServiceException(
TemplateServiceException.UNKNOWN_ERROR);
} catch (CompressorException e) {
throw new TemplateServiceException(
TemplateServiceException.UNKNOWN_ERROR);
}
}
public final static String toCompressorAlgorithm
(String compressionAlgorithm
) {
if ("bz2".equalsIgnoreCase(compressionAlgorithm)
|| "bzip2".equalsIgnoreCase(compressionAlgorithm)) {
return CompressorStreamFactory.BZIP2;
} else if ("gz".equalsIgnoreCase(compressionAlgorithm)
|| "gzip".equalsIgnoreCase(compressionAlgorithm)) {
return CompressorStreamFactory.GZIP;
} else if ("xz".equalsIgnoreCase(compressionAlgorithm)) {
return CompressorStreamFactory.XZ;
} else if ("pack200".equalsIgnoreCase(compressionAlgorithm)) {
return CompressorStreamFactory.PACK200;
} else {
return compressionAlgorithm;
}
}