Package jadex.bridge.component.streams
Class InputConnection
- java.lang.Object
- 
- jadex.bridge.component.streams.AbstractConnection
- 
- jadex.bridge.component.streams.InputConnection
 
 
- 
- All Implemented Interfaces:
- IConnection,- IInputConnection
 
 public class InputConnection extends AbstractConnection implements IInputConnection Input connection implementation for byte streams. Must synchronized its internal data because the connection handler and the connection user (i.e. a component) are using the connection concurrently. - the handler uses addData to forward received data to the connection. - the connection user calls interface methods to read data.
- 
- 
Field SummaryFields Modifier and Type Field Description protected java.util.List<byte[]>dataThe data.protected SubscriptionIntermediateFuture<byte[]>ifutureThe read futures.protected intoffsetThe offset (startvalue of current first row).protected Future<java.lang.Byte>ofutureprotected intpositionThe position.protected intsizeThe size.- 
Fields inherited from class jadex.bridge.component.streams.AbstractConnectionch, closed, closing, id, ini, inited, initiator, input, participant
 
- 
 - 
Constructor SummaryConstructors Constructor Description InputConnection(IComponentIdentifier sender, IComponentIdentifier receiver, int id, boolean initiator, IAbstractConnectionHandler ch)Create a new input connection.
 - 
Method SummaryAll Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddData(byte[] data)Add data to the internal data buffer.ISubscriptionIntermediateFuture<byte[]>aread()Asynchronous read.IFuture<java.lang.Byte>areadNext()Asynchronous read.intavailable()Get the number of available bytes.protected voiddataRead()byte[]getNextByteArray()Get the next data byte array.intgetStoredDataSize()Get the size of the stored data.protected intinternalRead()Non-blocking read.intread()Non-blocking read.intread(byte[] buffer)Non-blocking read.voidsetClosed()Set the stream to be closed.ISubscriptionIntermediateFuture<java.lang.Long>writeToOutputStream(java.io.OutputStream os, IExternalAccess component)Read all data from output stream to the connection.- 
Methods inherited from class jadex.bridge.component.streams.AbstractConnectionclose, getConnectionHandler, getConnectionId, getInitiator, getNonFunctionalProperties, getParticipant, isClosed, isClosing, isInited, isInitiatorSide, isInputConnection, setClosing, setInited
 - 
Methods inherited from class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 - 
Methods inherited from interface jadex.bridge.IConnectionclose, getConnectionId, getInitiator, getNonFunctionalProperties, getParticipant
 
- 
 
- 
- 
- 
Field Detail- 
dataprotected java.util.List<byte[]> data The data.
 - 
offsetprotected int offset The offset (startvalue of current first row).
 - 
positionprotected int position The position.
 - 
sizeprotected int size The size.
 - 
ifutureprotected SubscriptionIntermediateFuture<byte[]> ifuture The read futures.
 - 
ofutureprotected Future<java.lang.Byte> ofuture 
 
- 
 - 
Constructor Detail- 
InputConnectionpublic InputConnection(IComponentIdentifier sender, IComponentIdentifier receiver, int id, boolean initiator, IAbstractConnectionHandler ch) Create a new input connection.
 
- 
 - 
Method Detail- 
readpublic int read() Non-blocking read. Tries to read the next byte.- Specified by:
- readin interface- IInputConnection
- Returns:
- The next byte or -1 if the end of the stream has been reached.
 
 - 
readpublic int read(byte[] buffer) Non-blocking read. Tries to fill the buffer from the stream.- Specified by:
- readin interface- IInputConnection
- Parameters:
- buffer- The buffer to read in.
- Returns:
- The number of bytes that could be read into the buffer.
 
 - 
internalReadprotected int internalRead() Non-blocking read. Tries to read the next byte.- Returns:
- The next byte or -1 if none is currently available.
- Throws:
- exception- if end of stream has been reached.
 
 - 
getNextByteArraypublic byte[] getNextByteArray() Get the next data byte array.
 - 
areadpublic ISubscriptionIntermediateFuture<byte[]> aread() Asynchronous read.- Specified by:
- areadin interface- IInputConnection
- Returns:
- Bytes one by one till end of stream or closed.
 
 - 
areadNextpublic IFuture<java.lang.Byte> areadNext() Asynchronous read.- Returns:
- Bytes one by one till end of stream or closed.
 
 - 
availablepublic int available() Get the number of available bytes.- Specified by:
- availablein interface- IInputConnection
- Returns:
- The number of available bytes.
 
 - 
addDatapublic void addData(byte[] data) Add data to the internal data buffer.- Parameters:
- data- The data to add. If stream is closed adding data is not allowed.
 
 - 
setClosedpublic void setClosed() Set the stream to be closed.- Overrides:
- setClosedin class- AbstractConnection
 
 - 
getStoredDataSizepublic int getStoredDataSize() Get the size of the stored data.
 - 
dataReadprotected void dataRead() 
 - 
writeToOutputStreampublic ISubscriptionIntermediateFuture<java.lang.Long> writeToOutputStream(java.io.OutputStream os, IExternalAccess component) Read all data from output stream to the connection. The result is an intermediate future that reports back the size that was read. It can also be used to terminate reading.- Specified by:
- writeToOutputStreamin interface- IInputConnection
- Parameters:
- is- The input stream.
- component- The component.
 
 
- 
 
-