Buffer documentation
This commit is contained in:
1 parent
def89acd40
commit
1a86f73807
28 files changed
+1243
-1209
No files matched your search
@@ -1,336 +0,0 @@
|
||||
import java.math.BigInteger;
|
||||
|
||||
public class Buffer extends DoublyLinkedListNode {
|
||||
|
||||
public static final LinkedList pool0 = new LinkedList();
|
||||
public static final LinkedList pool1 = new LinkedList();
|
||||
public static final LinkedList pool2 = new LinkedList();
|
||||
private static final int[] BITMASK = {0, 1, 3, 7, 15, 31, 63, 127, 255, 511, 1023, 2047, 4095, 8191, 16383, 32767, 65535, 0x1ffff, 0x3ffff, 0x7ffff, 0xfffff, 0x1fffff, 0x3fffff, 0x7fffff, 0xffffff, 0x1ffffff, 0x3ffffff, 0x7ffffff, 0xfffffff, 0x1fffffff, 0x3fffffff, 0x7fffffff, -1};
|
||||
public static int poolSize0;
|
||||
public static int poolSize1;
|
||||
public static int poolSize2;
|
||||
|
||||
public static Buffer create(int sizeType) {
|
||||
synchronized (pool1) {
|
||||
Buffer buffer = null;
|
||||
|
||||
if ((sizeType == 0) && (poolSize0 > 0)) {
|
||||
poolSize0--;
|
||||
buffer = (Buffer) pool0.method251();
|
||||
} else if ((sizeType == 1) && (poolSize1 > 0)) {
|
||||
poolSize1--;
|
||||
buffer = (Buffer) pool1.method251();
|
||||
} else if ((sizeType == 2) && (poolSize2 > 0)) {
|
||||
poolSize2--;
|
||||
buffer = (Buffer) pool2.method251();
|
||||
}
|
||||
|
||||
if (buffer != null) {
|
||||
buffer.position = 0;
|
||||
return buffer;
|
||||
}
|
||||
}
|
||||
|
||||
Buffer buffer = new Buffer();
|
||||
buffer.position = 0;
|
||||
|
||||
if (sizeType == 0) {
|
||||
buffer.data = new byte[100];
|
||||
} else if (sizeType == 1) {
|
||||
buffer.data = new byte[5000];
|
||||
} else {
|
||||
buffer.data = new byte[30000];
|
||||
}
|
||||
|
||||
return buffer;
|
||||
}
|
||||
|
||||
public byte[] data;
|
||||
public int position;
|
||||
public int bitPosition;
|
||||
public ISAACCipher cipher;
|
||||
|
||||
public Buffer() {
|
||||
}
|
||||
|
||||
public Buffer(byte[] src) {
|
||||
data = src;
|
||||
position = 0;
|
||||
}
|
||||
|
||||
public void putOp(int i) {
|
||||
data[position++] = (byte) (i + cipher.method246());
|
||||
}
|
||||
|
||||
public void putSize1(int i) {
|
||||
data[position - i - 1] = (byte) i;
|
||||
}
|
||||
|
||||
public void put1(int i) {
|
||||
data[position++] = (byte) i;
|
||||
}
|
||||
|
||||
public void put1C(int i) {
|
||||
data[position++] = (byte) (-i);
|
||||
}
|
||||
|
||||
public void put1S(int j) {
|
||||
data[position++] = (byte) (128 - j);
|
||||
}
|
||||
|
||||
public void put2(int i) {
|
||||
data[position++] = (byte) (i >> 8);
|
||||
data[position++] = (byte) i;
|
||||
}
|
||||
|
||||
public void put2A(int j) {
|
||||
data[position++] = (byte) (j >> 8);
|
||||
data[position++] = (byte) (j + 128);
|
||||
}
|
||||
|
||||
public void put2LE(int i) {
|
||||
data[position++] = (byte) i;
|
||||
data[position++] = (byte) (i >> 8);
|
||||
}
|
||||
|
||||
public void put2LEA(int j) {
|
||||
data[position++] = (byte) (j + 128);
|
||||
data[position++] = (byte) (j >> 8);
|
||||
}
|
||||
|
||||
public void put3(int i) {
|
||||
data[position++] = (byte) (i >> 16);
|
||||
data[position++] = (byte) (i >> 8);
|
||||
data[position++] = (byte) i;
|
||||
}
|
||||
|
||||
public void put4(int i) {
|
||||
data[position++] = (byte) (i >> 24);
|
||||
data[position++] = (byte) (i >> 16);
|
||||
data[position++] = (byte) (i >> 8);
|
||||
data[position++] = (byte) i;
|
||||
}
|
||||
|
||||
public void put4LE(int j) {
|
||||
data[position++] = (byte) j;
|
||||
data[position++] = (byte) (j >> 8);
|
||||
data[position++] = (byte) (j >> 16);
|
||||
data[position++] = (byte) (j >> 24);
|
||||
}
|
||||
|
||||
public void put8(long l) {
|
||||
data[position++] = (byte) (int) (l >> 56);
|
||||
data[position++] = (byte) (int) (l >> 48);
|
||||
data[position++] = (byte) (int) (l >> 40);
|
||||
data[position++] = (byte) (int) (l >> 32);
|
||||
data[position++] = (byte) (int) (l >> 24);
|
||||
data[position++] = (byte) (int) (l >> 16);
|
||||
data[position++] = (byte) (int) (l >> 8);
|
||||
data[position++] = (byte) (int) l;
|
||||
}
|
||||
|
||||
public void put(String s) {
|
||||
put(s.getBytes());
|
||||
put1('\n');
|
||||
}
|
||||
|
||||
public void put(byte[] src, int len, int off) {
|
||||
System.arraycopy(src, off, data, position, len);
|
||||
position += len;
|
||||
}
|
||||
|
||||
public void put(byte[] src) {
|
||||
put(src, 0, src.length);
|
||||
}
|
||||
|
||||
public void putA(byte[] src, int off, int len) {
|
||||
for (int i = (off + len) - 1; i >= off; i--) {
|
||||
data[position++] = (byte) (src[i] + 128);
|
||||
}
|
||||
}
|
||||
|
||||
public byte get1() {
|
||||
return data[position++];
|
||||
}
|
||||
|
||||
public byte get1C() {
|
||||
return (byte) (-data[position++]);
|
||||
}
|
||||
|
||||
public byte get1S() {
|
||||
return (byte) (128 - data[position++]);
|
||||
}
|
||||
|
||||
public int get1U() {
|
||||
return data[position++] & 0xff;
|
||||
}
|
||||
|
||||
public int get1UA() {
|
||||
return (data[position++] - 128) & 0xff;
|
||||
}
|
||||
|
||||
public int getU1C() {
|
||||
return -data[position++] & 0xff;
|
||||
}
|
||||
|
||||
public int get1US() {
|
||||
return (128 - data[position++]) & 0xff;
|
||||
}
|
||||
|
||||
public int getSmart() {
|
||||
int i = data[position] & 0xff;
|
||||
if (i < 0x80) {
|
||||
return get1U() - 0x40;
|
||||
} else {
|
||||
return get2U() - 0xc000;
|
||||
}
|
||||
}
|
||||
|
||||
public int getUSmart() {
|
||||
int i = data[position] & 0xff;
|
||||
if (i < 0x80) {
|
||||
return get1U();
|
||||
} else {
|
||||
return get2U() - 0x7fff;
|
||||
}
|
||||
}
|
||||
|
||||
public int get2U() {
|
||||
position += 2;
|
||||
return ((data[position - 2] & 0xff) << 8) + (data[position - 1] & 0xff);
|
||||
}
|
||||
|
||||
public int get2UA() {
|
||||
position += 2;
|
||||
return ((data[position - 2] & 0xff) << 8) + ((data[position - 1] - 128) & 0xff);
|
||||
}
|
||||
|
||||
public int get2ULE() {
|
||||
position += 2;
|
||||
return ((data[position - 1] & 0xff) << 8) + (data[position - 2] & 0xff);
|
||||
}
|
||||
|
||||
public int get2ULEA() {
|
||||
position += 2;
|
||||
return ((data[position - 1] & 0xff) << 8) + ((data[position - 2] - 128) & 0xff);
|
||||
}
|
||||
|
||||
public int get2() {
|
||||
position += 2;
|
||||
int i = ((data[position - 2] & 0xff) << 8) + (data[position - 1] & 0xff);
|
||||
if (i > 0x7fff) {
|
||||
i -= 0x10000;
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
public int get2LE() {
|
||||
position += 2;
|
||||
int j = ((data[position - 1] & 0xff) << 8) + (data[position - 2] & 0xff);
|
||||
if (j > 0x7fff) {
|
||||
j -= 0x10000;
|
||||
}
|
||||
return j;
|
||||
}
|
||||
|
||||
public int get2LEA() {
|
||||
position += 2;
|
||||
int j = ((data[position - 1] & 0xff) << 8) + ((data[position - 2] - 128) & 0xff);
|
||||
if (j > 0x7fff) {
|
||||
j -= 0x10000;
|
||||
}
|
||||
return j;
|
||||
}
|
||||
|
||||
public int get3() {
|
||||
position += 3;
|
||||
return ((data[position - 3] & 0xff) << 16) + ((data[position - 2] & 0xff) << 8) + (data[position - 1] & 0xff);
|
||||
}
|
||||
|
||||
public int get4() {
|
||||
position += 4;
|
||||
return ((data[position - 4] & 0xff) << 24) + ((data[position - 3] & 0xff) << 16) + ((data[position - 2] & 0xff) << 8) + (data[position - 1] & 0xff);
|
||||
}
|
||||
|
||||
public int get4ME() {
|
||||
position += 4;
|
||||
return ((data[position - 3] & 0xff) << 24) + ((data[position - 4] & 0xff) << 16) + ((data[position - 1] & 0xff) << 8) + (data[position - 2] & 0xff);
|
||||
}
|
||||
|
||||
public int get4RME() {
|
||||
position += 4;
|
||||
return ((data[position - 2] & 0xff) << 24) + ((data[position - 1] & 0xff) << 16) + ((data[position - 4] & 0xff) << 8) + (data[position - 3] & 0xff);
|
||||
}
|
||||
|
||||
public long get8() {
|
||||
long l = (long) get4() & 0xffffffffL;
|
||||
long l1 = (long) get4() & 0xffffffffL;
|
||||
return (l << 32) + l1;
|
||||
}
|
||||
|
||||
public String getString() {
|
||||
int start = position;
|
||||
while (data[position++] != '\n') {
|
||||
}
|
||||
return new String(data, start, position - start - 1);
|
||||
}
|
||||
|
||||
public byte[] getStringRaw() {
|
||||
int start = position;
|
||||
while (data[position++] != '\n') {
|
||||
}
|
||||
byte[] raw = new byte[position - start - 1];
|
||||
for (int j = start; j < (position - 1); j++) {
|
||||
raw[j - start] = data[j];
|
||||
}
|
||||
return raw;
|
||||
}
|
||||
|
||||
public void get(byte[] dst, int off, int len) {
|
||||
System.arraycopy(data, position, dst, off, len);
|
||||
position += len;
|
||||
}
|
||||
|
||||
public void getReversed(byte[] dst, int off, int len) {
|
||||
for (int i = (off + len) - 1; i >= off; i--) {
|
||||
dst[i] = data[position++];
|
||||
}
|
||||
}
|
||||
|
||||
public void accessBits() {
|
||||
bitPosition = position * 8;
|
||||
}
|
||||
|
||||
public int getBits(int n) {
|
||||
int bytePos = bitPosition >> 3;
|
||||
int remaining = 8 - (bitPosition & 7);
|
||||
int value = 0;
|
||||
bitPosition += n;
|
||||
for (; n > remaining; remaining = 8) {
|
||||
value += (data[bytePos++] & BITMASK[remaining]) << (n - remaining);
|
||||
n -= remaining;
|
||||
}
|
||||
if (n == remaining) {
|
||||
value += data[bytePos] & BITMASK[remaining];
|
||||
} else {
|
||||
value += (data[bytePos] >> (remaining - n)) & BITMASK[n];
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
public void accessBytes() {
|
||||
position = (bitPosition + 7) / 8;
|
||||
}
|
||||
|
||||
public void encrypt(BigInteger exponent, BigInteger modulus) {
|
||||
int length = position;
|
||||
position = 0;
|
||||
byte[] raw = new byte[length];
|
||||
get(raw, 0, length);
|
||||
byte[] encrypted = new BigInteger(raw).modPow(exponent, modulus).toByteArray();
|
||||
position = 0;
|
||||
put1(encrypted.length);
|
||||
put(encrypted, encrypted.length, 0);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user