本文整理汇总了Java中org.apache.commons.compress.compressors.bzip2.BZip2CompressorInputStream.close方法的典型用法代码示例。如果您正苦于以下问题:Java BZip2CompressorInputStream.close方法的具体用法?Java BZip2CompressorInputStream.close怎么用?Java BZip2CompressorInputStream.close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.compress.compressors.bzip2.BZip2CompressorInputStream
的用法示例。
在下文中一共展示了BZip2CompressorInputStream.close方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: readRecordsDirectly
import org.apache.commons.compress.compressors.bzip2.BZip2CompressorInputStream; //导入方法依赖的package包/类
public String[] readRecordsDirectly(URL testFileUrl, boolean bzip)
throws IOException {
int MAX_DATA_SIZE = 1024 * 1024;
byte[] data = new byte[MAX_DATA_SIZE];
FileInputStream fis = new FileInputStream(testFileUrl.getFile());
int count;
if (bzip) {
BZip2CompressorInputStream bzIn = new BZip2CompressorInputStream(fis);
count = bzIn.read(data);
bzIn.close();
} else {
count = fis.read(data);
}
fis.close();
assertTrue("Test file data too big for buffer", count < data.length);
return new String(data, 0, count, "UTF-8").split("\n");
}
示例2: extractBzip2ByteArray
import org.apache.commons.compress.compressors.bzip2.BZip2CompressorInputStream; //导入方法依赖的package包/类
private byte[] extractBzip2ByteArray(byte[] data) {
byte[] b = null;
try {
ByteArrayInputStream bis = new ByteArrayInputStream(data);
BZip2CompressorInputStream bzip2 = new BZip2CompressorInputStream(bis);
byte[] buf = new byte[1024];
int num = -1;
ByteArrayOutputStream baos = new ByteArrayOutputStream();
while ((num = bzip2.read(buf, 0, buf.length)) != -1) {
baos.write(buf, 0, num);
}
b = baos.toByteArray();
baos.flush();
baos.close();
bzip2.close();
bis.close();
} catch (Exception ex) {
ex.printStackTrace();
}
return b;
}
示例3: openBZip2File
import org.apache.commons.compress.compressors.bzip2.BZip2CompressorInputStream; //导入方法依赖的package包/类
/**
*
* @param file
* @return
*/
public static BufferedReader openBZip2File(final String file) {
String s = "";
try {
final FileInputStream in = new FileInputStream(file);
final ByteArrayOutputStream out = new ByteArrayOutputStream();
final BZip2CompressorInputStream bzIn = new BZip2CompressorInputStream(in);
final byte[] buffer = new byte[1028];
int n = 0;
while (-1 != (n = bzIn.read(buffer))) {
out.write(buffer, 0, n);
}
out.close();
bzIn.close();
s = out.toString();
} catch (final Exception e) {
LOG.error("\n", e);
return null;
}
return new BufferedReader(new StringReader(s));
}
示例4: getStringListFromFile
import org.apache.commons.compress.compressors.bzip2.BZip2CompressorInputStream; //导入方法依赖的package包/类
public static Collection<String> getStringListFromFile(File f) {
List<String> stringList = new ArrayList<String>();
Scanner sc = null;
try {
if (FilenameUtils.getExtension(f.toString()).equals("bz2")) {
FileInputStream in = new FileInputStream(f);
BufferedInputStream bis = new BufferedInputStream(in);
BZip2CompressorInputStream bzIn = new BZip2CompressorInputStream(bis);
sc = new Scanner(bzIn);
bzIn.close();
} else {
sc = new Scanner(f);
}
while (sc.hasNextLine())
stringList.add(sc.nextLine());
} catch (IOException e) {
throw new RuntimeException(e);
} finally {
if (sc != null)
sc.close();
}
return stringList;
}
示例5: getAndDecompressBz2
import org.apache.commons.compress.compressors.bzip2.BZip2CompressorInputStream; //导入方法依赖的package包/类
public static String getAndDecompressBz2 (String url) {
Request request = new Request.Builder()
.url(url)
.build();
try {
Response response = client.newCall(request).execute();
BZip2CompressorInputStream cis = new BZip2CompressorInputStream(response.body().byteStream());
String ret = IOUtils.toString(cis, "UTF-8");
cis.close();
return ret;
} catch (IOException ioe) {
log.error("error downloading curse bz2", ioe);
}
return null;
}
示例6: read
import org.apache.commons.compress.compressors.bzip2.BZip2CompressorInputStream; //导入方法依赖的package包/类
/**
* Read from compressed file
*
* @param srcPath
* path of compressed file
* @param fileCompressor
* FileCompressor object
* @throws Exception
*/
@Override
public void read(String srcPath, FileCompressor fileCompressor)
throws Exception {
long t1 = System.currentTimeMillis();
byte[] data = FileUtil.convertFileToByte(srcPath);
ByteArrayInputStream bais = new ByteArrayInputStream(data);
BZip2CompressorInputStream cis = new BZip2CompressorInputStream(bais);
TarArchiveInputStream ais = new TarArchiveInputStream(cis);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try {
byte[] buffer = new byte[1024];
int readByte;
TarArchiveEntry entry = ais.getNextTarEntry();
while (entry != null && entry.getSize() > 0) {
long t2 = System.currentTimeMillis();
baos = new ByteArrayOutputStream();
readByte = ais.read(buffer);
while (readByte != -1) {
baos.write(buffer, 0, readByte);
readByte = ais.read(buffer);
}
BinaryFile binaryFile = new BinaryFile(entry.getName(),
baos.toByteArray());
fileCompressor.addBinaryFile(binaryFile);
LogUtil.createAddFileLog(fileCompressor, binaryFile, t2,
System.currentTimeMillis());
entry = ais.getNextTarEntry();
}
} catch (Exception e) {
FileCompressor.LOGGER.error("Error on get compressor file", e);
} finally {
baos.close();
ais.close();
cis.close();
bais.close();
}
LogUtil.createReadLog(fileCompressor, srcPath, data.length, t1,
System.currentTimeMillis());
}
示例7: bunzip2
import org.apache.commons.compress.compressors.bzip2.BZip2CompressorInputStream; //导入方法依赖的package包/类
public static void bunzip2(File bz2f, File f) throws Throwable {
BZip2CompressorInputStream is = new BZip2CompressorInputStream(new BufferedInputStream(
new FileInputStream(bz2f), BUFFER_SIZE));
BufferedOutputStream os = new BufferedOutputStream(new FileOutputStream(f), BUFFER_SIZE);
try {
IOUtils.copy(is, os, BUFFER_SIZE);
os.flush();
} finally {
os.close();
is.close();
}
}
示例8: read
import org.apache.commons.compress.compressors.bzip2.BZip2CompressorInputStream; //导入方法依赖的package包/类
/**
* Read from compressed file
*
* @param srcPath
* path of compressed file
* @param fileCompressor
* FileCompressor object
* @throws Exception
*/
@Override
public void read(String srcPath, FileCompressor fileCompressor)
throws Exception {
long t1 = System.currentTimeMillis();
byte[] data = FileUtil.convertFileToByte(srcPath);
ByteArrayInputStream bais = new ByteArrayInputStream(data);
BZip2CompressorInputStream cis = new BZip2CompressorInputStream(bais);
ZipInputStream zis = new ZipInputStream(cis);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try {
byte[] buffer = new byte[1024];
int readByte;
ZipEntry entry = zis.getNextEntry();
while (entry != null) {
long t2 = System.currentTimeMillis();
baos = new ByteArrayOutputStream();
readByte = zis.read(buffer);
while (readByte != -1) {
baos.write(buffer, 0, readByte);
readByte = zis.read(buffer);
}
zis.closeEntry();
BinaryFile binaryFile = new BinaryFile(entry.getName(),
baos.toByteArray());
fileCompressor.addBinaryFile(binaryFile);
LogUtil.createAddFileLog(fileCompressor, binaryFile, t2,
System.currentTimeMillis());
entry = zis.getNextEntry();
}
} catch (Exception e) {
FileCompressor.LOGGER.error("Error on get compressor file", e);
} finally {
baos.close();
zis.close();
cis.close();
bais.close();
}
LogUtil.createReadLog(fileCompressor, srcPath, data.length, t1,
System.currentTimeMillis());
}