|
Block |
|
/*
* To Do:
*
*/
/**
*
* Block - Tim Tyler 2001.
*
* This code has been placed in the public domain.
* You can do what you like with it.
* Note that this code comes with no warranty.
*
*/
public class Block {
public byte data[];
public int block_size; // in bytes - e.g. 16
Block(int size) {
block_size = size;
data = new byte[block_size];
}
Block(TerminatedFile tf, int off, int size) {
block_size = size;
data = new byte[block_size];
if ((off >= 0) && ((off + block_size) <= tf.length)) {
System.arraycopy(tf.data, off, data, 0, block_size);
}
else
{
fillWith(TerminatedFile.DUD);
}
}
void fillWith(byte fill) {
for (int i = 0; i < block_size; i++) {
data[i] = fill;
}
}
boolean isPadding(byte p) {
for (int i = 0; i < block_size; i++) {
if (data[i] != p) {
return false;
}
}
return true;
}
boolean isMark(byte m, byte p) {
// Log.log("->" + data);
if (data[0] != m) {
return false;
}
for (int i = 1; i < block_size; i++) {
if (data[i] != p) {
return false;
}
}
return true;
}
// assume the same size...
byte[] addByteArray(byte[] ba) {
byte[] out = new byte[block_size];
int carry = 0;
int b1;
int b2;
int result;
for (int i = 1; i < block_size; i++) {
b1 = ba[i] & 0xff;
b2 = data[i] & 0xff;
result = b1 + b2 + carry;
out[i] = (byte)result;
carry = result >>> 8;
}
// any carry at the end is ignored...
return out;
}
void setGranularity(int n) {
block_size = n;
}
public static void main(String args[]) {
BIAESFrEnd.main(args);
}
}
|
Block |
|