本文整理匯總了Java中org.apache.commons.compress.compressors.bzip2.BZip2CompressorOutputStream.close方法的典型用法代碼示例。如果您正苦於以下問題:Java BZip2CompressorOutputStream.close方法的具體用法?Java BZip2CompressorOutputStream.close怎麽用?Java BZip2CompressorOutputStream.close使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.commons.compress.compressors.bzip2.BZip2CompressorOutputStream
的用法示例。
在下文中一共展示了BZip2CompressorOutputStream.close方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: 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();
}
示例2: 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 ();
}
示例3: compressData
import org.apache.commons.compress.compressors.bzip2.BZip2CompressorOutputStream; //導入方法依賴的package包/類
/**
* Compress data
*
* @param fileCompressor
* FileCompressor object
* @return
* @throws Exception
*/
@Override
public byte[] compressData(FileCompressor fileCompressor) throws Exception {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
BZip2CompressorOutputStream cos = new BZip2CompressorOutputStream(baos);
ZipOutputStream zos = new ZipOutputStream(cos);
try {
zos.setLevel(fileCompressor.getLevel().getValue());
zos.setMethod(ZipOutputStream.DEFLATED);
zos.setComment(fileCompressor.getComment());
for (BinaryFile binaryFile : fileCompressor.getMapBinaryFile()
.values()) {
zos.putNextEntry(new ZipEntry(binaryFile.getDesPath()));
zos.write(binaryFile.getData());
zos.closeEntry();
}
zos.flush();
zos.finish();
} catch (Exception e) {
FileCompressor.LOGGER.error("Error on compress data", e);
} finally {
zos.close();
cos.close();
baos.close();
}
return baos.toByteArray();
}
示例4: compressData
import org.apache.commons.compress.compressors.bzip2.BZip2CompressorOutputStream; //導入方法依賴的package包/類
/**
* Compress data
*
* @param fileCompressor
* FileCompressor object
* @return
* @throws Exception
*/
@Override
public byte[] compressData(FileCompressor fileCompressor) throws Exception {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
BZip2CompressorOutputStream cos = new BZip2CompressorOutputStream(baos);
TarArchiveOutputStream aos = new TarArchiveOutputStream(cos);
try {
for (BinaryFile binaryFile : fileCompressor.getMapBinaryFile()
.values()) {
TarArchiveEntry entry = new TarArchiveEntry(
binaryFile.getDesPath());
entry.setSize(binaryFile.getActualSize());
aos.putArchiveEntry(entry);
aos.write(binaryFile.getData());
aos.closeArchiveEntry();
}
aos.flush();
aos.finish();
} catch (Exception e) {
FileCompressor.LOGGER.error("Error on compress data", e);
} finally {
aos.close();
cos.close();
baos.close();
}
return baos.toByteArray();
}
示例5: bzip2
import org.apache.commons.compress.compressors.bzip2.BZip2CompressorOutputStream; //導入方法依賴的package包/類
public static void bzip2(File f, File bz2f) throws Throwable {
BufferedInputStream is = new BufferedInputStream(new FileInputStream(f), BUFFER_SIZE);
BZip2CompressorOutputStream os = new BZip2CompressorOutputStream(new BufferedOutputStream(new FileOutputStream(
bz2f), BUFFER_SIZE));
try {
IOUtils.copy(is, os, BUFFER_SIZE);
os.flush();
} finally {
os.close();
is.close();
}
}
示例6: doCompress
import org.apache.commons.compress.compressors.bzip2.BZip2CompressorOutputStream; //導入方法依賴的package包/類
@Override
protected byte[] doCompress(byte[] plain) throws IOException {
@Cleanup ByteArrayOutputStream bos = new ByteArrayOutputStream();
@Cleanup BZip2CompressorOutputStream bzip2 = new BZip2CompressorOutputStream(bos);
bzip2.write(plain);
bzip2.close();
return bos.toByteArray();
}
示例7: bzip2
import org.apache.commons.compress.compressors.bzip2.BZip2CompressorOutputStream; //導入方法依賴的package包/類
/**
* Bzip2s the specified array.
*
* @param bytes The uncompressed array.
* @return The compressed array.
* @throws IOException If an I/O error occurs.
*/
public static byte[] bzip2(byte[] bytes) throws IOException {
ByteArrayOutputStream bout = new ByteArrayOutputStream();
BZip2CompressorOutputStream os = new BZip2CompressorOutputStream(bout, 1);
try {
os.write(bytes);
os.finish();
byte[] compressed = bout.toByteArray();
byte[] newCompressed = new byte[compressed.length - 4];
System.arraycopy(compressed, 4, newCompressed, 0, newCompressed.length);
return newCompressed;
} finally {
os.close();
}
}