本文整理汇总了Java中org.apache.tools.bzip2.CBZip2OutputStream.close方法的典型用法代码示例。如果您正苦于以下问题:Java CBZip2OutputStream.close方法的具体用法?Java CBZip2OutputStream.close怎么用?Java CBZip2OutputStream.close使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.tools.bzip2.CBZip2OutputStream
的用法示例。
在下文中一共展示了CBZip2OutputStream.close方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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;
}
示例2: 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();
}
}
示例3: 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();
}
}