phelps.io

Class ByteArrayRAF

public class ByteArrayRAF extends Object implements RandomAccess

A RandomAccess interface to a byte[], in the same way java.io.ByteArrayInputStream provides an InputStream interface. Useful to make java.io.File-like objects from in-memory data, as within an applet or Java Web Start sandbox.

Does not subclass java.io.RandomAccessFile because we want to use this class in restricted situations where reading of local files is not permitted, and java.io.RandomAccessFile always checks the readability of its file.

Version: $Revision$ $Date$

See Also: BufferedRandomAccessFile

Constructor Summary
ByteArrayRAF(byte[] buf, String mode)
ByteArrayRAF(InputStream in, String mode)
Sets contents from (remainder of) in and closes in.
Method Summary
voidclose()
longgetFilePointer()
longlength()
intread(byte[] b)
intread(byte[] b, int off, int len)
intread()
voidreadFully(byte[] b)
voidreadFully(byte[] b, int off, int len)
voidseek(long pos)
voidsetLength(long newLength)
intskipBytes(int n)
byte[]toByteArray()
voidwrite(byte[] b)
voidwrite(byte[] b, int off, int len)
voidwrite(int b)
voidwriteChar(char ch)
voidwriteString16(String s)
voidwriteString8(String s)

Constructor Detail

ByteArrayRAF

public ByteArrayRAF(byte[] buf, String mode)

Parameters: mode can be any mode accepted by java.io.RandomAccessFile: "r", "rw", "rws", "rwd".

ByteArrayRAF

public ByteArrayRAF(InputStream in, String mode)
Sets contents from (remainder of) in and closes in.

Method Detail

close

public void close()

getFilePointer

public long getFilePointer()

length

public long length()

read

public int read(byte[] b)

read

public int read(byte[] b, int off, int len)

read

public int read()

readFully

public void readFully(byte[] b)

readFully

public void readFully(byte[] b, int off, int len)

seek

public void seek(long pos)

setLength

public void setLength(long newLength)

skipBytes

public int skipBytes(int n)

toByteArray

public byte[] toByteArray()

write

public void write(byte[] b)

write

public void write(byte[] b, int off, int len)

write

public void write(int b)

writeChar

public void writeChar(char ch)

writeString16

public void writeString16(String s)

writeString8

public void writeString8(String s)