Package ej.rcommand.impl
Class DynamicRemoteConnection
- java.lang.Object
-
- ej.rcommand.impl.DynamicRemoteConnection
-
- All Implemented Interfaces:
CommandReader,CommandSender,RemoteConnection
public class DynamicRemoteConnection extends Object implements RemoteConnection
Implements anRemoteConnectionthat wraps anotherRemoteConnectionthat can change dynamically.
-
-
Constructor Summary
Constructors Constructor Description DynamicRemoteConnection()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Closes the connection.voidflushCommand()Ends the command frame.InputStreamgetInputStream()Get the InputStream used by the instance.OutputStreamgetOutputStream()Get the OuputStream used by the instance.booleanreadBoolean()Reads a boolean parameter.byte[]readByteArray()Reads a byte array parameter.InputStreamreadByteArrayAsInputStream()Reads a byte array using an input stream.StringreadCommand()Reads a command.doublereadDouble()Reads a double parameter.floatreadFloat()Reads a float parameter.InputStreamreadInputStream()Reads an input stream.intreadInt()Reads an integer parameter.longreadLong()Reads a long parameter.ObjectreadObject()Reads a parameter, whatever it's type.List<Object>readParameters()Reads the parameters of a command.StringreadString()Reads a string parameter.voidsendBoolean(boolean b)Sends a boolean parameter.voidsendByteArray(byte[] a)Sends a byte array parameter.voidsendByteArray(byte[] buffer, int offset, int length)Sends a byte array parameter with offset and length.voidsendByteArrayAsInputStream(InputStream is)Sends a byte array parameter using an input stream.voidsendDouble(double d)Sends a double parameter.voidsendFloat(float f)Sends a float parameter.voidsendInputStream(InputStream is)Sends an input stream.voidsendInt(int i)Sends an integer parameter.voidsendLong(long l)Sends a long parameter.voidsendParams(List<Object> params)Sends the given parameters.voidsendString(String s)Sends a string parameter.voidsetConnection(RemoteConnection newConnection)Set the underlying connection.voidskipParameters()Skips the parameters of a command and get ready to read the following command.voidstartCommand(String command)Starts a command.
-
-
-
Method Detail
-
setConnection
public void setConnection(@Nullable RemoteConnection newConnection)
Set the underlying connection. If defined, previous connection is closed.
Given newConnection can be null.
-
readCommand
public String readCommand() throws IOException
Description copied from interface:CommandReaderReads a command.- Specified by:
readCommandin interfaceCommandReader- Returns:
- the command name.
- Throws:
IOException- the stream has been closed and the contained input stream does not support reading after close, or another I/O error occurs.
-
readString
public String readString() throws IOException
Description copied from interface:CommandReaderReads a string parameter.- Specified by:
readStringin interfaceCommandReader- Returns:
- the read string.
- Throws:
IOException- the stream has been closed and the contained input stream does not support reading after close, or another I/O error occurs.
-
readLong
public long readLong() throws IOExceptionDescription copied from interface:CommandReaderReads a long parameter.- Specified by:
readLongin interfaceCommandReader- Returns:
- the read long.
- Throws:
IOException- the stream has been closed and the contained input stream does not support reading after close, or another I/O error occurs.
-
readByteArray
public byte[] readByteArray() throws IOExceptionDescription copied from interface:CommandReaderReads a byte array parameter.- Specified by:
readByteArrayin interfaceCommandReader- Returns:
- the read byte array.
- Throws:
IOException- the stream has been closed and the contained input stream does not support reading after close, or another I/O error occurs.
-
readByteArrayAsInputStream
public InputStream readByteArrayAsInputStream() throws IOException
Description copied from interface:CommandReaderReads a byte array using an input stream.The returned input stream must be fully read before returning the method.
- Specified by:
readByteArrayAsInputStreamin interfaceCommandReader- Returns:
- an inputStream that reads the underlying byte array.
- Throws:
IOException- the stream has been closed and the contained input stream does not support reading after close, or another I/O error occurs.
-
readObject
public Object readObject() throws IOException
Description copied from interface:CommandReaderReads a parameter, whatever it's type. Note that if the parameter is a byte array, it will be returned as an InputStream that must be completely consumed before reading the next parameter.- Specified by:
readObjectin interfaceCommandReader- Returns:
- an object reflecting the read parameter.
- Throws:
IOException- the stream has been closed and the contained input stream does not support reading after close, or another I/O error occurs.
-
startCommand
public void startCommand(String command)
Description copied from interface:CommandSenderStarts a command.A command can be followed by arguments.
- Specified by:
startCommandin interfaceCommandSender- Parameters:
command- the command name.
-
sendString
public void sendString(String s)
Description copied from interface:CommandSenderSends a string parameter.- Specified by:
sendStringin interfaceCommandSender- Parameters:
s- the string to send.
-
sendLong
public void sendLong(long l)
Description copied from interface:CommandSenderSends a long parameter.- Specified by:
sendLongin interfaceCommandSender- Parameters:
l- the long to send.
-
sendByteArray
public void sendByteArray(byte[] a)
Description copied from interface:CommandSenderSends a byte array parameter.- Specified by:
sendByteArrayin interfaceCommandSender- Parameters:
a- the byte array to send.
-
sendByteArray
public void sendByteArray(byte[] buffer, int offset, int length)Description copied from interface:CommandSenderSends a byte array parameter with offset and length.- Specified by:
sendByteArrayin interfaceCommandSender- Parameters:
buffer- the byte array to send.offset- offset in the byte array.length- data length to send.
-
sendByteArrayAsInputStream
public void sendByteArrayAsInputStream(InputStream is)
Description copied from interface:CommandSenderSends a byte array parameter using an input stream.The given input stream is fully read.
- Specified by:
sendByteArrayAsInputStreamin interfaceCommandSender- Parameters:
is- the input stream to send.
-
flushCommand
public void flushCommand()
Description copied from interface:CommandSenderEnds the command frame.- Specified by:
flushCommandin interfaceCommandSender
-
close
public void close()
Description copied from interface:RemoteConnectionCloses the connection.- Specified by:
closein interfaceRemoteConnection
-
skipParameters
public void skipParameters() throws IOExceptionDescription copied from interface:CommandReaderSkips the parameters of a command and get ready to read the following command.- Specified by:
skipParametersin interfaceCommandReader- Throws:
IOException
-
readParameters
public List<Object> readParameters() throws IOException
Description copied from interface:RemoteConnectionReads the parameters of a command.Method
CommandReader.skipParameters()must be called after to be ready to read the following command.- Specified by:
readParametersin interfaceRemoteConnection- Returns:
- list of the parameters.
- Throws:
IOException
-
sendParams
public void sendParams(List<Object> params)
Description copied from interface:RemoteConnectionSends the given parameters.- Specified by:
sendParamsin interfaceRemoteConnection- Parameters:
params- the list of parameters to send.
-
sendInt
public void sendInt(int i)
Description copied from interface:CommandSenderSends an integer parameter.- Specified by:
sendIntin interfaceCommandSender- Parameters:
i- the integer to send.
-
sendFloat
public void sendFloat(float f)
Description copied from interface:CommandSenderSends a float parameter.- Specified by:
sendFloatin interfaceCommandSender- Parameters:
f- the float to send.
-
sendDouble
public void sendDouble(double d)
Description copied from interface:CommandSenderSends a double parameter.- Specified by:
sendDoublein interfaceCommandSender- Parameters:
d- the double to send.
-
sendBoolean
public void sendBoolean(boolean b)
Description copied from interface:CommandSenderSends a boolean parameter.- Specified by:
sendBooleanin interfaceCommandSender- Parameters:
b- the boolean to send.
-
readInt
public int readInt() throws IOExceptionDescription copied from interface:CommandReaderReads an integer parameter.- Specified by:
readIntin interfaceCommandReader- Returns:
- the read integer.
- Throws:
IOException- the stream has been closed and the contained input stream does not support reading after close, or another I/O error occurs.
-
readFloat
public float readFloat() throws IOExceptionDescription copied from interface:CommandReaderReads a float parameter.- Specified by:
readFloatin interfaceCommandReader- Returns:
- the read float.
- Throws:
IOException- the stream has been closed and the contained input stream does not support reading after close, or another I/O error occurs.
-
readDouble
public double readDouble() throws IOExceptionDescription copied from interface:CommandReaderReads a double parameter.- Specified by:
readDoublein interfaceCommandReader- Returns:
- the read double.
- Throws:
IOException- the stream has been closed and the contained input stream does not support reading after close, or another I/O error occurs.
-
readBoolean
public boolean readBoolean() throws IOExceptionDescription copied from interface:CommandReaderReads a boolean parameter.- Specified by:
readBooleanin interfaceCommandReader- Returns:
- the read boolean.
- Throws:
IOException- the stream has been closed and the contained input stream does not support reading after close, or another I/O error occurs.
-
sendInputStream
public void sendInputStream(InputStream is)
Description copied from interface:CommandSenderSends an input stream.- Specified by:
sendInputStreamin interfaceCommandSender- Parameters:
is- the input stream to send.
-
readInputStream
public InputStream readInputStream() throws IOException
Description copied from interface:CommandReaderReads an input stream.The returned input stream must be fully read before returning the method.
- Specified by:
readInputStreamin interfaceCommandReader- Returns:
- an inputStream.
- Throws:
IOException- the stream has been closed and the contained input stream does not support reading after close, or another I/O error occurs.
-
getOutputStream
@Nullable public OutputStream getOutputStream()
Description copied from interface:CommandSenderGet the OuputStream used by the instance.- Specified by:
getOutputStreamin interfaceCommandSender- Returns:
- the OuputStream used by the instance, or
nullif this command sender is not ready to send a command.
-
getInputStream
@Nullable public InputStream getInputStream()
Description copied from interface:CommandSenderGet the InputStream used by the instance.- Specified by:
getInputStreamin interfaceCommandSender- Returns:
- the InputStream used by the instance, or
nullif this command sender is not ready to send a command.
-
-