diff --git a/sigServer.java b/sigServer.java index a25995d..e8d9c82 100644 --- a/sigServer.java +++ b/sigServer.java @@ -84,71 +84,73 @@ public class sigServer { if (boundary.length()>0) { if (line.equals(boundary)) { truncateUntilBoundary=true; + System.out.println("Boundary found."); } } - } else - if (line.contains("Content-Disposition: ")||line.contains("Content-Type: ")) { - if (line.contains("filename=")) { - filename=line.substring(line.indexOf("filename=")+"filename=".length()+1); - filename = filename.substring(0,filename.length()-1); - int dotPosition=0; - if (filename.contains(".")) { - for (int i=filename.length()-1;i>=0;i--) { - if (filename.charAt(i)=='.') { - dotPosition=i; - break; + } else { + if (line.contains("Content-Disposition: ")||line.contains("Content-Type: ")) { + if (line.contains("filename=")) { + filename=line.substring(line.indexOf("filename=")+"filename=".length()+1); + filename = filename.substring(0,filename.length()-1); + int dotPosition=0; + if (filename.contains(".")) { + for (int i=filename.length()-1;i>=0;i--) { + if (filename.charAt(i)=='.') { + dotPosition=i; + break; + } } } + filename="upload"+System.nanoTime()+filename.substring(dotPosition); + System.out.println("Filename: "+filename); + } else { + System.out.println(line); } - filename="upload"+System.nanoTime()+filename.substring(dotPosition); - System.out.println("Filename: "+filename); } else { - System.out.println(line); - } - } else { - File myFile = new File(new File(sigPlace.OUTDIR,sigPlace.UPLOADSDIR),filename); - // check if file exist, otherwise create the file before writing - myFile.mkdirs(); - if (!myFile.exists()) { - myFile.createNewFile(); - } else { - myFile.delete(); - myFile.createNewFile(); - } - stream = new FileOutputStream(myFile); - char[] buffer = new char[1024]; - int count; - boolean wroteData=false; - while ((count = in.read(buffer))>0) { - //stream.write(in.read(buffer)); - //stream.write(buffer.,0,count); - String buf = new String(buffer); - byte[] data = buf.getBytes("ISO-8859-1"); - stream.write(data,0,count); - wroteData=true; - if (buf.contains(boundary)) { - System.out.println(""); - System.out.println("<...>"); - System.out.println(""); - System.out.println(new String(data,StandardCharsets.UTF_8)); - break; + File myFile = new File(new File(sigPlace.OUTDIR,sigPlace.UPLOADSDIR),filename); + // check if file exist, otherwise create the file before writing + myFile.mkdirs(); + if (!myFile.exists()) { + myFile.createNewFile(); + } else { + myFile.delete(); + myFile.createNewFile(); } - } - stream.close(); + stream = new FileOutputStream(myFile); + char[] buffer = new char[1024]; + int count; + boolean wroteData=false; + while ((count = in.read(buffer))>0) { + //stream.write(in.read(buffer)); + //stream.write(buffer.,0,count); + String buf = new String(buffer); + byte[] data = buf.getBytes("ISO-8859-1"); + stream.write(data,0,count); + wroteData=true; + if (buf.contains(boundary)) { + System.out.println(""); + System.out.println("<...>"); + System.out.println(""); + System.out.println(new String(data,StandardCharsets.UTF_8)); + break; + } + } + stream.close(); - if (!wroteData) { - System.out.println("Upload failed!"); - in.close(); - CreateRequest(client,"400","Bad Request",Paths.get(sigPlace.OUTDIR,"testfile.html")); - return; - } else { - System.out.println("Saving upload to "+sigPlace.UPLOADSDIR+" directory."); - if (filename.contains(".png")) { - ArcadeReader.submitToDatabase(Paths.get(sigPlace.OUTDIR,sigPlace.UPLOADSDIR,filename)); - System.out.println("Submitted to the database!"); + if (!wroteData) { + System.out.println("Upload failed!"); + in.close(); + CreateRequest(client,"400","Bad Request",Paths.get(sigPlace.OUTDIR,"testfile.html")); + return; + } else { + System.out.println("Saving upload to "+sigPlace.UPLOADSDIR+" directory."); + if (filename.contains(".png")) { + ArcadeReader.submitToDatabase(Paths.get(sigPlace.OUTDIR,sigPlace.UPLOADSDIR,filename)); + System.out.println("Submitted to the database!"); + } } + filename=null; } - filename=null; } } if (line.contains("Content-Length: ")) { @@ -157,8 +159,7 @@ public class sigServer { } if (line.contains("Content-Type:")) { if (line.contains("Content-Type: multipart/form-data; boundary=")) { - boundary=line.substring("Content-Type: multipart/form-data; boundary=".length()); - System.out.println("Boundary set to "+boundary); + boundary="--"+line.substring("Content-Type: multipart/form-data; boundary=".length()); } else if (line.contains("application/json")){ isApplication=true;