| 1 | |
package org.webslinger.vfs; |
| 2 | |
|
| 3 | |
import java.io.InputStream; |
| 4 | |
import java.io.IOException; |
| 5 | |
import java.io.OutputStream; |
| 6 | |
|
| 7 | 0 | public abstract class RandomAccess { |
| 8 | |
protected long pointer; |
| 9 | |
|
| 10 | |
public abstract long getLength() throws IOException; |
| 11 | |
public abstract InputStream getInputStream() throws IOException; |
| 12 | |
public abstract OutputStream getOutputStream() throws IOException; |
| 13 | |
public abstract boolean seek(long pos); |
| 14 | |
public abstract int read() throws IOException; |
| 15 | |
public abstract void write(int b) throws IOException; |
| 16 | |
public abstract void close() throws IOException; |
| 17 | |
|
| 18 | |
public long getFilePointer() throws IOException { |
| 19 | 0 | return pointer; |
| 20 | |
} |
| 21 | |
|
| 22 | |
public int read(byte[] buffer, int offset, int length) throws IOException { |
| 23 | 0 | int result = read(pointer, buffer, offset, length); |
| 24 | 0 | if (result >= 0) pointer += result; |
| 25 | 0 | return result; |
| 26 | |
} |
| 27 | |
|
| 28 | |
public void write(byte[] buffer, int offset, int length) throws IOException { |
| 29 | 0 | write(pointer, buffer, offset, length); |
| 30 | 0 | pointer += length; |
| 31 | 0 | } |
| 32 | |
|
| 33 | |
public abstract int read(long ptr, byte[] buffer, int offset, int length) throws IOException; |
| 34 | |
public abstract void write(long ptr, byte[] buffer, int offset, int length) throws IOException; |
| 35 | |
} |