|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--com.adobe.acrobat.bytearray.ByteArray
An abstract class that encapsulates an ordered, arbitrarily sized array of bytes.
A ByteArray's contents are accessed via InputStreams, which are created in the createStream
method, which takes a ContiguousByteRange
describing a set of bytes and returns an InputStream returning the bytes at the positions
defined by the ContiguousByteRange object in order.
Implementers of subclasses of ByteArray must be able to guarantee that the contents of the ByteArray are invariant--i.e., if the nth byte of a given ByteArray is x today, it had better be x tomorrow. If during normal execution a ByteArray "discovers" that it is unable to satisfy this invariant (say, a file's contents on disk change spontaneously), it must turn "invalid."
A more precise, but less readable, way of expressing the invariant described above follows:
Given the following definition:
For any two invokations of fetchBytes(br1) and fetchBytes(br2), where i1 is the InputStream returned by the first invokation and i2 is the InputStream returned by the second invokation, for any integer value n where n is contained in br1 and br2, b(i1, o(br1, n)) == b(i2, o(br2, n)).
A ByteArray is "invalid" if it is unable to reliably satisfy this constraint.
Constructor Summary | |
protected |
ByteArray(ByteArraySource source) Create a new ByteArray From Source. |
Method Summary | |
protected int |
computeLength() Called by getLength, and only once in the lifetime of the ByteArray. |
protected void |
confirmValid() Implementors of ByteArray subclasses might want to override this to provide on-the-fly checking for validity even if no byte-range requests are taking place. |
protected abstract
java.io.InputStream |
createStream(ContiguousByteRange br) Create an InputStream based on the bytes delimited by the given ContiguousByteRange. |
int |
findBytes(byte[] bytes,
int start, int numToScan, boolean forward, int pageSize) Locate the given sequence of bytes in this ByteArray with the given search criteria. |
int |
findString(java.lang.String s,
int start, int numToScan, boolean forward, int pageSize) Search for the given String in the ByteArray subject to the given search criteria. |
ByteArraySource |
getByteArraySource()
Get the associated ByteArraySource. |
void |
getBytes(ContiguousByteRange br, byte[] b) Fill the array of bytes with the bytes from the given ContiguousByteRange. |
void |
getBytes(ContiguousByteRange br, byte[] b,
int offset) Fill the array of bytes starting at the element at the given offset with the bytes delimited by the given ContiguousByteRange. |
void |
getBytes(int pos,
byte[] b) Fill the array of bytes b
with bytes from this ByteArray starting at the given position to the end of b . |
void |
getBytes(int pos,
int len, byte[] b, int offset) Fill the array of bytes b ,
starting at offset , with the len bytes in this ByteArray
starting at pos . |
java.io.InputStream |
getByteStream(ContiguousByteRange br) Get an InputStream that returns the bytes delimited by the given ContiguousByteRange in order by index. |
java.io.InputStream |
getByteStream(int offset)
Get an InputStream that returns the bytes beginning at the given offset to the end of the ByteArray. |
java.io.InputStream |
getByteStream(int offset,
int len) Get an InputStream that returns the bytes beginning at the given offset to the end of the ByteArray or after len bytes, whichever comes first. |
int |
getLength() |
protected boolean |
isValid() Returns true if the ByteArray is valid. |
protected void |
setInvalid(java.io.IOException exception)
Marks the ByteArray as invalid. |
protected void |
throwIfInvalid() If the ByteArray is invalid, throw the exception that caused it to be invalid. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait,
wait, wait |
Constructor Detail |
protected ByteArray(ByteArraySource source)
Method Detail |
public ByteArraySource getByteArraySource()
public java.io.InputStream getByteStream(ContiguousByteRange br) throws java.io.IOException
br
- the ContiguousByteRange
describing which subset of the ByteArray's bytes were requestedpublic java.io.InputStream getByteStream(int offset) throws java.io.IOException
offset
- the offset at which to start reading bytesgetByteStream(ContiguousByteRange)
public java.io.InputStream getByteStream(int offset, int len) throws java.io.IOException
offset
- the offset at which to start reading byteslen
- the maximum number of bytes to read before the stream terminatesgetByteStream(ContiguousByteRange)
public void getBytes(ContiguousByteRange br, byte[] b, int offset) throws java.io.IOException
Implmenters of subclasses of ByteArray may wish to override this method for performance reasons. They must respect the above invariants.
br
- the subrange of this ByteArray which is to be read into bb
- the array of bytes into which this ByteArray's contents are to be readoffset
- the start offset in b at which bytes are to be writtenpublic void getBytes(ContiguousByteRange br, byte[] b) throws java.io.IOException
b[0]
and ends at b[br.length() - 1]
.br
- the subrange of bytes requestedb
- the buffer into which to write the bytes.getBytes(ContiguousByteRange,
byte[], int)
public void getBytes(int pos, int len, byte[] b, int offset) throws java.io.IOException
b
, starting at offset
, with the len
bytes in this ByteArray starting at pos
.pos
- the starting position in this ByteArray from which to copy byteslen
- the number of bytes to copyb
- the buffer into which to copy the bytesoffset
- the offset into b
at which to start copyinggetBytes(ContiguousByteRange,
byte[], int)
public void getBytes(int pos, byte[] b) throws java.io.IOException
b
with bytes from this ByteArray starting at the
given position to the end of b
. If this ByteArray ends before the end of b is
reached, subsequent vaules in b
go unchanged.pos
- the position in this ByteArray from which to start copying bytesb
- the array of bytes into which bytes should be copiedgetBytes(ContiguousByteRange,
byte[], int)
public int getLength() throws java.io.IOException
public int findBytes(byte[] bytes, int start, int numToScan, boolean forward, int pageSize) throws java.io.IOException
bytes
- Array of bytes to search for.start
- Offset where to start looking. If search is backwards, search will
not return an index >= start.numToScan
- Number of bytes to scan before giving up, -1 indicates search
to the end. The sequence must be located completely within numToScan bytes for a
successful result.forward
- true if search should move forward from start; false if backwardpageSize
- number of bytes to request at a time from the ByteArray (-1 for
default). This search will never request a chunk of bytes larger than this.public int findString(java.lang.String s, int start, int numToScan, boolean forward, int pageSize) throws java.io.IOException
Util.rawBytesFromString
,
and then passed on to findBytes.s
- the String to search for.start
- Offset where to start looking. If search is backwards, search will
not return an index >= start.numToScan
- Number of bytes to scan before giving up, -1 indicates search
to the end. The sequence must be located completely within numToScan bytes for a
successful result.forward
- true if search should move forward from start; false if backwardpageSize
- number of bytes to request at a time from the ByteArray (-1 for
default). This search will never request a chunk of bytes larger than this.protected abstract java.io.InputStream createStream(ContiguousByteRange br) throws java.io.IOException
br
- the ContiguousByteRange delimiting the requested bytesbr
ByteRangeInputStream
protected void setInvalid(java.io.IOException exception)
exception
- The exception to throw on this and future uses of the
ByteArray.protected int computeLength() throws java.io.IOException
protected void throwIfInvalid() throws java.io.IOException
protected boolean isValid()
protected void confirmValid() throws java.io.IOException
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |