FileDocCategorySizeDatePackage
ClientNetworkWrapper.javaAPI DocExample2389Thu Nov 08 00:23:44 GMT 2001com.ora.rmibook.chapter3

ClientNetworkWrapper

public class ClientNetworkWrapper extends NetworkBaseClass implements PrinterConstants

Fields Summary
private String
_serverMachine
private int
_serverPort
Constructors Summary
public ClientNetworkWrapper()

        this (DEFAULT_SERVER_NAME, DEFAULT_SERVER_PORT);
    
public ClientNetworkWrapper(String serverMachine, int serverPort)

        _serverMachine = serverMachine;
        _serverPort = serverPort;
    
Methods Summary
private voidreadStatusFromSocket(java.net.Socket connection)

        InputStream inputStream = connection.getInputStream();
        DataInputStream dataInputStream = new DataInputStream(inputStream);
        BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
        boolean response = dataInputStream.readBoolean();

        if (response) {
            return;
        }
        PrinterException error = new PrinterException(inputStream);

        throw error;
    
public voidsendDocumentToPrinter(java.io.InputStream actualDocument)

        sendDocumentToPrinter(actualDocument, DEFAULT_DOCUMENT_TYPE,
            DEFAULT_PRINT_TWO_SIDED, DEFAULT_PRINT_QUALITY);
    
public voidsendDocumentToPrinter(java.io.InputStream actualDocument, int documentType, boolean printTwoSided, int printQuality)

        DocumentDescription documentToSend;

        try {
            documentToSend = new DocumentDescription(actualDocument, documentType, printTwoSided, printQuality);
        } catch (IOException e) {
            throw new ConnectionException();
        }
        sendDocumentToPrinter(documentToSend);
    
public voidsendDocumentToPrinter(DocumentDescription documentDescription)

        Socket connection = null;

        try {
            connection = new Socket(_serverMachine, _serverPort);
            documentDescription.writeToStream(connection.getOutputStream());
            readStatusFromSocket(connection);
        } catch (IOException e) {
            e.printStackTrace();
            throw new ConnectionException();
        }
        closeSocket(connection);