本文整理汇总了Java中org.apache.tools.bzip2.CBZip2OutputStream类的典型用法代码示例。如果您正苦于以下问题:Java CBZip2OutputStream类的具体用法?Java CBZip2OutputStream怎么用?Java CBZip2OutputStream使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CBZip2OutputStream类属于org.apache.tools.bzip2包,在下文中一共展示了CBZip2OutputStream类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getCompressor
import org.apache.tools.bzip2.CBZip2OutputStream; //导入依赖的package包/类
public static ArchiveOutputStreamFactory getCompressor() {
// this is not very beautiful but at some point we will
// get rid of ArchiveOutputStreamFactory in favor of the writable Resource
return new ArchiveOutputStreamFactory() {
public OutputStream createArchiveOutputStream(File destination) throws FileNotFoundException {
OutputStream outStr = new BufferedOutputStream(new FileOutputStream(destination));
try {
outStr.write('B');
outStr.write('Z');
return new CBZip2OutputStream(outStr);
} catch (Exception e) {
IOUtils.closeQuietly(outStr);
String message = String.format("Unable to create bzip2 output stream for file %s", destination);
throw new RuntimeException(message, e);
}
}
};
}
示例2: getCompressionStream
import org.apache.tools.bzip2.CBZip2OutputStream; //导入依赖的package包/类
/**
* Creates stream for compression
*
* @param path
* path to file to compress
* @return compression stream
* @throws IOException
*/
public OutputStream getCompressionStream(String path)
throws IOException
{
File archivedFile = new File(path);
archivedFile.createNewFile();
FileOutputStream fos = new FileOutputStream(archivedFile);
BufferedOutputStream bufStr = new BufferedOutputStream(fos);
// added bzip2 prefix
fos.write("BZ".getBytes());
CBZip2OutputStream bzip2 = new CBZip2OutputStream(bufStr);
return bzip2;
}
示例3: getCompressor
import org.apache.tools.bzip2.CBZip2OutputStream; //导入依赖的package包/类
public static ArchiveOutputStreamFactory getCompressor() {
// this is not very beautiful but at some point we will
// get rid of ArchiveOutputStreamFactory in favor of the writable Resource
return new ArchiveOutputStreamFactory() {
public OutputStream createArchiveOutputStream(File destination) {
try {
OutputStream outStr = new FileOutputStream(destination);
outStr.write('B');
outStr.write('Z');
return new CBZip2OutputStream(outStr);
} catch (Exception e) {
String message = String.format("Unable to create bzip2 output stream for file %s", destination);
throw new RuntimeException(message, e);
}
}
};
}
示例4: compress
import org.apache.tools.bzip2.CBZip2OutputStream; //导入依赖的package包/类
/**
* This method wraps the output stream with the
* corresponding compression method
*
* @param ostream output stream
* @return output stream with on-the-fly compression
* @exception IOException thrown if file is not writable
*/
private OutputStream compress(final OutputStream ostream)
throws IOException {
final String v = getValue();
if (GZIP.equals(v)) {
return new GZIPOutputStream(ostream);
}
if (XZ.equals(v)) {
return newXZOutputStream(ostream);
}
if (BZIP2.equals(v)) {
ostream.write('B');
ostream.write('Z');
return new CBZip2OutputStream(ostream);
}
return ostream;
}
示例5: createBZip2File
import org.apache.tools.bzip2.CBZip2OutputStream; //导入依赖的package包/类
static OutputStream createBZip2File(String param) throws IOException, FileNotFoundException {
OutputStream outfile = createOutputFile(param);
// bzip2 expects a two-byte 'BZ' signature header
outfile.write('B');
outfile.write('Z');
return new CBZip2OutputStream(outfile);
}
示例6: d2
import org.apache.tools.bzip2.CBZip2OutputStream; //导入依赖的package包/类
public double d2(String x, String y) {
String str = x + y;
double result = 0.0f;
try {
ByteArrayOutputStream baos = new ByteArrayOutputStream(str.length());
CBZip2OutputStream os = new CBZip2OutputStream(baos);
os.write(str.getBytes());
os.close();
baos.close();
result = baos.toByteArray().length;
} catch (IOException e) {
e.printStackTrace();
}
return result;
}
示例7: openBzipFileForWriting
import org.apache.tools.bzip2.CBZip2OutputStream; //导入依赖的package包/类
/**
* Opens a BZIP encoded file for writing
*
* @param file the file to write to
* @param append whether to append to the file if it already exists (we overwrite it if false)
* @return the output stream to write to
*/
public static OutputStream openBzipFileForWriting(final File file, final boolean append) {
try {
final FileOutputStream fos = new FileOutputStream(file, append);
fos.write(66); //write magic number 'BZ' because CBZip2OutputStream does not do it for you
fos.write(90);
return IOUtil.maybeBufferOutputStream(new CBZip2OutputStream(fos));
}
catch (IOException ioe) {
throw new PicardException("Error opening file for writing: " + file.getName(), ioe);
}
}
示例8: compress
import org.apache.tools.bzip2.CBZip2OutputStream; //导入依赖的package包/类
/**
* Compress a decompressed BZIP2 file.
* @param bytes The uncompressed BZIP2 file.
* @return The compressed BZIP2 file.
*/
public static byte[] compress(byte[] bytes) {
try {
InputStream is = new ByteArrayInputStream(bytes);
try {
ByteArrayOutputStream bout = new ByteArrayOutputStream();
OutputStream os = new CBZip2OutputStream(bout, 1);
try {
byte[] buf = new byte[4096];
int len = 0;
while ((len = is.read(buf, 0, buf.length)) != -1) {
os.write(buf, 0, len);
}
os.close();
} finally {
os.close();
}
/* strip the header from the byte array and return it */
bytes = bout.toByteArray();
byte[] bzip2 = new byte[bytes.length - 2];
System.arraycopy(bytes, 2, bzip2, 0, bzip2.length);
return bzip2;
} finally {
is.close();
}
} catch(Exception e) {
e.printStackTrace();
return null;
}
}
示例9: wrapStream
import org.apache.tools.bzip2.CBZip2OutputStream; //导入依赖的package包/类
/**
* Compress on the fly using {@link CBZip2OutputStream}.
* @param out the stream to wrap.
* @return the wrapped stream.
* @throws IOException if there is a problem.
*/
@Override
protected OutputStream wrapStream(OutputStream out) throws IOException {
for (int i = 0; i < MAGIC.length; i++) {
out.write(MAGIC[i]);
}
return new CBZip2OutputStream(out);
}
示例10: createBZip2OutputStream
import org.apache.tools.bzip2.CBZip2OutputStream; //导入依赖的package包/类
private static OutputStream createBZip2OutputStream(MemByteBuffer zipped) throws IOException {
return new CBZip2OutputStream(zipped);
}
示例11: compress
import org.apache.tools.bzip2.CBZip2OutputStream; //导入依赖的package包/类
/**
* Creates bz2 archive file from file in path
*
* @param path
* to file to compress
*/
public void compress(String path)
{
try {
File fileToArchive = new File(path);
BufferedInputStream input = new BufferedInputStream(new FileInputStream(fileToArchive));
File archivedFile = new File(fileToArchive.getName() + ".bz2");
archivedFile.createNewFile();
FileOutputStream fos = new FileOutputStream(archivedFile);
BufferedOutputStream bufStr = new BufferedOutputStream(fos);
// added bzip2 prefix
fos.write("BZ".getBytes());
CBZip2OutputStream bzip2 = new CBZip2OutputStream(bufStr);
while (input.available() > 0) {
int size = COMPRESSION_CACHE;
if (input.available() < COMPRESSION_CACHE) {
size = input.available();
}
byte[] bytes = new byte[size];
input.read(bytes);
bzip2.write(bytes);
}
bzip2.close();
bufStr.close();
fos.close();
input.close();
}
catch (IOException e) {
e.printStackTrace();
}
}
示例12: compress
import org.apache.tools.bzip2.CBZip2OutputStream; //导入依赖的package包/类
/**
* Creates bz2 archive file from file in path
*
* @param path
* to file to compress
*/
public void compress(String path)
{
try {
File fileToArchive = new File(path);
FileInputStream input = new FileInputStream(fileToArchive);
File archivedFile = new File(fileToArchive.getName() + ".bz2");
archivedFile.createNewFile();
FileOutputStream fos = new FileOutputStream(archivedFile);
BufferedOutputStream bufStr = new BufferedOutputStream(fos);
// added bzip2 prefix
fos.write("BZ".getBytes());
CBZip2OutputStream bzip2 = new CBZip2OutputStream(bufStr);
while (input.available() > 0) {
int size = COMPRESSION_CACHE;
if (input.available() < COMPRESSION_CACHE) {
size = input.available();
}
byte[] bytes = new byte[size];
input.read(bytes);
bzip2.write(bytes);
}
bzip2.close();
bufStr.close();
fos.close();
input.close();
}
catch (IOException e) {
e.printStackTrace();
}
}