WebBox Klassenbibliothek
ulrich
2020-07-24 e4ff596039e48bb219ca49b03d8f84ad05236f2a
PDF-Ausgabe binaer schreiben
1 files modified
22 ■■■■■ changed files
src/de/uhilger/wbx/web/AdocServlet.java 22 ●●●●● patch | view | raw | blame | history
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);
    }
  }