You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2022/06/17 13:03:43 UTC

[tomcat] 03/06: Remove unused code - thanks to UCDetector

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

markt pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tomcat.git

commit 01763b4ee77e7751f40deb0920f116e65b0b5a91
Author: Mark Thomas <ma...@apache.org>
AuthorDate: Fri Jun 17 12:46:38 2022 +0100

    Remove unused code - thanks to UCDetector
---
 MERGE.txt                                          |   3 +
 java/org/apache/catalina/connector/Request.java    |   4 +-
 .../http/fileupload/ByteArrayOutputStream.java     |  29 -----
 .../tomcat/util/http/fileupload/FileUpload.java    |  13 --
 .../util/http/fileupload/FileUploadBase.java       |  53 --------
 .../util/http/fileupload/FileUploadException.java  |  10 --
 .../util/http/fileupload/MultipartStream.java      |  21 ----
 .../http/fileupload/servlet/ServletFileUpload.java | 137 ---------------------
 .../tomcat/util/http/fileupload/util/Streams.java  |  36 ------
 9 files changed, 5 insertions(+), 301 deletions(-)

diff --git a/MERGE.txt b/MERGE.txt
index e1403d4853..fd18d82c80 100644
--- a/MERGE.txt
+++ b/MERGE.txt
@@ -33,6 +33,7 @@ the patch file has been applied and committed
 
 BCEL
 ----
+Unused code is removed
 Sub-tree:
 src/main/java/org/apache/bcel
 The SHA1 ID / tag for the most recent commit to be merged to Tomcat is:
@@ -40,6 +41,7 @@ The SHA1 ID / tag for the most recent commit to be merged to Tomcat is:
 
 Codec
 -----
+Unused code is removed
 Sub-tree:
 src/main/java/org/apache/commons/codec
 The SHA1 ID / tag for the most recent commit to be merged to Tomcat is:
@@ -48,6 +50,7 @@ Note: Only classes required for Base64 encoding/decoding. The rest are removed.
 
 FileUpload
 ----------
+Unused code is removed
 Sub-tree:
 src/main/java/org/apache/commons/fileupload2
 The SHA1 ID / tag for the most recent commit to be merged to Tomcat is:
diff --git a/java/org/apache/catalina/connector/Request.java b/java/org/apache/catalina/connector/Request.java
index 72f308aa99..40475e8fc5 100644
--- a/java/org/apache/catalina/connector/Request.java
+++ b/java/org/apache/catalina/connector/Request.java
@@ -106,10 +106,10 @@ import org.apache.tomcat.util.http.Parameters.FailReason;
 import org.apache.tomcat.util.http.ServerCookie;
 import org.apache.tomcat.util.http.ServerCookies;
 import org.apache.tomcat.util.http.fileupload.FileItem;
+import org.apache.tomcat.util.http.fileupload.FileUpload;
 import org.apache.tomcat.util.http.fileupload.disk.DiskFileItemFactory;
 import org.apache.tomcat.util.http.fileupload.impl.InvalidContentTypeException;
 import org.apache.tomcat.util.http.fileupload.impl.SizeException;
-import org.apache.tomcat.util.http.fileupload.servlet.ServletFileUpload;
 import org.apache.tomcat.util.http.fileupload.servlet.ServletRequestContext;
 import org.apache.tomcat.util.http.parser.AcceptLanguage;
 import org.apache.tomcat.util.http.parser.Upgrade;
@@ -2865,7 +2865,7 @@ public class Request implements HttpServletRequest {
             }
             factory.setSizeThreshold(mce.getFileSizeThreshold());
 
-            ServletFileUpload upload = new ServletFileUpload();
+            FileUpload upload = new FileUpload();
             upload.setFileItemFactory(factory);
             upload.setFileSizeMax(mce.getMaxFileSize());
             upload.setSizeMax(mce.getMaxRequestSize());
diff --git a/java/org/apache/tomcat/util/http/fileupload/ByteArrayOutputStream.java b/java/org/apache/tomcat/util/http/fileupload/ByteArrayOutputStream.java
index 5cc26df6ef..aaee63f112 100644
--- a/java/org/apache/tomcat/util/http/fileupload/ByteArrayOutputStream.java
+++ b/java/org/apache/tomcat/util/http/fileupload/ByteArrayOutputStream.java
@@ -17,7 +17,6 @@
 package org.apache.tomcat.util.http.fileupload;
 
 import java.io.IOException;
-import java.io.InputStream;
 import java.io.OutputStream;
 import java.util.ArrayList;
 import java.util.List;
@@ -167,34 +166,6 @@ public class ByteArrayOutputStream extends OutputStream {
         count++;
     }
 
-    /**
-     * Writes the entire contents of the specified input stream to this
-     * byte stream. Bytes from the input stream are read directly into the
-     * internal buffers of this streams.
-     *
-     * @param in the input stream to read from
-     * @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 1.4
-     */
-    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);
-        while (n != -1) {
-            readCount += n;
-            inBufferPos += n;
-            count += n;
-            if (inBufferPos == currentBuffer.length) {
-                needNewBuffer(currentBuffer.length);
-                inBufferPos = 0;
-            }
-            n = in.read(currentBuffer, inBufferPos, currentBuffer.length - inBufferPos);
-        }
-        return readCount;
-    }
-
     /**
      * Closing a {@code ByteArrayOutputStream} has no effect. The methods in
      * this class can be called after the stream has been closed without
diff --git a/java/org/apache/tomcat/util/http/fileupload/FileUpload.java b/java/org/apache/tomcat/util/http/fileupload/FileUpload.java
index f0cfebcf08..06846f18d6 100644
--- a/java/org/apache/tomcat/util/http/fileupload/FileUpload.java
+++ b/java/org/apache/tomcat/util/http/fileupload/FileUpload.java
@@ -48,23 +48,10 @@ public class FileUpload
      * A factory must be
      * configured, using {@code setFileItemFactory()}, before attempting
      * to parse requests.
-     *
-     * @see #FileUpload(FileItemFactory)
      */
     public FileUpload() {
     }
 
-    /**
-     * Constructs an instance of this class which uses the supplied factory to
-     * create {@code FileItem} instances.
-     *
-     * @see #FileUpload()
-     * @param fileItemFactory The factory to use for creating file items.
-     */
-    public FileUpload(final FileItemFactory fileItemFactory) {
-        this.fileItemFactory = fileItemFactory;
-    }
-
     // ----------------------------------------------------- Property accessors
 
     /**
diff --git a/java/org/apache/tomcat/util/http/fileupload/FileUploadBase.java b/java/org/apache/tomcat/util/http/fileupload/FileUploadBase.java
index 7d678c24d8..45c4fb93c0 100644
--- a/java/org/apache/tomcat/util/http/fileupload/FileUploadBase.java
+++ b/java/org/apache/tomcat/util/http/fileupload/FileUploadBase.java
@@ -19,7 +19,6 @@ package org.apache.tomcat.util.http.fileupload;
 import java.io.IOException;
 import java.nio.charset.StandardCharsets;
 import java.util.ArrayList;
-import java.util.HashMap;
 import java.util.List;
 import java.util.Locale;
 import java.util.Map;
@@ -48,30 +47,6 @@ import org.apache.tomcat.util.http.fileupload.util.Streams;
  */
 public abstract class FileUploadBase {
 
-    // ---------------------------------------------------------- Class methods
-
-    /**
-     * <p>Utility method that determines whether the request contains multipart
-     * content.</p>
-     *
-     * <p><strong>NOTE:</strong>This method will be moved to the
-     * {@code ServletFileUpload} class after the FileUpload 1.1 release.
-     * Unfortunately, since this method is static, it is not possible to
-     * provide its replacement until this method is removed.</p>
-     *
-     * @param ctx The request context to be evaluated. Must be non-null.
-     *
-     * @return {@code true} if the request is multipart;
-     *         {@code false} otherwise.
-     */
-    public static final boolean isMultipartContent(final RequestContext ctx) {
-        final String contentType = ctx.getContentType();
-        if (contentType == null) {
-            return false;
-        }
-        return contentType.toLowerCase(Locale.ENGLISH).startsWith(MULTIPART);
-    }
-
     // ----------------------------------------------------- Manifest constants
 
     /**
@@ -314,34 +289,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 ctx The context for the request to be parsed.
-     *
-     * @return A map of {@code FileItem} instances parsed from the request.
-     *
-     * @throws FileUploadException if there are problems reading/parsing
-     *                             the request or storing files.
-     *
-     * @since 1.3
-     */
-    public Map<String, List<FileItem>> parseParameterMap(final RequestContext ctx)
-            throws FileUploadException {
-        final List<FileItem> items = parseRequest(ctx);
-        final Map<String, List<FileItem>> itemsMap = new HashMap<>(items.size());
-
-        for (final FileItem fileItem : items) {
-            final String fieldName = fileItem.getFieldName();
-            List<FileItem> mappedItems = itemsMap.computeIfAbsent(fieldName, k -> new ArrayList<>());
-
-            mappedItems.add(fileItem);
-        }
-
-        return itemsMap;
-    }
-
     // ------------------------------------------------------ Protected methods
 
     /**
diff --git a/java/org/apache/tomcat/util/http/fileupload/FileUploadException.java b/java/org/apache/tomcat/util/http/fileupload/FileUploadException.java
index 47b8230217..d7a8d11819 100644
--- a/java/org/apache/tomcat/util/http/fileupload/FileUploadException.java
+++ b/java/org/apache/tomcat/util/http/fileupload/FileUploadException.java
@@ -52,14 +52,4 @@ public class FileUploadException extends IOException {
     public FileUploadException(final String msg, final Throwable cause) {
         super(msg, cause);
     }
-
-    /**
-     * Creates a new {@code FileUploadException} with the given
-     * cause.
-     *
-     * @param cause The exceptions cause.
-     */
-    public FileUploadException(final Throwable cause) {
-        super(cause);
-    }
 }
diff --git a/java/org/apache/tomcat/util/http/fileupload/MultipartStream.java b/java/org/apache/tomcat/util/http/fileupload/MultipartStream.java
index ab6e8e58ad..d38eb379d5 100644
--- a/java/org/apache/tomcat/util/http/fileupload/MultipartStream.java
+++ b/java/org/apache/tomcat/util/http/fileupload/MultipartStream.java
@@ -650,27 +650,6 @@ public class MultipartStream {
         return true;
     }
 
-    /**
-     * Searches for a byte of specified value in the {@code buffer},
-     * starting at the specified {@code position}.
-     *
-     * @param value The value to find.
-     * @param pos   The starting position for searching.
-     *
-     * @return The position of byte found, counting from beginning of the
-     *         {@code buffer}, or {@code -1} if not found.
-     */
-    protected int findByte(final byte value,
-            final int pos) {
-        for (int i = pos; i < tail; i++) {
-            if (buffer[i] == value) {
-                return i;
-            }
-        }
-
-        return -1;
-    }
-
     /**
      * Searches for the {@code boundary} in the {@code buffer}
      * region delimited by {@code head} and {@code tail}.
diff --git a/java/org/apache/tomcat/util/http/fileupload/servlet/ServletFileUpload.java b/java/org/apache/tomcat/util/http/fileupload/servlet/ServletFileUpload.java
deleted file mode 100644
index da07201538..0000000000
--- a/java/org/apache/tomcat/util/http/fileupload/servlet/ServletFileUpload.java
+++ /dev/null
@@ -1,137 +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.tomcat.util.http.fileupload.servlet;
-
-import java.io.IOException;
-import java.util.List;
-import java.util.Map;
-
-import jakarta.servlet.http.HttpServletRequest;
-
-import org.apache.tomcat.util.http.fileupload.FileItem;
-import org.apache.tomcat.util.http.fileupload.FileItemFactory;
-import org.apache.tomcat.util.http.fileupload.FileItemIterator;
-import org.apache.tomcat.util.http.fileupload.FileUpload;
-import org.apache.tomcat.util.http.fileupload.FileUploadBase;
-import org.apache.tomcat.util.http.fileupload.FileUploadException;
-
-
-/**
- * <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(org.apache.tomcat.util.http.fileupload.RequestContext)} to
- * acquire a list of {@link org.apache.tomcat.util.http.fileupload.FileItem}s
- * associated with a given HTML widget.</p>
- *
- * <p>How the data for individual parts is stored is determined by the factory
- * used to create them; a given part may be in memory, on disk, or somewhere
- * else.</p>
- */
-public class ServletFileUpload extends FileUpload {
-
-    /**
-     * Constant for HTTP POST method.
-     */
-    private static final String POST_METHOD = "POST";
-
-    // ---------------------------------------------------------- Class methods
-
-    /**
-     * Utility method that determines whether the request contains multipart
-     * content.
-     *
-     * @param request The servlet request to be evaluated. Must be non-null.
-     *
-     * @return {@code true} if the request is multipart;
-     *         {@code false} otherwise.
-     */
-    public static final boolean isMultipartContent(
-            final HttpServletRequest request) {
-        if (!POST_METHOD.equalsIgnoreCase(request.getMethod())) {
-            return false;
-        }
-        return FileUploadBase.isMultipartContent(new ServletRequestContext(request));
-    }
-
-    // ----------------------------------------------------------- Constructors
-
-    /**
-     * Constructs an uninitialized instance of this class. A factory must be
-     * configured, using {@code setFileItemFactory()}, before attempting
-     * to parse requests.
-     *
-     * @see FileUpload#FileUpload(FileItemFactory)
-     */
-    public ServletFileUpload() {
-    }
-
-    /**
-     * Constructs an instance of this class which uses the supplied factory to
-     * create {@code FileItem} instances.
-     *
-     * @see FileUpload#FileUpload()
-     * @param fileItemFactory The factory to use for creating file items.
-     */
-    public ServletFileUpload(final FileItemFactory fileItemFactory) {
-        super(fileItemFactory);
-    }
-
-    // --------------------------------------------------------- Public methods
-
-    /**
-     * Processes an <a href="http://www.ietf.org/rfc/rfc1867.txt">RFC 1867</a>
-     * compliant {@code multipart/form-data} stream.
-     *
-     * @param request The servlet request to be parsed.
-     *
-     * @return A map of {@code FileItem} instances parsed from the request.
-     *
-     * @throws FileUploadException if there are problems reading/parsing
-     *                             the request or storing files.
-     *
-     * @since 1.3
-     */
-    public Map<String, List<FileItem>> parseParameterMap(final HttpServletRequest request)
-            throws FileUploadException {
-        return parseParameterMap(new ServletRequestContext(request));
-    }
-
-    /**
-     * Processes an <a href="http://www.ietf.org/rfc/rfc1867.txt">RFC 1867</a>
-     * compliant {@code multipart/form-data} stream.
-     *
-     * @param request The servlet request to be parsed.
-     *
-     * @return An iterator to instances of {@code FileItemStream}
-     *         parsed from the request, in the order that they were
-     *         transmitted.
-     *
-     * @throws FileUploadException if there are problems reading/parsing
-     *                             the request or storing files.
-     * @throws IOException An I/O error occurred. This may be a network
-     *   error while communicating with the client or a problem while
-     *   storing the uploaded content.
-     */
-    public FileItemIterator getItemIterator(final HttpServletRequest request)
-    throws FileUploadException, IOException {
-        return super.getItemIterator(new ServletRequestContext(request));
-    }
-
-}
diff --git a/java/org/apache/tomcat/util/http/fileupload/util/Streams.java b/java/org/apache/tomcat/util/http/fileupload/util/Streams.java
index 03c1f90486..5fe3314bce 100644
--- a/java/org/apache/tomcat/util/http/fileupload/util/Streams.java
+++ b/java/org/apache/tomcat/util/http/fileupload/util/Streams.java
@@ -16,7 +16,6 @@
  */
 package org.apache.tomcat.util.http.fileupload.util;
 
-import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
@@ -117,41 +116,6 @@ public final class Streams {
         }
     }
 
-    /**
-     * This convenience method allows to read a
-     * {@link org.apache.tomcat.util.http.fileupload.FileItemStream}'s
-     * content into a string. The platform's default character encoding
-     * is used for converting bytes into characters.
-     *
-     * @param inputStream The input stream to read.
-     * @see #asString(InputStream, String)
-     * @return The streams contents, as a string.
-     * @throws IOException An I/O error occurred.
-     */
-    public static String asString(final InputStream inputStream) throws IOException {
-        final ByteArrayOutputStream baos = new ByteArrayOutputStream();
-        copy(inputStream, baos, true);
-        return baos.toString();
-    }
-
-    /**
-     * This convenience method allows to read a
-     * {@link org.apache.tomcat.util.http.fileupload.FileItemStream}'s
-     * content into a string, using the given character encoding.
-     *
-     * @param inputStream The input stream to read.
-     * @param encoding The character encoding, typically "UTF-8".
-     * @see #asString(InputStream)
-     * @return The streams contents, as a string.
-     * @throws IOException An I/O error occurred.
-     */
-    public static String asString(final InputStream inputStream, final String encoding)
-            throws IOException {
-        final ByteArrayOutputStream baos = new ByteArrayOutputStream();
-        copy(inputStream, baos, true);
-        return baos.toString(encoding);
-    }
-
     /**
      * Checks, whether the given file name is valid in the sense,
      * that it doesn't contain any NUL characters. If the file name


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