本文整理匯總了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.");
}