当前位置: 首页>>代码示例>>Java>>正文


Java CBZip2OutputStream类代码示例

本文整理汇总了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);
            }
        }
    };
}
 
开发者ID:lxxlxx888,项目名称:Reer,代码行数:19,代码来源:Bzip2Archiver.java

示例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;
}
 
开发者ID:dkpro,项目名称:dkpro-jwpl,代码行数:25,代码来源:Bzip2Archiver.java

示例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);
            }
        }
    };
}
 
开发者ID:Pushjet,项目名称:Pushjet-Android,代码行数:18,代码来源:Bzip2Archiver.java

示例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;
}
 
开发者ID:apache,项目名称:ant,代码行数:25,代码来源:Tar.java

示例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);
}
 
开发者ID:dkpro,项目名称:dkpro-jwpl,代码行数:8,代码来源:Tools.java

示例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;
}
 
开发者ID:paolociccarese,项目名称:simile-vicino,代码行数:16,代码来源:BZip2Distance.java

示例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);
    }
}
 
开发者ID:cinquin,项目名称:mutinack,代码行数:21,代码来源:IoUtil.java

示例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;
	}
}
 
开发者ID:Displee,项目名称:RS2-Cache-Library,代码行数:35,代码来源:BZIP2Compressor.java

示例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);
}
 
开发者ID:apache,项目名称:ant,代码行数:14,代码来源:BZip2Resource.java

示例10: createBZip2OutputStream

import org.apache.tools.bzip2.CBZip2OutputStream; //导入依赖的package包/类
private static OutputStream createBZip2OutputStream(MemByteBuffer zipped) throws IOException {
	return new CBZip2OutputStream(zipped);
}
 
开发者ID:RetGal,项目名称:Dayon,代码行数:4,代码来源:BZIP2_Zipper.java

示例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();
	}

}
 
开发者ID:dkpro,项目名称:dkpro-jwpl,代码行数:47,代码来源:Bzip2Archiver.java

示例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();
	}

}
 
开发者ID:fauconnier,项目名称:LaToe,代码行数:47,代码来源:Bzip2Archiver.java


注:本文中的org.apache.tools.bzip2.CBZip2OutputStream类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。