當前位置: 首頁>>代碼示例>>Java>>正文


Java BZip2CompressorInputStream.read方法代碼示例

本文整理匯總了Java中org.apache.commons.compress.compressors.bzip2.BZip2CompressorInputStream.read方法的典型用法代碼示例。如果您正苦於以下問題:Java BZip2CompressorInputStream.read方法的具體用法?Java BZip2CompressorInputStream.read怎麽用?Java BZip2CompressorInputStream.read使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.commons.compress.compressors.bzip2.BZip2CompressorInputStream的用法示例。


在下文中一共展示了BZip2CompressorInputStream.read方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: uncompress

import org.apache.commons.compress.compressors.bzip2.BZip2CompressorInputStream; //導入方法依賴的package包/類
@Override
public byte[] uncompress(byte[] data) throws IOException {
	ByteArrayOutputStream out = new ByteArrayOutputStream();
	ByteArrayInputStream in = new ByteArrayInputStream(data);

	try {
		@SuppressWarnings("resource")
		BZip2CompressorInputStream ungzip = new BZip2CompressorInputStream(in);
		byte[] buffer = new byte[2048];
		int n;
		while ((n = ungzip.read(buffer)) >= 0) {
			out.write(buffer, 0, n);
		}
	} catch (IOException e) {
		e.printStackTrace();
	}

	return out.toByteArray();
}
 
開發者ID:yu120,項目名稱:compress,代碼行數:20,代碼來源:Bzip2Compress.java

示例2: 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

示例3: 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

示例4: 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

示例5: doDecompress

import org.apache.commons.compress.compressors.bzip2.BZip2CompressorInputStream; //導入方法依賴的package包/類
@Override
protected byte[] doDecompress(byte[] compressed) throws IOException {

    @Cleanup ByteArrayOutputStream bos = new ByteArrayOutputStream();
    @Cleanup ByteArrayInputStream bis = new ByteArrayInputStream(compressed);
    @Cleanup BZip2CompressorInputStream bzip2 = new BZip2CompressorInputStream(bis);

    byte[] buff = new byte[BUFFER_SIZE];
    int n;
    while ((n = bzip2.read(buff, 0, BUFFER_SIZE)) > 0) {
        bos.write(buff, 0, n);
    }

    return bos.toByteArray();
}
 
開發者ID:debop,項目名稱:debop4j,代碼行數:16,代碼來源:BZip2Compressor.java

示例6: reassemblePacket

import org.apache.commons.compress.compressors.bzip2.BZip2CompressorInputStream; //導入方法依賴的package包/類
/**
 * Reassembles the data of a split and/or compressed packet into a single
 * packet object
 *
 * @param splitPackets An array of packet data
 * @param isCompressed whether the data of this packet is compressed
 * @param uncompressedSize The size of the decompressed packet data
 * @param packetChecksum The CRC32 checksum of the decompressed
 *        packet data
 * @throws SteamCondenserException if decompressing the packet data fails
 * @throws PacketFormatException if the calculated CRC32 checksum does not
 *         match the expected value
 * @return SteamPacket The reassembled packet
 * @see SteamPacketFactory#getPacketFromData
 */
public static SteamPacket reassemblePacket(ArrayList<byte[]> splitPackets,
        boolean isCompressed, int uncompressedSize, int packetChecksum)
        throws SteamCondenserException {
    byte[] packetData, tmpData;
    packetData = new byte[0];

    for(byte[] splitPacket : splitPackets) {
        tmpData = packetData;
        packetData = new byte[tmpData.length + splitPacket.length];
        System.arraycopy(tmpData, 0, packetData, 0, tmpData.length);
        System.arraycopy(splitPacket, 0, packetData, tmpData.length,
                splitPacket.length);
    }

    if(isCompressed) {
        try {
            ByteArrayInputStream stream = new ByteArrayInputStream(packetData);
            stream.read();
            stream.read();
            BZip2CompressorInputStream bzip2 = new BZip2CompressorInputStream(stream);
            byte[] uncompressedPacketData = new byte[uncompressedSize];
            bzip2.read(uncompressedPacketData, 0, uncompressedSize);

            CRC32 crc32 = new CRC32();
            crc32.update(uncompressedPacketData);
            int crc32checksum = (int) crc32.getValue();

            if (crc32checksum != packetChecksum) {
                throw new PacketFormatException(
                        "CRC32 checksum mismatch of uncompressed packet data.");
            }
            packetData = uncompressedPacketData;
        } catch(IOException e) {
            throw new SteamCondenserException(e.getMessage(), e);
        }
    }

    tmpData = packetData;
    packetData = new byte[tmpData.length - 4];
    System.arraycopy(tmpData, 4, packetData, 0, tmpData.length - 4);

    return SteamPacketFactory.getPacketFromData(packetData);
}
 
開發者ID:JamesGames,項目名稱:steam-condenser-for-rust,代碼行數:59,代碼來源:SteamPacketFactory.java


注:本文中的org.apache.commons.compress.compressors.bzip2.BZip2CompressorInputStream.read方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。