Class MemoryAsset

  • All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable, java.nio.channels.ByteChannel, java.nio.channels.Channel, java.nio.channels.ReadableByteChannel, java.nio.channels.SeekableByteChannel, java.nio.channels.WritableByteChannel, Asset
    Direct Known Subclasses:
    MemoryNamedAsset

    public class MemoryAsset
    extends java.lang.Object
    implements Asset, java.nio.channels.SeekableByteChannel
    An Asset implementation backed by an internal memory representation; able to be directly added to an Archive, and supports all operations designated by the NIO.2 SeekableByteChannel API. Thread-safe.
    • Constructor Summary

      Constructors 
      Constructor Description
      MemoryAsset()
      Creates a new instance with internal memory buffer initially sized at 0 and at position 0, capable of holding a maximum of Integer.MAX_VALUE bytes.
      MemoryAsset​(SeekableInMemoryByteChannel delegate)
      Creates a new instance with internal memory buffer delegate using the specified (required) SeekableInMemoryByteChannel
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void close()  
      boolean isOpen()  
      java.io.InputStream openStream()
      Get a input stream for the resource content.
      long position()  
      java.nio.channels.SeekableByteChannel position​(long newPosition)
      int read​(java.nio.ByteBuffer dst)  
      long size()
      java.nio.channels.SeekableByteChannel truncate​(long size)
      int write​(java.nio.ByteBuffer src)  
      • Methods inherited from class java.lang.Object

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

      • MemoryAsset

        public MemoryAsset()
        Creates a new instance with internal memory buffer initially sized at 0 and at position 0, capable of holding a maximum of Integer.MAX_VALUE bytes.
      • MemoryAsset

        MemoryAsset​(SeekableInMemoryByteChannel delegate)
             throws java.lang.IllegalArgumentException
        Creates a new instance with internal memory buffer delegate using the specified (required) SeekableInMemoryByteChannel
        Parameters:
        delegate -
        Throws:
        java.lang.IllegalArgumentException
    • Method Detail

      • isOpen

        public boolean isOpen()
        Specified by:
        isOpen in interface java.nio.channels.Channel
        Returns:
        See Also:
        Channel.isOpen()
      • close

        public void close()
                   throws java.io.IOException
        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
        Throws:
        java.io.IOException
        See Also:
        Channel.close()
      • read

        public int read​(java.nio.ByteBuffer dst)
                 throws java.io.IOException
        Specified by:
        read in interface java.nio.channels.ReadableByteChannel
        Specified by:
        read in interface java.nio.channels.SeekableByteChannel
        Parameters:
        dst -
        Returns:
        Throws:
        java.io.IOException
        See Also:
        SeekableByteChannel.read(java.nio.ByteBuffer)
      • write

        public int write​(java.nio.ByteBuffer src)
                  throws java.io.IOException
        Specified by:
        write in interface java.nio.channels.SeekableByteChannel
        Specified by:
        write in interface java.nio.channels.WritableByteChannel
        Parameters:
        src -
        Returns:
        Throws:
        java.io.IOException
        See Also:
        SeekableByteChannel.write(java.nio.ByteBuffer)
      • position

        public long position()
                      throws java.io.IOException
        Specified by:
        position in interface java.nio.channels.SeekableByteChannel
        Returns:
        Throws:
        java.io.IOException
        See Also:
        SeekableByteChannel.position()
      • position

        public java.nio.channels.SeekableByteChannel position​(long newPosition)
                                                       throws java.io.IOException
        Specified by:
        position in interface java.nio.channels.SeekableByteChannel
        Parameters:
        newPosition -
        Returns:
        Throws:
        java.io.IOException
        See Also:
        SeekableByteChannel.position(long)
      • size

        public long size()
                  throws java.io.IOException
        Specified by:
        size in interface java.nio.channels.SeekableByteChannel
        Returns:
        Throws:
        java.io.IOException
        See Also:
        SeekableByteChannel.size()
      • truncate

        public java.nio.channels.SeekableByteChannel truncate​(long size)
                                                       throws java.io.IOException
        Specified by:
        truncate in interface java.nio.channels.SeekableByteChannel
        Parameters:
        size -
        Returns:
        Throws:
        java.io.IOException
        See Also:
        SeekableByteChannel.truncate(long)
      • openStream

        public java.io.InputStream openStream()
        Get a input stream for the resource content. The caller is responsible for closing the stream.
        Specified by:
        openStream in interface Asset
        Returns:
        A new open InputStream for each call
        See Also:
        Asset.openStream()