当前位置: 首页>>代码示例>>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;未经允许,请勿转载。