public class DataBinStream
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
private int |
chunkIndex
Is the index of byte in the chunk pointed by
chunkPos . |
private int |
chunkPos
Is the index of the chunk.
|
private java.util.ArrayList<byte[]> |
chunks
One-dimensional array with the data of the data-bin.
|
private long |
dataBinPos
Is the position in the whole data bin.
|
private long |
length
Is the length of all chunks (data bin saved).
|
Constructor and Description |
---|
DataBinStream()
Constructor.
|
DataBinStream(int numChunks)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
addData(byte[] data)
Adds a new byte array to the stream.
|
void |
addData(byte[] data,
long offset)
Adds a new byte array to the stream beginning at the offset position.
|
void |
addStream(byte[] data,
long offset)
Adds a new byte array to the stream beginning at the offset position.
|
private byte[] |
ArrayListToArray(byte[] dst) |
long |
available()
Definition in
getNumBytesLeft() . |
long |
getLength()
Returns the length of the stored data.
|
long |
getNumBytesLeft()
The number of bytes that can be read from the actual position to the end.
|
long |
getPos()
Returns the position of the next byte to be read in the data stream.
|
void |
list(java.io.PrintStream out)
Prints this DataBin out to the specified output stream.
|
byte |
readByte()
Reads a byte from the data stream.
|
void |
readFully(byte[] b)
Reads an array of bytes.
|
void |
readFully(byte[] b,
int off,
int len)
Reads
len bytes form the data stream saving the in the
b array at position off . |
void |
reset()
Sets internal attributes to their initial values.
|
void |
seek(long offset)
Sets the position of the pointer in the next byte to be read.
|
int |
skipBytes(int n)
Skips
n bytes in the data stream. |
java.lang.String |
toString() |
void |
trimToSize()
Trims the capacity of list of objects used to be the list's current size,
in order to minimize the storage.
|
private java.util.ArrayList<byte[]> chunks
private long length
private int chunkPos
private int chunkIndex
chunkPos
.private long dataBinPos
Its value is deduced from chunkIndex
and chunkPos
as:
pos = offset(chunkIndex) + chunPos, where offset() is the offset of the
chunk in the databin.
Although it can be computed it is considered to reduce the cost of computing it value.
public DataBinStream()
public DataBinStream(int numChunks)
It allows that an initial capacity, number of chunks, being set in order to improve the performance.
numChunks
- initial capacity.public void addData(byte[] data)
data
- byte array to be added.public void addData(byte[] data, long offset)
Data to be added must be placed just after the previous data or overlapped, but not gaps/holes between the previous and new data are allowed.
data
- byte array to be added.offset
- position in which to add the data.public void addStream(byte[] data, long offset)
Data to be added must be placed just after the previous data or overlapped, but not gaps/holes between the previous and new data are allowed.
data
- byte array to be added.offset
- position in which to add the data.public void reset()
public void seek(long offset)
offset
- position of next byte to be read.public long getLength()
public int skipBytes(int n)
n
bytes in the data stream.n
- number of bytes to skippublic long getPos()
public long getNumBytesLeft()
public long available()
getNumBytesLeft()
.public byte readByte() throws java.io.EOFException
java.io.EOFException
public void readFully(byte[] b)
b
- array of bytes to be read.public void readFully(byte[] b, int off, int len) throws java.io.EOFException
len
bytes form the data stream saving the in the
b
array at position off
.b
- off
- len
- java.io.EOFException
public void trimToSize()
public java.lang.String toString()
toString
in class java.lang.Object
public void list(java.io.PrintStream out)
out
- an output stream.private byte[] ArrayListToArray(byte[] dst)
CADI - Copyright (C) 2007
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
Group on Interactive Coding of Images (GICI) (contact)