dirk_krause.jtools
Class PrintClient

java.lang.Object
  extended by dirk_krause.jtools.PrintClient

public class PrintClient
extends java.lang.Object

Printer client. Objects of this class can send a byte array or a string containing the print job data to an LPD server or directly to a printer using a direct TCP connection.


Field Summary
protected  boolean appendCtrlD
          Flag: Append CTRL-D to end if not present.
protected  java.lang.String destinationHost
          Host (name or IP) to submit job to.
protected  int destinationPort
          Port number on destination host.
protected  int destinationProtocol
          Protocol for print job submission.
protected  java.lang.String destinationQueue
          Queue name on destination host.
protected  java.lang.String destinationUser
          User name for print job.
static int ERROR_BAD_REMOTE_ADDRESS
          Error: Problems with remote address.
static int ERROR_FAILED_LOCAL_PORT
          Error: Failed to bind local port.
static int ERROR_FAILED_TO_CONNECT
          Error: Failed to connect to remote address.
static int ERROR_FAILED_TO_CREATE_SOCKET
          Error: Failed to create socket.
static int ERROR_FAILED_TO_FIND_HOSTNAME
          Error: Failed to find my own host name.
static int ERROR_INVALID_ARGUMENT
          Error: An invalid argument was passed to a method.
static int ERROR_MEMORY
          Error: Memory allocation problem.
static int ERROR_NO_DESTINATION
          Error: No destination specified yet.
static int ERROR_REJECTED_BY_SERVER
          Error: Request rejected by server.
static int ERROR_UNKNOWN_PROTOCOL
          Error: Unknown protocol, must be "tcp" or "lpd".
static int ERROR_WHILE_READING
          Error: Failed to read response.
static int ERROR_WHILE_WRITING
          Error: Failed to write data.
protected  int lastError
          Error code for last error occured.
protected  int localPortMax
          Local port (maximum value).
protected  int localPortMin
          Local port (minimum value).
static java.lang.String[] optionKeys
          Option keywords.
static java.lang.String prefKey
          Key to retrieve job ID.
static java.lang.String prefRoot
          Preferences root key.
static int PROTOCOL_LPR
          Protocol: LPR/LPD.
static int PROTOCOL_TCP
          Protocol: Raw TCP.
static int PROTOCOL_UNKNOWN
          Protocol: Not yet specified.
static java.lang.String[] protocols
          Protocol strings.
protected  boolean readResponse
          Flag: Read response from printer.
protected  java.lang.String responseString
          Response from printer.
static byte[] zerobyte
          Confirmation byte to send after LPR requests.
 
Constructor Summary
PrintClient()
           
 
Method Summary
 int getLastError()
          Retrieve last error code, reset error code.
 java.lang.String getResponse()
           
 boolean setDestination(java.lang.String ds)
          Set destination for print jobs submitted later.
 boolean submit(byte[] printJob)
          Submit print job specified as byte array.
 boolean submit(byte[] printJob, boolean ctrlD)
          Submit print job.
 boolean submit(java.lang.String printJob)
          Submit print job.
 boolean submit(java.lang.String printJob, boolean ctrlD)
          Submit print job.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ERROR_MEMORY

public static final int ERROR_MEMORY
Error: Memory allocation problem.

See Also:
Constant Field Values

ERROR_UNKNOWN_PROTOCOL

public static final int ERROR_UNKNOWN_PROTOCOL
Error: Unknown protocol, must be "tcp" or "lpd".

See Also:
Constant Field Values

ERROR_NO_DESTINATION

public static final int ERROR_NO_DESTINATION
Error: No destination specified yet.

See Also:
Constant Field Values

ERROR_INVALID_ARGUMENT

public static final int ERROR_INVALID_ARGUMENT
Error: An invalid argument was passed to a method.

See Also:
Constant Field Values

ERROR_FAILED_TO_CREATE_SOCKET

public static final int ERROR_FAILED_TO_CREATE_SOCKET
Error: Failed to create socket.

See Also:
Constant Field Values

ERROR_FAILED_LOCAL_PORT

public static final int ERROR_FAILED_LOCAL_PORT
Error: Failed to bind local port.

See Also:
Constant Field Values

ERROR_BAD_REMOTE_ADDRESS

public static final int ERROR_BAD_REMOTE_ADDRESS
Error: Problems with remote address.

See Also:
Constant Field Values

ERROR_FAILED_TO_CONNECT

public static final int ERROR_FAILED_TO_CONNECT
Error: Failed to connect to remote address.

See Also:
Constant Field Values

ERROR_WHILE_WRITING

public static final int ERROR_WHILE_WRITING
Error: Failed to write data.

See Also:
Constant Field Values

ERROR_WHILE_READING

public static final int ERROR_WHILE_READING
Error: Failed to read response.

See Also:
Constant Field Values

ERROR_FAILED_TO_FIND_HOSTNAME

public static final int ERROR_FAILED_TO_FIND_HOSTNAME
Error: Failed to find my own host name.

See Also:
Constant Field Values

ERROR_REJECTED_BY_SERVER

public static final int ERROR_REJECTED_BY_SERVER
Error: Request rejected by server.

See Also:
Constant Field Values

PROTOCOL_UNKNOWN

public static final int PROTOCOL_UNKNOWN
Protocol: Not yet specified.

See Also:
Constant Field Values

PROTOCOL_LPR

public static final int PROTOCOL_LPR
Protocol: LPR/LPD.

See Also:
Constant Field Values

PROTOCOL_TCP

public static final int PROTOCOL_TCP
Protocol: Raw TCP.

See Also:
Constant Field Values

protocols

public static final java.lang.String[] protocols
Protocol strings.


optionKeys

public static final java.lang.String[] optionKeys
Option keywords.


prefRoot

public static final java.lang.String prefRoot
Preferences root key.

See Also:
Constant Field Values

prefKey

public static final java.lang.String prefKey
Key to retrieve job ID.

See Also:
Constant Field Values

zerobyte

public static final byte[] zerobyte
Confirmation byte to send after LPR requests.


destinationProtocol

protected int destinationProtocol
Protocol for print job submission.


destinationHost

protected java.lang.String destinationHost
Host (name or IP) to submit job to.


destinationPort

protected int destinationPort
Port number on destination host.


destinationQueue

protected java.lang.String destinationQueue
Queue name on destination host.


destinationUser

protected java.lang.String destinationUser
User name for print job.


lastError

protected int lastError
Error code for last error occured.


localPortMin

protected int localPortMin
Local port (minimum value).


localPortMax

protected int localPortMax
Local port (maximum value).


readResponse

protected boolean readResponse
Flag: Read response from printer.


appendCtrlD

protected boolean appendCtrlD
Flag: Append CTRL-D to end if not present.


responseString

protected java.lang.String responseString
Response from printer.

Constructor Detail

PrintClient

public PrintClient()
Method Detail

getLastError

public int getLastError()
Retrieve last error code, reset error code.

Returns:
Last error code.

submit

public boolean submit(byte[] printJob,
                      boolean ctrlD)
Submit print job.

Parameters:
printJob - Print job data.
ctrlD - Flag: Must add final CTRL-D if not present.
Returns:
Flag to indicate success.

submit

public boolean submit(byte[] printJob)
Submit print job specified as byte array.

Parameters:
printJob - Print job data.
Returns:
Flag to indicate success.

submit

public boolean submit(java.lang.String printJob,
                      boolean ctrlD)
Submit print job.

Parameters:
printJob - Print job data.
ctrlD - Flag: Must add final CTRL-D if not present.
Returns:
Flag to indicate success.

submit

public boolean submit(java.lang.String printJob)
Submit print job.

Parameters:
printJob - Print job data as string.
Returns:
Flag to indicate success.

setDestination

public boolean setDestination(java.lang.String ds)
Set destination for print jobs submitted later. Destination is in form "tcp:host:port[;options]" or "lpd:[user@]host[:port]!queue[;options]".

Parameters:
ds - Destination description.
Returns:
Flag to indicate success.

getResponse

public java.lang.String getResponse()