FileDocCategorySizeDatePackage
DocumentDescription.javaAPI DocExample4246Thu Nov 08 00:23:44 GMT 2001com.ora.rmibook.chapter3

DocumentDescription

public class DocumentDescription extends Object

Fields Summary
private DataInputStream
_actualDocument
private int
_documentType
private boolean
_printTwoSided
private int
_printQuality
private int
_length
Constructors Summary
public DocumentDescription(InputStream source)

        readFromStream(source);
    
public DocumentDescription(InputStream actualDocument, int documentType, boolean printTwoSided, int printQuality)

        _documentType = documentType;
        _printTwoSided = printTwoSided;
        _printQuality = printQuality;
        BufferedInputStream buffer = new BufferedInputStream(actualDocument);
        DataInputStream dataInputStream = new DataInputStream(buffer);
        ByteArrayOutputStream temporaryBuffer = new ByteArrayOutputStream();

        _length = copy(dataInputStream, new DataOutputStream(temporaryBuffer));
        _actualDocument = new DataInputStream(new ByteArrayInputStream(temporaryBuffer.toByteArray()));
    
public DocumentDescription(InputStream actualDocument, int documentType, boolean printTwoSided, int printQuality, int length)

        _actualDocument = new DataInputStream(actualDocument);
        _documentType = documentType;
        _printTwoSided = printTwoSided;
        _printQuality = printQuality;
        _length = length;
    
Methods Summary
private voidcopy(java.io.InputStream source, java.io.OutputStream destination, int length)

        int counter;
        int nextByte;

        for (counter = 0; counter < length; counter++) {
            nextByte = source.read();
            destination.write(nextByte);
        }
        destination.flush();
    
private intcopy(java.io.InputStream source, java.io.OutputStream destination)

        int nextByte;
        int numberOfBytesCopied = 0;

        while (-1 != (nextByte = source.read())) {
            destination.write(nextByte);
            numberOfBytesCopied++;
        }
        destination.flush();
        return numberOfBytesCopied;
    
public intgetDocumentType()

        return _documentType;
    
public intgetLength()

        return _length;
    
public intgetPrintQuality()

        return _printQuality;
    
public booleanisPrintTwoSided()

        return _printTwoSided;
    
public voidreadFromStream(java.io.InputStream inputStream)

        BufferedInputStream buffer = new BufferedInputStream(inputStream);
        DataInputStream dataInputStream = new DataInputStream(buffer);

        readMetadataFromStream(dataInputStream);
        ByteArrayOutputStream temporaryBuffer = new ByteArrayOutputStream();

        copy(dataInputStream, new DataOutputStream(temporaryBuffer), _length);
        _actualDocument = new DataInputStream(new ByteArrayInputStream(temporaryBuffer.toByteArray()));
    
private voidreadMetadataFromStream(java.io.DataInputStream dataInputStream)

        _documentType = dataInputStream.readInt();
        _printTwoSided = dataInputStream.readBoolean();
        _printQuality = dataInputStream.readInt();
        _length = dataInputStream.readInt();
    
private voidwriteMetadataToStream(java.io.DataOutputStream dataOutputStream)

        dataOutputStream.writeInt(_documentType);
        dataOutputStream.writeBoolean(_printTwoSided);
        dataOutputStream.writeInt(_printQuality);
        dataOutputStream.writeInt(_length);
    
public voidwriteToStream(java.io.OutputStream outputStream)

        BufferedOutputStream buffer = new BufferedOutputStream(outputStream);
        DataOutputStream dataOutputStream = new DataOutputStream(buffer);

        writeMetadataToStream(dataOutputStream);
        copy(_actualDocument, dataOutputStream, _length);