+ 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;
+ }
+ }
+