?? block.java
字號:
class Block {
public String filename; //文件名
public long blockno; // 文件塊號
public long head; // 文件頭大小
public byte[] block; // 塊內容,一共4096個字節大小
public int pos;
public Block() {
filename = null;
blockno = 0;
block = null;
head = 0;
pos = 0;
}
public Block(String fname, long bn, long hd, byte[] context) {
filename = fname;
blockno = bn;
head = hd;
block = context;
pos = 0;
}
public byte[] getByte()
{
return block;
}
public int read(){
int a = block[pos];
pos++;
a=a&0x000000FF;
return a;
}
public void read(byte[] b){
for(int i=0 ;i<b.length; i++){
b[i]= block[pos];
pos++;
}
}
public void read(byte[] b,int len){
for(int i=0 ;i<b.length; i++){
b[i]= block[pos+i];
}
pos = pos+len;
}
public void readFully(byte[] b){
for(int i=0 ;i<b.length; i++){
b[i]= block[pos];
pos++;
}
}
public int readInt(){
int a = 0;
for(int i = 0; i < 4; i ++) {
int tmpVal = (block[pos+i] << (8 * (3-i)));
switch (i) {
case 0:
tmpVal = tmpVal & 0xFF000000;
break;
case 1:
tmpVal = tmpVal & 0x00FF0000;
break;
case 2:
tmpVal = tmpVal & 0x0000FF00;
break;
case 3:
tmpVal = tmpVal & 0x000000FF;
break;
}
a = a | tmpVal;
}
pos = pos +4 ;
return a;
}
public float readFloat(){
int a = 0;
for(int i = 0; i < 4; i ++) {
int tmpVal = (block[pos+i] << (8 * (3-i)));
switch (i) {
case 0:
tmpVal = tmpVal & 0xFF000000;
break;
case 1:
tmpVal = tmpVal & 0x00FF0000;
break;
case 2:
tmpVal = tmpVal & 0x0000FF00;
break;
case 3:
tmpVal = tmpVal & 0x000000FF;
break;
}
a = a | tmpVal;
}
pos = pos +4 ;
return Float.intBitsToFloat(a);
}
public long readLong(){
long a = 0;
for(int i=0 ; i<8 ;i++,pos++){
a = a<<8;
a = a | (block[pos]&0xFF);
}
return a;
}
public boolean readBoolean(){
if(block[pos]==0){
pos++;
return false;
}
else{
pos++;
return true;
}
}
public void write(int a){
block[pos] = (byte)a;
pos++;
}
public void writeByte(byte a){
block[pos] = a;
pos++;
}
public void writeInt(int a){
block[pos]=(byte)((a&0xFF000000) >>> 24);
block[pos+1]=(byte)((a&0x00FF0000) >>> 16);
block[pos+2]=(byte)((a&0x0000FF00) >>> 8);
block[pos+3]=(byte)(a&0x000000FF);
pos = pos +4 ;
}
public void writeFloat(float a){
int temp = Float.floatToRawIntBits(a);
for(int i= 0; i<4;i++){
block[pos+3-i] = (byte)(temp&0xff);
temp = temp>>>8;
}
pos = pos +4;
}
public void writeBoolean(boolean a){
if(a)
block[pos]=1;
else
block[pos]=0;
pos++;
}
public void writeLong(long a){
for(int i = 0; i< 8 ;i++){
block[pos+7-i]=(byte)(a&0xff);
a = a>>>8;
}
pos = pos + 8;
}
public void writeBytes(byte[] a){
for(int i = 0; i<a.length ; i++){
block[pos+i] = a[i];
}
pos = pos + a.length;
}
public void writeChars(String a){
byte[] b = a.getBytes();
for(int i = 0; i<b.length ; i++){
block[pos+2*i]=0;
block[pos+2*i+1]=b[i];
}
pos = pos + b.length*2;
}
public void writeChars(String a, int len){
byte[] b = a.getBytes();
for(int i = 0; i<b.length ; i++){
block[pos+2*i]=0;
block[pos+2*i+1]=b[i];
}
for(int i=b.length*2; i<len ; i++)
block[pos+i]=0;
pos = pos + len;
}
public void seek(int p){
pos = p;
}
public void writeZero(int len){
for(int i=0;i<len;i++)
block[pos++]=0;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -