This is an automated email from the ASF dual-hosted git repository.

jochen pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-fileupload.git


The following commit(s) were added to refs/heads/master by this push:
     new 18db2b7  FILEUPLOAD-342 Remove methods which use javax|jakarta classes 
from FileUploadBase (#109)
18db2b7 is described below

commit 18db2b7e5a471b5bd81dab119db43c9efceda3cf
Author: Martin Grigorov <marti...@users.noreply.github.com>
AuthorDate: Mon Sep 13 15:44:34 2021 +0300

    FILEUPLOAD-342 Remove methods which use javax|jakarta classes from 
FileUploadBase (#109)
    
    * FILEUPLOAD-342 Remove methods which use javax|jakarta classes from 
FileUploadBase
    
    It should be neutral.
    
    * FILEUPLOAD-342 Remove all deprecated classes and their tests
---
 .../commons/fileupload2/DefaultFileItem.java       |  71 -----
 .../fileupload2/DefaultFileItemFactory.java        | 104 ------
 .../apache/commons/fileupload2/DiskFileUpload.java | 200 ------------
 .../apache/commons/fileupload2/FileUploadBase.java |  40 ---
 .../fileupload2/pub/UnknownSizeException.java      |  55 ----
 .../fileupload2/servlet/ServletFileUpload.java     |   1 -
 .../commons/fileupload2/DefaultFileItemTest.java   | 355 ---------------------
 .../commons/fileupload2/DiskFileUploadTest.java    | 100 ------
 8 files changed, 926 deletions(-)

diff --git a/src/main/java/org/apache/commons/fileupload2/DefaultFileItem.java 
b/src/main/java/org/apache/commons/fileupload2/DefaultFileItem.java
deleted file mode 100644
index 3e55865..0000000
--- a/src/main/java/org/apache/commons/fileupload2/DefaultFileItem.java
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * 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.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.commons.fileupload2;
-
-import java.io.File;
-
-import org.apache.commons.fileupload2.disk.DiskFileItem;
-
-/**
- * <p> The default implementation of the
- * {@link org.apache.commons.fileupload2.FileItem FileItem} interface.
- *
- * <p> After retrieving an instance of this class from a {@link
- * org.apache.commons.fileupload2.DiskFileUpload DiskFileUpload} instance (see
- * {@link org.apache.commons.fileupload2.DiskFileUpload
- * #parseRequest(javax.servlet.http.HttpServletRequest)}), you may
- * either request all contents of file at once using {@link #get()} or
- * request an {@link java.io.InputStream InputStream} with
- * {@link #getInputStream()} and process the file without attempting to load
- * it into memory, which may come handy with large files.
- *
- * @deprecated 1.1 Use {@code DiskFileItem} instead.
- */
-@Deprecated
-public class DefaultFileItem
-    extends DiskFileItem {
-
-    // ----------------------------------------------------------- Constructors
-
-    /**
-     * Constructs a new {@code DefaultFileItem} instance.
-     *
-     * @param fieldName     The name of the form field.
-     * @param contentType   The content type passed by the browser or
-     *                      {@code null} if not specified.
-     * @param isFormField   Whether or not this item is a plain form field, as
-     *                      opposed to a file upload.
-     * @param fileName      The original file name in the user's file system, 
or
-     *                      {@code null} if not specified.
-     * @param sizeThreshold The threshold, in bytes, below which items will be
-     *                      retained in memory and above which they will be
-     *                      stored as a file.
-     * @param repository    The data repository, which is the directory in
-     *                      which files will be created, should the item size
-     *                      exceed the threshold.
-     *
-     * @deprecated 1.1 Use {@code DiskFileItem} instead.
-     */
-    @Deprecated
-    public DefaultFileItem(final String fieldName, final String contentType,
-            final boolean isFormField, final String fileName, final int 
sizeThreshold,
-            final File repository) {
-        super(fieldName, contentType, isFormField, fileName, sizeThreshold,
-                repository);
-    }
-
-}
diff --git 
a/src/main/java/org/apache/commons/fileupload2/DefaultFileItemFactory.java 
b/src/main/java/org/apache/commons/fileupload2/DefaultFileItemFactory.java
deleted file mode 100644
index 5c9d34a..0000000
--- a/src/main/java/org/apache/commons/fileupload2/DefaultFileItemFactory.java
+++ /dev/null
@@ -1,104 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * 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.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.commons.fileupload2;
-
-import java.io.File;
-
-import org.apache.commons.fileupload2.disk.DiskFileItemFactory;
-
-/**
- * <p>The default {@link org.apache.commons.fileupload2.FileItemFactory}
- * implementation. This implementation creates
- * {@link org.apache.commons.fileupload2.FileItem} instances which keep their
- * content either in memory, for smaller items, or in a temporary file on disk,
- * for larger items. The size threshold, above which content will be stored on
- * disk, is configurable, as is the directory in which temporary files will be
- * created.</p>
- *
- * <p>If not otherwise configured, the default configuration values are as
- * follows:
- * <ul>
- *   <li>Size threshold is 10KB.</li>
- *   <li>Repository is the system default temp directory, as returned by
- *       {@code System.getProperty("java.io.tmpdir")}.</li>
- * </ul>
- *
- * @deprecated 1.1 Use {@code DiskFileItemFactory} instead.
- */
-@Deprecated
-public class DefaultFileItemFactory extends DiskFileItemFactory {
-
-    // ----------------------------------------------------------- Constructors
-
-    /**
-     * Constructs an unconfigured instance of this class. The resulting factory
-     * may be configured by calling the appropriate setter methods.
-     *
-     * @deprecated 1.1 Use {@code DiskFileItemFactory} instead.
-     */
-    @Deprecated
-    public DefaultFileItemFactory() {
-    }
-
-    /**
-     * Constructs a preconfigured instance of this class.
-     *
-     * @param sizeThreshold The threshold, in bytes, below which items will be
-     *                      retained in memory and above which they will be
-     *                      stored as a file.
-     * @param repository    The data repository, which is the directory in
-     *                      which files will be created, should the item size
-     *                      exceed the threshold.
-     *
-     * @deprecated 1.1 Use {@code DiskFileItemFactory} instead.
-     */
-    @Deprecated
-    public DefaultFileItemFactory(final int sizeThreshold, final File 
repository) {
-        super(sizeThreshold, repository);
-    }
-
-    // --------------------------------------------------------- Public Methods
-
-    /**
-     * Create a new {@link org.apache.commons.fileupload2.DefaultFileItem}
-     * instance from the supplied parameters and the local factory
-     * configuration.
-     *
-     * @param fieldName   The name of the form field.
-     * @param contentType The content type of the form field.
-     * @param isFormField {@code true} if this is a plain form field;
-     *                    {@code false} otherwise.
-     * @param fileName    The name of the uploaded file, if any, as supplied
-     *                    by the browser or other client.
-     *
-     * @return The newly created file item.
-     *
-     * @deprecated 1.1 Use {@code DiskFileItemFactory} instead.
-     */
-    @Override
-    @Deprecated
-    public FileItem createItem(
-            final String fieldName,
-            final String contentType,
-            final boolean isFormField,
-            final String fileName
-            ) {
-        return new DefaultFileItem(fieldName, contentType,
-                isFormField, fileName, getSizeThreshold(), getRepository());
-    }
-
-}
diff --git a/src/main/java/org/apache/commons/fileupload2/DiskFileUpload.java 
b/src/main/java/org/apache/commons/fileupload2/DiskFileUpload.java
deleted file mode 100644
index 0cd617b..0000000
--- a/src/main/java/org/apache/commons/fileupload2/DiskFileUpload.java
+++ /dev/null
@@ -1,200 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * 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.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.commons.fileupload2;
-
-import java.io.File;
-import java.util.List;
-import javax.servlet.http.HttpServletRequest;
-
-/**
- * <p>High level API for processing file uploads.</p>
- *
- * <p>This class handles multiple files per single HTML widget, sent using
- * {@code multipart/mixed} encoding type, as specified by
- * <a href="http://www.ietf.org/rfc/rfc1867.txt";>RFC 1867</a>.  Use {@link
- * #parseRequest(HttpServletRequest)} to acquire a list of {@link
- * org.apache.commons.fileupload2.FileItem}s associated with a given HTML
- * widget.</p>
- *
- * <p>Individual parts will be stored in temporary disk storage or in memory,
- * depending on their size, and will be available as {@link
- * org.apache.commons.fileupload2.FileItem}s.</p>
- *
- * @deprecated 1.1 Use {@code ServletFileUpload} together with
- *             {@code DiskFileItemFactory} instead.
- */
-@Deprecated
-public class DiskFileUpload
-    extends FileUploadBase {
-
-    // ----------------------------------------------------------- Data members
-
-    /**
-     * The factory to use to create new form items.
-     */
-    private DefaultFileItemFactory fileItemFactory;
-
-    // ----------------------------------------------------------- Constructors
-
-    /**
-     * Constructs an instance of this class which uses the default factory to
-     * create {@code FileItem} instances.
-     *
-     * @see #DiskFileUpload(DefaultFileItemFactory fileItemFactory)
-     *
-     * @deprecated 1.1 Use {@code FileUpload} instead.
-     */
-    @Deprecated
-    public DiskFileUpload() {
-        this.fileItemFactory = new DefaultFileItemFactory();
-    }
-
-    /**
-     * Constructs an instance of this class which uses the supplied factory to
-     * create {@code FileItem} instances.
-     *
-     * @see #DiskFileUpload()
-     * @param fileItemFactory The file item factory to use.
-     *
-     * @deprecated 1.1 Use {@code FileUpload} instead.
-     */
-    @Deprecated
-    public DiskFileUpload(final DefaultFileItemFactory fileItemFactory) {
-        this.fileItemFactory = fileItemFactory;
-    }
-
-    // ----------------------------------------------------- Property accessors
-
-    /**
-     * Returns the factory class used when creating file items.
-     *
-     * @return The factory class for new file items.
-     *
-     * @deprecated 1.1 Use {@code FileUpload} instead.
-     */
-    @Override
-    @Deprecated
-    public FileItemFactory getFileItemFactory() {
-        return fileItemFactory;
-    }
-
-    /**
-     * Sets the factory class to use when creating file items. The factory must
-     * be an instance of {@code DefaultFileItemFactory} or a subclass
-     * thereof, or else a {@code ClassCastException} will be thrown.
-     *
-     * @param factory The factory class for new file items.
-     *
-     * @deprecated 1.1 Use {@code FileUpload} instead.
-     */
-    @Override
-    @Deprecated
-    public void setFileItemFactory(final FileItemFactory factory) {
-        this.fileItemFactory = (DefaultFileItemFactory) factory;
-    }
-
-    /**
-     * Returns the size threshold beyond which files are written directly to
-     * disk.
-     *
-     * @return The size threshold, in bytes.
-     *
-     * @see #setSizeThreshold(int)
-     *
-     * @deprecated 1.1 Use {@code DiskFileItemFactory} instead.
-     */
-    @Deprecated
-    public int getSizeThreshold() {
-        return fileItemFactory.getSizeThreshold();
-    }
-
-    /**
-     * Sets the size threshold beyond which files are written directly to disk.
-     *
-     * @param sizeThreshold The size threshold, in bytes.
-     *
-     * @see #getSizeThreshold()
-     *
-     * @deprecated 1.1 Use {@code DiskFileItemFactory} instead.
-     */
-    @Deprecated
-    public void setSizeThreshold(final int sizeThreshold) {
-        fileItemFactory.setSizeThreshold(sizeThreshold);
-    }
-
-    /**
-     * Returns the location used to temporarily store files that are larger
-     * than the configured size threshold.
-     *
-     * @return The path to the temporary file location.
-     *
-     * @see #setRepositoryPath(String)
-     *
-     * @deprecated 1.1 Use {@code DiskFileItemFactory} instead.
-     */
-    @Deprecated
-    public String getRepositoryPath() {
-        return fileItemFactory.getRepository().getPath();
-    }
-
-    /**
-     * Sets the location used to temporarily store files that are larger
-     * than the configured size threshold.
-     *
-     * @param repositoryPath The path to the temporary file location.
-     *
-     * @see #getRepositoryPath()
-     *
-     * @deprecated 1.1 Use {@code DiskFileItemFactory} instead.
-     */
-    @Deprecated
-    public void setRepositoryPath(final String repositoryPath) {
-        fileItemFactory.setRepository(new File(repositoryPath));
-    }
-
-    // --------------------------------------------------------- Public methods
-
-    /**
-     * Processes an <a href="http://www.ietf.org/rfc/rfc1867.txt";>RFC 1867</a>
-     * compliant {@code multipart/form-data} stream. If files are stored
-     * on disk, the path is given by {@code getRepository()}.
-     *
-     * @param req           The servlet request to be parsed. Must be non-null.
-     * @param sizeThreshold The max size in bytes to be stored in memory.
-     * @param sizeMax       The maximum allowed upload size, in bytes.
-     * @param path          The location where the files should be stored.
-     *
-     * @return A list of {@code FileItem} instances parsed from the
-     *         request, in the order that they were transmitted.
-     *
-     * @throws FileUploadException if there are problems reading/parsing
-     *                             the request or storing files.
-     *
-     * @deprecated 1.1 Use {@code ServletFileUpload} instead.
-     */
-    @Deprecated
-    public List<FileItem> parseRequest(final HttpServletRequest req,
-                                            final int sizeThreshold,
-                                            final long sizeMax, final String 
path)
-        throws FileUploadException {
-        setSizeThreshold(sizeThreshold);
-        setSizeMax(sizeMax);
-        setRepositoryPath(path);
-        return parseRequest(req);
-    }
-
-}
diff --git a/src/main/java/org/apache/commons/fileupload2/FileUploadBase.java 
b/src/main/java/org/apache/commons/fileupload2/FileUploadBase.java
index c6fcbbb..410de67 100644
--- a/src/main/java/org/apache/commons/fileupload2/FileUploadBase.java
+++ b/src/main/java/org/apache/commons/fileupload2/FileUploadBase.java
@@ -28,13 +28,9 @@ import java.util.Locale;
 import java.util.Map;
 import java.util.Objects;
 
-import javax.servlet.http.HttpServletRequest;
-
 import org.apache.commons.fileupload2.impl.FileItemIteratorImpl;
 import org.apache.commons.fileupload2.pub.FileUploadIOException;
 import org.apache.commons.fileupload2.pub.IOFileUploadException;
-import org.apache.commons.fileupload2.servlet.ServletFileUpload;
-import org.apache.commons.fileupload2.servlet.ServletRequestContext;
 import org.apache.commons.fileupload2.util.FileItemHeadersImpl;
 import org.apache.commons.fileupload2.util.Streams;
 
@@ -78,22 +74,6 @@ public abstract class FileUploadBase {
         return contentType.toLowerCase(Locale.ENGLISH).startsWith(MULTIPART);
     }
 
-    /**
-     * Utility method that determines whether the request contains multipart
-     * content.
-     *
-     * @param req The servlet request to be evaluated. Must be non-null.
-     *
-     * @return {@code true} if the request is multipart;
-     *         {@code false} otherwise.
-     *
-     * @deprecated 1.1 Use the method on {@code ServletFileUpload} instead.
-     */
-    @Deprecated
-    public static boolean isMultipartContent(final HttpServletRequest req) {
-        return ServletFileUpload.isMultipartContent(req);
-    }
-
     // ----------------------------------------------------- Manifest constants
 
     /**
@@ -266,26 +246,6 @@ public abstract class FileUploadBase {
      * Processes an <a href="http://www.ietf.org/rfc/rfc1867.txt";>RFC 1867</a>
      * compliant {@code multipart/form-data} stream.
      *
-     * @param req The servlet request to be parsed.
-     *
-     * @return A list of {@code FileItem} instances parsed from the
-     *         request, in the order that they were transmitted.
-     *
-     * @throws FileUploadException if there are problems reading/parsing
-     *                             the request or storing files.
-     *
-     * @deprecated 1.1 Use {@link 
ServletFileUpload#parseRequest(HttpServletRequest)} instead.
-     */
-    @Deprecated
-    public List<FileItem> parseRequest(final HttpServletRequest req)
-    throws FileUploadException {
-        return parseRequest(new ServletRequestContext(req));
-    }
-
-    /**
-     * Processes an <a href="http://www.ietf.org/rfc/rfc1867.txt";>RFC 1867</a>
-     * compliant {@code multipart/form-data} stream.
-     *
      * @param ctx The context for the request to be parsed.
      *
      * @return An iterator to instances of {@code FileItemStream}
diff --git 
a/src/main/java/org/apache/commons/fileupload2/pub/UnknownSizeException.java 
b/src/main/java/org/apache/commons/fileupload2/pub/UnknownSizeException.java
deleted file mode 100644
index 1f4e0bf..0000000
--- a/src/main/java/org/apache/commons/fileupload2/pub/UnknownSizeException.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * 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.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.commons.fileupload2.pub;
-
-import org.apache.commons.fileupload2.FileUploadException;
-
-/**
- * Thrown to indicate that the request size is not specified. In other
- * words, it is thrown, if the content-length header is missing or
- * contains the value -1.
- *
- * @deprecated 1.2 As of commons-fileupload 1.2, the presence of a
- *   content-length header is no longer required.
- */
-@Deprecated
-public class UnknownSizeException
-    extends FileUploadException {
-
-    /**
-     * The exceptions UID, for serializing an instance.
-     */
-    private static final long serialVersionUID = 7062279004812015273L;
-
-    /**
-     * Constructs a {@code UnknownSizeException} with no
-     * detail message.
-     */
-    public UnknownSizeException() {
-    }
-
-    /**
-     * Constructs an {@code UnknownSizeException} with
-     * the specified detail message.
-     *
-     * @param message The detail message.
-     */
-    public UnknownSizeException(final String message) {
-        super(message);
-    }
-
-}
diff --git 
a/src/main/java/org/apache/commons/fileupload2/servlet/ServletFileUpload.java 
b/src/main/java/org/apache/commons/fileupload2/servlet/ServletFileUpload.java
index 2cc96a9..3831ad8 100644
--- 
a/src/main/java/org/apache/commons/fileupload2/servlet/ServletFileUpload.java
+++ 
b/src/main/java/org/apache/commons/fileupload2/servlet/ServletFileUpload.java
@@ -106,7 +106,6 @@ public class ServletFileUpload extends FileUpload {
      * @throws FileUploadException if there are problems reading/parsing
      *                             the request or storing files.
      */
-    @Override
     public List<FileItem> parseRequest(final HttpServletRequest request)
     throws FileUploadException {
         return parseRequest(new ServletRequestContext(request));
diff --git 
a/src/test/java/org/apache/commons/fileupload2/DefaultFileItemTest.java 
b/src/test/java/org/apache/commons/fileupload2/DefaultFileItemTest.java
deleted file mode 100644
index ee662d5..0000000
--- a/src/test/java/org/apache/commons/fileupload2/DefaultFileItemTest.java
+++ /dev/null
@@ -1,355 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * 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.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.commons.fileupload2;
-
-import static org.junit.jupiter.api.Assertions.assertArrayEquals;
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertFalse;
-import static org.junit.jupiter.api.Assertions.assertNotNull;
-import static org.junit.jupiter.api.Assertions.assertNull;
-import static org.junit.jupiter.api.Assertions.assertTrue;
-import static org.junit.jupiter.api.Assertions.fail;
-
-import java.io.File;
-import java.io.IOException;
-import java.io.OutputStream;
-import java.io.UncheckedIOException;
-import org.apache.commons.io.FileUtils;
-
-
-import org.junit.jupiter.api.Test;
-
-/**
- * Unit tests for {@link org.apache.commons.fileupload2.DefaultFileItem}.
- */
-@SuppressWarnings({"deprecation", "javadoc"}) // unit tests for deprecated 
class
-public class DefaultFileItemTest {
-
-    /**
-     * Content type for regular form items.
-     */
-    private static final String TEXT_CONTENT_TYPE = "text/plain";
-
-    /**
-     * Content type for file uploads.
-     */
-    private static final String FILE_CONTENT_TYPE = "application/octet-stream";
-
-    /**
-     * Very low threshold for testing memory versus disk options.
-     */
-    private static final int THRESHOLD = 16;
-
-    /**
-     * Test construction of a regular text field.
-     */
-    @Test
-    public void testTextFieldConstruction() {
-        final FileItemFactory factory = createFactory(null);
-        final String textFieldName = "textField";
-
-        final FileItem item = factory.createItem(
-                textFieldName,
-                TEXT_CONTENT_TYPE,
-                true,
-                null
-        );
-        assertNotNull(item);
-        assertEquals(item.getFieldName(), textFieldName);
-        assertEquals(item.getContentType(), TEXT_CONTENT_TYPE);
-        assertTrue(item.isFormField());
-        assertNull(item.getName());
-    }
-
-    /**
-     * Test construction of a file field.
-     */
-    @Test
-    public void testFileFieldConstruction() {
-        final FileItemFactory factory = createFactory(null);
-        final String fileFieldName = "fileField";
-        final String fileName = "originalFileName";
-
-        final FileItem item = factory.createItem(
-                fileFieldName,
-                FILE_CONTENT_TYPE,
-                false,
-                fileName
-        );
-        assertNotNull(item);
-        assertEquals(item.getFieldName(), fileFieldName);
-        assertEquals(item.getContentType(), FILE_CONTENT_TYPE);
-        assertFalse(item.isFormField());
-        assertEquals(item.getName(), fileName);
-    }
-
-    /**
-     * Test creation of a field for which the amount of data falls below the
-     * configured threshold.
-     */
-    @Test
-    public void testBelowThreshold() {
-        final FileItemFactory factory = createFactory(null);
-        final String textFieldName = "textField";
-        final String textFieldValue = "0123456789";
-        final byte[] testFieldValueBytes = textFieldValue.getBytes();
-
-        final FileItem item = factory.createItem(
-                textFieldName,
-                TEXT_CONTENT_TYPE,
-                true,
-                null
-        );
-        assertNotNull(item);
-
-        try {
-            final OutputStream os = item.getOutputStream();
-            os.write(testFieldValueBytes);
-            os.close();
-        } catch (final IOException e) {
-            fail("Unexpected IOException");
-        }
-        assertTrue(item.isInMemory());
-        assertEquals(item.getSize(), testFieldValueBytes.length);
-        try {
-            assertArrayEquals(item.get(), testFieldValueBytes);
-        } catch (UncheckedIOException e) {
-            fail("Unexpected IOException", e);
-        }
-        assertEquals(item.getString(), textFieldValue);
-    }
-
-
-    /**
-     * Test creation of a field for which the amount of data falls above the
-     * configured threshold, where no specific repository is configured.
-     */
-    @Test
-    public void testAboveThresholdDefaultRepository() {
-        doTestAboveThreshold(null);
-    }
-
-    /**
-     * Test creation of a field for which the amount of data falls above the
-     * configured threshold, where a specific repository is configured.
-     */
-    @Test
-    public void testAboveThresholdSpecifiedRepository() throws IOException {
-        final String tempPath = System.getProperty("java.io.tmpdir");
-        final String tempDirName = "testAboveThresholdSpecifiedRepository";
-        final File tempDir = new File(tempPath, tempDirName);
-        FileUtils.forceMkdir(tempDir);
-        doTestAboveThreshold(tempDir);
-        assertTrue(tempDir.delete());
-    }
-
-    /**
-     * Common code for cases where the amount of data is above the configured
-     * threshold, but the ultimate destination of the data has not yet been
-     * determined.
-     *
-     * @param repository The directory within which temporary files will be
-     *                   created.
-     */
-    public void doTestAboveThreshold(final File repository) {
-        final FileItemFactory factory = createFactory(repository);
-        final String textFieldName = "textField";
-        final String textFieldValue = "01234567890123456789";
-        final byte[] testFieldValueBytes = textFieldValue.getBytes();
-
-        final FileItem item = factory.createItem(
-                textFieldName,
-                TEXT_CONTENT_TYPE,
-                true,
-                null
-        );
-        assertNotNull(item);
-
-        try {
-            final OutputStream os = item.getOutputStream();
-            os.write(testFieldValueBytes);
-            os.close();
-        } catch (final IOException e) {
-            fail("Unexpected IOException");
-        }
-        assertFalse(item.isInMemory());
-        assertEquals(item.getSize(), testFieldValueBytes.length);
-        try {
-            assertArrayEquals(item.get(), testFieldValueBytes);
-        } catch (UncheckedIOException e) {
-            fail("Unexpected IOException", e);
-        }
-        assertEquals(item.getString(), textFieldValue);
-
-        assertTrue(item instanceof DefaultFileItem);
-        final DefaultFileItem dfi = (DefaultFileItem) item;
-        final File storeLocation = dfi.getStoreLocation();
-        assertNotNull(storeLocation);
-        assertTrue(storeLocation.exists());
-        assertEquals(storeLocation.length(), testFieldValueBytes.length);
-
-        if (repository != null) {
-            assertEquals(storeLocation.getParentFile(), repository);
-        }
-
-        item.delete();
-    }
-
-
-    /**
-     * Creates a new {@code FileItemFactory} and returns it, obscuring
-     * from the caller the underlying implementation of this interface.
-     *
-     * @param repository The directory within which temporary files will be
-     *                   created.
-     * @return the new {@code FileItemFactory} instance.
-     */
-    protected FileItemFactory createFactory(final File repository) {
-        return new DefaultFileItemFactory(THRESHOLD, repository);
-    }
-
-    static final String CHARSET_ISO88591 = "ISO-8859-1";
-
-    static final String CHARSET_ASCII = "US-ASCII";
-
-    static final String CHARSET_UTF8 = "UTF-8";
-
-    static final String CHARSET_KOI8_R = "KOI8_R";
-
-    static final String CHARSET_WIN1251 = "Cp1251";
-
-    static final int[] SWISS_GERMAN_STUFF_UNICODE = {
-        0x47, 0x72, 0xFC, 0x65, 0x7A, 0x69, 0x5F, 0x7A, 0xE4, 0x6D, 0xE4
-    };
-
-    static final int[] SWISS_GERMAN_STUFF_ISO8859_1 = {
-        0x47, 0x72, 0xFC, 0x65, 0x7A, 0x69, 0x5F, 0x7A, 0xE4, 0x6D, 0xE4
-    };
-
-    static final int[] SWISS_GERMAN_STUFF_UTF8 = {
-        0x47, 0x72, 0xC3, 0xBC, 0x65, 0x7A, 0x69, 0x5F, 0x7A, 0xC3, 0xA4,
-        0x6D, 0xC3, 0xA4
-    };
-
-    static final int[] RUSSIAN_STUFF_UNICODE = {
-        0x412, 0x441, 0x435, 0x43C, 0x5F, 0x43F, 0x440, 0x438,
-        0x432, 0x435, 0x442
-    };
-
-    static final int[] RUSSIAN_STUFF_UTF8 = {
-        0xD0, 0x92, 0xD1, 0x81, 0xD0, 0xB5, 0xD0, 0xBC, 0x5F,
-        0xD0, 0xBF, 0xD1, 0x80, 0xD0, 0xB8, 0xD0, 0xB2, 0xD0,
-        0xB5, 0xD1, 0x82
-    };
-
-    static final int[] RUSSIAN_STUFF_KOI8R = {
-        0xF7, 0xD3, 0xC5, 0xCD, 0x5F, 0xD0, 0xD2, 0xC9, 0xD7,
-        0xC5, 0xD4
-    };
-
-    static final int[] RUSSIAN_STUFF_WIN1251 = {
-        0xC2, 0xF1, 0xE5, 0xEC, 0x5F, 0xEF, 0xF0, 0xE8, 0xE2,
-        0xE5, 0xF2
-    };
-
-    private static String constructString(final int[] unicodeChars) {
-        final StringBuilder buffer = new StringBuilder();
-        if (unicodeChars != null) {
-            for (final int unicodeChar : unicodeChars) {
-                buffer.append((char) unicodeChar);
-            }
-        }
-        return buffer.toString();
-    }
-
-    /**
-     * Test construction of content charset.
-     */
-    public void testContentCharSet() throws Exception {
-        final FileItemFactory factory = createFactory(null);
-
-        String teststr = constructString(SWISS_GERMAN_STUFF_UNICODE);
-
-        FileItem item =
-            factory.createItem(
-                "doesnotmatter",
-                "text/plain; charset=" + CHARSET_ISO88591,
-                true,
-                null);
-        OutputStream outstream = item.getOutputStream();
-        for (final int element : SWISS_GERMAN_STUFF_ISO8859_1) {
-            outstream.write(element);
-        }
-        outstream.close();
-        assertEquals(teststr, teststr, item.getString());
-
-        item =
-            factory.createItem(
-                "doesnotmatter",
-                "text/plain; charset=" + CHARSET_UTF8,
-                true,
-                null);
-        outstream = item.getOutputStream();
-        for (final int element : SWISS_GERMAN_STUFF_UTF8) {
-            outstream.write(element);
-        }
-        outstream.close();
-        assertEquals(teststr, teststr, item.getString());
-
-        teststr = constructString(RUSSIAN_STUFF_UNICODE);
-
-        item =
-            factory.createItem(
-                "doesnotmatter",
-                "text/plain; charset=" + CHARSET_KOI8_R,
-                true,
-                null);
-        outstream = item.getOutputStream();
-        for (final int element : RUSSIAN_STUFF_KOI8R) {
-            outstream.write(element);
-        }
-        outstream.close();
-        assertEquals(teststr, teststr, item.getString());
-
-        item =
-            factory.createItem(
-                "doesnotmatter",
-                "text/plain; charset=" + CHARSET_WIN1251,
-                true,
-                null);
-        outstream = item.getOutputStream();
-        for (final int element : RUSSIAN_STUFF_WIN1251) {
-            outstream.write(element);
-        }
-        outstream.close();
-        assertEquals(teststr, teststr, item.getString());
-
-        item =
-            factory.createItem(
-                "doesnotmatter",
-                "text/plain; charset=" + CHARSET_UTF8,
-                true,
-                null);
-        outstream = item.getOutputStream();
-        for (final int element : RUSSIAN_STUFF_UTF8) {
-            outstream.write(element);
-        }
-        outstream.close();
-        assertEquals(teststr, teststr, item.getString());
-    }
-
-}
diff --git 
a/src/test/java/org/apache/commons/fileupload2/DiskFileUploadTest.java 
b/src/test/java/org/apache/commons/fileupload2/DiskFileUploadTest.java
deleted file mode 100644
index eb18dad..0000000
--- a/src/test/java/org/apache/commons/fileupload2/DiskFileUploadTest.java
+++ /dev/null
@@ -1,100 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements.  See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * 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.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.commons.fileupload2;
-
-
-import java.io.File;
-import java.nio.charset.StandardCharsets;
-import java.util.List;
-
-import javax.servlet.http.HttpServletRequest;
-
-import org.apache.commons.fileupload2.disk.DiskFileItem;
-import org.apache.commons.fileupload2.pub.InvalidContentTypeException;
-import org.junit.jupiter.api.BeforeEach;
-import org.junit.jupiter.api.Test;
-
-import static org.junit.jupiter.api.Assertions.assertFalse;
-import static org.junit.jupiter.api.Assertions.assertNotNull;
-import static org.junit.jupiter.api.Assertions.fail;
-
-/**
- * Test for {@link DiskFileUpload}. Remove when deprecated class is removed.
- *
- * @since 1.4
- */
-@SuppressWarnings({"deprecation"}) // unit tests for deprecated class
-public class DiskFileUploadTest {
-
-    private DiskFileUpload upload;
-
-    @BeforeEach
-    public void setUp() {
-        upload = new DiskFileUpload();
-    }
-
-    @Test
-    public void testWithInvalidRequest() {
-        final HttpServletRequest req = 
HttpServletRequestFactory.createInvalidHttpServletRequest();
-
-        try {
-            upload.parseRequest(req);
-            fail("testWithInvalidRequest: expected exception was not thrown");
-        } catch (final FileUploadException expected) {
-            // this exception is expected
-        }
-    }
-
-    @Test
-    public void testWithNullContentType() {
-        final HttpServletRequest req = 
HttpServletRequestFactory.createHttpServletRequestWithNullContentType();
-
-        try {
-            upload.parseRequest(req);
-            fail("testWithNullContentType: expected exception was not thrown");
-        } catch (final InvalidContentTypeException expected) {
-            // this exception is expected
-        } catch (final FileUploadException unexpected) {
-            fail("testWithNullContentType: unexpected exception was thrown");
-        }
-    }
-
-    /** Proposed test for FILEUPLOAD-293. As of yet, doesn't reproduce the 
problem.
-     */
-    @Test
-    public void testMoveFile() throws Exception {
-        final DiskFileUpload myUpload = new DiskFileUpload();
-        myUpload.setSizeThreshold(0);
-        final String content =
-                "-----1234\r\n" +
-                "Content-Disposition: form-data; name=\"file\";"
-                        + "filename=\"foo.tab\"\r\n" +
-                "Content-Type: text/whatever\r\n" +
-                "\r\n" +
-                "This is the content of the file\n" +
-                "\r\n" +
-                "-----1234--\r\n";
-        final byte[] contentBytes = 
content.getBytes(StandardCharsets.US_ASCII);
-        final HttpServletRequest request = new 
MockHttpServletRequest(contentBytes, Constants.CONTENT_TYPE);
-        final List<FileItem> items = myUpload.parseRequest(request);
-        assertNotNull(items);
-        assertFalse(items.isEmpty());
-        final DiskFileItem dfi = (DiskFileItem) items.get(0);
-        final File out = File.createTempFile("install", ".tmp");
-        dfi.write(out);
-    }
-}

Reply via email to