Package net.i2p.client.streaming.impl
Class MessageInputStream
java.lang.Object
java.io.InputStream
net.i2p.client.streaming.impl.MessageInputStream
- All Implemented Interfaces:
- Closeable,- AutoCloseable
Stream that can be given messages out of order 
 yet present them in order.
I2PSession -> MessageHandler -> PacketHandler -> ConnectionPacketHandler -> MessageInputStream
This buffers unlimited data via messageReceived() - limiting / blocking is done in ConnectionPacketHandler.receivePacket().
- 
Constructor SummaryConstructorsConstructorDescriptionMessageInputStream(I2PAppContext ctx, int maxMessageSize, int maxWindowSize, int maxBufferSize) 
- 
Method SummaryModifier and TypeMethodDescriptionintbooleancanAccept(long messageId, int payloadSize) Determine if this packet will fit in our buffering limits.voidclose()voidThere is no more data coming from the I2P side.longlongWhat is the highest block ID we've completely received through?long[]getNacks()Retrieve the message IDs that are holes in our sequence - ones past the highest ready ID and below the highest received message ID.inthow long a read() call should block (if less than 0, block indefinitely, but if it is 0, do not block at all)intSame as available() but doesn't throw IOEbooleanbooleanmessageReceived(long messageId, ByteArray payload) A new message has arrived - toss it on the appropriate queue (moving previously pending messages to the ready queue if it fills the gap, etc).voidintread()On a read timeout, this throws a SocketTimeoutException as of 0.9.36.intread(byte[] target) On a read timeout, this throws a SocketTimeoutException as of 0.9.36.intread(byte[] target, int offset, int length) On a read timeout, this throws a SocketTimeoutException as of 0.9.36.voidsetReadTimeout(int timeout) how long a read() call should block (if less than 0, block indefinitely, but if it is 0, do not block at all)(package private) voidStream b0rked, die with the given errorvoidupdateAcks(PacketLocal packet) Adds the ack-through and nack fields to a packet we are building for transmissionMethods inherited from class java.io.InputStreammark, markSupported, nullInputStream, readAllBytes, readNBytes, readNBytes, reset, skip, skipNBytes, transferTo
- 
Constructor Details- 
MessageInputStreampublic MessageInputStream(I2PAppContext ctx, int maxMessageSize, int maxWindowSize, int maxBufferSize) 
 
- 
- 
Method Details- 
getHighestReadyBlockIdpublic long getHighestReadyBlockId()What is the highest block ID we've completely received through?- Returns:
- highest data block ID completely received or -1 for none
 
- 
getHighestBlockIdpublic long getHighestBlockId()- Returns:
- highest data block ID received or -1 for none
 
- 
isLocallyClosedpublic boolean isLocallyClosed()- Returns:
- true if this has been closed on the read side with close()
 
- 
canAcceptpublic boolean canAccept(long messageId, int payloadSize) Determine if this packet will fit in our buffering limits. Always returns true for zero payloadSize and dups, even if locally closed. Returns false if there is no room, OR it's not a dup and the stream has been closed on the read side with close(). If this returns false, you probably want to call isLocallyClosed() to find out why.- Returns:
- true if we have room. If false, do not call messageReceived()
- Since:
- 0.9.20 moved from ConnectionPacketHandler.receivePacket() so it can all be under one lock, and we can efficiently do several checks
 
- 
getNackspublic long[] getNacks()Retrieve the message IDs that are holes in our sequence - ones past the highest ready ID and below the highest received message ID. This may return null if there are no such IDs.- Returns:
- array of message ID holes, or null if none
 
- 
updateAcksAdds the ack-through and nack fields to a packet we are building for transmission
- 
getReadTimeoutpublic int getReadTimeout()how long a read() call should block (if less than 0, block indefinitely, but if it is 0, do not block at all)- Returns:
- how long read calls should block, 0 for nonblocking, negative to indefinitely block
 
- 
setReadTimeoutpublic void setReadTimeout(int timeout) how long a read() call should block (if less than 0, block indefinitely, but if it is 0, do not block at all)- Parameters:
- timeout- how long read calls should block, 0 for nonblocking, negative to indefinitely block
 
- 
closeReceivedpublic void closeReceived()There is no more data coming from the I2P side. Does NOT clear pending data. messageReceived() MUST have been called previously with the messageId of the CLOSE packet.
- 
notifyActivitypublic void notifyActivity()
- 
messageReceivedA new message has arrived - toss it on the appropriate queue (moving previously pending messages to the ready queue if it fills the gap, etc). This does no limiting of pending data - see canAccept() for limiting. Warning - returns true if locally closed.- Parameters:
- messageId- ID of the message
- payload- message payload, may be null or have null or zero-length data
- Returns:
- true if this is a new packet, false if it is a dup
 
- 
readOn a read timeout, this throws a SocketTimeoutException as of 0.9.36. Prior to that, returned -1.- Specified by:
- readin class- InputStream
- Throws:
- IOException
 
- 
readOn a read timeout, this throws a SocketTimeoutException as of 0.9.36. Prior to that, returned 0.- Overrides:
- readin class- InputStream
- Throws:
- IOException
 
- 
readOn a read timeout, this throws a SocketTimeoutException as of 0.9.36. Prior to that, returned 0.- Overrides:
- readin class- InputStream
- Throws:
- IOException
 
- 
available- Overrides:
- availablein class- InputStream
- Throws:
- IOException
 
- 
getTotalReadySizepublic int getTotalReadySize()Same as available() but doesn't throw IOE
- 
closepublic void close()- Specified by:
- closein interface- AutoCloseable
- Specified by:
- closein interface- Closeable
- Overrides:
- closein class- InputStream
 
- 
streamErrorOccurredStream b0rked, die with the given error
 
-