| 
									
										
										
										
											2022-05-02 21:03:16 -05:00
										 |  |  |         try { | 
					
						
							| 
									
										
										
										
											2022-05-03 13:45:03 +00:00
										 |  |  |             socket = new ServerSocket(sigPlace.PORT); | 
					
						
							|  |  |  |             System.out.println("Listening on port "+sigPlace.PORT+"."); | 
					
						
							| 
									
										
										
										
											2022-05-02 21:03:16 -05:00
										 |  |  |             while (true) { | 
					
						
							|  |  |  |                 try (Socket client = socket.accept()) { | 
					
						
							|  |  |  |                     System.out.println("New client connection detected: "+client.toString()); | 
					
						
							| 
									
										
										
										
											2022-08-02 13:23:51 +00:00
										 |  |  |                     InputStreamReader reader = new InputStreamReader(client.getInputStream(),"ISO-8859-1"); | 
					
						
							|  |  |  |                     BufferedReader in = new BufferedReader(reader); | 
					
						
							| 
									
										
										
										
											2022-05-06 18:16:42 +00:00
										 |  |  |                     String requestLine,line; | 
					
						
							|  |  |  |                     ZonedDateTime modifiedDate = null; | 
					
						
							| 
									
										
										
										
											2022-05-18 22:54:41 -05:00
										 |  |  |                     String boundary=null; | 
					
						
							|  |  |  |                     boolean truncateUntilBoundary=false; | 
					
						
							|  |  |  |                     String filename=null; | 
					
						
							| 
									
										
										
										
											2022-05-19 19:07:33 +00:00
										 |  |  |                     OutputStream stream = null; | 
					
						
							| 
									
										
										
										
											2022-08-02 13:23:51 +00:00
										 |  |  |                     int expectedDataLength=0; | 
					
						
							| 
									
										
										
										
											2022-05-06 18:16:42 +00:00
										 |  |  |                     requestLine=in.readLine(); //Read the first line, this should be our request. | 
					
						
							| 
									
										
										
										
											2022-08-02 13:23:51 +00:00
										 |  |  |                     //System.out.println(requestLine); | 
					
						
							| 
									
										
										
										
											2022-05-06 18:16:42 +00:00
										 |  |  |                     if (requestLine!=null) { | 
					
						
							| 
									
										
										
										
											2022-05-18 22:54:41 -05:00
										 |  |  |                         String[] splitter = requestLine.split(Pattern.quote(" ")); | 
					
						
							|  |  |  |                         boolean ISPOST = splitter[0].equals("POST"); | 
					
						
							| 
									
										
										
										
											2022-08-02 13:23:51 +00:00
										 |  |  |                         boolean isApplication=false; | 
					
						
							| 
									
										
										
										
											2022-05-18 22:54:41 -05:00
										 |  |  |                         if (splitter.length==3) { | 
					
						
							|  |  |  |                             while (in.ready()) { | 
					
						
							|  |  |  |                                 line=in.readLine(); | 
					
						
							| 
									
										
										
										
											2022-08-02 13:23:51 +00:00
										 |  |  |                                 System.out.println(line); | 
					
						
							| 
									
										
										
										
											2022-05-18 22:54:41 -05:00
										 |  |  |                                 if (ISPOST) { | 
					
						
							| 
									
										
										
										
											2022-08-02 13:23:51 +00:00
										 |  |  |                                     if (isApplication) { | 
					
						
							|  |  |  |                                         if (line.length()==0) { //Now expecting the body since the header is done. | 
					
						
							|  |  |  |                                             for (int i=0;i<expectedDataLength;i++) { | 
					
						
							|  |  |  |                                                 System.out.print((char)in.read()); | 
					
						
							|  |  |  |                                             } | 
					
						
							|  |  |  |                                             break;    | 
					
						
							|  |  |  |                                         } | 
					
						
							|  |  |  |                                     } else //File transfer? | 
					
						
							| 
									
										
										
										
											2022-05-18 22:54:41 -05:00
										 |  |  |                                     if (boundary!=null) { | 
					
						
							|  |  |  |                                         if (!truncateUntilBoundary) { | 
					
						
							|  |  |  |                                             System.out.println(line); | 
					
						
							|  |  |  |              | 
					
						
							|  |  |  |                                             if (boundary.length()>0) { | 
					
						
							|  |  |  |                                                 if (line.equals(boundary)) { |