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


Java CompressorException类代码示例

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


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

示例1: system_size

import org.apache.commons.compress.compressors.CompressorException; //导入依赖的package包/类
@Test
public void system_size() throws IOException, CompressorException, ArchiveException
{
   ProcessingManager mgr = new ProcessingManager();
   long size = mgr.system_size(sample);
   Assert.assertEquals(size, 494928);
   
   File folder=sample.getParentFile();
   File extaction_folder=new File(folder, "unzip");
   extaction_folder.mkdirs();
   
   UnZip.unCompress(sample.getAbsolutePath(), 
      extaction_folder.getAbsolutePath());
   
   File tocheck = extaction_folder.listFiles()[0];
   size = mgr.system_size(tocheck);
   Assert.assertEquals(size, SIZE, tocheck.getAbsolutePath());
}
 
开发者ID:SentinelDataHub,项目名称:dhus-core,代码行数:19,代码来源:ProcessingManagerTest.java

示例2: setupSegmentsAndOutput

import org.apache.commons.compress.compressors.CompressorException; //导入依赖的package包/类
private void setupSegmentsAndOutput(PatchExecutor executor)
    throws CompressorException, IOException {
  controlBlockLen = readOffset();
  diffBlockLen = readOffset();
  int newFileSize = readOffset();

  extraBlockLen =
      patchInput.array().length - (BSDIFF_HEADER_LENGTH + controlBlockLen + diffBlockLen);

  executor.createOutput(newFileSize);
  controlStream = new BZip2CompressorInputStream(
      new ByteArrayInputStream(patchInput.array(), BSDIFF_HEADER_LENGTH, controlBlockLen));
  diffStream = new BZip2CompressorInputStream(
      new ByteArrayInputStream(patchInput.array(), BSDIFF_HEADER_LENGTH + controlBlockLen,
          diffBlockLen));
  extraStream = new BZip2CompressorInputStream(
      new ByteArrayInputStream(patchInput.array(),
          BSDIFF_HEADER_LENGTH + controlBlockLen + diffBlockLen,
          extraBlockLen));
}
 
开发者ID:inferjay,项目名称:r8,代码行数:21,代码来源:BSPatch.java

示例3: testPack

import org.apache.commons.compress.compressors.CompressorException; //导入依赖的package包/类
@Test
public void testPack() throws IOException, CompressorException {
    ws.create("c/a.txt");
    ws.create("a/c.txt");
    ws.create("中文文件名.txt");
    ws.create("a.txt");
    ws.create("b.wma");

    ws.write("a.txt","111",false,true,true);


    File targetFile = new File("./target/ws.tar.gz");

    try (OutputStream out = new FileOutputStream(targetFile)) {
        ws.pack("/", out);
    }

    assertEntry(targetFile, "a/c.txt");
    assertEntry(targetFile, "中文文件名.txt");

    targetFile.delete();
}
 
开发者ID:Coding,项目名称:WebIDE-Backend,代码行数:23,代码来源:WorkspaceTest.java

示例4: createInputStreamIterator

import org.apache.commons.compress.compressors.CompressorException; //导入依赖的package包/类
Iterator<InputStream> createInputStreamIterator(InputStream in)
        throws IOException {
    // It is required to support mark to detect a file format.
    in = in.markSupported() ? in : new BufferedInputStream(in);
    try {
        return new ArchiveInputStreamIterator(
                createArchiveInputStream(AUTO_DETECT_FORMAT, in),
                this.matchName
        );
    } catch (IOException | ArchiveException e) {
        // ArchiveStreamFactory set mark and reset the stream.
        // So, we can use the same stream to check compressor.
        try {
            return toIterator(createCompressorInputStream(AUTO_DETECT_FORMAT, in));
        } catch (CompressorException e2) {
            throw new IOException("Failed to detect a file format.", e2);
        }
    }
}
 
开发者ID:hata,项目名称:embulk-decoder-commons-compress,代码行数:20,代码来源:CommonsCompressProvider.java

示例5: createCompressorInputStream

import org.apache.commons.compress.compressors.CompressorException; //导入依赖的package包/类
CompressorInputStream createCompressorInputStream(String format,
        InputStream in) throws IOException, CompressorException {
    CompressorStreamFactory factory = new CompressorStreamFactory();
    factory.setDecompressConcatenated(decompressConcatenated);
    if (CommonsCompressUtil.isAutoDetect(format)) {
        in = in.markSupported() ? in : new BufferedInputStream(in);
        try {
            return factory.createCompressorInputStream(in);
        } catch (CompressorException e) {
            throw new IOException(
                    "Failed to detect a file format. Please try to set a format explicitly.",
                    e);
        }
    } else {
        return factory.createCompressorInputStream(format, in);
    }
}
 
开发者ID:hata,项目名称:embulk-decoder-commons-compress,代码行数:18,代码来源:CommonsCompressProvider.java

示例6: compress

import org.apache.commons.compress.compressors.CompressorException; //导入依赖的package包/类
@Override
public void compress(File[] files, String location, String name)
        throws IOException, ArchiveException, CompressorException {

    initAlgorithmProgress(files);
    String fullname = FileUtils.combinePathAndFilename(location, name);

    try (BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(fullname))) {
        try (CompressorOutputStream cos = makeCompressorOutputStream(bos)) {
            try (ArchiveOutputStream aos = cos != null
                    ? makeArchiveOutputStream(cos)
                    : makeArchiveOutputStream(bos)) {
                compress(files, "", aos);
            }
        }
    }
}
 
开发者ID:turbolocust,项目名称:GZipper,代码行数:18,代码来源:ArchivingAlgorithm.java

示例7: main

import org.apache.commons.compress.compressors.CompressorException; //导入依赖的package包/类
/**
 * Select s8rXX, non-anti, games from the file  ~/dev/novello/Othello/latest.223270.bz2
 */
public static void main(String[] args) throws IOException, CompressorException {
    final List<MeValue> mvs = new RandGameMvSource().getMvs();
    System.out.format("%,d total positions", mvs.size());

    int nPrinted = 0;
    for (MeValue mv : mvs) {
        if (Math.abs(mv.value) > 2000 && mv.nEmpty() < 3) {
            System.out.println(mv);
            nPrinted++;
        }
        if (nPrinted > 100) {
            break;
        }
    }
}
 
开发者ID:weltyc,项目名称:novello,代码行数:19,代码来源:RandGameMvSource.java

示例8: unCompress

import org.apache.commons.compress.compressors.CompressorException; //导入依赖的package包/类
/** Unpackages single file content, uses various techniques to uncompress it */
    public static byte[] unCompress(byte[] content) throws IOException {
        //TODO: should probably catch the case if the file is already uncompressed
        try (
                ByteArrayInputStream compressedIn = new ByteArrayInputStream(content);
                CompressorInputStream compressedInStream = new CompressorStreamFactory().createCompressorInputStream(compressedIn);
                ByteArrayOutputStream out = new ByteArrayOutputStream();
                ) {
            final byte[] buffer = new byte[8192];
            int n;
            while ((n = compressedInStream.read(buffer)) != -1) {
                out.write(buffer, 0, n);
            }

            byte[] uncompressed = out.toByteArray();
            return uncompressed;
        } catch (CompressorException e) {
//            System.out.println("General gunzip approach failed trying unzip");
//            e.printStackTrace();
            
            // try unzip approach, given the other ones failed
            return unZip(content);
        }
    }
 
开发者ID:stucco,项目名称:collectors,代码行数:25,代码来源:UnpackUtils.java

示例9: getArchive

import org.apache.commons.compress.compressors.CompressorException; //导入依赖的package包/类
private static Path getArchive(final Path path) throws IOException {
    final Path result;
    // Get the extension
    final String fileName = path.getFileName().toString();
    final String loweredFileName = fileName.toLowerCase(Locale.ENGLISH);
    if (loweredFileName.endsWith(".gz")) {
        String tempFileName = fileName.substring(0, loweredFileName.indexOf(".gz"));
        final int index = tempFileName.lastIndexOf('.');
        if (index > 0) {
            result = Files.createTempFile(tempFileName.substring(0, index), tempFileName.substring(index, tempFileName.length()));
        } else {
            result = Files.createTempFile(tempFileName.substring(0, index), "");
        }
        try (CompressorInputStream in = new CompressorStreamFactory().createCompressorInputStream(new BufferedInputStream(Files.newInputStream(path)))) {
            Files.copy(in, result, StandardCopyOption.REPLACE_EXISTING);
        } catch (CompressorException e) {
            throw new IOException(e);
        }
    } else {
        result = path;
    }
    return result;
}
 
开发者ID:wildfly,项目名称:wildfly-maven-plugin,代码行数:24,代码来源:Archives.java

示例10: compress

import org.apache.commons.compress.compressors.CompressorException; //导入依赖的package包/类
@Override
public void compress(File source, File destination) throws IllegalArgumentException, IOException {
    assertSource(source);
    assertDestination(destination);

    if (destination.isDirectory()) {
        destination = new File(destination, getCompressedFilename(source));
    }

    CompressorOutputStream compressed = null;
    BufferedInputStream input = null;
    try {
        input = new BufferedInputStream(new FileInputStream(source));
        compressed = createCompressorOutputStream(this, destination);

        IOUtils.copy(input, compressed);
    } catch (CompressorException e) {
        throw new IOException(e);
    } finally {
        IOUtils.closeQuietly(compressed);
        IOUtils.closeQuietly(input);
    }
}
 
开发者ID:thrau,项目名称:jarchivelib,代码行数:24,代码来源:CommonsCompressor.java

示例11: decompress

import org.apache.commons.compress.compressors.CompressorException; //导入依赖的package包/类
@Override
public void decompress(File source, File destination) throws IOException {
    assertSource(source);
    assertDestination(destination);

    if (destination.isDirectory()) {
        destination = new File(destination, getDecompressedFilename(source));
    }

    CompressorInputStream compressed = null;
    FileOutputStream output = null;
    try {
        compressed = createCompressorInputStream(getCompressionType(), source);
        output = new FileOutputStream(destination);
        IOUtils.copy(compressed, output);
    } catch (CompressorException e) {
        throw new IOException(e);
    } finally {
        IOUtils.closeQuietly(compressed);
        IOUtils.closeQuietly(output);
    }
}
 
开发者ID:thrau,项目名称:jarchivelib,代码行数:23,代码来源:CommonsCompressor.java

示例12: createCompressorInputStream

import org.apache.commons.compress.compressors.CompressorException; //导入依赖的package包/类
@Override
public CompressorInputStream createCompressorInputStream(
        final String fileName, final InputStream inputStream)
        throws CompressorException {
    checkNotNull(inputStream, "inputStream");
    checkNotNull(fileName, "fileName");

    try {
        if (GZIP.equalsIgnoreCase(fileName)) {
            return createGZipCompressorInputStream(inputStream);
        } else if (BZIP2.equalsIgnoreCase(fileName)) {
            return createBZip2CompressorInputStream(inputStream);
        } else if (XZ.equalsIgnoreCase(fileName)) {
            return createXZCompressorInputStream(inputStream);
        } else if (PACK200.equalsIgnoreCase(fileName)) {
            return createPack200CompressorInputStream(inputStream);
        } else if (nameDetectionFallback) {
            return createCompressorInputStream(inputStream);
        }
    } catch (IOException e) {
        throw new CompressorException("Could not create CompressorInputStream.", e);
    }
    throw new CompressorException("Compressor: " + fileName + " not found.");
}
 
开发者ID:hamishmorgan,项目名称:WAG,代码行数:25,代码来源:CompressorStreamFactory2.java

示例13: createCompressorOutputStream

import org.apache.commons.compress.compressors.CompressorException; //导入依赖的package包/类
/**
 * Create an compressor output stream from an compressor name and an input
 * stream.
 *
 * @param name         the compressor name, i.e. "gz", "bzip2", "xz", or "pack200"
 * @param outputStream the output stream
 * @return the compressor output stream
 * @throws CompressorException      if the archiver name is not known
 * @throws IllegalArgumentException if the archiver name or stream is null
 */
@Override
public CompressorOutputStream createCompressorOutputStream(
        final String name, final OutputStream outputStream)
        throws CompressorException {
    checkNotNull(outputStream, "outputStream");
    checkNotNull(name, "fileName");
    try {
        if (GZIP.equalsIgnoreCase(name)) {
            return createGZipCompressorOutputStream(outputStream);
        } else if (BZIP2.equalsIgnoreCase(name)) {
            return createBZip2CompressorOutputStream(outputStream);
        } else if (XZ.equalsIgnoreCase(name)) {
            return createXZCompressorOutputStream(outputStream);
        } else if (PACK200.equalsIgnoreCase(name)) {
            return createPack200CompressorOutputStream(outputStream);
        } else if (nameDetectionFallback && transparentSignatureDetection) {
            return createForwardingCompressorOutputStream(outputStream);
        }
    } catch (IOException e) {
        throw new CompressorException("Could not create CompressorOutputStream", e);
    }
    throw new CompressorException("Compressor: " + name + " not found.");
}
 
开发者ID:hamishmorgan,项目名称:WAG,代码行数:34,代码来源:CompressorStreamFactory2.java

示例14: testDecompressBZip2

import org.apache.commons.compress.compressors.CompressorException; //导入依赖的package包/类
@Test
public void testDecompressBZip2() throws IOException, CompressorException {
    final File outputFile = new File(OUTPUT_PATH, BZIP2_FILE.getName() + ".decompressed");

    final CompressorStreamFactory2 instance = CompressorStreamFactory2.builder().build();

    final Closer closer = Closer.create();
    try {
        final CompressorInputStream cis =
                closer.register(instance.createCompressorInputStream(
                        closer.register(new BufferedInputStream(
                                closer.register(new FileInputStream(BZIP2_FILE))))));

        final OutputStream os = closer.register(new BufferedOutputStream(
                closer.register(new FileOutputStream(outputFile))));

        ByteStreams.copy(cis, os);
    } catch (Throwable t) {
        throw closer.rethrow(t);
    } finally {
        closer.close();
    }

    assertTrue("Output files differ.", Files.equal(outputFile, TEXT_FILE));
}
 
开发者ID:hamishmorgan,项目名称:WAG,代码行数:26,代码来源:CompressorStreamFactory2Test.java

示例15: testDecompressBZip2_Concatenate

import org.apache.commons.compress.compressors.CompressorException; //导入依赖的package包/类
@Test
public void testDecompressBZip2_Concatenate() throws IOException, CompressorException {
    final File outputFile = new File(OUTPUT_PATH, BZIP2_FILE.getName() + ".decompressed");

    final CompressorStreamFactory2 instance = CompressorStreamFactory2.builder()
            .setDecompressConcatenated(true).build();

    final Closer closer = Closer.create();
    try {
        final CompressorInputStream cis =
                closer.register(instance.createCompressorInputStream(
                        closer.register(new BufferedInputStream(
                                closer.register(new FileInputStream(BZIP2_FILE))))));

        final OutputStream os = closer.register(new BufferedOutputStream(
                closer.register(new FileOutputStream(outputFile))));

        ByteStreams.copy(cis, os);
    } catch (Throwable t) {
        throw closer.rethrow(t);
    } finally {
        closer.close();
    }
    assertTrue("Output files differ.", Files.equal(outputFile, TEXT_FILE));
}
 
开发者ID:hamishmorgan,项目名称:WAG,代码行数:26,代码来源:CompressorStreamFactory2Test.java


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