當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。