Skip to content

Instantly share code, notes, and snippets.

@octylFractal
Created July 11, 2015 18:18
Show Gist options
  • Save octylFractal/827d7fd804df6cb34c4c to your computer and use it in GitHub Desktop.
Save octylFractal/827d7fd804df6cb34c4c to your computer and use it in GitHub Desktop.
import java.io.*;
import java.nio.*;
import java.nio.file.*;
public class Encode {
private static final byte INIT_BYTE = (byte) 0x17;
private static final byte ESCAPE_BYTE = (byte) 0x18;
private static final byte EXIT_BYTE = (byte) 0x19;
public static void main(String[] args) throws Exception {
try (InputStream in = System.in; OutputStream out = Files.newOutputStream(Paths.get("./encoded.jar"))) {
int read = -1;
out.write(INIT_BYTE);
while ((read = in.read()) != -1) {
if (read == INIT_BYTE || read == ESCAPE_BYTE || read == EXIT_BYTE) {
out.write(ESCAPE_BYTE);
}
out.write(read);
}
out.write(EXIT_BYTE);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment