|
2 | 2 |
|
3 | 3 | import org.apache.commons.compress.archivers.ArchiveException; |
4 | 4 | import org.apache.commons.compress.compressors.CompressorException; |
| 5 | +import org.apache.commons.io.IOUtils; |
5 | 6 |
|
6 | 7 | import static com.Bombs.CommonsCompressHandler.*; |
7 | 8 | import static com.Bombs.SnappyHandler.*; |
|
21 | 22 | import javax.servlet.http.Part; |
22 | 23 |
|
23 | 24 | @WebServlet( |
24 | | - name = "helloServlet", |
25 | | - urlPatterns = {"/hello-servlet"}) |
| 25 | + name = "helloServlet", |
| 26 | + urlPatterns = {"/hello-servlet"}) |
26 | 27 | @MultipartConfig() |
27 | 28 | public class HelloServlet extends HttpServlet { |
28 | 29 |
|
29 | | - public void init() {} |
30 | | - |
31 | | - public void doPost(HttpServletRequest request, HttpServletResponse response) |
32 | | - throws IOException, ServletException { |
33 | | - response.setContentType("text/html"); |
34 | | - Part remoteFile = request.getPart("zipFile"); |
35 | | - // Zip |
36 | | - ZipInputStreamSafe2(remoteFile.getInputStream()); |
37 | | - ZipInputStreamSafe(request.getPart("zipFile").getInputStream()); |
38 | | - ZipInputStreamUnsafe(remoteFile.getInputStream()); |
39 | | - GZipInputStreamUnsafe(request.getPart("zipFile").getInputStream()); |
40 | | - InflaterInputStreamUnsafe(request.getPart("zipFile").getInputStream()); |
41 | | - try { |
42 | | - InflaterUnsafe(request.getParameter("data").getBytes(StandardCharsets.UTF_8)); |
43 | | - } catch (DataFormatException e) { |
44 | | - throw new RuntimeException(e); |
45 | | - } |
46 | | - try { |
47 | | - ZipFile1(request.getParameter("zipFileName")); |
48 | | - } catch (DataFormatException e) { |
49 | | - throw new RuntimeException(e); |
| 30 | + public void init() { |
50 | 31 | } |
51 | 32 |
|
52 | | - // Zip4j |
53 | | - zip4jZipInputStream(remoteFile.getInputStream()); |
54 | | - zip4jZipInputStreamSafe(remoteFile.getInputStream()); |
55 | | - // SnappyZip |
56 | | - SnappyZipInputStream(remoteFile.getInputStream()); |
57 | | - // apache Commons |
58 | | - commonsCompressArchiveInputStream2(remoteFile.getInputStream()); |
59 | | - commonsCompressorInputStream(remoteFile.getInputStream()); |
60 | | - try { |
61 | | - commonsCompressArchiveInputStream(remoteFile.getInputStream()); |
62 | | - commonsCompressArchiveStreamFactory(remoteFile.getInputStream()); |
63 | | - } catch (ArchiveException e) { |
64 | | - throw new RuntimeException(e); |
65 | | - } |
66 | | - try { |
67 | | - commonsCompressCompressorStreamFactory(remoteFile.getInputStream()); |
68 | | - } catch (CompressorException e) { |
69 | | - throw new RuntimeException(e); |
70 | | - } |
| 33 | + public void doPost(HttpServletRequest request, HttpServletResponse response) |
| 34 | + throws IOException, ServletException { |
| 35 | + response.setContentType("text/html"); |
| 36 | + Part remoteFile = request.getPart("zipFile"); |
| 37 | + // Zip |
| 38 | + ZipInputStreamSafe2(remoteFile.getInputStream()); |
| 39 | + ZipInputStreamSafe(request.getPart("zipFile").getInputStream()); |
| 40 | + ZipInputStreamUnsafe(remoteFile.getInputStream()); |
| 41 | + GZipInputStreamUnsafe(request.getPart("zipFile").getInputStream()); |
| 42 | + InflaterInputStreamUnsafe(request.getPart("zipFile").getInputStream()); |
| 43 | + try { |
| 44 | + InflaterUnsafe(request.getParameter("data").getBytes(StandardCharsets.UTF_8)); |
| 45 | + } catch (DataFormatException e) { |
| 46 | + throw new RuntimeException(e); |
| 47 | + } |
| 48 | + try { |
| 49 | + ZipFile1(request.getParameter("zipFileName")); |
| 50 | + } catch (DataFormatException e) { |
| 51 | + throw new RuntimeException(e); |
| 52 | + } |
71 | 53 |
|
72 | | - PrintWriter out = response.getWriter(); |
73 | | - out.println("<html><body>end</body></html>"); |
74 | | - } |
| 54 | + // Zip4j |
| 55 | + zip4jZipInputStream(remoteFile.getInputStream()); |
| 56 | + zip4jZipInputStreamSafe(remoteFile.getInputStream()); |
| 57 | + // SnappyZip |
| 58 | + SnappyZipInputStream(remoteFile.getInputStream()); |
| 59 | + // apache Commons |
| 60 | + commonsCompressArchiveInputStream2(remoteFile.getInputStream()); |
| 61 | + commonsCompressorInputStream(remoteFile.getInputStream()); |
| 62 | + try { |
| 63 | + commonsCompressArchiveInputStream(remoteFile.getInputStream()); |
| 64 | + commonsCompressArchiveStreamFactory(remoteFile.getInputStream()); |
| 65 | + } catch (ArchiveException e) { |
| 66 | + throw new RuntimeException(e); |
| 67 | + } |
| 68 | + try { |
| 69 | + commonsCompressCompressorStreamFactory(remoteFile.getInputStream()); |
| 70 | + } catch (CompressorException e) { |
| 71 | + throw new RuntimeException(e); |
| 72 | + } |
75 | 73 |
|
76 | | - public void destroy() {} |
| 74 | + // FP |
| 75 | + String xmlResult = IOUtils.toString(request.getInputStream(), request.getCharacterEncoding()); |
| 76 | + byte[] inputStreamResult = request.getInputStream().readAllBytes(); |
| 77 | + |
| 78 | + PrintWriter out = response.getWriter(); |
| 79 | + out.println("<html><body>end</body></html>"); |
| 80 | + } |
| 81 | + |
| 82 | + public void destroy() { |
| 83 | + } |
77 | 84 | } |
0 commit comments