From fac420807bedd1ace55f335fc8ae9f015a15ebb6 Mon Sep 17 00:00:00 2001 From: adam Date: Wed, 29 Dec 2004 04:42:03 +0000 Subject: [PATCH] added org.ibex.util.Encode.JavaSourceCode darcs-hash:20041229044203-5007d-51d0438d9b6e4b82dfe2d0808d0f490c06a3a019.gz --- src/org/ibex/util/Encode.java | 50 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 src/org/ibex/util/Encode.java diff --git a/src/org/ibex/util/Encode.java b/src/org/ibex/util/Encode.java new file mode 100644 index 0000000..7021dc2 --- /dev/null +++ b/src/org/ibex/util/Encode.java @@ -0,0 +1,50 @@ +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