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) {
throw new PrintException(
"Can't read data from document souce");
}
PSInterpreter interpreter = new PSInterpreter(data, serviceName,
this, attributes);
interpreter.interpret();
} else {
throw new PrintException("DocFlavor is not supported");
}
}
}