@Override public void write(final byte[] buf, final int off, final int len) throws IOException { out.write(buf, off, len); }
@Override public void write(final int b) throws IOException { out.write(b); }
@Override public void write(final int b) throws IOException { out.write(b); }
@Override public void write(final byte[] buf, final int off, final int len) throws IOException { out.write(buf, off, len); }
private static byte[] xz(byte[] data, byte[] checksums, File path) throws IOException { ByteArrayOutputStream out = new ByteArrayOutputStream(); LZMA2Options options = new LZMA2Options(); options.setPreset(8); XZOutputStream xz = new XZOutputStream(out, options); int x = checksums.length; xz.write(data); xz.write(checksums); xz.write(new byte[]{ (byte) (x & 0x000000FF), (byte)((x & 0x0000FF00) >> 8), (byte)((x & 0x00FF0000) >> 16), (byte)((x & 0xFF000000) >> 24) }); xz.write("SIGN".getBytes()); //Add our sign to validate xz.close(); byte[] xzed = out.toByteArray(); Files.write(xzed, new File(path.getAbsolutePath() + ".pack.xz")); return xzed; }
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(); } }
@Override public void run() { try { DataBuffer buffer = writableBuffers.take(); int currentFile = buffer.fileID; byte[][] dataBuffers = buffer.data; FileOutputStream logOutputStream = new FileOutputStream(new File(targetDirectory, "robotData." + currentFile + ".xz")); XZOutputStream xzOutputStream = new XZOutputStream(logOutputStream, new LZMA2Options(COMPRESSION_LEVEL)); int writtenLength = 0; for (int i = 0; i < getNumberOfVariables(); i++) { writtenLength += buffer.length * 8; xzOutputStream.write(dataBuffers[i], 0, buffer.length * 8); } out.println("Wrote " + writtenLength / (1024 * 1024) + " MB to robotData." + currentFile + ".xz"); xzOutputStream.close(); logOutputStream.close(); availableBuffers.put(buffer); incrementProgressMonitor(); } catch (IOException | InterruptedException e) { e.printStackTrace(); } }
@Override public void run() { try { DataBuffer buffer = writableBuffers.take(); int currentFile = buffer.fileID; byte[][] dataBuffers = buffer.data; FileOutputStream logOutputStream = new FileOutputStream(new File(targetDirectory, "robotData." + currentFile + ".xz")); XZOutputStream xzOutputStream = new XZOutputStream(logOutputStream, new LZMA2Options(COMPRESSION_LEVEL)); int writtenLength = 0; for (int i = 0; i < getNumberOfVariables(); i++) { writtenLength += buffer.length * 8; xzOutputStream.write(dataBuffers[i], 0, buffer.length * 8); } out.println("Wrote " + writtenLength / (1024 * 1024) + " MB to robotData." + currentFile + ".xz"); xzOutputStream.close(); logOutputStream.close(); availableBuffers.put(buffer); incrementProgressMonitor(); } catch (IOException | InterruptedException e) { e.printStackTrace(); } }
@Override public void run() { try { DataBuffer buffer = writableBuffers.take(); int currentFile = buffer.fileID; byte[][] dataBuffers = buffer.data; FileOutputStream logOutputStream = new FileOutputStream(new File(out + "robotData." + currentFile + ".xz")); XZOutputStream xzOutputStream = new XZOutputStream(logOutputStream, new LZMA2Options(COMPRESSION_LEVEL)); int writtenLength = 0; for (int i = 0; i < getNumberOfVariables(); i++) { writtenLength += dataBuffers[i].length; xzOutputStream.write(dataBuffers[i]); } System.out.println("Wrote " + writtenLength / (1024 * 1024) + " MB"); xzOutputStream.close(); logOutputStream.close(); availableBuffers.put(buffer); } catch (IOException | InterruptedException e) { e.printStackTrace(); } }