From fc73b258af00744953b5098c1edb30f871039ef1 Mon Sep 17 00:00:00 2001 From: adam Date: Wed, 29 Dec 2004 07:25:40 +0000 Subject: [PATCH] added Encode.JavaSourceCode.decode() darcs-hash:20041229072540-5007d-a998b9a7c0367d510326b8aee80afddb04099a8c.gz --- src/org/ibex/util/Encode.java | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/src/org/ibex/util/Encode.java b/src/org/ibex/util/Encode.java index 7021dc2..9334d46 100644 --- a/src/org/ibex/util/Encode.java +++ b/src/org/ibex/util/Encode.java @@ -10,6 +10,31 @@ public class Encode { 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=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 @@ -29,7 +54,7 @@ public class Encode { 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