Package dap4.dap4lib

Class ChunkInputStream

  • All Implemented Interfaces:
    Closeable, AutoCloseable

    public class ChunkInputStream
    extends InputStream
    This class wraps a chunked source of databuffer as an InputStream. It is mostly pass-thru in the sense that reads on this class are turned into a series of reads of the underlying stream.
    • Field Detail

      • state

        protected dap4.dap4lib.ChunkInputStream.State state
      • remoteorder

        protected ByteOrder remoteorder
      • nochecksum

        protected boolean nochecksum
      • flags

        protected int flags
      • chunksize

        protected int chunksize
      • avail

        protected int avail
    • Method Detail

      • getHostByteOrder

        public ByteOrder getHostByteOrder()
      • getRemoteByteOrder

        public ByteOrder getRemoteByteOrder()
      • getNoChecksum

        public boolean getNoChecksum()
      • readDMR

        public String readDMR()
                       throws dap4.core.util.DapException
        Read the DMR, trimmed.
        Returns:
        the DMR as a Java String
        Throws:
        dap4.core.util.DapException
      • throwError

        public void throwError​(String document)
                        throws ErrorException
        Convert an error chunk to an exception
        Parameters:
        document - XML representation of the error
        Throws:
        dap4.core.util.DapException - containing the contents of the error chunk
        ErrorException
      • read

        public int read()
                 throws IOException
        Reads the next byte of databuffer from the input stream. The value byte is returned as an int in the range 0 to 255. If no byte is available because the end of the stream has been reached, the value -1 is returned. This method blocks until input databuffer is available, the end of the stream is detected, or an exception is thrown.

        Operates by loading chunk by chunk. If an error chunk is detected, then return ErrorException (which is a subclass of IOException).

        Specified by:
        read in class InputStream
        Returns:
        the next byte of databuffer, or -1 if the end of the stream is reached.
        Throws:
        IOException - if an I/O error occurs.
      • read

        public int read​(byte[] buf,
                        int off,
                        int len)
                 throws IOException
        Reads up to len databuffer of databuffer from the input stream into an array of databuffer. An attempt is made to read as many as len databuffer, but a smaller number may be read. The number of databuffer actually read is returned as an integer.
        Overrides:
        read in class InputStream
        Parameters:
        buf - the byte array into which databuffer is read
        off - the offset in the byte array at which to write
        len - the amount to read
        Returns:
        the actual number of databuffer read
        Throws:
        IOException
      • available

        public int available()
        Returns an estimate of the number of databuffer that can be read (or skipped over) from this input stream without blocking by the next invocation of a method for this input stream.

        Repurposed here to do equivalent of peek().

        Overrides:
        available in class InputStream
        Returns:
        0 if at eof, some number > 0 otherwise.
      • close

        public void close()
                   throws IOException
        Closes this output stream and releases any system resources associated with this stream. The underlying servlet stream is not closed; that is left to the level above.
        Specified by:
        close in interface AutoCloseable
        Specified by:
        close in interface Closeable
        Overrides:
        close in class InputStream
        Throws:
        IOException