super.appendToResponse(response, aContext);
if (enabled()) {
File tempFile = null;
File psFile = null;
try {
NSData content = response.content();
tempFile = File.createTempFile("pdftops", "pdf");
tempFile.deleteOnExit();
psFile = File.createTempFile("pdftops", "ps");
psFile.deleteOnExit();
NSMutableArray<String> array = new NSMutableArray<String>(pdftops, "-expand", tempFile.getPath(), psFile.getPath());
if (duplex()) {
array.add(1, "-duplex");
}
content.writeToStream(new FileOutputStream(tempFile));
Process process = Runtime.getRuntime().exec(array.toArray(new String[array.size()]));
process.waitFor();
NSData data = new NSData(new FileInputStream(psFile), 4096);
String header = response.headerForKey("content-disposition");
response.setHeader(header.replace(".pdf", ".ps"), "content-disposition");
response.setHeader("application/postscript", "Content-Type");
response.setHeader(String.valueOf(data.length()), "Content-Length");
response.setContent(data);
} catch (FileNotFoundException e) {
throw NSForwardException._runtimeExceptionForThrowable(e);
} catch (IOException e) {
throw NSForwardException._runtimeExceptionForThrowable(e);