本文整理匯總了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());
}
示例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));
}
示例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();
}
示例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);
}
}
}
示例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);
}
}
示例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);
}
}
}
}
示例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;
}
}
}
示例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);
}
}
示例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;
}
示例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);
}
}
示例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);
}
}
示例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.");
}
示例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.");
}
示例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));
}
示例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));
}