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


Java BZip2CompressorInputStream.close方法代码示例

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

示例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;

}
 
开发者ID:GIScience,项目名称:osmgpxfilter,代码行数:23,代码来源:OsmGpxScraper.java

示例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));
}
 
开发者ID:dice-group,项目名称:FOX,代码行数:26,代码来源:FileUtil.java

示例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;
}
 
开发者ID:hltcoe,项目名称:rebar,代码行数:27,代码来源:FileUtil.java

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

示例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());
}
 
开发者ID:espringtran,项目名称:compressor4j,代码行数:49,代码来源:TarBz2Processor.java

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

示例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());
}
 
开发者ID:espringtran,项目名称:compressor4j,代码行数:50,代码来源:Bzip2Processor.java


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