You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2016/08/22 15:38:49 UTC

svn commit: r1757214 [2/2] - in /tomcat/tc7.0.x/trunk: ./ java/org/apache/tomcat/util/http/fileupload/ java/org/apache/tomcat/util/http/fileupload/disk/ java/org/apache/tomcat/util/http/fileupload/util/ java/org/apache/tomcat/util/http/fileupload/util/...

Modified: tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/http/fileupload/ParameterParser.java
URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/http/fileupload/ParameterParser.java?rev=1757214&r1=1757213&r2=1757214&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/http/fileupload/ParameterParser.java (original)
+++ tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/http/fileupload/ParameterParser.java Mon Aug 22 15:38:48 2016
@@ -127,8 +127,8 @@ public class ParameterParser {
      */
     private boolean isOneOf(char ch, final char[] charray) {
         boolean result = false;
-        for (int i = 0; i < charray.length; i++) {
-            if (ch == charray[i]) {
+        for (char element : charray) {
+            if (ch == element) {
                 result = true;
                 break;
             }
@@ -233,11 +233,11 @@ public class ParameterParser {
         char separator = separators[0];
         if (str != null) {
             int idx = str.length();
-            for (int i = 0;  i < separators.length;  i++) {
-                int tmp = str.indexOf(separators[i]);
+            for (char separator2 : separators) {
+                int tmp = str.indexOf(separator2);
                 if (tmp != -1 && tmp < idx) {
                     idx = tmp;
-                    separator = separators[i];
+                    separator = separator2;
                 }
             }
         }
@@ -264,24 +264,24 @@ public class ParameterParser {
      * Extracts a map of name/value pairs from the given array of
      * characters. Names are expected to be unique.
      *
-     * @param chars the array of characters that contains a sequence of
+     * @param charArray the array of characters that contains a sequence of
      * name/value pairs
      * @param separator the name/value pairs separator
      *
      * @return a map of name/value pairs
      */
-    public Map<String,String> parse(final char[] chars, char separator) {
-        if (chars == null) {
+    public Map<String,String> parse(final char[] charArray, char separator) {
+        if (charArray == null) {
             return new HashMap<String,String>();
         }
-        return parse(chars, 0, chars.length, separator);
+        return parse(charArray, 0, charArray.length, separator);
     }
 
     /**
      * Extracts a map of name/value pairs from the given array of
      * characters. Names are expected to be unique.
      *
-     * @param chars the array of characters that contains a sequence of
+     * @param charArray the array of characters that contains a sequence of
      * name/value pairs
      * @param offset - the initial offset.
      * @param length - the length.
@@ -290,16 +290,16 @@ public class ParameterParser {
      * @return a map of name/value pairs
      */
     public Map<String,String> parse(
-        final char[] chars,
+        final char[] charArray,
         int offset,
         int length,
         char separator) {
 
-        if (chars == null) {
+        if (charArray == null) {
             return new HashMap<String,String>();
         }
         HashMap<String,String> params = new HashMap<String,String>();
-        this.chars = chars;
+        this.chars = charArray;
         this.pos = offset;
         this.len = length;
 
@@ -309,7 +309,7 @@ public class ParameterParser {
             paramName = parseToken(new char[] {
                     '=', separator });
             paramValue = null;
-            if (hasChar() && (chars[pos] == '=')) {
+            if (hasChar() && (charArray[pos] == '=')) {
                 pos++; // skip '='
                 paramValue = parseQuotedToken(new char[] {
                         separator });
@@ -322,7 +322,7 @@ public class ParameterParser {
                     }
                 }
             }
-            if (hasChar() && (chars[pos] == separator)) {
+            if (hasChar() && (charArray[pos] == separator)) {
                 pos++; // skip separator
             }
             if ((paramName != null) && (paramName.length() > 0)) {

Modified: tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/http/fileupload/ThresholdingOutputStream.java
URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/http/fileupload/ThresholdingOutputStream.java?rev=1757214&r1=1757213&r2=1757214&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/http/fileupload/ThresholdingOutputStream.java (original)
+++ tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/http/fileupload/ThresholdingOutputStream.java Mon Aug 22 15:38:48 2016
@@ -5,9 +5,9 @@
  * The ASF licenses this file to You 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.

Modified: tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/http/fileupload/disk/DiskFileItem.java
URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/http/fileupload/disk/DiskFileItem.java?rev=1757214&r1=1757213&r2=1757214&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/http/fileupload/disk/DiskFileItem.java (original)
+++ tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/http/fileupload/disk/DiskFileItem.java Mon Aug 22 15:38:48 2016
@@ -276,12 +276,13 @@ public class DiskFileItem
      * contents of the file were not yet cached in memory, they will be
      * loaded from the disk storage and cached.
      *
-     * @return The contents of the file as an array of bytes.
+     * @return The contents of the file as an array of bytes
+     * or {@code null} if the data cannot be read
      */
     @Override
     public byte[] get() {
         if (isInMemory()) {
-            if (cachedContent == null) {
+            if (cachedContent == null && dfos != null) {
                 cachedContent = dfos.getData();
             }
             return cachedContent;
@@ -291,18 +292,12 @@ public class DiskFileItem
         InputStream fis = null;
 
         try {
-            fis = new BufferedInputStream(new FileInputStream(dfos.getFile()));
-            fis.read(fileData);
+            fis = new FileInputStream(dfos.getFile());
+            IOUtils.readFully(fis, fileData);
         } catch (IOException e) {
             fileData = null;
         } finally {
-            if (fis != null) {
-                try {
-                    fis.close();
-                } catch (IOException e) {
-                    // ignore
-                }
-            }
+            IOUtils.closeQuietly(fis);
         }
 
         return fileData;
@@ -399,21 +394,10 @@ public class DiskFileItem
                         out = new BufferedOutputStream(
                                 new FileOutputStream(file));
                         IOUtils.copy(in, out);
+                        out.close();
                     } finally {
-                        if (in != null) {
-                            try {
-                                in.close();
-                            } catch (IOException e) {
-                                // ignore
-                            }
-                        }
-                        if (out != null) {
-                            try {
-                                out.close();
-                            } catch (IOException e) {
-                                // ignore
-                            }
-                        }
+                        IOUtils.closeQuietly(in);
+                        IOUtils.closeQuietly(out);
                     }
                 }
             } else {
@@ -551,6 +535,9 @@ public class DiskFileItem
      */
     @Override
     protected void finalize() {
+        if (dfos == null) {
+            return;
+        }
         File outputFile = dfos.getFile();
 
         if (outputFile != null && outputFile.exists()) {
@@ -563,6 +550,9 @@ public class DiskFileItem
      * named temporary file in the configured repository path. The lifetime of
      * the file is tied to the lifetime of the <code>FileItem</code> instance;
      * the file will be deleted when the instance is garbage collected.
+     * <p>
+     * <b>Note: Subclasses that override this method must ensure that they return the
+     * same File each time.</b>
      *
      * @return The {@link java.io.File File} to be used for temporary storage.
      */

Modified: tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/http/fileupload/disk/DiskFileItemFactory.java
URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/http/fileupload/disk/DiskFileItemFactory.java?rev=1757214&r1=1757213&r2=1757214&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/http/fileupload/disk/DiskFileItemFactory.java (original)
+++ tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/http/fileupload/disk/DiskFileItemFactory.java Mon Aug 22 15:38:48 2016
@@ -18,7 +18,6 @@ package org.apache.tomcat.util.http.file
 
 import java.io.File;
 
-import org.apache.tomcat.util.http.fileupload.FileCleaningTracker;
 import org.apache.tomcat.util.http.fileupload.FileItem;
 import org.apache.tomcat.util.http.fileupload.FileItemFactory;
 
@@ -78,13 +77,6 @@ public class DiskFileItemFactory impleme
      */
     private int sizeThreshold = DEFAULT_SIZE_THRESHOLD;
 
-    /**
-     * <p>The instance of {@link FileCleaningTracker}, which is responsible
-     * for deleting temporary files.</p>
-     * <p>May be null, if tracking files is not required.</p>
-     */
-    private FileCleaningTracker fileCleaningTracker;
-
     // ----------------------------------------------------------- Constructors
 
     /**
@@ -181,36 +173,7 @@ public class DiskFileItemFactory impleme
     @Override
     public FileItem createItem(String fieldName, String contentType,
             boolean isFormField, String fileName) {
-        DiskFileItem result = new DiskFileItem(fieldName, contentType,
+        return new DiskFileItem(fieldName, contentType,
                 isFormField, fileName, sizeThreshold, repository);
-        FileCleaningTracker tracker = getFileCleaningTracker();
-        if (tracker != null) {
-            tracker.track(result.getTempFile(), result);
-        }
-        return result;
-    }
-
-    /**
-     * Returns the tracker, which is responsible for deleting temporary
-     * files.
-     *
-     * @return An instance of {@link FileCleaningTracker}, or null
-     *   (default), if temporary files aren't tracked.
-     */
-    public FileCleaningTracker getFileCleaningTracker() {
-        return fileCleaningTracker;
     }
-
-    /**
-     * Sets the tracker, which is responsible for deleting temporary
-     * files.
-     *
-     * @param pTracker An instance of {@link FileCleaningTracker},
-     *   which will from now on track the created files, or null
-     *   (default), to disable tracking.
-     */
-    public void setFileCleaningTracker(FileCleaningTracker pTracker) {
-        fileCleaningTracker = pTracker;
-    }
-
 }

Modified: tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/http/fileupload/util/LimitedInputStream.java
URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/http/fileupload/util/LimitedInputStream.java?rev=1757214&r1=1757213&r2=1757214&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/http/fileupload/util/LimitedInputStream.java (original)
+++ tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/http/fileupload/util/LimitedInputStream.java Mon Aug 22 15:38:48 2016
@@ -44,12 +44,12 @@ public abstract class LimitedInputStream
     /**
      * Creates a new instance.
      *
-     * @param pIn The input stream, which shall be limited.
+     * @param inputStream The input stream, which shall be limited.
      * @param pSizeMax The limit; no more than this number of bytes
      *   shall be returned by the source stream.
      */
-    public LimitedInputStream(InputStream pIn, long pSizeMax) {
-        super(pIn);
+    public LimitedInputStream(InputStream inputStream, long pSizeMax) {
+        super(inputStream);
         sizeMax = pSizeMax;
     }
 
@@ -91,7 +91,7 @@ public abstract class LimitedInputStream
      *
      * @return     the next byte of data, or <code>-1</code> if the end of the
      *             stream is reached.
-     * @exception  IOException  if an I/O error occurs.
+     * @throws  IOException  if an I/O error occurs.
      * @see        java.io.FilterInputStream#in
      */
     @Override
@@ -120,11 +120,11 @@ public abstract class LimitedInputStream
      * @return     the total number of bytes read into the buffer, or
      *             <code>-1</code> if there is no more data because the end of
      *             the stream has been reached.
-     * @exception  NullPointerException If <code>b</code> is <code>null</code>.
-     * @exception  IndexOutOfBoundsException If <code>off</code> is negative,
+     * @throws  NullPointerException If <code>b</code> is <code>null</code>.
+     * @throws  IndexOutOfBoundsException If <code>off</code> is negative,
      * <code>len</code> is negative, or <code>len</code> is greater than
      * <code>b.length - off</code>
-     * @exception  IOException  if an I/O error occurs.
+     * @throws  IOException  if an I/O error occurs.
      * @see        java.io.FilterInputStream#in
      */
     @Override
@@ -154,7 +154,7 @@ public abstract class LimitedInputStream
      * This
      * method simply performs <code>in.close()</code>.
      *
-     * @exception  IOException  if an I/O error occurs.
+     * @throws  IOException  if an I/O error occurs.
      * @see        java.io.FilterInputStream#in
      */
     @Override

Modified: tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/http/fileupload/util/Streams.java
URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/http/fileupload/util/Streams.java?rev=1757214&r1=1757213&r2=1757214&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/http/fileupload/util/Streams.java (original)
+++ tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/http/fileupload/util/Streams.java Mon Aug 22 15:38:48 2016
@@ -21,6 +21,7 @@ import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
 
+import org.apache.tomcat.util.http.fileupload.IOUtils;
 import org.apache.tomcat.util.http.fileupload.InvalidFileNameException;
 
 /**
@@ -49,66 +50,64 @@ public final class Streams {
      *   copy(pInputStream, pOutputStream, new byte[8192]);
      * </pre>
      *
-     * @param pInputStream The input stream, which is being read.
+     * @param inputStream The input stream, which is being read.
      * It is guaranteed, that {@link InputStream#close()} is called
      * on the stream.
-     * @param pOutputStream The output stream, to which data should
+     * @param outputStream The output stream, to which data should
      * be written. May be null, in which case the input streams
      * contents are simply discarded.
-     * @param pClose True guarantees, that {@link OutputStream#close()}
+     * @param closeOutputStream True guarantees, that {@link OutputStream#close()}
      * is called on the stream. False indicates, that only
      * {@link OutputStream#flush()} should be called finally.
      *
      * @return Number of bytes, which have been copied.
      * @throws IOException An I/O error occurred.
      */
-    public static long copy(InputStream pInputStream,
-            OutputStream pOutputStream, boolean pClose)
+    public static long copy(InputStream inputStream, OutputStream outputStream, boolean closeOutputStream)
             throws IOException {
-        return copy(pInputStream, pOutputStream, pClose,
-                new byte[DEFAULT_BUFFER_SIZE]);
+        return copy(inputStream, outputStream, closeOutputStream, new byte[DEFAULT_BUFFER_SIZE]);
     }
 
     /**
      * Copies the contents of the given {@link InputStream}
      * to the given {@link OutputStream}.
      *
-     * @param pIn The input stream, which is being read.
+     * @param inputStream The input stream, which is being read.
      *   It is guaranteed, that {@link InputStream#close()} is called
      *   on the stream.
-     * @param pOut The output stream, to which data should
+     * @param outputStream The output stream, to which data should
      *   be written. May be null, in which case the input streams
      *   contents are simply discarded.
-     * @param pClose True guarantees, that {@link OutputStream#close()}
+     * @param closeOutputStream True guarantees, that {@link OutputStream#close()}
      *   is called on the stream. False indicates, that only
      *   {@link OutputStream#flush()} should be called finally.
-     * @param pBuffer Temporary buffer, which is to be used for
+     * @param buffer Temporary buffer, which is to be used for
      *   copying data.
      * @return Number of bytes, which have been copied.
      * @throws IOException An I/O error occurred.
      */
-    public static long copy(InputStream pIn,
-            OutputStream pOut, boolean pClose,
-            byte[] pBuffer)
+    public static long copy(InputStream inputStream,
+            OutputStream outputStream, boolean closeOutputStream,
+            byte[] buffer)
     throws IOException {
-        OutputStream out = pOut;
-        InputStream in = pIn;
+        OutputStream out = outputStream;
+        InputStream in = inputStream;
         try {
             long total = 0;
             for (;;) {
-                int res = in.read(pBuffer);
+                int res = in.read(buffer);
                 if (res == -1) {
                     break;
                 }
                 if (res > 0) {
                     total += res;
                     if (out != null) {
-                        out.write(pBuffer, 0, res);
+                        out.write(buffer, 0, res);
                     }
                 }
             }
             if (out != null) {
-                if (pClose) {
+                if (closeOutputStream) {
                     out.close();
                 } else {
                     out.flush();
@@ -119,19 +118,9 @@ public final class Streams {
             in = null;
             return total;
         } finally {
-            if (in != null) {
-                try {
-                    in.close();
-                } catch (IOException ioe) {
-                    /* Ignore me */
-                }
-            }
-            if (pClose  &&  out != null) {
-                try {
-                    out.close();
-                } catch (IOException ioe) {
-                    /* Ignore me */
-                }
+            IOUtils.closeQuietly(in);
+            if (closeOutputStream) {
+                IOUtils.closeQuietly(out);
             }
         }
     }
@@ -142,14 +131,14 @@ public final class Streams {
      * content into a string. The platform's default character encoding
      * is used for converting bytes into characters.
      *
-     * @param pStream The input stream to read.
+     * @param inputStream The input stream to read.
      * @see #asString(InputStream, String)
      * @return The streams contents, as a string.
      * @throws IOException An I/O error occurred.
      */
-    public static String asString(InputStream pStream) throws IOException {
+    public static String asString(InputStream inputStream) throws IOException {
         ByteArrayOutputStream baos = new ByteArrayOutputStream();
-        copy(pStream, baos, true);
+        copy(inputStream, baos, true);
         return baos.toString();
     }
 
@@ -158,17 +147,16 @@ public final class Streams {
      * {@link org.apache.tomcat.util.http.fileupload.FileItemStream}'s
      * content into a string, using the given character encoding.
      *
-     * @param pStream The input stream to read.
-     * @param pEncoding The character encoding, typically "UTF-8".
+     * @param inputStream The input stream to read.
+     * @param encoding The character encoding, typically "UTF-8".
      * @see #asString(InputStream)
      * @return The streams contents, as a string.
      * @throws IOException An I/O error occurred.
      */
-    public static String asString(InputStream pStream, String pEncoding)
-            throws IOException {
+    public static String asString(InputStream inputStream, String encoding) throws IOException {
         ByteArrayOutputStream baos = new ByteArrayOutputStream();
-        copy(pStream, baos, true);
-        return baos.toString(pEncoding);
+        copy(inputStream, baos, true);
+        return baos.toString(encoding);
     }
 
     /**
@@ -177,16 +165,16 @@ public final class Streams {
      * is valid, it will be returned without any modifications. Otherwise,
      * an {@link InvalidFileNameException} is raised.
      *
-     * @param pFileName The file name to check
+     * @param fileName The file name to check
      * @return Unmodified file name, if valid.
      * @throws InvalidFileNameException The file name was found to be invalid.
      */
-    public static String checkFileName(String pFileName) {
-        if (pFileName != null  &&  pFileName.indexOf('\u0000') != -1) {
+    public static String checkFileName(String fileName) {
+        if (fileName != null  &&  fileName.indexOf('\u0000') != -1) {
             // pFileName.replace("\u0000", "\\0")
             final StringBuilder sb = new StringBuilder();
-            for (int i = 0;  i < pFileName.length();  i++) {
-                char c = pFileName.charAt(i);
+            for (int i = 0;  i < fileName.length();  i++) {
+                char c = fileName.charAt(i);
                 switch (c) {
                     case 0:
                         sb.append("\\0");
@@ -196,10 +184,10 @@ public final class Streams {
                         break;
                 }
             }
-            throw new InvalidFileNameException(pFileName,
+            throw new InvalidFileNameException(fileName,
                     "Invalid file name: " + sb);
         }
-        return pFileName;
+        return fileName;
     }
 
 }

Modified: tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/http/fileupload/util/mime/QuotedPrintableDecoder.java
URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/http/fileupload/util/mime/QuotedPrintableDecoder.java?rev=1757214&r1=1757213&r2=1757214&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/http/fileupload/util/mime/QuotedPrintableDecoder.java (original)
+++ tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/http/fileupload/util/mime/QuotedPrintableDecoder.java Mon Aug 22 15:38:48 2016
@@ -44,7 +44,8 @@ final class QuotedPrintableDecoder {
      * @param out    The output stream used to return the decoded data.
      *
      * @return the number of bytes produced.
-     * @exception IOException
+     * @throws IOException if a problem occurs during either decoding or
+     *            writing to the stream
      */
     public static int decode(byte[] data, OutputStream out) throws IOException {
         int off = 0;

Modified: tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml
URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml?rev=1757214&r1=1757213&r2=1757214&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml (original)
+++ tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml Mon Aug 22 15:38:48 2016
@@ -277,6 +277,11 @@
         Update the internal fork of Commons Codec to r1757174. Code formatting
         changes only. (markt)
       </update>
+      <update>
+        Update the internal fork of Commons FileUpload to afdedc9. This pulls in
+        a fix to improve the performance with large multipart boundaries.
+        (markt)
+      </update>
     </changelog>
   </subsection>
 </section>



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org