Author: markt
Date: Fri Mar 15 14:37:04 2013
New Revision: 1456969
URL: http://svn.apache.org/r1456969
Log:
Update to Commons IO 2.4 and run UCDetector over the copied classes
Modified:
tomcat/tc7.0.x/trunk/ (props changed)
tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/http/fileupload/ (props
changed)
tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/http/fileupload/ByteArrayOutputStream.java
tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/http/fileupload/DeferredFileOutputStream.java
tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/http/fileupload/FileCleaningTracker.java
tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/http/fileupload/FileDeleteStrategy.java
tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/http/fileupload/FileUtils.java
tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/http/fileupload/IOUtils.java
tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/http/fileupload/ThresholdingOutputStream.java
tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml
Propchange: tomcat/tc7.0.x/trunk/
------------------------------------------------------------------------------
Merged /tomcat/trunk:r1456963
Propchange: tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/http/fileupload/
------------------------------------------------------------------------------
Merged /tomcat/trunk/java/org/apache/tomcat/util/http/fileupload:r1456963
Modified:
tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/http/fileupload/ByteArrayOutputStream.java
URL:
http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/http/fileupload/ByteArrayOutputStream.java?rev=1456969&r1=1456968&r2=1456969&view=diff
==============================================================================
---
tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/http/fileupload/ByteArrayOutputStream.java
(original)
+++
tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/http/fileupload/ByteArrayOutputStream.java
Fri Mar 15 14:37:04 2013
@@ -19,7 +19,6 @@ package org.apache.tomcat.util.http.file
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
-import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.List;
@@ -35,7 +34,7 @@ import java.util.List;
* this class can be called after the stream has been closed without
* generating an <tt>IOException</tt>.
* <p>
- * This is an alternative implementation of the java.io.ByteArrayOutputStream
+ * This is an alternative implementation of the {@link
java.io.ByteArrayOutputStream}
* class. The original implementation only allocates 32 bytes at the beginning.
* As this class is designed for heavy duty it starts at 1024 bytes. In
contrast
* to the original it doesn't reallocate the whole memory block but allocates
@@ -44,8 +43,6 @@ import java.util.List;
* designed to behave exactly like the original. The only exception is the
* deprecated toString(int) method that has been ignored.
*
- * @author <a href="mailto:[email protected]">Jeremias Maerki</a>
- * @author Holger Hoffstatte
* @version $Id$
*/
public class ByteArrayOutputStream extends OutputStream {
@@ -54,7 +51,7 @@ public class ByteArrayOutputStream exten
private static final byte[] EMPTY_BYTE_ARRAY = new byte[0];
/** The list of buffers, which grows and never reduces. */
- private List<byte[]> buffers = new ArrayList<byte[]>();
+ private final List<byte[]> buffers = new ArrayList<byte[]>();
/** The index of the current buffer. */
private int currentBufferIndex;
/** The total count of bytes in all the filled buffers. */
@@ -84,18 +81,9 @@ public class ByteArrayOutputStream exten
throw new IllegalArgumentException(
"Negative initial size: " + size);
}
- needNewBuffer(size);
- }
-
- /**
- * Return the appropriate <code>byte[]</code> buffer
- * specified by index.
- *
- * @param index the index of the buffer required
- * @return the buffer
- */
- private byte[] getBuffer(int index) {
- return buffers.get(index);
+ synchronized (this) {
+ needNewBuffer(size);
+ }
}
/**
@@ -110,7 +98,7 @@ public class ByteArrayOutputStream exten
filledBufferSum += currentBuffer.length;
currentBufferIndex++;
- currentBuffer = getBuffer(currentBufferIndex);
+ currentBuffer = buffers.get(currentBufferIndex);
} else {
//Creating new buffer
int newBufferSize;
@@ -188,7 +176,7 @@ public class ByteArrayOutputStream exten
* @return total number of bytes read from the input stream
* (and written to this stream)
* @throws IOException if an I/O error occurs while reading the input
stream
- * @since Commons IO 1.4
+ * @since 1.4
*/
public synchronized int write(InputStream in) throws IOException {
int readCount = 0;
@@ -208,14 +196,6 @@ public class ByteArrayOutputStream exten
}
/**
- * Return the current size of the byte array.
- * @return the current size of the byte array
- */
- public synchronized int size() {
- return count;
- }
-
- /**
* Closing a <tt>ByteArrayOutputStream</tt> has no effect. The methods in
* this class can be called after the stream has been closed without
* generating an <tt>IOException</tt>.
@@ -229,16 +209,6 @@ public class ByteArrayOutputStream exten
}
/**
- * @see java.io.ByteArrayOutputStream#reset()
- */
- public synchronized void reset() {
- count = 0;
- filledBufferSum = 0;
- currentBufferIndex = 0;
- currentBuffer = getBuffer(currentBufferIndex);
- }
-
- /**
* Writes the entire contents of this byte stream to the
* specified output stream.
*
@@ -248,8 +218,7 @@ public class ByteArrayOutputStream exten
*/
public synchronized void writeTo(OutputStream out) throws IOException {
int remaining = count;
- for (int i = 0; i < buffers.size(); i++) {
- byte[] buf = getBuffer(i);
+ for (byte[] buf : buffers) {
int c = Math.min(buf.length, remaining);
out.write(buf, 0, c);
remaining -= c;
@@ -273,8 +242,7 @@ public class ByteArrayOutputStream exten
}
byte newbuf[] = new byte[remaining];
int pos = 0;
- for (int i = 0; i < buffers.size(); i++) {
- byte[] buf = getBuffer(i);
+ for (byte[] buf : buffers) {
int c = Math.min(buf.length, remaining);
System.arraycopy(buf, 0, newbuf, pos, c);
pos += c;
@@ -295,18 +263,4 @@ public class ByteArrayOutputStream exten
public String toString() {
return new String(toByteArray());
}
-
- /**
- * Gets the curent contents of this byte stream as a string
- * using the specified encoding.
- *
- * @param enc the name of the character encoding
- * @return the string converted from the byte array
- * @throws UnsupportedEncodingException if the encoding is not supported
- * @see java.io.ByteArrayOutputStream#toString(String)
- */
- public String toString(String enc) throws UnsupportedEncodingException {
- return new String(toByteArray(), enc);
- }
-
}
Modified:
tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/http/fileupload/DeferredFileOutputStream.java
URL:
http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/http/fileupload/DeferredFileOutputStream.java?rev=1456969&r1=1456968&r2=1456969&view=diff
==============================================================================
---
tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/http/fileupload/DeferredFileOutputStream.java
(original)
+++
tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/http/fileupload/DeferredFileOutputStream.java
Fri Mar 15 14:37:04 2013
@@ -17,7 +17,6 @@
package org.apache.tomcat.util.http.fileupload;
import java.io.File;
-import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
@@ -34,9 +33,6 @@ import java.io.OutputStream;
* you want to store it in memory (for speed), but if the file is large you
want
* to store it to file (to avoid memory issues).
*
- * @author <a href="mailto:[email protected]">Martin Cooper</a>
- * @author gaxzerow
- *
* @version $Id$
*/
public class DeferredFileOutputStream
@@ -69,23 +65,17 @@ public class DeferredFileOutputStream
/**
* The temporary file prefix.
*/
- private String prefix;
+ private final String prefix;
/**
* The temporary file suffix.
*/
- private String suffix;
+ private final String suffix;
/**
* The directory to use for temporary files.
*/
- private File directory;
-
-
- /**
- * True when close() has been called successfully.
- */
- private boolean closed = false;
+ private final File directory;
// ----------------------------------------------------------- Constructors
@@ -99,31 +89,26 @@ public class DeferredFileOutputStream
*/
public DeferredFileOutputStream(int threshold, File outputFile)
{
- super(threshold);
- this.outputFile = outputFile;
-
- memoryOutputStream = new ByteArrayOutputStream();
- currentOutputStream = memoryOutputStream;
+ this(threshold, outputFile, null, null, null);
}
/**
* Constructs an instance of this class which will trigger an event at the
- * specified threshold, and save data to a temporary file beyond that
point.
+ * specified threshold, and save data either to a file beyond that point.
*
* @param threshold The number of bytes at which to trigger an event.
+ * @param outputFile The file to which data is saved beyond the threshold.
* @param prefix Prefix to use for the temporary file.
* @param suffix Suffix to use for the temporary file.
* @param directory Temporary file directory.
- *
- * @since Commons IO 1.4
*/
- public DeferredFileOutputStream(int threshold, String prefix, String
suffix, File directory)
- {
- this(threshold, (File)null);
- if (prefix == null) {
- throw new IllegalArgumentException("Temporary file prefix is
missing");
- }
+ private DeferredFileOutputStream(int threshold, File outputFile, String
prefix, String suffix, File directory) {
+ super(threshold);
+ this.outputFile = outputFile;
+
+ memoryOutputStream = new ByteArrayOutputStream();
+ currentOutputStream = memoryOutputStream;
this.prefix = prefix;
this.suffix = suffix;
this.directory = directory;
@@ -176,21 +161,21 @@ public class DeferredFileOutputStream
* Determines whether or not the data for this output stream has been
* retained in memory.
*
- * @return <code>true</code> if the data is available in memory;
- * <code>false</code> otherwise.
+ * @return {@code true} if the data is available in memory;
+ * {@code false} otherwise.
*/
public boolean isInMemory()
{
- return (!isThresholdExceeded());
+ return !isThresholdExceeded();
}
/**
* Returns the data for this output stream as an array of bytes, assuming
* that the data has been retained in memory. If the data was written to
- * disk, this method returns <code>null</code>.
+ * disk, this method returns {@code null}.
*
- * @return The data for this output stream, or <code>null</code> if no such
+ * @return The data for this output stream, or {@code null} if no such
* data is available.
*/
public byte[] getData()
@@ -208,13 +193,13 @@ public class DeferredFileOutputStream
* the temporary file created or null.
* <p>
* If the constructor specifying the file is used then it returns that
- * same output file, even when threashold has not been reached.
+ * same output file, even when threshold has not been reached.
* <p>
* If constructor specifying a temporary file prefix/suffix is used
- * then the temporary file created once the threashold is reached is
returned
- * If the threshold was not reached then <code>null</code> is returned.
+ * then the temporary file created once the threshold is reached is
returned
+ * If the threshold was not reached then {@code null} is returned.
*
- * @return The file for this output stream, or <code>null</code> if no such
+ * @return The file for this output stream, or {@code null} if no such
* file exists.
*/
public File getFile()
@@ -232,39 +217,5 @@ public class DeferredFileOutputStream
public void close() throws IOException
{
super.close();
- closed = true;
- }
-
-
- /**
- * Writes the data from this output stream to the specified output stream,
- * after it has been closed.
- *
- * @param out output stream to write to.
- * @exception IOException if this stream is not yet closed or an error
occurs.
- */
- public void writeTo(OutputStream out) throws IOException
- {
- // we may only need to check if this is closed if we are working with
a file
- // but we should force the habit of closing wether we are working with
- // a file or memory.
- if (!closed)
- {
- throw new IOException("Stream not closed");
- }
-
- if(isInMemory())
- {
- memoryOutputStream.writeTo(out);
- }
- else
- {
- FileInputStream fis = new FileInputStream(outputFile);
- try {
- IOUtils.copy(fis, out);
- } finally {
- IOUtils.closeQuietly(fis);
- }
- }
}
}
Modified:
tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/http/fileupload/FileCleaningTracker.java
URL:
http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/http/fileupload/FileCleaningTracker.java?rev=1456969&r1=1456968&r2=1456969&view=diff
==============================================================================
---
tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/http/fileupload/FileCleaningTracker.java
(original)
+++
tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/http/fileupload/FileCleaningTracker.java
Fri Mar 15 14:37:04 2013
@@ -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.
@@ -19,8 +19,11 @@ package org.apache.tomcat.util.http.file
import java.io.File;
import java.lang.ref.PhantomReference;
import java.lang.ref.ReferenceQueue;
+import java.util.ArrayList;
import java.util.Collection;
-import java.util.Vector;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.List;
/**
* Keeps track of files awaiting deletion, and deletes them when an associated
@@ -36,27 +39,29 @@ import java.util.Vector;
* {@link #exitWhenFinished}, typically in
* {@link javax.servlet.ServletContextListener#contextDestroyed} or similar.
*
- * @author Noel Bergman
- * @author Martin Cooper
- * @version $Id: FileCleaner.java 490987 2006-12-29 12:11:48Z scolebourne $
+ * @version $Id$
*/
public class FileCleaningTracker {
/**
* Queue of <code>Tracker</code> instances being watched.
*/
- ReferenceQueue /* Tracker */ q = new ReferenceQueue();
+ private final ReferenceQueue<Object> q = new ReferenceQueue<Object>();
/**
* Collection of <code>Tracker</code> instances in existence.
*/
- final Collection<Tracker> trackers = new Vector<Tracker>(); //
synchronized
+ private final Collection<Tracker> trackers =
Collections.synchronizedSet(new HashSet<Tracker>()); // synchronized
+ /**
+ * Collection of File paths that failed to delete.
+ */
+ private final List<String> deleteFailures =
Collections.synchronizedList(new ArrayList<String>());
/**
* Whether to terminate the thread when the tracking is complete.
*/
- volatile boolean exitWhenFinished = false;
+ private volatile boolean exitWhenFinished = false;
/**
* The thread that will clean up registered files.
*/
- Thread reaper;
+ private Thread reaper;
//-----------------------------------------------------------------------
/**
@@ -90,38 +95,8 @@ public class FileCleaningTracker {
}
/**
- * Track the specified file, using the provided marker, deleting the file
- * when the marker instance is garbage collected.
- * The {@link FileDeleteStrategy#NORMAL normal} deletion strategy will be
used.
- *
- * @param path the full path to the file to be tracked, not null
- * @param marker the marker object used to track the file, not null
- * @throws NullPointerException if the path is null
- */
- public void track(String path, Object marker) {
- track(path, marker, (FileDeleteStrategy) null);
- }
-
- /**
- * Track the specified file, using the provided marker, deleting the file
- * when the marker instance is garbage collected.
- * The speified deletion strategy is used.
- *
- * @param path the full path to the file to be tracked, not null
- * @param marker the marker object used to track the file, not null
- * @param deleteStrategy the strategy to delete the file, null means
normal
- * @throws NullPointerException if the path is null
- */
- public void track(String path, Object marker, FileDeleteStrategy
deleteStrategy) {
- if (path == null) {
- throw new NullPointerException("The path must not be null");
- }
- addTracker(path, marker, deleteStrategy);
- }
-
- /**
* Adds a tracker to the list of trackers.
- *
+ *
* @param path the full path to the file to be tracked, not null
* @param marker the marker object used to track the file, not null
* @param deleteStrategy the strategy to delete the file, null means
normal
@@ -140,48 +115,6 @@ public class FileCleaningTracker {
//-----------------------------------------------------------------------
/**
- * Retrieve the number of files currently being tracked, and therefore
- * awaiting deletion.
- *
- * @return the number of files being tracked
- */
- public int getTrackCount() {
- return trackers.size();
- }
-
- /**
- * Call this method to cause the file cleaner thread to terminate when
- * there are no more objects being tracked for deletion.
- * <p>
- * In a simple environment, you don't need this method as the file cleaner
- * thread will simply exit when the JVM exits. In a more complex
environment,
- * with multiple class loaders (such as an application server), you should
be
- * aware that the file cleaner thread will continue running even if the
class
- * loader it was started from terminates. This can consitute a memory leak.
- * <p>
- * For example, suppose that you have developed a web application, which
- * contains the commons-io jar file in your WEB-INF/lib directory. In other
- * words, the FileCleaner class is loaded through the class loader of your
- * web application. If the web application is terminated, but the servlet
- * container is still running, then the file cleaner thread will still
exist,
- * posing a memory leak.
- * <p>
- * This method allows the thread to be terminated. Simply call this method
- * in the resource cleanup code, such as {@link
javax.servlet.ServletContextListener#contextDestroyed}.
- * One called, no new objects can be tracked by the file cleaner.
- */
- public synchronized void exitWhenFinished() {
- // synchronized block protects reaper
- exitWhenFinished = true;
- if (reaper != null) {
- synchronized (reaper) {
- reaper.interrupt();
- }
- }
- }
-
- //-----------------------------------------------------------------------
- /**
* The reaper thread.
*/
private final class Reaper extends Thread {
@@ -200,17 +133,16 @@ public class FileCleaningTracker {
public void run() {
// thread exits when exitWhenFinished is true and there are no
more tracked objects
while (exitWhenFinished == false || trackers.size() > 0) {
- Tracker tracker = null;
try {
// Wait for a tracker to remove.
- tracker = (Tracker) q.remove();
- } catch (Exception e) {
- continue;
- }
- if (tracker != null) {
- tracker.delete();
- tracker.clear();
+ Tracker tracker = (Tracker) q.remove(); // cannot return
null
trackers.remove(tracker);
+ if (!tracker.delete()) {
+ deleteFailures.add(tracker.getPath());
+ }
+ tracker.clear();
+ } catch (InterruptedException e) {
+ continue;
}
}
}
@@ -220,7 +152,7 @@ public class FileCleaningTracker {
/**
* Inner class which acts as the reference for a file pending deletion.
*/
- private static final class Tracker extends PhantomReference {
+ private static final class Tracker extends PhantomReference<Object> {
/**
* The full path to the file being tracked.
@@ -239,17 +171,26 @@ public class FileCleaningTracker {
* @param marker the marker object used to track the file, not null
* @param queue the queue on to which the tracker will be pushed, not
null
*/
- Tracker(String path, FileDeleteStrategy deleteStrategy, Object marker,
ReferenceQueue queue) {
+ Tracker(String path, FileDeleteStrategy deleteStrategy, Object marker,
ReferenceQueue<? super Object> queue) {
super(marker, queue);
this.path = path;
- this.deleteStrategy = (deleteStrategy == null ?
FileDeleteStrategy.NORMAL : deleteStrategy);
+ this.deleteStrategy = deleteStrategy == null ?
FileDeleteStrategy.NORMAL : deleteStrategy;
+ }
+
+ /**
+ * Return the path.
+ *
+ * @return the path
+ */
+ public String getPath() {
+ return path;
}
/**
* Deletes the file associated with this tracker instance.
*
- * @return <code>true</code> if the file was deleted successfully;
- * <code>false</code> otherwise.
+ * @return {@code true} if the file was deleted successfully;
+ * {@code false} otherwise.
*/
public boolean delete() {
return deleteStrategy.deleteQuietly(new File(path));
Modified:
tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/http/fileupload/FileDeleteStrategy.java
URL:
http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/http/fileupload/FileDeleteStrategy.java?rev=1456969&r1=1456968&r2=1456969&view=diff
==============================================================================
---
tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/http/fileupload/FileDeleteStrategy.java
(original)
+++
tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/http/fileupload/FileDeleteStrategy.java
Fri Mar 15 14:37:04 2013
@@ -28,9 +28,8 @@ import java.io.IOException;
* <p>
* This class captures the strategy to use and is designed for user
subclassing.
*
- * @author Stephen Colebourne
* @version $Id$
- * @since Commons IO 1.3
+ * @since 1.3
*/
public class FileDeleteStrategy {
@@ -39,11 +38,6 @@ public class FileDeleteStrategy {
* the deletion of directories that are not empty.
*/
public static final FileDeleteStrategy NORMAL = new
FileDeleteStrategy("Normal");
- /**
- * The singleton instance for forced file deletion, which always deletes,
- * even if the file represents a non-empty directory.
- */
- public static final FileDeleteStrategy FORCE = new
ForceFileDeleteStrategy();
/** The name of the strategy. */
private final String name;
@@ -81,22 +75,6 @@ public class FileDeleteStrategy {
}
/**
- * Deletes the file object, which may be a file or a directory.
- * If the file does not exist, the method just returns.
- * <p>
- * Subclass writers should override {@link #doDelete(File)}, not this
method.
- *
- * @param fileToDelete the file to delete, not null
- * @throws NullPointerException if the file is null
- * @throws IOException if an error occurs during file deletion
- */
- public void delete(File fileToDelete) throws IOException {
- if (fileToDelete.exists() && doDelete(fileToDelete) == false) {
- throw new IOException("Deletion failed: " + fileToDelete);
- }
- }
-
- /**
* Actually deletes the file object, which may be a file or a directory.
* <p>
* This method is designed for subclasses to override.
@@ -144,7 +122,7 @@ public class FileDeleteStrategy {
* if the file exists.
*
* @param fileToDelete the file to delete, not null
- * @return Always returns <code>true</code>
+ * @return Always returns {@code true}
* @throws NullPointerException if the file is null
* @throws IOException if an error occurs during file deletion
*/
Modified:
tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/http/fileupload/FileUtils.java
URL:
http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/http/fileupload/FileUtils.java?rev=1456969&r1=1456968&r2=1456969&view=diff
==============================================================================
---
tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/http/fileupload/FileUtils.java
(original)
+++
tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/http/fileupload/FileUtils.java
Fri Mar 15 14:37:04 2013
@@ -40,20 +40,6 @@ import java.io.IOException;
* <p>
* Origin of code: Excalibur, Alexandria, Commons-Utils
*
- * @author <a href="mailto:[email protected]">Kevin A. Burton</A>
- * @author <a href="mailto:[email protected]">Scott Sanders</a>
- * @author <a href="mailto:[email protected]">Daniel Rall</a>
- * @author <a href="mailto:[email protected]">Christoph.Reck</a>
- * @author <a href="mailto:[email protected]">Peter Donald</a>
- * @author <a href="mailto:[email protected]">Jeff Turner</a>
- * @author Matthew Hawthorne
- * @author <a href="mailto:[email protected]">Jeremias Maerki</a>
- * @author Stephen Colebourne
- * @author Ian Springer
- * @author Chris Eldredge
- * @author Jim Harrington
- * @author Niall Pemberton
- * @author Sandy McArthur
* @version $Id$
*/
public class FileUtils {
@@ -77,7 +63,10 @@ public class FileUtils {
return;
}
- cleanDirectory(directory);
+ if (!isSymlink(directory)) {
+ cleanDirectory(directory);
+ }
+
if (!directory.delete()) {
String message =
"Unable to delete directory " + directory + ".";
@@ -85,7 +74,6 @@ public class FileUtils {
}
}
-
/**
* Cleans a directory without deleting it.
*
@@ -109,8 +97,7 @@ public class FileUtils {
}
IOException exception = null;
- for (int i = 0; i < files.length; i++) {
- File file = files[i];
+ for (File file : files) {
try {
forceDelete(file);
} catch (IOException ioe) {
@@ -122,8 +109,7 @@ public class FileUtils {
throw exception;
}
}
-
-
+
//-----------------------------------------------------------------------
/**
* Deletes a file. If file is a directory, delete it and all
sub-directories.
@@ -135,8 +121,8 @@ public class FileUtils {
* (java.io.File methods returns a boolean)</li>
* </ul>
*
- * @param file file or directory to delete, must not be <code>null</code>
- * @throws NullPointerException if the directory is <code>null</code>
+ * @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
*/
@@ -160,8 +146,8 @@ 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</code>
- * @throws NullPointerException if the file is <code>null</code>
+ * @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
*/
public static void forceDeleteOnExit(File file) throws IOException {
@@ -175,8 +161,8 @@ public class FileUtils {
/**
* Schedules a directory recursively for deletion on JVM exit.
*
- * @param directory directory to delete, must not be <code>null</code>
- * @throws NullPointerException if the directory is <code>null</code>
+ * @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
*/
private static void deleteDirectoryOnExit(File directory) throws
IOException {
@@ -184,15 +170,17 @@ public class FileUtils {
return;
}
- cleanDirectoryOnExit(directory);
directory.deleteOnExit();
+ if (!isSymlink(directory)) {
+ cleanDirectoryOnExit(directory);
+ }
}
/**
* Cleans a directory without deleting it.
*
- * @param directory directory to clean, must not be <code>null</code>
- * @throws NullPointerException if the directory is <code>null</code>
+ * @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
*/
private static void cleanDirectoryOnExit(File directory) throws
IOException {
@@ -212,8 +200,7 @@ public class FileUtils {
}
IOException exception = null;
- for (int i = 0; i < files.length; i++) {
- File file = files[i];
+ for (File file : files) {
try {
forceDeleteOnExit(file);
} catch (IOException ioe) {
@@ -225,4 +212,43 @@ public class FileUtils {
throw exception;
}
}
+
+
+ /**
+ * Determines whether the specified file is a Symbolic Link rather than an
actual file.
+ * <p>
+ * Will not return true if there is a Symbolic Link anywhere in the path,
+ * only if the specific file is.
+ * <p>
+ * <b>Note:</b> the current implementation always returns {@code false} if
+ * the system is detected as Windows using
+ * {@link File#separatorChar} == '\\'
+ *
+ * @param file the file to check
+ * @return true if the file is a Symbolic Link
+ * @throws IOException if an IO error occurs while checking the file
+ * @since 2.0
+ */
+ public static boolean isSymlink(File file) throws IOException {
+ if (file == null) {
+ throw new NullPointerException("File must not be null");
+ }
+ //FilenameUtils.isSystemWindows()
+ if (File.separatorChar == '\\') {
+ return false;
+ }
+ File fileInCanonicalDir = null;
+ if (file.getParent() == null) {
+ fileInCanonicalDir = file;
+ } else {
+ File canonicalDir = file.getParentFile().getCanonicalFile();
+ fileInCanonicalDir = new File(canonicalDir, file.getName());
+ }
+
+ if
(fileInCanonicalDir.getCanonicalFile().equals(fileInCanonicalDir.getAbsoluteFile()))
{
+ return false;
+ } else {
+ return true;
+ }
+ }
}
Modified:
tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/http/fileupload/IOUtils.java
URL:
http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/http/fileupload/IOUtils.java?rev=1456969&r1=1456968&r2=1456969&view=diff
==============================================================================
---
tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/http/fileupload/IOUtils.java
(original)
+++
tomcat/tc7.0.x/trunk/java/org/apache/tomcat/util/http/fileupload/IOUtils.java
Fri Mar 15 14:37:04 2013
@@ -20,7 +20,6 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
-
/**
* General IO stream manipulation utilities.
* <p>
@@ -52,14 +51,6 @@ import java.io.OutputStream;
* <p>
* Origin of code: Excalibur.
*
- * @author Peter Donald
- * @author Jeff Turner
- * @author Matthew Hawthorne
- * @author Stephen Colebourne
- * @author Gareth Davis
- * @author Ian Springer
- * @author Niall Pemberton
- * @author Sandy McArthur
* @version $Id$
*/
public class IOUtils {
@@ -67,8 +58,13 @@ public class IOUtils {
// Writer. Each method should take at least one of these as a parameter,
// or return one of them.
+ private static final int EOF = -1;
+
/**
- * The default buffer size to use.
+ * The default buffer size ({@value}) to use for
+ * {@link #copyLarge(InputStream, OutputStream)}
+ * and
+ * {@link #copyLarge(Reader, Writer)}
*/
private static final int DEFAULT_BUFFER_SIZE = 1024 * 4;
@@ -79,25 +75,6 @@ public class IOUtils {
super();
}
-
- /**
- * Unconditionally close an <code>InputStream</code>.
- * <p>
- * Equivalent to {@link InputStream#close()}, except any exceptions will
be ignored.
- * This is typically used in finally blocks.
- *
- * @param input the InputStream to close, may be null or already closed
- */
- public static void closeQuietly(InputStream input) {
- try {
- if (input != null) {
- input.close();
- }
- } catch (IOException ioe) {
- // ignore
- }
- }
-
// copy from InputStream
//-----------------------------------------------------------------------
/**
@@ -114,11 +91,10 @@ public class IOUtils {
*
* @param input the <code>InputStream</code> to read from
* @param output the <code>OutputStream</code> to write to
- * @return the number of bytes copied
+ * @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 ArithmeticException if the byte count is too large
- * @since Commons IO 1.1
+ * @since 1.1
*/
public static int copy(InputStream input, OutputStream output) throws
IOException {
long count = copyLarge(input, output);
@@ -134,25 +110,26 @@ public class IOUtils {
* <p>
* This method buffers the input internally, so there is no need to use a
* <code>BufferedInputStream</code>.
- *
+ * <p>
+ * The buffer size is given by {@link #DEFAULT_BUFFER_SIZE}.
+ *
* @param input the <code>InputStream</code> to read from
* @param output the <code>OutputStream</code> 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
- * @since Commons IO 1.3
+ * @since 1.3
*/
public static long copyLarge(InputStream input, OutputStream output)
throws IOException {
+
byte[] buffer = new byte[DEFAULT_BUFFER_SIZE];
long count = 0;
int n = 0;
- while (-1 != (n = input.read(buffer))) {
+ while (EOF != (n = input.read(buffer))) {
output.write(buffer, 0, n);
count += n;
}
return count;
}
-
-
}
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=1456969&r1=1456968&r2=1456969&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
Fri Mar 15 14:37:04 2013
@@ -34,8 +34,6 @@ import java.io.OutputStream;
* is actually reached, since it triggers when a pending write operation would
* cause the threshold to be exceeded.
*
- * @author <a href="mailto:[email protected]">Martin Cooper</a>
- *
* @version $Id$
*/
public abstract class ThresholdingOutputStream
@@ -48,7 +46,7 @@ public abstract class ThresholdingOutput
/**
* The threshold at which the event will be triggered.
*/
- private int threshold;
+ private final int threshold;
/**
@@ -171,37 +169,15 @@ public abstract class ThresholdingOutput
/**
- * Returns the threshold, in bytes, at which an event will be triggered.
- *
- * @return The threshold point, in bytes.
- */
- public int getThreshold()
- {
- return threshold;
- }
-
-
- /**
- * Returns the number of bytes that have been written to this output
stream.
- *
- * @return The number of bytes written.
- */
- public long getByteCount()
- {
- return written;
- }
-
-
- /**
* Determines whether or not the configured threshold has been exceeded for
* this output stream.
*
- * @return <code>true</code> if the threshold has been reached;
- * <code>false</code> otherwise.
+ * @return {@code true} if the threshold has been reached;
+ * {@code false} otherwise.
*/
public boolean isThresholdExceeded()
{
- return (written > threshold);
+ return written > threshold;
}
@@ -220,23 +196,13 @@ public abstract class ThresholdingOutput
*/
protected void checkThreshold(int count) throws IOException
{
- if (!thresholdExceeded && (written + count > threshold))
+ if (!thresholdExceeded && written + count > threshold)
{
thresholdExceeded = true;
thresholdReached();
}
}
- /**
- * Resets the byteCount to zero. You can call this from
- * {@link #thresholdReached()} if you want the event to be triggered
again.
- */
- protected void resetByteCount()
- {
- this.thresholdExceeded = false;
- this.written = 0;
- }
-
// ------------------------------------------------------- Abstract methods
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=1456969&r1=1456968&r2=1456969&view=diff
==============================================================================
--- tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml (original)
+++ tomcat/tc7.0.x/trunk/webapps/docs/changelog.xml Fri Mar 15 14:37:04 2013
@@ -79,7 +79,8 @@
</add>
<update>
Update Tomcat's internal copy of Commons FileUpload to FileUpload
trunk,
- revision 1456918. (markt)
+ revision 1456918 and the associated extract from Commons IO to 2.4.
+ (markt)
</update>
</changelog>
</subsection>
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]