Package dap4.dap4lib
Class ChunkInputStream
- java.lang.Object
-
- java.io.InputStream
-
- dap4.dap4lib.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 Summary
Fields Modifier and Type Field Description protected intavailprotected intchunksizeprotected intflagsprotected InputStreaminputprotected ByteOrderlocalorderprotected booleannochecksumprotected ByteOrderremoteorderprotected RequestModerequestmodeprotected dap4.dap4lib.ChunkInputStream.Statestate
-
Constructor Summary
Constructors Constructor Description ChunkInputStream(InputStream input, RequestMode requestmode)ChunkInputStream(InputStream input, RequestMode requestmode, ByteOrder order)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intavailable()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.voidclose()Closes this output stream and releases any system resources associated with this stream.ByteOrdergetHostByteOrder()booleangetNoChecksum()ByteOrdergetRemoteByteOrder()intread()Reads the next byte of databuffer from the input stream.intread(byte[] buf, int off, int len)Reads up to len databuffer of databuffer from the input stream into an array of databuffer.StringreadDMR()Read the DMR, trimmed.StringreadError()Read an error chunkvoidthrowError(String document)Convert an error chunk to an exception-
Methods inherited from class java.io.InputStream
mark, markSupported, nullInputStream, read, readAllBytes, readNBytes, readNBytes, reset, skip, transferTo
-
-
-
-
Field Detail
-
input
protected InputStream input
-
state
protected dap4.dap4lib.ChunkInputStream.State state
-
requestmode
protected RequestMode requestmode
-
localorder
protected ByteOrder localorder
-
remoteorder
protected ByteOrder remoteorder
-
nochecksum
protected boolean nochecksum
-
flags
protected int flags
-
chunksize
protected int chunksize
-
avail
protected int avail
-
-
Constructor Detail
-
ChunkInputStream
public ChunkInputStream(InputStream input, RequestMode requestmode)
-
ChunkInputStream
public ChunkInputStream(InputStream input, RequestMode requestmode, ByteOrder order)
-
-
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 chunkErrorException
-
readError
public String readError() throws IOException
Read an error chunk- Returns:
- the error document as a string
- Throws:
IOException
-
read
public int read() throws IOExceptionReads the next byte of databuffer from the input stream. The value byte is returned as anintin the range0to255. If no byte is available because the end of the stream has been reached, the value-1is 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:
readin classInputStream- Returns:
- the next byte of databuffer, or
-1if 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 IOExceptionReads 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:
readin classInputStream- Parameters:
buf- the byte array into which databuffer is readoff- the offset in the byte array at which to writelen- 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:
availablein classInputStream- Returns:
- 0 if at eof, some number > 0 otherwise.
-
close
public void close() throws IOExceptionCloses 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:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classInputStream- Throws:
IOException
-
-