mschachter 01/04/18 07:21:25 Modified: src/share/org/apache/struts/upload BufferedMultipartInputStream.java MultipartIterator.java src/upload/org/apache/struts/webapp/upload UploadAction.java Added: src/share/org/apache/struts/upload ContentLengthExceededException.java MaxLengthExceededException.java Log: - Added descriptive Exceptions to be thrown when the content lenght or maximum length is exceeded - Fixed problem with temporary files not being deleted in MultipartIterator - Fixed small bug in UploadAction where the input stream wasn't closed Revision Changes Path 1.3 +3 -6 jakarta-struts/src/share/org/apache/struts/upload/BufferedMultipartInputStream.java Index: BufferedMultipartInputStream.java =================================================================== RCS file: /home/cvs/jakarta-struts/src/share/org/apache/struts/upload/BufferedMultipartInputStream.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -r1.2 -r1.3 --- BufferedMultipartInputStream.java 2001/04/18 02:27:19 1.2 +++ BufferedMultipartInputStream.java 2001/04/18 14:21:18 1.3 @@ -82,8 +82,7 @@ this.maxSize = maxSize; if (maxSize < contentLength) { - throw new IOException("Posted Content-Length of " + contentLength + - " bytes exceeds maximum post size of " + maxSize + " bytes"); + throw new MaxLengthExceededException(maxSize); } buffer = new byte[bufferSize]; fill(); @@ -141,12 +140,10 @@ public int read() throws IOException { if (maxLengthMet) { - throw new IOException("Maximum post length of " + maxSize + " bytes " + - "has been reached"); + throw new MaxLengthExceededException(maxSize); } if (contentLengthMet) { - throw new IOException("Content-Length of " + contentLength + " bytes " + - "has been exceeded"); + throw new ContentLengthExceededException(contentLength); } if (buffer == null) { return -1; 1.12 +26 -19 jakarta-struts/src/share/org/apache/struts/upload/MultipartIterator.java Index: MultipartIterator.java =================================================================== RCS file: /home/cvs/jakarta-struts/src/share/org/apache/struts/upload/MultipartIterator.java,v retrieving revision 1.11 retrieving revision 1.12 diff -u -r1.11 -r1.12 --- MultipartIterator.java 2001/04/18 02:27:18 1.11 +++ MultipartIterator.java 2001/04/18 14:21:20 1.12 @@ -483,27 +483,34 @@ boolean cutCarriage = false; boolean cutNewline = false; - while ((bytesRead != -1) && (!equals(lineBuffer, 0, boundaryBytes.length, - boundaryBytes))) { - - if (cutCarriage) { - fos.write('\r'); - } - if (cutNewline) { - fos.write('\n'); - } - if (bytesRead > 0) { - if (lineBuffer[bytesRead-1] == '\r') { - bytesRead--; - cutCarriage = true; + try { + while ((bytesRead != -1) && (!equals(lineBuffer, 0, boundaryBytes.length, + boundaryBytes))) { + + if (cutCarriage) { + fos.write('\r'); } - else { - cutCarriage = false; + if (cutNewline) { + fos.write('\n'); } - } - cutNewline = true; - fos.write(lineBuffer, 0, bytesRead); - bytesRead = inputStream.readLine(lineBuffer, 0, MAX_LINE_SIZE); + if (bytesRead > 0) { + if (lineBuffer[bytesRead-1] == '\r') { + bytesRead--; + cutCarriage = true; + } + else { + cutCarriage = false; + } + } + cutNewline = true; + fos.write(lineBuffer, 0, bytesRead); + bytesRead = inputStream.readLine(lineBuffer, 0, MAX_LINE_SIZE); + } + } + catch (IOException ioe) { + fos.close(); + tempFile.delete(); + throw ioe; } fos.flush(); 1.1 jakarta-struts/src/share/org/apache/struts/upload/ContentLengthExceededException.java Index: ContentLengthExceededException.java =================================================================== package org.apache.struts.upload; import java.io.IOException; /** * This exception is thrown when multipart post data exceeds the value * given by the Content-Length header */ public class ContentLengthExceededException extends IOException { protected String message; public ContentLengthExceededException() { message = "The Content-Length has been exceeded for this request"; } public ContentLengthExceededException(long contentLength) { message = "The Content-Length of " + contentLength + " bytes has been " + "exceeded"; } public String getMessage() { return message; } } 1.1 jakarta-struts/src/share/org/apache/struts/upload/MaxLengthExceededException.java Index: MaxLengthExceededException.java =================================================================== package org.apache.struts.upload; import java.io.IOException; /** * This exception is thrown when multipart post data exceeds the maximum * value set */ public class MaxLengthExceededException extends IOException { protected String message; public MaxLengthExceededException() { message = "The maximum length has been exceeded for this request"; } public MaxLengthExceededException(long maxLength) { message = "The maximum length of " + maxLength + " bytes has been " + "exceeded"; } public String getMessage() { return message; } } 1.4 +6 -4 jakarta-struts/src/upload/org/apache/struts/webapp/upload/UploadAction.java Index: UploadAction.java =================================================================== RCS file: /home/cvs/jakarta-struts/src/upload/org/apache/struts/webapp/upload/UploadAction.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- UploadAction.java 2001/04/14 12:54:09 1.3 +++ UploadAction.java 2001/04/18 14:21:23 1.4 @@ -1,7 +1,7 @@ /* - * $Header: /home/cvs/jakarta-struts/src/upload/org/apache/struts/webapp/upload/UploadAction.java,v 1.3 2001/04/14 12:54:09 rleland Exp $ - * $Revision: 1.3 $ - * $Date: 2001/04/14 12:54:09 $ + * $Header: /home/cvs/jakarta-struts/src/upload/org/apache/struts/webapp/upload/UploadAction.java,v 1.4 2001/04/18 14:21:23 mschachter Exp $ + * $Revision: 1.4 $ + * $Date: 2001/04/18 14:21:23 $ * * ==================================================================== * @@ -87,7 +87,7 @@ * page to display them * * @author Mike Schachter - * @version $Revision: 1.3 $ $Date: 2001/04/14 12:54:09 $ + * @version $Revision: 1.4 $ $Date: 2001/04/18 14:21:23 $ */ @@ -155,6 +155,8 @@ bos.close(); data = "The file has been written to \"" + theForm.getFilePath() + "\""; } + //close the stream + stream.close(); } catch (FileNotFoundException fnfe) { return null;