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


Java Decoder类代码示例

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


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

示例1: uncompress

import lzma.sdk.lzma.Decoder; //导入依赖的package包/类
/**
 * The compressed file extractor method that takes a compressed file and a destination folder
 * and extracts the given file according to its compression format. The supported formats are declared
 * in the formats class.
 * @param file the compressed file to be extracted
 * @param destinationFolder the folder to which the extracted file will be moved to
 */
public void uncompress(File file, File destinationFolder) {
	String name = file.getName();
	try {
		if (name.endsWith(".zip")) {
			ZipUncompressor.extract(file, destinationFolder);
		} else if (name.endsWith(".tar.gz") || name.endsWith(".tgz")) {
			TarUncompressor.extract(file, new GZIPInputStream(new FileInputStream(file)), destinationFolder);
		} else if (name.endsWith(".tar.bz2") || name.endsWith(".tar.bzip2") || name.endsWith(".tbz2")) {
			TarUncompressor.extract(file, new BZip2CompressorInputStream(new FileInputStream(file)), destinationFolder);
		} else if (name.endsWith(".tar.lzma") || name.endsWith(".tlzma")) {
			TarUncompressor.extract(file, new LzmaInputStream(new FileInputStream(file), new Decoder()), destinationFolder);
		} else if (name.endsWith(".rar")) {
			RarUncompressor.extract(file, destinationFolder);
		} else if (name.endsWith(".tar")) {
			TarUncompressor.extract(file, new FileInputStream(file), destinationFolder);
		} 
	} catch (IOException e) {
		e.printStackTrace();
		throw new GroundhogException("Error when trying to extract the source code", e);
	}
}
 
开发者ID:spgroup,项目名称:groundhog,代码行数:29,代码来源:DefaultUncompressor.java

示例2: decompress

import lzma.sdk.lzma.Decoder; //导入依赖的package包/类
public static byte[] decompress(byte[] compressedBytes) throws IOException {
    InputStream in = new ByteArrayInputStream(compressedBytes);
    ByteArrayOutputStream out = new ByteArrayOutputStream();

    int propertiesSize = 5;
    byte[] properties = new byte[propertiesSize];
    if (in.read(properties, 0, propertiesSize) != propertiesSize) {
        throw new IOException("LZMA-input is too short.");
    }

    Decoder decoder = new Decoder();
    if (!decoder.setDecoderProperties(properties)) {
        throw new IOException("Incorrect stream properties.");
    }

    long outSize = 0;
    for (int i = 0; i < 8; i++) {
        int v = in.read();
        if (v < 0) {
            throw new IOException("Can't read stream size.");
        }
        //noinspection IntegerMultiplicationImplicitCastToLong
        outSize |= (long) v << (8 * i);
    }

    if (!decoder.code(in, out, outSize)) {
        throw new IOException("Error in data stream.");
    }

    in.close();

    return out.toByteArray();
}
 
开发者ID:Codeforces,项目名称:codeforces-commons,代码行数:34,代码来源:LzmaUtil.java


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