Return-Path: Delivered-To: apmail-jakarta-commons-dev-archive@www.apache.org Received: (qmail 99188 invoked from network); 6 Aug 2006 03:15:11 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 6 Aug 2006 03:15:11 -0000 Received: (qmail 98001 invoked by uid 500); 6 Aug 2006 03:15:08 -0000 Delivered-To: apmail-jakarta-commons-dev-archive@jakarta.apache.org Received: (qmail 97908 invoked by uid 500); 6 Aug 2006 03:15:08 -0000 Mailing-List: contact commons-dev-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Help: List-Post: List-Id: "Jakarta Commons Developers List" Reply-To: "Jakarta Commons Developers List" Delivered-To: mailing list commons-dev@jakarta.apache.org Received: (qmail 97897 invoked by uid 500); 6 Aug 2006 03:15:08 -0000 Received: (qmail 97894 invoked by uid 99); 6 Aug 2006 03:15:08 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 05 Aug 2006 20:15:08 -0700 X-ASF-Spam-Status: No, hits=-9.4 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received-SPF: pass (asf.osuosl.org: local policy) Received: from [140.211.166.113] (HELO eris.apache.org) (140.211.166.113) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 05 Aug 2006 20:15:06 -0700 Received: by eris.apache.org (Postfix, from userid 65534) id 415021A981A; Sat, 5 Aug 2006 20:14:40 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r429098 - in /jakarta/commons/proper/fileupload/trunk: ./ src/java/org/apache/commons/fileupload/ src/java/org/apache/commons/fileupload/servlet/ src/test/org/apache/commons/fileupload/ xdocs/ Date: Sun, 06 Aug 2006 03:14:37 -0000 To: commons-cvs@jakarta.apache.org From: jochen@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20060806031440.415021A981A@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Author: jochen Date: Sat Aug 5 20:14:36 2006 New Revision: 429098 URL: http://svn.apache.org/viewvc?rev=429098&view=rev Log: Added the ProgressListener, which allows to implement a progress bar. PR: FILEUPLOAD-87 Added: jakarta/commons/proper/fileupload/trunk/src/java/org/apache/commons/fileupload/ProgressListener.java jakarta/commons/proper/fileupload/trunk/src/test/org/apache/commons/fileupload/FileUploadTestCase.java jakarta/commons/proper/fileupload/trunk/src/test/org/apache/commons/fileupload/ProgressListenerTest.java Modified: jakarta/commons/proper/fileupload/trunk/.classpath jakarta/commons/proper/fileupload/trunk/src/java/org/apache/commons/fileupload/FileUploadBase.java jakarta/commons/proper/fileupload/trunk/src/java/org/apache/commons/fileupload/MultipartStream.java jakarta/commons/proper/fileupload/trunk/src/java/org/apache/commons/fileupload/servlet/ServletFileUpload.java jakarta/commons/proper/fileupload/trunk/src/test/org/apache/commons/fileupload/MultipartStreamTest.java jakarta/commons/proper/fileupload/trunk/src/test/org/apache/commons/fileupload/ServletFileUploadTest.java jakarta/commons/proper/fileupload/trunk/src/test/org/apache/commons/fileupload/SizesTest.java jakarta/commons/proper/fileupload/trunk/src/test/org/apache/commons/fileupload/TestAll.java jakarta/commons/proper/fileupload/trunk/xdocs/changes.xml Modified: jakarta/commons/proper/fileupload/trunk/.classpath URL: http://svn.apache.org/viewvc/jakarta/commons/proper/fileupload/trunk/.classpath?rev=429098&r1=429097&r2=429098&view=diff ============================================================================== --- jakarta/commons/proper/fileupload/trunk/.classpath (original) +++ jakarta/commons/proper/fileupload/trunk/.classpath Sat Aug 5 20:14:36 2006 @@ -1,7 +1,7 @@ - + Modified: jakarta/commons/proper/fileupload/trunk/src/java/org/apache/commons/fileupload/FileUploadBase.java URL: http://svn.apache.org/viewvc/jakarta/commons/proper/fileupload/trunk/src/java/org/apache/commons/fileupload/FileUploadBase.java?rev=429098&r1=429097&r2=429098&view=diff ============================================================================== --- jakarta/commons/proper/fileupload/trunk/src/java/org/apache/commons/fileupload/FileUploadBase.java (original) +++ jakarta/commons/proper/fileupload/trunk/src/java/org/apache/commons/fileupload/FileUploadBase.java Sat Aug 5 20:14:36 2006 @@ -28,6 +28,8 @@ import javax.servlet.http.HttpServletRequest; import org.apache.commons.fileupload.servlet.ServletRequestContext; +import org.apache.commons.fileupload.servlet.ServletFileUpload; + /** *

High level API for processing file uploads.

@@ -94,18 +96,8 @@ * * @deprecated Use the method on ServletFileUpload instead. */ - public static final boolean isMultipartContent(HttpServletRequest req) { - if (!"post".equals(req.getMethod().toLowerCase())) { - return false; - } - String contentType = req.getContentType(); - if (contentType == null) { - return false; - } - if (contentType.toLowerCase().startsWith(MULTIPART)) { - return true; - } - return false; + public static boolean isMultipartContent(HttpServletRequest req) { + return ServletFileUpload.isMultipartContent(req); } @@ -169,6 +161,10 @@ */ private String headerEncoding; + /** + * The progress listener + */ + private ProgressListener listener; // ----------------------------------------------------- Property accessors @@ -530,6 +526,7 @@ } private final MultipartStream multi; + private final MultipartStream.ProgressNotifier notifier; private final byte[] boundary; private FileItemStreamImpl currentItem; private String currentFieldName; @@ -583,7 +580,8 @@ + "no multipart boundary was found"); } - multi = new MultipartStream(input, boundary); + notifier = new MultipartStream.ProgressNotifier(listener, ctx.getContentLength()); + multi = new MultipartStream(input, boundary, notifier); multi.setHeaderEncoding(charEncoding); skipPreamble = true; @@ -642,6 +640,7 @@ currentItem = new FileItemStreamImpl(fileName, fieldName, getHeader(headers, CONTENT_TYPE), fileName == null); + notifier.noteItem(); itemValid = true; return true; } @@ -652,6 +651,7 @@ currentItem = new FileItemStreamImpl(fileName, currentFieldName, getHeader(headers, CONTENT_TYPE), false); + notifier.noteItem(); itemValid = true; return true; } @@ -865,5 +865,19 @@ return permitted; } } + + /** + * Returns the progress listener, if any. Defaults to null. + */ + public ProgressListener getProgressListener() { + return listener; + } + + /** + * Sets the progress listener, if any. Defaults to null. + */ + public void setProgressListener(ProgressListener pListener) { + listener = pListener; + } } Modified: jakarta/commons/proper/fileupload/trunk/src/java/org/apache/commons/fileupload/MultipartStream.java URL: http://svn.apache.org/viewvc/jakarta/commons/proper/fileupload/trunk/src/java/org/apache/commons/fileupload/MultipartStream.java?rev=429098&r1=429097&r2=429098&view=diff ============================================================================== --- jakarta/commons/proper/fileupload/trunk/src/java/org/apache/commons/fileupload/MultipartStream.java (original) +++ jakarta/commons/proper/fileupload/trunk/src/java/org/apache/commons/fileupload/MultipartStream.java Sat Aug 5 20:14:36 2006 @@ -82,8 +82,33 @@ * * @version $Id$ */ -public class MultipartStream { - +class MultipartStream { + static class ProgressNotifier { + private final ProgressListener listener; + private final long contentLength; + private long bytesRead; + private int items; + ProgressNotifier(ProgressListener pListener, long pContentLength) { + listener = pListener; + contentLength = pContentLength; + } + void noteBytesRead(int pBytes) { + /* Indicates, that the given number of bytes have been read from + * the input stream. + */ + bytesRead += pBytes; + notifyListener(); + } + void noteItem() { + ++items; + } + private void notifyListener() { + if (listener != null) { + listener.update(bytesRead, contentLength, items); + } + } + } + // ----------------------------------------------------- Manifest constants @@ -162,7 +187,7 @@ /** * The input stream from which data is read. */ - private InputStream input; + private final InputStream input; /** @@ -187,13 +212,13 @@ /** * The length of the buffer used for processing the request. */ - private int bufSize; + private final int bufSize; /** * The buffer used for processing the request. */ - private byte[] buffer; + private final byte[] buffer; /** @@ -217,19 +242,13 @@ */ private String headerEncoding; - - // ----------------------------------------------------------- Constructors - - + /** - * Default constructor. - * - * @see #MultipartStream(InputStream, byte[], int) - * @see #MultipartStream(InputStream, byte[]) - * + * The progress notifier, if any, or null. */ - public MultipartStream() { - } + private final ProgressNotifier notifier; + + // ----------------------------------------------------------- Constructors /** @@ -246,16 +265,16 @@ * @param bufSize The size of the buffer to be used, in bytes. * * - * @see #MultipartStream() - * @see #MultipartStream(InputStream, byte[]) - * + * @see #MultipartStream(InputStream, byte[], ProgressNotifier) */ public MultipartStream(InputStream input, byte[] boundary, - int bufSize) { + int bufSize, + ProgressNotifier pNotifier) { this.input = input; this.bufSize = bufSize; this.buffer = new byte[bufSize]; + this.notifier = pNotifier; // We prepend CR/LF to the boundary to chop trailng CR/LF from // body-data tokens. @@ -281,14 +300,13 @@ * * @throws IOException when an error occurs. * - * @see #MultipartStream() - * @see #MultipartStream(InputStream, byte[], int) - * + * @see #MultipartStream(InputStream, byte[], int, ProgressNotifier) */ public MultipartStream(InputStream input, - byte[] boundary) + byte[] boundary, + ProgressNotifier pNotifier) throws IOException { - this(input, boundary, DEFAULT_BUFSIZE); + this(input, boundary, DEFAULT_BUFSIZE, pNotifier); } @@ -338,6 +356,8 @@ if (tail == -1) { // No more data available. throw new IOException("No more data is available"); + } else { + notifier.noteBytesRead(tail); } } return buffer[head++]; @@ -482,7 +502,7 @@ * *

Arbitrary large amounts of data can be processed by this * method using a constant size buffer. (see {@link - * #MultipartStream(InputStream,byte[],int) constructor}). + * #MultipartStream(InputStream,byte[],int, ProgressNotifier) constructor}). * * @param output The Stream to write data into. May * be null, in which case this method is equivalent @@ -632,20 +652,6 @@ } /** - * Returns a string representation of this object. - * - * @return The string representation of this object. - */ - public String toString() { - StringBuffer sbTemp = new StringBuffer(); - sbTemp.append("boundary='"); - sbTemp.append(String.valueOf(boundary)); - sbTemp.append("'\nbufSize="); - sbTemp.append(bufSize); - return sbTemp.toString(); - } - - /** * Thrown to indicate that the input stream fails to follow the * required syntax. */ @@ -819,6 +825,8 @@ // condition. throw new MalformedStreamException( "Stream ended unexpectedly"); + } else { + notifier.noteBytesRead(bytesRead); } tail = pad + bytesRead; findSeparator(); Added: jakarta/commons/proper/fileupload/trunk/src/java/org/apache/commons/fileupload/ProgressListener.java URL: http://svn.apache.org/viewvc/jakarta/commons/proper/fileupload/trunk/src/java/org/apache/commons/fileupload/ProgressListener.java?rev=429098&view=auto ============================================================================== --- jakarta/commons/proper/fileupload/trunk/src/java/org/apache/commons/fileupload/ProgressListener.java (added) +++ jakarta/commons/proper/fileupload/trunk/src/java/org/apache/commons/fileupload/ProgressListener.java Sat Aug 5 20:14:36 2006 @@ -0,0 +1,33 @@ +/* + * Copyright 2001-2004 The Apache Software Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.commons.fileupload; + + +/** + * The {@link ProgressListener} may be used to display a progress bar + * or do stuff like that. + */ +public interface ProgressListener { + /** Updates the listeners status information. + * @param pBytesRead The total number of bytes, which have been read + * so far. + * @param pContentLength The total number of bytes, which are being + * read. May be -1, if this number is unknown. + * @param pItems The number of the field, which is currently being + * read. (0 = no item so far, 1 = first item is being read, ...) + */ + void update(long pBytesRead, long pContentLength, int pItems); +} Modified: jakarta/commons/proper/fileupload/trunk/src/java/org/apache/commons/fileupload/servlet/ServletFileUpload.java URL: http://svn.apache.org/viewvc/jakarta/commons/proper/fileupload/trunk/src/java/org/apache/commons/fileupload/servlet/ServletFileUpload.java?rev=429098&r1=429097&r2=429098&view=diff ============================================================================== --- jakarta/commons/proper/fileupload/trunk/src/java/org/apache/commons/fileupload/servlet/ServletFileUpload.java (original) +++ jakarta/commons/proper/fileupload/trunk/src/java/org/apache/commons/fileupload/servlet/ServletFileUpload.java Sat Aug 5 20:14:36 2006 @@ -56,21 +56,25 @@ * Utility method that determines whether the request contains multipart * content. * - * @param req The servlet request to be evaluated. Must be non-null. + * @param request The servlet request to be evaluated. Must be non-null. * * @return true if the request is multipart; * false otherwise. */ - //NOTE: This method cannot be enabled until the one in FileUploadBase is - // removed, since it is not possible to override a static method. - //public static final boolean isMultipartContent( - // HttpServletRequest request) { - // if (!"post".equals(request.getMethod().toLowerCase())) { - // return false; - // } - // return FileUploadBase.isMultipartContent( - // new ServletRequestContext(request)); - //} + public static final boolean isMultipartContent( + HttpServletRequest request) { + if (!"post".equals(request.getMethod().toLowerCase())) { + return false; + } + String contentType = request.getContentType(); + if (contentType == null) { + return false; + } + if (contentType.toLowerCase().startsWith(MULTIPART)) { + return true; + } + return false; + } // ----------------------------------------------------------- Constructors Added: jakarta/commons/proper/fileupload/trunk/src/test/org/apache/commons/fileupload/FileUploadTestCase.java URL: http://svn.apache.org/viewvc/jakarta/commons/proper/fileupload/trunk/src/test/org/apache/commons/fileupload/FileUploadTestCase.java?rev=429098&view=auto ============================================================================== --- jakarta/commons/proper/fileupload/trunk/src/test/org/apache/commons/fileupload/FileUploadTestCase.java (added) +++ jakarta/commons/proper/fileupload/trunk/src/test/org/apache/commons/fileupload/FileUploadTestCase.java Sat Aug 5 20:14:36 2006 @@ -0,0 +1,37 @@ +package org.apache.commons.fileupload; + +import java.io.UnsupportedEncodingException; +import java.util.List; + +import javax.servlet.http.HttpServletRequest; + +import org.apache.commons.fileupload.disk.DiskFileItemFactory; +import org.apache.commons.fileupload.servlet.ServletFileUpload; + +import junit.framework.TestCase; + + +/** + * Base class for deriving test cases. + */ +public abstract class FileUploadTestCase extends TestCase { + protected List parseUpload(byte[] bytes) throws FileUploadException { + String contentType = "multipart/form-data; boundary=---1234"; + return parseUpload(bytes, contentType); + } + + protected List parseUpload(byte[] bytes, String contentType) throws FileUploadException { + ServletFileUpload upload = new ServletFileUpload(new DiskFileItemFactory()); + HttpServletRequest request = new MockHttpServletRequest(bytes, contentType); + + List fileItems = upload.parseRequest(request); + return fileItems; + } + + protected List parseUpload(String content) + throws UnsupportedEncodingException, FileUploadException + { + byte[] bytes = content.getBytes("US-ASCII"); + return parseUpload(bytes, "multipart/form-data; boundary=---1234"); + } +} Modified: jakarta/commons/proper/fileupload/trunk/src/test/org/apache/commons/fileupload/MultipartStreamTest.java URL: http://svn.apache.org/viewvc/jakarta/commons/proper/fileupload/trunk/src/test/org/apache/commons/fileupload/MultipartStreamTest.java?rev=429098&r1=429097&r2=429098&view=diff ============================================================================== --- jakarta/commons/proper/fileupload/trunk/src/test/org/apache/commons/fileupload/MultipartStreamTest.java (original) +++ jakarta/commons/proper/fileupload/trunk/src/test/org/apache/commons/fileupload/MultipartStreamTest.java Sat Aug 5 20:14:36 2006 @@ -30,33 +30,27 @@ { static private final String BOUNDARY_TEXT = "myboundary"; - public void testDefaultConstructor() throws Exception { - MultipartStream ms = new MultipartStream(); - // todo - ms.setBoundary(BOUNDARY_TEXT.getBytes()); - } - public void testThreeParamConstructor() throws Exception { final String strData = "foobar"; - InputStream input = new ByteArrayInputStream(strData.getBytes()); + final byte[] contents = strData.getBytes(); + InputStream input = new ByteArrayInputStream(contents); byte[] boundary = BOUNDARY_TEXT.getBytes(); int iBufSize = boundary.length; MultipartStream ms = new MultipartStream( input, boundary, - iBufSize); + iBufSize, + new MultipartStream.ProgressNotifier(null, contents.length)); } public void testTwoParamConstructor() throws Exception { final String strData = "foobar"; - InputStream input = new ByteArrayInputStream(strData.getBytes()); + final byte[] contents = strData.getBytes(); + InputStream input = new ByteArrayInputStream(contents); byte[] boundary = BOUNDARY_TEXT.getBytes(); MultipartStream ms = new MultipartStream( input, - boundary); - } - - public void testToString() { - MultipartStream ms = new MultipartStream(); - assertNotNull(ms.toString()); + boundary, + new MultipartStream.ProgressNotifier(null, contents.length)); } } Added: jakarta/commons/proper/fileupload/trunk/src/test/org/apache/commons/fileupload/ProgressListenerTest.java URL: http://svn.apache.org/viewvc/jakarta/commons/proper/fileupload/trunk/src/test/org/apache/commons/fileupload/ProgressListenerTest.java?rev=429098&view=auto ============================================================================== --- jakarta/commons/proper/fileupload/trunk/src/test/org/apache/commons/fileupload/ProgressListenerTest.java (added) +++ jakarta/commons/proper/fileupload/trunk/src/test/org/apache/commons/fileupload/ProgressListenerTest.java Sat Aug 5 20:14:36 2006 @@ -0,0 +1,84 @@ +package org.apache.commons.fileupload; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; + +import org.apache.commons.fileupload.ProgressListener; +import org.apache.commons.fileupload.servlet.ServletFileUpload; + + +/** Tests the progress listener. + */ +public class ProgressListenerTest extends FileUploadTestCase { + private class ProgressListenerImpl implements ProgressListener { + private final long expectedContentLength; + private final int expectedItems; + private Long bytesRead; + private Integer items; + ProgressListenerImpl(long pContentLength, int pItems) { + expectedContentLength = pContentLength; + expectedItems = pItems; + } + public void update(long pBytesRead, long pContentLength, int pItems) { + assertTrue(pBytesRead >= 0 && pBytesRead <= expectedContentLength); + assertTrue(pContentLength == -1 || pContentLength == expectedContentLength); + assertTrue(pItems >= 0 && pItems <= expectedItems); + + assertTrue(bytesRead == null || pBytesRead >= bytesRead.longValue()); + bytesRead = new Long(pBytesRead); + assertTrue(items == null || pItems >= items.intValue()); + items = new Integer(pItems); + } + void checkFinished(){ + assertEquals(expectedContentLength, bytesRead.longValue()); + assertEquals(expectedItems, items.intValue()); + } + } + + /** + * Parse a very long file upload by using a progress listener. + */ + public void testProgressListener() throws Exception { + final int NUM_ITEMS = 512; + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + for (int i = 0; i < NUM_ITEMS; i++) { + String header = "-----1234\r\n" + + "Content-Disposition: form-data; name=\"field" + (i+1) + "\"\r\n" + + "\r\n"; + baos.write(header.getBytes("US-ASCII")); + for (int j = 0; j < 16384+i; j++) { + baos.write((byte) j); + } + baos.write("\r\n".getBytes("US-ASCII")); + } + baos.write("-----1234--\r\n".getBytes("US-ASCII")); + byte[] contents = baos.toByteArray(); + + MockHttpServletRequest request = new MockHttpServletRequest(contents, "multipart/form-data; boundary=---1234"); + runTest(NUM_ITEMS, contents.length, request); + request = new MockHttpServletRequest(contents, "multipart/form-data; boundary=---1234"){ + public int getContentLength() { + return -1; + } + }; + runTest(NUM_ITEMS, contents.length, request); + } + + private void runTest(final int NUM_ITEMS, long pContentLength, MockHttpServletRequest request) throws FileUploadException, IOException { + ServletFileUpload upload = new ServletFileUpload(); + ProgressListenerImpl listener = new ProgressListenerImpl(pContentLength, NUM_ITEMS); + upload.setProgressListener(listener); + FileItemIterator iter = upload.getItemIterator(request); + for (int i = 0; i < NUM_ITEMS; i++) { + FileItemStream stream = iter.next(); + InputStream istream = stream.openStream(); + for (int j = 0; j < 16384+i; j++) { + assertEquals((byte) j, (byte) istream.read()); + } + assertEquals(-1, istream.read()); + } + assertTrue(!iter.hasNext()); + listener.checkFinished(); + } +} Modified: jakarta/commons/proper/fileupload/trunk/src/test/org/apache/commons/fileupload/ServletFileUploadTest.java URL: http://svn.apache.org/viewvc/jakarta/commons/proper/fileupload/trunk/src/test/org/apache/commons/fileupload/ServletFileUploadTest.java?rev=429098&r1=429097&r2=429098&view=diff ============================================================================== --- jakarta/commons/proper/fileupload/trunk/src/test/org/apache/commons/fileupload/ServletFileUploadTest.java (original) +++ jakarta/commons/proper/fileupload/trunk/src/test/org/apache/commons/fileupload/ServletFileUploadTest.java Sat Aug 5 20:14:36 2006 @@ -18,8 +18,8 @@ import java.io.IOException; import java.io.UnsupportedEncodingException; import java.util.List; + import javax.servlet.http.HttpServletRequest; -import junit.framework.TestCase; /** * Unit tests {@link org.apache.commons.fileupload.DiskFileUpload}. @@ -28,7 +28,7 @@ * @author Sean C. Sullivan * */ -public class ServletFileUploadTest extends TestCase +public class ServletFileUploadTest extends FileUploadTestCase { public void testWithInvalidRequest() { @@ -207,18 +207,46 @@ assertEquals("fieldValue2", field2.getString()); } - private List parseUpload(String content) - throws UnsupportedEncodingException, FileUploadException - { - byte[] bytes = content.getBytes("US-ASCII"); - - String contentType = "multipart/form-data; boundary=---1234"; - - FileUploadBase upload = new DiskFileUpload(); - HttpServletRequest request = new MockHttpServletRequest(bytes, contentType); - - List fileItems = upload.parseRequest(request); - return fileItems; + /** + * Test for FILEUPLOAD + */ + public void testFILEUPLOAD62() throws Exception { + final String contentType = "multipart/form-data; boundary=AaB03x"; + final String request = + "--AaB03x\r\n" + + "content-disposition: form-data; name=\"field1\"\r\n" + + "\r\n" + + "Joe Blow\r\n" + + "--AaB03x\r\n" + + "content-disposition: form-data; name=\"pics\"\r\n" + + "Content-type: multipart/mixed; boundary=BbC04y\r\n" + + "\r\n" + + "--BbC04y\r\n" + + "Content-disposition: attachment; filename=\"file1.txt\"\r\n" + + "Content-Type: text/plain\r\n" + + "\r\n" + + "... contents of file1.txt ...\r\n" + + "--BbC04y\r\n" + + "Content-disposition: attachment; filename=\"file2.gif\"\r\n" + + "Content-type: image/gif\r\n" + + "Content-Transfer-Encoding: binary\r\n" + + "\r\n" + + "...contents of file2.gif...\r\n" + + "--BbC04y--\r\n" + + "--AaB03x--"; + List fileItems = parseUpload(request.getBytes("US-ASCII"), contentType); + assertEquals(3, fileItems.size()); + FileItem item0 = (FileItem) fileItems.get(0); + assertEquals("field1", item0.getFieldName()); + assertNull(item0.getName()); + assertEquals("Joe Blow", new String(item0.get())); + FileItem item1 = (FileItem) fileItems.get(1); + assertEquals("pics", item1.getFieldName()); + assertEquals("file1.txt", item1.getName()); + assertEquals("... contents of file1.txt ...", new String(item1.get())); + FileItem item2 = (FileItem) fileItems.get(2); + assertEquals("pics", item2.getFieldName()); + assertEquals("file2.gif", item2.getName()); + assertEquals("...contents of file2.gif...", new String(item2.get())); } - } Modified: jakarta/commons/proper/fileupload/trunk/src/test/org/apache/commons/fileupload/SizesTest.java URL: http://svn.apache.org/viewvc/jakarta/commons/proper/fileupload/trunk/src/test/org/apache/commons/fileupload/SizesTest.java?rev=429098&r1=429097&r2=429098&view=diff ============================================================================== --- jakarta/commons/proper/fileupload/trunk/src/test/org/apache/commons/fileupload/SizesTest.java (original) +++ jakarta/commons/proper/fileupload/trunk/src/test/org/apache/commons/fileupload/SizesTest.java Sat Aug 5 20:14:36 2006 @@ -19,16 +19,21 @@ import java.io.IOException; import java.util.Iterator; import java.util.List; + import javax.servlet.http.HttpServletRequest; -import junit.framework.TestCase; + +import org.apache.commons.fileupload.disk.DiskFileItemFactory; +import org.apache.commons.fileupload.servlet.ServletFileUpload; /** * Unit test for items with varying sizes. */ -public class SizesTest extends TestCase +public class SizesTest extends FileUploadTestCase { - public void testFileUpload() + /** Runs a test with varying file sizes. + */ + public void testFileUpload() throws IOException, FileUploadException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); @@ -67,15 +72,4 @@ } assertTrue(!fileIter.hasNext()); } - - private List parseUpload(byte[] bytes) throws FileUploadException { - String contentType = "multipart/form-data; boundary=---1234"; - - FileUploadBase upload = new DiskFileUpload(); - HttpServletRequest request = new MockHttpServletRequest(bytes, contentType); - - List fileItems = upload.parseRequest(request); - return fileItems; - } - } Modified: jakarta/commons/proper/fileupload/trunk/src/test/org/apache/commons/fileupload/TestAll.java URL: http://svn.apache.org/viewvc/jakarta/commons/proper/fileupload/trunk/src/test/org/apache/commons/fileupload/TestAll.java?rev=429098&r1=429097&r2=429098&view=diff ============================================================================== --- jakarta/commons/proper/fileupload/trunk/src/test/org/apache/commons/fileupload/TestAll.java (original) +++ jakarta/commons/proper/fileupload/trunk/src/test/org/apache/commons/fileupload/TestAll.java Sat Aug 5 20:14:36 2006 @@ -41,6 +41,7 @@ suite.addTest(new TestSuite(MultipartStreamTest.class)); suite.addTest(new TestSuite(ServletFileUploadTest.class)); suite.addTest(new TestSuite(StreamingTest.class)); + suite.addTest(new TestSuite(ProgressListenerTest.class)); return suite; } Modified: jakarta/commons/proper/fileupload/trunk/xdocs/changes.xml URL: http://svn.apache.org/viewvc/jakarta/commons/proper/fileupload/trunk/xdocs/changes.xml?rev=429098&r1=429097&r2=429098&view=diff ============================================================================== --- jakarta/commons/proper/fileupload/trunk/xdocs/changes.xml (original) +++ jakarta/commons/proper/fileupload/trunk/xdocs/changes.xml Sat Aug 5 20:14:36 2006 @@ -60,6 +60,12 @@ header line. (The total size of all headers is already limited, so there's no need for another limit.) + + + Added the ProgressListener, which allows to implement a + progress bar. + + --------------------------------------------------------------------- To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org For additional commands, e-mail: commons-dev-help@jakarta.apache.org