org.simoes.lpd.util
Class NetUtil

java.lang.Object
  extended byorg.simoes.lpd.util.NetUtil

public class NetUtil
extends java.lang.Object

Provides utility methods helping us to parse the byte streams sent to us from the client.

Author:
Chris Simoes

Constructor Summary
NetUtil()
          Default Contructor.
 
Method Summary
 byte[] readCommand(java.io.InputStream is)
          Reads a command defined by the RFC1179 spec.
 byte[] readControlFile(java.io.InputStream is, java.io.OutputStream os)
          Reads the ControlFile and retunrs it as a byte[]
 byte[] readNextInput(java.io.InputStream is, java.io.OutputStream os)
          Used by CommandReceiveJob to read the headers of the ControlFile or the DataFile from the client.
 byte[] readPrintFile(java.io.InputStream is, java.io.OutputStream os)
          Reads the DataFile and returns it as a byte[]
 byte[] readPrintFile(java.io.InputStream is, java.io.OutputStream os, int size)
          Reads the DataFile and returns it as a byte[]
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

NetUtil

public NetUtil()
Default Contructor.

Method Detail

readCommand

public byte[] readCommand(java.io.InputStream is)
                   throws java.io.IOException
Reads a command defined by the RFC1179 spec. Basically the command is all the data until we see 0x10.

Parameters:
is - the InputStream providing us with a command from the client.
Returns:
the command we found in the InputStream
Throws:
java.io.IOException - thrown if there is an IO problem

readNextInput

public byte[] readNextInput(java.io.InputStream is,
                            java.io.OutputStream os)
                     throws java.io.IOException
Used by CommandReceiveJob to read the headers of the ControlFile or the DataFile from the client. Please see section 6 of the RFC1179 specification for more details.

Parameters:
is - the InputStream from the client sending us the print job
os - the OutputStream to the client we are writing reponses to
Returns:
a byte[] from the InputStream holding the ControlFile or the DataFile
Throws:
java.io.IOException - thrown if there is an IO problem

readControlFile

public byte[] readControlFile(java.io.InputStream is,
                              java.io.OutputStream os)
                       throws java.io.IOException
Reads the ControlFile and retunrs it as a byte[]

Parameters:
is - the InputStream from the client sending us the control file
os - the OutputStream to the client we are writing reponses to
Returns:
a byte[] from the InputStream holding the ControlFile
Throws:
java.io.IOException - thrown if there is an IO problem

readPrintFile

public byte[] readPrintFile(java.io.InputStream is,
                            java.io.OutputStream os)
                     throws java.io.IOException
Reads the DataFile and returns it as a byte[]

Parameters:
is - the InputStream from the client sending us the data file
os - the OutputStream to the client we are writing reponses to
Returns:
a byte[] from the InputStream holding the DataFile
Throws:
java.io.IOException - thrown if there is an IO problem

readPrintFile

public byte[] readPrintFile(java.io.InputStream is,
                            java.io.OutputStream os,
                            int size)
                     throws java.io.IOException
Reads the DataFile and returns it as a byte[]

Parameters:
is - the InputStream from the client sending us the data file
os - the OutputStream to the client we are writing reponses to
size - the number of bytes to read from the stream
Returns:
a byte[] from the InputStream holding the DataFile
Throws:
java.io.IOException - thrown if there is an IO problem