public abstract class MultichannelConnection extends Object implements ConnectionWithWriteLogging
Connection and if only the Connection methods are used, the SDK will attempt to open
both the printing and status channels. MultichannelConnection will use the raw Connection when a method is
called directly. Furthermore, when using a ZebraPrinterLinkOs in conjunction with a
MultichannelConnection, the ZebraPrinterLinkOs will attempt to use whichever connection is the most
efficient. If you wish to only open up a specific channel, use either the
openPrintingChannel() or
openStatusChannel() method and their corresponding
closePrintingChannel() and
closeStatusChannel() method.| 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 both the printing and status channels of this MultichannelConnection.
|
void |
closePrintingChannel()
Closes the printing channel of this MultichannelConnection.
|
void |
closeStatusChannel()
Closes the status channel of this MultichannelConnection.
|
ConnectionReestablisher |
getConnectionReestablisher(long thresholdTime)
Returns a
ConnectionReestablisher which allows for easy recreation of a connection which may have
been closed. |
int |
getMaxTimeoutForRead()
Returns the maximum time, in milliseconds, to wait for any data to be received on the printing channel.
|
Connection |
getPrintingChannel()
Returns the underlying printing
Connection of this MultichannelConnection. |
StatusConnection |
getStatusChannel()
Returns the underlying status
StatusConnection of this MultichannelConnection. |
int |
getTimeToWaitForMoreData()
Returns the maximum time, in milliseconds, to wait in-between reads after the initial read for the printing
channel.
|
boolean |
isConnected()
Returns true if the connection is open.
|
void |
open()
Opens both the printing and status channel of this Multichannel connection.
|
void |
openPrintingChannel()
Opens the printing channel of this Multichannel connection.
|
void |
openStatusChannel()
Opens the status channel of this Multichannel connection.
|
byte[] |
read()
Reads all 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 |
setMaxTimeoutForRead(int maxTimeoutForRead)
Set the maximum time, in milliseconds, to wait for any data to be received.
|
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, waitgetSimpleConnectionName, toStringpublic void open()
throws ConnectionException
ConnectionException is thrown. When this Multichannel connection is no longer needed, you must
call Connection.close() to free up system resources.open in interface ConnectionConnectionException - if the connection cannot be established.public void openPrintingChannel()
throws ConnectionException
Connection.close() or closePrintingChannel() to
free up system resources.ConnectionException - if the connection cannot be established.public void openStatusChannel()
throws ConnectionException
Connection.close() or closeStatusChannel() to free up
system resources.ConnectionExceptionpublic void close()
throws ConnectionException
close in interface ConnectionConnectionException - if an I/O error occurs.public void closePrintingChannel()
throws ConnectionException
ConnectionException - if an I/O error occurs.public void closeStatusChannel()
throws ConnectionException
ConnectionException - if an I/O error occurs.public void write(byte[] data)
throws ConnectionException
Connectiondata.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 Connectiondata - the data.ConnectionException - if an I/O error occurs.Connection.write(byte[])public void write(byte[] data,
int offset,
int length)
throws ConnectionException
Connectionlength 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 Connectiondata - 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 void write(java.io.InputStream dataSource)
throws ConnectionException
Connectionwrite is called when a connection is closed, a ConnectionException
is thrown.write in interface ConnectiondataSource - the data.ConnectionException - if an I/O error occurs.Connection.write(java.io.InputStream)public byte[] read()
throws ConnectionException
Connectionbyte[] data = printerConnection.read();
read in interface ConnectionConnectionException - if an I/O error occurs.Connection.read()public void read(java.io.OutputStream destinationStream)
throws ConnectionException
Connectionread in interface ConnectiondestinationStream - for read dataConnectionException - if an I/O error occurs.Connection.read(java.io.OutputStream)public int readChar()
throws ConnectionException
Connectionint singleCharacter = printerConnection.readChar();
readChar in interface ConnectionConnectionException - if an I/O error occurs.Connection.readChar()public boolean isConnected()
ConnectionisConnected in interface Connectiontrue if this connection is open.Connection.isConnected()public int bytesAvailable()
throws ConnectionException
ConnectionbytesAvailable in interface ConnectionConnectionException - if an I/O error occurs.Connection.bytesAvailable()public void waitForData(int maxTimeout)
throws ConnectionException
ConnectionConnection.bytesAvailable() > 0, or for a maximum of
maxTimeout milliseconds.waitForData in interface ConnectionmaxTimeout - 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()
getMaxTimeoutForRead in interface Connectionpublic int getTimeToWaitForMoreData()
getTimeToWaitForMoreData in interface Connectionpublic void setMaxTimeoutForRead(int maxTimeoutForRead)
setMaxTimeoutForRead in interface ConnectionmaxTimeoutForRead - the maximum time, in milliseconds, to wait for any data to be received.public void setTimeToWaitForMoreData(int timeToWaitForMoreData)
setTimeToWaitForMoreData in interface ConnectiontimeToWaitForMoreData - the maximum time, in milliseconds, to wait in-between reads after the initial read.public byte[] sendAndWaitForResponse(byte[] dataToSend,
int initialResponseTimeout,
int responseCompletionTimeout,
String terminator)
throws ConnectionException
ConnectiondataToSend 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 ConnectiondataToSend - 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
ConnectionsourceStream 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 ConnectiondestinationStream - 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
ConnectiondataToSend 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 ConnectiondataToSend - 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
ConnectionsourceStream 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 ConnectiondestinationStream - 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 Connection getPrintingChannel()
Connection of this MultichannelConnection.public StatusConnection getStatusChannel()
StatusConnection of this MultichannelConnection.public ConnectionReestablisher getConnectionReestablisher(long thresholdTime) throws ConnectionException
ConnectionConnectionReestablisher which allows for easy recreation of a connection which may have
been closed.
getConnectionReestablisher in interface ConnectionthresholdTime - 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)
ConnectionWithWriteLoggingaddWriteLogStream in interface ConnectionWithWriteLogginglogStream - log all write data to this stream.ConnectionWithWriteLogging.addWriteLogStream(OutputStream)
© 2017 ZIH Corp. All Rights Reserved.