Package com.mckoi.util
Class LengthMarkedBufferedInputStream
java.lang.Object
java.io.InputStream
java.io.FilterInputStream
com.mckoi.util.LengthMarkedBufferedInputStream
- All Implemented Interfaces:
Closeable
,AutoCloseable
Reads a command block on the underlying stream that is constrained by
a length marker preceeding the command. This can be used as a hack
work around for non-blocking IO because we know ahead of time how much data
makes up the next block of information over the stream.
- Author:
- Tobias Downer
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionint
void
Blocks until a complete command has been read in.boolean
boolean
pollForCommand
(int max_size) Checks to see if there is a complete command waiting on the input stream.int
read()
int
read
(byte[] b, int off, int len) Methods inherited from class java.io.InputStream
nullInputStream, readAllBytes, readNBytes, readNBytes, skipNBytes, transferTo
-
Constructor Details
-
LengthMarkedBufferedInputStream
The Constructor.
-
-
Method Details
-
read
- Overrides:
read
in classFilterInputStream
- Throws:
IOException
-
read
- Overrides:
read
in classFilterInputStream
- Throws:
IOException
-
available
- Overrides:
available
in classFilterInputStream
- Throws:
IOException
-
markSupported
public boolean markSupported()- Overrides:
markSupported
in classFilterInputStream
-
pollForCommand
Checks to see if there is a complete command waiting on the input stream. Returns true if there is. If this method returns true then it is safe to go ahead and process a single command from this stream. This will return true only once while there is a command pending until that command is completely read in.'max_size' is the maximum number of bytes we are allowing before an IOException is thrown.
- Throws:
IOException
-
blockForCommand
Blocks until a complete command has been read in.- Throws:
IOException
-