--- /dev/null
+package org.ibex.util;
+import java.io.*;
+import java.util.*;
+import java.util.zip.*;
+
+public class Encode {
+
+ public static class JavaSourceCode {
+
+ 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 String encode(String packageName, String className, InputStream is) throws IOException {
+
+ // compress first, since the encoded form has more entropy
+ ByteArrayOutputStream baos;
+ OutputStream os = new GZIPOutputStream(baos = new ByteArrayOutputStream());
+
+ byte[] buf = new byte[1024];
+ while(true) {
+ int numread = is.read(buf, 0, buf.length);
+ if (numread == -1) break;
+ os.write(buf, 0, numread);
+ }
+ os.close();
+ buf = baos.toByteArray();
+
+ StringBuffer ret = new StringBuffer();
+ 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");
+ for(int pos = 0; pos<buf.length;) {
+ ret.append(" \"");
+ for(int i=0; i<LINE_LENGTH && pos<buf.length; i++) {
+ String cs = Integer.toOctalString(buf[pos++] & 0xff);
+ while(cs.length() < 3) cs = "0" + cs;
+ ret.append("\\" + cs);
+ }
+ ret.append("\" +\n");
+ }
+ ret.append(" \"\";\n");
+ ret.append("}\n");
+ return ret.toString();
+ }
+
+ }
+
+}
+