package textconvert;
import java.io.UnsupportedEncodingException;
public class ConstByteArray {
private byte[] buffer;
private int size;
private int offset;
public ConstByteArray(){
this(1024);
}
public ConstByteArray(int size){
this.buffer = new byte[size];
this.size = size; //the same with buffer.length
this.offset = 0;
}
public ConstByteArray(byte[] buf, int offset, int len){
this.buffer = buf;
this.offset = offset;
this.size = len;
}
public final void resetSize(int offset, int size){
this.offset = offset;
this.size = size;
}
public final byte byteAt(int i){
return buffer[offset + i];
}
public int length(){
return size;
}
public String toString(String enc) throws UnsupportedEncodingException{
return new String(buffer, offset, size, enc);
}
public byte[] getByte(int offset, int len){
byte[] buf = new byte[len];
System.arraycopy(buffer, this.offset + offset, buf, 0, len);
return buf;
}
}
ConstByteArray.java
最新推荐文章于 2016-01-19 17:13:00 发布