This is an automated email from the ASF dual-hosted git repository. markt pushed a commit to branch 9.0.x in repository https://gitbox.apache.org/repos/asf/tomcat.git
commit 9ba3b0c57fff311cd898716db19e508183545b28 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 -- .../http/fileupload/servlet/ServletFileUpload.java | 136 --------------------- .../tomcat/util/http/fileupload/util/Streams.java | 35 ------ 8 files changed, 5 insertions(+), 278 deletions(-) diff --git a/MERGE.txt b/MERGE.txt index b73dfeeb8e..0ee5ce424b 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 @@ rel/commons-bcel-6.8.2 (2024-02-25) 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 67ad9e5ca3..c28a9bf216 100644 --- a/java/org/apache/catalina/connector/Request.java +++ b/java/org/apache/catalina/connector/Request.java @@ -109,10 +109,10 @@ import org.apache.tomcat.util.http.Rfc6265CookieProcessor; 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; @@ -2607,7 +2607,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 c17eb978af..b9f5cfe174 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; @@ -49,30 +48,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 /** @@ -343,34 +318,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/servlet/ServletFileUpload.java b/java/org/apache/tomcat/util/http/fileupload/servlet/ServletFileUpload.java deleted file mode 100644 index e2d074c3df..0000000000 --- a/java/org/apache/tomcat/util/http/fileupload/servlet/ServletFileUpload.java +++ /dev/null @@ -1,136 +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 javax.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 ed83840d90..7289d06665 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,40 +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-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org