mirror of
https://github.com/DieReicheErethons/Brewery.git
synced 2025-01-05 18:37:40 +01:00
Made En/Decode table static
Create a new En/Decoder Instance for each Stream
This commit is contained in:
parent
3b7e019de3
commit
ca2c49ea08
@ -6,10 +6,9 @@ import java.io.InputStream;
|
||||
|
||||
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[] buf = new byte[16];
|
||||
private byte[] buf = new byte[18];
|
||||
private int reader = 0;
|
||||
private int count = 0;
|
||||
private byte[] markBuf = null;
|
||||
@ -22,13 +21,13 @@ public class Base91DecoderStream extends FilterInputStream {
|
||||
reader = 0;
|
||||
count = in.read(decbuf);
|
||||
if (count < 1) {
|
||||
count = DECODER.decEnd(buf);
|
||||
count = decoder.decEnd(buf);
|
||||
if (count < 1) {
|
||||
count = -1;
|
||||
}
|
||||
return;
|
||||
}
|
||||
count = DECODER.decode(decbuf, count, buf);
|
||||
count = decoder.decode(decbuf, count, buf);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -100,14 +99,14 @@ public class Base91DecoderStream extends FilterInputStream {
|
||||
|
||||
@Override
|
||||
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
|
||||
public void close() throws IOException {
|
||||
in.close();
|
||||
count = -1;
|
||||
DECODER.decReset();
|
||||
decoder.decReset();
|
||||
buf = null;
|
||||
decbuf = null;
|
||||
}
|
||||
@ -117,7 +116,7 @@ public class Base91DecoderStream extends FilterInputStream {
|
||||
if (!markSupported()) return;
|
||||
if (count == -1) return;
|
||||
in.mark(readlimit);
|
||||
DECODER.decMark();
|
||||
decoder.decMark();
|
||||
if (count > 0 && reader < count) {
|
||||
markBuf = new byte[count - reader];
|
||||
System.arraycopy(buf, reader, markBuf, 0, markBuf.length);
|
||||
@ -128,9 +127,9 @@ public class Base91DecoderStream extends FilterInputStream {
|
||||
|
||||
@Override
|
||||
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();
|
||||
DECODER.decUnmark();
|
||||
decoder.decUnmark();
|
||||
reader = 0;
|
||||
count = 0;
|
||||
if (markBuf != null) {
|
||||
|
@ -7,8 +7,7 @@ import java.io.OutputStream;
|
||||
|
||||
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[] encBuf = new byte[24];
|
||||
private int writer = 0;
|
||||
@ -19,7 +18,7 @@ public class Base91EncoderStream extends FilterOutputStream {
|
||||
}
|
||||
|
||||
private void encFlush() throws IOException {
|
||||
encoded = ENCODER.encode(buf, writer, encBuf);
|
||||
encoded = encoder.encode(buf, writer, encBuf);
|
||||
out.write(encBuf, 0, encoded);
|
||||
writer = 0;
|
||||
}
|
||||
@ -51,9 +50,9 @@ public class Base91EncoderStream extends FilterOutputStream {
|
||||
}
|
||||
|
||||
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();
|
||||
encoded = ENCODER.encode(b, len, encBuf);
|
||||
encoded = encoder.encode(b, len, encBuf);
|
||||
out.write(encBuf, 0, encoded);
|
||||
return;
|
||||
}
|
||||
@ -76,7 +75,7 @@ public class Base91EncoderStream extends FilterOutputStream {
|
||||
encFlush();
|
||||
}
|
||||
|
||||
encoded = ENCODER.encEnd(encBuf);
|
||||
encoded = encoder.encEnd(encBuf);
|
||||
if (encoded > 0) {
|
||||
out.write(encBuf, 0, encoded);
|
||||
}
|
||||
@ -86,7 +85,7 @@ public class Base91EncoderStream extends FilterOutputStream {
|
||||
@Override
|
||||
public void close() throws IOException {
|
||||
super.close();
|
||||
ENCODER.encReset();
|
||||
encoder.encReset();
|
||||
buf = null;
|
||||
encBuf = null;
|
||||
}
|
||||
|
@ -25,7 +25,7 @@ public class LoreWriter extends ByteArrayOutputStream {
|
||||
public void flush() throws IOException {
|
||||
super.flush();
|
||||
if (size() <= 0) return;
|
||||
if (flushed) {
|
||||
if (flushed || meta == null) {
|
||||
// Dont write twice
|
||||
return;
|
||||
}
|
||||
|
@ -33,10 +33,11 @@ package com.dre.brewery.lore;
|
||||
|
||||
public class basE91
|
||||
{
|
||||
public static final byte[] enctab;
|
||||
private static final byte[] dectab;
|
||||
|
||||
private int ebq, en, dbq, dn, dv;
|
||||
private int[] marker = null;
|
||||
public final byte[] enctab;
|
||||
private final byte[] dectab;
|
||||
|
||||
public int encode(byte[] ib, int n, byte[] ob)
|
||||
{
|
||||
@ -136,6 +137,11 @@ public class basE91
|
||||
|
||||
public basE91()
|
||||
{
|
||||
encReset();
|
||||
decReset();
|
||||
}
|
||||
|
||||
static {
|
||||
int i;
|
||||
String ts = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!$%&()*+,-./:;<=>?@[]^_`{|}~\""; // Added '-' removed '#'
|
||||
|
||||
@ -145,7 +151,5 @@ public class basE91
|
||||
dectab[i] = -1;
|
||||
for (i = 0; i < 91; ++i)
|
||||
dectab[enctab[i]] = (byte) i;
|
||||
encReset();
|
||||
decReset();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user