本文整理汇总了Java中org.apache.commons.compress.compressors.bzip2.BZip2CompressorOutputStream类的典型用法代码示例。如果您正苦于以下问题:Java BZip2CompressorOutputStream类的具体用法?Java BZip2CompressorOutputStream怎么用?Java BZip2CompressorOutputStream使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
BZip2CompressorOutputStream类属于org.apache.commons.compress.compressors.bzip2包,在下文中一共展示了BZip2CompressorOutputStream类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: S3TransportBuffer
import org.apache.commons.compress.compressors.bzip2.BZip2CompressorOutputStream; //导入依赖的package包/类
public S3TransportBuffer(long maxBytes, boolean useCompression, S3TransportSerializer serializer)
throws TransportException {
this.maxBytes = maxBytes;
this.serializer = serializer;
baos = new ByteArrayOutputStream();
cos = new CountingOutputStream(baos);
if (useCompression) {
this.isCompressed = true;
try {
os = new BZip2CompressorOutputStream(cos);
} catch (IOException e) {
throw new TransportException("unable to create BZip2CompressorOutputStream", e);
}
} else {
this.isCompressed = false;
os = cos;
}
}
示例2: getOutputStreamForMode
import org.apache.commons.compress.compressors.bzip2.BZip2CompressorOutputStream; //导入依赖的package包/类
/**
* Get a compressing stream for a given compression mode.
*/
private OutputStream getOutputStreamForMode(CompressionMode mode, OutputStream stream)
throws IOException {
switch (mode) {
case GZIP:
return new GzipCompressorOutputStream(stream);
case BZIP2:
return new BZip2CompressorOutputStream(stream);
case ZIP:
return new TestZipOutputStream(stream);
case DEFLATE:
return new DeflateCompressorOutputStream(stream);
default:
throw new RuntimeException("Unexpected compression mode");
}
}
示例3: openOutput
import org.apache.commons.compress.compressors.bzip2.BZip2CompressorOutputStream; //导入依赖的package包/类
public Writer openOutput(String key) throws UncheckedIOException {
try {
if (holdersByKey.containsKey(key)) {
throw new IllegalStateException("Output already opened");
}
FileHolder holder = new FileHolder();
holdersByKey.put(key, holder);
return new OutputStreamWriter(new TeeOutputStream(
new TeeOutputStream(new GZIPOutputStream(Files.newOutputStream(holder.gzTempFile)),
new BZip2CompressorOutputStream(Files.newOutputStream(holder.bzTempFile))),
Files.newOutputStream(holder.plainTempFile)), Charsets.UTF_8);
}
catch (IOException e) {
throw new UncheckedIOException(e);
}
}
示例4: testCreateCompressorOutputStreamBzip2
import org.apache.commons.compress.compressors.bzip2.BZip2CompressorOutputStream; //导入依赖的package包/类
@Test
public void testCreateCompressorOutputStreamBzip2() throws Exception {
new NonStrictExpectations() {{
task.getFormat(); result = "bzip2";
task.getBufferAllocator(); result = new MockBufferAllocator();
}};
provider = new CommonsCompressCompressorProvider(task, fileOutput);
OutputStream out = provider.createCompressorOutputStream();
assertTrue("Verify a stream instance.", out instanceof BZip2CompressorOutputStream);
provider.close();
new Verifications() {{
fileOutput.close(); times = 1;
}};
}
开发者ID:hata,项目名称:embulk-encoder-commons-compress,代码行数:17,代码来源:TestCommonsCompressCompressorProvider.java
示例5: zip
import org.apache.commons.compress.compressors.bzip2.BZip2CompressorOutputStream; //导入依赖的package包/类
public static InputStream zip(
File fileOrDir,
long[] sizePtr
) throws IOException {
File tmp = File.createTempFile(fileOrDir.getName(), ".tar.bz2");
tmp.deleteOnExit();
OutputStream target = new FileOutputStream(tmp);
/* Closes target */
try (OutputStream bzip2 = new BZip2CompressorOutputStream(target)) {
tarTo(fileOrDir, bzip2);
}
if (sizePtr != null) {
sizePtr[0] = tmp.length();
}
return new DeletingFileInputStream(tmp);
}
示例6: getCompressedData
import org.apache.commons.compress.compressors.bzip2.BZip2CompressorOutputStream; //导入依赖的package包/类
@Override
protected byte[] getCompressedData() throws IOException {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
try (BZip2CompressorOutputStream os = new BZip2CompressorOutputStream(bos)) {
os.write(getUncompressedData());
}
return bos.toByteArray();
}
示例7: getBZip2BlockSize
import org.apache.commons.compress.compressors.bzip2.BZip2CompressorOutputStream; //导入依赖的package包/类
int getBZip2BlockSize() {
final int level = AbstractZipOutputStream.this.getLevel();
if (BZip2CompressorOutputStream.MIN_BLOCKSIZE <= level
&& level <= BZip2CompressorOutputStream.MAX_BLOCKSIZE)
return level;
return BZip2CompressorOutputStream.MAX_BLOCKSIZE;
}
示例8: compress
import org.apache.commons.compress.compressors.bzip2.BZip2CompressorOutputStream; //导入依赖的package包/类
@Override
public byte[] compress(byte[] data) throws IOException {
ByteArrayOutputStream out = new ByteArrayOutputStream();
BZip2CompressorOutputStream bcos = new BZip2CompressorOutputStream(out);
bcos.write(data);
bcos.close();
return out.toByteArray();
}
示例9: startRevisionProcessing
import org.apache.commons.compress.compressors.bzip2.BZip2CompressorOutputStream; //导入依赖的package包/类
@Override
public void startRevisionProcessing() {
logger.debug("Starting (" + featureFile + ")...");
try {
OutputStreamWriter writer =
new OutputStreamWriter(
getPipedOutputStreamStream(
new BZip2CompressorOutputStream(
new BufferedOutputStream(
new FileOutputStream(featureFile)),
BZIP2_BLOCKSIZE)),
"utf-8");
String[] header = new String[features.size()];
for (int i = 0; i < features.size(); i++) {
header[i] = features.get(i).getName();
}
csvPrinter = CSVFormat.RFC4180.withHeader(header).print(writer);
} catch (IOException e) {
logger.error("", e);
}
}
示例10: run
import org.apache.commons.compress.compressors.bzip2.BZip2CompressorOutputStream; //导入依赖的package包/类
public void run() {
try {
// This compression seems to be really slow and is a major bottleneck of the whole program
OutputStream compressedOutStream = new BZip2CompressorOutputStream(out, 1);
IOUtils.copy(in, compressedOutStream);
in.close();
compressedOutStream.close();
out.close();
} catch (IOException e) {
logger.error("", e);
}
}
示例11: bzip2
import org.apache.commons.compress.compressors.bzip2.BZip2CompressorOutputStream; //导入依赖的package包/类
/**
* Bzip2s the specified array, removing the header.
*
* @param uncompressed The uncompressed array.
* @return The compressed array.
* @throws IOException If there is an error compressing the array.
*/
public static byte[] bzip2(byte[] uncompressed) throws IOException {
ByteArrayOutputStream out = new ByteArrayOutputStream();
try (BZip2CompressorOutputStream compressor = new BZip2CompressorOutputStream(out, 1)) {
compressor.write(uncompressed);
compressor.finish();
byte[] compressed = out.toByteArray();
byte[] stripped = new byte[compressed.length - 4]; // Strip the header
System.arraycopy(compressed, 4, stripped, 0, stripped.length);
return stripped;
}
}
示例12: openOutputStream
import org.apache.commons.compress.compressors.bzip2.BZip2CompressorOutputStream; //导入依赖的package包/类
public static DataOutputStream openOutputStream(String filename) throws IOException {
FSUtil.makeParentDirectories(filename);
if (filename.endsWith(".gz")) {
return new DataOutputStream(new GZIPOutputStream(new FileOutputStream(filename)));
} else if (filename.endsWith(".bz") || filename.endsWith(".bz2")) {
return new DataOutputStream(new BZip2CompressorOutputStream(new FileOutputStream(filename)));
} else if(filename.endsWith(".xz")) {
return new DataOutputStream(new XZOutputStream(new FileOutputStream(filename), new LZMA2Options()));
} else {
return new DataOutputStream(new FileOutputStream(filename));
}
}
示例13: cacheLibrary
import org.apache.commons.compress.compressors.bzip2.BZip2CompressorOutputStream; //导入依赖的package包/类
private void cacheLibrary (String language, String name)
throws IOException, FTPIllegalReplyException, FTPException, FTPDataTransferException, FTPAbortedException,
FTPListParseException
{
File libdir = new File(cachedir, language + "/" + name);
WorkerMain.getLogger().info("Caching Library " + name + " (" + language + ") to " + libdir.getAbsolutePath());
libdir.mkdirs();
DatastoreFtpClient.retrieveLibrary(name, language, libdir);
File libtar = new File(cachedir, language + "/" + name + ".tar.bz2");
TarArchiveOutputStream tar = new TarArchiveOutputStream(new BZip2CompressorOutputStream(new FileOutputStream(libtar)));
tar.setBigNumberMode(BIGNUMBER_POSIX);
tar.setLongFileMode(LONGFILE_POSIX);
addToTar(libdir, tar, "");
tar.close();
}
示例14: compressBzip2
import org.apache.commons.compress.compressors.bzip2.BZip2CompressorOutputStream; //导入依赖的package包/类
private byte[] compressBzip2 ( final byte[] data ) throws IOException
{
final ByteArrayOutputStream bos = new ByteArrayOutputStream ();
final BZip2CompressorOutputStream b2os = new BZip2CompressorOutputStream ( bos );
b2os.write ( data );
b2os.close ();
return bos.toByteArray ();
}
示例15: createCompressorOutputStream
import org.apache.commons.compress.compressors.bzip2.BZip2CompressorOutputStream; //导入依赖的package包/类
CompressorOutputStream createCompressorOutputStream() throws IOException {
switch (format) {
case BZIP2:
return new BZip2CompressorOutputStream(output);
case DEFLATE:
return new DeflateCompressorOutputStream(output);
case GZIP:
return new GzipCompressorOutputStream(output);
}
// Normally, this exception is not thrown.
throw new IOException("Unknown format found.");
}