public abstract class ConnectionA extends Object implements ConnectionWithWriteLogging
Connection
.Modifier and Type | Method and Description |
---|---|
void |
addWriteLogStream(java.io.OutputStream logStream)
Adds the OutputStream to the connection to log all data written to the connected device.
|
int |
bytesAvailable()
Returns an estimate of the number of bytes that can be read from this connection without blocking.
|
void |
close()
Closes this connection and releases any system resources associated with the connection.
|
com.zebra.sdk.comm.ConnectionReestablisher |
getConnectionReestablisher(long thresholdTime)
Returns a
ConnectionReestablisher which allows for easy recreation of a connection which may have
been closed. |
String |
getManufacturer()
Returns the printer's manufacturer.
|
int |
getMaxDataToWrite()
Gets the maximum number of bytes to write at one time
|
int |
getMaxTimeoutForRead()
Returns the maximum time, in milliseconds, to wait for any data to be received.
|
int |
getTimeToWaitForMoreData()
Returns the maximum time, in milliseconds, to wait in-between reads after the initial read.
|
boolean |
isConnected()
Returns true if the connection is open.
|
void |
open()
Opens the connection to a device.
|
byte[] |
read()
Reads all the available data from the connection.
|
byte[] |
read(int maxBytesToRead)
Reads
maxBytesToRead of the available data from the connection. |
byte[] |
read(int maxBytesToRead,
boolean exitOnFirstRead)
Reads
maxBytesToRead of the available data from the connection. |
void |
read(java.io.OutputStream destinationStream)
Reads all the available data from the connection.
|
int |
readChar()
Reads the next byte of data from the connection, similar to a Java InputStream.
|
byte[] |
sendAndWaitForResponse(byte[] dataToSend,
int initialResponseTimeout,
int responseCompletionTimeout,
String terminator)
Sends
dataToSend and returns the response data. |
void |
sendAndWaitForResponse(java.io.OutputStream destinationStream,
java.io.InputStream sourceStream,
int initialResponseTimeout,
int responseCompletionTimeout,
String terminator)
Sends data from
sourceStream and writes the response data to destinationStream. |
byte[] |
sendAndWaitForValidResponse(byte[] dataToSend,
int initialResponseTimeout,
int responseCompletionTimeout,
ResponseValidator validator)
Sends
dataToSend and returns the response data. |
void |
sendAndWaitForValidResponse(java.io.OutputStream destinationStream,
java.io.InputStream sourceStream,
int initialResponseTimeout,
int responseCompletionTimeout,
ResponseValidator validator)
Sends data from
sourceStream and writes the response data to destinationStream. |
void |
setMaxDataToWrite(int maxDataSize)
Sets the maximum number of bytes to write at one time
|
void |
setMaxTimeoutForRead(int maxTimeoutForRead)
Set the maximum time, in milliseconds, to wait for any data to be received
|
void |
setReadTimeout(int timeout)
Sets the underlying socket read timeout value
|
void |
setTimeToWaitForMoreData(int timeToWaitForMoreData)
Set the maximum time, in milliseconds, to wait in-between reads after the initial read.
|
void |
waitForData(int maxTimeout)
Causes the currently executing thread to sleep until
Connection.bytesAvailable() > 0, or for a maximum of
maxTimeout milliseconds. |
void |
write(byte[] data)
Writes
data.length bytes from the specified byte array to this output stream. |
void |
write(byte[] data,
int offset,
int length)
Writes
length bytes from data starting at offset . |
void |
write(java.io.InputStream dataSource)
Writes all available bytes from the data source to this output stream.
|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getSimpleConnectionName, toString
public void open() throws ConnectionException
Connection
open
method is called when this connection has already been
opened, this call is ignored. When a handle to the connection is no longer needed, you must call Connection.close()
to free up system resources.open
in interface Connection
ConnectionException
- if the connection cannot be established.Connection.open()
public void close() throws ConnectionException
Connection
close
in interface Connection
ConnectionException
- if an I/O error occurs.Connection.close()
public void write(byte[] data) throws ConnectionException
Connection
data.length
bytes from the specified byte array to this output stream. The connection must be
open before this method is called. If write
is called when a connection is closed, a
ConnectionException
is thrown.write
in interface Connection
data
- the data.ConnectionException
- if an I/O error occurs.Connection.write(byte[])
public void write(java.io.InputStream dataSource) throws ConnectionException
Connection
write
is called when a connection is closed, a ConnectionException
is thrown.write
in interface Connection
dataSource
- the data.ConnectionException
- if an I/O error occurs.Connection.write(java.io.InputStream)
public void write(byte[] data, int offset, int length) throws ConnectionException
Connection
length
bytes from data
starting at offset
. The connection must be
open before this method is called. If write
is called when a connection is closed, a
ConnectionException
is thrown.write
in interface Connection
data
- the data.offset
- the start offset in the data
.length
- number of bytes to write.ConnectionException
- if an I/O error occurs.Connection.write(byte[], int, int)
public boolean isConnected()
Connection
isConnected
in interface Connection
true
if this connection is open.Connection.isConnected()
public byte[] read() throws ConnectionException
Connection
byte[] data = printerConnection.read();
read
in interface Connection
ConnectionException
- if an I/O error occurs.Connection.read()
public byte[] read(int maxBytesToRead) throws ConnectionException
maxBytesToRead
of the available data from the connection. This call is non-blocking.maxBytesToRead
- number of bytes to readConnectionException
- if an I/O error occurs.public void read(java.io.OutputStream destinationStream) throws ConnectionException
Connection
read
in interface Connection
destinationStream
- for read dataConnectionException
- if an I/O error occurs.Connection.read(java.io.OutputStream)
public int readChar() throws ConnectionException
Connection
int singleCharacter = printerConnection.readChar();
readChar
in interface Connection
ConnectionException
- if an I/O error occurs.Connection.readChar()
public int bytesAvailable() throws ConnectionException
Connection
bytesAvailable
in interface Connection
ConnectionException
- if an I/O error occurs.Connection.bytesAvailable()
public void waitForData(int maxTimeout) throws ConnectionException
Connection
Connection.bytesAvailable()
> 0, or for a maximum of
maxTimeout
milliseconds.waitForData
in interface Connection
maxTimeout
- maximum time in milliseconds to wait for an initial response from the printer.ConnectionException
- if an I/O error occurs.Connection.waitForData(int)
public int getMaxTimeoutForRead()
Connection
getMaxTimeoutForRead
in interface Connection
Connection.getMaxTimeoutForRead()
public int getTimeToWaitForMoreData()
Connection
getTimeToWaitForMoreData
in interface Connection
Connection.getTimeToWaitForMoreData()
public byte[] sendAndWaitForResponse(byte[] dataToSend, int initialResponseTimeout, int responseCompletionTimeout, String terminator) throws ConnectionException
Connection
dataToSend
and returns the response data. The software returns immediately if the data
received contains terminator
. The connection must be open before this method is called. If
sendAndWaitForResponse
is called when a connection is closed, a ConnectionException
is
thrown.sendAndWaitForResponse
in interface Connection
dataToSend
- byte array of data to sendinitialResponseTimeout
- The maximum time, in milliseconds, to wait for the initial response to be received.
If no data is received during this time, the function returns a zero length array.responseCompletionTimeout
- After the initial response, if no data is received for this period of time, the
input is considered complete and the method returns.terminator
- If the response contains this string, the input is considered complete and the method returns.
May be used to avoid waiting for more data when the response is always terminated with a known string. Use
null
if no terminator is desired.ConnectionException
- if an I/O error occurs.Connection.sendAndWaitForResponse(byte[], int, int, java.lang.String)
public void sendAndWaitForResponse(java.io.OutputStream destinationStream, java.io.InputStream sourceStream, int initialResponseTimeout, int responseCompletionTimeout, String terminator) throws ConnectionException
Connection
sourceStream
and writes the response data to destinationStream. The software returns
immediately if the data received contains terminator
. The connection must be open before this method
is called. If sendAndWaitForResponse
is called when a connection is closed, a
ConnectionException
is thrown.sendAndWaitForResponse
in interface Connection
destinationStream
- Destination for response.sourceStream
- Source of data to be sent.initialResponseTimeout
- The maximum time, in milliseconds, to wait for the initial response to be received.
If no data is received during this time, the function does not write any data to the destination stream.responseCompletionTimeout
- After the initial response, if no data is received for this period of time, the
input is considered complete and the method returns.terminator
- If the response contains this string, the input is considered complete and the method returns.
May be used to avoid waiting for more data when the response is always terminated with a known string. Use
null
if no terminator is desired.ConnectionException
- if an I/O error occurs.Connection.sendAndWaitForResponse(java.io.OutputStream, java.io.InputStream, int, int,
java.lang.String)
public byte[] sendAndWaitForValidResponse(byte[] dataToSend, int initialResponseTimeout, int responseCompletionTimeout, ResponseValidator validator) throws ConnectionException
Connection
dataToSend
and returns the response data. The software returns immediately if the data
received satisfies validator
. The connection must be open before this method is called. If
sendAndWaitForResponse
is called when a connection is closed, a ConnectionException
is
thrown.sendAndWaitForValidResponse
in interface Connection
dataToSend
- byte array of data to sendinitialResponseTimeout
- The maximum time, in milliseconds, to wait for the initial response to be received.
If no data is received during this time, the function returns a zero length array.responseCompletionTimeout
- After the initial response, if no data is received for this period of time, the
input is considered complete and the method returns.validator
- If the response satisfies this validator, the input is considered complete and the method
returns. May be used to avoid waiting for more data when the response follows a known format.ConnectionException
- if an I/O error occurs.Connection.sendAndWaitForValidResponse(byte[], int, int,
com.zebra.sdk.comm.ResponseValidator)
public void sendAndWaitForValidResponse(java.io.OutputStream destinationStream, java.io.InputStream sourceStream, int initialResponseTimeout, int responseCompletionTimeout, ResponseValidator validator) throws ConnectionException
Connection
sourceStream
and writes the response data to destinationStream. The software returns
immediately if the data received satisfies validator
. The connection must be open before this method
is called. If sendAndWaitForResponse
is called when a connection is closed, a
ConnectionException
is thrown.sendAndWaitForValidResponse
in interface Connection
destinationStream
- Destination for response.sourceStream
- Source of data to be sent.initialResponseTimeout
- The maximum time, in milliseconds, to wait for the initial response to be received.
If no data is received during this time, the function does not write any data to the destination stream.responseCompletionTimeout
- After the initial response, if no data is received for this period of time, the
input is considered complete and the method returns.validator
- If the response satisfies this validator, the input is considered complete and the method
returns. May be used to avoid waiting for more data when the response follows a known format. If validator is
null, no validation is performed. When performing validation, this method will use enough memory to hold the
entire response.ConnectionException
- if an I/O error occurs.Connection.sendAndWaitForValidResponse(java.io.OutputStream, java.io.InputStream, int,
int, com.zebra.sdk.comm.ResponseValidator)
public void setMaxTimeoutForRead(int maxTimeoutForRead)
Connection
setMaxTimeoutForRead
in interface Connection
maxTimeoutForRead
- the maximum time, in milliseconds, to wait for any data to be received.Connection.setMaxTimeoutForRead(int)
public void setTimeToWaitForMoreData(int timeToWaitForMoreData)
Connection
setTimeToWaitForMoreData
in interface Connection
timeToWaitForMoreData
- the maximum time, in milliseconds, to wait in-between reads after the initial read.Connection.setTimeToWaitForMoreData(int)
public com.zebra.sdk.comm.ConnectionReestablisher getConnectionReestablisher(long thresholdTime) throws ConnectionException
Connection
ConnectionReestablisher
which allows for easy recreation of a connection which may have
been closed.
getConnectionReestablisher
in interface Connection
thresholdTime
- how long the Connection reestablisher will wait before attempting to reconnection to the
printerConnectionException
- if the ConnectionReestablisher could not be created.Connection.getConnectionReestablisher(long thresholdTime)
public void addWriteLogStream(java.io.OutputStream logStream)
ConnectionWithWriteLogging
addWriteLogStream
in interface ConnectionWithWriteLogging
logStream
- log all write data to this stream.ConnectionWithWriteLogging.addWriteLogStream(OutputStream)
public void setMaxDataToWrite(int maxDataSize)
maxDataSize
- maximum number of bytes to write at one timepublic int getMaxDataToWrite()
public byte[] read(int maxBytesToRead, boolean exitOnFirstRead) throws ConnectionException
maxBytesToRead
of the available data from the connection.maxBytesToRead
- number of bytes to readexitOnFirstRead
- true to exit on first data readConnectionException
- if an I/O error occurs.public String getManufacturer()
public void setReadTimeout(int timeout) throws ConnectionException
timeout
- The read timeout in millisecondsConnectionException
- If an error occurs while setting the read timeout
© 2016 ZIH Corp. All Rights Reserved.