• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java CBZip2InputStream类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.apache.tools.bzip2.CBZip2InputStream的典型用法代码示例。如果您正苦于以下问题:Java CBZip2InputStream类的具体用法?Java CBZip2InputStream怎么用?Java CBZip2InputStream使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



CBZip2InputStream类属于org.apache.tools.bzip2包,在下文中一共展示了CBZip2InputStream类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: bunzip2

import org.apache.tools.bzip2.CBZip2InputStream; //导入依赖的package包/类
/**
 * Uncompresses a BZIP2 file.
 * 
 * @param bytes The compressed bytes without the header.
 * @return The uncompressed bytes.
 * @throws IOException if an I/O error occurs.
 */
public static byte[] bunzip2(byte[] bytes) throws IOException {
	/* prepare a new byte array with the bzip2 header at the start */
	byte[] bzip2 = new byte[bytes.length + 2];
	bzip2[0] = 'h';
	bzip2[1] = '1';
	System.arraycopy(bytes, 0, bzip2, 2, bytes.length);

	InputStream is = new CBZip2InputStream(new ByteArrayInputStream(bzip2));
	try {
		ByteArrayOutputStream os = new ByteArrayOutputStream();
		try {
			byte[] buf = new byte[4096];
			int len = 0;
			while ((len = is.read(buf, 0, buf.length)) != -1) {
				os.write(buf, 0, len);
			}
		} finally {
			os.close();
		}

		return os.toByteArray();
	} finally {
		is.close();
	}
}
 
开发者ID:jordanabrahambaws,项目名称:Quavo,代码行数:33,代码来源:CompressionUtils.java


示例2: bunzip2

import org.apache.tools.bzip2.CBZip2InputStream; //导入依赖的package包/类
/**
 * Uncompresses a BZIP2 file.
 * 
 * @param bytes
 *            The compressed bytes without the header.
 * @return The uncompressed bytes.
 * @throws IOException
 *             if an I/O error occurs.
 */
public static byte[] bunzip2(byte[] bytes) throws IOException {
	/* prepare a new byte array with the bzip2 header at the start */
	byte[] bzip2 = new byte[bytes.length + 2];
	bzip2[0] = 'h';
	bzip2[1] = '1';
	System.arraycopy(bytes, 0, bzip2, 2, bytes.length);

	InputStream is = new CBZip2InputStream(new ByteArrayInputStream(bzip2));
	try {
		ByteArrayOutputStream os = new ByteArrayOutputStream();
		try {
			byte[] buf = new byte[4096];
			int len = 0;
			while ((len = is.read(buf, 0, buf.length)) != -1) {
				os.write(buf, 0, len);
			}
		} finally {
			os.close();
		}

		return os.toByteArray();
	} finally {
		is.close();
	}
}
 
开发者ID:kfricilone,项目名称:OpenRS,代码行数:35,代码来源:CompressionUtils.java


示例3: openBzipFileForReading

import org.apache.tools.bzip2.CBZip2InputStream; //导入依赖的package包/类
/**
 * Opens a GZIP-encoded file for reading, decompressing it if necessary
 *
 * @param file  The file to open
 * @return the input stream to read from
 */
public static InputStream openBzipFileForReading(final File file) {

    try {
        final FileInputStream fis = new FileInputStream(file);
        if(fis.read() != 66 || fis.read() != 90) { //Read magic number 'BZ' or else CBZip2InputStream will complain about it
            fis.close();
            throw new PicardException(file.getAbsolutePath() + " is not a BZIP file.");
        }

        return new CBZip2InputStream(fis);
    }
    catch (IOException ioe) {
        throw new PicardException("Error opening file: " + file.getName(), ioe);
    }
}
 
开发者ID:cinquin,项目名称:mutinack,代码行数:22,代码来源:IoUtil.java


示例4: extractBzip

import org.apache.tools.bzip2.CBZip2InputStream; //导入依赖的package包/类
private void extractBzip(File downloadFile)
    throws IOException
{
  try (FileInputStream inputSkipTwo = new FileInputStream(downloadFile)) {
    // see javadoc for CBZip2InputStream
    // first two bits need to be skipped
    inputSkipTwo.read();
    inputSkipTwo.read();

    LOG.debug("Extract tar...");
    try (TarInputStream tarIn = new TarInputStream(new CBZip2InputStream(inputSkipTwo))) {
      for (TarEntry entry = tarIn.getNextEntry(); entry != null; entry = tarIn.getNextEntry()) {
        LOG.debug("Extracting {}", entry.getName());

        File extractedFile = new File(downloadFile.getParent() + File.separator + entry.getName());
        extractEntry(extractedFile, entry.isDirectory(), tarIn);
      }
    }
  }
}
 
开发者ID:partnet,项目名称:seauto,代码行数:21,代码来源:StandaloneDriverDownloadAssistant.java


示例5: getInputStreamAtOffset

import org.apache.tools.bzip2.CBZip2InputStream; //导入依赖的package包/类
private InputStream getInputStreamAtOffset(final RandomAccessFile file, long offset) throws IOException {
	if (offset + 2 >= file.length()) {
		throw new IOException("read past EOF");
	}
	file.seek(offset + 2); // skip past 'BZ' header
	InputStream is = new CBZip2InputStream(new FileInputStream(file.getFD()) {
		@Override
		public void close() throws IOException {
		}
	});
	if (offset == 0) {
		return new SequenceInputStream(is, new ByteArrayInputStream(MEDIAWIKI_CLOSING.getBytes()));
	} else {
		return new SequenceInputStream(
				new ByteArrayInputStream(MEDIAWIKI_OPENING.getBytes()),
				new SequenceInputStream(is,
						new ByteArrayInputStream(MEDIAWIKI_CLOSING.getBytes())));
	}
}
 
开发者ID:dkpro,项目名称:dkpro-jwktl,代码行数:20,代码来源:MultistreamXMLDumpParser.java


示例6: decompress

import org.apache.tools.bzip2.CBZip2InputStream; //导入依赖的package包/类
/**
 *  This method wraps the input stream with the
 *     corresponding decompression method
 *
 *  @param name provides location information for BuildException
 *  @param istream input stream
 *  @return input stream with on-the-fly decompression
 *  @exception IOException thrown by GZIPInputStream constructor
 *  @exception BuildException thrown if bzip stream does not
 *     start with expected magic values
 */
public InputStream decompress(final String name,
                               final InputStream istream)
    throws IOException, BuildException {
    final String v = getValue();
    if (GZIP.equals(v)) {
        return new GZIPInputStream(istream);
    }
    if (XZ.equals(v)) {
        return newXZInputStream(istream);
    }
    if (BZIP2.equals(v)) {
        final char[] magic = new char[] { 'B', 'Z' };
        for (int i = 0; i < magic.length; i++) {
            if (istream.read() != magic[i]) {
                throw new BuildException("Invalid bz2 file." + name);
            }
        }
        return new CBZip2InputStream(istream);
    }
    return istream;
}
 
开发者ID:apache,项目名称:ant,代码行数:33,代码来源:Untar.java


示例7: bunzip2

import org.apache.tools.bzip2.CBZip2InputStream; //导入依赖的package包/类
/**
 * Uncompresses a BZIP2 file.
 * @param bytes The compressed bytes without the header.
 * @return The uncompressed bytes.
 * @throws IOException if an I/O error occurs.
 */
public static byte[] bunzip2(byte[] bytes) throws IOException {
	/* prepare a new byte array with the bzip2 header at the start */
	byte[] bzip2 = new byte[bytes.length + 2];
	bzip2[0] = 'h';
	bzip2[1] = '1';
	System.arraycopy(bytes, 0, bzip2, 2, bytes.length);

	try (InputStream is = new CBZip2InputStream(new ByteArrayInputStream(bzip2))) {
		try (ByteArrayOutputStream os = new ByteArrayOutputStream()) {
			byte[] buf = new byte[4096];
			int len;
			while ((len = is.read(buf, 0, buf.length)) != -1) {
				os.write(buf, 0, len);
			}

               return os.toByteArray();
		}
	}
}
 
开发者ID:davidi2,项目名称:mopar,代码行数:26,代码来源:CompressionUtils.java


示例8: tryOpenAsArchive

import org.apache.tools.bzip2.CBZip2InputStream; //导入依赖的package包/类
static public InputStream tryOpenAsArchive (File file, String mimeType, String contentType) {
  String fileName = file.getName ();
  try {
    if (fileName.endsWith (".tar.gz") || fileName.endsWith (".tgz")) {
      return new TarInputStream (new GZIPInputStream (new FileInputStream (file)));
    } else if (fileName.endsWith (".tar.bz2")) {
      return new TarInputStream (new CBZip2InputStream (new FileInputStream (file)));
    } else if (fileName.endsWith (".tar") || "application/x-tar".equals (contentType)) {
      return new TarInputStream (new FileInputStream (file));
    } else if (fileName.endsWith (".zip")
               || "application/x-zip-compressed".equals (contentType)
               || "application/zip".equals (contentType)
               || "application/x-compressed".equals (contentType)
               || "multipar/x-zip".equals (contentType)) {
      return new ZipInputStream (new FileInputStream (file));
    } else if (fileName.endsWith (".kmz")) {
      return new ZipInputStream (new FileInputStream (file));
    }
  } catch (IOException e) {}
  return null;
}
 
开发者ID:dfci-cccb,项目名称:mev,代码行数:22,代码来源:ImportingUtilities.java


示例9: tryOpenAsCompressedFile

import org.apache.tools.bzip2.CBZip2InputStream; //导入依赖的package包/类
static public InputStream tryOpenAsCompressedFile (File file, String mimeType, String contentEncoding) {
  String fileName = file.getName ();
  try {
    if (fileName.endsWith (".gz")
        || "gzip".equals (contentEncoding)
        || "x-gzip".equals (contentEncoding)
        || "application/x-gzip".equals (mimeType)) {
      return new GZIPInputStream (new FileInputStream (file));
    } else if (fileName.endsWith (".bz2")
               || "application/x-bzip2".equals (mimeType)) {
      InputStream is = new FileInputStream (file);
      is.mark (4);
      if (!(is.read () == 'B' && is.read () == 'Z')) {
        // No BZ prefix as appended by command line tools. Reset and hope for
        // the best
        is.reset ();
      }
      return new CBZip2InputStream (is);
    }
  } catch (IOException e) {
    logger.warn ("Something that looked like a compressed file gave an error on open: " + file, e);
  }
  return null;
}
 
开发者ID:dfci-cccb,项目名称:mev,代码行数:25,代码来源:ImportingUtilities.java


示例10: getInputSource

import org.apache.tools.bzip2.CBZip2InputStream; //导入依赖的package包/类
/**
 * 
 * @return An InputSource created from wikiXMLFile
 * @throws Exception
 */
protected InputSource getInputSource() throws Exception
{		
	BufferedReader br = null;
	
	if(this.wikiXMLBufferedReader != null) {
		br = this.wikiXMLBufferedReader;
	} else if(wikiXMLFile.endsWith(".gz")) {		
		br = new BufferedReader(new InputStreamReader(
				new GZIPInputStream(new FileInputStream(wikiXMLFile)), "UTF8"));
	} else if(wikiXMLFile.endsWith(".bz2")) {
		FileInputStream fis = new FileInputStream(wikiXMLFile);
		byte [] ignoreBytes = new byte[2];
		fis.read(ignoreBytes); //"B", "Z" bytes from commandline tools
		br = new BufferedReader(new InputStreamReader(
				new CBZip2InputStream(fis), "UTF8"));
	} else {
		br = new BufferedReader(new InputStreamReader( 
				new FileInputStream(wikiXMLFile), "UTF8"));
	}
	
	return new InputSource(br);
}
 
开发者ID:shopping24,项目名称:wikitionary-solr-synonyms,代码行数:28,代码来源:WikiXMLParser.java


示例11: read

import org.apache.tools.bzip2.CBZip2InputStream; //导入依赖的package包/类
public InputStream read() {
    InputStream is = resource.read();
    try {
        // CBZip2InputStream expects the opening "BZ" to be skipped
        byte[] skip = new byte[2];
        is.read(skip);
        return new CBZip2InputStream(is);
    } catch (Exception e) {
        IOUtils.closeQuietly(is);
        throw ResourceExceptions.readFailed(resource.getDisplayName(), e);
    }
}
 
开发者ID:lxxlxx888,项目名称:Reer,代码行数:13,代码来源:Bzip2Archiver.java


示例12: decompressMultiBlock

import org.apache.tools.bzip2.CBZip2InputStream; //导入依赖的package包/类
/**
 * Decompresses a block which was compressed using the multi compression method.
 * 
 * @param block block to be decompressed
 * @param outSize size of the decompressed data
 * @param dest buffer to copy the decompressed data
 * @param destPos position in the destination buffer to copy the decompressed data
 * @throws InvalidMpqArchiveException if unsupported compression is found or the decompression of the block fails
 */
public static void decompressMultiBlock( byte[] block, final int outSize, final byte[] dest, final int destPos ) throws InvalidMpqArchiveException {
	// Check if block is really compressed, some blocks have set the compression flag, but are not compressed.
	if ( block.length >= outSize ) {
		// Copy block
		System.arraycopy( block, 0, dest, destPos, outSize );
	} else {
		final byte compressionFlag = block[ 0 ];
		
		switch ( compressionFlag ) {
			case FLAG_COMPRESSION_ZLIB : {
				// Handle deflated code (compressionFlag = 0x02)
				final Inflater inflater = new Inflater();
				inflater.setInput( block, 1, block.length - 1 );
				try {
					inflater.inflate( dest, destPos, outSize );
					inflater.end();
				} catch ( final DataFormatException dfe ) {
					throw new InvalidMpqArchiveException( "Data format exception, failed to decompressed block!", dfe );
				}
				break;
				// End of inflating
			}
			case FLAG_COMPRESSION_BZIP2 : {
				try ( final CBZip2InputStream cis = new CBZip2InputStream( new ByteArrayInputStream( block, 3, block.length - 3 ) ) ) {
					cis.read( dest );
				} catch ( final IOException ie ) {
					throw new InvalidMpqArchiveException( "Data format exception, failed to decompressed block!", ie );
				}
				break;
			}
			default :
				throw new InvalidMpqArchiveException( "Compression (" + compressionFlag + ") not supported!" );
		}
	}
}
 
开发者ID:icza,项目名称:scelight,代码行数:45,代码来源:AlgorithmUtil.java


示例13: createInputStream

import org.apache.tools.bzip2.CBZip2InputStream; //导入依赖的package包/类
/**
 * Creates an input stream to read from a regular or compressed file.
 * 
 * @param fileName a file name with an extension (.gz or .bz2) or without it;
 *                   if the user specifies an extension .gz or .bz2,
 *                   we assume that the input
 *                   file is compressed.
 * @return an input stream to read from the file. 
 * @throws IOException
 */
public static InputStream createInputStream(String fileName) throws IOException {
  InputStream finp = new FileInputStream(fileName);
  if (fileName.endsWith(".gz")) return new GZIPInputStream(finp);
  if (fileName.endsWith(".bz2")) {
    finp.read(new byte[2]); // skip the mark

    return new CBZip2InputStream(finp);
  }
  return finp;
}
 
开发者ID:oaqa,项目名称:knn4qa,代码行数:21,代码来源:CompressUtils.java


示例14: openBZip2Stream

import org.apache.tools.bzip2.CBZip2InputStream; //导入依赖的package包/类
static InputStream openBZip2Stream(InputStream infile) throws IOException {
	int first = infile.read();
	int second = infile.read();
	if (first != 'B' || second != 'Z') {
		throw new IOException("Didn't find BZ file signature in .bz2 file");
	}
	return new CBZip2InputStream(infile);
}
 
开发者ID:dkpro,项目名称:dkpro-jwpl,代码行数:9,代码来源:Tools.java


示例15: decompress

import org.apache.tools.bzip2.CBZip2InputStream; //导入依赖的package包/类
/**
 * Uncompress bz2 file
 *
 * @param path
 *            path to file to uncompress
 * @throws IOException
 */
public void decompress(String path)
	throws IOException
{
	File bzip2 = new File(path);

	//
	File unarchived = new File(bzip2.getName().replace(".bz2", ""));

	unarchived.createNewFile();

	BufferedInputStream inputStr = new BufferedInputStream(new FileInputStream(bzip2));

	// read bzip2 prefix
	inputStr.read();
	inputStr.read();

	BufferedInputStream buffStr = new BufferedInputStream(inputStr);

	CBZip2InputStream input = new CBZip2InputStream(buffStr);

	FileOutputStream outStr = new FileOutputStream(unarchived);

	while (true) {
		byte[] compressedBytes = new byte[DECOMPRESSION_CACHE];

		int byteRead = input.read(compressedBytes);

		outStr.write(compressedBytes, 0, byteRead);
		if (byteRead != DECOMPRESSION_CACHE) {
			break;
		}
	}

	input.close();
	buffStr.close();
	inputStr.close();
	outStr.close();
}
 
开发者ID:dkpro,项目名称:dkpro-jwpl,代码行数:46,代码来源:Bzip2Archiver.java


示例16: read

import org.apache.tools.bzip2.CBZip2InputStream; //导入依赖的package包/类
public InputStream read() {
    InputStream is = resource.read();
    try {
        // CBZip2InputStream expects the opening "BZ" to be skipped
        byte[] skip = new byte[2];
        is.read(skip);
        return new CBZip2InputStream(is);
    } catch (Exception e) {
        String message = String.format("Unable to create bzip2 input stream for resource %s.", resource.getDisplayName());
        throw new ResourceException(message, e);
    }
}
 
开发者ID:Pushjet,项目名称:Pushjet-Android,代码行数:13,代码来源:Bzip2Archiver.java


示例17: decompressMultiBlock

import org.apache.tools.bzip2.CBZip2InputStream; //导入依赖的package包/类
/**
 * Decompresses a block which was compressed using the multi compression method.
 * 
 * @param block   block to be decompressed
 * @param outSize size of the decompressed data
 * @param dest    buffer to copy the decompressed data
 * @param destPos position in the destination buffer to copy the decompressed data
 * @throws InvalidMpqArchiveException if unsupported compression is found or the decompression of the block fails  
 */
public static void decompressMultiBlock( byte[] block, final int outSize, final byte[] dest, final int destPos ) throws InvalidMpqArchiveException {
	// Check if block is really compressed, some blocks have set the compression flag, but are not compressed.
	if ( block.length >= outSize ) {
		// Copy block
		System.arraycopy( block, 0, dest, destPos, outSize );
	}
	else {
		final byte compressionFlag = block[ 0 ];
		
		switch ( compressionFlag ) {
		case FLAG_COMPRESSION_ZLIB : {
			// Handle deflated code (compressionFlag = 0x02)
			final Inflater inflater = new Inflater();
			inflater.setInput( block, 1, block.length - 1 );
			try {
				inflater.inflate( dest, destPos, outSize );
				inflater.end();
			} catch ( final DataFormatException dfe ) {
				throw new InvalidMpqArchiveException( "Data format exception, failed to decompressed block!", dfe );
			}
			break;
			// End of inflating
		}
		case FLAG_COMPRESSION_BZIP2 : {
			try {
				new CBZip2InputStream( new ByteArrayInputStream( block, 3, block.length - 3 ) ).read( dest );
			} catch ( final IOException ie ) {
				throw new InvalidMpqArchiveException( "Data format exception, failed to decompressed block!", ie );
			}
			break;
		}
		default :
			throw new InvalidMpqArchiveException( "Compression (" + compressionFlag + ") not supported!" );
		}
	}
}
 
开发者ID:icza,项目名称:sc2gears,代码行数:46,代码来源:AlgorithmUtil.java


示例18: wrapStream

import org.apache.tools.bzip2.CBZip2InputStream; //导入依赖的package包/类
/**
 * Decompress on the fly using {@link CBZip2InputStream}.
 * @param in the stream to wrap.
 * @return the wrapped stream.
 * @throws IOException if there is a problem.
 */
@Override
protected InputStream wrapStream(InputStream in) throws IOException {
    for (int i = 0; i < MAGIC.length; i++) {
        if (in.read() != MAGIC[i]) {
            throw new IOException("Invalid bz2 stream.");
        }
    }
    return new CBZip2InputStream(in);
}
 
开发者ID:apache,项目名称:ant,代码行数:16,代码来源:BZip2Resource.java


示例19: decompress

import org.apache.tools.bzip2.CBZip2InputStream; //导入依赖的package包/类
/**
 * Uncompress bz2 file
 *
 * @param path
 *            path to file to uncompress
 * @throws IOException
 */
public void decompress(String path)
	throws IOException
{
	File bzip2 = new File(path);

	//
	File unarchived = new File(bzip2.getName().replace(".bz2", ""));

	unarchived.createNewFile();

	FileInputStream inputStr = new FileInputStream(bzip2);

	// read bzip2 prefix
	inputStr.read();
	inputStr.read();

	BufferedInputStream buffStr = new BufferedInputStream(inputStr);

	CBZip2InputStream input = new CBZip2InputStream(buffStr);

	FileOutputStream outStr = new FileOutputStream(unarchived);

	while (true) {
		byte[] compressedBytes = new byte[DECOMPRESSION_CACHE];

		int byteRead = input.read(compressedBytes);

		outStr.write(compressedBytes, 0, byteRead);
		if (byteRead != DECOMPRESSION_CACHE) {
			break;
		}
	}

	input.close();
	buffStr.close();
	inputStr.close();
	outStr.close();
}
 
开发者ID:fauconnier,项目名称:LaToe,代码行数:46,代码来源:Bzip2Archiver.java


示例20: EvidenceRecordFileIterator

import org.apache.tools.bzip2.CBZip2InputStream; //导入依赖的package包/类
EvidenceRecordFileIterator(File file) throws FileNotFoundException, IOException {
	InputStream is = new FileInputStream(file);
	// have to skip first two bytes due to some apache bzip2 peculiarity:
	is.read();
	is.read();
	reader = new BufferedReader(new InputStreamReader(new CBZip2InputStream(is)));
	readHeader();
	readNext();
}
 
开发者ID:enasequence,项目名称:cramtools,代码行数:10,代码来源:EvidenceRecordFileIterator.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java IWorkingSetManager类代码示例发布时间:2022-05-21
下一篇:
Java AuthnContextClassRef类代码示例发布时间:2022-05-21
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap