public static void main(String[] args) throws Exception { String from = args[0]; String to = args[1]; try (FileInputStream fileStream = new FileInputStream(from); XZInputStream xzStream = new XZInputStream(fileStream, BasicArrayCache.getInstance())) { Files.copy(xzStream, Paths.get(to), StandardCopyOption.REPLACE_EXISTING); } } }
public static void main(String[] args) throws Exception { String from = CompressXz.class.getClassLoader().getResource("/map/SurfaceMarsMap.dat").toExternalForm(); String to = CompressXz.class.getClassLoader().getResource("/map/SurfaceMarsMap.xz").toExternalForm(); try (FileOutputStream fileStream = new FileOutputStream(to); XZOutputStream xzStream = new XZOutputStream( fileStream, new LZMA2Options(LZMA2Options.PRESET_MAX), BasicArrayCache.getInstance())) { Files.copy(Paths.get(from), xzStream); } } }
public static void main(String[] args) throws Exception { String from = args[0]; String to = args[1]; int offset = Integer.parseInt(args[2]); int size = Integer.parseInt(args[3]); try (SeekableInputStream fileStream = new SeekableFileInputStream(from); SeekableXZInputStream xzStream = new SeekableXZInputStream(fileStream, BasicArrayCache.getInstance())) { xzStream.seek(offset); byte[] buf = new byte[size]; if (size != xzStream.read(buf)) { xzStream.available(); // let it throw the last exception, if any throw new IOException("Truncated stream"); } Files.write(Paths.get(to), buf); } } }