Move XorUpdate back to org.qora package for mainstream use

This commit is contained in:
catbref
2019-11-26 09:02:35 +00:00
parent d9bafaa42c
commit 04839d1fba

View File

@@ -1,58 +0,0 @@
package org.qora.test.apps;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import org.qora.controller.AutoUpdate;
public class XorUpdate {
private static final byte XOR_VALUE = AutoUpdate.XOR_VALUE;
public static void main(String[] args) {
if (args.length != 2) {
System.err.println("usage: XorUpdate <input-file> <output-file>");
System.exit(1);
}
Path inPath = Paths.get(args[0]);
if (!Files.isReadable(inPath)) {
System.err.println(String.format("Cannot open '%s'", args[0]));
System.exit(2);
}
Path outPath = Paths.get(args[1]);
try (InputStream in = Files.newInputStream(inPath); OutputStream out = Files.newOutputStream(outPath)) {
byte[] buffer = new byte[1024 * 1024];
do {
int nread = in.read(buffer);
if (nread == -1)
break;
for (int i = 0; i < nread; ++i)
buffer[i] ^= XOR_VALUE;
out.write(buffer, 0, nread);
} while (true);
out.flush();
} catch (IOException e) {
System.err.println(e.getLocalizedMessage());
try {
Files.deleteIfExists(outPath);
} catch (IOException e1) {
System.err.println(e.getLocalizedMessage());
}
System.exit(2);
}
System.exit(0);
}
}