Package com.mckoi.util
Class LengthMarkedBufferedInputStream
- java.lang.Object
-
- java.io.InputStream
-
- java.io.FilterInputStream
-
- com.mckoi.util.LengthMarkedBufferedInputStream
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable
public final class LengthMarkedBufferedInputStream extends java.io.FilterInputStreamReads 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 Constructor Description LengthMarkedBufferedInputStream(java.io.InputStream in)The Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intavailable()voidblockForCommand()Blocks until a complete command has been read in.booleanmarkSupported()booleanpollForCommand(int max_size)Checks to see if there is a complete command waiting on the input stream.intread()intread(byte[] b, int off, int len)
-
-
-
Method Detail
-
read
public int read() throws java.io.IOException- Overrides:
readin classjava.io.FilterInputStream- Throws:
java.io.IOException
-
read
public int read(byte[] b, int off, int len) throws java.io.IOException- Overrides:
readin classjava.io.FilterInputStream- Throws:
java.io.IOException
-
available
public int available() throws java.io.IOException- Overrides:
availablein classjava.io.FilterInputStream- Throws:
java.io.IOException
-
markSupported
public boolean markSupported()
- Overrides:
markSupportedin classjava.io.FilterInputStream
-
pollForCommand
public boolean pollForCommand(int max_size) throws java.io.IOExceptionChecks 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:
java.io.IOException
-
blockForCommand
public void blockForCommand() throws java.io.IOExceptionBlocks until a complete command has been read in.- Throws:
java.io.IOException
-
-