Package org.jmrtd.io
Class FragmentBuffer
- java.lang.Object
-
- org.jmrtd.io.FragmentBuffer
-
- All Implemented Interfaces:
Serializable
public class FragmentBuffer extends Object implements Serializable
A buffer that can be partially filled.- Version:
- $Revision: 1786 $
- Author:
- The JMRTD team ([email protected])
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
FragmentBuffer.Fragment
Fragments encapsulate pairs of offset and length.
-
Constructor Summary
Constructors Constructor Description FragmentBuffer()
Creates a fragment buffer with default size.FragmentBuffer(int length)
Creates a fragment buffer.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addFragment(int offset, byte b)
Adds a fragment containing the given byte.void
addFragment(int offset, byte[] bytes)
Adds a fragment of bytes at a specific offset to this file.void
addFragment(int offset, byte[] bytes, int srcOffset, int srcLength)
Adds a fragment of bytes at a specific offset to this file.boolean
equals(Object otherObject)
byte[]
getBuffer()
Returns the current buffer.int
getBufferedLength(int index)
Calculates the number of bytes left in the buffer starting from indexindex
.int
getBytesBuffered()
Returns the number of bytes currently buffered.Collection<FragmentBuffer.Fragment>
getFragments()
Returns the fragments of this buffer.int
getLength()
Returns the buffer (the size of the underlying byte array).int
getPosition()
Returns the position within the buffer.FragmentBuffer.Fragment
getSmallestUnbufferedFragment(int offset, int length)
Gets the smallest fragment that containsoffset
andoffset + length
that has not been buffered in this buffer.int
hashCode()
boolean
isCoveredByFragment(int offset)
Checks whether the byte at the given offset is covered by a fragment.boolean
isCoveredByFragment(int offset, int length)
Checks whether the segment specified by the given offset and length is completely covered by fragments.String
toString()
void
updateFrom(FragmentBuffer other)
Updates this buffer based on the given buffer.
-
-
-
Method Detail
-
updateFrom
public void updateFrom(FragmentBuffer other)
Updates this buffer based on the given buffer.- Parameters:
other
- some other fragment buffer
-
addFragment
public void addFragment(int offset, byte b)
Adds a fragment containing the given byte.- Parameters:
offset
- the offsetb
- the byte to insert
-
addFragment
public void addFragment(int offset, byte[] bytes)
Adds a fragment of bytes at a specific offset to this file.- Parameters:
offset
- the fragment offsetbytes
- the bytes from which fragment content will be copied
-
addFragment
public void addFragment(int offset, byte[] bytes, int srcOffset, int srcLength)
Adds a fragment of bytes at a specific offset to this file.- Parameters:
offset
- the fragment offsetbytes
- the bytes from which fragment contents will be copiedsrcOffset
- the offset within bytes where the contents of the fragment startsrcLength
- the length of the fragment
-
getPosition
public int getPosition()
Returns the position within the buffer. This is the upper limit of the farthest fragment read so far.- Returns:
- the position within the buffer
-
getBytesBuffered
public int getBytesBuffered()
Returns the number of bytes currently buffered.- Returns:
- the number of bytes currently buffered
-
isCoveredByFragment
public boolean isCoveredByFragment(int offset)
Checks whether the byte at the given offset is covered by a fragment.- Parameters:
offset
- the offset- Returns:
- a boolean indicating whether the byte at the given offset is covered
-
isCoveredByFragment
public boolean isCoveredByFragment(int offset, int length)
Checks whether the segment specified by the given offset and length is completely covered by fragments.- Parameters:
offset
- the given offsetlength
- the given length- Returns:
- a boolean indicating whether the specified segment is fully covered
-
getBufferedLength
public int getBufferedLength(int index)
Calculates the number of bytes left in the buffer starting from indexindex
.- Parameters:
index
- the index- Returns:
- the number of bytes left in the buffer
-
getFragments
public Collection<FragmentBuffer.Fragment> getFragments()
Returns the fragments of this buffer.- Returns:
- the fragments
-
getBuffer
public byte[] getBuffer()
Returns the current buffer.- Returns:
- the buffer
-
getLength
public int getLength()
Returns the buffer (the size of the underlying byte array).- Returns:
- the size of the buffer
-
getSmallestUnbufferedFragment
public FragmentBuffer.Fragment getSmallestUnbufferedFragment(int offset, int length)
Gets the smallest fragment that containsoffset
andoffset + length
that has not been buffered in this buffer.- Parameters:
offset
- the offsetlength
- the length- Returns:
- the fragment that has not yet been buffered
-
-