1 package org.xwt.mips.util;
3 import java.io.IOException;
5 public class SeekableByteArray implements SeekableData {
8 private final boolean writable;
10 public SeekableByteArray(byte[] data, boolean writable) {
13 this.writable = writable;
16 public int read(byte[] buf, int off, int len) {
17 len = Math.min(len,data.length-pos);
18 if(len <= 0) return -1;
19 System.arraycopy(data,pos,buf,off,len);
24 public int write(byte[] buf, int off, int len) throws IOException {
25 if(!writable) throw new IOException("read-only data");
26 len = Math.min(len,data.length-pos);
27 if(len <= 0) throw new IOException("no space");
28 System.arraycopy(buf,off,data,pos,len);
33 public int length() { return data.length; }
34 public int pos() { return pos; }
35 public void seek(int pos) { this.pos = pos; }
36 public void close() { }