StreamOneFour.java Source code

Java tutorial

Introduction

Here is the source code for StreamOneFour.java

Source

import java.io.FileInputStream;
import java.io.FileOutputStream;

import javax.print.Doc;
import javax.print.DocFlavor;
import javax.print.DocPrintJob;
import javax.print.SimpleDoc;
import javax.print.StreamPrintService;
import javax.print.StreamPrintServiceFactory;
import javax.print.attribute.HashPrintRequestAttributeSet;
import javax.print.attribute.PrintRequestAttributeSet;

public class StreamOneFour {
    public static void main(String args[]) throws Exception {
        String infile = "StreamOneFour.java";
        DocFlavor flavor = DocFlavor.INPUT_STREAM.GIF;
        String mimeType = DocFlavor.INPUT_STREAM.POSTSCRIPT.getMimeType();
        StreamPrintServiceFactory[] factories = StreamPrintServiceFactory.lookupStreamPrintServiceFactories(flavor,
                mimeType);
        String filename = "out.ps";
        FileOutputStream fos = new FileOutputStream(filename);
        StreamPrintService sps = factories[0].getPrintService(fos);

        FileInputStream fis = new FileInputStream(infile);
        DocPrintJob dpj = sps.createPrintJob();
        PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();
        Doc doc = new SimpleDoc(fis, flavor, null);
        dpj.print(doc, pras);
        fos.close();
    }
}