Package tv.hd3g.transfertfiles
Class BufferVault
- java.lang.Object
-
- tv.hd3g.transfertfiles.BufferVault
-
public class BufferVault extends Object
Thread safe
-
-
Constructor Summary
Constructors Constructor Description BufferVault()BufferVault(int baseInternalArraySize)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description OutputStreamasOutputStream()voidclear()voidcompactAndAppend(int pos, BufferVault inserted)Remove all internal datas betwen 0 and pos, add append (copy/write) newDataSource content.BufferVaultcopy()BufferVaultensureBufferSize(int itemsCountToAdd)booleanequals(Object obj)intgetSize()inthashCode()Iterator<byte[]>iterator(int bufferSize)Internal buffer will be reused for each nextintread(byte[] b, int pos, int off, int len)intread(int pos)BufferVaultread(OutputStream outStream)Don't close/flush after write.byte[]readAll()ByteBufferreadAllToByteBuffer()Stream<byte[]>stream(int bufferSize)Internal buffer will be reused for each itemstatic BufferVaultwrap(byte[] byteArrayToHeapByteBuffer)Short end for ByteBuffer.wrap and BufferVault.wrap(ByteBuffer)BufferVaultwrite(byte[] buffer)BufferVaultwrite(byte[] buffer, int pos, int len)intwrite(InputStream inStream, int bufferSize)Don't close/flush after read, call available before start read to pre-heat internal bufferBufferVaultwrite(ByteBuffer buffer)
-
-
-
Method Detail
-
copy
public BufferVault copy()
-
wrap
public static BufferVault wrap(byte[] byteArrayToHeapByteBuffer)
Short end for ByteBuffer.wrap and BufferVault.wrap(ByteBuffer)- Parameters:
byteArrayToHeaByteBuffer-- Returns:
-
ensureBufferSize
public BufferVault ensureBufferSize(int itemsCountToAdd)
-
clear
public void clear()
-
write
public BufferVault write(ByteBuffer buffer)
- Returns:
- this
-
write
public BufferVault write(byte[] buffer, int pos, int len)
- Returns:
- this
-
write
public BufferVault write(byte[] buffer)
- Returns:
- this
-
getSize
public int getSize()
-
readAll
public byte[] readAll()
- Returns:
- empty if not datas to read.
-
read
public int read(byte[] b, int pos, int off, int len)- Parameters:
b- the array to feed with dataspos- where start to read data in internal arrayoff- where to put data in blen- max data len to put in b- Returns:
- real data len readed from internal array, -1 no datas/pos to big
-
read
public int read(int pos)
-
readAllToByteBuffer
public ByteBuffer readAllToByteBuffer()
- Returns:
- empty if not datas to read.
-
iterator
public Iterator<byte[]> iterator(int bufferSize)
Internal buffer will be reused for each next
-
stream
public Stream<byte[]> stream(int bufferSize)
Internal buffer will be reused for each item
-
asOutputStream
public OutputStream asOutputStream()
-
read
public BufferVault read(OutputStream outStream) throws IOException
Don't close/flush after write. Inject direcly the internal byte array. If outStream change it, it will change internally.- Returns:
- this
- Throws:
IOException
-
write
public int write(InputStream inStream, int bufferSize) throws IOException
Don't close/flush after read, call available before start read to pre-heat internal buffer- Parameters:
inStream-- Returns:
- total transferred bytes
- Throws:
IOException
-
compactAndAppend
public void compactAndAppend(int pos, BufferVault inserted)Remove all internal datas betwen 0 and pos, add append (copy/write) newDataSource content.
-
-