daily pastebin goal
1%
SHARE
TWEET

Untitled

a guest May 16th, 2018 189 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package isi.lab3;
  2.  
  3. import javax.servlet.ServletContext;
  4. import javax.servlet.ServletException;
  5. import javax.servlet.ServletOutputStream;
  6. import javax.servlet.annotation.WebServlet;
  7. import javax.servlet.http.HttpServlet;
  8. import javax.servlet.http.HttpServletRequest;
  9. import javax.servlet.http.HttpServletResponse;
  10. import java.io.File;
  11. import java.io.FileInputStream;
  12. import java.io.IOException;
  13.  
  14. @WebServlet(urlPatterns = "/SendPdfAbout", name = "SendPdfAbout")
  15. public class SendPdfAbout extends HttpServlet {
  16.  
  17.     protected void doGet(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws ServletException, IOException {
  18.  
  19.         ServletContext servletContext = httpServletRequest.getServletContext();
  20.         String file = servletContext.getRealPath("Stabilnosc_kredytowa.pdf");
  21.         String mimeType = servletContext.getMimeType(file);
  22.         httpServletResponse.setContentType(mimeType != null ? mimeType : "application/octet-stream");
  23.         FileInputStream fileInputStream = new FileInputStream(file);
  24.         ServletOutputStream servletOutputStream = httpServletResponse.getOutputStream();
  25.         readBuffer(fileInputStream,servletOutputStream);
  26.     }
  27.  
  28.     private void readBuffer(FileInputStream fileInputStream, ServletOutputStream servletOutputStream) throws IOException {
  29.         byte[] buffer = new byte[4096];
  30.         int bytesRead;
  31.         while ((bytesRead = fileInputStream.read(buffer)) != -1) {
  32.             servletOutputStream.write(buffer, 0, bytesRead);
  33.         }
  34.         fileInputStream.close();
  35.         servletOutputStream.close();
  36.     }
  37. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top