public class FragmentBuffer extends Object implements Serializable
Modifier and Type | Class and Description |
---|---|
static class |
FragmentBuffer.Fragment
Fragments encapsulate pairs of offset and length.
|
Constructor and Description |
---|
FragmentBuffer()
Creates a fragment buffer with default size.
|
FragmentBuffer(int length)
Creates a fragment buffer.
|
Modifier and Type | Method and 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 index
index . |
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)
Returns the smallest fragment which, when added, makes the fragment buffer contains
offset to offset + 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.
|
public FragmentBuffer()
public FragmentBuffer(int length)
length
- the length of the bufferpublic void updateFrom(FragmentBuffer other)
other
- some other fragment bufferpublic void addFragment(int offset, byte b)
offset
- the offsetb
- the byte to insertpublic void addFragment(int offset, byte[] bytes)
offset
- the fragment offsetbytes
- the bytes from which fragment content will be copiedpublic void addFragment(int offset, byte[] bytes, int srcOffset, int srcLength)
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 fragmentpublic int getPosition()
public int getBytesBuffered()
public boolean isCoveredByFragment(int offset)
offset
- the offsetpublic boolean isCoveredByFragment(int offset, int length)
offset
- the given offsetlength
- the given lengthpublic int getBufferedLength(int index)
index
.index
- the indexpublic Collection<FragmentBuffer.Fragment> getFragments()
public byte[] getBuffer()
public int getLength()
public FragmentBuffer.Fragment getSmallestUnbufferedFragment(int offset, int length)
offset
to offset + length
that has not been buffered in this buffer.offset
- the offset into the filelength
- the lengthCopyright © 2022. All rights reserved.