Class DataItemImpl

  • All Implemented Interfaces:
    DataItem, Item, java.io.Closeable, java.io.Externalizable, java.io.Serializable, java.lang.AutoCloseable, java.nio.channels.ByteChannel, java.nio.channels.Channel, java.nio.channels.ReadableByteChannel, java.nio.channels.SeekableByteChannel, java.nio.channels.WritableByteChannel

    public class DataItemImpl
    extends ItemImpl
    implements DataItem
    Created by kurila on 09.05.14. A data item which may produce uniformly distributed non-compressible content. Uses UniformDataSource as a ring buffer. Not thread safe. Note: the ReadableByteChannel.read(ByteBuffer) method implementation will not return 0 or -1 (endless)
    See Also:
    Serialized Form
    • Field Detail

      • layerNum

        protected int layerNum
      • offset

        protected long offset
      • position

        protected long position
      • size

        protected long size
      • modifiedRangesMask

        protected final java.util.BitSet modifiedRangesMask
    • Constructor Detail

      • DataItemImpl

        public DataItemImpl()
      • DataItemImpl

        public DataItemImpl​(java.lang.String value)
                     throws java.lang.IllegalArgumentException
        Throws:
        java.lang.IllegalArgumentException
      • DataItemImpl

        public DataItemImpl​(long offset,
                            long size)
      • DataItemImpl

        public DataItemImpl​(java.lang.String name,
                            long offset,
                            long size)
      • DataItemImpl

        public DataItemImpl​(long offset,
                            long size,
                            int layerNum)
      • DataItemImpl

        public DataItemImpl​(java.lang.String name,
                            long offset,
                            long size,
                            int layerNum)
      • DataItemImpl

        public DataItemImpl​(DataItemImpl baseDataItem,
                            long internalOffset,
                            long size,
                            boolean nextLayer)
    • Method Detail

      • toString

        public java.lang.String toString()
        Overrides:
        toString in class ItemImpl
      • toString

        public java.lang.String toString​(java.lang.String itemPath)
        Specified by:
        toString in interface Item
        Overrides:
        toString in class ItemImpl
      • layer

        public final int layer()
        Specified by:
        layer in interface DataItem
      • layer

        public final void layer​(int layerNum)
        Specified by:
        layer in interface DataItem
      • size

        public final void size​(long size)
        Specified by:
        size in interface DataItem
      • offset

        public final long offset()
        Specified by:
        offset in interface DataItem
      • offset

        public final void offset​(long offset)
        Specified by:
        offset in interface DataItem
      • position

        public long position()
        Specified by:
        position in interface DataItem
        Specified by:
        position in interface java.nio.channels.SeekableByteChannel
      • position

        public final DataItemImpl position​(long position)
        Specified by:
        position in interface DataItem
        Specified by:
        position in interface java.nio.channels.SeekableByteChannel
      • size

        public long size()
        Specified by:
        size in interface java.nio.channels.SeekableByteChannel
      • truncate

        public DataItemImpl truncate​(long size)
        Specified by:
        truncate in interface java.nio.channels.SeekableByteChannel
      • rangeSize

        public final long rangeSize​(int i)
        Specified by:
        rangeSize in interface DataItem
      • isUpdated

        public final boolean isUpdated()
        Specified by:
        isUpdated in interface DataItem
      • commitUpdatedRanges

        public final void commitUpdatedRanges​(java.util.BitSet[] updatingRangesMaskPair)
        Specified by:
        commitUpdatedRanges in interface DataItem
      • isRangeUpdated

        public final boolean isRangeUpdated​(int rangeIdx)
        Specified by:
        isRangeUpdated in interface DataItem
      • close

        public final void close()
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.nio.channels.Channel
        Specified by:
        close in interface java.io.Closeable
      • isOpen

        public final boolean isOpen()
        Specified by:
        isOpen in interface java.nio.channels.Channel
      • read

        public final int read​(java.nio.ByteBuffer dst)
        Specified by:
        read in interface java.nio.channels.ReadableByteChannel
        Specified by:
        read in interface java.nio.channels.SeekableByteChannel
      • writeToSocketChannel

        public final long writeToSocketChannel​(java.nio.channels.WritableByteChannel chanDst,
                                               long maxCount)
                                        throws java.io.IOException
        Specified by:
        writeToSocketChannel in interface DataItem
        Returns:
        The number of bytes written, possibly zero
        Throws:
        java.nio.channels.ClosedChannelException - If this channel is closed
        java.nio.channels.AsynchronousCloseException - If another thread closes this channel while the write operation is in progress
        java.nio.channels.ClosedByInterruptException - If another thread interrupts the current thread while the write operation is in progress, thereby closing the channel and setting the current thread's interrupt status
        java.io.IOException - If some other I/O error occurs
      • writeToFileChannel

        public final long writeToFileChannel​(java.nio.channels.FileChannel chanDst,
                                             long maxCount)
                                      throws java.io.IOException
        Specified by:
        writeToFileChannel in interface DataItem
        Throws:
        java.io.IOException
      • writeToAsyncChannel

        public final <A> void writeToAsyncChannel​(AsyncChannel dstChan,
                                                  long dstPos,
                                                  long maxCount,
                                                  A attach,
                                                  java.nio.channels.CompletionHandler<java.lang.Integer,​? super A> handler)
        Description copied from interface: DataItem
        Warning: the data item's position should be updated by the handler
        Specified by:
        writeToAsyncChannel in interface DataItem
        handler - note that the handler should invoke {@link DataItem#position(long))} to set the new position for this
      • equals

        public boolean equals​(java.lang.Object o)
        Overrides:
        equals in class ItemImpl
      • writeExternal

        public void writeExternal​(java.io.ObjectOutput out)
                           throws java.io.IOException
        Specified by:
        writeExternal in interface java.io.Externalizable
        Overrides:
        writeExternal in class ItemImpl
        Throws:
        java.io.IOException
      • readExternal

        public void readExternal​(java.io.ObjectInput in)
                          throws java.io.IOException,
                                 java.lang.ClassNotFoundException
        Specified by:
        readExternal in interface java.io.Externalizable
        Overrides:
        readExternal in class ItemImpl
        Throws:
        java.io.IOException
        java.lang.ClassNotFoundException