public static final int LINE_LENGTH = 80 / 4;
public static void main(String[] s) throws Exception { System.out.println(encode(s[0], s[1], System.in)); }
+ public static InputStream decode(String s) throws IOException {
+ return new GZIPInputStream(new StringInputStream(s)); }
+
+ private static class StringInputStream extends InputStream {
+ private final String s;
+ private final int length;
+ private int pos = 0;
+ public StringInputStream(String s) { this.s = s; this.length = s.length(); }
+ public int read() {
+ byte[] b = new byte[1];
+ int numread = read(b, 0, 1);
+ if (numread == -1) return -1;
+ if (numread == 0) throw new Error();
+ return b[0] & 0xff;
+ }
+ public int read(byte[] b, int off, int len) {
+ for(int i=off; i<off+len; i++) {
+ if (pos>=length) return i-off;
+ //int out = s.charAt(pos++);
+ b[i] = (byte)s.charAt(pos++);//(byte)(out > 127 ? 127-out : out);
+ }
+ return len;
+ }
+ }
+
public static String encode(String packageName, String className, InputStream is) throws IOException {
// compress first, since the encoded form has more entropy
ret.append("// generated by " + Encode.class.getName() + "\n\n");
ret.append("package " + packageName + ";\n\n");
ret.append("public class " + className + " {\n");
- ret.append(" public static String data = \n");
+ ret.append(" public static final String data = \n");
for(int pos = 0; pos<buf.length;) {
ret.append(" \"");
for(int i=0; i<LINE_LENGTH && pos<buf.length; i++) {