From e4ff596039e48bb219ca49b03d8f84ad05236f2a Mon Sep 17 00:00:00 2001 From: ulrich Date: Fri, 24 Jul 2020 10:29:37 +0000 Subject: [PATCH] PDF-Ausgabe binaer schreiben --- src/de/uhilger/wbx/web/AdocServlet.java | 22 +++++++++++++--------- 1 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/de/uhilger/wbx/web/AdocServlet.java b/src/de/uhilger/wbx/web/AdocServlet.java index f89b21f..cd8f798 100644 --- a/src/de/uhilger/wbx/web/AdocServlet.java +++ b/src/de/uhilger/wbx/web/AdocServlet.java @@ -22,6 +22,7 @@ import java.io.File; import java.io.FileInputStream; import java.io.IOException; +import java.io.InputStream; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.HashMap; @@ -30,6 +31,7 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.util.Map; +import javax.servlet.ServletOutputStream; import static org.asciidoctor.Asciidoctor.Factory.create; import org.asciidoctor.Asciidoctor; @@ -89,6 +91,7 @@ wenn die Quelle sich geandert hat oder die PDF-Datei noch nicht existiert */ + String pdf = request.getParameter(PDF); if(null != pdf && pdf.equalsIgnoreCase(Boolean.TRUE.toString())) { File pdffile = new File(adocfile.getParentFile(), fname + DOT + PDF); @@ -97,16 +100,17 @@ response.setContentType("application/pdf"); transform(absname, PDF); } - } - - try (PrintWriter out = response.getWriter()) { - // abhaengig vom Parameter pdf HTML- oder PDF-Datei ausgeben - FileInputStream in = new FileInputStream(outfile); - BufferedReader reader = new BufferedReader(new InputStreamReader(in, "UTF-8")); - String line; - while ((line = reader.readLine()) != null) { - out.println(line); + ServletOutputStream os = response.getOutputStream(); + InputStream bytes = new FileInputStream(outfile); + int b = bytes.read(); + while(b > -1 ) { + os.write(b); + b = bytes.read(); } + } else { + PrintWriter out = response.getWriter(); + InputStreamReader in = new InputStreamReader(new FileInputStream(outfile), "UTF-8"); + in.transferTo(out); } } -- Gitblit v1.9.3