* javax.print.attribute.PrintRequestAttributeSet)
*/
public void print(Doc doc, PrintRequestAttributeSet attributes)
throws PrintException {
synchronized (this) {
DocFlavor flavor = doc.getDocFlavor();
if (flavor.equals(DocFlavor.INPUT_STREAM.POSTSCRIPT) ||
flavor.equals(DocFlavor.BYTE_ARRAY.POSTSCRIPT) ||
flavor.equals(DocFlavor.URL.POSTSCRIPT) ||
flavor.equals(DocFlavor.INPUT_STREAM.AUTOSENSE) ||
flavor.equals(DocFlavor.BYTE_ARRAY.AUTOSENSE) ||
flavor.equals(DocFlavor.URL.AUTOSENSE)) {
InputStream data = null;
try {
if (flavor.equals(DocFlavor.URL.POSTSCRIPT)) {
data = ((URL)doc.getPrintData()).openStream();
} else {
data = doc.getStreamForBytes();
}
} catch (IOException ioe) {
throw new PrintException(
"Can't read data from document souce");
}
int printerID = startDocPrinter(serviceName,
convertAttributes(attributes, flavor),
getJobName(attributes), getDestination(attributes));
if (printerID != 0) {
byte[] buffer = new byte[10240];
try {
int bytesRead = data.read(buffer);
while (bytesRead >= 0) {
if (!writePrinter(buffer, bytesRead, printerID)) {
endDocPrinter(printerID);
throw new PrintException(
"Can't send data to printer");
}
bytesRead = data.read(buffer);
}
} catch (IOException ioe) {
throw new PrintException(
"Can't read print data from Doc");
}
if (!endDocPrinter(printerID)) {
throw new PrintException("Can't finish job normally");
}
} else {
throw new PrintException("Can't start printing");
}
} else if (flavor.getMimeType().toLowerCase().equals(
"internal/postscript") &&
flavor.getRepresentationClassName().equals(
"java.io.InputStream")) {
InputStream data = null;
try {
data = (InputStream)doc.getPrintData();
} catch (IOException ioe) {