mirror of
https://github.com/exituser/Brewery.git
synced 2026-09-17 05:28:59 +00:00
Made En/Decode table static
Create a new En/Decoder Instance for each Stream
This commit is contained in:
@@ -6,10 +6,9 @@ import java.io.InputStream;
|
|||||||
|
|
||||||
public class Base91DecoderStream extends FilterInputStream {
|
public class Base91DecoderStream extends FilterInputStream {
|
||||||
|
|
||||||
private static final basE91 DECODER = new basE91();
|
private final basE91 decoder = new basE91();
|
||||||
|
|
||||||
private byte[] decbuf = new byte[18];
|
private byte[] decbuf = new byte[18];
|
||||||
private byte[] buf = new byte[16];
|
private byte[] buf = new byte[18];
|
||||||
private int reader = 0;
|
private int reader = 0;
|
||||||
private int count = 0;
|
private int count = 0;
|
||||||
private byte[] markBuf = null;
|
private byte[] markBuf = null;
|
||||||
@@ -22,13 +21,13 @@ public class Base91DecoderStream extends FilterInputStream {
|
|||||||
reader = 0;
|
reader = 0;
|
||||||
count = in.read(decbuf);
|
count = in.read(decbuf);
|
||||||
if (count < 1) {
|
if (count < 1) {
|
||||||
count = DECODER.decEnd(buf);
|
count = decoder.decEnd(buf);
|
||||||
if (count < 1) {
|
if (count < 1) {
|
||||||
count = -1;
|
count = -1;
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
count = DECODER.decode(decbuf, count, buf);
|
count = decoder.decode(decbuf, count, buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -100,14 +99,14 @@ public class Base91DecoderStream extends FilterInputStream {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int available() throws IOException {
|
public int available() throws IOException {
|
||||||
return Math.round(in.available() * 0.813F); // Ratio encoded to decoded with random data
|
return (int) (in.available() * 0.813F); // Ratio encoded to decoded with random data
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void close() throws IOException {
|
public void close() throws IOException {
|
||||||
in.close();
|
in.close();
|
||||||
count = -1;
|
count = -1;
|
||||||
DECODER.decReset();
|
decoder.decReset();
|
||||||
buf = null;
|
buf = null;
|
||||||
decbuf = null;
|
decbuf = null;
|
||||||
}
|
}
|
||||||
@@ -117,7 +116,7 @@ public class Base91DecoderStream extends FilterInputStream {
|
|||||||
if (!markSupported()) return;
|
if (!markSupported()) return;
|
||||||
if (count == -1) return;
|
if (count == -1) return;
|
||||||
in.mark(readlimit);
|
in.mark(readlimit);
|
||||||
DECODER.decMark();
|
decoder.decMark();
|
||||||
if (count > 0 && reader < count) {
|
if (count > 0 && reader < count) {
|
||||||
markBuf = new byte[count - reader];
|
markBuf = new byte[count - reader];
|
||||||
System.arraycopy(buf, reader, markBuf, 0, markBuf.length);
|
System.arraycopy(buf, reader, markBuf, 0, markBuf.length);
|
||||||
@@ -128,9 +127,9 @@ public class Base91DecoderStream extends FilterInputStream {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public synchronized void reset() throws IOException {
|
public synchronized void reset() throws IOException {
|
||||||
if (!markSupported()) throw new IOException("mark and reset not supported");
|
if (!markSupported()) throw new IOException("mark and reset not supported by underlying Stream");
|
||||||
in.reset();
|
in.reset();
|
||||||
DECODER.decUnmark();
|
decoder.decUnmark();
|
||||||
reader = 0;
|
reader = 0;
|
||||||
count = 0;
|
count = 0;
|
||||||
if (markBuf != null) {
|
if (markBuf != null) {
|
||||||
|
|||||||
@@ -7,8 +7,7 @@ import java.io.OutputStream;
|
|||||||
|
|
||||||
public class Base91EncoderStream extends FilterOutputStream {
|
public class Base91EncoderStream extends FilterOutputStream {
|
||||||
|
|
||||||
private static final basE91 ENCODER = new basE91();
|
private final basE91 encoder = new basE91();
|
||||||
|
|
||||||
private byte[] buf = new byte[16];
|
private byte[] buf = new byte[16];
|
||||||
private byte[] encBuf = new byte[24];
|
private byte[] encBuf = new byte[24];
|
||||||
private int writer = 0;
|
private int writer = 0;
|
||||||
@@ -19,7 +18,7 @@ public class Base91EncoderStream extends FilterOutputStream {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void encFlush() throws IOException {
|
private void encFlush() throws IOException {
|
||||||
encoded = ENCODER.encode(buf, writer, encBuf);
|
encoded = encoder.encode(buf, writer, encBuf);
|
||||||
out.write(encBuf, 0, encoded);
|
out.write(encBuf, 0, encoded);
|
||||||
writer = 0;
|
writer = 0;
|
||||||
}
|
}
|
||||||
@@ -51,9 +50,9 @@ public class Base91EncoderStream extends FilterOutputStream {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (off == 0 && buf.length >= len) {
|
if (off == 0 && buf.length >= len) {
|
||||||
// Buffer is too full, so flush and encode data directly
|
// Buffer is too full but it would fit, so flush and encode data directly
|
||||||
encFlush();
|
encFlush();
|
||||||
encoded = ENCODER.encode(b, len, encBuf);
|
encoded = encoder.encode(b, len, encBuf);
|
||||||
out.write(encBuf, 0, encoded);
|
out.write(encBuf, 0, encoded);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -76,7 +75,7 @@ public class Base91EncoderStream extends FilterOutputStream {
|
|||||||
encFlush();
|
encFlush();
|
||||||
}
|
}
|
||||||
|
|
||||||
encoded = ENCODER.encEnd(encBuf);
|
encoded = encoder.encEnd(encBuf);
|
||||||
if (encoded > 0) {
|
if (encoded > 0) {
|
||||||
out.write(encBuf, 0, encoded);
|
out.write(encBuf, 0, encoded);
|
||||||
}
|
}
|
||||||
@@ -86,7 +85,7 @@ public class Base91EncoderStream extends FilterOutputStream {
|
|||||||
@Override
|
@Override
|
||||||
public void close() throws IOException {
|
public void close() throws IOException {
|
||||||
super.close();
|
super.close();
|
||||||
ENCODER.encReset();
|
encoder.encReset();
|
||||||
buf = null;
|
buf = null;
|
||||||
encBuf = null;
|
encBuf = null;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ public class LoreWriter extends ByteArrayOutputStream {
|
|||||||
public void flush() throws IOException {
|
public void flush() throws IOException {
|
||||||
super.flush();
|
super.flush();
|
||||||
if (size() <= 0) return;
|
if (size() <= 0) return;
|
||||||
if (flushed) {
|
if (flushed || meta == null) {
|
||||||
// Dont write twice
|
// Dont write twice
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,10 +33,11 @@ package com.dre.brewery.lore;
|
|||||||
|
|
||||||
public class basE91
|
public class basE91
|
||||||
{
|
{
|
||||||
|
public static final byte[] enctab;
|
||||||
|
private static final byte[] dectab;
|
||||||
|
|
||||||
private int ebq, en, dbq, dn, dv;
|
private int ebq, en, dbq, dn, dv;
|
||||||
private int[] marker = null;
|
private int[] marker = null;
|
||||||
public final byte[] enctab;
|
|
||||||
private final byte[] dectab;
|
|
||||||
|
|
||||||
public int encode(byte[] ib, int n, byte[] ob)
|
public int encode(byte[] ib, int n, byte[] ob)
|
||||||
{
|
{
|
||||||
@@ -136,6 +137,11 @@ public class basE91
|
|||||||
|
|
||||||
public basE91()
|
public basE91()
|
||||||
{
|
{
|
||||||
|
encReset();
|
||||||
|
decReset();
|
||||||
|
}
|
||||||
|
|
||||||
|
static {
|
||||||
int i;
|
int i;
|
||||||
String ts = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!$%&()*+,-./:;<=>?@[]^_`{|}~\""; // Added '-' removed '#'
|
String ts = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!$%&()*+,-./:;<=>?@[]^_`{|}~\""; // Added '-' removed '#'
|
||||||
|
|
||||||
@@ -145,7 +151,5 @@ public class basE91
|
|||||||
dectab[i] = -1;
|
dectab[i] = -1;
|
||||||
for (i = 0; i < 91; ++i)
|
for (i = 0; i < 91; ++i)
|
||||||
dectab[enctab[i]] = (byte) i;
|
dectab[enctab[i]] = (byte) i;
|
||||||
encReset();
|
|
||||||
decReset();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user