Package com.db4o.io

Class MemoryBin

  • All Implemented Interfaces:
    Bin

    public class MemoryBin
    extends java.lang.Object
    implements Bin
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      long bufferSize()  
      void close()
      closes the Bin.
      byte[] data()
      Returns a copy of the raw data contained in this bin for external processing.
      long length()
      returns the length of the Bin (on disc, in memory).
      int read​(long pos, byte[] bytes, int length)
      reads a given number of bytes into an array of bytes at an offset position.
      void sync()
      flushes the buffer content to the physical storage media.
      void sync​(java.lang.Runnable runnable)
      runs the Runnable between two calls to sync();
      int syncRead​(long position, byte[] bytes, int bytesToRead)
      reads a given number of bytes into an array of bytes at an offset position.
      void write​(long pos, byte[] buffer, int length)
      for internal processing only.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • MemoryBin

        public MemoryBin​(int initialSize,
                         GrowthStrategy growthStrategy)
      • MemoryBin

        public MemoryBin​(byte[] bytes,
                         GrowthStrategy growthStrategy)
    • Method Detail

      • length

        public long length()
        Description copied from interface: Bin
        returns the length of the Bin (on disc, in memory).
        Specified by:
        length in interface Bin
      • bufferSize

        public long bufferSize()
      • read

        public int read​(long pos,
                        byte[] bytes,
                        int length)
                 throws Db4oIOException
        Description copied from interface: Bin
        reads a given number of bytes into an array of bytes at an offset position.
        Specified by:
        read in interface Bin
        Parameters:
        pos - the offset position to read at
        bytes - the byte array to read bytes into
        length - the number of bytes to be read
        Returns:
        The number of bytes actually read (<= bytesToRead) or -1 if position already points to/exceeds the end of the bin
        Throws:
        Db4oIOException
      • sync

        public void sync()
                  throws Db4oIOException
        Description copied from interface: Bin
        flushes the buffer content to the physical storage media.
        Specified by:
        sync in interface Bin
        Throws:
        Db4oIOException
      • syncRead

        public int syncRead​(long position,
                            byte[] bytes,
                            int bytesToRead)
        Description copied from interface: Bin
        reads a given number of bytes into an array of bytes at an offset position. In contrast to the normal Bin.read(long, byte[], int) method, the Bin should ensure direct access to the raw storage medium. No caching should take place.
        Specified by:
        syncRead in interface Bin
        Parameters:
        position - the offset position to read at
        bytes - the byte array to read bytes into
        bytesToRead - the number of bytes to be read
        Returns:
      • close

        public void close()
        Description copied from interface: Bin
        closes the Bin.
        Specified by:
        close in interface Bin
      • data

        public byte[] data()
        Returns a copy of the raw data contained in this bin for external processing. Access to the data is not guarded by synchronisation. If this method is called while the MemoryBin is in use, it is possible that the returned byte array is not consistent.
      • write

        public void write​(long pos,
                          byte[] buffer,
                          int length)
                   throws Db4oIOException
        for internal processing only.
        Specified by:
        write in interface Bin
        Parameters:
        pos - the offset position to write at
        buffer - the array of bytes to write
        length - the number of bytes to write
        Throws:
        Db4oIOException
      • sync

        public void sync​(java.lang.Runnable runnable)
        Description copied from interface: Bin
        runs the Runnable between two calls to sync();
        Specified by:
        sync in interface Bin