use of org.apache.commons.compress.compressors.bzip2.BZip2CompressorOutputStream in project stanbol by apache.
the class Urify method urify.
private void urify(String resource) throws IOException {
File source = new File(resource);
if (source.isFile()) {
String path = FilenameUtils.getFullPathNoEndSeparator(resource);
String name = FilenameUtils.getName(resource);
File target = new File(path, outputFilePrefix + name);
int i = 0;
while (target.exists()) {
i++;
target = new File(path, "uf" + i + "_" + name);
}
InputStream is = new FileInputStream(source);
OutputStream os = new FileOutputStream(target);
log.info("RDFTerm: {}", resource);
log.info("Target : {}", target);
if ("gz".equalsIgnoreCase(FilenameUtils.getExtension(name))) {
is = new GZIPInputStream(is);
os = new GZIPOutputStream(os);
name = FilenameUtils.removeExtension(name);
log.debug(" - from GZIP Archive");
} else if ("bz2".equalsIgnoreCase(FilenameUtils.getExtension(name))) {
is = new BZip2CompressorInputStream(is);
os = new BZip2CompressorOutputStream(os);
name = FilenameUtils.removeExtension(name);
log.debug(" - from BZip2 Archive");
}
// TODO: No Zip File support
//else no complression
BlockingQueue<String> queue = new ArrayBlockingQueue<String>(1000);
ReaderDaemon reader = new ReaderDaemon(new BufferedReader(new InputStreamReader(is, charset)), queue);
WriterDaemon writer = new WriterDaemon(new BufferedWriter(new OutputStreamWriter(os, charset)), queue);
Thread readerDaemon = new Thread(reader, name + " reader");
Thread writerDaemon = new Thread(writer, name + " writer");
readerDaemon.setDaemon(true);
writerDaemon.setDaemon(true);
writerDaemon.start();
readerDaemon.start();
Object notifier = writer.getNotifier();
synchronized (notifier) {
//wait until processed
if (!writer.completed()) {
try {
notifier.wait();
} catch (InterruptedException e) {
/*ignore*/
}
}
}
if (reader.getError() != null) {
throw new IOException("Error while reading source " + source, reader.getError());
}
if (writer.getError() != null) {
throw new IOException("Error while writing resource " + target, writer.getError());
}
log.info(" ... completed resource {}", resource);
} else {
throw new FileNotFoundException("Parsed File " + resource + " does not exist or is not a File!");
}
}
use of org.apache.commons.compress.compressors.bzip2.BZip2CompressorOutputStream in project Lucee by lucee.
the class CompressUtil method _compressBZip2.
/**
* compress a source file to a bzip2 file
* @param source
* @param target
* @throws IOException
*/
private static void _compressBZip2(InputStream source, OutputStream target) throws IOException {
InputStream is = IOUtil.toBufferedInputStream(source);
OutputStream os = new BZip2CompressorOutputStream(IOUtil.toBufferedOutputStream(target));
IOUtil.copy(is, os, true, true);
}
Aggregations