Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 9DCE2200D50 for ; Mon, 4 Dec 2017 23:33:01 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id 9C0CF160BF9; Mon, 4 Dec 2017 22:33:01 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id E8DF8160BF7 for ; Mon, 4 Dec 2017 23:32:59 +0100 (CET) Received: (qmail 92230 invoked by uid 500); 4 Dec 2017 22:32:58 -0000 Mailing-List: contact dev-help@tomcat.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "Tomcat Developers List" Delivered-To: mailing list dev@tomcat.apache.org Received: (qmail 92220 invoked by uid 99); 4 Dec 2017 22:32:58 -0000 Received: from Unknown (HELO svn01-us-west.apache.org) (209.188.14.144) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 04 Dec 2017 22:32:58 +0000 Received: from svn01-us-west.apache.org (localhost [127.0.0.1]) by svn01-us-west.apache.org (ASF Mail Server at svn01-us-west.apache.org) with ESMTP id E44003A00E7 for ; Mon, 4 Dec 2017 22:32:56 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1817136 - in /tomcat/trunk: ./ java/org/apache/tomcat/util/http/fileupload/ java/org/apache/tomcat/util/http/fileupload/disk/ webapps/docs/ Date: Mon, 04 Dec 2017 22:32:54 -0000 To: dev@tomcat.apache.org From: markt@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20171204223256.E44003A00E7@svn01-us-west.apache.org> archived-at: Mon, 04 Dec 2017 22:33:01 -0000 Author: markt Date: Mon Dec 4 22:32:54 2017 New Revision: 1817136 URL: http://svn.apache.org/viewvc?rev=1817136&view=rev Log: Align packaged renamed FileUpload with original. Update the internal fork of Commons FileUpload to 6c00d57 (2017-11-23) Modified: tomcat/trunk/MERGE.txt tomcat/trunk/java/org/apache/tomcat/util/http/fileupload/ByteArrayOutputStream.java tomcat/trunk/java/org/apache/tomcat/util/http/fileupload/DeferredFileOutputStream.java tomcat/trunk/java/org/apache/tomcat/util/http/fileupload/FileUtils.java tomcat/trunk/java/org/apache/tomcat/util/http/fileupload/IOUtils.java tomcat/trunk/java/org/apache/tomcat/util/http/fileupload/MultipartStream.java tomcat/trunk/java/org/apache/tomcat/util/http/fileupload/ThresholdingOutputStream.java tomcat/trunk/java/org/apache/tomcat/util/http/fileupload/disk/DiskFileItem.java tomcat/trunk/java/org/apache/tomcat/util/http/fileupload/disk/DiskFileItemFactory.java tomcat/trunk/webapps/docs/changelog.xml Modified: tomcat/trunk/MERGE.txt URL: http://svn.apache.org/viewvc/tomcat/trunk/MERGE.txt?rev=1817136&r1=1817135&r2=1817136&view=diff ============================================================================== --- tomcat/trunk/MERGE.txt (original) +++ tomcat/trunk/MERGE.txt Mon Dec 4 22:32:54 2017 @@ -57,7 +57,7 @@ FileUpload Sub-tree: src/main/java/org/apache/commons/fileupload The SHA1 ID for the most recent commit to be merged to Tomcat is: -86b11bbc1437a12fa64bc1484c4edc0bdd5a0966 +6c00d575a9521c386743891fd34bc5181174cc01 Note: Tomcat's copy of fileupload also includes classes copied manually (rather than svn copied) from Commons IO. Modified: tomcat/trunk/java/org/apache/tomcat/util/http/fileupload/ByteArrayOutputStream.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/http/fileupload/ByteArrayOutputStream.java?rev=1817136&r1=1817135&r2=1817136&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/tomcat/util/http/fileupload/ByteArrayOutputStream.java (original) +++ tomcat/trunk/java/org/apache/tomcat/util/http/fileupload/ByteArrayOutputStream.java Mon Dec 4 22:32:54 2017 @@ -30,9 +30,9 @@ import java.util.List; * The data can be retrieved using toByteArray() and * toString(). *

- * Closing a ByteArrayOutputStream has no effect. The methods in + * Closing a {@code ByteArrayOutputStream} has no effect. The methods in * this class can be called after the stream has been closed without - * generating an IOException. + * generating an {@code IOException}. *

* This is an alternative implementation of the {@link java.io.ByteArrayOutputStream} * class. The original implementation only allocates 32 bytes at the beginning. @@ -45,6 +45,8 @@ import java.util.List; */ public class ByteArrayOutputStream extends OutputStream { + static final int DEFAULT_SIZE = 1024; + /** A singleton empty byte array. */ private static final byte[] EMPTY_BYTE_ARRAY = new byte[0]; @@ -64,7 +66,7 @@ public class ByteArrayOutputStream exten * initially 1024 bytes, though its size increases if necessary. */ public ByteArrayOutputStream() { - this(1024); + this(DEFAULT_SIZE); } /** @@ -74,7 +76,7 @@ public class ByteArrayOutputStream exten * @param size the initial size * @throws IllegalArgumentException if size is negative */ - public ByteArrayOutputStream(int size) { + public ByteArrayOutputStream(final int size) { if (size < 0) { throw new IllegalArgumentException( "Negative initial size: " + size); @@ -90,7 +92,7 @@ public class ByteArrayOutputStream exten * * @param newcount the size of the buffer if one is created */ - private void needNewBuffer(int newcount) { + private void needNewBuffer(final int newcount) { if (currentBufferIndex < buffers.size() - 1) { //Recycling old buffer filledBufferSum += currentBuffer.length; @@ -123,7 +125,7 @@ public class ByteArrayOutputStream exten * @param len The number of bytes to write */ @Override - public void write(byte[] b, int off, int len) { + public void write(final byte[] b, final int off, final int len) { if ((off < 0) || (off > b.length) || (len < 0) @@ -134,11 +136,11 @@ public class ByteArrayOutputStream exten return; } synchronized (this) { - int newcount = count + len; + final int newcount = count + len; int remaining = len; int inBufferPos = count - filledBufferSum; while (remaining > 0) { - int part = Math.min(remaining, currentBuffer.length - inBufferPos); + final int part = Math.min(remaining, currentBuffer.length - inBufferPos); System.arraycopy(b, off + len - remaining, currentBuffer, inBufferPos, part); remaining -= part; if (remaining > 0) { @@ -155,7 +157,7 @@ public class ByteArrayOutputStream exten * @param b the byte to write */ @Override - public synchronized void write(int b) { + public synchronized void write(final int b) { int inBufferPos = count - filledBufferSum; if (inBufferPos == currentBuffer.length) { needNewBuffer(count + 1); @@ -176,7 +178,7 @@ public class ByteArrayOutputStream exten * @throws IOException if an I/O error occurs while reading the input stream * @since 1.4 */ - public synchronized int write(InputStream in) throws IOException { + public synchronized int write(final InputStream in) throws IOException { int readCount = 0; int inBufferPos = count - filledBufferSum; int n = in.read(currentBuffer, inBufferPos, currentBuffer.length - inBufferPos); @@ -194,12 +196,12 @@ public class ByteArrayOutputStream exten } /** - * Closing a ByteArrayOutputStream has no effect. The methods in + * Closing a {@code ByteArrayOutputStream} has no effect. The methods in * this class can be called after the stream has been closed without - * generating an IOException. + * generating an {@code IOException}. * * @throws IOException never (this method should not declare this exception - * but it has to now due to backwards compatability) + * but it has to now due to backwards compatibility) */ @Override public void close() throws IOException { @@ -214,10 +216,10 @@ public class ByteArrayOutputStream exten * @throws IOException if an I/O error occurs, such as if the stream is closed * @see java.io.ByteArrayOutputStream#writeTo(OutputStream) */ - public synchronized void writeTo(OutputStream out) throws IOException { + public synchronized void writeTo(final OutputStream out) throws IOException { int remaining = count; - for (byte[] buf : buffers) { - int c = Math.min(buf.length, remaining); + for (final byte[] buf : buffers) { + final int c = Math.min(buf.length, remaining); out.write(buf, 0, c); remaining -= c; if (remaining == 0) { @@ -227,7 +229,7 @@ public class ByteArrayOutputStream exten } /** - * Gets the curent contents of this byte stream as a byte array. + * Gets the current contents of this byte stream as a byte array. * The result is independent of this stream. * * @return the current contents of this output stream, as a byte array @@ -238,10 +240,10 @@ public class ByteArrayOutputStream exten if (remaining == 0) { return EMPTY_BYTE_ARRAY; } - byte newbuf[] = new byte[remaining]; + final byte newbuf[] = new byte[remaining]; int pos = 0; - for (byte[] buf : buffers) { - int c = Math.min(buf.length, remaining); + for (final byte[] buf : buffers) { + final int c = Math.min(buf.length, remaining); System.arraycopy(buf, 0, newbuf, pos, c); pos += c; remaining -= c; @@ -251,14 +253,4 @@ public class ByteArrayOutputStream exten } return newbuf; } - - /** - * Gets the curent contents of this byte stream as a string. - * @return the contents of the byte array as a String - * @see java.io.ByteArrayOutputStream#toString() - */ - @Override - public String toString() { - return new String(toByteArray()); - } } Modified: tomcat/trunk/java/org/apache/tomcat/util/http/fileupload/DeferredFileOutputStream.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/http/fileupload/DeferredFileOutputStream.java?rev=1817136&r1=1817135&r2=1817136&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/tomcat/util/http/fileupload/DeferredFileOutputStream.java (original) +++ tomcat/trunk/java/org/apache/tomcat/util/http/fileupload/DeferredFileOutputStream.java Mon Dec 4 22:32:54 2017 @@ -36,12 +36,11 @@ import java.io.OutputStream; public class DeferredFileOutputStream extends ThresholdingOutputStream { - // ----------------------------------------------------------- Data members /** - * The output stream to which data will be written prior to the theshold + * The output stream to which data will be written prior to the threshold * being reached. */ private ByteArrayOutputStream memoryOutputStream; @@ -81,13 +80,14 @@ public class DeferredFileOutputStream /** * Constructs an instance of this class which will trigger an event at the * specified threshold, and save data to a file beyond that point. + * The initial buffer size will default to 1024 bytes which is ByteArrayOutputStream's default buffer size. * * @param threshold The number of bytes at which to trigger an event. * @param outputFile The file to which data is saved beyond the threshold. */ - public DeferredFileOutputStream(int threshold, File outputFile) + public DeferredFileOutputStream(final int threshold, final File outputFile) { - this(threshold, outputFile, null, null, null); + this(threshold, outputFile, null, null, null, ByteArrayOutputStream.DEFAULT_SIZE); } @@ -100,16 +100,18 @@ public class DeferredFileOutputStream * @param prefix Prefix to use for the temporary file. * @param suffix Suffix to use for the temporary file. * @param directory Temporary file directory. + * @param initialBufferSize The initial size of the in memory buffer. */ - private DeferredFileOutputStream(int threshold, File outputFile, String prefix, String suffix, File directory) { + private DeferredFileOutputStream(final int threshold, final File outputFile, final String prefix, + final String suffix, final File directory, final int initialBufferSize) { super(threshold); this.outputFile = outputFile; - - memoryOutputStream = new ByteArrayOutputStream(); - currentOutputStream = memoryOutputStream; this.prefix = prefix; this.suffix = suffix; this.directory = directory; + + memoryOutputStream = new ByteArrayOutputStream(initialBufferSize); + currentOutputStream = memoryOutputStream; } @@ -122,7 +124,7 @@ public class DeferredFileOutputStream * * @return The underlying output stream. * - * @exception IOException if an error occurs. + * @throws IOException if an error occurs. */ @Override protected OutputStream getStream() throws IOException @@ -137,7 +139,7 @@ public class DeferredFileOutputStream * much data is being written to keep in memory, so we elect to switch to * disk-based storage. * - * @exception IOException if an error occurs. + * @throws IOException if an error occurs. */ @Override protected void thresholdReached() throws IOException @@ -145,8 +147,14 @@ public class DeferredFileOutputStream if (prefix != null) { outputFile = File.createTempFile(prefix, suffix, directory); } - FileOutputStream fos = new FileOutputStream(outputFile); - memoryOutputStream.writeTo(fos); + FileUtils.forceMkdirParent(outputFile); + final FileOutputStream fos = new FileOutputStream(outputFile); + try { + memoryOutputStream.writeTo(fos); + } catch (final IOException e){ + fos.close(); + throw e; + } currentOutputStream = fos; memoryOutputStream = null; } @@ -209,7 +217,7 @@ public class DeferredFileOutputStream /** * Closes underlying output stream, and mark this as closed * - * @exception IOException if an error occurs. + * @throws IOException if an error occurs. */ @Override public void close() throws IOException Modified: tomcat/trunk/java/org/apache/tomcat/util/http/fileupload/FileUtils.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/http/fileupload/FileUtils.java?rev=1817136&r1=1817135&r2=1817136&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/tomcat/util/http/fileupload/FileUtils.java (original) +++ tomcat/trunk/java/org/apache/tomcat/util/http/fileupload/FileUtils.java Mon Dec 4 22:32:54 2017 @@ -38,6 +38,10 @@ import java.io.IOException; *

  • calculating a checksum * *

    + * Note that a specific charset should be specified whenever possible. + * Relying on the platform default means that the code is Locale-dependent. + * Only use the default if the files are known to always use the platform default. + *

    * Origin of code: Excalibur, Alexandria, Commons-Utils */ public class FileUtils { @@ -53,10 +57,11 @@ public class FileUtils { /** * Deletes a directory recursively. * - * @param directory directory to delete - * @throws IOException in case deletion is unsuccessful + * @param directory directory to delete + * @throws IOException in case deletion is unsuccessful + * @throws IllegalArgumentException if {@code directory} does not exist or is not a directory */ - public static void deleteDirectory(File directory) throws IOException { + public static void deleteDirectory(final File directory) throws IOException { if (!directory.exists()) { return; } @@ -66,8 +71,8 @@ public class FileUtils { } if (!directory.delete()) { - String message = - "Unable to delete directory " + directory + "."; + final String message = + "Unable to delete directory " + directory + "."; throw new IOException(message); } } @@ -76,20 +81,21 @@ public class FileUtils { * Cleans a directory without deleting it. * * @param directory directory to clean - * @throws IOException in case cleaning is unsuccessful + * @throws IOException in case cleaning is unsuccessful + * @throws IllegalArgumentException if {@code directory} does not exist or is not a directory */ - public static void cleanDirectory(File directory) throws IOException { + public static void cleanDirectory(final File directory) throws IOException { if (!directory.exists()) { - String message = directory + " does not exist"; + final String message = directory + " does not exist"; throw new IllegalArgumentException(message); } if (!directory.isDirectory()) { - String message = directory + " is not a directory"; + final String message = directory + " is not a directory"; throw new IllegalArgumentException(message); } - File[] files = directory.listFiles(); + final File[] files = directory.listFiles(); if (files == null) { // null if security restricted throw new IOException("Failed to list contents of " + directory); } @@ -116,25 +122,25 @@ public class FileUtils { *

      *
    • A directory to be deleted does not have to be empty.
    • *
    • You get exceptions when a file or directory cannot be deleted. - * (java.io.File methods returns a boolean)
    • + * (java.io.File methods returns a boolean) *
    * - * @param file file or directory to delete, must not be {@code null} - * @throws NullPointerException if the directory is {@code null} + * @param file file or directory to delete, must not be {@code null} + * @throws NullPointerException if the directory is {@code null} * @throws FileNotFoundException if the file was not found - * @throws IOException in case deletion is unsuccessful + * @throws IOException in case deletion is unsuccessful */ - public static void forceDelete(File file) throws IOException { + public static void forceDelete(final File file) throws IOException { if (file.isDirectory()) { deleteDirectory(file); } else { - boolean filePresent = file.exists(); + final boolean filePresent = file.exists(); if (!file.delete()) { - if (!filePresent){ + if (!filePresent) { throw new FileNotFoundException("File does not exist: " + file); } - String message = - "Unable to delete file: " + file; + final String message = + "Unable to delete file: " + file; throw new IOException(message); } } @@ -144,11 +150,11 @@ public class FileUtils { * Schedules a file to be deleted when JVM exits. * If file is directory delete it and all sub-directories. * - * @param file file or directory to delete, must not be {@code null} + * @param file file or directory to delete, must not be {@code null} * @throws NullPointerException if the file is {@code null} - * @throws IOException in case deletion is unsuccessful + * @throws IOException in case deletion is unsuccessful */ - public static void forceDeleteOnExit(File file) throws IOException { + public static void forceDeleteOnExit(final File file) throws IOException { if (file.isDirectory()) { deleteDirectoryOnExit(file); } else { @@ -159,11 +165,11 @@ public class FileUtils { /** * Schedules a directory recursively for deletion on JVM exit. * - * @param directory directory to delete, must not be {@code null} + * @param directory directory to delete, must not be {@code null} * @throws NullPointerException if the directory is {@code null} - * @throws IOException in case deletion is unsuccessful + * @throws IOException in case deletion is unsuccessful */ - private static void deleteDirectoryOnExit(File directory) throws IOException { + private static void deleteDirectoryOnExit(final File directory) throws IOException { if (!directory.exists()) { return; } @@ -177,11 +183,11 @@ public class FileUtils { /** * Cleans a directory without deleting it. * - * @param directory directory to clean, must not be {@code null} + * @param directory directory to clean, must not be {@code null} * @throws NullPointerException if the directory is {@code null} - * @throws IOException in case cleaning is unsuccessful + * @throws IOException in case cleaning is unsuccessful */ - private static void cleanDirectoryOnExit(File directory) throws IOException { + private static void cleanDirectoryOnExit(final File directory) throws IOException { if (!directory.exists()) { String message = directory + " does not exist"; throw new IllegalArgumentException(message); @@ -211,6 +217,57 @@ public class FileUtils { } } + /** + * Makes a directory, including any necessary but nonexistent parent + * directories. If a file already exists with specified name but it is + * not a directory then an IOException is thrown. + * If the directory cannot be created (or does not already exist) + * then an IOException is thrown. + * + * @param directory directory to create, must not be {@code null} + * @throws NullPointerException if the directory is {@code null} + * @throws IOException if the directory cannot be created or the file already exists but is not a directory + */ + public static void forceMkdir(final File directory) throws IOException { + if (directory.exists()) { + if (!directory.isDirectory()) { + final String message = + "File " + + directory + + " exists and is " + + "not a directory. Unable to create directory."; + throw new IOException(message); + } + } else { + if (!directory.mkdirs()) { + // Double-check that some other thread or process hasn't made + // the directory in the background + if (!directory.isDirectory()) { + final String message = + "Unable to create directory " + directory; + throw new IOException(message); + } + } + } + } + + /** + * Makes any necessary but nonexistent parent directories for a given File. If the parent directory cannot be + * created then an IOException is thrown. + * + * @param file file with parent to create, must not be {@code null} + * @throws NullPointerException if the file is {@code null} + * @throws IOException if the parent directory cannot be created + * @since 2.5 + */ + public static void forceMkdirParent(final File file) throws IOException { + final File parent = file.getParentFile(); + if (parent == null) { + return; + } + forceMkdir(parent); + } + /** * Determines whether the specified file is a Symbolic Link rather than an actual file. Modified: tomcat/trunk/java/org/apache/tomcat/util/http/fileupload/IOUtils.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/http/fileupload/IOUtils.java?rev=1817136&r1=1817135&r2=1817136&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/tomcat/util/http/fileupload/IOUtils.java (original) +++ tomcat/trunk/java/org/apache/tomcat/util/http/fileupload/IOUtils.java Mon Dec 4 22:32:54 2017 @@ -54,7 +54,7 @@ import java.io.OutputStream; * Origin of code: Excalibur. */ public class IOUtils { - // NOTE: This class is focussed on InputStream, OutputStream, Reader and + // NOTE: This class is focused on InputStream, OutputStream, Reader and // Writer. Each method should take at least one of these as a parameter, // or return one of them. @@ -82,7 +82,7 @@ public class IOUtils { * finally blocks. *

    * Example code: - * + *

    *
          * Closeable closeable = null;
          * try {
    @@ -95,9 +95,9 @@ public class IOUtils {
          *     IOUtils.closeQuietly(closeable);
          * }
          * 
    - * + *

    * Closing all streams: - * + *

    *
          * try {
          *     return IOUtils.copy(inputStream, outputStream);
    @@ -107,8 +107,7 @@ public class IOUtils {
          * }
          * 
    * - * @param closeable - * the objects to close, may be null or already closed + * @param closeable the objects to close, may be null or already closed * @since 2.0 */ public static void closeQuietly(final Closeable closeable) { @@ -124,7 +123,7 @@ public class IOUtils { // copy from InputStream //----------------------------------------------------------------------- /** - * Copy bytes from an InputStream to an + * Copies bytes from an InputStream to an * OutputStream. *

    * This method buffers the input internally, so there is no need to use a @@ -135,15 +134,15 @@ public class IOUtils { * number of bytes cannot be returned as an int. For large streams * use the copyLarge(InputStream, OutputStream) method. * - * @param input the InputStream to read from - * @param output the OutputStream to write to + * @param input the InputStream to read from + * @param output the OutputStream to write to * @return the number of bytes copied, or -1 if > Integer.MAX_VALUE * @throws NullPointerException if the input or output is null - * @throws IOException if an I/O error occurs + * @throws IOException if an I/O error occurs * @since 1.1 */ - public static int copy(InputStream input, OutputStream output) throws IOException { - long count = copyLarge(input, output); + public static int copy(final InputStream input, final OutputStream output) throws IOException { + final long count = copyLarge(input, output); if (count > Integer.MAX_VALUE) { return -1; } @@ -151,7 +150,7 @@ public class IOUtils { } /** - * Copy bytes from a large (over 2GB) InputStream to an + * Copies bytes from a large (over 2GB) InputStream to an * OutputStream. *

    * This method buffers the input internally, so there is no need to use a @@ -159,14 +158,14 @@ public class IOUtils { *

    * The buffer size is given by {@link #DEFAULT_BUFFER_SIZE}. * - * @param input the InputStream to read from - * @param output the OutputStream to write to + * @param input the InputStream to read from + * @param output the OutputStream to write to * @return the number of bytes copied * @throws NullPointerException if the input or output is null - * @throws IOException if an I/O error occurs + * @throws IOException if an I/O error occurs * @since 1.3 */ - public static long copyLarge(InputStream input, OutputStream output) + public static long copyLarge(final InputStream input, final OutputStream output) throws IOException { byte[] buffer = new byte[DEFAULT_BUFFER_SIZE]; @@ -193,7 +192,8 @@ public class IOUtils { * @throws IOException if a read error occurs * @since 2.2 */ - public static int read(final InputStream input, final byte[] buffer, final int offset, final int length) throws IOException { + public static int read(final InputStream input, final byte[] buffer, final int offset, final int length) + throws IOException { if (length < 0) { throw new IllegalArgumentException("Length must not be negative: " + length); } @@ -220,12 +220,13 @@ public class IOUtils { * @param offset initial offset into buffer * @param length length to read, must be >= 0 * - * @throws IOException if there is a problem reading the file + * @throws IOException if there is a problem reading the file * @throws IllegalArgumentException if length is negative - * @throws EOFException if the number of bytes read was incorrect + * @throws EOFException if the number of bytes read was incorrect * @since 2.2 */ - public static void readFully(final InputStream input, final byte[] buffer, final int offset, final int length) throws IOException { + public static void readFully(final InputStream input, final byte[] buffer, final int offset, final int length) + throws IOException { final int actual = read(input, buffer, offset, length); if (actual != length) { throw new EOFException("Length to read: " + length + " actual: " + actual); @@ -241,9 +242,9 @@ public class IOUtils { * @param input where to read input from * @param buffer destination * - * @throws IOException if there is a problem reading the file + * @throws IOException if there is a problem reading the file * @throws IllegalArgumentException if length is negative - * @throws EOFException if the number of bytes read was incorrect + * @throws EOFException if the number of bytes read was incorrect * @since 2.2 */ public static void readFully(final InputStream input, final byte[] buffer) throws IOException { Modified: tomcat/trunk/java/org/apache/tomcat/util/http/fileupload/MultipartStream.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/http/fileupload/MultipartStream.java?rev=1817136&r1=1817135&r2=1817136&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/tomcat/util/http/fileupload/MultipartStream.java (original) +++ tomcat/trunk/java/org/apache/tomcat/util/http/fileupload/MultipartStream.java Mon Dec 4 22:32:54 2017 @@ -87,6 +87,7 @@ public class MultipartStream { * {@link ProgressListener}. */ public static class ProgressNotifier { + /** * The listener to invoke. */ @@ -226,7 +227,7 @@ public class MultipartStream { private final byte[] boundary; /** - * The table for Knuth-Morris-Pratt search algorithm + * The table for Knuth-Morris-Pratt search algorithm. */ private int[] boundaryTable; @@ -302,7 +303,7 @@ public class MultipartStream { } this.input = input; - this.bufSize = Math.max(bufSize, boundaryLength*2); + this.bufSize = Math.max(bufSize, boundaryLength * 2); this.buffer = new byte[this.bufSize]; this.notifier = pNotifier; @@ -732,7 +733,6 @@ public class MultipartStream { */ public static class IllegalBoundaryException extends IOException { - /** * The UID to use when serializing this instance. */ Modified: tomcat/trunk/java/org/apache/tomcat/util/http/fileupload/ThresholdingOutputStream.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/http/fileupload/ThresholdingOutputStream.java?rev=1817136&r1=1817135&r2=1817136&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/tomcat/util/http/fileupload/ThresholdingOutputStream.java (original) +++ tomcat/trunk/java/org/apache/tomcat/util/http/fileupload/ThresholdingOutputStream.java Mon Dec 4 22:32:54 2017 @@ -68,7 +68,7 @@ public abstract class ThresholdingOutput * * @param threshold The number of bytes at which to trigger an event. */ - public ThresholdingOutputStream(int threshold) + public ThresholdingOutputStream(final int threshold) { this.threshold = threshold; } @@ -82,10 +82,10 @@ public abstract class ThresholdingOutput * * @param b The byte to be written. * - * @exception IOException if an error occurs. + * @throws IOException if an error occurs. */ @Override - public void write(int b) throws IOException + public void write(final int b) throws IOException { checkThreshold(1); getStream().write(b); @@ -99,10 +99,10 @@ public abstract class ThresholdingOutput * * @param b The array of bytes to be written. * - * @exception IOException if an error occurs. + * @throws IOException if an error occurs. */ @Override - public void write(byte b[]) throws IOException + public void write(final byte b[]) throws IOException { checkThreshold(b.length); getStream().write(b); @@ -118,10 +118,10 @@ public abstract class ThresholdingOutput * @param off The start offset in the byte array. * @param len The number of bytes to write. * - * @exception IOException if an error occurs. + * @throws IOException if an error occurs. */ @Override - public void write(byte b[], int off, int len) throws IOException + public void write(final byte b[], final int off, final int len) throws IOException { checkThreshold(len); getStream().write(b, off, len); @@ -133,7 +133,7 @@ public abstract class ThresholdingOutput * Flushes this output stream and forces any buffered output bytes to be * written out. * - * @exception IOException if an error occurs. + * @throws IOException if an error occurs. */ @Override public void flush() throws IOException @@ -146,7 +146,7 @@ public abstract class ThresholdingOutput * Closes this output stream and releases any system resources associated * with this stream. * - * @exception IOException if an error occurs. + * @throws IOException if an error occurs. */ @Override public void close() throws IOException @@ -155,7 +155,7 @@ public abstract class ThresholdingOutput { flush(); } - catch (IOException ignored) + catch (final IOException ignored) { // ignore } @@ -190,9 +190,9 @@ public abstract class ThresholdingOutput * @param count The number of bytes about to be written to the underlying * output stream. * - * @exception IOException if an error occurs. + * @throws IOException if an error occurs. */ - protected void checkThreshold(int count) throws IOException + protected void checkThreshold(final int count) throws IOException { if (!thresholdExceeded && written + count > threshold) { @@ -210,7 +210,7 @@ public abstract class ThresholdingOutput * * @return The underlying output stream. * - * @exception IOException if an error occurs. + * @throws IOException if an error occurs. */ protected abstract OutputStream getStream() throws IOException; @@ -220,7 +220,7 @@ public abstract class ThresholdingOutput * subclass should take whatever action necessary on this event. This may * include changing the underlying output stream. * - * @exception IOException if an error occurs. + * @throws IOException if an error occurs. */ protected abstract void thresholdReached() throws IOException; } Modified: tomcat/trunk/java/org/apache/tomcat/util/http/fileupload/disk/DiskFileItem.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/http/fileupload/disk/DiskFileItem.java?rev=1817136&r1=1817135&r2=1817136&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/tomcat/util/http/fileupload/disk/DiskFileItem.java (original) +++ tomcat/trunk/java/org/apache/tomcat/util/http/fileupload/disk/DiskFileItem.java Mon Dec 4 22:32:54 2017 @@ -140,6 +140,12 @@ public class DiskFileItem */ private FileItemHeaders headers; + /** + * Default content charset to be used when no explicit charset + * parameter is provided by the sender. + */ + private String defaultCharset = DEFAULT_CHARSET; + // ----------------------------------------------------------- Constructors /** @@ -335,7 +341,7 @@ public class DiskFileItem byte[] rawdata = get(); String charset = getCharSet(); if (charset == null) { - charset = DEFAULT_CHARSET; + charset = defaultCharset; } try { return new String(rawdata, charset); @@ -422,7 +428,7 @@ public class DiskFileItem public void delete() { cachedContent = null; File outputFile = getStoreLocation(); - if (outputFile != null && outputFile.exists()) { + if (outputFile != null && !isInMemory() && outputFile.exists()) { outputFile.delete(); } } @@ -535,7 +541,7 @@ public class DiskFileItem */ @Override protected void finalize() { - if (dfos == null) { + if (dfos == null || dfos.isInMemory()) { return; } File outputFile = dfos.getFile(); @@ -622,4 +628,21 @@ public class DiskFileItem headers = pHeaders; } + /** + * Returns the default charset for use when no explicit charset + * parameter is provided by the sender. + * @return the default charset + */ + public String getDefaultCharset() { + return defaultCharset; + } + + /** + * Sets the default charset for use when no explicit charset + * parameter is provided by the sender. + * @param charset the default charset + */ + public void setDefaultCharset(String charset) { + defaultCharset = charset; + } } Modified: tomcat/trunk/java/org/apache/tomcat/util/http/fileupload/disk/DiskFileItemFactory.java URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/tomcat/util/http/fileupload/disk/DiskFileItemFactory.java?rev=1817136&r1=1817135&r2=1817136&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/tomcat/util/http/fileupload/disk/DiskFileItemFactory.java (original) +++ tomcat/trunk/java/org/apache/tomcat/util/http/fileupload/disk/DiskFileItemFactory.java Mon Dec 4 22:32:54 2017 @@ -77,6 +77,12 @@ public class DiskFileItemFactory impleme */ private int sizeThreshold = DEFAULT_SIZE_THRESHOLD; + /** + * Default content charset to be used when no explicit charset + * parameter is provided by the sender. + */ + private String defaultCharset = DiskFileItem.DEFAULT_CHARSET; + // ----------------------------------------------------------- Constructors /** @@ -173,7 +179,27 @@ public class DiskFileItemFactory impleme @Override public FileItem createItem(String fieldName, String contentType, boolean isFormField, String fileName) { - return new DiskFileItem(fieldName, contentType, + DiskFileItem result = new DiskFileItem(fieldName, contentType, isFormField, fileName, sizeThreshold, repository); + result.setDefaultCharset(defaultCharset); + return result; + } + + /** + * Returns the default charset for use when no explicit charset + * parameter is provided by the sender. + * @return the default charset + */ + public String getDefaultCharset() { + return defaultCharset; + } + + /** + * Sets the default charset for use when no explicit charset + * parameter is provided by the sender. + * @param pCharset the default charset + */ + public void setDefaultCharset(String pCharset) { + defaultCharset = pCharset; } } Modified: tomcat/trunk/webapps/docs/changelog.xml URL: http://svn.apache.org/viewvc/tomcat/trunk/webapps/docs/changelog.xml?rev=1817136&r1=1817135&r2=1817136&view=diff ============================================================================== --- tomcat/trunk/webapps/docs/changelog.xml (original) +++ tomcat/trunk/webapps/docs/changelog.xml Mon Dec 4 22:32:54 2017 @@ -86,6 +86,10 @@ Update the internal fork of Commons DBCP 2 to 8a71764 (2017-10-18) to pick up some bug fixes and enhancements. (markt) + + Update the internal fork of Commons FileUpload to 6c00d57 (2017-11-23) + to pick up some code clean-up. (markt) + --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org For additional commands, e-mail: dev-help@tomcat.apache.org