summaryrefslogtreecommitdiff
path: root/Java
diff options
context:
space:
mode:
Diffstat (limited to 'Java')
-rw-r--r--Java/b91cli.java181
-rw-r--r--Java/basE91.java137
-rwxr-xr-xJava/build_jar.sh4
-rw-r--r--Java/license.txt25
-rw-r--r--Java/manifest.mf4
-rw-r--r--Java/readme.txt26
6 files changed, 377 insertions, 0 deletions
diff --git a/Java/b91cli.java b/Java/b91cli.java
new file mode 100644
index 0000000..7d39990
--- /dev/null
+++ b/Java/b91cli.java
@@ -0,0 +1,181 @@
+/*
+ * basE91 command line front-end
+ *
+ * Copyright (c) 2000-2006 Joachim Henke
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * - Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * - Neither the name of Joachim Henke nor the names of his contributors may
+ * be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+import java.io.*;
+
+public class b91cli
+{
+ private static void encode(InputStream is, OutputStream os)
+ {
+ int s;
+ byte[] ibuf = new byte[53248];
+ byte[] obuf = new byte[65536];
+ basE91 b91 = new basE91();
+
+ try {
+ while ((s = is.read(ibuf)) > 0) {
+ s = b91.encode(ibuf, s, obuf);
+ os.write(obuf, 0, s);
+ }
+ s = b91.encEnd(obuf);
+ os.write(obuf, 0, s);
+ } catch (Exception e) {
+ System.err.println(e);
+ }
+ }
+
+ private static void encodeWrap(InputStream is, OutputStream os)
+ {
+ int i, s;
+ int n = 0;
+ byte[] ibuf = new byte[53248];
+ byte[] obuf = new byte[65536];
+ char[] line = new char[76];
+ basE91 b91 = new basE91();
+
+ try {
+ PrintStream ps = new PrintStream(os, false, "US-ASCII");
+
+ while ((s = is.read(ibuf)) > 0) {
+ s = b91.encode(ibuf, s, obuf);
+ for (i = 0; i < s; ++i) {
+ line[n++] = (char) obuf[i];
+ if (n == 76) {
+ ps.println(line);
+ n = 0;
+ }
+ }
+ }
+ s = b91.encEnd(obuf);
+ for (i = 0; i < s; ++i) {
+ line[n++] = (char) obuf[i];
+ if (n == 76) {
+ ps.println(line);
+ n = 0;
+ }
+ }
+ if (n > 0)
+ ps.println(new String(line, 0, n));
+ } catch (Exception e) {
+ System.err.println(e);
+ }
+ }
+
+ private static void decode(InputStream is, OutputStream os)
+ {
+ int s;
+ byte[] ibuf = new byte[65536];
+ byte[] obuf = new byte[57344];
+ basE91 b91 = new basE91();
+
+ try {
+ while ((s = is.read(ibuf)) > 0) {
+ s = b91.decode(ibuf, s, obuf);
+ os.write(obuf, 0, s);
+ }
+ s = b91.decEnd(obuf);
+ os.write(obuf, 0, s);
+ } catch (Exception e) {
+ System.err.println(e);
+ }
+ }
+
+ private static void errExit(String msg)
+ {
+ System.err.println("syntax error - " + msg + "\nTry `-h' option for more information.");
+ System.exit(3);
+ }
+
+ public static void main(String[] args)
+ {
+ int i;
+ boolean enc = true;
+ boolean lbr = true;
+ String ifn = null;
+ String ofn = null;
+
+ for (i = 0; i < args.length; ++i)
+ if (args[i].length() == 2 && args[i].charAt(0) == '-')
+ switch (args[i].charAt(1)) {
+ case 'd':
+ enc = false;
+ break;
+ case 'u':
+ lbr = false;
+ break;
+ case 'h':
+ System.out.println("Usage: base91 [OPTION] infile [outfile]\n\n -d\tdecode a basE91 encoded file\n -u\tleave encoder output unformatted (disable line wrapping)\n -h\tdisplay this help and exit\n -V\toutput version information and exit");
+ return;
+ case 'V':
+ System.out.println("base91 0.6.0\nCopyright (c) 2000-2006 Joachim Henke");
+ return;
+ default:
+ errExit("invalid option: " + args[i]);
+ }
+ else if (ifn == null)
+ ifn = args[i];
+ else if (ofn == null)
+ ofn = args[i];
+ else
+ errExit("too many arguments: " + args[i]);
+ if (ifn == null)
+ errExit("file name missing");
+ if (ofn == null)
+ if (enc)
+ ofn = ifn + (lbr ? "_b91.txt" : ".b91");
+ else {
+ String lifn = ifn.toLowerCase();
+ if (ifn.length() > 4 && lifn.endsWith(".b91"))
+ ofn = ifn.substring(0, ifn.length() - 4);
+ else if (ifn.length() > 8 && lifn.endsWith("_b91.txt"))
+ ofn = ifn.substring(0, ifn.length() - 8);
+ else
+ ofn = ifn + ".bin";
+ }
+
+ try {
+ FileInputStream ifs = new FileInputStream(ifn);
+ FileOutputStream ofs = new FileOutputStream(ofn);
+
+ if (enc)
+ if (lbr)
+ encodeWrap(ifs, ofs);
+ else
+ encode(ifs, ofs);
+ else
+ decode(ifs, ofs);
+ ifs.close();
+ ofs.close();
+ } catch (Exception e) {
+ System.err.println(e);
+ }
+ }
+}
diff --git a/Java/basE91.java b/Java/basE91.java
new file mode 100644
index 0000000..56d7fda
--- /dev/null
+++ b/Java/basE91.java
@@ -0,0 +1,137 @@
+/*
+ * basE91 encoding/decoding routines
+ *
+ * Copyright (c) 2000-2006 Joachim Henke
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * - Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * - Neither the name of Joachim Henke nor the names of his contributors may
+ * be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+public class basE91
+{
+ private int ebq, en, dbq, dn, dv;
+ public final byte[] enctab;
+ private final byte[] dectab;
+
+ public int encode(byte[] ib, int n, byte[] ob)
+ {
+ int i, c = 0;
+
+ for (i = 0; i < n; ++i) {
+ ebq |= (ib[i] & 255) << en;
+ en += 8;
+ if (en > 13) {
+ int ev = ebq & 8191;
+
+ if (ev > 88) {
+ ebq >>= 13;
+ en -= 13;
+ } else {
+ ev = ebq & 16383;
+ ebq >>= 14;
+ en -= 14;
+ }
+ ob[c++] = enctab[ev % 91];
+ ob[c++] = enctab[ev / 91];
+ }
+ }
+ return c;
+ }
+
+ public int encEnd(byte[] ob)
+ {
+ int c = 0;
+
+ if (en > 0) {
+ ob[c++] = enctab[ebq % 91];
+ if (en > 7 || ebq > 90)
+ ob[c++] = enctab[ebq / 91];
+ }
+ encReset();
+ return c;
+ }
+
+ public void encReset()
+ {
+ ebq = 0;
+ en = 0;
+ }
+
+ public int decode(byte[] ib, int n, byte[] ob)
+ {
+ int i, c = 0;
+
+ for (i = 0; i < n; ++i) {
+ if (dectab[ib[i]] == -1)
+ continue;
+ if (dv == -1)
+ dv = dectab[ib[i]];
+ else {
+ dv += dectab[ib[i]] * 91;
+ dbq |= dv << dn;
+ dn += (dv & 8191) > 88 ? 13 : 14;
+ do {
+ ob[c++] = (byte) dbq;
+ dbq >>= 8;
+ dn -= 8;
+ } while (dn > 7);
+ dv = -1;
+ }
+ }
+ return c;
+ }
+
+ public int decEnd(byte[] ob)
+ {
+ int c = 0;
+
+ if (dv != -1)
+ ob[c++] = (byte) (dbq | dv << dn);
+ decReset();
+ return c;
+ }
+
+ public void decReset()
+ {
+ dbq = 0;
+ dn = 0;
+ dv = -1;
+ }
+
+ public basE91()
+ {
+ int i;
+ String ts = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!#$%&()*+,./:;<=>?@[]^_`{|}~\"";
+
+ enctab = ts.getBytes();
+ dectab = new byte[256];
+ for (i = 0; i < 256; ++i)
+ dectab[i] = -1;
+ for (i = 0; i < 91; ++i)
+ dectab[enctab[i]] = (byte) i;
+ encReset();
+ decReset();
+ }
+}
diff --git a/Java/build_jar.sh b/Java/build_jar.sh
new file mode 100755
index 0000000..bd54b3e
--- /dev/null
+++ b/Java/build_jar.sh
@@ -0,0 +1,4 @@
+#!/bin/sh
+
+javac -encoding US-ASCII -g:none -source 1.3 -target 1.2 basE91.java b91cli.java && \
+jar cvfm base91.jar manifest.mf b91cli.class basE91.class license.txt readme.txt
diff --git a/Java/license.txt b/Java/license.txt
new file mode 100644
index 0000000..8b952bd
--- /dev/null
+++ b/Java/license.txt
@@ -0,0 +1,25 @@
+Copyright (c) 2000-2006 Joachim Henke
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+ - Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+ - Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+ - Neither the name of Joachim Henke nor the names of his contributors may be
+ used to endorse or promote products derived from this software without
+ specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
diff --git a/Java/manifest.mf b/Java/manifest.mf
new file mode 100644
index 0000000..b06ff67
--- /dev/null
+++ b/Java/manifest.mf
@@ -0,0 +1,4 @@
+Main-Class: b91cli
+Package-Title: basE91 command line tool
+Package-Version: 0.6.0
+Package-Vendor: Joachim Henke
diff --git a/Java/readme.txt b/Java/readme.txt
new file mode 100644
index 0000000..bc5a3ac
--- /dev/null
+++ b/Java/readme.txt
@@ -0,0 +1,26 @@
+This is an implementation of the basE91 encoder and decoder in Java.
+
+Syntax:
+ java -jar base91.jar [OPTION] infile [outfile]
+
+Options:
+
+-d decode a basE91 encoded file;
+ all non-alphabet characters (such as newlines) are ignored
+
+-u leave encoder output unformatted;
+ i. e., disable line wrapping after 76 characters
+
+-h display short help and exit
+
+-V output version information and exit
+
+
+If no outfile is given for encoding, it defaults to `infile_b91.txt' (or to
+`infile.b91' with the `-u' switch).
+On decoding, the added file extension is removed to generate the name for
+outfile; otherwise, if infile hasn't a default extension, the decoded data is
+written to `infile.bin'.
+
+For further information visit the basE91 home page at
+http://base91.sourceforge.net/