Package de.intarsys.tools.randomaccess
Class RandomAccessViewport
java.lang.Object
de.intarsys.tools.randomaccess.AbstractRandomAccess
de.intarsys.tools.randomaccess.RandomAccessFilter
de.intarsys.tools.randomaccess.RandomAccessViewport
- All Implemented Interfaces:
IRandomAccess
A viewport in an existing
IRandomAccess.-
Field Summary
Fields inherited from class de.intarsys.tools.randomaccess.RandomAccessFilter
random -
Constructor Summary
ConstructorsConstructorDescriptionRandomAccessViewport(IRandomAccess ra, long offset, long length) Create a viewport to the existingIRandomAccessra. -
Method Summary
Modifier and TypeMethodDescriptionlongReturns the length of this data container.longReturns the current offset in this data container.protected longprotected longprotected longbooleantrueif this is a read only data container.intread()Reads a byte of data from this data container.intread(byte[] buffer) Reads up tobuffer.lengthbytes of data from this data container into an array of bytes.intread(byte[] buffer, int start, int numBytes) Reads up tolenbytes of data from this data container into an array of bytes.voidseek(long offset) Sets the offset, measured from the beginning of the data container at which the next read or write occurs.voidseekBy(long delta) Sets the offset, measured from the current offset at which the next read or write occurs.voidsetLength(long newLength) Assign the length.voidwrite(byte[] buffer) Writesb.lengthbytes from the specified byte array, starting at the current offset.voidwrite(byte[] buffer, int start, int numBytes) Writeslenbytes from the specified byte array starting atstart.voidwrite(int b) Writes the specified byte .Methods inherited from class de.intarsys.tools.randomaccess.RandomAccessFilter
close, flush, getRandomMethods inherited from class de.intarsys.tools.randomaccess.AbstractRandomAccess
asInputStream, asOutputStream, getPositionStack, mark, reset
-
Constructor Details
-
RandomAccessViewport
Create a viewport to the existingIRandomAccessra.ATTENTION: This will not seek to
offsetinra. This means after creation before initial use you have to position theIRandomAccessyourself usingseek.- Parameters:
ra-offset-length-- Throws:
IOException
-
-
Method Details
-
getLength
Description copied from interface:IRandomAccessReturns the length of this data container.- Specified by:
getLengthin interfaceIRandomAccess- Overrides:
getLengthin classRandomAccessFilter- Returns:
- the length of this data container, measured in bytes.
- Throws:
IOException- if an I/O error occurs.
-
getOffset
Description copied from interface:IRandomAccessReturns the current offset in this data container.- Specified by:
getOffsetin interfaceIRandomAccess- Overrides:
getOffsetin classRandomAccessFilter- Returns:
- the offset from the beginning of the data container, in bytes, at which the next read or write occurs.
- Throws:
IOException- if an I/O error occurs.
-
getViewEnd
protected long getViewEnd() -
getViewLength
protected long getViewLength() -
getViewOffset
protected long getViewOffset() -
isReadOnly
public boolean isReadOnly()Description copied from interface:IRandomAccesstrueif this is a read only data container.- Specified by:
isReadOnlyin interfaceIRandomAccess- Overrides:
isReadOnlyin classRandomAccessFilter- Returns:
trueif this is a read only data container.
-
read
Description copied from interface:IRandomAccessReads a byte of data from this data container. The byte is returned as an integer in the range 0 to 255 (0x00-0x0ff). This method blocks if no input is yet available.This method behaves in exactly the same way as the
InputStream.read()method ofInputStream.- Specified by:
readin interfaceIRandomAccess- Overrides:
readin classRandomAccessFilter- Returns:
- the next byte of data, or
-1if the end of the data container has been reached. - Throws:
IOException- if an I/O error occurs. Not thrown if the end of the data container has been reached.
-
read
Description copied from interface:IRandomAccessReads up tobuffer.lengthbytes of data from this data container into an array of bytes. This method blocks until at least one byte of input is available.This method behaves in the exactly the same way as the
InputStream.read(byte[])method ofInputStream.- Specified by:
readin interfaceIRandomAccess- Overrides:
readin classRandomAccessFilter- Parameters:
buffer- the buffer into which the data is read.- Returns:
- the total number of bytes read into the buffer, or
-1if there is no more data because the end of this data container has been reached. - Throws:
IOException- if an I/O error occurs.
-
read
Description copied from interface:IRandomAccessReads up tolenbytes of data from this data container into an array of bytes. This method blocks until at least one byte of input is available.- Specified by:
readin interfaceIRandomAccess- Overrides:
readin classRandomAccessFilter- Parameters:
buffer- the buffer into which the data is read.start- the start offset of the data.numBytes- the maximum number of bytes read.- Returns:
- the total number of bytes read into the buffer, or
-1if there is no more data because the end of the file has been reached. - Throws:
IOException- if an I/O error occurs.
-
seek
Description copied from interface:IRandomAccessSets the offset, measured from the beginning of the data container at which the next read or write occurs. The offset may be set beyond the end of the data container. Setting the offset beyond the end of the data container does not change the data container length. The length will change only by writing after the offset has been set beyond the end of the data container.- Specified by:
seekin interfaceIRandomAccess- Overrides:
seekin classRandomAccessFilter- Parameters:
offset- the offset position, measured in bytes from the beginning of the data container- Throws:
IOException- ifoffsetis less than0or if an I/O error occurs.
-
seekBy
Description copied from interface:IRandomAccessSets the offset, measured from the current offset at which the next read or write occurs. The offset may be set beyond the end of the data container. Setting the offset beyond the end of the data container does not change the data container length. The length will change only by writing after the offset has been set beyond the end of the data container.- Specified by:
seekByin interfaceIRandomAccess- Overrides:
seekByin classRandomAccessFilter- Parameters:
delta- the amount of bytes by which to change the current offset position- Throws:
IOException- if the resultingoffsetis less than0or if an I/O error occurs.
-
setLength
Description copied from interface:IRandomAccessAssign the length. All bytes after length are truncated. If the real length is currently less than newLength, the data structure will be enlarged.- Specified by:
setLengthin interfaceIRandomAccess- Overrides:
setLengthin classRandomAccessFilter- Parameters:
newLength-- Throws:
IOException
-
write
Description copied from interface:IRandomAccessWritesb.lengthbytes from the specified byte array, starting at the current offset.- Specified by:
writein interfaceIRandomAccess- Overrides:
writein classRandomAccessFilter- Parameters:
buffer- the data.- Throws:
IOException- if an I/O error occurs.
-
write
Description copied from interface:IRandomAccessWriteslenbytes from the specified byte array starting atstart.- Specified by:
writein interfaceIRandomAccess- Overrides:
writein classRandomAccessFilter- Parameters:
buffer- the data.start- the start offset in the data.numBytes- the number of bytes to write.- Throws:
IOException- if an I/O error occurs.
-
write
Description copied from interface:IRandomAccessWrites the specified byte . The write starts at the current offset.- Specified by:
writein interfaceIRandomAccess- Overrides:
writein classRandomAccessFilter- Parameters:
b- thebyteto be written.- Throws:
IOException- if an I/O error occurs.
-