org.tukaani.xz.LZMA2Options Java Examples
The following examples show how to use
org.tukaani.xz.LZMA2Options.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: XZPayloadCoding.java From packagedrone with Eclipse Public License 1.0 | 6 votes |
@Override public OutputStream createOutputStream ( final OutputStream out, final Optional<String> optionalFlags ) throws IOException { final String flags; final int preset; if ( optionalFlags.isPresent () && ( flags = optionalFlags.get () ).length () > 0 ) { preset = Integer.parseInt ( flags.substring ( 0, 1 ) ); } else { preset = LZMA2Options.PRESET_DEFAULT; } return new XZCompressorOutputStream ( out, preset ); }
Example #2
Source File: XzStep.java From buck with Apache License 2.0 | 6 votes |
/** * Create an {@link XzStep} to compress a file using XZ. * * @param sourceFile file to compress * @param destinationFile where to store compressed data * @param compressionLevel a value between 0-9, it impacts memory requirements for decompression * @param keep by default, {@code xz} deletes the source file when compressing. This argument * forces {@code xz} to keep it. * @param check integrity check to use. Must be one of {@link XZ#CHECK_CRC32}, {@link * XZ#CHECK_CRC64}, {@link XZ#CHECK_SHA256}, {@link XZ#CHECK_NONE} (Note: XZ Embedded can only * verify CRC32). */ @VisibleForTesting XzStep( ProjectFilesystem filesystem, Path sourceFile, Path destinationFile, int compressionLevel, boolean keep, int check) { this.filesystem = filesystem; this.sourceFile = sourceFile; this.destinationFile = destinationFile; Preconditions.checkArgument( compressionLevel >= LZMA2Options.PRESET_MIN && compressionLevel <= LZMA2Options.PRESET_MAX, "compressionLevel out of bounds."); this.compressionLevel = compressionLevel; this.keep = keep; this.check = check; }
Example #3
Source File: XzStep.java From buck with Apache License 2.0 | 6 votes |
@Override public StepExecutionResult execute(ExecutionContext context) throws IOException { boolean deleteSource = false; try (InputStream in = filesystem.newFileInputStream(sourceFile); OutputStream out = filesystem.newFileOutputStream(destinationFile); XZOutputStream xzOut = new XZOutputStream(out, new LZMA2Options(compressionLevel), check)) { XzMemorySemaphore.acquireMemory(compressionLevel); ByteStreams.copy(in, xzOut); xzOut.finish(); deleteSource = !keep; } finally { XzMemorySemaphore.releaseMemory(compressionLevel); } if (deleteSource) { filesystem.deleteFileAtPath(sourceFile); } return StepExecutionResults.SUCCESS; }
Example #4
Source File: HeapAnalysisModule.java From spark with GNU General Public License v3.0 | 5 votes |
@Override public Path compress(Path file, LongConsumer progressHandler) throws IOException { Path compressedFile = file.getParent().resolve(file.getFileName().toString() + ".xz"); try (InputStream in = Files.newInputStream(file)) { try (OutputStream out = Files.newOutputStream(compressedFile)) { try (XZOutputStream compressionOut = new XZOutputStream(out, new LZMA2Options())) { copy(in, compressionOut, progressHandler); } } } return compressedFile; }
Example #5
Source File: HeapAnalysisModule.java From spark with GNU General Public License v3.0 | 5 votes |
@Override public Path compress(Path file, LongConsumer progressHandler) throws IOException { Path compressedFile = file.getParent().resolve(file.getFileName().toString() + ".lzma"); try (InputStream in = Files.newInputStream(file)) { try (OutputStream out = Files.newOutputStream(compressedFile)) { try (LZMAOutputStream compressionOut = new LZMAOutputStream(out, new LZMA2Options(), true)) { copy(in, compressionOut, progressHandler); } } } return compressedFile; }
Example #6
Source File: StandardCompressXz.java From mars-sim with GNU General Public License v3.0 | 5 votes |
public static void main(String[] args) throws Exception { // InputStream fis; //File file = new File(DEFAULT_DIR, TEMP_FILE); // This works both within Eclipse project and in runnable JAR //InputStream fis = StandardCompressXz.class.getResourceAsStream("SurfaceMarsMap.dat"); // This works both within Eclipse project and in runnable JAR //InputStream fis = this.getClass().getClassLoader().getResourceAsStream("/map/SurfaceMarsMap.dat"); //fis = this.getClass().getClassLoader().getResourceAsStream("examples/resources/verdana.ttf"); // fis = StandardCompressXz.class.getClassLoader().getResourceAsStream("SurfaceMarsMap.dat.7z"); FileInputStream inFile = new FileInputStream(StandardCompressXz.class.getClassLoader().getResource("/map/SurfaceMarsMap.dat").toExternalForm());//"SurfaceMarsMap.dat"); FileOutputStream outfile = new FileOutputStream("/map/SurfaceMarsMap.xz"); LZMA2Options options = new LZMA2Options(); options.setPreset(7); // play with this number: 6 is default but 7 works better for mid sized archives ( > 8mb) XZOutputStream out = new XZOutputStream(outfile, options); byte[] buf = new byte[8192]; int size; while ((size = inFile.read(buf)) != -1) out.write(buf, 0, size); out.finish(); }
Example #7
Source File: XZCompressionFilterTest.java From kieker with Apache License 2.0 | 5 votes |
/** * Test method for * {@link kieker.monitoring.writer.compression.XZCompressionFilter#chainOutputStream(java.io.OutputStream, java.nio.file.Path)}. */ @Test public void testChainOutputStream() { final String inputStr = "Hello World"; final byte[] inputData = inputStr.getBytes(Charset.defaultCharset()); final ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); // Stream replicating constructor in test final ByteArrayOutputStream byteArrayOutputStreamR = new ByteArrayOutputStream(); final Configuration configuration = ConfigurationFactory.createDefaultConfiguration(); final XZCompressionFilter unit = new XZCompressionFilter(configuration); final Path path = Paths.get(""); try { // Passing inflated output stream final OutputStream value = unit.chainOutputStream(byteArrayOutputStream, path); // Writing byte array to stream value.write(inputData); // Closing stream value.close(); // Replicating method to be tested final FilterOptions filterOptions = new LZMA2Options(LZMA2Options.PRESET_MAX); final XZOutputStream xzzip = new XZOutputStream(byteArrayOutputStreamR, filterOptions); xzzip.write(inputData); xzzip.close(); // Checking if byteArrayOutputStreamR is equal to byteArrayOutputStream Assert.assertArrayEquals("Expected result does not match with actual result", byteArrayOutputStreamR.toByteArray(), byteArrayOutputStream.toByteArray()); } catch (final IOException e) { e.printStackTrace(); Assert.fail(e.getMessage()); } }
Example #8
Source File: WriteFilmlistJson.java From MLib with GNU General Public License v3.0 | 5 votes |
private void compressFile(String inputName, String outputName) throws IOException { try (InputStream input = new FileInputStream(inputName); FileOutputStream fos = new FileOutputStream(outputName); final OutputStream output = new XZOutputStream(fos, new LZMA2Options()); final ReadableByteChannel inputChannel = Channels.newChannel(input); final WritableByteChannel outputChannel = Channels.newChannel(output)) { fastChannelCopy(inputChannel, outputChannel); } catch (IOException ignored) { } }
Example #9
Source File: LzmaCompression.java From joyrpc with Apache License 2.0 | 4 votes |
public MyLZMAOutputStream(OutputStream os) throws IOException { super(os, new LZMA2Options(), -1); this.os = os; }
Example #10
Source File: XZCompressionFilter.java From kieker with Apache License 2.0 | 4 votes |
@Override public OutputStream chainOutputStream(final OutputStream outputStream, final Path fileName) throws IOException { final FilterOptions filterOptions = new LZMA2Options(LZMA2Options.PRESET_MAX); return new XZOutputStream(outputStream, filterOptions); }