/[projects]/miscJava/Test4Simple/src/main/java/DumpFile.java
ViewVC logotype

Contents of /miscJava/Test4Simple/src/main/java/DumpFile.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2516 - (show annotations) (download)
Mon Apr 27 15:41:43 2015 UTC (9 years ago) by torben
File size: 1126 byte(s)
forked test3 to test4 with out the advanced ejb stuff etc
1
2
3 import java.io.ByteArrayOutputStream;
4 import java.io.FileInputStream;
5 import java.io.IOException;
6 import java.io.InputStream;
7
8 import javax.servlet.ServletException;
9 import javax.servlet.http.HttpServlet;
10 import javax.servlet.http.HttpServletRequest;
11 import javax.servlet.http.HttpServletResponse;
12
13
14 public class DumpFile extends HttpServlet {
15 private static final long serialVersionUID = 1L;
16
17
18 String dumpStream(InputStream is) throws IOException {
19 ByteArrayOutputStream baos = new ByteArrayOutputStream();
20
21 byte buf[] = new byte[1024];
22 int len;
23
24 while ( (len = is.read(buf)) != -1) {
25 baos.write(buf,0,len);
26 }
27
28 return new String( baos.toByteArray() );
29 }
30
31 protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
32 response.setContentType("text/plain");
33 InputStream s1 = getServletContext().getResource("/index.html").openStream();
34
35 InputStream s2 = new FileInputStream(getServletContext().getRealPath("/index.html"));
36
37
38 response.getWriter().print( dumpStream(s2) );
39
40 }
41
42 }

  ViewVC Help
Powered by ViewVC 1.1.20