Class BufferVault

java.lang.Object
tv.hd3g.transfertfiles.BufferVault

public class BufferVault extends Object
Thread safe
  • Constructor Details

    • BufferVault

      public BufferVault()
    • BufferVault

      public BufferVault(int baseInternalArraySize)
  • Method Details

    • 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 datas
      pos - where start to read data in internal array
      off - where to put data in b
      len - 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
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • compactAndAppend

      public void compactAndAppend(int pos, BufferVault inserted)
      Remove all internal datas betwen 0 and pos, add append (copy/write) newDataSource content.