libcommons-fileupload2-java-2.0.0~M5/0000755000175000017500000000000015142145735016107 5ustar zigozigolibcommons-fileupload2-java-2.0.0~M5/RELEASE-NOTES.txt0000644000175000017500000005714315142145735020630 0ustar zigozigoApache Commons FileUpload 2.0.0-M5 Release Notes ------------------------------------------------ The Apache Commons FileUpload team is pleased to announce the release of Apache Commons FileUpload 2.0.0-M5. The Apache Commons FileUpload component provides a simple yet flexible means of adding support for multipart file upload functionality to Servlets and web applications. This version requires Java 11 or above. This release requires Java 11. Changes in version 2.0.0-M5 include: New features: o Add AbstractFileUpload support for a maximum part header size #429. Thanks to Ryan J Murphy. o FILEUPLOAD-367: Jakarta and Javax ServletFileUpload.isMultipartContent(HttpServletRequest) should allow PUT and PATCH request methods in addition to POST. Thanks to Gary Gregory. o FILEUPLOAD-367: Add AbstractFileUpload.isMultipartRequestMethod(String). Thanks to Gary Gregory. Fixed Bugs: o Better exception message in org.apache.commons.fileupload2.core.AbstractFileUpload.parseRequest(RequestContext). Thanks to Chenjp, Gary Gregory. o FILEUPLOAD-295: Clarified the precise meaning of isInMemory(), get(), getPath(), etc. in DiskFileItem o Better exception type and message if a multipart/mixed part is presented without a boundary defined Thanks to Coverity Scan. o Rename MultipartInput.Builder.[get|set]PartHeaderSizeMax() to [get|set]MaxPartHeaderSize(). Thanks to Gary Gregory. o Rename MultipartInput.getPartHeaderSizeMax() to getMaxPartHeaderSize(). Thanks to Gary Gregory. o Rename AbstractFileUpload.[get|set]SizeMax() to AbstractFileUpload.[get|set]MaxSize(). Thanks to Gary Gregory. o Rename AbstractFileUpload.[get|set]FileSizeMax() to AbstractFileUpload.[get|set]MaxFileSize(). Thanks to Gary Gregory. o Rename AbstractFileUpload.[get|set]FileCountMax() to AbstractFileUpload.[get|set]MaxFileCount(). Thanks to Gary Gregory. o Minor readability and cleanup improvements in DiskFileItem #458. Thanks to tPionTech. o Fix Apache RAT plugin console warnings. Thanks to Gary Gregory. Changes: o Bump org.apache.commons:commons-parent from 84 to 96 #444, #459, #463. Thanks to Gary Gregory, Dependabot. o Bump org.apache.commons:commons-lang3 from 3.17.0 to 3.20.0 #427. Thanks to Gary Gregory. o Bump commons-io:commons-io from 2.19.0 to 2.21.0. Thanks to Gary Gregory. For complete information on Apache Commons FileUpload, including instructions on how to submit bug reports, patches, or suggestions for improvement, see the Apache Commons FileUpload website: https://commons.apache.org/proper/commons-fileupload/ Download it from https://commons.apache.org/proper/commons-fileupload/download_fileupload.cgi ------------------------------------------------------------------------------ Apache Commons FileUpload 2.0.0-M4 Release Notes ------------------------------------------------ The Apache Commons FileUpload team is pleased to announce the release of Apache Commons FileUpload 2.0.0-M4. The Apache Commons FileUpload component provides a simple yet flexible means of adding support for multipart file upload functionality to Servlets and web applications. This version requires Java 11 or above. This release requires Java 11. Changes in version 2.0.0-M4 include: New features: o SECURITY - CVE-2025-48976. Add partHeaderSizeMax, a new limit that sets a maximum number of bytes for each individual multipart header. The default is 512 bytes. Thanks to Mark Thomas. Fixed Bugs: o Simplify exception handling in FileItem API #309. Thanks to Basil Crow. For complete information on Apache Commons FileUpload, including instructions on how to submit bug reports, patches, or suggestions for improvement, see the Apache Commons FileUpload website: https://commons.apache.org/proper/commons-fileupload/ Download it from https://commons.apache.org/proper/commons-fileupload/download_fileupload.cgi ------------------------------------------------------------------------------ Apache Commons FileUpload 2.0.0-M3 Release Notes ------------------------------------------------ The Apache Commons FileUpload team is pleased to announce the release of Apache Commons FileUpload 2.0.0-M3. The Apache Commons FileUpload component provides a simple yet flexible means of adding support for multipart file upload functionality to Servlets and web applications. This version requires Java 11 or above. This release requires Java 11. Changes in version 2.0.0-M3 include: New features: o Handle multipart/related Requests without content-disposition header. Thanks to mufasa1976, Gary Gregory. Fixed Bugs: o [site] Fix instantiation of DiskFileItemFactory in migration guide #273. Thanks to Gregor Dschung. o FILEUPLOAD-355: [site] Update code example: Use IOUtils instead of Streams utils class. Thanks to Ana, Gary Gregory. o Replace internal use of Locale.ENGLISH with Locale.ROOT. Thanks to Gary Gregory. o Pick up JUnit version from parent POM. Thanks to Gary Gregory. o FILEUPLOAD-356: [site] Fix incorrect link to changes report in Commons FileUpload #357. Thanks to Mattias Reichel, GirirajSinghRathore, Gary Gregory. o Fix changes report link for new version of Maven Changes plugin from commons-parent 79 #388. Thanks to Filipe Roque. o Fix SpotBugs multithreading issues in DiskFileItem. Thanks to Gary Gregory. Changes: o Bump org.apache.commons:commons-parent from 66 to 83 #283, #294, #335, #343, #345, #351, #356, #360, #368. Thanks to Gary Gregory. o Bump commons-io:commons-io from 2.16.0 to 2.19.0 #297, #352, #377. Thanks to Gary Gregory. o Bump org.apache.maven.plugins:maven-javadoc-plugin from 3.6.3 to 3.7.0 #319. Thanks to Gary Gregory. o Bump org.codehaus.mojo:taglist-maven-plugin from 3.0.0 to 3.1.0 #327. Thanks to Gary Gregory. o Bump org.apache.commons:commons-lang3 from 3.14.0 to 3.17.0 #331, #338, #346. Thanks to Gary Gregory. For complete information on Apache Commons FileUpload, including instructions on how to submit bug reports, patches, or suggestions for improvement, see the Apache Commons FileUpload website: https://commons.apache.org/proper/commons-fileupload/ Download it from https://commons.apache.org/proper/commons-fileupload/download_fileupload.cgi ------------------------------------------------------------------------------ Apache Commons FileUpload 2.0.0-M2 Release Notes ------------------------------------------------ The Apache Commons FileUpload team is pleased to announce the release of Apache Commons FileUpload 2.0.0-M2. The Apache Commons FileUpload component provides a simple yet flexible means of adding support for multipart file upload functionality to Servlets and web applications. This version requires Java 11 or above. 2.0.0-M2 Release Changes in version 2.0.0-M2 include: New features: o Fix off-by-one error when checking fileSizeMax in FileItemInputImpl #235. Thanks to James Reeves. o FILEUPLOAD-352: NullPointerException in DiskFileItem#toString. Thanks to Bj�rn Kautler, Gary Gregory. o Fail fast on null inputs to org.apache.commons.fileupload2.core.AbstractRequestContext.AbstractRequestContext(Function, LongSupplier, T). Thanks to Gary Gregory. o Complete refactoring in JakartaServletRequestContext. Thanks to Gary Gregory. o Fix "Implicit narrowing conversion in compound assignment" from https://github.com/apache/commons-fileupload/security/code-scanning/118. Thanks to Gary Gregory. o Refactor to support Jakarta Servlet 5 and 6. Thanks to Gary Gregory. o Generate some OSGi metadata. Thanks to Michal H Siemaszko, Gary Gregory. Fixed Bugs: o Pick up Maven Moditect plugin version from parent POM. Thanks to Gary Gregory. Changes: o Bump Java from 8 to 11. Thanks to Dependabot. o Bump commons-parent from 58 to 65. Thanks to Gary Gregory. o Bump commons-lang3 from 3.12.0 to 3.14.0. Thanks to Gary Gregory. o Bump commons-io from 2.13.0 to 2.15.1. Thanks to Gary Gregory. For complete information on Apache Commons FileUpload, including instructions on how to submit bug reports, patches, or suggestions for improvement, see the Apache Commons FileUpload website: https://commons.apache.org/proper/commons-fileupload/ Download it from https://commons.apache.org/proper/commons-fileupload/download_fileupload.cgi ------------------------------------------------------------------------------ Apache Commons FileUpload 2.0.0-M1 Release Notes ------------------------------------------------ The Apache Commons FileUpload Parent team is pleased to announce the release of Apache Commons FileUpload Parent 2.0.0-M1. The Apache Commons FileUpload component provides a simple yet flexible means of adding support for multipart file upload functionality to servlets and web applications. This version requires Java 11 or later. Note also that the base package name has changed to org.apache.commons.fileupload2, so source changes will be required. The Maven coordinates have also changed to: org.apache.commons commons-fileupload2 They were previously: commons-fileupload commons-fileupload 2.0.0-M1 Release Changes in version 2.0.0-M1 include: New features: o Add github/codeql-action from #144. Thanks to Gary Gregory. o Add the package org.apache.fileupload2.jaksrvlt, for compliance with Jakarta Servlet API 5.0. o Making FileUploadException a subclass of IOException. (Mibor API simplification.) o Add a configurable limit (disabled by default) for the number of files to upload per request. Fixed Bugs: o Changing Maven coordinates, and package name, due to binary incompatible changes. o FILEUPLOAD-293: DiskFileItem.write(File) had been changed to use FileUtils.moveFile internally, preventing an existing file as the target. o FILEUPLOAD-296: Performance gains by reusing an internal buffer. Thanks to David Georg Reochelt. o FILEUPLOAD-274: RFC 5987 compliance Thanks to Merbin J Anselm. o Slight optim: resuse the index position instead of recomputing it #49. Thanks to Emmanuel L�charny. o FILEUPLOAD-340: Make commons-fileupload2 a JPMS module by adding module-info.class. o FILEUPLOAD-341: Move Exception classes out of the impl package. Thanks to Martin Grigorov. o Rework exceptions to use propagated exception causes (introduced in Java 1.4). Thanks to Gary Gregory. o All custom exception extend FileUploadException. Thanks to Gary Gregory. o All custom exceptions serialVersionUID value is now 2. Thanks to Gary Gregory. o FILEUPLOAD-350: FileUploadByteCountLimitException ctor switches fileName and fieldName parameters #216. Thanks to Ernesto Reinaldo Barreiro. o [StepSecurity] ci: Harden GitHub Actions #224. Thanks to step-security-bot, Gary Gregory. Changes: o Bump actions/cache from 2.1.6 to 3.0.8 #128, #140. Thanks to Dependabot, Gary Gregory. o Bump actions/checkout from 2.3.4 to 3.0.2 #125. Thanks to Dependabot, Gary Gregory. o Bump build actions/setup-java from 1.4.3 to 3.8.0 #142, #175, #180, #182. Thanks to Gary Gregory. o Bump Java compiler level to 1.8. o Bump commons-io:commons-io 2.6 to 2.13.0, #104, #221. Thanks to Gary Gregory, Dependabot. o Bump junit-jupiter from 5.5.2 to 5.9.1 #31, #130, #156, #166. Thanks to Dependabot. o Bump maven-pmd-plugin from 3.13.0 to 3.19.0 #48, #162. Thanks to Dependabot. o Bump commons.japicmp.version from 0.13.0 to 0.16.0. Thanks to Gary Gregory. o Bump spotbugs-maven-plugin from 4.2.3 to 4.7.3.0 #103, #133, #141, #146, #155, #163, #179. Thanks to Dependabot. o Bump spotbugs from 4.2.3 to 4.7.3, ignore EI_EXPOSE_REP, and EI_EXPOSE_REP2, #152, #161, #174. Thanks to Dependabot. o Bump biz.aQute.bndlib from 6.0.0 to 6.4.0 #129, #181. Thanks to Dependabot. o Bump commons-parent from 52 to 58, #167, #183, #194. Thanks to Gary Gregory, Dependabot. o Bump maven-checkstyle-plugin from 3.1.2 to 3.2.0 #160. Thanks to Dependabot. Removed: o Remove deprecated constructors in MultipartStream. Thanks to Gary Gregory. o Remove deprecated RequestContext.getContentLength(). Thanks to Gary Gregory. o Remove deprecated JakSrvltRequestContext.getContentLength(). Thanks to Gary Gregory. o Remove deprecated PortletRequestContext.getContentLength(). Thanks to Gary Gregory. o Remove deprecated ServletRequestContext.getContentLength(). Thanks to Gary Gregory. o Remove deprecated FileUploadBase.MAX_HEADER_SIZE. Thanks to Gary Gregory. o Remove deprecated FileUploadBase.createItem(Map, boolean). Thanks to Gary Gregory. o Remove deprecated FileUploadBase.getFieldName(Map). Thanks to Gary Gregory. o Remove deprecated FileUploadBase.getFileName(Map). Thanks to Gary Gregory. o Remove deprecated FileUploadBase.getHeader(Map, String). Thanks to Gary Gregory. o Remove deprecated FileUploadBase.parseHeaders(String). Thanks to Gary Gregory. o Replace org.apache.commons.fileupload2.util.mime.Base64Decoder with java.util.Base64. Thanks to Gary Gregory. o Replace LimitedInputStream with BoundedInputStream. Thanks to Gary Gregory. o FileItemHeadersImpl is no longer Serializable. Thanks to Gary Gregory. o Reuse Java's InvalidPathException instead of the custom InvalidFileNameException. Thanks to Gary Gregory. For complete information on Apache Commons FileUpload Parent, including instructions on how to submit bug reports, patches, or suggestions for improvement, see the Apache Commons FileUpload Parent website: https://commons.apache.org/proper/commons-fileupload/ ------------------------------------------------------------------------------ Apache Commons FileUpload 1.6.0 Release Notes --------------------------------------------- The Apache Commons FileUpload team is pleased to announce the release of Apache Commons FileUpload 1.6.0. The Apache Commons FileUpload component provides a simple yet flexible means of adding support for multipart file upload functionality to servlets and web applications. This release requires Java 8. Changes in this version include: New features: o [1.x] Enable multipart/related on FileUpload #314. Thanks to mufasa1976, Jochen Wiedmann, Gary Gregory. o Add JApiCmp to the default Maven goal. Thanks to Gary Gregory. o Add partHeaderSizeMax, a new limit that sets a maximum number of bytes for each individual multipart header. The default is 512 bytes. Thanks to Mark Thomas. Fixed Bugs: o Replace use of Locale.ENGLISH with Locale.ROOT. Thanks to Gary Gregory. o Remove unused exception from FileUploadBase.createItem(Map, boolean). Thanks to Gary Gregory. o Migrate from deprecated API in DiskFileItem.getOutputStream(). Thanks to Gary Gregory. o Use try-with-resources. Thanks to Gary Gregory. o Port to Java 1.4 Throwable APIs (!). Thanks to Gary Gregory. o Remove -nouses directive from maven-bundle-plugin. OSGi package imports now state 'uses' definitions for package imports, this doesn't affect JPMS (from org.apache.commons:commons-parent:80). Thanks to Gary Gregory. o DiskFileItem.getInputStream() now uses NIO. Thanks to Gary Gregory. o Last statement in DiskFileItem.finalize() method should be a call to super.finalize(). Thanks to Gary Gregory. o org.apache.commons.fileupload.FileUploadBase.FileUploadIOException is now a proper Java 1.4-style exception (propagates its cause to super). Thanks to Gary Gregory. o Use java.util.Base64 instead of custom code. Thanks to Gary Gregory. Changes: o Bump Java from 6 to 8. Thanks to Gary Gregory. o Bump org.apache.commons:commons-parent from 62 to 84, upgrades Doxia from 1 to 2. Thanks to Gary Gregory. o Bump commons-io from 2.11.0 to 2.19.0. Thanks to Gary Gregory. o Bump javax.servlet:servlet-api from 2.4 to 2.5. Thanks to Gary Gregory. o Bump JUnit from junit:junit:4.13.2 org.junit.vintage:junit-vintage-engine from parent POM. Thanks to Gary Gregory. Historical list of changes: https://commons.apache.org/proper/commons-fileupload/changes.html For complete information on Apache Commons FileUpload, including instructions on how to submit bug reports, patches, or suggestions for improvement, see the Apache Commons FileUpload website: https://commons.apache.org/proper/commons-fileupload/ Download page: https://commons.apache.org/proper/commons-fileupload/download_fileupload.cgi Apache Commons Team ------------------------------------------------------------------------------ Apache Commons FileUpload 1.5 RELEASE NOTES The Apache Commons FileUpload team is pleased to announce the release of Apache Commons FileUpload 1.5. The Apache Commons FileUpload component provides a simple yet flexible means of adding support for multipart file upload functionality to servlets and web applications. Version 1.3 onwards requires Java 6 or later. No client code changes are required to migrate from version 1.4 to 1.5. Changes in version 1.5 include: New features: o Add a configurable limit (disabled by default) for the number of files to upload per request. Fixed Bugs: o FILEUPLOAD-293: DiskFileItem.write(File) had been changed to use FileUtils.moveFile internally, preventing an existing file as the target. o Improve parsing speed. Thanks to David Georg Reichelt. Changes: o Bump Commons IO to 2.11.0 o FILEUPLOAD-328 Switch from Cobertura code coverage to Jacoco code coverage. Thanks to Arturo Bernal. o Bump JUnit to 4.13.2 For complete information on Apache Commons FileUpload, including instructions on how to submit bug reports, patches, or suggestions for improvement, see the Apache Commons FileUpload website: https://commons.apache.org/proper/commons-fileupload/ ------------------------------------------------------------------------------ Apache Commons FileUpload 1.4 RELEASE NOTES The Apache Commons FileUpload team is pleased to announce the release of Apache Commons FileUpload 1.4. The Apache Commons FileUpload component provides a simple yet flexible means of adding support for multipart file upload functionality to servlets and web applications. Version 1.3 onwards requires Java 6 or later. 1.4 Release Changes in version 1.4 include: New features: o Site: added security report Fixed Bugs: o FILEUPLOAD-252: DiskFileItem#write() could lose original IO exception o FILEUPLOAD-258: DiskFileItem#getStoreLocation() wrongly returned a File object for items stored in memory o FILEUPLOAD-242: FileUploadBase - should not silently catch and ignore all Throwables o FILEUPLOAD-257: Fix Javadoc 1.8.0 errors o FILEUPLOAD-234: Fix section "Resource cleanup" of the user guide o FILEUPLOAD-237: Fix streaming example: use FileItem.getInputStream() instead of openStream() o FILEUPLOAD-248: DiskFileItem might suppress critical IOExceptions on rename - use FileUtil.move instead o FILEUPLOAD-251: DiskFileItem#getTempFile() is broken o FILEUPLOAD-250: FileUploadBase - potential resource leak - InputStream not closed on exception o FILEUPLOAD-244: DiskFileItem.readObject fails to close FileInputStream o FILEUPLOAD-245: DiskFileItem.get() may not fully read the data Changes: o FILEUPLOAD-292: Don't create un-needed resources in FileUploadBase.java o FILEUPLOAD-282: Upversion complier.source, compiler.target to 1.6 o FILEUPLOAD-246: FileUpload should use IOUtils.closeQuietly where relevant o FILEUPLOAD-243: Make some MultipartStream private fields final Thanks to Ville Skytt�. For complete information on Apache Commons FileUpload, including instructions on how to submit bug reports, patches, or suggestions for improvement, see the Apache Commons FileUpload website: https://commons.apache.org/proper/commons-fileupload/ ------------------------------------------------------------------------------ Apache Commons FileUpload 1.3.3 RELEASE NOTES The Apache Commons FileUpload team is pleased to announce the release of Apache Commons FileUpload 1.3.3. The Apache Commons FileUpload component provides a simple yet flexible means of adding support for multipart file upload functionality to servlets and web applications. Version 1.3 onwards requires Java 5 or later. No client code changes are required to migrate from version 1.3.0, 1.3.1, or 1.3.2, to 1.3.3 Changes in version 1.3.3 include: o FILEUPLOAD-279: DiskFileItem can no longer be deserialized, unless a particular system property is set. For complete information on Apache Commons FileUpload, including instructions on how to submit bug reports, patches, or suggestions for improvement, see the Apache Commons FileUpload website: https://commons.apache.org/proper/commons-fileupload/ ------------------------------------------------------------------------------ No client code changes are required to migrate from version 1.3.1 to 1.3.2. Changes in version 1.3.2 include: o FILEUPLOAD-272: Performance Improvement in MultipartStream. Prevents a DoS (CVE-2016-3092) For complete information on Apache Commons FileUpload, including instructions on how to submit bug reports, patches, or suggestions for improvement, see the Apache Commons FileUpload website: https://commons.apache.org/proper/commons-fileupload/ ------------------------------------------------------------------------------ Apache Commons FileUpload 1.3.1 RELEASE NOTES The Apache Commons FileUpload team is pleased to announce the release of Apache Commons FileUpload 1.3.1. The Apache Commons FileUpload component provides a simple yet flexible means of adding support for multipart file upload functionality to servlets and web applications. Version 1.3 onwards requires Java 5 or later. No client code changes are required to migrate from version 1.3.0 to 1.3.1. This is a security and maintenance release that includes an important security fix as well as a small number of bugfixes. Changes in version 1.3.1 include: Fixed Bugs: o SECURITY - CVE-2014-0050. Specially crafted input can trigger a DoS if the buffer used by the MultipartStream is not big enough. When constructing MultipartStream enforce the requirements for buffer size by throwing an IllegalArgumentException if the requested buffer size is too small. This prevents the DoS. o When deserializing DiskFileItems ensure that the repository location, if any, is a valid one. Thanks to Arun Babu Neelicattu. o Correct example in usage documentation so it compiles. For complete information on Apache Commons FileUpload, including instructions on how to submit bug reports, patches, or suggestions for improvement, see the Apache Commons FileUpload website: https://commons.apache.org/proper/commons-fileupload/ libcommons-fileupload2-java-2.0.0~M5/CONTRIBUTING.md0000644000175000017500000001554215142145735020347 0ustar zigozigo Contributing to Apache Commons FileUpload ====================== Have you found a bug or have an idea for a cool new feature? Contributing code is a great way to give something back to the open-source community. Before you dig right into the code, we need contributors to follow a few guidelines to have a chance of keeping on top of things. Getting Started --------------- + Make sure you have a [JIRA account](https://issues.apache.org/jira/). + Make sure you have a [GitHub account](https://github.com/signup/free). This is not essential, but makes providing patches much easier. + If you're planning to implement a new feature it makes sense to discuss your changes on the [dev list](https://commons.apache.org/mail-lists.html) first. This way you can make sure you're not wasting your time on something that isn't considered to be in Apache Commons FileUpload's scope. + Submit a [Jira Ticket][jira] for your issue, assuming one does not already exist. + Clearly describe the issue including steps to reproduce when it is a bug. + Make sure you fill in the earliest version that you know has the issue. + Find the corresponding [repository on GitHub](https://github.com/apache/?query=commons-), [fork](https://help.github.com/articles/fork-a-repo/) and check out your forked repository. If you don't have a GitHub account, you can still clone the Commons repository. Making Changes -------------- + Create a _topic branch_ for your isolated work. * Usually you should base your branch from the `master` branch. * A good topic branch name can be the JIRA bug ID plus a keyword, e.g. `FILEUPLOAD-123-InputStream`. * If you have submitted multiple JIRA issues, try to maintain separate branches and pull requests. + Make commits of logical units. * Make sure your commit messages are meaningful and in the proper format. Your commit message should contain the key of the JIRA issue. * For example, `[FILEUPLOAD-123] Close input stream sooner` + Respect the original code style: + Only use spaces for indentation; you can check for unnecessary whitespace with `git diff` before committing. + Create minimal diffs - disable _On Save_ actions like _Reformat Source Code_ or _Organize Imports_. If you feel the source code should be reformatted create a separate PR for this change first. + Write unit tests that match behavioral changes, where the tests fail if the changes to the runtime are not applied. This may not always be possible but is a best practice. Unit tests are typically in the `src/test/java` directory. + Run a successful build using the default [Maven](https://maven.apache.org/) goal with `mvn`; that's `mvn` on the command line by itself. + Write a pull request description that is detailed enough to understand what the pull request does, how, and why. + Each commit in the pull request should have a meaningful subject line and body. Note that commits might be squashed by a maintainer on merge. Making Trivial Changes ---------------------- The JIRA tickets are used to generate the changelog for the next release. For changes of a trivial nature to comments and documentation, it is not always necessary to create a new ticket in JIRA. In this case, it is appropriate to start the first line of a commit with '[doc]' or '[javadoc]' instead of a ticket number. Submitting Changes ------------------ + Sign and submit the Apache [Contributor License Agreement][cla] if you haven't already. * Note that small patches & typical bug fixes do not require a CLA as clause 5 of the [Apache License](https://www.apache.org/licenses/LICENSE-2.0.html#contributions) covers them. + Push your changes to a topic branch in your fork of the repository. + Submit a _Pull Request_ to the corresponding repository in the `apache` organization. * Verify _Files Changed_ shows only your intended changes and does not include additional files like `target/*.class` + Update your JIRA ticket and include a link to the pull request in the ticket. If you prefer to not use GitHub, then you can instead use `git format-patch` (or `svn diff`) and attach the patch file to the JIRA issue. Additional Resources -------------------- + [Contributing patches](https://commons.apache.org/patches.html) + [Apache Commons FileUpload JIRA project page][jira] + [Contributor License Agreement][cla] + [General GitHub documentation](https://help.github.com/) + [GitHub pull request documentation](https://help.github.com/articles/creating-a-pull-request/) [cla]:https://www.apache.org/licenses/#clas [jira]:https://issues.apache.org/jira/browse/FILEUPLOAD libcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-jakarta-servlet6/0000755000175000017500000000000015227714536025156 5ustar zigozigolibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-jakarta-servlet6/pom.xml0000644000175000017500000001331115142145735026465 0ustar zigozigo 4.0.0 org.apache.commons commons-fileupload2 2.0.0-M5 ../ commons-fileupload2-jakarta-servlet6 Apache Commons FileUpload Jakarta Servlet 6 The Apache Commons FileUpload Jakarta component provides a simple yet flexible means of adding support for multipart file upload functionality to Jakarta servlets and web applications. ${basedir}/.. org.apache.commons.fileupload2.jakarta.servlet6 osgi.contract;filter:="(&(osgi.contract=JakartaServlet)(version=6.0))" https://jakarta.ee/specifications/platform/10/apidocs/ 2026-02-08T17:46:05Z 0.75 0.60 0.61 0.00 0.60 0.55 org.apache.commons commons-fileupload2-core 2.0.0-M5 org.apache.commons commons-fileupload2-core 2.0.0-M5 tests test org.junit.jupiter junit-jupiter test commons-io commons-io jakarta.servlet jakarta.servlet-api 6.0.0 provided org.apache.commons commons-lang3 test org.apache.maven.plugins maven-dependency-plugin dep-unpack-main-resources unpack generate-resources ${project.build.outputDirectory} dep-unpack-test-resources unpack generate-resources ${project.build.testOutputDirectory} org.apache apache-jar-resource-bundle 1.4 META-INF/LICENSE.txt,META-INF/NOTICE.txt org.apache.rat apache-rat-plugin .project .classpath .settings/**/ bin/** libcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-jakarta-servlet6/src/0000755000175000017500000000000015142145735025740 5ustar zigozigolibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-jakarta-servlet6/src/site/0000755000175000017500000000000015142145735026704 5ustar zigozigolibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-jakarta-servlet6/src/site/resources/0000755000175000017500000000000015227714536030723 5ustar zigozigo././@LongLink0000644000000000000000000000015400000000000011603 Lustar rootrootlibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-jakarta-servlet6/src/site/resources/profile.jacocolibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-jakarta-servlet6/src/site/resources/profile0000644000175000017500000000166215142145735032306 0ustar zigozigo# 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 # # https://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. # ----------------------------------------------------------------------------- # # Empty file used to automatically trigger JaCoCo profile from commons parent pom libcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-jakarta-servlet6/src/test/0000755000175000017500000000000015142145735026717 5ustar zigozigolibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-jakarta-servlet6/src/test/java/0000755000175000017500000000000015142145735027640 5ustar zigozigolibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-jakarta-servlet6/src/test/java/org/0000755000175000017500000000000015142145735030427 5ustar zigozigolibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-jakarta-servlet6/src/test/java/org/apache/0000755000175000017500000000000015142145735031650 5ustar zigozigo././@LongLink0000644000000000000000000000015400000000000011603 Lustar rootrootlibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-jakarta-servlet6/src/test/java/org/apache/commons/libcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-jakarta-servlet6/src/test/java/org/apache/c0000755000175000017500000000000015142145735032013 5ustar zigozigo././@LongLink0000644000000000000000000000017000000000000011601 Lustar rootrootlibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-jakarta-servlet6/src/test/java/org/apache/commons/fileupload2/libcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-jakarta-servlet6/src/test/java/org/apache/c0000755000175000017500000000000015142145735032013 5ustar zigozigo././@LongLink0000644000000000000000000000020000000000000011573 Lustar rootrootlibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-jakarta-servlet6/src/test/java/org/apache/commons/fileupload2/jakarta/libcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-jakarta-servlet6/src/test/java/org/apache/c0000755000175000017500000000000015142145735032013 5ustar zigozigo././@LongLink0000644000000000000000000000021100000000000011575 Lustar rootrootlibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-jakarta-servlet6/src/test/java/org/apache/commons/fileupload2/jakarta/servlet6/libcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-jakarta-servlet6/src/test/java/org/apache/c0000755000175000017500000000000015227714536032020 5ustar zigozigo././@LongLink0000644000000000000000000000024200000000000011601 Lustar rootrootlibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-jakarta-servlet6/src/test/java/org/apache/commons/fileupload2/jakarta/servlet6/JakartaSizesDiskTest.javalibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-jakarta-servlet6/src/test/java/org/apache/c0000644000175000017500000000333215142145735032016 0ustar zigozigo/* * 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 * * https://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.jakarta.servlet6; import java.io.InputStream; import org.apache.commons.fileupload2.core.AbstractSizesTest; import org.apache.commons.fileupload2.core.DiskFileItem; import org.apache.commons.fileupload2.core.DiskFileItemFactory; import jakarta.servlet.http.HttpServletRequest; /** * Unit test for items with varying sizes. */ class JakartaSizesDiskTest extends AbstractSizesTest { @Override protected JakartaServletDiskFileUpload newFileUpload() { return new JakartaServletDiskFileUpload(); } @Override protected JakartaMockHttpServletRequest newMockHttpServletRequest(final InputStream request, final long requestLength, final String contentType, final int readLimit) { return new JakartaMockHttpServletRequest(request, requestLength, contentType, readLimit); } } ././@LongLink0000644000000000000000000000025600000000000011606 Lustar rootrootlibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-jakarta-servlet6/src/test/java/org/apache/commons/fileupload2/jakarta/servlet6/JakartaServletFileUploadDiskTest.javalibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-jakarta-servlet6/src/test/java/org/apache/c0000644000175000017500000001171715142145735032024 0ustar zigozigo/* * 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 * * https://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.jakarta.servlet6; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; import java.nio.charset.StandardCharsets; import java.util.List; import org.apache.commons.fileupload2.core.AbstractFileUploadTest; import org.apache.commons.fileupload2.core.Constants; import org.apache.commons.fileupload2.core.DiskFileItem; import org.apache.commons.fileupload2.core.DiskFileItemFactory; import org.apache.commons.fileupload2.core.FileUploadException; import org.junit.jupiter.api.Test; import jakarta.servlet.http.HttpServletRequest; /** * Tests {@link JakartaServletFileUpload} and * * @see AbstractFileUploadTest */ class JakartaServletFileUploadDiskTest extends AbstractFileUploadTest { public JakartaServletFileUploadDiskTest() { super(new JakartaServletDiskFileUpload()); } @Override public List parseUpload(final JakartaServletDiskFileUpload upload, final byte[] bytes, final String contentType) throws FileUploadException { final HttpServletRequest request = new JakartaMockHttpServletRequest(bytes, contentType); return upload.parseRequest(new JakartaServletRequestContext(request)); } @Test void testParseImpliedUtf8() throws Exception { // utf8 encoded form-data without explicit content-type encoding // @formatter:off final var text = "-----1234\r\n" + "Content-Disposition: form-data; name=\"utf8Html\"\r\n" + "\r\n" + "Thís ís the coñteñt of the fíle\n" + "\r\n" + "-----1234--\r\n"; // @formatter:on final var bytes = text.getBytes(StandardCharsets.UTF_8); final HttpServletRequest request = new JakartaMockServletHttpRequest(bytes, Constants.CONTENT_TYPE); // @formatter:off final var fileItemFactory = DiskFileItemFactory.builder() .setCharset(StandardCharsets.UTF_8) .get(); // @formatter:on final var upload = new JakartaServletDiskFileUpload(fileItemFactory); final var fileItems = upload.parseRequest(request); final var fileItem = fileItems.get(0); assertTrue(fileItem.getString().contains("coñteñt"), fileItem.getString()); } /* * Test case for */ @Test void testParseParameterMap() throws Exception { // @formatter:off final var text = "-----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" + "Content-Disposition: form-data; name=\"field\"\r\n" + "\r\n" + "fieldValue\r\n" + "-----1234\r\n" + "Content-Disposition: form-data; name=\"multi\"\r\n" + "\r\n" + "value1\r\n" + "-----1234\r\n" + "Content-Disposition: form-data; name=\"multi\"\r\n" + "\r\n" + "value2\r\n" + "-----1234--\r\n"; // @formatter:on final var bytes = text.getBytes(StandardCharsets.US_ASCII); final HttpServletRequest request = new JakartaMockServletHttpRequest(bytes, Constants.CONTENT_TYPE); final var upload = new JakartaServletDiskFileUpload(); final var mappedParameters = upload.parseParameterMap(request); assertTrue(mappedParameters.containsKey("file")); assertEquals(1, mappedParameters.get("file").size()); assertTrue(mappedParameters.containsKey("field")); assertEquals(1, mappedParameters.get("field").size()); assertTrue(mappedParameters.containsKey("multi")); assertEquals(2, mappedParameters.get("multi").size()); } } ././@LongLink0000644000000000000000000000025200000000000011602 Lustar rootrootlibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-jakarta-servlet6/src/test/java/org/apache/commons/fileupload2/jakarta/servlet6/JakartaServletFileUploadTest.javalibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-jakarta-servlet6/src/test/java/org/apache/c0000644000175000017500000001211615142145735032016 0ustar zigozigo/* * 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 * * https://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.jakarta.servlet6; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; import java.nio.charset.StandardCharsets; import java.util.List; import org.apache.commons.fileupload2.core.AbstractFileUploadTest; import org.apache.commons.fileupload2.core.Constants; import org.apache.commons.fileupload2.core.DiskFileItem; import org.apache.commons.fileupload2.core.DiskFileItemFactory; import org.apache.commons.fileupload2.core.FileUploadException; import org.junit.jupiter.api.Test; import jakarta.servlet.http.HttpServletRequest; /** * Tests {@link JakartaServletFileUpload}. * * @see AbstractFileUploadTest */ class JakartaServletFileUploadTest extends AbstractFileUploadTest, HttpServletRequest, DiskFileItem, DiskFileItemFactory> { public JakartaServletFileUploadTest() { super(new JakartaServletFileUpload<>(DiskFileItemFactory.builder().get())); } @Override public List parseUpload(final JakartaServletFileUpload upload, final byte[] bytes, final String contentType) throws FileUploadException { final HttpServletRequest request = new JakartaMockHttpServletRequest(bytes, contentType); return upload.parseRequest(new JakartaServletRequestContext(request)); } @Test void testParseImpliedUtf8() throws Exception { // utf8 encoded form-data without explicit content-type encoding // @formatter:off final var text = "-----1234\r\n" + "Content-Disposition: form-data; name=\"utf8Html\"\r\n" + "\r\n" + "Thís ís the coñteñt of the fíle\n" + "\r\n" + "-----1234--\r\n"; // @formatter:on final var bytes = text.getBytes(StandardCharsets.UTF_8); final HttpServletRequest request = new JakartaMockServletHttpRequest(bytes, Constants.CONTENT_TYPE); // @formatter:off final var fileItemFactory = DiskFileItemFactory.builder() .setCharset(StandardCharsets.UTF_8) .get(); // @formatter:on final var upload = new JakartaServletFileUpload<>(fileItemFactory); final var fileItems = upload.parseRequest(request); final var fileItem = fileItems.get(0); assertTrue(fileItem.getString().contains("coñteñt"), fileItem.getString()); } /* * Test case for */ @Test void testParseParameterMap() throws Exception { // @formatter:off final var text = "-----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" + "Content-Disposition: form-data; name=\"field\"\r\n" + "\r\n" + "fieldValue\r\n" + "-----1234\r\n" + "Content-Disposition: form-data; name=\"multi\"\r\n" + "\r\n" + "value1\r\n" + "-----1234\r\n" + "Content-Disposition: form-data; name=\"multi\"\r\n" + "\r\n" + "value2\r\n" + "-----1234--\r\n"; // @formatter:on final var bytes = text.getBytes(StandardCharsets.US_ASCII); final HttpServletRequest request = new JakartaMockServletHttpRequest(bytes, Constants.CONTENT_TYPE); final var upload = new JakartaServletFileUpload<>(DiskFileItemFactory.builder().get()); final var mappedParameters = upload.parseParameterMap(request); assertTrue(mappedParameters.containsKey("file")); assertEquals(1, mappedParameters.get("file").size()); assertTrue(mappedParameters.containsKey("field")); assertEquals(1, mappedParameters.get("field").size()); assertTrue(mappedParameters.containsKey("multi")); assertEquals(2, mappedParameters.get("multi").size()); } } ././@LongLink0000644000000000000000000000025100000000000011601 Lustar rootrootlibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-jakarta-servlet6/src/test/java/org/apache/commons/fileupload2/jakarta/servlet6/JakartaProgressListenerTest.javalibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-jakarta-servlet6/src/test/java/org/apache/c0000644000175000017500000000353515142145735032023 0ustar zigozigo/* * 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 * * https://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.jakarta.servlet6; import java.io.InputStream; import org.apache.commons.fileupload2.core.AbstractProgressListenerTest; import org.apache.commons.fileupload2.core.DiskFileItem; import org.apache.commons.fileupload2.core.DiskFileItemFactory; import org.apache.commons.fileupload2.core.ProgressListener; import jakarta.servlet.http.HttpServletRequest; /** * Tests the {@link ProgressListener}. */ class JakartaProgressListenerTest extends AbstractProgressListenerTest, HttpServletRequest, DiskFileItem, DiskFileItemFactory> { @Override protected JakartaServletFileUpload newFileUpload() { return new JakartaServletFileUpload<>(); } @Override protected HttpServletRequest newMockHttpServletRequest(final InputStream request, final long requestLength, final String contentType, final int readLimit) { return new JakartaMockHttpServletRequest(request, requestLength, contentType, readLimit); } } ././@LongLink0000644000000000000000000000023600000000000011604 Lustar rootrootlibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-jakarta-servlet6/src/test/java/org/apache/commons/fileupload2/jakarta/servlet6/JakartaSizesTest.javalibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-jakarta-servlet6/src/test/java/org/apache/c0000644000175000017500000000347515142145735032026 0ustar zigozigo/* * 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 * * https://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.jakarta.servlet6; import java.io.InputStream; import org.apache.commons.fileupload2.core.AbstractSizesTest; import org.apache.commons.fileupload2.core.DiskFileItem; import org.apache.commons.fileupload2.core.DiskFileItemFactory; import jakarta.servlet.http.HttpServletRequest; /** * Unit test for items with varying sizes. */ class JakartaSizesTest extends AbstractSizesTest, HttpServletRequest, DiskFileItem, DiskFileItemFactory> { @Override protected JakartaServletFileUpload newFileUpload() { return new JakartaServletFileUpload<>(DiskFileItemFactory.builder().get()); } @Override protected JakartaMockHttpServletRequest newMockHttpServletRequest(final InputStream request, final long requestLength, final String contentType, final int readLimit) { return new JakartaMockHttpServletRequest(request, requestLength, contentType, readLimit); } } ././@LongLink0000644000000000000000000000025500000000000011605 Lustar rootrootlibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-jakarta-servlet6/src/test/java/org/apache/commons/fileupload2/jakarta/servlet6/JakartaProgressListenerDiskTest.javalibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-jakarta-servlet6/src/test/java/org/apache/c0000644000175000017500000000350415142145735032017 0ustar zigozigo/* * 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 * * https://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.jakarta.servlet6; import java.io.InputStream; import org.apache.commons.fileupload2.core.AbstractProgressListenerTest; import org.apache.commons.fileupload2.core.DiskFileItem; import org.apache.commons.fileupload2.core.DiskFileItemFactory; import org.apache.commons.fileupload2.core.ProgressListener; import jakarta.servlet.http.HttpServletRequest; /** * Tests the {@link ProgressListener}. */ class JakartaProgressListenerDiskTest extends AbstractProgressListenerTest, HttpServletRequest, DiskFileItem, DiskFileItemFactory> { @Override protected JakartaServletDiskFileUpload newFileUpload() { return new JakartaServletDiskFileUpload(); } @Override protected HttpServletRequest newMockHttpServletRequest(final InputStream request, final long requestLength, final String contentType, final int readLimit) { return new JakartaMockHttpServletRequest(request, requestLength, contentType, readLimit); } } ././@LongLink0000644000000000000000000000025300000000000011603 Lustar rootrootlibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-jakarta-servlet6/src/test/java/org/apache/commons/fileupload2/jakarta/servlet6/JakartaMockServletHttpRequest.javalibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-jakarta-servlet6/src/test/java/org/apache/c0000644000175000017500000003552615142145735032030 0ustar zigozigo/* * 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 * * https://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.jakarta.servlet6; import java.io.BufferedReader; import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; import java.io.UnsupportedEncodingException; import java.security.Principal; import java.util.Collection; import java.util.Enumeration; import java.util.Locale; import java.util.Map; import org.apache.commons.fileupload2.core.AbstractFileUpload; import jakarta.servlet.AsyncContext; import jakarta.servlet.DispatcherType; import jakarta.servlet.ReadListener; import jakarta.servlet.RequestDispatcher; import jakarta.servlet.ServletConnection; import jakarta.servlet.ServletContext; import jakarta.servlet.ServletException; import jakarta.servlet.ServletInputStream; import jakarta.servlet.ServletRequest; import jakarta.servlet.ServletResponse; import jakarta.servlet.http.Cookie; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; import jakarta.servlet.http.HttpSession; import jakarta.servlet.http.HttpUpgradeHandler; import jakarta.servlet.http.Part; public class JakartaMockServletHttpRequest implements HttpServletRequest { private static final class MyServletInputStream extends jakarta.servlet.ServletInputStream { private final InputStream inputStream; private final int readLimit; /** * Creates a new instance, which returns the given streams data. */ public MyServletInputStream(final InputStream inputStream, final int readLimit) { this.inputStream = inputStream; this.readLimit = readLimit; } @Override public boolean isFinished() { return false; } @Override public boolean isReady() { return false; } @Override public int read() throws IOException { return inputStream.read(); } @Override public int read(final byte[] b, final int off, final int len) throws IOException { if (readLimit > 0) { return inputStream.read(b, off, Math.min(readLimit, len)); } return inputStream.read(b, off, len); } @Override public void setReadListener(final ReadListener readListener) { throw new IllegalStateException("Not implemented"); } } private final InputStream requestInputStream; private long requestLength; private final String contentType; private int readLimit = -1; private final Map headers = new java.util.HashMap<>(); /** * Creates a new instance with the given request data and content type. */ public JakartaMockServletHttpRequest(final byte[] requestData, final String strContentType) { this(new ByteArrayInputStream(requestData), requestData.length, strContentType); } /** * Creates a new instance with the given request data and content type. */ public JakartaMockServletHttpRequest(final InputStream requestData, final long requestLength, final String strContentType) { this.requestInputStream = requestData; this.requestLength = requestLength; this.contentType = strContentType; this.headers.put(AbstractFileUpload.CONTENT_TYPE, strContentType); } @Override public boolean authenticate(final HttpServletResponse response) throws IOException, ServletException { return false; } @Override public String changeSessionId() { return null; } @Override public AsyncContext getAsyncContext() { return null; } /** * @see ServletRequest#getAttribute(String) */ @Override public Object getAttribute(final String arg0) { return null; } /** * @see ServletRequest#getAttributeNames() */ @Override public Enumeration getAttributeNames() { return null; } /** * @see HttpServletRequest#getAuthType() */ @Override public String getAuthType() { return null; } /** * @see ServletRequest#getCharacterEncoding() */ @Override public String getCharacterEncoding() { return null; } /** * @see ServletRequest#getContentLength() */ @Override public int getContentLength() { return requestInputStream != null ? Math.toIntExact(requestLength) : -1; } @Override public long getContentLengthLong() { return getContentLength(); } /** * @see ServletRequest#getContentType() */ @Override public String getContentType() { return contentType; } /** * @see HttpServletRequest#getContextPath() */ @Override public String getContextPath() { return null; } /** * @see HttpServletRequest#getCookies() */ @Override public Cookie[] getCookies() { return null; } /** * @see HttpServletRequest#getDateHeader(String) */ @Override public long getDateHeader(final String arg0) { return 0; } @Override public DispatcherType getDispatcherType() { return null; } /** * @see HttpServletRequest#getHeader(String) */ @Override public String getHeader(final String headerName) { return headers.get(headerName); } /** * @see HttpServletRequest#getHeaderNames() */ @Override public Enumeration getHeaderNames() { // todo - implement return null; } /** * @see HttpServletRequest#getHeaders(String) */ @Override public Enumeration getHeaders(final String arg0) { // todo - implement return null; } /** * @see ServletRequest#getInputStream() */ @Override public ServletInputStream getInputStream() throws IOException { return new MyServletInputStream(requestInputStream, readLimit); } /** * @see HttpServletRequest#getIntHeader(String) */ @Override public int getIntHeader(final String arg0) { return 0; } /** * @see ServletRequest#getLocalAddr() */ @Override @SuppressWarnings("javadoc") // This is a Servlet 2.4 method public String getLocalAddr() { return null; } /** * @see ServletRequest#getLocale() */ @Override public Locale getLocale() { return null; } /** * @see ServletRequest#getLocales() */ @Override public Enumeration getLocales() { return null; } /** * @see ServletRequest#getLocalName() */ @Override @SuppressWarnings("javadoc") // This is a Servlet 2.4 method public String getLocalName() { return null; } /** * @see ServletRequest#getLocalPort() */ @Override @SuppressWarnings("javadoc") // This is a Servlet 2.4 method public int getLocalPort() { return 0; } /** * @see HttpServletRequest#getMethod() */ @Override public String getMethod() { return null; } /** * @see ServletRequest#getParameter(String) */ @Override public String getParameter(final String arg0) { return null; } /** * @see ServletRequest#getParameterMap() */ @Override public Map getParameterMap() { return null; } /** * @see ServletRequest#getParameterNames() */ @Override public Enumeration getParameterNames() { return null; } /** * @see ServletRequest#getParameterValues(String) */ @Override public String[] getParameterValues(final String arg0) { return null; } @Override public Part getPart(final String name) throws IOException, ServletException { return null; } @Override public Collection getParts() throws IOException, ServletException { return null; } /** * @see HttpServletRequest#getPathInfo() */ @Override public String getPathInfo() { return null; } /** * @see HttpServletRequest#getPathTranslated() */ @Override public String getPathTranslated() { return null; } /** * @see ServletRequest#getProtocol() */ @Override public String getProtocol() { return null; } @Override public String getProtocolRequestId() { throw new IllegalStateException("Not implemented 6.0.0"); } /** * @see HttpServletRequest#getQueryString() */ @Override public String getQueryString() { return null; } /** * @see ServletRequest#getReader() */ @Override public BufferedReader getReader() throws IOException { return null; } /** * @see ServletRequest#getRemoteAddr() */ @Override public String getRemoteAddr() { return null; } /** * @see ServletRequest#getRemoteHost() */ @Override public String getRemoteHost() { return null; } /** * @see ServletRequest#getRemotePort() */ @Override @SuppressWarnings("javadoc") // This is a Servlet 2.4 method public int getRemotePort() { return 0; } /** * @see HttpServletRequest#getRemoteUser() */ @Override public String getRemoteUser() { return null; } /** * @see ServletRequest#getRequestDispatcher(String) */ @Override public RequestDispatcher getRequestDispatcher(final String arg0) { return null; } /** * @see HttpServletRequest#getRequestedSessionId() */ @Override public String getRequestedSessionId() { return null; } @Override public String getRequestId() { throw new IllegalStateException("Not implemented 6.0.0"); } /** * @see HttpServletRequest#getRequestURI() */ @Override public String getRequestURI() { return null; } /** * @see HttpServletRequest#getRequestURL() */ @Override public StringBuffer getRequestURL() { return null; } /** * @see ServletRequest#getScheme() */ @Override public String getScheme() { return null; } /** * @see ServletRequest#getServerName() */ @Override public String getServerName() { return null; } /** * @see ServletRequest#getServerPort() */ @Override public int getServerPort() { return 0; } @Override public ServletConnection getServletConnection() { throw new IllegalStateException("Not implemented"); } @Override public ServletContext getServletContext() { final var session = getSession(); if (session == null) { return null; } return session.getServletContext(); } /** * @see HttpServletRequest#getServletPath() */ @Override public String getServletPath() { return null; } /** * @see HttpServletRequest#getSession() */ @Override public HttpSession getSession() { return null; } /** * @see HttpServletRequest#getSession(boolean) */ @Override public HttpSession getSession(final boolean arg0) { return null; } /** * @see HttpServletRequest#getUserPrincipal() */ @Override public Principal getUserPrincipal() { return null; } @Override public boolean isAsyncStarted() { return false; } @Override public boolean isAsyncSupported() { return false; } /** * @see HttpServletRequest#isRequestedSessionIdFromCookie() */ @Override public boolean isRequestedSessionIdFromCookie() { return false; } /** * @see HttpServletRequest#isRequestedSessionIdFromURL() */ @Override public boolean isRequestedSessionIdFromURL() { return false; } /** * @see HttpServletRequest#isRequestedSessionIdValid() */ @Override public boolean isRequestedSessionIdValid() { return false; } /** * @see ServletRequest#isSecure() */ @Override public boolean isSecure() { return false; } /** * @see HttpServletRequest#isUserInRole(String) */ @Override public boolean isUserInRole(final String arg0) { return false; } @Override public void login(final String username, final String password) throws ServletException { throw new IllegalStateException("Not implemented"); } @Override public void logout() throws ServletException { throw new IllegalStateException("Not implemented"); } /** * @see ServletRequest#removeAttribute(String) */ @Override public void removeAttribute(final String arg0) { } /** * @see ServletRequest#setAttribute(String, Object) */ @Override public void setAttribute(final String arg0, final Object arg1) { } /** * @see ServletRequest#setCharacterEncoding(String) */ @Override public void setCharacterEncoding(final String arg0) throws UnsupportedEncodingException { } /** * For testing attack scenarios in SizesTest. */ public void setContentLength(final long length) { this.requestLength = length; } /** * Sets the read limit. This can be used to limit the number of bytes to read ahead. * * @param readLimit the read limit to use */ public void setReadLimit(final int readLimit) { this.readLimit = readLimit; } @Override public AsyncContext startAsync() throws IllegalStateException { throw new IllegalStateException("Not implemented"); } @Override public AsyncContext startAsync(final ServletRequest servletRequest, final ServletResponse servletResponse) throws IllegalStateException { throw new IllegalStateException("Not implemented"); } @Override public T upgrade(final Class handlerClass) throws IOException, ServletException { throw new IllegalStateException("Not implemented"); } } ././@LongLink0000644000000000000000000000025300000000000011603 Lustar rootrootlibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-jakarta-servlet6/src/test/java/org/apache/commons/fileupload2/jakarta/servlet6/JakartaMockHttpServletRequest.javalibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-jakarta-servlet6/src/test/java/org/apache/c0000644000175000017500000003375315142145735032030 0ustar zigozigo/* * 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 * * https://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.jakarta.servlet6; import java.io.BufferedReader; import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; import java.io.UnsupportedEncodingException; import java.security.Principal; import java.util.Collection; import java.util.Enumeration; import java.util.HashMap; import java.util.Locale; import java.util.Map; import org.apache.commons.fileupload2.core.AbstractFileUpload; import jakarta.servlet.AsyncContext; import jakarta.servlet.DispatcherType; import jakarta.servlet.ReadListener; import jakarta.servlet.RequestDispatcher; import jakarta.servlet.ServletConnection; import jakarta.servlet.ServletContext; import jakarta.servlet.ServletException; import jakarta.servlet.ServletInputStream; import jakarta.servlet.ServletRequest; import jakarta.servlet.ServletResponse; import jakarta.servlet.http.Cookie; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; import jakarta.servlet.http.HttpSession; import jakarta.servlet.http.HttpUpgradeHandler; import jakarta.servlet.http.Part; /** * Test fixture for {@link HttpServletRequest}. */ public class JakartaMockHttpServletRequest implements HttpServletRequest { private static final class MyServletInputStream extends ServletInputStream { private final InputStream inputStream; private final int readLimit; /** * Creates a new instance, which returns the given streams data. */ MyServletInputStream(final InputStream inputStream, final int readLimit) { this.inputStream = inputStream; this.readLimit = readLimit; } @Override public boolean isFinished() { return false; } @Override public boolean isReady() { return false; } @Override public int read() throws IOException { return inputStream.read(); } @Override public int read(final byte[] b, final int off, final int len) throws IOException { if (readLimit > 0) { return inputStream.read(b, off, Math.min(readLimit, len)); } return inputStream.read(b, off, len); } @Override public void setReadListener(final ReadListener readListener) { } } private final InputStream requestInputStream; private final long requestLength; private final String contentType; private final int readLimit; private final Map headers = new HashMap<>(); /** * Creates a new instance with the given request data and content type. */ public JakartaMockHttpServletRequest(final byte[] requestData, final String contentType) { this(new ByteArrayInputStream(requestData), requestData.length, contentType, -1); } /** * Creates a new instance with the given request data and content type. */ public JakartaMockHttpServletRequest(final InputStream requestInputStream, final long requestLength, final String contentType, final int readLimit) { this.requestInputStream = requestInputStream; this.requestLength = requestLength; this.contentType = contentType; this.headers.put(AbstractFileUpload.CONTENT_TYPE, contentType); this.readLimit = readLimit; } @Override public boolean authenticate(final HttpServletResponse response) throws IOException, ServletException { return false; } @Override public String changeSessionId() { return null; } @Override public AsyncContext getAsyncContext() { return null; } /** * @see ServletRequest#getAttribute(String) */ @Override public Object getAttribute(final String arg0) { return null; } /** * @see ServletRequest#getAttributeNames() */ @Override public Enumeration getAttributeNames() { return null; } /** * @see HttpServletRequest#getAuthType() */ @Override public String getAuthType() { return null; } /** * @see ServletRequest#getCharacterEncoding() */ @Override public String getCharacterEncoding() { return null; } /** * @see ServletRequest#getContentLength() */ @Override public int getContentLength() { return requestInputStream != null ? Math.toIntExact(requestLength) : -1; } @Override public long getContentLengthLong() { return 0; } /** * @see ServletRequest#getContentType() */ @Override public String getContentType() { return contentType; } /** * @see HttpServletRequest#getContextPath() */ @Override public String getContextPath() { return null; } /** * @see HttpServletRequest#getCookies() */ @Override public Cookie[] getCookies() { return null; } /** * @see HttpServletRequest#getDateHeader(String) */ @Override public long getDateHeader(final String arg0) { return 0; } @Override public DispatcherType getDispatcherType() { return null; } /** * @see HttpServletRequest#getHeader(String) */ @Override public String getHeader(final String headerName) { return headers.get(headerName); } /** * @see HttpServletRequest#getHeaderNames() */ @Override public Enumeration getHeaderNames() { // todo - implement return null; } /** * @see HttpServletRequest#getHeaders(String) */ @Override public Enumeration getHeaders(final String arg0) { // todo - implement return null; } /** * @see ServletRequest#getInputStream() */ @Override public ServletInputStream getInputStream() throws IOException { return new MyServletInputStream(requestInputStream, readLimit); } /** * @see HttpServletRequest#getIntHeader(String) */ @Override public int getIntHeader(final String arg0) { return 0; } /** * @see ServletRequest#getLocalAddr() */ @Override @SuppressWarnings("javadoc") // This is a Servlet 2.4 method public String getLocalAddr() { return null; } /** * @see ServletRequest#getLocale() */ @Override public Locale getLocale() { return null; } /** * @see ServletRequest#getLocales() */ @Override public Enumeration getLocales() { return null; } /** * @see ServletRequest#getLocalName() */ @Override @SuppressWarnings("javadoc") // This is a Servlet 2.4 method public String getLocalName() { return null; } /** * @see ServletRequest#getLocalPort() */ @Override @SuppressWarnings("javadoc") // This is a Servlet 2.4 method public int getLocalPort() { return 0; } /** * @see HttpServletRequest#getMethod() */ @Override public String getMethod() { return null; } /** * @see ServletRequest#getParameter(String) */ @Override public String getParameter(final String arg0) { return null; } /** * @see ServletRequest#getParameterMap() */ @Override public Map getParameterMap() { return null; } /** * @see ServletRequest#getParameterNames() */ @Override public Enumeration getParameterNames() { return null; } /** * @see ServletRequest#getParameterValues(String) */ @Override public String[] getParameterValues(final String arg0) { return null; } @Override public Part getPart(final String name) throws IOException, ServletException { return null; } @Override public Collection getParts() throws IOException, ServletException { return null; } /** * @see HttpServletRequest#getPathInfo() */ @Override public String getPathInfo() { return null; } /** * @see HttpServletRequest#getPathTranslated() */ @Override public String getPathTranslated() { return null; } /** * @see ServletRequest#getProtocol() */ @Override public String getProtocol() { return null; } @Override public String getProtocolRequestId() { return null; } /** * @see HttpServletRequest#getQueryString() */ @Override public String getQueryString() { return null; } /** * @see ServletRequest#getReader() */ @Override public BufferedReader getReader() throws IOException { return null; } /** * @see ServletRequest#getRemoteAddr() */ @Override public String getRemoteAddr() { return null; } /** * @see ServletRequest#getRemoteHost() */ @Override public String getRemoteHost() { return null; } /** * @see ServletRequest#getRemotePort() */ @Override @SuppressWarnings("javadoc") // This is a Servlet 2.4 method public int getRemotePort() { return 0; } /** * @see HttpServletRequest#getRemoteUser() */ @Override public String getRemoteUser() { return null; } /** * @see ServletRequest#getRequestDispatcher(String) */ @Override public RequestDispatcher getRequestDispatcher(final String arg0) { return null; } /** * @see HttpServletRequest#getRequestedSessionId() */ @Override public String getRequestedSessionId() { return null; } @Override public String getRequestId() { return null; } /** * @see HttpServletRequest#getRequestURI() */ @Override public String getRequestURI() { return null; } /** * @see HttpServletRequest#getRequestURL() */ @Override public StringBuffer getRequestURL() { return null; } /** * @see ServletRequest#getScheme() */ @Override public String getScheme() { return null; } /** * @see ServletRequest#getServerName() */ @Override public String getServerName() { return null; } /** * @see ServletRequest#getServerPort() */ @Override public int getServerPort() { return 0; } @Override public ServletConnection getServletConnection() { return null; } @Override public ServletContext getServletContext() { return null; } /** * @see HttpServletRequest#getServletPath() */ @Override public String getServletPath() { return null; } /** * @see HttpServletRequest#getSession() */ @Override public HttpSession getSession() { return null; } /** * @see HttpServletRequest#getSession(boolean) */ @Override public HttpSession getSession(final boolean arg0) { return null; } /** * @see HttpServletRequest#getUserPrincipal() */ @Override public Principal getUserPrincipal() { return null; } @Override public boolean isAsyncStarted() { return false; } @Override public boolean isAsyncSupported() { return false; } /** * @see HttpServletRequest#isRequestedSessionIdFromCookie() */ @Override public boolean isRequestedSessionIdFromCookie() { return false; } /** * @see HttpServletRequest#isRequestedSessionIdFromURL() */ @Override public boolean isRequestedSessionIdFromURL() { return false; } /** * @see HttpServletRequest#isRequestedSessionIdValid() */ @Override public boolean isRequestedSessionIdValid() { return false; } /** * @see ServletRequest#isSecure() */ @Override public boolean isSecure() { return false; } /** * @see HttpServletRequest#isUserInRole(String) */ @Override public boolean isUserInRole(final String arg0) { return false; } @Override public void login(final String username, final String password) throws ServletException { } @Override public void logout() throws ServletException { } /** * @see ServletRequest#removeAttribute(String) */ @Override public void removeAttribute(final String arg0) { } /** * @see ServletRequest#setAttribute(String, Object) */ @Override public void setAttribute(final String arg0, final Object arg1) { } /** * @see ServletRequest#setCharacterEncoding(String) */ @Override public void setCharacterEncoding(final String arg0) throws UnsupportedEncodingException { } @Override public AsyncContext startAsync() throws IllegalStateException { return null; } @Override public AsyncContext startAsync(final ServletRequest servletRequest, final ServletResponse servletResponse) throws IllegalStateException { return null; } @Override public T upgrade(final Class handlerClass) throws IOException, ServletException { return null; } } ././@LongLink0000644000000000000000000000024600000000000011605 Lustar rootrootlibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-jakarta-servlet6/src/test/java/org/apache/commons/fileupload2/jakarta/servlet6/JakartaStreamingDiskTest.javalibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-jakarta-servlet6/src/test/java/org/apache/c0000644000175000017500000000406215142145735032017 0ustar zigozigo/* * 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 * * https://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.jakarta.servlet6; import java.io.InputStream; import org.apache.commons.fileupload2.core.AbstractStreamingTest; import org.apache.commons.fileupload2.core.DiskFileItem; import org.apache.commons.fileupload2.core.DiskFileItemFactory; import jakarta.servlet.http.HttpServletRequest; /** * Unit test for items with varying sizes. */ class JakartaStreamingDiskTest extends AbstractStreamingTest { @Override protected DiskFileItemFactory newDiskFileItemFactory() { return DiskFileItemFactory.builder().get(); } @Override protected JakartaServletDiskFileUpload newFileUpload() { return new JakartaServletDiskFileUpload(); } @Override protected HttpServletRequest newMockHttpServletRequest(final InputStream request, final long requestLength, final String contentType, final int readLimit) { return new JakartaMockHttpServletRequest(request, requestLength, contentType, readLimit); } @Override protected JakartaServletRequestContext newServletRequestContext(final HttpServletRequest request) { return new JakartaServletRequestContext(request); } } ././@LongLink0000644000000000000000000000024200000000000011601 Lustar rootrootlibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-jakarta-servlet6/src/test/java/org/apache/commons/fileupload2/jakarta/servlet6/JakartaStreamingTest.javalibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-jakarta-servlet6/src/test/java/org/apache/c0000644000175000017500000000415215142145735032017 0ustar zigozigo/* * 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 * * https://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.jakarta.servlet6; import java.io.InputStream; import org.apache.commons.fileupload2.core.AbstractStreamingTest; import org.apache.commons.fileupload2.core.DiskFileItem; import org.apache.commons.fileupload2.core.DiskFileItemFactory; import jakarta.servlet.http.HttpServletRequest; /** * Unit test for items with varying sizes. */ class JakartaStreamingTest extends AbstractStreamingTest, HttpServletRequest, JakartaServletRequestContext, DiskFileItem, DiskFileItemFactory> { @Override protected DiskFileItemFactory newDiskFileItemFactory() { return DiskFileItemFactory.builder().get(); } @Override protected JakartaServletFileUpload newFileUpload() { return new JakartaServletFileUpload<>(); } @Override protected HttpServletRequest newMockHttpServletRequest(final InputStream request, final long requestLength, final String contentType, final int readLimit) { return new JakartaMockHttpServletRequest(request, requestLength, contentType, readLimit); } @Override protected JakartaServletRequestContext newServletRequestContext(final HttpServletRequest request) { return new JakartaServletRequestContext(request); } } libcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-jakarta-servlet6/src/main/0000755000175000017500000000000015142145735026664 5ustar zigozigolibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-jakarta-servlet6/src/main/java/0000755000175000017500000000000015142145735027605 5ustar zigozigolibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-jakarta-servlet6/src/main/java/org/0000755000175000017500000000000015142145735030374 5ustar zigozigolibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-jakarta-servlet6/src/main/java/org/apache/0000755000175000017500000000000015142145735031615 5ustar zigozigo././@LongLink0000644000000000000000000000015400000000000011603 Lustar rootrootlibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-jakarta-servlet6/src/main/java/org/apache/commons/libcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-jakarta-servlet6/src/main/java/org/apache/c0000755000175000017500000000000015142145735031760 5ustar zigozigo././@LongLink0000644000000000000000000000017000000000000011601 Lustar rootrootlibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-jakarta-servlet6/src/main/java/org/apache/commons/fileupload2/libcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-jakarta-servlet6/src/main/java/org/apache/c0000755000175000017500000000000015142145735031760 5ustar zigozigo././@LongLink0000644000000000000000000000020000000000000011573 Lustar rootrootlibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-jakarta-servlet6/src/main/java/org/apache/commons/fileupload2/jakarta/libcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-jakarta-servlet6/src/main/java/org/apache/c0000755000175000017500000000000015142145735031760 5ustar zigozigo././@LongLink0000644000000000000000000000021100000000000011575 Lustar rootrootlibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-jakarta-servlet6/src/main/java/org/apache/commons/fileupload2/jakarta/servlet6/libcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-jakarta-servlet6/src/main/java/org/apache/c0000755000175000017500000000000015227714536031765 5ustar zigozigo././@LongLink0000644000000000000000000000023200000000000011600 Lustar rootrootlibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-jakarta-servlet6/src/main/java/org/apache/commons/fileupload2/jakarta/servlet6/package-info.javalibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-jakarta-servlet6/src/main/java/org/apache/c0000644000175000017500000000314615142145735031766 0ustar zigozigo/* * 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 * * https://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. */ /** *

* An implementation of {@link org.apache.commons.fileupload2.core.AbstractFileUpload} for use in servlets conforming to the namespace {@code jakarta.servlet}. * *

*

* The following code fragment demonstrates typical usage. *

* *
{@code
 * DiskFileItemFactory factory = DiskFileItemFactory().builder().get();
 * // Configure the factory here, if desired.
 * JakartaServletFileUpload upload = new JakartaServletFileUpload(factory);
 * // Configure the uploader here, if desired.
 * List fileItems = upload.parseRequest(request);
 * }
*

* Please see the FileUpload User Guide for further details and examples of how to * use this package. *

*/ package org.apache.commons.fileupload2.jakarta.servlet6; ././@LongLink0000644000000000000000000000024000000000000011577 Lustar rootrootlibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-jakarta-servlet6/src/main/java/org/apache/commons/fileupload2/jakarta/servlet6/JakartaFileCleaner.javalibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-jakarta-servlet6/src/main/java/org/apache/c0000644000175000017500000000637715142145735031777 0ustar zigozigo/* * 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 * * https://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.jakarta.servlet6; import org.apache.commons.io.FileCleaningTracker; import jakarta.servlet.ServletContext; import jakarta.servlet.ServletContextEvent; import jakarta.servlet.ServletContextListener; /** * A servlet context listener, which ensures that the {@link FileCleaningTracker}'s reaper thread is terminated, when the web application is destroyed. */ public class JakartaFileCleaner implements ServletContextListener { /** * Attribute name, which is used for storing an instance of {@link FileCleaningTracker} in the web application. */ public static final String FILE_CLEANING_TRACKER_ATTRIBUTE = JakartaFileCleaner.class.getName() + ".FileCleaningTracker"; /** * Gets the instance of {@link FileCleaningTracker}, which is associated with the given {@link ServletContext}. * * @param servletContext The servlet context to query * @return The contexts tracker */ public static FileCleaningTracker getFileCleaningTracker(final ServletContext servletContext) { return (FileCleaningTracker) servletContext.getAttribute(FILE_CLEANING_TRACKER_ATTRIBUTE); } /** * Sets the instance of {@link FileCleaningTracker}, which is associated with the given {@link ServletContext}. * * @param servletContext The servlet context to modify * @param tracker The tracker to set */ public static void setFileCleaningTracker(final ServletContext servletContext, final FileCleaningTracker tracker) { servletContext.setAttribute(FILE_CLEANING_TRACKER_ATTRIBUTE, tracker); } /** * Constructs a new instance. */ public JakartaFileCleaner() { // empty } /** * Called when the web application is being destroyed. Calls {@link FileCleaningTracker#exitWhenFinished()}. * * @param sce The servlet context, used for calling {@link #getFileCleaningTracker(ServletContext)}. */ @Override public void contextDestroyed(final ServletContextEvent sce) { getFileCleaningTracker(sce.getServletContext()).exitWhenFinished(); } /** * Called when the web application is initialized. Does nothing. * * @param sce The servlet context, used for calling {@link #setFileCleaningTracker(ServletContext, FileCleaningTracker)}. */ @Override public void contextInitialized(final ServletContextEvent sce) { setFileCleaningTracker(sce.getServletContext(), new FileCleaningTracker()); } } ././@LongLink0000644000000000000000000000025200000000000011602 Lustar rootrootlibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-jakarta-servlet6/src/main/java/org/apache/commons/fileupload2/jakarta/servlet6/JakartaServletDiskFileUpload.javalibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-jakarta-servlet6/src/main/java/org/apache/c0000644000175000017500000000310415142145735031760 0ustar zigozigo/* * 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 * * https://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.jakarta.servlet6; import org.apache.commons.fileupload2.core.DiskFileItem; import org.apache.commons.fileupload2.core.DiskFileItemFactory; /** * A JakartaServletFileUpload for {@link DiskFileItem} and {@link DiskFileItemFactory}. */ public class JakartaServletDiskFileUpload extends JakartaServletFileUpload { /** * Constructs a new instance. */ public JakartaServletDiskFileUpload() { super(DiskFileItemFactory.builder().get()); } /** * Constructs a new instance. * * @param fileItemFactory The factory to use for creating file items. */ public JakartaServletDiskFileUpload(final DiskFileItemFactory fileItemFactory) { super(fileItemFactory); } } ././@LongLink0000644000000000000000000000025200000000000011602 Lustar rootrootlibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-jakarta-servlet6/src/main/java/org/apache/commons/fileupload2/jakarta/servlet6/JakartaServletRequestContext.javalibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-jakarta-servlet6/src/main/java/org/apache/c0000644000175000017500000000435115142145735031765 0ustar zigozigo/* * 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 * * https://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.jakarta.servlet6; import java.io.IOException; import java.io.InputStream; import org.apache.commons.fileupload2.core.AbstractRequestContext; import jakarta.servlet.http.HttpServletRequest; /** * Provides access to the request information needed for a request made to an HTTP servlet. */ public class JakartaServletRequestContext extends AbstractRequestContext { /** * Constructs a context for this request. * * @param request The request to which this context applies. */ public JakartaServletRequestContext(final HttpServletRequest request) { super(request::getHeader, request::getContentLength, request); } /** * Gets the character encoding for the request. * * @return The character encoding for the request. */ @Override public String getCharacterEncoding() { return getRequest().getCharacterEncoding(); } /** * Gets the content type of the request. * * @return The content type of the request. */ @Override public String getContentType() { return getRequest().getContentType(); } /** * Gets the input stream for the request. * * @return The input stream for the request. * @throws IOException if a problem occurs. */ @Override public InputStream getInputStream() throws IOException { return getRequest().getInputStream(); } } ././@LongLink0000644000000000000000000000024600000000000011605 Lustar rootrootlibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-jakarta-servlet6/src/main/java/org/apache/commons/fileupload2/jakarta/servlet6/JakartaServletFileUpload.javalibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-jakarta-servlet6/src/main/java/org/apache/c0000644000175000017500000001225115142145735031763 0ustar zigozigo/* * 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 * * https://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.jakarta.servlet6; import java.io.IOException; import java.util.List; import java.util.Map; import org.apache.commons.fileupload2.core.AbstractFileUpload; import org.apache.commons.fileupload2.core.FileItem; import org.apache.commons.fileupload2.core.FileItemFactory; import org.apache.commons.fileupload2.core.FileItemInputIterator; import org.apache.commons.fileupload2.core.FileUploadException; import jakarta.servlet.http.HttpServletRequest; /** * High level API for processing file uploads. *

* This class handles multiple files per single HTML widget, sent using {@code multipart/mixed} encoding type, as specified by * RFC 1867. Use {@link #parseRequest(HttpServletRequest)} to acquire a list of {@link FileItem}s associated * with a given HTML widget. *

*

* 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. *

* * @param The FileItem type. * @param the FileItemFactory type. */ public class JakartaServletFileUpload, F extends FileItemFactory> extends AbstractFileUpload { /** * Tests 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) { return isMultipartRequestMethod(request.getMethod()) && isMultipartContent(new JakartaServletRequestContext(request)); } /** * Constructs an uninitialized instance of this class. A factory must be configured, using {@code setFileItemFactory()}, before attempting to parse * requests. * * @see AbstractFileUpload#AbstractFileUpload() */ public JakartaServletFileUpload() { } /** * Constructs an instance of this class which uses the supplied factory to create {@code FileItem} instances. * * @see AbstractFileUpload#AbstractFileUpload() * @param fileItemFactory The factory to use for creating file items. */ public JakartaServletFileUpload(final F fileItemFactory) { setFileItemFactory(fileItemFactory); } /** * Gets an RFC 1867 compliant {@code multipart/form-data} file item iterator. * * @param request The servlet request to be parsed. * @return An iterator to instances of {@code FileItemInput} 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. */ @Override public FileItemInputIterator getItemIterator(final HttpServletRequest request) throws FileUploadException, IOException { return super.getItemIterator(new JakartaServletRequestContext(request)); } /** * Parses an RFC 1867 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. */ @Override public Map> parseParameterMap(final HttpServletRequest request) throws FileUploadException { return parseParameterMap(new JakartaServletRequestContext(request)); } /** * Parses an RFC 1867 compliant {@code multipart/form-data} stream. * * @param request 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. */ @Override public List parseRequest(final HttpServletRequest request) throws FileUploadException { return parseRequest(new JakartaServletRequestContext(request)); } } libcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-distribution/0000755000175000017500000000000015227714536024510 5ustar zigozigolibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-distribution/pom.xml0000644000175000017500000002517515142145735026032 0ustar zigozigo 4.0.0 Apache Commons FileUpload Distribution commons-fileupload2-distribution pom Apache Commons FileUpload Distribution archives. org.apache.commons commons-fileupload2 2.0.0-M5 ../ true ${basedir}/.. true 2026-02-08T17:46:05Z ${basedir}/src/main/resources ${commons.parent.dir} META-INF NOTICE.txt LICENSE.txt src/test/resources ${commons.parent.dir} META-INF NOTICE.txt LICENSE.txt release org.apache.commons commons-fileupload2-core ${project.version} org.apache.commons commons-fileupload2-core ${project.version} sources org.apache.commons commons-fileupload2-core ${project.version} javadoc org.apache.commons commons-fileupload2-core ${project.version} tests org.apache.commons commons-fileupload2-core ${project.version} test-sources org.apache.commons commons-fileupload2-jakarta-servlet5 ${project.version} org.apache.commons commons-fileupload2-jakarta-servlet5 ${project.version} sources org.apache.commons commons-fileupload2-jakarta-servlet5 ${project.version} javadoc org.apache.commons commons-fileupload2-jakarta-servlet5 ${project.version} tests org.apache.commons commons-fileupload2-jakarta-servlet5 ${project.version} test-sources org.apache.commons commons-fileupload2-jakarta-servlet6 ${project.version} org.apache.commons commons-fileupload2-jakarta-servlet6 ${project.version} sources org.apache.commons commons-fileupload2-jakarta-servlet6 ${project.version} javadoc org.apache.commons commons-fileupload2-jakarta-servlet6 ${project.version} tests org.apache.commons commons-fileupload2-jakarta-servlet6 ${project.version} test-sources org.apache.commons commons-fileupload2-javax ${project.version} org.apache.commons commons-fileupload2-javax ${project.version} sources org.apache.commons commons-fileupload2-javax ${project.version} javadoc org.apache.commons commons-fileupload2-javax ${project.version} tests org.apache.commons commons-fileupload2-javax ${project.version} test-sources org.apache.commons commons-fileupload2-portlet ${project.version} org.apache.commons commons-fileupload2-portlet ${project.version} sources org.apache.commons commons-fileupload2-portlet ${project.version} javadoc org.apache.commons commons-fileupload2-portlet ${project.version} tests org.apache.commons commons-fileupload2-portlet ${project.version} test-sources maven-assembly-plugin fileupload2-source-release-assembly package single commons-fileupload2-${project.version} src/assembly/src.xml gnu binary commons-fileupload2-${project.version} src/assembly/bin.xml gnu single package libcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-distribution/src/0000755000175000017500000000000015142145735025272 5ustar zigozigolibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-distribution/src/assembly/0000755000175000017500000000000015227714536027116 5ustar zigozigolibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-distribution/src/assembly/bin.xml0000644000175000017500000000365715142145735030416 0ustar zigozigo bin tar.gz zip false org.apache.commons:commons-fileupload2-core org.apache.commons:commons-fileupload2-jakarta-servlet5 org.apache.commons:commons-fileupload2-jakarta-servlet6 org.apache.commons:commons-fileupload2-javax org.apache.commons:commons-fileupload2-portlet false .. LICENSE.txt NOTICE.txt RELEASE-NOTES.txt libcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-distribution/src/assembly/src.xml0000644000175000017500000000327315142145735030427 0ustar zigozigo src tar.gz zip ${basedir}/.. **/.classpath **/.project **/.settings/ **/.checkstyle/ **/doap_*.rdf **/bin/ **/.externalToolBuilders/ **/${project.build.directory}/ **/download*.cgi **/site-content/ libcommons-fileupload2-java-2.0.0~M5/.mvn/0000755000175000017500000000000015142145735016765 5ustar zigozigolibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-portlet/0000755000175000017500000000000015227714536023462 5ustar zigozigolibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-portlet/pom.xml0000644000175000017500000001260715142145735025000 0ustar zigozigo 4.0.0 org.apache.commons commons-fileupload2 2.0.0-M5 ../ commons-fileupload2-portlet Apache Commons FileUpload Portlet The Apache Commons FileUpload Portlet component provides a simple yet flexible means of adding support for multipart file upload functionality to portlet. ${basedir}/.. org.apache.commons.fileupload2.portlet !javax.portlet,* javax.portlet 2026-02-08T17:46:05Z 1.00 0.64 0.60 1.00 0.64 0.60 true org.apache.commons commons-fileupload2-core 2.0.0-M5 org.apache.commons commons-fileupload2-core 2.0.0-M5 tests test org.apache.commons commons-fileupload2-javax 2.0.0-M5 org.apache.commons commons-fileupload2-javax 2.0.0-M5 tests test org.junit.jupiter junit-jupiter test javax.servlet servlet-api ${commons.servlet-api.version} provided portlet-api portlet-api 1.0 provided org.apache.maven.plugins maven-dependency-plugin dep-unpack-main-resources unpack generate-resources ${project.build.outputDirectory} dep-unpack-test-resources unpack generate-resources ${project.build.testOutputDirectory} org.apache apache-jar-resource-bundle 1.4 META-INF/LICENSE.txt,META-INF/NOTICE.txt libcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-portlet/src/0000755000175000017500000000000015142145735024244 5ustar zigozigolibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-portlet/src/site/0000755000175000017500000000000015142145735025210 5ustar zigozigolibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-portlet/src/site/resources/0000755000175000017500000000000015227714536027227 5ustar zigozigolibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-portlet/src/site/resources/profile.jacoco0000644000175000017500000000166215142145735032047 0ustar zigozigo# 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 # # https://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. # ----------------------------------------------------------------------------- # # Empty file used to automatically trigger JaCoCo profile from commons parent pom libcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-portlet/src/test/0000755000175000017500000000000015142145735025223 5ustar zigozigolibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-portlet/src/test/java/0000755000175000017500000000000015142145735026144 5ustar zigozigolibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-portlet/src/test/java/org/0000755000175000017500000000000015142145735026733 5ustar zigozigolibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-portlet/src/test/java/org/apache/0000755000175000017500000000000015142145735030154 5ustar zigozigolibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-portlet/src/test/java/org/apache/commons/0000755000175000017500000000000015142145735031627 5ustar zigozigo././@LongLink0000644000000000000000000000015700000000000011606 Lustar rootrootlibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-portlet/src/test/java/org/apache/commons/fileupload2/libcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-portlet/src/test/java/org/apache/commons/fi0000755000175000017500000000000015142145735032146 5ustar zigozigo././@LongLink0000644000000000000000000000016700000000000011607 Lustar rootrootlibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-portlet/src/test/java/org/apache/commons/fileupload2/portlet/libcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-portlet/src/test/java/org/apache/commons/fi0000755000175000017500000000000015227714536032153 5ustar zigozigo././@LongLink0000644000000000000000000000023100000000000011577 Lustar rootrootlibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-portlet/src/test/java/org/apache/commons/fileupload2/portlet/JavaxPortletMockActionRequest.javalibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-portlet/src/test/java/org/apache/commons/fi0000644000175000017500000001460115142145735032152 0ustar zigozigo/* * 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 * * https://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.portlet; import java.io.BufferedReader; import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; import java.io.UnsupportedEncodingException; import java.security.Principal; import java.util.Arrays; import java.util.Collections; import java.util.Enumeration; import java.util.HashMap; import java.util.Hashtable; import java.util.Locale; import java.util.Map; import javax.portlet.ActionRequest; import javax.portlet.PortalContext; import javax.portlet.PortletMode; import javax.portlet.PortletPreferences; import javax.portlet.PortletSession; import javax.portlet.WindowState; import org.apache.commons.fileupload2.core.AbstractFileUpload; /** * Mock class for tests. Implements an {@link ActionRequest}. * * @see JavaxPortletFileUploadTest */ @SuppressWarnings("rawtypes") // because of the portlet ActionRequest API does not use generics public class JavaxPortletMockActionRequest implements ActionRequest { private final Hashtable attributes = new Hashtable<>(); private final Map parameters = new HashMap<>(); private String characterEncoding; private final int length; private final String contentType; private final InputStream requestData; public JavaxPortletMockActionRequest(final byte[] requestData, final String contentType) { this(new ByteArrayInputStream(requestData), requestData.length, contentType); } public JavaxPortletMockActionRequest(final ByteArrayInputStream requestData, final int length, final String contentType) { this.requestData = requestData; this.length = length; this.contentType = contentType; this.attributes.put(AbstractFileUpload.CONTENT_TYPE, contentType); } @Override public Object getAttribute(final String key) { return attributes.get(key); } @Override public Enumeration getAttributeNames() { return attributes.keys(); } @Override public String getAuthType() { return null; } @Override public String getCharacterEncoding() { return characterEncoding; } @Override public int getContentLength() { return length; } @Override public String getContentType() { return contentType; } @Override public String getContextPath() { return null; } @Override public Locale getLocale() { return Locale.getDefault(); } @Override public Enumeration getLocales() { return Collections.enumeration(Arrays.asList(Locale.getAvailableLocales())); } @Override public String getParameter(final String key) { return parameters.get(key); } @Override public Map getParameterMap() { return Collections.unmodifiableMap(parameters); } @Override public Enumeration getParameterNames() { return Collections.enumeration(parameters.keySet()); } @Override public String[] getParameterValues(final String arg0) { return null; } @Override public PortalContext getPortalContext() { return null; } @Override public InputStream getPortletInputStream() throws IOException { return requestData; } @Override public PortletMode getPortletMode() { return null; } @Override public PortletSession getPortletSession() { return null; } @Override public PortletSession getPortletSession(final boolean arg0) { return null; } @Override public PortletPreferences getPreferences() { return null; } @Override public Enumeration getProperties(final String arg0) { return null; } @Override public String getProperty(final String arg0) { return null; } @Override public Enumeration getPropertyNames() { return null; } @Override public BufferedReader getReader() throws UnsupportedEncodingException, IOException { return null; } @Override public String getRemoteUser() { return null; } @Override public String getRequestedSessionId() { return null; } @Override public String getResponseContentType() { return null; } @Override public Enumeration getResponseContentTypes() { return null; } @Override public String getScheme() { return null; } @Override public String getServerName() { return null; } @Override public int getServerPort() { return 0; } @Override public Principal getUserPrincipal() { return null; } @Override public WindowState getWindowState() { return null; } @Override public boolean isPortletModeAllowed(final PortletMode arg0) { return false; } @Override public boolean isRequestedSessionIdValid() { return false; } @Override public boolean isSecure() { return false; } @Override public boolean isUserInRole(final String arg0) { return false; } @Override public boolean isWindowStateAllowed(final WindowState arg0) { return false; } @Override public void removeAttribute(final String key) { attributes.remove(key); } @Override public void setAttribute(final String key, final Object value) { attributes.put(key, value); } @Override public void setCharacterEncoding(final String characterEncoding) throws UnsupportedEncodingException { this.characterEncoding = characterEncoding; } } ././@LongLink0000644000000000000000000000022600000000000011603 Lustar rootrootlibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-portlet/src/test/java/org/apache/commons/fileupload2/portlet/JavaxPortletFileUploadTest.javalibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-portlet/src/test/java/org/apache/commons/fi0000644000175000017500000000742715142145735032162 0ustar zigozigo/* * 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 * * https://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.portlet; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; import java.nio.charset.StandardCharsets; import java.util.List; import javax.portlet.ActionRequest; import org.apache.commons.fileupload2.core.AbstractFileUploadTest; import org.apache.commons.fileupload2.core.Constants; import org.apache.commons.fileupload2.core.DiskFileItem; import org.apache.commons.fileupload2.core.DiskFileItemFactory; import org.apache.commons.fileupload2.core.FileUploadException; import org.junit.jupiter.api.Test; /** * Tests {@link JavaxPortletFileUpload}. * * @see AbstractFileUploadTest */ class JavaxPortletFileUploadTest extends AbstractFileUploadTest, ActionRequest, DiskFileItem, DiskFileItemFactory> { public JavaxPortletFileUploadTest() { super(new JavaxPortletFileUpload<>(DiskFileItemFactory.builder().get())); } @Override public List parseUpload(final JavaxPortletFileUpload upload, final byte[] bytes, final String contentType) throws FileUploadException { final ActionRequest request = new JavaxPortletMockActionRequest(bytes, contentType); return upload.parseRequest(new JavaxPortletRequestContext(request)); } @Test void testParseParameterMap() throws Exception { // @formatter:off final var text = "-----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" + "Content-Disposition: form-data; name=\"field\"\r\n" + "\r\n" + "fieldValue\r\n" + "-----1234\r\n" + "Content-Disposition: form-data; name=\"multi\"\r\n" + "\r\n" + "value1\r\n" + "-----1234\r\n" + "Content-Disposition: form-data; name=\"multi\"\r\n" + "\r\n" + "value2\r\n" + "-----1234--\r\n"; // @formatter:on final var bytes = text.getBytes(StandardCharsets.US_ASCII); final ActionRequest request = new JavaxPortletMockActionRequest(bytes, Constants.CONTENT_TYPE); final var mappedParameters = upload.parseParameterMap(request); assertTrue(mappedParameters.containsKey("file")); assertEquals(1, mappedParameters.get("file").size()); assertTrue(mappedParameters.containsKey("field")); assertEquals(1, mappedParameters.get("field").size()); assertTrue(mappedParameters.containsKey("multi")); assertEquals(2, mappedParameters.get("multi").size()); } } libcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-portlet/src/main/0000755000175000017500000000000015142145735025170 5ustar zigozigolibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-portlet/src/main/java/0000755000175000017500000000000015142145735026111 5ustar zigozigolibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-portlet/src/main/java/org/0000755000175000017500000000000015142145735026700 5ustar zigozigolibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-portlet/src/main/java/org/apache/0000755000175000017500000000000015142145735030121 5ustar zigozigolibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-portlet/src/main/java/org/apache/commons/0000755000175000017500000000000015142145735031574 5ustar zigozigo././@LongLink0000644000000000000000000000015700000000000011606 Lustar rootrootlibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-portlet/src/main/java/org/apache/commons/fileupload2/libcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-portlet/src/main/java/org/apache/commons/fi0000755000175000017500000000000015142145735032113 5ustar zigozigo././@LongLink0000644000000000000000000000016700000000000011607 Lustar rootrootlibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-portlet/src/main/java/org/apache/commons/fileupload2/portlet/libcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-portlet/src/main/java/org/apache/commons/fi0000755000175000017500000000000015227714536032120 5ustar zigozigo././@LongLink0000644000000000000000000000021000000000000011574 Lustar rootrootlibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-portlet/src/main/java/org/apache/commons/fileupload2/portlet/package-info.javalibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-portlet/src/main/java/org/apache/commons/fi0000644000175000017500000000347215142145735032123 0ustar zigozigo/* * 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 * * https://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. */ /** *

* An implementation of {@link org.apache.commons.fileupload2.core.AbstractFileUpload} for use in portlets conforming to JSR 168. This implementation requires * only access to the portlet's current {@code ActionRequest} instance, and a suitable {@link org.apache.commons.fileupload2.core.FileItemFactory} * implementation, such as {@link org.apache.commons.fileupload2.core.DiskFileItemFactory}. *

*

* The following code fragment demonstrates typical usage. *

* *
{@code
 * DiskFileItemFactory factory = DiskFileItemFactory().builder().get();
 * // Configure the factory here, if desired.
 * PortletFileUpload upload = new PortletFileUpload(factory);
 * // Configure the uploader here, if desired.
 * List fileItems = upload.parseRequest(request);
 * }
*

* Please see the FileUpload User Guide for further details and examples of how to * use this package. *

*/ package org.apache.commons.fileupload2.portlet; ././@LongLink0000644000000000000000000000022200000000000011577 Lustar rootrootlibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-portlet/src/main/java/org/apache/commons/fileupload2/portlet/JavaxPortletFileUpload.javalibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-portlet/src/main/java/org/apache/commons/fi0000644000175000017500000001227415142145735032123 0ustar zigozigo/* * 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 * * https://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.portlet; import java.io.IOException; import java.util.List; import java.util.Map; import javax.portlet.ActionRequest; import org.apache.commons.fileupload2.core.AbstractFileUpload; import org.apache.commons.fileupload2.core.FileItem; import org.apache.commons.fileupload2.core.FileItemFactory; import org.apache.commons.fileupload2.core.FileItemInputIterator; import org.apache.commons.fileupload2.core.FileUploadException; import org.apache.commons.fileupload2.javax.JavaxServletFileUpload; /** * High level API for processing file uploads. *

* This class handles multiple files per single HTML widget, sent using {@code multipart/mixed} encoding type, as specified by * RFC 1867. Use {@link JavaxServletFileUpload#parseRequest(javax.servlet.http.HttpServletRequest)} to * acquire a list of {@link FileItem}s associated with a given HTML widget. *

*

* 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. *

* * @param The FileItem type. * @param the FileItemFactory type. */ public class JavaxPortletFileUpload, F extends FileItemFactory> extends AbstractFileUpload { /** * Tests whether the request contains multipart content. * * @param request The portlet 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 ActionRequest request) { return AbstractFileUpload.isMultipartContent(new JavaxPortletRequestContext(request)); } /** * Constructs an uninitialized instance of this class. A factory must be configured, using {@code setFileItemFactory()}, before attempting to parse * requests. * * @see AbstractFileUpload#AbstractFileUpload() */ public JavaxPortletFileUpload() { } /** * Constructs an instance of this class which uses the supplied factory to create {@code FileItem} instances. * * @see AbstractFileUpload#AbstractFileUpload() * @param fileItemFactory The factory to use for creating file items. */ public JavaxPortletFileUpload(final F fileItemFactory) { setFileItemFactory(fileItemFactory); } /** * Gets an RFC 1867 compliant {@code multipart/form-data} file item iterator. * * @param request The portlet request to be parsed. * @return An iterator to instances of {@code FileItemInput} 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. */ @Override public FileItemInputIterator getItemIterator(final ActionRequest request) throws FileUploadException, IOException { return super.getItemIterator(new JavaxPortletRequestContext(request)); } /** * Parses an RFC 1867 compliant {@code multipart/form-data} stream. * * @param request The portlet 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. */ @Override public Map> parseParameterMap(final ActionRequest request) throws FileUploadException { return parseParameterMap(new JavaxPortletRequestContext(request)); } /** * Parses an RFC 1867 compliant {@code multipart/form-data} stream. * * @param request The portlet 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. */ @Override public List parseRequest(final ActionRequest request) throws FileUploadException { return parseRequest(new JavaxPortletRequestContext(request)); } } ././@LongLink0000644000000000000000000000022600000000000011603 Lustar rootrootlibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-portlet/src/main/java/org/apache/commons/fileupload2/portlet/JavaxPortletRequestContext.javalibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-portlet/src/main/java/org/apache/commons/fi0000644000175000017500000000431115142145735032114 0ustar zigozigo/* * 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 * * https://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.portlet; import java.io.IOException; import java.io.InputStream; import javax.portlet.ActionRequest; import org.apache.commons.fileupload2.core.AbstractRequestContext; /** * Provides access to the request information needed for a request made to a portlet. */ public class JavaxPortletRequestContext extends AbstractRequestContext { /** * Constructs a context for this request. * * @param request The request to which this context applies. */ public JavaxPortletRequestContext(final ActionRequest request) { super(request::getProperty, request::getContentLength, request); } /** * Gets the character encoding for the request. * * @return The character encoding for the request. */ @Override public String getCharacterEncoding() { return getRequest().getCharacterEncoding(); } /** * Gets the content type of the request. * * @return The content type of the request. */ @Override public String getContentType() { return getRequest().getContentType(); } /** * Gets the input stream for the request. * * @return The input stream for the request. * @throws IOException if a problem occurs. */ @Override public InputStream getInputStream() throws IOException { return getRequest().getPortletInputStream(); } } libcommons-fileupload2-java-2.0.0~M5/README.md0000644000175000017500000001506715142145735017377 0ustar zigozigo Apache Commons FileUpload =================== [![Java CI](https://github.com/apache/commons-fileupload/actions/workflows/maven.yml/badge.svg)](https://github.com/apache/commons-fileupload/actions/workflows/maven.yml) [![Maven Central](https://img.shields.io/maven-central/v/org.apache.commons/commons-fileupload2?label=Maven%20Central)](https://search.maven.org/artifact/org.apache.commons/commons-fileupload2) [![Javadocs](https://javadoc.io/badge/org.apache.commons/commons-fileupload2/2.0.0-M5.svg)](https://javadoc.io/doc/org.apache.commons/commons-fileupload2/2.0.0-M5) [![CodeQL](https://github.com/apache/commons-fileupload/actions/workflows/codeql-analysis.yml/badge.svg)](https://github.com/apache/commons-fileupload/actions/workflows/codeql-analysis.yml) [![OpenSSF Scorecard](https://api.securityscorecards.dev/projects/github.com/apache/commons-fileupload/badge)](https://api.securityscorecards.dev/projects/github.com/apache/commons-fileupload) The Apache Commons FileUpload component provides a simple yet flexible means of adding support for multipart file upload functionality to servlets and web applications. Documentation ------------- More information can be found on the [Apache Commons FileUpload homepage](https://commons.apache.org/proper/commons-fileupload). The [Javadoc](https://commons.apache.org/proper/commons-fileupload/apidocs) can be browsed. Questions related to the usage of Apache Commons FileUpload should be posted to the [user mailing list](https://commons.apache.org/mail-lists.html). Getting the latest release -------------------------- You can download source and binaries from our [download page](https://commons.apache.org/proper/commons-fileupload/download_fileupload.cgi). Alternatively, you can pull it from the central Maven repositories: ```xml org.apache.commons commons-fileupload2 2.0.0-M5 ``` Building -------- Building requires a Java JDK and [Apache Maven](https://maven.apache.org/). The required Java version is found in the `pom.xml` as the `maven.compiler.source` property. From a command shell, run `mvn` without arguments to invoke the default Maven goal to run all tests and checks. Contributing ------------ We accept Pull Requests via GitHub. The [developer mailing list](https://commons.apache.org/mail-lists.html) is the main channel of communication for contributors. There are some guidelines which will make applying PRs easier for us: + No tabs! Please use spaces for indentation. + Respect the existing code style for each file. + Create minimal diffs - disable on save actions like reformat source code or organize imports. If you feel the source code should be reformatted create a separate PR for this change. + Provide JUnit tests for your changes and make sure your changes don't break any existing tests by running `mvn`. + Before you push a PR, run `mvn` (without arguments). This runs the default goal which contains all build checks. + To see the code coverage report, regardless of coverage failures, run `mvn clean site -Dcommons.jacoco.haltOnFailure=false -Pjacoco` If you plan to contribute on a regular basis, please consider filing a [contributor license agreement](https://www.apache.org/licenses/#clas). You can learn more about contributing via GitHub in our [contribution guidelines](CONTRIBUTING.md). License ------- This code is licensed under the [Apache License v2](https://www.apache.org/licenses/LICENSE-2.0). See the `NOTICE.txt` file for required notices and attributions. Donating -------- You like Apache Commons FileUpload? Then [donate back to the ASF](https://www.apache.org/foundation/contributing.html) to support development. Additional Resources -------------------- + [Apache Commons Homepage](https://commons.apache.org/) + [Apache Issue Tracker (JIRA)](https://issues.apache.org/jira/browse/FILEUPLOAD) + [Apache Commons Slack Channel](https://the-asf.slack.com/archives/C60NVB8AD) Apache Commons Components ------------------------- Please see the [list of components](https://commons.apache.org/components.html) libcommons-fileupload2-java-2.0.0~M5/LICENSE.txt0000644000175000017500000002613715142145735017743 0ustar zigozigo Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright [yyyy] [name of copyright owner] Licensed 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 https://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. libcommons-fileupload2-java-2.0.0~M5/SECURITY.md0000644000175000017500000000160515142145735017702 0ustar zigozigo The Apache Commons security page is [https://commons.apache.org/security.html](https://commons.apache.org/security.html). libcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-jakarta-servlet5/0000755000175000017500000000000015227714536025155 5ustar zigozigolibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-jakarta-servlet5/pom.xml0000644000175000017500000001330315142145735026465 0ustar zigozigo 4.0.0 org.apache.commons commons-fileupload2 2.0.0-M5 ../ commons-fileupload2-jakarta-servlet5 Apache Commons FileUpload Jakarta Servlet 5 The Apache Commons FileUpload Jakarta component provides a simple yet flexible means of adding support for multipart file upload functionality to Jakarta servlets and web applications. ${basedir}/.. org.apache.commons.fileupload2.jakarta.servlet5 osgi.contract;filter:="(&(osgi.contract=JakartaServlet)(version=5.0))" https://jakarta.ee/specifications/platform/9.1/apidocs/ 2026-02-08T17:46:05Z 0.75 0.60 0.61 0.00 0.60 0.55 org.apache.commons commons-fileupload2-core 2.0.0-M5 org.apache.commons commons-fileupload2-core 2.0.0-M5 tests test org.junit.jupiter junit-jupiter test commons-io commons-io jakarta.servlet jakarta.servlet-api 5.0.0 provided org.apache.commons commons-lang3 test org.apache.maven.plugins maven-dependency-plugin dep-unpack-main-resources unpack generate-resources ${project.build.outputDirectory} dep-unpack-test-resources unpack generate-resources ${project.build.testOutputDirectory} org.apache apache-jar-resource-bundle 1.4 META-INF/LICENSE.txt,META-INF/NOTICE.txt org.apache.rat apache-rat-plugin .project .classpath .settings/**/ bin/** libcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-jakarta-servlet5/src/0000755000175000017500000000000015142145735025737 5ustar zigozigolibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-jakarta-servlet5/src/site/0000755000175000017500000000000015142145735026703 5ustar zigozigolibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-jakarta-servlet5/src/site/resources/0000755000175000017500000000000015227714536030722 5ustar zigozigo././@LongLink0000644000000000000000000000015400000000000011603 Lustar rootrootlibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-jakarta-servlet5/src/site/resources/profile.jacocolibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-jakarta-servlet5/src/site/resources/profile0000644000175000017500000000166215142145735032305 0ustar zigozigo# 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 # # https://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. # ----------------------------------------------------------------------------- # # Empty file used to automatically trigger JaCoCo profile from commons parent pom libcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-jakarta-servlet5/src/test/0000755000175000017500000000000015142145735026716 5ustar zigozigolibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-jakarta-servlet5/src/test/java/0000755000175000017500000000000015142145735027637 5ustar zigozigolibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-jakarta-servlet5/src/test/java/org/0000755000175000017500000000000015142145735030426 5ustar zigozigolibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-jakarta-servlet5/src/test/java/org/apache/0000755000175000017500000000000015142145735031647 5ustar zigozigo././@LongLink0000644000000000000000000000015400000000000011603 Lustar rootrootlibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-jakarta-servlet5/src/test/java/org/apache/commons/libcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-jakarta-servlet5/src/test/java/org/apache/c0000755000175000017500000000000015142145735032012 5ustar zigozigo././@LongLink0000644000000000000000000000017000000000000011601 Lustar rootrootlibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-jakarta-servlet5/src/test/java/org/apache/commons/fileupload2/libcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-jakarta-servlet5/src/test/java/org/apache/c0000755000175000017500000000000015142145735032012 5ustar zigozigo././@LongLink0000644000000000000000000000020000000000000011573 Lustar rootrootlibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-jakarta-servlet5/src/test/java/org/apache/commons/fileupload2/jakarta/libcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-jakarta-servlet5/src/test/java/org/apache/c0000755000175000017500000000000015142145735032012 5ustar zigozigo././@LongLink0000644000000000000000000000021100000000000011575 Lustar rootrootlibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-jakarta-servlet5/src/test/java/org/apache/commons/fileupload2/jakarta/servlet5/libcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-jakarta-servlet5/src/test/java/org/apache/c0000755000175000017500000000000015227714536032017 5ustar zigozigo././@LongLink0000644000000000000000000000024200000000000011601 Lustar rootrootlibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-jakarta-servlet5/src/test/java/org/apache/commons/fileupload2/jakarta/servlet5/JakartaSizesDiskTest.javalibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-jakarta-servlet5/src/test/java/org/apache/c0000644000175000017500000000333215142145735032015 0ustar zigozigo/* * 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 * * https://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.jakarta.servlet5; import java.io.InputStream; import org.apache.commons.fileupload2.core.AbstractSizesTest; import org.apache.commons.fileupload2.core.DiskFileItem; import org.apache.commons.fileupload2.core.DiskFileItemFactory; import jakarta.servlet.http.HttpServletRequest; /** * Unit test for items with varying sizes. */ class JakartaSizesDiskTest extends AbstractSizesTest { @Override protected JakartaServletDiskFileUpload newFileUpload() { return new JakartaServletDiskFileUpload(); } @Override protected JakartaMockHttpServletRequest newMockHttpServletRequest(final InputStream request, final long requestLength, final String contentType, final int readLimit) { return new JakartaMockHttpServletRequest(request, requestLength, contentType, readLimit); } } ././@LongLink0000644000000000000000000000025600000000000011606 Lustar rootrootlibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-jakarta-servlet5/src/test/java/org/apache/commons/fileupload2/jakarta/servlet5/JakartaServletFileUploadDiskTest.javalibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-jakarta-servlet5/src/test/java/org/apache/c0000644000175000017500000001171715142145735032023 0ustar zigozigo/* * 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 * * https://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.jakarta.servlet5; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; import java.nio.charset.StandardCharsets; import java.util.List; import org.apache.commons.fileupload2.core.AbstractFileUploadTest; import org.apache.commons.fileupload2.core.Constants; import org.apache.commons.fileupload2.core.DiskFileItem; import org.apache.commons.fileupload2.core.DiskFileItemFactory; import org.apache.commons.fileupload2.core.FileUploadException; import org.junit.jupiter.api.Test; import jakarta.servlet.http.HttpServletRequest; /** * Tests {@link JakartaServletFileUpload} and * * @see AbstractFileUploadTest */ class JakartaServletFileUploadDiskTest extends AbstractFileUploadTest { public JakartaServletFileUploadDiskTest() { super(new JakartaServletDiskFileUpload()); } @Override public List parseUpload(final JakartaServletDiskFileUpload upload, final byte[] bytes, final String contentType) throws FileUploadException { final HttpServletRequest request = new JakartaMockHttpServletRequest(bytes, contentType); return upload.parseRequest(new JakartaServletRequestContext(request)); } @Test void testParseImpliedUtf8() throws Exception { // utf8 encoded form-data without explicit content-type encoding // @formatter:off final var text = "-----1234\r\n" + "Content-Disposition: form-data; name=\"utf8Html\"\r\n" + "\r\n" + "Thís ís the coñteñt of the fíle\n" + "\r\n" + "-----1234--\r\n"; // @formatter:on final var bytes = text.getBytes(StandardCharsets.UTF_8); final HttpServletRequest request = new JakartaMockServletHttpRequest(bytes, Constants.CONTENT_TYPE); // @formatter:off final var fileItemFactory = DiskFileItemFactory.builder() .setCharset(StandardCharsets.UTF_8) .get(); // @formatter:on final var upload = new JakartaServletDiskFileUpload(fileItemFactory); final var fileItems = upload.parseRequest(request); final var fileItem = fileItems.get(0); assertTrue(fileItem.getString().contains("coñteñt"), fileItem.getString()); } /* * Test case for */ @Test void testParseParameterMap() throws Exception { // @formatter:off final var text = "-----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" + "Content-Disposition: form-data; name=\"field\"\r\n" + "\r\n" + "fieldValue\r\n" + "-----1234\r\n" + "Content-Disposition: form-data; name=\"multi\"\r\n" + "\r\n" + "value1\r\n" + "-----1234\r\n" + "Content-Disposition: form-data; name=\"multi\"\r\n" + "\r\n" + "value2\r\n" + "-----1234--\r\n"; // @formatter:on final var bytes = text.getBytes(StandardCharsets.US_ASCII); final HttpServletRequest request = new JakartaMockServletHttpRequest(bytes, Constants.CONTENT_TYPE); final var upload = new JakartaServletDiskFileUpload(); final var mappedParameters = upload.parseParameterMap(request); assertTrue(mappedParameters.containsKey("file")); assertEquals(1, mappedParameters.get("file").size()); assertTrue(mappedParameters.containsKey("field")); assertEquals(1, mappedParameters.get("field").size()); assertTrue(mappedParameters.containsKey("multi")); assertEquals(2, mappedParameters.get("multi").size()); } } ././@LongLink0000644000000000000000000000025200000000000011602 Lustar rootrootlibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-jakarta-servlet5/src/test/java/org/apache/commons/fileupload2/jakarta/servlet5/JakartaServletFileUploadTest.javalibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-jakarta-servlet5/src/test/java/org/apache/c0000644000175000017500000001314515142145735032020 0ustar zigozigo/* * 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 * * https://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.jakarta.servlet5; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; import java.nio.charset.StandardCharsets; import java.util.List; import java.util.concurrent.atomic.AtomicInteger; import org.apache.commons.fileupload2.core.AbstractFileUploadTest; import org.apache.commons.fileupload2.core.Constants; import org.apache.commons.fileupload2.core.DiskFileItem; import org.apache.commons.fileupload2.core.DiskFileItemFactory; import org.apache.commons.fileupload2.core.FileUploadException; import org.junit.jupiter.api.Test; import jakarta.servlet.http.HttpServletRequest; /** * Tests {@link JakartaServletFileUpload}. * * @see AbstractFileUploadTest */ class JakartaServletFileUploadTest extends AbstractFileUploadTest, HttpServletRequest, DiskFileItem, DiskFileItemFactory> { public JakartaServletFileUploadTest() { super(new JakartaServletFileUpload<>(DiskFileItemFactory.builder().get())); } @Override public List parseUpload(final JakartaServletFileUpload upload, final byte[] bytes, final String contentType) throws FileUploadException { final HttpServletRequest request = new JakartaMockHttpServletRequest(bytes, contentType); return upload.parseRequest(new JakartaServletRequestContext(request)); } @Test void testParseImpliedUtf8() throws Exception { // utf8 encoded form-data without explicit content-type encoding // @formatter:off final var text = "-----1234\r\n" + "Content-Disposition: form-data; name=\"utf8Html\"\r\n" + "\r\n" + "Thís ís the coñteñt of the fíle\n" + "\r\n" + "-----1234--\r\n"; // @formatter:on final var bytes = text.getBytes(StandardCharsets.UTF_8); final HttpServletRequest request = new JakartaMockServletHttpRequest(bytes, Constants.CONTENT_TYPE); // @formatter:off final var fileItemFactory = DiskFileItemFactory.builder() .setCharset(StandardCharsets.UTF_8) .get(); // @formatter:on final var upload = new JakartaServletFileUpload<>(fileItemFactory); final var fileItems = upload.parseRequest(request); final var fileItem = fileItems.get(0); assertTrue(fileItem.getString().contains("coñteñt"), fileItem.getString()); } /* * Test case for */ @Test void testParseParameterMap() throws Exception { // @formatter:off final var text = "-----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" + "Content-Disposition: form-data; name=\"field\"\r\n" + "\r\n" + "fieldValue\r\n" + "-----1234\r\n" + "Content-Disposition: form-data; name=\"multi\"\r\n" + "\r\n" + "value1\r\n" + "-----1234\r\n" + "Content-Disposition: form-data; name=\"multi\"\r\n" + "\r\n" + "value2\r\n" + "-----1234--\r\n"; // @formatter:on final var bytes = text.getBytes(StandardCharsets.US_ASCII); final HttpServletRequest request = new JakartaMockServletHttpRequest(bytes, Constants.CONTENT_TYPE); final var upload = new JakartaServletFileUpload<>(DiskFileItemFactory.builder().get()); final var mappedParameters = upload.parseParameterMap(request); assertTrue(mappedParameters.containsKey("file")); assertEquals(1, mappedParameters.get("file").size()); assertTrue(mappedParameters.containsKey("field")); assertEquals(1, mappedParameters.get("field").size()); assertTrue(mappedParameters.containsKey("multi")); assertEquals(2, mappedParameters.get("multi").size()); final var itemCount = new AtomicInteger(); // Replace iterator with this one to make test passed final var request2 = new JakartaMockServletHttpRequest(bytes, Constants.CONTENT_TYPE); upload.parseParameterMap(request); upload.getItemIterator(request2).forEachRemaining(item -> itemCount.incrementAndGet()); upload.getItemIterator(request).forEachRemaining(item -> itemCount.incrementAndGet()); assertEquals(4, itemCount.get()); } } ././@LongLink0000644000000000000000000000025100000000000011601 Lustar rootrootlibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-jakarta-servlet5/src/test/java/org/apache/commons/fileupload2/jakarta/servlet5/JakartaProgressListenerTest.javalibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-jakarta-servlet5/src/test/java/org/apache/c0000644000175000017500000000353515142145735032022 0ustar zigozigo/* * 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 * * https://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.jakarta.servlet5; import java.io.InputStream; import org.apache.commons.fileupload2.core.AbstractProgressListenerTest; import org.apache.commons.fileupload2.core.DiskFileItem; import org.apache.commons.fileupload2.core.DiskFileItemFactory; import org.apache.commons.fileupload2.core.ProgressListener; import jakarta.servlet.http.HttpServletRequest; /** * Tests the {@link ProgressListener}. */ class JakartaProgressListenerTest extends AbstractProgressListenerTest, HttpServletRequest, DiskFileItem, DiskFileItemFactory> { @Override protected JakartaServletFileUpload newFileUpload() { return new JakartaServletFileUpload<>(); } @Override protected HttpServletRequest newMockHttpServletRequest(final InputStream request, final long requestLength, final String contentType, final int readLimit) { return new JakartaMockHttpServletRequest(request, requestLength, contentType, readLimit); } } ././@LongLink0000644000000000000000000000023600000000000011604 Lustar rootrootlibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-jakarta-servlet5/src/test/java/org/apache/commons/fileupload2/jakarta/servlet5/JakartaSizesTest.javalibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-jakarta-servlet5/src/test/java/org/apache/c0000644000175000017500000000347515142145735032025 0ustar zigozigo/* * 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 * * https://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.jakarta.servlet5; import java.io.InputStream; import org.apache.commons.fileupload2.core.AbstractSizesTest; import org.apache.commons.fileupload2.core.DiskFileItem; import org.apache.commons.fileupload2.core.DiskFileItemFactory; import jakarta.servlet.http.HttpServletRequest; /** * Unit test for items with varying sizes. */ class JakartaSizesTest extends AbstractSizesTest, HttpServletRequest, DiskFileItem, DiskFileItemFactory> { @Override protected JakartaServletFileUpload newFileUpload() { return new JakartaServletFileUpload<>(DiskFileItemFactory.builder().get()); } @Override protected JakartaMockHttpServletRequest newMockHttpServletRequest(final InputStream request, final long requestLength, final String contentType, final int readLimit) { return new JakartaMockHttpServletRequest(request, requestLength, contentType, readLimit); } } ././@LongLink0000644000000000000000000000025500000000000011605 Lustar rootrootlibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-jakarta-servlet5/src/test/java/org/apache/commons/fileupload2/jakarta/servlet5/JakartaProgressListenerDiskTest.javalibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-jakarta-servlet5/src/test/java/org/apache/c0000644000175000017500000000350415142145735032016 0ustar zigozigo/* * 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 * * https://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.jakarta.servlet5; import java.io.InputStream; import org.apache.commons.fileupload2.core.AbstractProgressListenerTest; import org.apache.commons.fileupload2.core.DiskFileItem; import org.apache.commons.fileupload2.core.DiskFileItemFactory; import org.apache.commons.fileupload2.core.ProgressListener; import jakarta.servlet.http.HttpServletRequest; /** * Tests the {@link ProgressListener}. */ class JakartaProgressListenerDiskTest extends AbstractProgressListenerTest, HttpServletRequest, DiskFileItem, DiskFileItemFactory> { @Override protected JakartaServletDiskFileUpload newFileUpload() { return new JakartaServletDiskFileUpload(); } @Override protected HttpServletRequest newMockHttpServletRequest(final InputStream request, final long requestLength, final String contentType, final int readLimit) { return new JakartaMockHttpServletRequest(request, requestLength, contentType, readLimit); } } ././@LongLink0000644000000000000000000000025300000000000011603 Lustar rootrootlibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-jakarta-servlet5/src/test/java/org/apache/commons/fileupload2/jakarta/servlet5/JakartaMockServletHttpRequest.javalibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-jakarta-servlet5/src/test/java/org/apache/c0000644000175000017500000003611115142145735032016 0ustar zigozigo/* * 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 * * https://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.jakarta.servlet5; import java.io.BufferedReader; import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; import java.io.UnsupportedEncodingException; import java.security.Principal; import java.util.Collection; import java.util.Enumeration; import java.util.Locale; import java.util.Map; import org.apache.commons.fileupload2.core.AbstractFileUpload; import jakarta.servlet.AsyncContext; import jakarta.servlet.DispatcherType; import jakarta.servlet.ReadListener; import jakarta.servlet.RequestDispatcher; import jakarta.servlet.ServletContext; import jakarta.servlet.ServletException; import jakarta.servlet.ServletInputStream; import jakarta.servlet.ServletRequest; import jakarta.servlet.ServletResponse; import jakarta.servlet.http.Cookie; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; import jakarta.servlet.http.HttpSession; import jakarta.servlet.http.HttpUpgradeHandler; import jakarta.servlet.http.Part; public class JakartaMockServletHttpRequest implements HttpServletRequest { private static final class MyServletInputStream extends jakarta.servlet.ServletInputStream { private final InputStream inputStream; private final int readLimit; /** * Creates a new instance, which returns the given streams data. */ public MyServletInputStream(final InputStream inputStream, final int readLimit) { this.inputStream = inputStream; this.readLimit = readLimit; } @Override public boolean isFinished() { return false; } @Override public boolean isReady() { return false; } @Override public int read() throws IOException { return inputStream.read(); } @Override public int read(final byte[] b, final int off, final int len) throws IOException { if (readLimit > 0) { return inputStream.read(b, off, Math.min(readLimit, len)); } return inputStream.read(b, off, len); } @Override public void setReadListener(final ReadListener readListener) { throw new IllegalStateException("Not implemented"); } } private final InputStream requestInputStream; private long requestLength; private final String contentType; private int readLimit = -1; private final Map headers = new java.util.HashMap<>(); /** * Creates a new instance with the given request data and content type. */ public JakartaMockServletHttpRequest(final byte[] requestData, final String strContentType) { this(new ByteArrayInputStream(requestData), requestData.length, strContentType); } /** * Creates a new instance with the given request data and content type. */ public JakartaMockServletHttpRequest(final InputStream requestData, final long requestLength, final String strContentType) { this.requestInputStream = requestData; this.requestLength = requestLength; this.contentType = strContentType; this.headers.put(AbstractFileUpload.CONTENT_TYPE, strContentType); } @Override public boolean authenticate(final HttpServletResponse response) throws IOException, ServletException { return false; } @Override public String changeSessionId() { return null; } @Override public AsyncContext getAsyncContext() { return null; } /** * @see ServletRequest#getAttribute(String) */ @Override public Object getAttribute(final String arg0) { return null; } /** * @see ServletRequest#getAttributeNames() */ @Override public Enumeration getAttributeNames() { return null; } /** * @see HttpServletRequest#getAuthType() */ @Override public String getAuthType() { return null; } /** * @see ServletRequest#getCharacterEncoding() */ @Override public String getCharacterEncoding() { return null; } /** * @see ServletRequest#getContentLength() */ @Override public int getContentLength() { return requestInputStream != null ? Math.toIntExact(requestLength) : -1; } @Override public long getContentLengthLong() { return getContentLength(); } /** * @see ServletRequest#getContentType() */ @Override public String getContentType() { return contentType; } /** * @see HttpServletRequest#getContextPath() */ @Override public String getContextPath() { return null; } /** * @see HttpServletRequest#getCookies() */ @Override public Cookie[] getCookies() { return null; } /** * @see HttpServletRequest#getDateHeader(String) */ @Override public long getDateHeader(final String arg0) { return 0; } @Override public DispatcherType getDispatcherType() { return null; } /** * @see HttpServletRequest#getHeader(String) */ @Override public String getHeader(final String headerName) { return headers.get(headerName); } /** * @see HttpServletRequest#getHeaderNames() */ @Override public Enumeration getHeaderNames() { // todo - implement return null; } /** * @see HttpServletRequest#getHeaders(String) */ @Override public Enumeration getHeaders(final String arg0) { // todo - implement return null; } /** * @see ServletRequest#getInputStream() */ @Override public ServletInputStream getInputStream() throws IOException { return new MyServletInputStream(requestInputStream, readLimit); } /** * @see HttpServletRequest#getIntHeader(String) */ @Override public int getIntHeader(final String arg0) { return 0; } /** * @see ServletRequest#getLocalAddr() */ @Override @SuppressWarnings("javadoc") // This is a Servlet 2.4 method public String getLocalAddr() { return null; } /** * @see ServletRequest#getLocale() */ @Override public Locale getLocale() { return null; } /** * @see ServletRequest#getLocales() */ @Override public Enumeration getLocales() { return null; } /** * @see ServletRequest#getLocalName() */ @Override @SuppressWarnings("javadoc") // This is a Servlet 2.4 method public String getLocalName() { return null; } /** * @see ServletRequest#getLocalPort() */ @Override @SuppressWarnings("javadoc") // This is a Servlet 2.4 method public int getLocalPort() { return 0; } /** * @see HttpServletRequest#getMethod() */ @Override public String getMethod() { return null; } /** * @see ServletRequest#getParameter(String) */ @Override public String getParameter(final String arg0) { return null; } /** * @see ServletRequest#getParameterMap() */ @Override public Map getParameterMap() { return null; } /** * @see ServletRequest#getParameterNames() */ @Override public Enumeration getParameterNames() { return null; } /** * @see ServletRequest#getParameterValues(String) */ @Override public String[] getParameterValues(final String arg0) { return null; } @Override public Part getPart(final String name) throws IOException, ServletException { return null; } @Override public Collection getParts() throws IOException, ServletException { return null; } /** * @see HttpServletRequest#getPathInfo() */ @Override public String getPathInfo() { return null; } /** * @see HttpServletRequest#getPathTranslated() */ @Override public String getPathTranslated() { return null; } /** * @see ServletRequest#getProtocol() */ @Override public String getProtocol() { return null; } public String getProtocolRequestId() { throw new IllegalStateException("Not implemented 6.0.0"); } /** * @see HttpServletRequest#getQueryString() */ @Override public String getQueryString() { return null; } /** * @see ServletRequest#getReader() */ @Override public BufferedReader getReader() throws IOException { return null; } @Override public String getRealPath(final String path) { return null; } /** * @see ServletRequest#getRemoteAddr() */ @Override public String getRemoteAddr() { return null; } /** * @see ServletRequest#getRemoteHost() */ @Override public String getRemoteHost() { return null; } /** * @see ServletRequest#getRemotePort() */ @Override @SuppressWarnings("javadoc") // This is a Servlet 2.4 method public int getRemotePort() { return 0; } /** * @see HttpServletRequest#getRemoteUser() */ @Override public String getRemoteUser() { return null; } /** * @see ServletRequest#getRequestDispatcher(String) */ @Override public RequestDispatcher getRequestDispatcher(final String arg0) { return null; } /** * @see HttpServletRequest#getRequestedSessionId() */ @Override public String getRequestedSessionId() { return null; } public String getRequestId() { throw new IllegalStateException("Not implemented 6.0.0"); } /** * @see HttpServletRequest#getRequestURI() */ @Override public String getRequestURI() { return null; } /** * @see HttpServletRequest#getRequestURL() */ @Override public StringBuffer getRequestURL() { return null; } /** * @see ServletRequest#getScheme() */ @Override public String getScheme() { return null; } /** * @see ServletRequest#getServerName() */ @Override public String getServerName() { return null; } /** * @see ServletRequest#getServerPort() */ @Override public int getServerPort() { return 0; } @Override public ServletContext getServletContext() { final var session = getSession(); if (session == null) { return null; } return session.getServletContext(); } /** * @see HttpServletRequest#getServletPath() */ @Override public String getServletPath() { return null; } /** * @see HttpServletRequest#getSession() */ @Override public HttpSession getSession() { return null; } /** * @see HttpServletRequest#getSession(boolean) */ @Override public HttpSession getSession(final boolean arg0) { return null; } /** * @see HttpServletRequest#getUserPrincipal() */ @Override public Principal getUserPrincipal() { return null; } @Override public boolean isAsyncStarted() { return false; } @Override public boolean isAsyncSupported() { return false; } /** * @see HttpServletRequest#isRequestedSessionIdFromCookie() */ @Override public boolean isRequestedSessionIdFromCookie() { return false; } /** * @see HttpServletRequest#isRequestedSessionIdFromUrl() * @deprecated */ @Override @Deprecated public boolean isRequestedSessionIdFromUrl() { return false; } /** * @see HttpServletRequest#isRequestedSessionIdFromURL() */ @Override public boolean isRequestedSessionIdFromURL() { return false; } /** * @see HttpServletRequest#isRequestedSessionIdValid() */ @Override public boolean isRequestedSessionIdValid() { return false; } /** * @see ServletRequest#isSecure() */ @Override public boolean isSecure() { return false; } /** * @see HttpServletRequest#isUserInRole(String) */ @Override public boolean isUserInRole(final String arg0) { return false; } @Override public void login(final String username, final String password) throws ServletException { throw new IllegalStateException("Not implemented"); } @Override public void logout() throws ServletException { throw new IllegalStateException("Not implemented"); } /** * @see ServletRequest#removeAttribute(String) */ @Override public void removeAttribute(final String arg0) { } /** * @see ServletRequest#setAttribute(String, Object) */ @Override public void setAttribute(final String arg0, final Object arg1) { } /** * @see ServletRequest#setCharacterEncoding(String) */ @Override public void setCharacterEncoding(final String arg0) throws UnsupportedEncodingException { } /** * For testing attack scenarios in SizesTest. */ public void setContentLength(final long length) { this.requestLength = length; } /** * Sets the read limit. This can be used to limit the number of bytes to read ahead. * * @param readLimit the read limit to use */ public void setReadLimit(final int readLimit) { this.readLimit = readLimit; } @Override public AsyncContext startAsync() throws IllegalStateException { throw new IllegalStateException("Not implemented"); } @Override public AsyncContext startAsync(final ServletRequest servletRequest, final ServletResponse servletResponse) throws IllegalStateException { throw new IllegalStateException("Not implemented"); } @Override public T upgrade(final Class handlerClass) throws IOException, ServletException { throw new IllegalStateException("Not implemented"); } // @Override // public ServletConnection getServletConnection() { // throw new IllegalStateException("Not implemented 6.0.0"); // } } ././@LongLink0000644000000000000000000000025300000000000011603 Lustar rootrootlibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-jakarta-servlet5/src/test/java/org/apache/commons/fileupload2/jakarta/servlet5/JakartaMockHttpServletRequest.javalibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-jakarta-servlet5/src/test/java/org/apache/c0000644000175000017500000003411415142145735032017 0ustar zigozigo/* * 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 * * https://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.jakarta.servlet5; import java.io.BufferedReader; import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; import java.io.UnsupportedEncodingException; import java.security.Principal; import java.util.Collection; import java.util.Enumeration; import java.util.HashMap; import java.util.Locale; import java.util.Map; import org.apache.commons.fileupload2.core.AbstractFileUpload; import jakarta.servlet.AsyncContext; import jakarta.servlet.DispatcherType; import jakarta.servlet.ReadListener; import jakarta.servlet.RequestDispatcher; import jakarta.servlet.ServletContext; import jakarta.servlet.ServletException; import jakarta.servlet.ServletInputStream; import jakarta.servlet.ServletRequest; import jakarta.servlet.ServletResponse; import jakarta.servlet.http.Cookie; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; import jakarta.servlet.http.HttpSession; import jakarta.servlet.http.HttpUpgradeHandler; import jakarta.servlet.http.Part; /** * Test fixture for {@link HttpServletRequest}. */ public class JakartaMockHttpServletRequest implements HttpServletRequest { private static final class MyServletInputStream extends ServletInputStream { private final InputStream inputStream; private final int readLimit; /** * Creates a new instance, which returns the given streams data. */ MyServletInputStream(final InputStream inputStream, final int readLimit) { this.inputStream = inputStream; this.readLimit = readLimit; } @Override public boolean isFinished() { return false; } @Override public boolean isReady() { return false; } @Override public int read() throws IOException { return inputStream.read(); } @Override public int read(final byte[] b, final int off, final int len) throws IOException { if (readLimit > 0) { return inputStream.read(b, off, Math.min(readLimit, len)); } return inputStream.read(b, off, len); } @Override public void setReadListener(final ReadListener readListener) { } } private final InputStream requestInputStream; private final long requestLength; private final String contentType; private final int readLimit; private final Map headers = new HashMap<>(); /** * Creates a new instance with the given request data and content type. */ public JakartaMockHttpServletRequest(final byte[] requestData, final String contentType) { this(new ByteArrayInputStream(requestData), requestData.length, contentType, -1); } /** * Creates a new instance with the given request data and content type. */ public JakartaMockHttpServletRequest(final InputStream requestInputStream, final long requestLength, final String contentType, final int readLimit) { this.requestInputStream = requestInputStream; this.requestLength = requestLength; this.contentType = contentType; this.headers.put(AbstractFileUpload.CONTENT_TYPE, contentType); this.readLimit = readLimit; } @Override public boolean authenticate(final HttpServletResponse response) throws IOException, ServletException { return false; } @Override public String changeSessionId() { return null; } @Override public AsyncContext getAsyncContext() { return null; } /** * @see ServletRequest#getAttribute(String) */ @Override public Object getAttribute(final String arg0) { return null; } /** * @see ServletRequest#getAttributeNames() */ @Override public Enumeration getAttributeNames() { return null; } /** * @see HttpServletRequest#getAuthType() */ @Override public String getAuthType() { return null; } /** * @see ServletRequest#getCharacterEncoding() */ @Override public String getCharacterEncoding() { return null; } /** * @see ServletRequest#getContentLength() */ @Override public int getContentLength() { return requestInputStream != null ? Math.toIntExact(requestLength) : -1; } @Override public long getContentLengthLong() { return 0; } /** * @see ServletRequest#getContentType() */ @Override public String getContentType() { return contentType; } /** * @see HttpServletRequest#getContextPath() */ @Override public String getContextPath() { return null; } /** * @see HttpServletRequest#getCookies() */ @Override public Cookie[] getCookies() { return null; } /** * @see HttpServletRequest#getDateHeader(String) */ @Override public long getDateHeader(final String arg0) { return 0; } @Override public DispatcherType getDispatcherType() { return null; } /** * @see HttpServletRequest#getHeader(String) */ @Override public String getHeader(final String headerName) { return headers.get(headerName); } /** * @see HttpServletRequest#getHeaderNames() */ @Override public Enumeration getHeaderNames() { // todo - implement return null; } /** * @see HttpServletRequest#getHeaders(String) */ @Override public Enumeration getHeaders(final String arg0) { // todo - implement return null; } /** * @see ServletRequest#getInputStream() */ @Override public ServletInputStream getInputStream() throws IOException { return new MyServletInputStream(requestInputStream, readLimit); } /** * @see HttpServletRequest#getIntHeader(String) */ @Override public int getIntHeader(final String arg0) { return 0; } /** * @see ServletRequest#getLocalAddr() */ @Override @SuppressWarnings("javadoc") // This is a Servlet 2.4 method public String getLocalAddr() { return null; } /** * @see ServletRequest#getLocale() */ @Override public Locale getLocale() { return null; } /** * @see ServletRequest#getLocales() */ @Override public Enumeration getLocales() { return null; } /** * @see ServletRequest#getLocalName() */ @Override @SuppressWarnings("javadoc") // This is a Servlet 2.4 method public String getLocalName() { return null; } /** * @see ServletRequest#getLocalPort() */ @Override @SuppressWarnings("javadoc") // This is a Servlet 2.4 method public int getLocalPort() { return 0; } /** * @see HttpServletRequest#getMethod() */ @Override public String getMethod() { return null; } /** * @see ServletRequest#getParameter(String) */ @Override public String getParameter(final String arg0) { return null; } /** * @see ServletRequest#getParameterMap() */ @Override public Map getParameterMap() { return null; } /** * @see ServletRequest#getParameterNames() */ @Override public Enumeration getParameterNames() { return null; } /** * @see ServletRequest#getParameterValues(String) */ @Override public String[] getParameterValues(final String arg0) { return null; } @Override public Part getPart(final String name) throws IOException, ServletException { return null; } @Override public Collection getParts() throws IOException, ServletException { return null; } /** * @see HttpServletRequest#getPathInfo() */ @Override public String getPathInfo() { return null; } /** * @see HttpServletRequest#getPathTranslated() */ @Override public String getPathTranslated() { return null; } /** * @see ServletRequest#getProtocol() */ @Override public String getProtocol() { return null; } /** * @see HttpServletRequest#getQueryString() */ @Override public String getQueryString() { return null; } /** * @see ServletRequest#getReader() */ @Override public BufferedReader getReader() throws IOException { return null; } /** * @see ServletRequest#getRealPath(String) * @deprecated */ @Override @Deprecated public String getRealPath(final String arg0) { return null; } /** * @see ServletRequest#getRemoteAddr() */ @Override public String getRemoteAddr() { return null; } /** * @see ServletRequest#getRemoteHost() */ @Override public String getRemoteHost() { return null; } /** * @see ServletRequest#getRemotePort() */ @Override @SuppressWarnings("javadoc") // This is a Servlet 2.4 method public int getRemotePort() { return 0; } /** * @see HttpServletRequest#getRemoteUser() */ @Override public String getRemoteUser() { return null; } /** * @see ServletRequest#getRequestDispatcher(String) */ @Override public RequestDispatcher getRequestDispatcher(final String arg0) { return null; } /** * @see HttpServletRequest#getRequestedSessionId() */ @Override public String getRequestedSessionId() { return null; } /** * @see HttpServletRequest#getRequestURI() */ @Override public String getRequestURI() { return null; } /** * @see HttpServletRequest#getRequestURL() */ @Override public StringBuffer getRequestURL() { return null; } /** * @see ServletRequest#getScheme() */ @Override public String getScheme() { return null; } /** * @see ServletRequest#getServerName() */ @Override public String getServerName() { return null; } /** * @see ServletRequest#getServerPort() */ @Override public int getServerPort() { return 0; } @Override public ServletContext getServletContext() { return null; } /** * @see HttpServletRequest#getServletPath() */ @Override public String getServletPath() { return null; } /** * @see HttpServletRequest#getSession() */ @Override public HttpSession getSession() { return null; } /** * @see HttpServletRequest#getSession(boolean) */ @Override public HttpSession getSession(final boolean arg0) { return null; } /** * @see HttpServletRequest#getUserPrincipal() */ @Override public Principal getUserPrincipal() { return null; } @Override public boolean isAsyncStarted() { return false; } @Override public boolean isAsyncSupported() { return false; } /** * @see HttpServletRequest#isRequestedSessionIdFromCookie() */ @Override public boolean isRequestedSessionIdFromCookie() { return false; } /** * @see HttpServletRequest#isRequestedSessionIdFromUrl() * @deprecated */ @Override @Deprecated public boolean isRequestedSessionIdFromUrl() { return false; } /** * @see HttpServletRequest#isRequestedSessionIdFromURL() */ @Override public boolean isRequestedSessionIdFromURL() { return false; } /** * @see HttpServletRequest#isRequestedSessionIdValid() */ @Override public boolean isRequestedSessionIdValid() { return false; } /** * @see ServletRequest#isSecure() */ @Override public boolean isSecure() { return false; } /** * @see HttpServletRequest#isUserInRole(String) */ @Override public boolean isUserInRole(final String arg0) { return false; } @Override public void login(final String username, final String password) throws ServletException { } @Override public void logout() throws ServletException { } /** * @see ServletRequest#removeAttribute(String) */ @Override public void removeAttribute(final String arg0) { } /** * @see ServletRequest#setAttribute(String, Object) */ @Override public void setAttribute(final String arg0, final Object arg1) { } /** * @see ServletRequest#setCharacterEncoding(String) */ @Override public void setCharacterEncoding(final String arg0) throws UnsupportedEncodingException { } @Override public AsyncContext startAsync() throws IllegalStateException { return null; } @Override public AsyncContext startAsync(final ServletRequest servletRequest, final ServletResponse servletResponse) throws IllegalStateException { return null; } @Override public T upgrade(final Class handlerClass) throws IOException, ServletException { return null; } } ././@LongLink0000644000000000000000000000024600000000000011605 Lustar rootrootlibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-jakarta-servlet5/src/test/java/org/apache/commons/fileupload2/jakarta/servlet5/JakartaStreamingDiskTest.javalibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-jakarta-servlet5/src/test/java/org/apache/c0000644000175000017500000000406215142145735032016 0ustar zigozigo/* * 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 * * https://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.jakarta.servlet5; import java.io.InputStream; import org.apache.commons.fileupload2.core.AbstractStreamingTest; import org.apache.commons.fileupload2.core.DiskFileItem; import org.apache.commons.fileupload2.core.DiskFileItemFactory; import jakarta.servlet.http.HttpServletRequest; /** * Unit test for items with varying sizes. */ class JakartaStreamingDiskTest extends AbstractStreamingTest { @Override protected DiskFileItemFactory newDiskFileItemFactory() { return DiskFileItemFactory.builder().get(); } @Override protected JakartaServletDiskFileUpload newFileUpload() { return new JakartaServletDiskFileUpload(); } @Override protected HttpServletRequest newMockHttpServletRequest(final InputStream request, final long requestLength, final String contentType, final int readLimit) { return new JakartaMockHttpServletRequest(request, requestLength, contentType, readLimit); } @Override protected JakartaServletRequestContext newServletRequestContext(final HttpServletRequest request) { return new JakartaServletRequestContext(request); } } ././@LongLink0000644000000000000000000000024200000000000011601 Lustar rootrootlibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-jakarta-servlet5/src/test/java/org/apache/commons/fileupload2/jakarta/servlet5/JakartaStreamingTest.javalibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-jakarta-servlet5/src/test/java/org/apache/c0000644000175000017500000000415215142145735032016 0ustar zigozigo/* * 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 * * https://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.jakarta.servlet5; import java.io.InputStream; import org.apache.commons.fileupload2.core.AbstractStreamingTest; import org.apache.commons.fileupload2.core.DiskFileItem; import org.apache.commons.fileupload2.core.DiskFileItemFactory; import jakarta.servlet.http.HttpServletRequest; /** * Unit test for items with varying sizes. */ class JakartaStreamingTest extends AbstractStreamingTest, HttpServletRequest, JakartaServletRequestContext, DiskFileItem, DiskFileItemFactory> { @Override protected DiskFileItemFactory newDiskFileItemFactory() { return DiskFileItemFactory.builder().get(); } @Override protected JakartaServletFileUpload newFileUpload() { return new JakartaServletFileUpload<>(); } @Override protected HttpServletRequest newMockHttpServletRequest(final InputStream request, final long requestLength, final String contentType, final int readLimit) { return new JakartaMockHttpServletRequest(request, requestLength, contentType, readLimit); } @Override protected JakartaServletRequestContext newServletRequestContext(final HttpServletRequest request) { return new JakartaServletRequestContext(request); } } libcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-jakarta-servlet5/src/main/0000755000175000017500000000000015142145735026663 5ustar zigozigolibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-jakarta-servlet5/src/main/java/0000755000175000017500000000000015142145735027604 5ustar zigozigolibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-jakarta-servlet5/src/main/java/org/0000755000175000017500000000000015142145735030373 5ustar zigozigolibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-jakarta-servlet5/src/main/java/org/apache/0000755000175000017500000000000015142145735031614 5ustar zigozigo././@LongLink0000644000000000000000000000015400000000000011603 Lustar rootrootlibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-jakarta-servlet5/src/main/java/org/apache/commons/libcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-jakarta-servlet5/src/main/java/org/apache/c0000755000175000017500000000000015142145735031757 5ustar zigozigo././@LongLink0000644000000000000000000000017000000000000011601 Lustar rootrootlibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-jakarta-servlet5/src/main/java/org/apache/commons/fileupload2/libcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-jakarta-servlet5/src/main/java/org/apache/c0000755000175000017500000000000015142145735031757 5ustar zigozigo././@LongLink0000644000000000000000000000020000000000000011573 Lustar rootrootlibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-jakarta-servlet5/src/main/java/org/apache/commons/fileupload2/jakarta/libcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-jakarta-servlet5/src/main/java/org/apache/c0000755000175000017500000000000015142145735031757 5ustar zigozigo././@LongLink0000644000000000000000000000021100000000000011575 Lustar rootrootlibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-jakarta-servlet5/src/main/java/org/apache/commons/fileupload2/jakarta/servlet5/libcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-jakarta-servlet5/src/main/java/org/apache/c0000755000175000017500000000000015227714536031764 5ustar zigozigo././@LongLink0000644000000000000000000000023200000000000011600 Lustar rootrootlibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-jakarta-servlet5/src/main/java/org/apache/commons/fileupload2/jakarta/servlet5/package-info.javalibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-jakarta-servlet5/src/main/java/org/apache/c0000644000175000017500000000314615142145735031765 0ustar zigozigo/* * 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 * * https://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. */ /** *

* An implementation of {@link org.apache.commons.fileupload2.core.AbstractFileUpload} for use in servlets conforming to the namespace {@code jakarta.servlet}. * *

*

* The following code fragment demonstrates typical usage. *

* *
{@code
 * DiskFileItemFactory factory = DiskFileItemFactory().builder().get();
 * // Configure the factory here, if desired.
 * JakartaServletFileUpload upload = new JakartaServletFileUpload(factory);
 * // Configure the uploader here, if desired.
 * List fileItems = upload.parseRequest(request);
 * }
*

* Please see the FileUpload User Guide for further details and examples of how to * use this package. *

*/ package org.apache.commons.fileupload2.jakarta.servlet5; ././@LongLink0000644000000000000000000000024000000000000011577 Lustar rootrootlibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-jakarta-servlet5/src/main/java/org/apache/commons/fileupload2/jakarta/servlet5/JakartaFileCleaner.javalibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-jakarta-servlet5/src/main/java/org/apache/c0000644000175000017500000000637715142145735031776 0ustar zigozigo/* * 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 * * https://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.jakarta.servlet5; import org.apache.commons.io.FileCleaningTracker; import jakarta.servlet.ServletContext; import jakarta.servlet.ServletContextEvent; import jakarta.servlet.ServletContextListener; /** * A servlet context listener, which ensures that the {@link FileCleaningTracker}'s reaper thread is terminated, when the web application is destroyed. */ public class JakartaFileCleaner implements ServletContextListener { /** * Attribute name, which is used for storing an instance of {@link FileCleaningTracker} in the web application. */ public static final String FILE_CLEANING_TRACKER_ATTRIBUTE = JakartaFileCleaner.class.getName() + ".FileCleaningTracker"; /** * Gets the instance of {@link FileCleaningTracker}, which is associated with the given {@link ServletContext}. * * @param servletContext The servlet context to query * @return The contexts tracker */ public static FileCleaningTracker getFileCleaningTracker(final ServletContext servletContext) { return (FileCleaningTracker) servletContext.getAttribute(FILE_CLEANING_TRACKER_ATTRIBUTE); } /** * Sets the instance of {@link FileCleaningTracker}, which is associated with the given {@link ServletContext}. * * @param servletContext The servlet context to modify * @param tracker The tracker to set */ public static void setFileCleaningTracker(final ServletContext servletContext, final FileCleaningTracker tracker) { servletContext.setAttribute(FILE_CLEANING_TRACKER_ATTRIBUTE, tracker); } /** * Constructs a new instance. */ public JakartaFileCleaner() { // empty } /** * Called when the web application is being destroyed. Calls {@link FileCleaningTracker#exitWhenFinished()}. * * @param sce The servlet context, used for calling {@link #getFileCleaningTracker(ServletContext)}. */ @Override public void contextDestroyed(final ServletContextEvent sce) { getFileCleaningTracker(sce.getServletContext()).exitWhenFinished(); } /** * Called when the web application is initialized. Does nothing. * * @param sce The servlet context, used for calling {@link #setFileCleaningTracker(ServletContext, FileCleaningTracker)}. */ @Override public void contextInitialized(final ServletContextEvent sce) { setFileCleaningTracker(sce.getServletContext(), new FileCleaningTracker()); } } ././@LongLink0000644000000000000000000000025200000000000011602 Lustar rootrootlibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-jakarta-servlet5/src/main/java/org/apache/commons/fileupload2/jakarta/servlet5/JakartaServletDiskFileUpload.javalibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-jakarta-servlet5/src/main/java/org/apache/c0000644000175000017500000000310415142145735031757 0ustar zigozigo/* * 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 * * https://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.jakarta.servlet5; import org.apache.commons.fileupload2.core.DiskFileItem; import org.apache.commons.fileupload2.core.DiskFileItemFactory; /** * A JakartaServletFileUpload for {@link DiskFileItem} and {@link DiskFileItemFactory}. */ public class JakartaServletDiskFileUpload extends JakartaServletFileUpload { /** * Constructs a new instance. */ public JakartaServletDiskFileUpload() { super(DiskFileItemFactory.builder().get()); } /** * Constructs a new instance. * * @param fileItemFactory The factory to use for creating file items. */ public JakartaServletDiskFileUpload(final DiskFileItemFactory fileItemFactory) { super(fileItemFactory); } } ././@LongLink0000644000000000000000000000025200000000000011602 Lustar rootrootlibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-jakarta-servlet5/src/main/java/org/apache/commons/fileupload2/jakarta/servlet5/JakartaServletRequestContext.javalibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-jakarta-servlet5/src/main/java/org/apache/c0000644000175000017500000000435115142145735031764 0ustar zigozigo/* * 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 * * https://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.jakarta.servlet5; import java.io.IOException; import java.io.InputStream; import org.apache.commons.fileupload2.core.AbstractRequestContext; import jakarta.servlet.http.HttpServletRequest; /** * Provides access to the request information needed for a request made to an HTTP servlet. */ public class JakartaServletRequestContext extends AbstractRequestContext { /** * Constructs a context for this request. * * @param request The request to which this context applies. */ public JakartaServletRequestContext(final HttpServletRequest request) { super(request::getHeader, request::getContentLength, request); } /** * Gets the character encoding for the request. * * @return The character encoding for the request. */ @Override public String getCharacterEncoding() { return getRequest().getCharacterEncoding(); } /** * Gets the content type of the request. * * @return The content type of the request. */ @Override public String getContentType() { return getRequest().getContentType(); } /** * Gets the input stream for the request. * * @return The input stream for the request. * @throws IOException if a problem occurs. */ @Override public InputStream getInputStream() throws IOException { return getRequest().getInputStream(); } } ././@LongLink0000644000000000000000000000024600000000000011605 Lustar rootrootlibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-jakarta-servlet5/src/main/java/org/apache/commons/fileupload2/jakarta/servlet5/JakartaServletFileUpload.javalibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-jakarta-servlet5/src/main/java/org/apache/c0000644000175000017500000001225115142145735031762 0ustar zigozigo/* * 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 * * https://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.jakarta.servlet5; import java.io.IOException; import java.util.List; import java.util.Map; import org.apache.commons.fileupload2.core.AbstractFileUpload; import org.apache.commons.fileupload2.core.FileItem; import org.apache.commons.fileupload2.core.FileItemFactory; import org.apache.commons.fileupload2.core.FileItemInputIterator; import org.apache.commons.fileupload2.core.FileUploadException; import jakarta.servlet.http.HttpServletRequest; /** * High level API for processing file uploads. *

* This class handles multiple files per single HTML widget, sent using {@code multipart/mixed} encoding type, as specified by * RFC 1867. Use {@link #parseRequest(HttpServletRequest)} to acquire a list of {@link FileItem}s associated * with a given HTML widget. *

*

* 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. *

* * @param The FileItem type. * @param the FileItemFactory type. */ public class JakartaServletFileUpload, F extends FileItemFactory> extends AbstractFileUpload { /** * Tests 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) { return isMultipartRequestMethod(request.getMethod()) && isMultipartContent(new JakartaServletRequestContext(request)); } /** * Constructs an uninitialized instance of this class. A factory must be configured, using {@code setFileItemFactory()}, before attempting to parse * requests. * * @see AbstractFileUpload#AbstractFileUpload() */ public JakartaServletFileUpload() { } /** * Constructs an instance of this class which uses the supplied factory to create {@code FileItem} instances. * * @param fileItemFactory The factory to use for creating file items. * @see AbstractFileUpload#AbstractFileUpload() */ public JakartaServletFileUpload(final F fileItemFactory) { setFileItemFactory(fileItemFactory); } /** * Gets an RFC 1867 compliant {@code multipart/form-data} file item iterator. * * @param request The servlet request to be parsed. * @return An iterator to instances of {@code FileItemInput} 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. */ @Override public FileItemInputIterator getItemIterator(final HttpServletRequest request) throws FileUploadException, IOException { return super.getItemIterator(new JakartaServletRequestContext(request)); } /** * Parses an RFC 1867 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. */ @Override public Map> parseParameterMap(final HttpServletRequest request) throws FileUploadException { return parseParameterMap(new JakartaServletRequestContext(request)); } /** * Parses an RFC 1867 compliant {@code multipart/form-data} stream. * * @param request 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. */ @Override public List parseRequest(final HttpServletRequest request) throws FileUploadException { return parseRequest(new JakartaServletRequestContext(request)); } } libcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-javax/0000755000175000017500000000000015227714536023102 5ustar zigozigolibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-javax/pom.xml0000644000175000017500000001277215142145735024423 0ustar zigozigo 4.0.0 org.apache.commons commons-fileupload2 2.0.0-M5 ../ commons-fileupload2-javax Apache Commons FileUpload Javax The Apache Commons FileUpload Javax component provides a simple yet flexible means of adding support for multipart file upload functionality to Javax servlets and web applications. ${basedir}/.. org.apache.commons.fileupload2.javax javax.servlet.*;version=${commons.servlet-api.version},* osgi.contract;filter:="(&(osgi.contract=JavaServlet)(version=${commons.servlet-api.version}))" 2026-02-08T17:46:05Z 0.75 0.56 0.55 0.00 0.53 0.50 org.apache.commons commons-fileupload2-core 2.0.0-M5 org.apache.commons commons-fileupload2-core 2.0.0-M5 tests test javax.servlet servlet-api ${commons.servlet-api.version} provided org.junit.jupiter junit-jupiter test commons-io commons-io org.apache.maven.plugins maven-dependency-plugin dep-unpack-main-resources unpack generate-resources ${project.build.outputDirectory} dep-unpack-test-resources unpack generate-resources ${project.build.testOutputDirectory} org.apache apache-jar-resource-bundle 1.4 META-INF/LICENSE.txt,META-INF/NOTICE.txt org.apache.rat apache-rat-plugin .project .classpath .settings/**/ bin/** libcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-javax/src/0000755000175000017500000000000015142145735023664 5ustar zigozigolibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-javax/src/site/0000755000175000017500000000000015142145735024630 5ustar zigozigolibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-javax/src/site/resources/0000755000175000017500000000000015227714536026647 5ustar zigozigolibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-javax/src/site/resources/profile.jacoco0000644000175000017500000000166215142145735031467 0ustar zigozigo# 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 # # https://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. # ----------------------------------------------------------------------------- # # Empty file used to automatically trigger JaCoCo profile from commons parent pom libcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-javax/src/test/0000755000175000017500000000000015142145735024643 5ustar zigozigolibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-javax/src/test/java/0000755000175000017500000000000015142145735025564 5ustar zigozigolibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-javax/src/test/java/org/0000755000175000017500000000000015142145735026353 5ustar zigozigolibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-javax/src/test/java/org/apache/0000755000175000017500000000000015142145735027574 5ustar zigozigolibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-javax/src/test/java/org/apache/commons/0000755000175000017500000000000015142145735031247 5ustar zigozigo././@LongLink0000644000000000000000000000015500000000000011604 Lustar rootrootlibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-javax/src/test/java/org/apache/commons/fileupload2/libcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-javax/src/test/java/org/apache/commons/file0000755000175000017500000000000015142145735032107 5ustar zigozigo././@LongLink0000644000000000000000000000016300000000000011603 Lustar rootrootlibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-javax/src/test/java/org/apache/commons/fileupload2/javax/libcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-javax/src/test/java/org/apache/commons/file0000755000175000017500000000000015227714536032114 5ustar zigozigo././@LongLink0000644000000000000000000000022600000000000011603 Lustar rootrootlibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-javax/src/test/java/org/apache/commons/fileupload2/javax/JavaxHttpServletRequestFactory.javalibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-javax/src/test/java/org/apache/commons/file0000644000175000017500000000363615142145735032121 0ustar zigozigo/* * 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 * * https://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.javax; import javax.servlet.http.HttpServletRequest; import org.apache.commons.fileupload2.core.AbstractFileUpload; final class JavaxHttpServletRequestFactory { public static HttpServletRequest createHttpServletRequestWithNullContentType() { final var requestData = "foobar".getBytes(); return new JavaxMockHttpServletRequest(requestData, null); } static public HttpServletRequest createInvalidHttpServletRequest() { final var requestData = "foobar".getBytes(); return new JavaxMockHttpServletRequest(requestData, AbstractFileUpload.MULTIPART_FORM_DATA); } public static HttpServletRequest createValidHttpServletRequest(final String[] strFileNames) { // TODO Provide a real implementation. final var sbRequestData = new StringBuilder(); for (final String strFileName : strFileNames) { sbRequestData.append(strFileName); } final var requestData = sbRequestData.toString().getBytes(); return new JavaxMockHttpServletRequest(requestData, AbstractFileUpload.MULTIPART_FORM_DATA); } } ././@LongLink0000644000000000000000000000021200000000000011576 Lustar rootrootlibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-javax/src/test/java/org/apache/commons/fileupload2/javax/JavaxSizesDiskTest.javalibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-javax/src/test/java/org/apache/commons/file0000644000175000017500000000330115142145735032106 0ustar zigozigo/* * 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 * * https://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.javax; import java.io.InputStream; import javax.servlet.http.HttpServletRequest; import org.apache.commons.fileupload2.core.AbstractSizesTest; import org.apache.commons.fileupload2.core.DiskFileItem; import org.apache.commons.fileupload2.core.DiskFileItemFactory; /** * Unit test for items with varying sizes. */ class JavaxSizesDiskTest extends AbstractSizesTest { @Override protected JavaxServletDiskFileUpload newFileUpload() { return new JavaxServletDiskFileUpload(); } @Override protected JavaxMockHttpServletRequest newMockHttpServletRequest(final InputStream request, final long requestLength, final String contentType, final int readLimit) { return new JavaxMockHttpServletRequest(request, requestLength, contentType, readLimit); } } ././@LongLink0000644000000000000000000000021200000000000011576 Lustar rootrootlibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-javax/src/test/java/org/apache/commons/fileupload2/javax/JavaxStreamingTest.javalibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-javax/src/test/java/org/apache/commons/file0000644000175000017500000000411515142145735032112 0ustar zigozigo/* * 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 * * https://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.javax; import java.io.InputStream; import javax.servlet.http.HttpServletRequest; import org.apache.commons.fileupload2.core.AbstractStreamingTest; import org.apache.commons.fileupload2.core.DiskFileItem; import org.apache.commons.fileupload2.core.DiskFileItemFactory; /** * Unit test for items with varying sizes. */ class JavaxStreamingTest extends AbstractStreamingTest, HttpServletRequest, JavaxServletRequestContext, DiskFileItem, DiskFileItemFactory> { @Override protected DiskFileItemFactory newDiskFileItemFactory() { return DiskFileItemFactory.builder().get(); } @Override protected JavaxServletFileUpload newFileUpload() { return new JavaxServletFileUpload<>(); } @Override protected HttpServletRequest newMockHttpServletRequest(final InputStream request, final long requestLength, final String contentType, final int readLimit) { return new JavaxMockHttpServletRequest(request, requestLength, contentType, readLimit); } @Override protected JavaxServletRequestContext newServletRequestContext(final HttpServletRequest request) { return new JavaxServletRequestContext(request); } } ././@LongLink0000644000000000000000000000022600000000000011603 Lustar rootrootlibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-javax/src/test/java/org/apache/commons/fileupload2/javax/JavaxServletFileUploadDiskTest.javalibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-javax/src/test/java/org/apache/commons/file0000644000175000017500000001470515142145735032120 0ustar zigozigo/* * 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 * * https://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.javax; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.nio.charset.StandardCharsets; import java.util.List; import javax.servlet.http.HttpServletRequest; import org.apache.commons.fileupload2.core.AbstractFileUploadTest; import org.apache.commons.fileupload2.core.Constants; import org.apache.commons.fileupload2.core.DiskFileItem; import org.apache.commons.fileupload2.core.DiskFileItemFactory; import org.apache.commons.fileupload2.core.FileUploadException; import org.junit.jupiter.api.Test; /** * Tests {@link JavaxServletFileUpload}. * * @see AbstractFileUploadTest */ class JavaxServletFileUploadDiskTest extends AbstractFileUploadTest { public JavaxServletFileUploadDiskTest() { super(new JavaxServletDiskFileUpload()); } @Override public List parseUpload(final JavaxServletDiskFileUpload upload, final byte[] bytes, final String contentType) throws FileUploadException { final HttpServletRequest request = new JavaxMockHttpServletRequest(bytes, contentType); return upload.parseRequest(new JavaxServletRequestContext(request)); } /** * Runs a test with varying file sizes. */ @Override @Test public void testFileUpload() throws IOException, FileUploadException { final var baos = new ByteArrayOutputStream(); var add = 16; var num = 0; for (var i = 0; i < 16384; i += add) { if (++add == 32) { add = 16; } final var header = "-----1234\r\n" + "Content-Disposition: form-data; name=\"field" + num++ + "\"\r\n" + "\r\n"; baos.write(header.getBytes(StandardCharsets.US_ASCII)); for (var j = 0; j < i; j++) { baos.write((byte) j); } baos.write("\r\n".getBytes(StandardCharsets.US_ASCII)); } baos.write("-----1234--\r\n".getBytes(StandardCharsets.US_ASCII)); final var fileItems = parseUpload(new JavaxServletDiskFileUpload(), baos.toByteArray()); final var fileIter = fileItems.iterator(); add = 16; num = 0; for (var i = 0; i < 16384; i += add) { if (++add == 32) { add = 16; } final var item = fileIter.next(); assertEquals("field" + num++, item.getFieldName()); final var bytes = item.get(); assertEquals(i, bytes.length); for (var j = 0; j < i; j++) { assertEquals((byte) j, bytes[j]); } } assertTrue(!fileIter.hasNext()); } @Test void testParseImpliedUtf8() throws Exception { // utf8 encoded form-data without explicit content-type encoding // @formatter:off final var text = "-----1234\r\n" + "Content-Disposition: form-data; name=\"utf8Html\"\r\n" + "\r\n" + "Thís ís the coñteñt of the fíle\n" + "\r\n" + "-----1234--\r\n"; // @formatter:on final var bytes = text.getBytes(StandardCharsets.UTF_8); final HttpServletRequest request = new JavaxMockHttpServletRequest(bytes, Constants.CONTENT_TYPE); // @formatter:off final var fileItemFactory = DiskFileItemFactory.builder() .setCharset(StandardCharsets.UTF_8) .get(); // @formatter:on final var upload = new JavaxServletFileUpload<>(fileItemFactory); final var fileItems = upload.parseRequest(request); final var fileItem = fileItems.get(0); assertTrue(fileItem.getString().contains("coñteñt"), fileItem.getString()); } /* * Test case for */ @Test void testParseParameterMap() throws Exception { // @formatter:off final var text = "-----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" + "Content-Disposition: form-data; name=\"field\"\r\n" + "\r\n" + "fieldValue\r\n" + "-----1234\r\n" + "Content-Disposition: form-data; name=\"multi\"\r\n" + "\r\n" + "value1\r\n" + "-----1234\r\n" + "Content-Disposition: form-data; name=\"multi\"\r\n" + "\r\n" + "value2\r\n" + "-----1234--\r\n"; // @formatter:on final var bytes = text.getBytes(StandardCharsets.US_ASCII); final HttpServletRequest request = new JavaxMockHttpServletRequest(bytes, Constants.CONTENT_TYPE); final var upload = new JavaxServletFileUpload<>(DiskFileItemFactory.builder().get()); final var mappedParameters = upload.parseParameterMap(request); assertTrue(mappedParameters.containsKey("file")); assertEquals(1, mappedParameters.get("file").size()); assertTrue(mappedParameters.containsKey("field")); assertEquals(1, mappedParameters.get("field").size()); assertTrue(mappedParameters.containsKey("multi")); assertEquals(2, mappedParameters.get("multi").size()); } } ././@LongLink0000644000000000000000000000022500000000000011602 Lustar rootrootlibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-javax/src/test/java/org/apache/commons/fileupload2/javax/JavaxProgressListenerDiskTest.javalibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-javax/src/test/java/org/apache/commons/file0000644000175000017500000000341615142145735032115 0ustar zigozigo/* * 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 * * https://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.javax; import java.io.InputStream; import javax.servlet.http.HttpServletRequest; import org.apache.commons.fileupload2.core.AbstractProgressListenerTest; import org.apache.commons.fileupload2.core.DiskFileItem; import org.apache.commons.fileupload2.core.DiskFileItemFactory; import org.apache.commons.fileupload2.core.ProgressListener; /** * Tests the {@link ProgressListener}. */ class JavaxProgressListenerDiskTest extends AbstractProgressListenerTest { @Override protected JavaxServletDiskFileUpload newFileUpload() { return new JavaxServletDiskFileUpload(); } @Override protected HttpServletRequest newMockHttpServletRequest(final InputStream request, final long requestLength, final String contentType, final int readLimit) { return new JavaxMockHttpServletRequest(request, requestLength, contentType, readLimit); } } ././@LongLink0000644000000000000000000000022300000000000011600 Lustar rootrootlibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-javax/src/test/java/org/apache/commons/fileupload2/javax/JavaxMockHttpServletRequest.javalibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-javax/src/test/java/org/apache/commons/file0000644000175000017500000002747015142145735032123 0ustar zigozigo/* * 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 * * https://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.javax; import java.io.BufferedReader; import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; import java.io.UnsupportedEncodingException; import java.security.Principal; import java.util.Enumeration; import java.util.HashMap; import java.util.Locale; import java.util.Map; import javax.servlet.RequestDispatcher; import javax.servlet.ServletInputStream; import javax.servlet.ServletRequest; import javax.servlet.http.Cookie; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpSession; import org.apache.commons.fileupload2.core.AbstractFileUpload; /** * Test fixture for {@link HttpServletRequest}. */ public class JavaxMockHttpServletRequest implements HttpServletRequest { private static final class MyServletInputStream extends ServletInputStream { private final InputStream inputStream; private final int readLimit; /** * Creates a new instance, which returns the given streams data. */ public MyServletInputStream(final InputStream inputStream, final int readLimit) { this.inputStream = inputStream; this.readLimit = readLimit; } @Override public int read() throws IOException { return inputStream.read(); } @Override public int read(final byte[] b, final int off, final int len) throws IOException { if (readLimit > 0) { return inputStream.read(b, off, Math.min(readLimit, len)); } return inputStream.read(b, off, len); } } private final InputStream requestInputStream; private final long requestLength; private final String contentType; private final int readLimit; private final Map headers = new HashMap<>(); /** * Creates a new instance with the given request data and content type. */ public JavaxMockHttpServletRequest(final byte[] requestData, final String contentType) { this(new ByteArrayInputStream(requestData), requestData.length, contentType, -1); } /** * Creates a new instance with the given request data and content type. */ public JavaxMockHttpServletRequest(final InputStream requestInputStream, final long requestLength, final String contentType, final int readLimit) { this.requestInputStream = requestInputStream; this.requestLength = requestLength; this.contentType = contentType; this.headers.put(AbstractFileUpload.CONTENT_TYPE, contentType); this.readLimit = readLimit; } /** * @see ServletRequest#getAttribute(String) */ @Override public Object getAttribute(final String arg0) { return null; } /** * @see ServletRequest#getAttributeNames() */ @Override public Enumeration getAttributeNames() { return null; } /** * @see HttpServletRequest#getAuthType() */ @Override public String getAuthType() { return null; } /** * @see ServletRequest#getCharacterEncoding() */ @Override public String getCharacterEncoding() { return null; } /** * @see ServletRequest#getContentLength() */ @Override public int getContentLength() { return requestInputStream != null ? Math.toIntExact(requestLength) : -1; } /** * @see ServletRequest#getContentType() */ @Override public String getContentType() { return contentType; } /** * @see HttpServletRequest#getContextPath() */ @Override public String getContextPath() { return null; } /** * @see HttpServletRequest#getCookies() */ @Override public Cookie[] getCookies() { return null; } /** * @see HttpServletRequest#getDateHeader(String) */ @Override public long getDateHeader(final String arg0) { return 0; } /** * @see HttpServletRequest#getHeader(String) */ @Override public String getHeader(final String headerName) { return headers.get(headerName); } /** * @see HttpServletRequest#getHeaderNames() */ @Override public Enumeration getHeaderNames() { // todo - implement return null; } /** * @see HttpServletRequest#getHeaders(String) */ @Override public Enumeration getHeaders(final String arg0) { // todo - implement return null; } /** * @see ServletRequest#getInputStream() */ @Override public ServletInputStream getInputStream() throws IOException { return new MyServletInputStream(requestInputStream, readLimit); } /** * @see HttpServletRequest#getIntHeader(String) */ @Override public int getIntHeader(final String arg0) { return 0; } /** * @see ServletRequest#getLocalAddr() */ @Override @SuppressWarnings("javadoc") // This is a Servlet 2.4 method public String getLocalAddr() { return null; } /** * @see ServletRequest#getLocale() */ @Override public Locale getLocale() { return null; } /** * @see ServletRequest#getLocales() */ @Override public Enumeration getLocales() { return null; } /** * @see ServletRequest#getLocalName() */ @Override @SuppressWarnings("javadoc") // This is a Servlet 2.4 method public String getLocalName() { return null; } /** * @see ServletRequest#getLocalPort() */ @Override @SuppressWarnings("javadoc") // This is a Servlet 2.4 method public int getLocalPort() { return 0; } /** * @see HttpServletRequest#getMethod() */ @Override public String getMethod() { return null; } /** * @see ServletRequest#getParameter(String) */ @Override public String getParameter(final String arg0) { return null; } /** * @see ServletRequest#getParameterMap() */ @Override public Map getParameterMap() { return null; } /** * @see ServletRequest#getParameterNames() */ @Override public Enumeration getParameterNames() { return null; } /** * @see ServletRequest#getParameterValues(String) */ @Override public String[] getParameterValues(final String arg0) { return null; } /** * @see HttpServletRequest#getPathInfo() */ @Override public String getPathInfo() { return null; } /** * @see HttpServletRequest#getPathTranslated() */ @Override public String getPathTranslated() { return null; } /** * @see ServletRequest#getProtocol() */ @Override public String getProtocol() { return null; } /** * @see HttpServletRequest#getQueryString() */ @Override public String getQueryString() { return null; } /** * @see ServletRequest#getReader() */ @Override public BufferedReader getReader() throws IOException { return null; } /** * @see ServletRequest#getRealPath(String) * @deprecated */ @Override @Deprecated public String getRealPath(final String arg0) { return null; } /** * @see ServletRequest#getRemoteAddr() */ @Override public String getRemoteAddr() { return null; } /** * @see ServletRequest#getRemoteHost() */ @Override public String getRemoteHost() { return null; } /** * @see ServletRequest#getRemotePort() */ @Override @SuppressWarnings("javadoc") // This is a Servlet 2.4 method public int getRemotePort() { return 0; } /** * @see HttpServletRequest#getRemoteUser() */ @Override public String getRemoteUser() { return null; } /** * @see ServletRequest#getRequestDispatcher(String) */ @Override public RequestDispatcher getRequestDispatcher(final String arg0) { return null; } /** * @see HttpServletRequest#getRequestedSessionId() */ @Override public String getRequestedSessionId() { return null; } /** * @see HttpServletRequest#getRequestURI() */ @Override public String getRequestURI() { return null; } /** * @see HttpServletRequest#getRequestURL() */ @Override public StringBuffer getRequestURL() { return null; } /** * @see ServletRequest#getScheme() */ @Override public String getScheme() { return null; } /** * @see ServletRequest#getServerName() */ @Override public String getServerName() { return null; } /** * @see ServletRequest#getServerPort() */ @Override public int getServerPort() { return 0; } /** * @see HttpServletRequest#getServletPath() */ @Override public String getServletPath() { return null; } /** * @see HttpServletRequest#getSession() */ @Override public HttpSession getSession() { return null; } /** * @see HttpServletRequest#getSession(boolean) */ @Override public HttpSession getSession(final boolean arg0) { return null; } /** * @see HttpServletRequest#getUserPrincipal() */ @Override public Principal getUserPrincipal() { return null; } /** * @see HttpServletRequest#isRequestedSessionIdFromCookie() */ @Override public boolean isRequestedSessionIdFromCookie() { return false; } /** * @see HttpServletRequest#isRequestedSessionIdFromUrl() * @deprecated */ @Override @Deprecated public boolean isRequestedSessionIdFromUrl() { return false; } /** * @see HttpServletRequest#isRequestedSessionIdFromURL() */ @Override public boolean isRequestedSessionIdFromURL() { return false; } /** * @see HttpServletRequest#isRequestedSessionIdValid() */ @Override public boolean isRequestedSessionIdValid() { return false; } /** * @see HttpServletRequest#isSecure() */ @Override public boolean isSecure() { return false; } /** * @see HttpServletRequest#isUserInRole(String) */ @Override public boolean isUserInRole(final String arg0) { return false; } /** * @see ServletRequest#removeAttribute(String) */ @Override public void removeAttribute(final String arg0) { } /** * @see ServletRequest#setAttribute(String, Object) */ @Override public void setAttribute(final String arg0, final Object arg1) { } /** * @see ServletRequest#setCharacterEncoding(String) */ @Override public void setCharacterEncoding(final String arg0) throws UnsupportedEncodingException { } } ././@LongLink0000644000000000000000000000021600000000000011602 Lustar rootrootlibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-javax/src/test/java/org/apache/commons/fileupload2/javax/JavaxStreamingDiskTest.javalibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-javax/src/test/java/org/apache/commons/file0000644000175000017500000000402515142145735032112 0ustar zigozigo/* * 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 * * https://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.javax; import java.io.InputStream; import javax.servlet.http.HttpServletRequest; import org.apache.commons.fileupload2.core.AbstractStreamingTest; import org.apache.commons.fileupload2.core.DiskFileItem; import org.apache.commons.fileupload2.core.DiskFileItemFactory; /** * Unit test for items with varying sizes. */ class JavaxStreamingDiskTest extends AbstractStreamingTest { @Override protected DiskFileItemFactory newDiskFileItemFactory() { return DiskFileItemFactory.builder().get(); } @Override protected JavaxServletDiskFileUpload newFileUpload() { return new JavaxServletDiskFileUpload(); } @Override protected HttpServletRequest newMockHttpServletRequest(final InputStream request, final long requestLength, final String contentType, final int readLimit) { return new JavaxMockHttpServletRequest(request, requestLength, contentType, readLimit); } @Override protected JavaxServletRequestContext newServletRequestContext(final HttpServletRequest request) { return new JavaxServletRequestContext(request); } } ././@LongLink0000644000000000000000000000022200000000000011577 Lustar rootrootlibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-javax/src/test/java/org/apache/commons/fileupload2/javax/JavaxServletFileUploadTest.javalibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-javax/src/test/java/org/apache/commons/file0000644000175000017500000001512115142145735032111 0ustar zigozigo/* * 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 * * https://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.javax; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.nio.charset.StandardCharsets; import java.util.List; import javax.servlet.http.HttpServletRequest; import org.apache.commons.fileupload2.core.AbstractFileUploadTest; import org.apache.commons.fileupload2.core.Constants; import org.apache.commons.fileupload2.core.DiskFileItem; import org.apache.commons.fileupload2.core.DiskFileItemFactory; import org.apache.commons.fileupload2.core.FileUploadException; import org.junit.jupiter.api.Test; /** * Tests {@link JavaxServletFileUpload}. * * @see AbstractFileUploadTest */ class JavaxServletFileUploadTest extends AbstractFileUploadTest, HttpServletRequest, DiskFileItem, DiskFileItemFactory> { public JavaxServletFileUploadTest() { super(new JavaxServletFileUpload<>(DiskFileItemFactory.builder().get())); } @Override public List parseUpload(final JavaxServletFileUpload upload, final byte[] bytes, final String contentType) throws FileUploadException { final HttpServletRequest request = new JavaxMockHttpServletRequest(bytes, contentType); return upload.parseRequest(new JavaxServletRequestContext(request)); } /** * Runs a test with varying file sizes. */ @Override @Test public void testFileUpload() throws IOException, FileUploadException { final var baos = new ByteArrayOutputStream(); var add = 16; var num = 0; for (var i = 0; i < 16384; i += add) { if (++add == 32) { add = 16; } final var header = "-----1234\r\n" + "Content-Disposition: form-data; name=\"field" + num++ + "\"\r\n" + "\r\n"; baos.write(header.getBytes(StandardCharsets.US_ASCII)); for (var j = 0; j < i; j++) { baos.write((byte) j); } baos.write("\r\n".getBytes(StandardCharsets.US_ASCII)); } baos.write("-----1234--\r\n".getBytes(StandardCharsets.US_ASCII)); final var fileItems = parseUpload(new JavaxServletFileUpload<>(DiskFileItemFactory.builder().get()), baos.toByteArray()); final var fileIter = fileItems.iterator(); add = 16; num = 0; for (var i = 0; i < 16384; i += add) { if (++add == 32) { add = 16; } final var item = fileIter.next(); assertEquals("field" + num++, item.getFieldName()); final var bytes = item.get(); assertEquals(i, bytes.length); for (var j = 0; j < i; j++) { assertEquals((byte) j, bytes[j]); } } assertTrue(!fileIter.hasNext()); } @Test void testParseImpliedUtf8() throws Exception { // utf8 encoded form-data without explicit content-type encoding // @formatter:off final var text = "-----1234\r\n" + "Content-Disposition: form-data; name=\"utf8Html\"\r\n" + "\r\n" + "Thís ís the coñteñt of the fíle\n" + "\r\n" + "-----1234--\r\n"; // @formatter:on final var bytes = text.getBytes(StandardCharsets.UTF_8); final HttpServletRequest request = new JavaxMockHttpServletRequest(bytes, Constants.CONTENT_TYPE); // @formatter:off final var fileItemFactory = DiskFileItemFactory.builder() .setCharset(StandardCharsets.UTF_8) .get(); // @formatter:on final var upload = new JavaxServletFileUpload<>(fileItemFactory); final var fileItems = upload.parseRequest(request); final var fileItem = fileItems.get(0); assertTrue(fileItem.getString().contains("coñteñt"), fileItem.getString()); } /* * Test case for */ @Test void testParseParameterMap() throws Exception { // @formatter:off final var text = "-----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" + "Content-Disposition: form-data; name=\"field\"\r\n" + "\r\n" + "fieldValue\r\n" + "-----1234\r\n" + "Content-Disposition: form-data; name=\"multi\"\r\n" + "\r\n" + "value1\r\n" + "-----1234\r\n" + "Content-Disposition: form-data; name=\"multi\"\r\n" + "\r\n" + "value2\r\n" + "-----1234--\r\n"; // @formatter:on final var bytes = text.getBytes(StandardCharsets.US_ASCII); final HttpServletRequest request = new JavaxMockHttpServletRequest(bytes, Constants.CONTENT_TYPE); final var upload = new JavaxServletFileUpload<>(DiskFileItemFactory.builder().get()); final var mappedParameters = upload.parseParameterMap(request); assertTrue(mappedParameters.containsKey("file")); assertEquals(1, mappedParameters.get("file").size()); assertTrue(mappedParameters.containsKey("field")); assertEquals(1, mappedParameters.get("field").size()); assertTrue(mappedParameters.containsKey("multi")); assertEquals(2, mappedParameters.get("multi").size()); } } ././@LongLink0000644000000000000000000000022100000000000011576 Lustar rootrootlibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-javax/src/test/java/org/apache/commons/fileupload2/javax/JavaxProgressListenerTest.javalibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-javax/src/test/java/org/apache/commons/file0000644000175000017500000000350615142145735032115 0ustar zigozigo/* * 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 * * https://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.javax; import java.io.InputStream; import javax.servlet.http.HttpServletRequest; import org.apache.commons.fileupload2.core.AbstractProgressListenerTest; import org.apache.commons.fileupload2.core.DiskFileItem; import org.apache.commons.fileupload2.core.DiskFileItemFactory; import org.apache.commons.fileupload2.core.ProgressListener; /** * Tests the {@link ProgressListener}. */ class JavaxProgressListenerTest extends AbstractProgressListenerTest, HttpServletRequest, DiskFileItem, DiskFileItemFactory> { @Override protected JavaxServletFileUpload newFileUpload() { return new JavaxServletFileUpload<>(); } @Override protected HttpServletRequest newMockHttpServletRequest(final InputStream request, final long requestLength, final String contentType, final int readLimit) { return new JavaxMockHttpServletRequest(request, requestLength, contentType, readLimit); } } ././@LongLink0000644000000000000000000000020600000000000011601 Lustar rootrootlibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-javax/src/test/java/org/apache/commons/fileupload2/javax/JavaxSizesTest.javalibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-javax/src/test/java/org/apache/commons/file0000644000175000017500000000344415142145735032116 0ustar zigozigo/* * 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 * * https://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.javax; import java.io.InputStream; import javax.servlet.http.HttpServletRequest; import org.apache.commons.fileupload2.core.AbstractSizesTest; import org.apache.commons.fileupload2.core.DiskFileItem; import org.apache.commons.fileupload2.core.DiskFileItemFactory; /** * Unit test for items with varying sizes. */ class JavaxSizesTest extends AbstractSizesTest, HttpServletRequest, DiskFileItem, DiskFileItemFactory> { @Override protected JavaxServletFileUpload newFileUpload() { return new JavaxServletFileUpload<>(DiskFileItemFactory.builder().get()); } @Override protected JavaxMockHttpServletRequest newMockHttpServletRequest(final InputStream request, final long requestLength, final String contentType, final int readLimit) { return new JavaxMockHttpServletRequest(request, requestLength, contentType, readLimit); } } libcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-javax/src/main/0000755000175000017500000000000015142145735024610 5ustar zigozigolibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-javax/src/main/java/0000755000175000017500000000000015142145735025531 5ustar zigozigolibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-javax/src/main/java/org/0000755000175000017500000000000015142145735026320 5ustar zigozigolibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-javax/src/main/java/org/apache/0000755000175000017500000000000015142145735027541 5ustar zigozigolibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-javax/src/main/java/org/apache/commons/0000755000175000017500000000000015142145735031214 5ustar zigozigo././@LongLink0000644000000000000000000000015500000000000011604 Lustar rootrootlibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-javax/src/main/java/org/apache/commons/fileupload2/libcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-javax/src/main/java/org/apache/commons/file0000755000175000017500000000000015142145735032054 5ustar zigozigo././@LongLink0000644000000000000000000000016300000000000011603 Lustar rootrootlibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-javax/src/main/java/org/apache/commons/fileupload2/javax/libcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-javax/src/main/java/org/apache/commons/file0000755000175000017500000000000015227714536032061 5ustar zigozigo././@LongLink0000644000000000000000000000022200000000000011577 Lustar rootrootlibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-javax/src/main/java/org/apache/commons/fileupload2/javax/JavaxServletRequestContext.javalibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-javax/src/main/java/org/apache/commons/file0000644000175000017500000000433015142145735032056 0ustar zigozigo/* * 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 * * https://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.javax; import java.io.IOException; import java.io.InputStream; import javax.servlet.http.HttpServletRequest; import org.apache.commons.fileupload2.core.AbstractRequestContext; /** * Provides access to the request information needed for a request made to an HTTP servlet. */ public class JavaxServletRequestContext extends AbstractRequestContext { /** * Constructs a context for this request. * * @param request The request to which this context applies. */ public JavaxServletRequestContext(final HttpServletRequest request) { super(request::getHeader, request::getContentLength, request); } /** * Gets the character encoding for the request. * * @return The character encoding for the request. */ @Override public String getCharacterEncoding() { return getRequest().getCharacterEncoding(); } /** * Gets the content type of the request. * * @return The content type of the request. */ @Override public String getContentType() { return getRequest().getContentType(); } /** * Gets the input stream for the request. * * @return The input stream for the request. * @throws IOException if a problem occurs. */ @Override public InputStream getInputStream() throws IOException { return getRequest().getInputStream(); } } ././@LongLink0000644000000000000000000000020400000000000011577 Lustar rootrootlibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-javax/src/main/java/org/apache/commons/fileupload2/javax/package-info.javalibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-javax/src/main/java/org/apache/commons/file0000644000175000017500000000347415142145735032066 0ustar zigozigo/* * 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 * * https://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. */ /** *

* An implementation of {@link org.apache.commons.fileupload2.core.AbstractFileUpload} for use in servlets conforming to JSR 53. This implementation requires * only access to the servlet's current {@code HttpServletRequest} instance, and a suitable {@link org.apache.commons.fileupload2.core.FileItemFactory} * implementation, such as {@link org.apache.commons.fileupload2.core.DiskFileItemFactory}. *

*

* The following code fragment demonstrates typical usage. *

* *
{@code
 * DiskFileItemFactory factory = DiskFileItemFactory().builder().get();
 * // Configure the factory here, if desired.
 * ServletFileUpload upload = new ServletFileUpload(factory);
 * // Configure the uploader here, if desired.
 * List fileItems = upload.parseRequest(request);
 * }
*

* Please see the FileUpload User Guide for further details and examples of how to * use this package. *

*/ package org.apache.commons.fileupload2.javax; ././@LongLink0000644000000000000000000000021600000000000011602 Lustar rootrootlibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-javax/src/main/java/org/apache/commons/fileupload2/javax/JavaxServletFileUpload.javalibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-javax/src/main/java/org/apache/commons/file0000644000175000017500000001224115142145735032056 0ustar zigozigo/* * 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 * * https://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.javax; import java.io.IOException; import java.util.List; import java.util.Map; import javax.servlet.http.HttpServletRequest; import org.apache.commons.fileupload2.core.AbstractFileUpload; import org.apache.commons.fileupload2.core.FileItem; import org.apache.commons.fileupload2.core.FileItemFactory; import org.apache.commons.fileupload2.core.FileItemInputIterator; import org.apache.commons.fileupload2.core.FileUploadException; /** * High level API for processing file uploads. *

* This class handles multiple files per single HTML widget, sent using {@code multipart/mixed} encoding type, as specified by * RFC 1867. Use {@link #parseRequest(HttpServletRequest)} to acquire a list of {@link FileItem}s associated * with a given HTML widget. *

*

* 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. *

* * @param The FileItem type. * @param the FileItemFactory type. */ public class JavaxServletFileUpload, F extends FileItemFactory> extends AbstractFileUpload { /** * Tests 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) { return isMultipartRequestMethod(request.getMethod()) && AbstractFileUpload.isMultipartContent(new JavaxServletRequestContext(request)); } /** * Constructs an uninitialized instance of this class. A factory must be configured, using {@code setFileItemFactory()}, before attempting to parse * requests. * * @see AbstractFileUpload#AbstractFileUpload() */ public JavaxServletFileUpload() { } /** * Constructs an instance of this class which uses the supplied factory to create {@code FileItem} instances. * * @see AbstractFileUpload#AbstractFileUpload() * @param fileItemFactory The factory to use for creating file items. */ public JavaxServletFileUpload(final F fileItemFactory) { setFileItemFactory(fileItemFactory); } /** * Gets an RFC 1867 compliant {@code multipart/form-data} file item iterator. * * @param request The servlet request to be parsed. * @return An iterator to instances of {@code FileItemInput} 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. */ @Override public FileItemInputIterator getItemIterator(final HttpServletRequest request) throws FileUploadException, IOException { return super.getItemIterator(new JavaxServletRequestContext(request)); } /** * Parses an RFC 1867 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. */ @Override public Map> parseParameterMap(final HttpServletRequest request) throws FileUploadException { return parseParameterMap(new JavaxServletRequestContext(request)); } /** * Parses an RFC 1867 compliant {@code multipart/form-data} stream. * * @param request 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. */ @Override public List parseRequest(final HttpServletRequest request) throws FileUploadException { return parseRequest(new JavaxServletRequestContext(request)); } } ././@LongLink0000644000000000000000000000022200000000000011577 Lustar rootrootlibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-javax/src/main/java/org/apache/commons/fileupload2/javax/JavaxServletDiskFileUpload.javalibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-javax/src/main/java/org/apache/commons/file0000644000175000017500000000305715142145735032063 0ustar zigozigo/* * 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 * * https://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.javax; import org.apache.commons.fileupload2.core.DiskFileItem; import org.apache.commons.fileupload2.core.DiskFileItemFactory; /** * A JavaxServletFileUpload for {@link DiskFileItem} and {@link DiskFileItemFactory}. */ public class JavaxServletDiskFileUpload extends JavaxServletFileUpload { /** * Constructs a new instance. */ public JavaxServletDiskFileUpload() { super(DiskFileItemFactory.builder().get()); } /** * Constructs a new instance. * * @param fileItemFactory The factory to use for creating file items. */ public JavaxServletDiskFileUpload(final DiskFileItemFactory fileItemFactory) { super(fileItemFactory); } } ././@LongLink0000644000000000000000000000021000000000000011574 Lustar rootrootlibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-javax/src/main/java/org/apache/commons/fileupload2/javax/JavaxFileCleaner.javalibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-javax/src/main/java/org/apache/commons/file0000644000175000017500000000635115142145735032063 0ustar zigozigo/* * 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 * * https://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.javax; import javax.servlet.ServletContext; import javax.servlet.ServletContextEvent; import javax.servlet.ServletContextListener; import org.apache.commons.io.FileCleaningTracker; /** * A servlet context listener, which ensures that the {@link FileCleaningTracker}'s reaper thread is terminated, when the web application is destroyed. */ public class JavaxFileCleaner implements ServletContextListener { /** * Attribute name, which is used for storing an instance of {@link FileCleaningTracker} in the web application. */ public static final String FILE_CLEANING_TRACKER_ATTRIBUTE = JavaxFileCleaner.class.getName() + ".FileCleaningTracker"; /** * Gets the instance of {@link FileCleaningTracker}, which is associated with the given {@link ServletContext}. * * @param servletContext The servlet context to query * @return The contexts tracker */ public static FileCleaningTracker getFileCleaningTracker(final ServletContext servletContext) { return (FileCleaningTracker) servletContext.getAttribute(FILE_CLEANING_TRACKER_ATTRIBUTE); } /** * Sets the instance of {@link FileCleaningTracker}, which is associated with the given {@link ServletContext}. * * @param servletContext The servlet context to modify * @param tracker The tracker to set */ public static void setFileCleaningTracker(final ServletContext servletContext, final FileCleaningTracker tracker) { servletContext.setAttribute(FILE_CLEANING_TRACKER_ATTRIBUTE, tracker); } /** * Constructs a new instance. */ public JavaxFileCleaner() { // empty } /** * Called when the web application is being destroyed. Calls {@link FileCleaningTracker#exitWhenFinished()}. * * @param sce The servlet context, used for calling {@link #getFileCleaningTracker(ServletContext)}. */ @Override public void contextDestroyed(final ServletContextEvent sce) { getFileCleaningTracker(sce.getServletContext()).exitWhenFinished(); } /** * Called when the web application is initialized. Does nothing. * * @param sce The servlet context, used for calling {@link #setFileCleaningTracker(ServletContext, FileCleaningTracker)}. */ @Override public void contextInitialized(final ServletContextEvent sce) { setFileCleaningTracker(sce.getServletContext(), new FileCleaningTracker()); } } libcommons-fileupload2-java-2.0.0~M5/pom.xml0000644000175000017500000004063515142145735017434 0ustar zigozigo 4.0.0 org.apache.commons commons-parent 96 commons-fileupload2 2.0.0-M5 pom Apache Commons FileUpload The Apache Commons FileUpload component provides a simple yet flexible means of adding support for multipart file upload functionality to servlets and web applications. https://commons.apache.org/proper/commons-fileupload/ 2002 scm:git:https://gitbox.apache.org/repos/asf/commons-fileupload.git scm:git:https://gitbox.apache.org/repos/asf/commons-fileupload.git https://gitbox.apache.org/repos/asf?p=commons-fileupload.git HEAD https://issues.apache.org/jira/browse/FILEUPLOAD apache.website Apache Commons Site scm:svn:https://svn.apache.org/repos/infra/websites/production/commons/content/proper/commons-fileupload/ GitHub https://github.com/apache/commons-fileupload/actions 11 11 11 ${basedir} fileupload org.apache.commons.fileupload2 2.0.0-M5 2.0.0 in the org.apache.commons.fileupload2 namespace for Java 11 or later commons-fileupload-${commons.release.2.version} 1.6.0 in the org.apache.commons.fileupload namespace for Java 8 or later FILEUPLOAD 12310476 fileupload https://svn.apache.org/repos/infra/websites/production/commons/content/proper/commons-fileupload site-content ${basedir}/target/site ${commons.parent.dir}/RELEASE-NOTES.txt !org.apache.commons.fileupload.util.mime,org.apache.commons.*;version=${project.version};-noimport:=true !javax.portlet,* javax.portlet 2.5 2.21.0 3.20.0 true true https://jakarta.ee/specifications/platform/9.1/apidocs/ 2.0.0-M4 RC1 scm:svn:https://dist.apache.org/repos/dist/dev/commons/${commons.componentid} false 2026-02-08T17:46:05Z true 1.00 1.00 1.00 1.00 1.00 1.00 commons-io commons-io ${commons.io.version} org.apache.commons commons-lang3 ${commons.lang3.version} org.apache.rat apache-rat-plugin site-content/** src/checkstyle/license-header.txt com.github.siom79.japicmp japicmp-maven-plugin true org.apache.maven.plugins maven-checkstyle-plugin ${commons.parent.dir}/src/checkstyle/fileupload_checks.xml ${commons.parent.dir}/src/checkstyle/checkstyle-suppressions.xml false com.github.spotbugs spotbugs-maven-plugin ${commons.parent.dir}/spotbugs-exclude-filter.xml org.apache.maven.plugins maven-pmd-plugin ${maven.compiler.target} ${commons.parent.dir}/src/conf/pmd-ruleset.xml clean javadoc:javadoc verify apache-rat:check checkstyle:check pmd:check pmd:cpd-check spotbugs:check true org.apache.maven.plugins maven-javadoc-plugin src/main/java org.apache.maven.plugins maven-checkstyle-plugin ${commons.parent.dir}/src/checkstyle/fileupload_checks.xml ${commons.parent.dir}/src/checkstyle/checkstyle-suppressions.xml false false org.apache.maven.plugins maven-pmd-plugin ${maven.compiler.target} ${commons.parent.dir}/src/conf/pmd-ruleset.xml org.codehaus.mojo taglist-maven-plugin Needs Work TODO exact FIXME exact Noteable Markers NOTE exact NOPMD exact NOSONAR exact release maven-assembly-plugin true commons-fileupload2-core commons-fileupload2-jakarta-servlet5 commons-fileupload2-jakarta-servlet6 commons-fileupload2-javax commons-fileupload2-portlet commons-fileupload2-distribution Martin Cooper martinc martinc@apache.org Yahoo! dIon Gillard dion dion@apache.org Multitask Consulting John McNally jmcnally jmcnally@collab.net CollabNet Daniel Rall dlr dlr@finemaltcoding.com CollabNet Jason van Zyl jvanzyl jason@zenplex.com Zenplex Robert Burrell Donkin rdonkin rdonkin@apache.org Sean C. Sullivan sullis sean |at| seansullivan |dot| com Jochen Wiedmann jochen jochen.wiedmann@gmail.com Simone Tripodi simonetripodi simonetripodi@apache.org Adobe ggregory Gary Gregory ggregory at apache.org https://www.garygregory.com The Apache Software Foundation https://www.apache.org/ PMC Member America/New_York https://people.apache.org/~ggregory/img/garydgregory80.png Rob Tompkins chtompki chtompki@apache.org Aaron Freeman aaron@sendthisfile.com Daniel Fabian dfabian@google.com Jörg Heinicke joerg.heinicke@gmx.de Stepan Koltsov yozh@mx1.ru Michael Macaluso michael.public@wavecorp.com Amichai Rothman amichai2@amichais.net Alexander Sova bird@noir.crocodile.org Paul Spurr pspurr@gmail.com Thomas Vandahl tv@apache.org Henry Yandell bayard@apache.org Jan Novotný novotnaci@gmail.com frank mailsurfie@gmail.com maxxedev maxxedev@gmail.com Rafal Krzewski Rafal.Krzewski@e-point.pl Sean Legassick sean@informage.net Oleg Kalnichevski oleg@ural.ru David Sean Taylor taylor@apache.org fangwentong fangwentong2012@gmail.com David Georg Reichelt Merbin J Anselm merbinjanselm@gmail.com Arturo Bernal arturobernalg@gmail.com Martin Grigorov mgrigorov@apache.org mufasa1976 mufasa1976@coolstuff.software libcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-core/0000755000175000017500000000000015227714536022721 5ustar zigozigolibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-core/pom.xml0000644000175000017500000001133415142145735024233 0ustar zigozigo 4.0.0 org.apache.commons commons-fileupload2 2.0.0-M5 ../ commons-fileupload2-core Apache Commons FileUpload Core The Apache Commons FileUpload Core component provides the framework for a simple yet flexible means of adding support for multipart file upload functionality to servlets, portlets, and web applications. ${basedir}/.. org.apache.commons.fileupload2.core 2026-02-08T17:46:05Z 0.46 0.43 0.40 0.43 0.42 0.37 commons-io commons-io org.junit.jupiter junit-jupiter test org.apache.commons commons-lang3 test org.apache.maven.plugins maven-dependency-plugin dep-unpack-main-resources unpack generate-resources ${project.build.outputDirectory} dep-unpack-test-resources unpack generate-resources ${project.build.testOutputDirectory} org.apache apache-jar-resource-bundle 1.4 META-INF/LICENSE.txt,META-INF/NOTICE.txt org.apache.rat apache-rat-plugin .project .classpath .settings/**/ bin/** libcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-core/src/0000755000175000017500000000000015142145735023503 5ustar zigozigolibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-core/src/site/0000755000175000017500000000000015142145735024447 5ustar zigozigolibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-core/src/site/resources/0000755000175000017500000000000015227714536026466 5ustar zigozigolibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-core/src/site/resources/profile.jacoco0000644000175000017500000000166215142145735031306 0ustar zigozigo# 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 # # https://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. # ----------------------------------------------------------------------------- # # Empty file used to automatically trigger JaCoCo profile from commons parent pom libcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-core/src/test/0000755000175000017500000000000015142145735024462 5ustar zigozigolibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-core/src/test/java/0000755000175000017500000000000015142145735025403 5ustar zigozigolibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-core/src/test/java/org/0000755000175000017500000000000015142145735026172 5ustar zigozigolibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-core/src/test/java/org/apache/0000755000175000017500000000000015142145735027413 5ustar zigozigolibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-core/src/test/java/org/apache/commons/0000755000175000017500000000000015142145735031066 5ustar zigozigo././@LongLink0000644000000000000000000000015400000000000011603 Lustar rootrootlibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-core/src/test/java/org/apache/commons/fileupload2/libcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-core/src/test/java/org/apache/commons/fileu0000755000175000017500000000000015142145735032113 5ustar zigozigo././@LongLink0000644000000000000000000000016100000000000011601 Lustar rootrootlibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-core/src/test/java/org/apache/commons/fileupload2/core/libcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-core/src/test/java/org/apache/commons/fileu0000755000175000017500000000000015227714536032120 5ustar zigozigo././@LongLink0000644000000000000000000000021300000000000011577 Lustar rootrootlibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-core/src/test/java/org/apache/commons/fileupload2/core/AbstractStreamingTest.javalibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-core/src/test/java/org/apache/commons/fileu0000644000175000017500000002441315142145735032121 0ustar zigozigo/* * 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 * * https://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.core; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.fail; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.FilterInputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStreamWriter; import java.nio.charset.StandardCharsets; import java.nio.file.InvalidPathException; import java.util.List; import org.junit.jupiter.api.Test; /** * Unit test for items with varying sizes. * * @param The subclass of FileUpload. * @param The type of FileUpload request. * @param The request context type. * @param The FileItem type. * @param The FileItemFactory type. */ public abstract class AbstractStreamingTest, R, C extends AbstractRequestContext, I extends FileItem, F extends FileItemFactory> extends AbstractTest { protected String getFooter() { return "-----1234--\r\n"; } protected String getHeader(final String value) { // @formatter:off return "-----1234\r\n" + "Content-Disposition: form-data; name=\"" + value + "\"\r\n" + "\r\n"; // @formatter:on } protected abstract F newDiskFileItemFactory(); protected byte[] newRequest() throws IOException { final var baos = new ByteArrayOutputStream(); try (final var osw = new OutputStreamWriter(baos, StandardCharsets.US_ASCII)) { var add = 16; var num = 0; for (var i = 0; i < 16384; i += add) { if (++add == 32) { add = 16; } osw.write(getHeader("field" + num++)); osw.flush(); for (var j = 0; j < i; j++) { baos.write((byte) j); } osw.write("\r\n"); } osw.write(getFooter()); } return baos.toByteArray(); } protected abstract C newServletRequestContext(final R request); protected byte[] newShortRequest() throws IOException { final var baos = new ByteArrayOutputStream(); try (final var osw = new OutputStreamWriter(baos, StandardCharsets.US_ASCII)) { osw.write(getHeader("field")); osw.write("123"); osw.write("\r\n"); osw.write(getFooter()); } return baos.toByteArray(); } protected List parseUpload(final byte[] bytes) throws FileUploadException { return parseUpload(new ByteArrayInputStream(bytes), bytes.length); } protected List parseUpload(final InputStream inputStream, final int length) throws FileUploadException { final var contentType = "multipart/form-data; boundary=---1234"; final var upload = newFileUpload(); upload.setFileItemFactory(newDiskFileItemFactory()); final var request = newMockHttpServletRequest(inputStream, length, contentType, -1); return upload.parseRequest(newServletRequestContext(request)); } protected FileItemInputIterator parseUpload(final int length, final InputStream inputStream) throws FileUploadException, IOException { final var contentType = "multipart/form-data; boundary=---1234"; final var upload = newFileUpload(); upload.setFileItemFactory(newDiskFileItemFactory()); final var request = newMockHttpServletRequest(inputStream, length, contentType, -1); return upload.getItemIterator(newServletRequestContext(request)); } /** * Tests a file upload with varying file sizes. * * @throws IOException Test failure. */ @Test void testFileUpload() throws IOException { final var request = newRequest(); final var fileItems = parseUpload(request); final var fileIter = fileItems.iterator(); var add = 16; var num = 0; for (var i = 0; i < 16384; i += add) { if (++add == 32) { add = 16; } final var item = fileIter.next(); assertEquals("field" + num++, item.getFieldName()); final var bytes = item.get(); assertEquals(i, bytes.length); for (var j = 0; j < i; j++) { assertEquals((byte) j, bytes[j]); } } assertTrue(!fileIter.hasNext()); } /** * Test for FILEUPLOAD-135 * * @throws IOException Test failure. */ @Test void testFILEUPLOAD135() throws IOException { final var request = newShortRequest(); final var bais = new ByteArrayInputStream(request); final var fileItems = parseUpload(new InputStream() { @Override public int read() throws IOException { return bais.read(); } @Override public int read(final byte[] b, final int off, final int len) throws IOException { return bais.read(b, off, Math.min(len, 3)); } }, request.length); final var fileIter = fileItems.iterator(); assertTrue(fileIter.hasNext()); final var item = fileIter.next(); assertEquals("field", item.getFieldName()); final var bytes = item.get(); assertEquals(3, bytes.length); assertEquals((byte) '1', bytes[0]); assertEquals((byte) '2', bytes[1]); assertEquals((byte) '3', bytes[2]); assertTrue(!fileIter.hasNext()); } /** * Tests, whether an invalid request throws a proper exception. * * @throws IOException Test failure. */ @Test void testFileUploadException() throws IOException { final var request = newRequest(); final var invalidRequest = new byte[request.length - 11]; System.arraycopy(request, 0, invalidRequest, 0, request.length - 11); try { parseUpload(invalidRequest); fail("Expected EndOfStreamException"); } catch (final FileUploadException e) { assertTrue(e.getSuppressed()[0] instanceof MultipartInput.MalformedStreamException, e.toString()); } } /** * Tests, whether an {@link InvalidPathException} is thrown. * * @throws IOException Test failure. */ @Test void testInvalidFileNameException() throws IOException { final var fileName = "foo.exe\u0000.png"; // @formatter:off final var request = "-----1234\r\n" + "Content-Disposition: form-data; name=\"file\"; filename=\"" + fileName + "\"\r\n" + "Content-Type: text/whatever\r\n" + "\r\n" + "This is the content of the file\n" + "\r\n" + "-----1234\r\n" + "Content-Disposition: form-data; name=\"field\"\r\n" + "\r\n" + "fieldValue\r\n" + "-----1234\r\n" + "Content-Disposition: form-data; name=\"multi\"\r\n" + "\r\n" + "value1\r\n" + "-----1234\r\n" + "Content-Disposition: form-data; name=\"multi\"\r\n" + "\r\n" + "value2\r\n" + "-----1234--\r\n"; // @formatter:on final var reqBytes = request.getBytes(StandardCharsets.US_ASCII); final var fileItemIter = parseUpload(reqBytes.length, new ByteArrayInputStream(reqBytes)); final var fileItemInput = fileItemIter.next(); try { fileItemInput.getName(); fail("Expected exception"); } catch (final InvalidPathException e) { assertEquals(fileName, e.getInput()); assertEquals(26, e.getMessage().indexOf(fileName)); assertEquals(7, e.getIndex()); assertTrue(e.getMessage().contains("foo.exe\\0.png")); } try { parseUpload(reqBytes); fail("Expected exception"); } catch (final InvalidPathException e) { assertEquals(fileName, e.getInput()); assertEquals(26, e.getMessage().indexOf(fileName)); assertEquals(7, e.getIndex()); assertTrue(e.getMessage().contains("foo.exe\\0.png")); } } /** * Tests, whether an IOException is properly delegated. * * @throws IOException Test failure. */ @Test void testIOException() throws IOException { final var request = newRequest(); final InputStream stream = new FilterInputStream(new ByteArrayInputStream(request)) { private int num; @Override public int read() throws IOException { if (++num > 123) { throw new IOException("123"); } return super.read(); } @Override public int read(final byte[] buffer, final int offset, final int length) throws IOException { for (var i = 0; i < length; i++) { final var res = read(); if (res == -1) { return i == 0 ? -1 : i; } buffer[offset + i] = (byte) res; } return length; } }; try { parseUpload(stream, request.length); fail("Expected IOException"); } catch (final FileUploadException e) { assertTrue(e.getCause() instanceof IOException); assertEquals("123", e.getCause().getMessage()); } } } ././@LongLink0000644000000000000000000000022000000000000011575 Lustar rootrootlibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-core/src/test/java/org/apache/commons/fileupload2/core/DeferrableOutputStreamTest.javalibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-core/src/test/java/org/apache/commons/fileu0000644000175000017500000001705015142145735032120 0ustar zigozigo/* * 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 * * https://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.core; import static org.junit.jupiter.api.Assertions.assertArrayEquals; 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.assertSame; import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.UncheckedIOException; import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.util.function.Consumer; import java.util.function.Supplier; import org.apache.commons.fileupload2.core.DeferrableOutputStream.State; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; /** * Test suite for the {@link DeferrableOutputStream}. */ class DeferrableOutputStreamTest { private static final Path testDir = Paths.get("target/unit-tests/DeferrableOutputStreamTest"); private static Path tempTestDir; @BeforeAll static void setUpTestDirs() throws IOException { Files.createDirectories(testDir); tempTestDir = Files.createTempDirectory(testDir, "testDir"); } private Supplier testFileSupplier = () -> { try { return Files.createTempFile(tempTestDir, "testFile", ".bin"); } catch (IOException ioe) { throw new UncheckedIOException(ioe); } }; protected byte[] read(InputStream pIs) throws IOException { final ByteArrayOutputStream baos = new ByteArrayOutputStream(); final byte[] buffer = new byte[8192]; for (;;) { final int res = pIs.read(buffer); if (res == -1) { return baos.toByteArray(); } else if (res > 0) { baos.write(buffer, 0, res); } } } /** * Tests using the {@link DeferrableOutputStream} with a positive threshold. */ @Test void testExceedPositiveThreshold() { DeferrableOutputStream[] streams = new DeferrableOutputStream[1]; final Consumer> tester = (consumer) -> { try (final DeferrableOutputStream dos = new DeferrableOutputStream(5, testFileSupplier, null)) { streams[0] = dos; assertTrue(dos.isInMemory()); assertNull(dos.getPath()); assertNull(dos.getBytes()); assertSame(State.initialized, dos.getState()); for (int i = 0; i < 4; i++) { try { dos.write('.'); } catch (IOException ioe) { throw new UncheckedIOException(ioe); } assertSame(State.opened, dos.getState()); assertTrue(dos.isInMemory()); assertNull(dos.getPath()); assertNull(dos.getBytes()); } consumer.accept(dos); assertFalse(dos.isInMemory()); assertNotNull(dos.getPath()); assertNull(dos.getBytes()); } catch (IOException ioe) { throw new UncheckedIOException(ioe); } final DeferrableOutputStream dos = streams[0]; assertFalse(dos.isInMemory()); assertNotNull(dos.getPath()); assertTrue(Files.isRegularFile(dos.getPath())); final byte[] actual; try (InputStream is = dos.getInputStream()) { actual = read(is); } catch (IOException ioe) { throw new UncheckedIOException(ioe); } final byte[] expect = "....,".getBytes(StandardCharsets.UTF_8); assertArrayEquals(expect, actual); }; // Break the threshold using OutputStream.write(int); tester.accept((os) -> { try { os.write(','); } catch (IOException ioe) { throw new UncheckedIOException(ioe); } }); // Break the threshold using OutputStream.write(byte[]); tester.accept((os) -> { final byte[] buffer = new byte[] {','}; try { os.write(buffer); } catch (IOException ioe) { throw new UncheckedIOException(ioe); } }); // Break the threshold using OutputStream.write(byte[], int, int); tester.accept((os) -> { final byte[] buffer = new byte[] {',', '-'}; try { os.write(buffer, 0, 1); } catch (IOException ioe) { throw new UncheckedIOException(ioe); } }); } /** * Tests using the {@link DeferrableOutputStream} with threshold -1. */ @Test void testThresholdMinusOne() { DeferrableOutputStream[] streams = new DeferrableOutputStream[1]; final Runnable tester = () -> { try (final DeferrableOutputStream dos = new DeferrableOutputStream(-1, testFileSupplier, null)) { streams[0] = dos; assertFalse(dos.isInMemory()); assertNotNull(dos.getPath()); assertNull(dos.getBytes()); } catch (IOException ioe) { throw new UncheckedIOException(ioe); } final DeferrableOutputStream dos = streams[0]; assertFalse(dos.isInMemory()); assertNotNull(dos.getPath()); assertTrue(Files.isRegularFile(dos.getPath())); final byte[] actual; try (InputStream is = dos.getInputStream()) { actual = read(is); } catch (IOException ioe) { throw new UncheckedIOException(ioe); } final byte[] expect = "".getBytes(StandardCharsets.UTF_8); assertArrayEquals(expect, actual); }; tester.run(); } /** * Tests using the {@link DeferrableOutputStream} with threshold 0. */ @Test void testThresholdZero() { DeferrableOutputStream[] streams = new DeferrableOutputStream[1]; final Consumer> tester = (consumer) -> { try (final DeferrableOutputStream dos = new DeferrableOutputStream(0, testFileSupplier, null)) { streams[0] = dos; assertTrue(dos.isInMemory()); assertNull(dos.getPath()); assertNull(dos.getBytes()); assertSame(State.initialized, dos.getState()); consumer.accept(dos); assertFalse(dos.isInMemory()); assertNotNull(dos.getPath()); assertNull(dos.getBytes()); } catch (IOException ioe) { throw new UncheckedIOException(ioe); } final DeferrableOutputStream dos = streams[0]; assertFalse(dos.isInMemory()); assertNotNull(dos.getPath()); assertTrue(Files.isRegularFile(dos.getPath())); final byte[] actual; try (InputStream is = dos.getInputStream()) { actual = read(is); } catch (IOException ioe) { throw new UncheckedIOException(ioe); } final byte[] expect = ",".getBytes(StandardCharsets.UTF_8); assertArrayEquals(expect, actual); }; // Break the threshold using OutputStream.write(int); tester.accept((os) -> { try { os.write(','); } catch (IOException ioe) { throw new UncheckedIOException(ioe); } }); // Break the threshold using OutputStream.write(byte[]); tester.accept((os) -> { final byte[] buffer = new byte[] {','}; try { os.write(buffer); } catch (IOException ioe) { throw new UncheckedIOException(ioe); } }); // Break the threshold using OutputStream.write(byte[], int, int); tester.accept((os) -> { final byte[] buffer = new byte[] {',', '-'}; try { os.write(buffer, 0, 1); } catch (IOException ioe) { throw new UncheckedIOException(ioe); } }); } } ././@LongLink0000644000000000000000000000020700000000000011602 Lustar rootrootlibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-core/src/test/java/org/apache/commons/fileupload2/core/AbstractSizesTest.javalibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-core/src/test/java/org/apache/commons/fileu0000644000175000017500000002464415142145735032127 0ustar zigozigo/* * 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 * * https://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.core; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.fail; import java.io.ByteArrayOutputStream; import java.io.IOException; import org.apache.commons.io.IOUtils; import org.junit.jupiter.api.Test; /** * Unit test for items with varying sizes. * * @param The FileUpload type. * @param The FileUpload request type. * @param The FileItem type. * @param The FileItemFactory type. */ public abstract class AbstractSizesTest, R, I extends FileItem, F extends FileItemFactory> extends AbstractTest { /** * Checks whether limiting the PartHeaderSizeMax works. * * @throws IOException Test failure. */ @Test void testFilePartHeaderSizeMax() throws IOException { final String request = "-----1234\r\n" + "Content-Disposition: form-data; name=\"file\"; filename=\"foo.tab\"\r\n" + "Content-Type: text/whatever\r\n" + "Content-Length: 10\r\n" + "\r\n" + "This is the content of the file\n" + "\r\n" + "-----1234--\r\n"; final var upload = newFileUpload(); upload.setMaxPartHeaderSize(200); final var req = newMockHttpServletRequest(request, null, null); final var fileItems = upload.parseRequest(req); assertEquals(1, fileItems.size()); final var item = fileItems.get(0); assertEquals("This is the content of the file\n", new String(item.get())); var upload2 = newFileUpload(); upload2.setMaxPartHeaderSize(10); var req2 = newMockHttpServletRequest(request, null, null); assertThrows(FileUploadSizeException.class, () -> upload2.parseRequest(req2)); } /** * Checks, whether limiting the file size works. * * @throws IOException Test failure. */ @Test void testFileSizeLimit() throws IOException { final var content = "This is the content of the file\n"; final var contentSize = content.getBytes().length; // @formatter:off final var request = "-----1234\r\n" + "Content-Disposition: form-data; name=\"file\"; filename=\"foo.tab\"\r\n" + "Content-Type: text/whatever\r\n" + "\r\n" + content + "\r\n" + "-----1234--\r\n"; // @formatter:on var upload = newFileUpload(); upload.setMaxFileSize(-1); var req = newMockHttpServletRequest(request, null, null); var fileItems = upload.parseRequest(req); assertEquals(1, fileItems.size()); var item = fileItems.get(0); assertEquals(content, new String(item.get())); upload = newFileUpload(); upload.setMaxFileSize(40); req = newMockHttpServletRequest(request, null, null); fileItems = upload.parseRequest(req); assertEquals(1, fileItems.size()); item = fileItems.get(0); assertEquals(content, new String(item.get())); upload = newFileUpload(); upload.setMaxFileSize(contentSize); req = newMockHttpServletRequest(request, null, null); fileItems = upload.parseRequest(req); assertEquals(1, fileItems.size()); item = fileItems.get(0); assertEquals(content, new String(item.get())); upload = newFileUpload(); upload.setMaxFileSize(contentSize - 1); req = newMockHttpServletRequest(request, null, null); try { upload.parseRequest(req); fail("Expected exception."); } catch (final FileUploadByteCountLimitException e) { assertEquals(contentSize - 1, e.getPermitted()); } upload = newFileUpload(); upload.setMaxFileSize(30); req = newMockHttpServletRequest(request, null, null); try { upload.parseRequest(req); fail("Expected exception."); } catch (final FileUploadByteCountLimitException e) { assertEquals(30, e.getPermitted()); } } /** * Checks, whether a faked Content-Length header is detected. * * @throws IOException Test failure. */ @Test void testFileSizeLimitWithFakedContentLength() throws IOException { // @formatter:off final var request = "-----1234\r\n" + "Content-Disposition: form-data; name=\"file\"; filename=\"foo.tab\"\r\n" + "Content-Type: text/whatever\r\n" + "Content-Length: 10\r\n" + "\r\n" + "This is the content of the file\n" + "\r\n" + "-----1234--\r\n"; // @formatter:on var upload = newFileUpload(); upload.setMaxFileSize(-1); var req = newMockHttpServletRequest(request, null, null); var fileItems = upload.parseRequest(req); assertEquals(1, fileItems.size()); var item = fileItems.get(0); assertEquals("This is the content of the file\n", new String(item.get())); upload = newFileUpload(); upload.setMaxFileSize(40); req = newMockHttpServletRequest(request, null, null); fileItems = upload.parseRequest(req); assertEquals(1, fileItems.size()); item = fileItems.get(0); assertEquals("This is the content of the file\n", new String(item.get())); // provided Content-Length is larger than the FileSizeMax -> handled by ctor upload = newFileUpload(); upload.setMaxFileSize(5); req = newMockHttpServletRequest(request, null, null); try { upload.parseRequest(req); fail("Expected exception."); } catch (final FileUploadByteCountLimitException e) { assertEquals(5, e.getPermitted()); } // provided Content-Length is wrong, actual content is larger -> handled by LimitedInputStream upload = newFileUpload(); upload.setMaxFileSize(15); req = newMockHttpServletRequest(request, null, null); try { upload.parseRequest(req); fail("Expected exception."); } catch (final FileUploadByteCountLimitException e) { assertEquals(15, e.getPermitted()); } } /** * Checks whether maxSize works. * * @throws IOException Test failure. */ @Test void testMaxSizeLimit() throws IOException { // @formatter:off final var request = "-----1234\r\n" + "Content-Disposition: form-data; name=\"file1\"; filename=\"foo1.tab\"\r\n" + "Content-Type: text/whatever\r\n" + "Content-Length: 10\r\n" + "\r\n" + "This is the content of the file\n" + "\r\n" + "-----1234\r\n" + "Content-Disposition: form-data; name=\"file2\"; filename=\"foo2.tab\"\r\n" + "Content-Type: text/whatever\r\n" + "\r\n" + "This is the content of the file\n" + "\r\n" + "-----1234--\r\n"; // @formatter:on final var upload = newFileUpload(); upload.setMaxFileSize(-1); upload.setMaxSize(200); final var req = newMockHttpServletRequest(request, null, null); try { upload.parseRequest(req); fail("Expected exception."); } catch (final FileUploadSizeException e) { assertEquals(200, e.getPermitted()); } } @Test void testMaxSizeLimitUnknownContentLength() throws IOException { // @formatter:off final var request = "-----1234\r\n" + "Content-Disposition: form-data; name=\"file1\"; filename=\"foo1.tab\"\r\n" + "Content-Type: text/whatever\r\n" + "Content-Length: 10\r\n" + "\r\n" + "This is the content of the file\n" + "\r\n" + "-----1234\r\n" + "Content-Disposition: form-data; name=\"file2\"; filename=\"foo2.tab\"\r\n" + "Content-Type: text/whatever\r\n" + "\r\n" + "This is the content of the file\n" + "\r\n" + "-----1234--\r\n"; // @formatter:on final var upload = newFileUpload(); upload.setMaxFileSize(-1); upload.setMaxSize(300); // the first item should be within the max size limit // set the read limit to 10 to simulate a "real" stream // otherwise the buffer would be immediately filled final var req = newMockHttpServletRequest(request, -1L, 10); final var it = upload.getItemIterator(req); assertTrue(it.hasNext()); final var item = it.next(); assertFalse(item.isFormField()); assertEquals("file1", item.getFieldName()); assertEquals("foo1.tab", item.getName()); { try (final var baos = new ByteArrayOutputStream(); final var stream = item.getInputStream()) { IOUtils.copy(stream, baos); } } // the second item is over the size max, thus we expect an error // the header is still within size max -> this shall still succeed assertTrue(it.hasNext()); assertThrows(FileUploadException.class, () -> { final var item2 = it.next(); try (final var baos = new ByteArrayOutputStream(); final var stream = item2.getInputStream()) { IOUtils.copy(stream, baos); } }); } } ././@LongLink0000644000000000000000000000022400000000000011601 Lustar rootrootlibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-core/src/test/java/org/apache/commons/fileupload2/core/QuotedPrintableDecoderTestCase.javalibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-core/src/test/java/org/apache/commons/fileu0000644000175000017500000001041615142145735032117 0ustar zigozigo/* * 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 * * https://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.core; import static org.junit.jupiter.api.Assertions.assertArrayEquals; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.fail; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.nio.charset.StandardCharsets; import org.junit.jupiter.api.Test; /** */ public final class QuotedPrintableDecoderTestCase { private static void assertEncoded(final String clearText, final String encoded) throws Exception { final var expected = clearText.getBytes(StandardCharsets.US_ASCII); final var out = new ByteArrayOutputStream(encoded.length()); final var encodedData = encoded.getBytes(StandardCharsets.US_ASCII); QuotedPrintableDecoder.decode(encodedData, out); final var actual = out.toByteArray(); assertArrayEquals(expected, actual); } private static void assertIOException(final String messageText, final String encoded) { final var out = new ByteArrayOutputStream(encoded.length()); final var encodedData = encoded.getBytes(StandardCharsets.US_ASCII); try { QuotedPrintableDecoder.decode(encodedData, out); fail("Expected IOException"); } catch (final IOException e) { final var em = e.getMessage(); assertTrue(em.contains(messageText), "Expected to find " + messageText + " in '" + em + "'"); } } @Test void testBasicEncodeDecode() throws Exception { assertEncoded("= Hello there =\r\n", "=3D Hello there =3D=0D=0A"); } @Test void testEmptyDecode() throws Exception { assertEncoded("", ""); } @Test void testInvalidCharDecode() { assertThrows(IOException.class, () -> assertEncoded("=\r\n", "=3D=XD=XA")); } @Test void testInvalidQuotedPrintableEncoding() throws Exception { assertIOException("truncated escape sequence", "YWJjMTIzXy0uKn4hQCMkJV4mKCkre31cIlxcOzpgLC9bXQ=="); } @Test void testInvalidSoftBreak1() throws Exception { assertIOException("CR must be followed by LF", "=\r\r"); } @Test void testInvalidSoftBreak2() throws Exception { assertIOException("CR must be followed by LF", "=\rn"); } @Test void testPlainDecode() throws Exception { // spaces are allowed in encoded data // There are special rules for trailing spaces; these are not currently implemented. assertEncoded("The quick brown fox jumps over the lazy dog.", "The quick brown fox jumps over the lazy dog."); } /** * This is NOT supported by Commons-Codec, see CODEC-121. * * @throws Exception * @see CODEC-121 */ @Test void testSoftLineBreakDecode() throws Exception { assertEncoded("If you believe that truth=beauty, then surely mathematics is the most " + "beautiful branch of philosophy.", "If you believe that truth=3Dbeauty, then " + "surely=20=\r\nmathematics is the most beautiful branch of philosophy."); } @Test void testTruncatedEscape() throws Exception { assertIOException("truncated", "=1"); } @Test void testUnsafeDecode() throws Exception { assertEncoded("=\r\n", "=3D=0D=0A"); } @Test void testUnsafeDecodeLowerCase() throws Exception { assertEncoded("=\r\n", "=3d=0d=0a"); } } ././@LongLink0000644000000000000000000000021700000000000011603 Lustar rootrootlibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-core/src/test/java/org/apache/commons/fileupload2/core/AbstractFileUploadWrapper.javalibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-core/src/test/java/org/apache/commons/fileu0000644000175000017500000000414215142145735032116 0ustar zigozigo/* * 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 * * https://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.core; import java.nio.charset.StandardCharsets; import java.util.List; /** * Common tests for implementations of {@link AbstractFileUpload}. This is a parameterized test. Tests must be valid and common to all implementations of * FileUpload added as parameter in this class. * * @param The type for {@link AbstractFileUpload}. * @param The FileUpload request type. * @param The FileItem type. * @param The FileItemFactory type. */ public abstract class AbstractFileUploadWrapper, R, I extends FileItem, F extends FileItemFactory> { protected final AFU upload; protected AbstractFileUploadWrapper(final AFU fileUpload) { this.upload = fileUpload; } public List parseUpload(final AFU upload, final byte[] bytes) throws FileUploadException { return parseUpload(upload, bytes, Constants.CONTENT_TYPE); } public abstract List parseUpload(final AFU upload, final byte[] bytes, final String contentType) throws FileUploadException; public List parseUpload(final AFU upload, final String content) throws FileUploadException { final var bytes = content.getBytes(StandardCharsets.US_ASCII); return parseUpload(upload, bytes, Constants.CONTENT_TYPE); } } ././@LongLink0000644000000000000000000000021700000000000011603 Lustar rootrootlibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-core/src/test/java/org/apache/commons/fileupload2/core/DiskFileItemSerializeTest.javalibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-core/src/test/java/org/apache/commons/fileu0000644000175000017500000002263715142145735032127 0ustar zigozigo/* * 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 * * https://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.core; 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.assertThrows; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.ObjectOutputStream; import java.nio.file.FileVisitResult; import java.nio.file.Files; import java.nio.file.InvalidPathException; import java.nio.file.Path; import java.nio.file.attribute.BasicFileAttributes; import org.apache.commons.io.file.PathUtils; import org.apache.commons.io.file.SimplePathVisitor; import org.apache.commons.lang3.SerializationUtils; import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; /** * Serialization Unit tests for {@link DiskFileItem}. */ class DiskFileItemSerializeTest { /** * Use a private repository to catch any files left over by tests. */ private static final Path REPOSITORY = PathUtils.getTempDirectory().resolve("DiskFileItemRepo"); /** * Content type for regular form items. */ private static final String TEXT_CONTENT_TYPE = "text/plain"; /** * Very low threshold for testing memory versus disk options. */ private static final int THRESHOLD = 16; /** * Compare content bytes. */ private void compareBytes(final String text, final byte[] origBytes, final byte[] newBytes) { assertNotNull(origBytes, "origBytes must not be null"); assertNotNull(newBytes, "newBytes must not be null"); assertEquals(origBytes.length, newBytes.length, text + " byte[] length"); for (var i = 0; i < origBytes.length; i++) { assertEquals(origBytes[i], newBytes[i], text + " byte[" + i + "]"); } } /** * Create content bytes of a specified size. */ private byte[] createContentBytes(final int size) { final var buffer = new StringBuilder(size); byte count = 0; for (var i = 0; i < size; i++) { buffer.append(Byte.toString(count)); count++; if (count > 9) { count = 0; } } return buffer.toString().getBytes(); } /** * Create a FileItem with the specfied content bytes. */ private DiskFileItem createFileItem(final byte[] contentBytes, int threshold) throws IOException { return createFileItem(contentBytes, REPOSITORY, threshold); } /** * Create a FileItem with the specfied content bytes and repository. */ private DiskFileItem createFileItem(final byte[] contentBytes, final Path repository, int threshold) throws IOException { // @formatter:off final FileItemFactory factory = DiskFileItemFactory.builder() .setBufferSize(THRESHOLD) .setPath(repository) .setBufferSize(threshold) .get(); // @formatter:on // @formatter:off final var item = factory.fileItemBuilder() .setFieldName("textField") .setContentType(TEXT_CONTENT_TYPE) .setFormField(true) .setFileName("My File Name") .get(); // @formatter:on try (var os = item.getOutputStream()) { os.write(contentBytes); } return item; } /** * Deserializes. */ private Object deserialize(final ByteArrayOutputStream baos) { return SerializationUtils.deserialize(baos.toByteArray()); } /** * Serializes. */ private ByteArrayOutputStream serialize(final Object target) throws IOException { try (final var baos = new ByteArrayOutputStream(); final var oos = new ObjectOutputStream(baos)) { oos.writeObject(target); oos.flush(); return baos; } } @BeforeEach public void setUp() throws IOException { if (Files.exists(REPOSITORY)) { PathUtils.deleteDirectory(REPOSITORY); } else { Files.createDirectories(REPOSITORY); } } @AfterEach public void tearDown() throws IOException { if (Files.exists(REPOSITORY)) { PathUtils.visitFileTree(new SimplePathVisitor() { @Override public FileVisitResult visitFile(final Path file, final BasicFileAttributes attrs) throws IOException { System.out.println("Found leftover file " + file); return FileVisitResult.CONTINUE; } }, REPOSITORY); PathUtils.deleteDirectory(REPOSITORY); } } /** * Test creation of a field for which the amount of data falls above the configured threshold. * * @throws IOException Test failure. */ @Test void testAboveThreshold() throws IOException { // Create the FileItem final var testFieldValueBytes = createContentBytes(THRESHOLD + 1); final var item = createFileItem(testFieldValueBytes, THRESHOLD); // Check state is as expected assertFalse(item.isInMemory(), "Initial: in memory"); assertEquals(item.getSize(), testFieldValueBytes.length, "Initial: size"); compareBytes("Initial", item.get(), testFieldValueBytes); testWritingToFile(item, testFieldValueBytes); item.delete(); } /** * Test creation of a field for which the amount of data falls below the configured threshold. * * @throws IOException Test failure. */ @Test void testBelowThreshold() throws IOException { // Create the FileItem final var testFieldValueBytes = createContentBytes(THRESHOLD-1); testInMemoryObject(testFieldValueBytes, THRESHOLD); } @Test void testCheckFileName() { assertThrows(InvalidPathException.class, () -> DiskFileItem.checkFileName("\0")); } /** * Helper method to test creation of a field. */ private void testInMemoryObject(final byte[] testFieldValueBytes, int threshold) throws IOException { testInMemoryObject(testFieldValueBytes, REPOSITORY, threshold); } /** * Helper method to test creation of a field when a repository is used. */ private void testInMemoryObject(final byte[] testFieldValueBytes, final Path repository, int threshold) throws IOException { final var item = createFileItem(testFieldValueBytes, repository, threshold); // Check state is as expectedthreshold >= testFieldValueBytes.length, item.isInMemory(), "Initial: in memory"); assertEquals(item.getSize(), testFieldValueBytes.length, "Initial: size"); compareBytes("Inititem.getSize(), testFieldValueBytes.lengthial", item.get(), testFieldValueBytes); testWritingToFile(item, testFieldValueBytes); item.delete(); } /** * Test deserialization fails when repository is not valid. * * @throws IOException Test failure. */ @Test void testInvalidRepository() throws IOException { // Create the FileItem final var testFieldValueBytes = createContentBytes(THRESHOLD); final var repository = PathUtils.getTempDirectory().resolve("file"); final var item = createFileItem(testFieldValueBytes, repository, THRESHOLD); assertThrows(IOException.class, () -> deserialize(serialize(item))); } /** * Test creation of a field for which the amount of data equals the configured threshold. * * @throws IOException Test failure. */ @Test void testThreshold() throws IOException { // Create the FileItem final var testFieldValueBytes = createContentBytes(THRESHOLD); testInMemoryObject(testFieldValueBytes, THRESHOLD); } /** * Test serialization and deserialization when repository is not null. * * @throws IOException Test failure. */ @Test void testValidRepository() throws IOException { // Create the FileItem final var testFieldValueBytes = createContentBytes(THRESHOLD); testInMemoryObject(testFieldValueBytes, REPOSITORY, THRESHOLD+1); } /** * Helper method to test writing item contents to a file. */ private void testWritingToFile(final DiskFileItem item, final byte[] testFieldValueBytes) throws IOException { final var temp = Files.createTempFile("fileupload", null); // Note that the file exists and is initially empty; // write() must be able to handle that. item.write(temp); compareBytes("Initial", Files.readAllBytes(temp), testFieldValueBytes); } } ././@LongLink0000644000000000000000000000021400000000000011600 Lustar rootrootlibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-core/src/test/java/org/apache/commons/fileupload2/core/AbstractFileUploadTest.javalibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-core/src/test/java/org/apache/commons/fileu0000644000175000017500000005202015142145735032114 0ustar zigozigo/* * 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 * * https://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.core; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.IOException; import java.nio.charset.StandardCharsets; import org.apache.commons.fileupload2.core.MultipartInput.FileUploadBoundaryException; import org.junit.jupiter.api.Test; /** * Common tests for implementations of {@link AbstractFileUpload}. This is a parameterized test. Tests must be valid and common to all implementations of * FileUpload added as parameter in this class. * * @param The {@link AbstractFileUpload} type. * @param The FileUpload request type. * @param The FileItem type. * @param The FileItemFactory type. */ public abstract class AbstractFileUploadTest, R, I extends FileItem, F extends FileItemFactory> extends AbstractFileUploadWrapper { protected AbstractFileUploadTest(final AFU fileUpload) { super(fileUpload); } private void assertHeaders(final String[] headerNames, final String[] headerValues, final I fileItems, final int index) { for (var i = 0; i < headerNames.length; i++) { final var value = fileItems.getHeaders().getHeader(headerNames[i]); if (i == index) { assertEquals(headerValues[i], value); } else { assertNull(value); } } } /** * Tests FILEUPLOAD-239 * * @throws IOException Test failure. */ @Test void testContentTypeAttachment() throws IOException { // @formatter:off final var fileItems = parseUpload(upload, "-----1234\r\n" + "content-disposition: form-data; name=\"field1\"\r\n" + "\r\n" + "Joe Blow\r\n" + "-----1234\r\n" + "content-disposition: form-data; name=\"pics\"\r\n" + "Content-type: multipart/mixed, boundary=---9876\r\n" + "\r\n" + "-----9876\r\n" + "Content-disposition: attachment; filename=\"file1.txt\"\r\n" + "Content-Type: text/plain\r\n" + "\r\n" + "... contents of file1.txt ...\r\n" + "-----9876--\r\n" + "-----1234--\r\n"); // @formatter:on assertEquals(2, fileItems.size()); final var field = fileItems.get(0); assertEquals("field1", field.getFieldName()); assertTrue(field.isFormField()); assertEquals("Joe Blow", field.getString()); final var fileItem = fileItems.get(1); assertEquals("pics", fileItem.getFieldName()); assertFalse(fileItem.isFormField()); assertEquals("... contents of file1.txt ...", fileItem.getString()); assertEquals("text/plain", fileItem.getContentType()); assertEquals("file1.txt", fileItem.getName()); } /** * This is what the browser does if you submit the form without choosing a file. * * @throws FileUploadException Test failure. */ @Test void testEmptyFile() throws IOException { // @formatter:off final var fileItems = parseUpload (upload, "-----1234\r\n" + "Content-Disposition: form-data; name=\"file\"; filename=\"\"\r\n" + "\r\n" + "\r\n" + "-----1234--\r\n"); // @formatter:on assertEquals(1, fileItems.size()); final var file = fileItems.get(0); assertFalse(file.isFormField()); assertEquals("", file.getString()); assertEquals("", file.getName()); } @Test void testFileNameCaseSensitivity() throws IOException { // @formatter:off final var fileItems = parseUpload(upload, "-----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"); // @formatter:on assertEquals(1, fileItems.size()); final var file = fileItems.get(0); assertEquals("FiLe", file.getFieldName()); assertEquals("FOO.tab", file.getName()); } @Test public void testFileUpload() throws IOException { // @formatter:off final var fileItems = parseUpload(upload, "-----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" + "Content-Disposition: form-data; name=\"field\"\r\n" + "\r\n" + "fieldValue\r\n" + "-----1234\r\n" + "Content-Disposition: form-data; name=\"multi\"\r\n" + "\r\n" + "value1\r\n" + "-----1234\r\n" + "Content-Disposition: form-data; name=\"multi\"\r\n" + "\r\n" + "value2\r\n" + "-----1234--\r\n"); // @formatter:on assertEquals(4, fileItems.size()); final var file = fileItems.get(0); assertEquals("file", file.getFieldName()); assertFalse(file.isFormField()); assertEquals("This is the content of the file\n", file.getString()); assertEquals("text/whatever", file.getContentType()); assertEquals("foo.tab", file.getName()); final var field = fileItems.get(1); assertEquals("field", field.getFieldName()); assertTrue(field.isFormField()); assertEquals("fieldValue", field.getString()); final var multi0 = fileItems.get(2); assertEquals("multi", multi0.getFieldName()); assertTrue(multi0.isFormField()); assertEquals("value1", multi0.getString()); final var multi1 = fileItems.get(3); assertEquals("multi", multi1.getFieldName()); assertTrue(multi1.isFormField()); assertEquals("value2", multi1.getString()); } /** * Test case for FILEUPLOAD-130. * * @throws IOException Test failure. */ @Test void testFileUpload130() throws IOException { final String[] headerNames = { "SomeHeader", "OtherHeader", "YetAnotherHeader", "WhatAHeader" }; final String[] headerValues = { "present", "Is there", "Here", "Is That" }; // @formatter:off final var fileItems = parseUpload(upload, "-----1234\r\n" + "Content-Disposition: form-data; name=\"file\"; " + "filename=\"foo.tab\"\r\n" + "Content-Type: text/whatever\r\n" + headerNames[0] + ": " + headerValues[0] + "\r\n" + "\r\n" + "This is the content of the file\n" + "\r\n" + "-----1234\r\n" + "Content-Disposition: form-data; \r\n" + "\tname=\"field\"\r\n" + headerNames[1] + ": " + headerValues[1] + "\r\n" + "\r\n" + "fieldValue\r\n" + "-----1234\r\n" + "Content-Disposition: form-data;\r\n" + " name=\"multi\"\r\n" + headerNames[2] + ": " + headerValues[2] + "\r\n" + "\r\n" + "value1\r\n" + "-----1234\r\n" + "Content-Disposition: form-data; name=\"multi\"\r\n" + headerNames[3] + ": " + headerValues[3] + "\r\n" + "\r\n" + "value2\r\n" + "-----1234--\r\n"); // @formatter:on assertEquals(4, fileItems.size()); final var file = fileItems.get(0); assertHeaders(headerNames, headerValues, file, 0); final var field = fileItems.get(1); assertHeaders(headerNames, headerValues, field, 1); final var multi0 = fileItems.get(2); assertHeaders(headerNames, headerValues, multi0, 2); final var multi1 = fileItems.get(3); assertHeaders(headerNames, headerValues, multi1, 3); } /** * Test for FILEUPLOAD-62 * * @throws IOException Test failure. */ @Test void testFILEUPLOAD62() throws IOException { // @formatter:off final var contentType = "multipart/form-data; boundary=AaB03x"; final var request = "--AaB03x\r\n" + "content-disposition: form-data; name=\"field1\"\r\n" + "\r\n" + "Joe Blow\r\n" + "--AaB03x\r\n" + "content-disposition: form-data; name=\"pics\"\r\n" + "Content-type: multipart/mixed; boundary=BbC04y\r\n" + "\r\n" + "--BbC04y\r\n" + "Content-disposition: attachment; filename=\"file1.txt\"\r\n" + "Content-Type: text/plain\r\n" + "\r\n" + "... contents of file1.txt ...\r\n" + "--BbC04y\r\n" + "Content-disposition: attachment; filename=\"file2.gif\"\r\n" + "Content-type: image/gif\r\n" + "Content-Transfer-Encoding: binary\r\n" + "\r\n" + "...contents of file2.gif...\r\n" + "--BbC04y--\r\n" + "--AaB03x--"; // @formatter:on final var fileItems = parseUpload(upload, request.getBytes(StandardCharsets.US_ASCII), contentType); assertEquals(3, fileItems.size()); final var item0 = fileItems.get(0); assertEquals("field1", item0.getFieldName()); assertNull(item0.getName()); assertEquals("Joe Blow", new String(item0.get())); final var item1 = fileItems.get(1); assertEquals("pics", item1.getFieldName()); assertEquals("file1.txt", item1.getName()); assertEquals("... contents of file1.txt ...", new String(item1.get())); final var item2 = fileItems.get(2); assertEquals("pics", item2.getFieldName()); assertEquals("file2.gif", item2.getName()); assertEquals("...contents of file2.gif...", new String(item2.get())); } /** * Test for FILEUPLOAD-111 * * @throws IOException Test failure. */ @Test void testFoldedHeaders() throws IOException { // @formatter:off final var fileItems = parseUpload(upload, "-----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" + "Content-Disposition: form-data; \r\n" + "\tname=\"field\"\r\n" + "\r\n" + "fieldValue\r\n" + "-----1234\r\n" + "Content-Disposition: form-data;\r\n" + " name=\"multi\"\r\n" + "\r\n" + "value1\r\n" + "-----1234\r\n" + "Content-Disposition: form-data; name=\"multi\"\r\n" + "\r\n" + "value2\r\n" + "-----1234--\r\n"); // @formatter:on assertEquals(4, fileItems.size()); final var file = fileItems.get(0); assertEquals("file", file.getFieldName()); assertFalse(file.isFormField()); assertEquals("This is the content of the file\n", file.getString()); assertEquals("text/whatever", file.getContentType()); assertEquals("foo.tab", file.getName()); final var field = fileItems.get(1); assertEquals("field", field.getFieldName()); assertTrue(field.isFormField()); assertEquals("fieldValue", field.getString()); final var multi0 = fileItems.get(2); assertEquals("multi", multi0.getFieldName()); assertTrue(multi0.isFormField()); assertEquals("value1", multi0.getString()); final var multi1 = fileItems.get(3); assertEquals("multi", multi1.getFieldName()); assertTrue(multi1.isFormField()); assertEquals("value2", multi1.getString()); } /** * Internet Explorer 5 for the Mac has a bug where the carriage return is missing on any boundary line immediately preceding an input with type=image. * (type=submit does not have the bug.) * * @throws FileUploadException Test failure. */ @Test void testIE5MacBug() throws IOException { final var fileItems = parseUpload(upload, // @formatter:off "-----1234\r\n" + "Content-Disposition: form-data; name=\"field1\"\r\n" + "\r\n" + "fieldValue\r\n" + "-----1234\n" + // NOTE \r missing "Content-Disposition: form-data; name=\"submitName.x\"\r\n" + "\r\n" + "42\r\n" + "-----1234\n" + // NOTE \r missing "Content-Disposition: form-data; name=\"submitName.y\"\r\n" + "\r\n" + "21\r\n" + "-----1234\r\n" + "Content-Disposition: form-data; name=\"field2\"\r\n" + "\r\n" + "fieldValue2\r\n" + "-----1234--\r\n"); //@formatter:on assertEquals(4, fileItems.size()); final var field1 = fileItems.get(0); assertEquals("field1", field1.getFieldName()); assertTrue(field1.isFormField()); assertEquals("fieldValue", field1.getString()); final var submitX = fileItems.get(1); assertEquals("submitName.x", submitX.getFieldName()); assertTrue(submitX.isFormField()); assertEquals("42", submitX.getString()); final var submitY = fileItems.get(2); assertEquals("submitName.y", submitY.getFieldName()); assertTrue(submitY.isFormField()); assertEquals("21", submitY.getString()); final var field2 = fileItems.get(3); assertEquals("field2", field2.getFieldName()); assertTrue(field2.isFormField()); assertEquals("fieldValue2", field2.getString()); } @Test void testIsMultipartRequestMethod() { for (String allowed : new String[]{"POST", "PUT", "PATCH"}) { assertTrue(AbstractFileUpload.isMultipartRequestMethod(allowed)); } for (String disallowed : new String[]{"GET", "HEAD", "DELETE", "CONNECT", "OPTIONS", "TRACE"}) { assertFalse(AbstractFileUpload.isMultipartRequestMethod(disallowed)); } } /** * Test for multipart/mixed with no boundary defined */ @Test void testMultipartMixedNoBoundary() { // @formatter:off final var contentType = "multipart/form-data; boundary=AaB03x"; final var request = "--AaB03x\r\n" + "content-disposition: form-data; name=\"field1\"\r\n" + "\r\n" + "Joe Blow\r\n" + "--AaB03x\r\n" + "content-disposition: form-data; name=\"pics\"\r\n" + "Content-type: multipart/mixed\r\n" + "\r\n" + "--BbC04y\r\n" + "Content-disposition: attachment; filename=\"file1.txt\"\r\n" + "Content-Type: text/plain\r\n" + "\r\n" + "... contents of file1.txt ...\r\n" + "--BbC04y\r\n" + "Content-disposition: attachment; filename=\"file2.gif\"\r\n" + "Content-type: image/gif\r\n" + "Content-Transfer-Encoding: binary\r\n" + "\r\n" + "...contents of file2.gif...\r\n" + "--BbC04y--\r\n" + "--AaB03x--"; // @formatter:on assertThrows(FileUploadBoundaryException.class, () -> parseUpload(upload, request.getBytes(StandardCharsets.US_ASCII), contentType)); } /** * Test for multipart/related without any content-disposition Header. * This kind of Content-Type is commonly used by SOAP-Requests with Attachments (MTOM) */ @Test void testMultipleRelated() throws Exception { final String soapEnvelope = "\r\n" + " \r\n" + " \r\n" + " \r\n" + " \r\n" + " \r\n" + " \r\n" + " \r\n" + " \r\n" + ""; final String text = "-----1234\r\n" + "content-type: application/xop+xml; type=\"application/soap+xml\"\r\n" + "\r\n" + soapEnvelope + "\r\n" + "-----1234\r\n" + "Content-type: text/plain\r\n" + "content-id: \r\n" + "\r\n" + "some text/plain content\r\n" + "-----1234--\r\n"; final var bytes = text.getBytes(StandardCharsets.US_ASCII); final var fileItems = parseUpload(upload, bytes, "multipart/related; boundary=---1234;" + " type=\"application/xop+xml\"; start-info=\"application/soap+xml\""); assertEquals(2, fileItems.size()); final var part1 = fileItems.get(0); assertNull(part1.getFieldName()); assertFalse(part1.isFormField()); assertEquals(soapEnvelope, part1.getString()); final var part2 = fileItems.get(1); assertNull(part2.getFieldName()); assertFalse(part2.isFormField()); assertEquals("some text/plain content", part2.getString()); assertEquals("text/plain", part2.getContentType()); assertNull(part2.getName()); } } ././@LongLink0000644000000000000000000000021100000000000011575 Lustar rootrootlibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-core/src/test/java/org/apache/commons/fileupload2/core/MimeUtilityTestCase.javalibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-core/src/test/java/org/apache/commons/fileu0000644000175000017500000000511215142145735032114 0ustar zigozigo/* * 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 * * https://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.core; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; import java.io.UnsupportedEncodingException; import org.junit.jupiter.api.Test; /** * Use the online MimeHeadersDecoder to validate expected values. */ public final class MimeUtilityTestCase { private static void assertEncoded(final String expected, final String encoded) throws Exception { assertEquals(expected, MimeUtils.decodeText(encoded)); } @Test void testDecodeInvalidEncoding() { assertThrows(UnsupportedEncodingException.class, () -> MimeUtils.decodeText("=?invalid?B?xyz-?=")); } @Test void testDecodeIso88591Base64Encoded() throws Exception { assertEncoded("If you can read this you understand the example.", "=?ISO-8859-1?B?SWYgeW91IGNhbiByZWFkIHRoaXMgeW8=?= " + "=?ISO-8859-2?B?dSB1bmRlcnN0YW5kIHRoZSBleGFtcGxlLg==?=\"\r\n"); } @Test void testDecodeIso88591Base64EncodedWithWhiteSpace() throws Exception { assertEncoded("If you can read this you understand the example.", "=?ISO-8859-1?B?SWYgeW91IGNhbiByZWFkIHRoaXMgeW8=?=\t \r\n =?ISO-8859-" + "2?B?dSB1bmRlcnN0YW5kIHRoZSBleGFtcGxlLg==?=\"\r\n"); } @Test void testDecodeUtf8Base64Encoded() throws Exception { assertEncoded(" h\u00e9! \u00e0\u00e8\u00f4u !!!", "=?UTF-8?B?IGjDqSEgw6DDqMO0dSAhISE=?="); } @Test void testDecodeUtf8QuotedPrintableEncoded() throws Exception { assertEncoded(" h\u00e9! \u00e0\u00e8\u00f4u !!!", "=?UTF-8?Q?_h=C3=A9!_=C3=A0=C3=A8=C3=B4u_!!!?="); } @Test void testNoNeedToDecode() throws Exception { assertEncoded("abc", "abc"); } } ././@LongLink0000644000000000000000000000017700000000000011610 Lustar rootrootlibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-core/src/test/java/org/apache/commons/fileupload2/core/Constants.javalibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-core/src/test/java/org/apache/commons/fileu0000644000175000017500000000212215142145735032112 0ustar zigozigo/* * 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 * * https://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.core; /** * Constants used for testing. */ public final class Constants { /** * The content type used in several tests. */ public static final String CONTENT_TYPE = "multipart/form-data; boundary=---1234"; private Constants() { } } ././@LongLink0000644000000000000000000000020200000000000011575 Lustar rootrootlibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-core/src/test/java/org/apache/commons/fileupload2/core/AbstractTest.javalibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-core/src/test/java/org/apache/commons/fileu0000644000175000017500000000416015142145735032116 0ustar zigozigo/* * 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 * * https://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.core; import java.io.ByteArrayInputStream; import java.io.InputStream; import java.nio.charset.StandardCharsets; /** * Abstract test. * * @param The AbstractFileUpload type. * @param The FileUpload request type. * @param The FileItem type. * @param The FileItemFactory type. */ public abstract class AbstractTest, R, I extends FileItem, F extends FileItemFactory> { protected abstract AFU newFileUpload(); protected R newMockHttpServletRequest(final byte[] request, final Long overrideContenLength, final String contentType, final Integer overrideReadLimit) { return newMockHttpServletRequest(new ByteArrayInputStream(request), overrideContenLength != null ? overrideContenLength : request.length, contentType, overrideReadLimit != null ? overrideReadLimit : -1); } protected abstract R newMockHttpServletRequest(InputStream requestInputStream, long requestLength, String contentType, int readLimit); protected R newMockHttpServletRequest(final String request, final Long overrideContenLength, final Integer overrideReadLimit) { return newMockHttpServletRequest(request.getBytes(StandardCharsets.US_ASCII), overrideContenLength, Constants.CONTENT_TYPE, overrideReadLimit); } } ././@LongLink0000644000000000000000000000021100000000000011575 Lustar rootrootlibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-core/src/test/java/org/apache/commons/fileupload2/core/MultipartStreamTest.javalibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-core/src/test/java/org/apache/commons/fileu0000644000175000017500000001117615142145735032123 0ustar zigozigo/* * 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 * * https://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.core; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.fail; import java.io.ByteArrayInputStream; import java.io.InputStream; import java.nio.charset.StandardCharsets; import org.apache.commons.io.output.NullOutputStream; import org.junit.jupiter.api.Test; /** * Tests {@link MultipartInput}. */ class MultipartStreamTest { static private final String BOUNDARY_TEXT = "myboundary"; /** * Tests whether the maxSize works. */ @Test public void testPartHeaderSizeMaxLimit() throws Exception { final String request = "-----1234\r\n" + "Content-Disposition: form-data; name=\"file1\"; filename=\"foo1.tab\"\r\n" + "Content-Type: text/whatever\r\n" + "Content-Length: 10\r\n" + "\r\n" + "This is the content of the file\n" + "\r\n" + "-----1234\r\n" + "Content-Disposition: form-data; name=\"file2\"; filename=\"foo2.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[] byteContents = request.getBytes(StandardCharsets.UTF_8); final InputStream input = new ByteArrayInputStream(byteContents); final byte[] boundary = "---1234".getBytes(); final MultipartInput mi = MultipartInput.builder().setInputStream(input).setBoundary(boundary).setMaxPartHeaderSize(100).get(); assertNotNull(mi); try { boolean nextPart = mi.skipPreamble(); while (nextPart) { final String headers = mi.readHeaders(); System.out.print("Headers=" + headers.length() + ", " + headers); assertNotNull(headers); // process headers // create some output stream mi.readBodyData(NullOutputStream.INSTANCE); nextPart = mi.readBoundary(); } fail("Expected Exception"); } catch (final FileUploadSizeException fuse) { assertEquals(100, fuse.getPermitted()); } } @Test void testSmallBuffer() { final var strData = "foobar"; final var contents = strData.getBytes(); final InputStream input = new ByteArrayInputStream(contents); final var boundary = BOUNDARY_TEXT.getBytes(); final var iBufSize = 1; assertThrows(IllegalArgumentException.class, () -> MultipartInput.builder().setInputStream(input).setBoundary(boundary).setBufferSize(iBufSize) .setProgressNotifier(new MultipartInput.ProgressNotifier(null, contents.length)).get()); } @Test void testThreeParamConstructor() throws Exception { final var strData = "foobar"; final var contents = strData.getBytes(); final InputStream input = new ByteArrayInputStream(contents); final var boundary = BOUNDARY_TEXT.getBytes(); final var iBufSize = boundary.length + MultipartInput.BOUNDARY_PREFIX.length + 1; final var ms = MultipartInput.builder().setInputStream(input).setBoundary(boundary).setBufferSize(iBufSize) .setProgressNotifier(new MultipartInput.ProgressNotifier(null, contents.length)).get(); assertNotNull(ms); } @Test void testTwoParamConstructor() throws Exception { final var strData = "foobar"; final var contents = strData.getBytes(); final InputStream input = new ByteArrayInputStream(contents); final var boundary = BOUNDARY_TEXT.getBytes(); final var ms = MultipartInput.builder().setInputStream(input).setBoundary(boundary) .setProgressNotifier(new MultipartInput.ProgressNotifier(null, contents.length)).get(); assertNotNull(ms); } } ././@LongLink0000644000000000000000000000021100000000000011575 Lustar rootrootlibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-core/src/test/java/org/apache/commons/fileupload2/core/FileItemHeadersTest.javalibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-core/src/test/java/org/apache/commons/fileu0000644000175000017500000000772715142145735032132 0ustar zigozigo/* * 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 * * https://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.core; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertTrue; import java.util.Iterator; import org.junit.jupiter.api.Test; /** * Tests {@link FileItemHeaders} and {@link FileItemHeadersImpl}. */ class FileItemHeadersTest { /** * @throws Exception */ @Test void testFileItemHeaders() throws Exception { final var mutableFileItemHeaders = new FileItemHeadersImpl(); mutableFileItemHeaders.addHeader("Content-Disposition", "form-data; name=\"FileItem\"; filename=\"file1.txt\""); mutableFileItemHeaders.addHeader("Content-Type", "text/plain"); mutableFileItemHeaders.addHeader("TestHeader", "headerValue1"); mutableFileItemHeaders.addHeader("TestHeader", "headerValue2"); mutableFileItemHeaders.addHeader("TestHeader", "headerValue3"); mutableFileItemHeaders.addHeader("testheader", "headerValue4"); final var headerNameIterator = mutableFileItemHeaders.getHeaderNames(); assertEquals("content-disposition", headerNameIterator.next()); assertEquals("content-type", headerNameIterator.next()); assertEquals("testheader", headerNameIterator.next()); assertFalse(headerNameIterator.hasNext()); assertEquals(mutableFileItemHeaders.getHeader("Content-Disposition"), "form-data; name=\"FileItem\"; filename=\"file1.txt\""); assertEquals(mutableFileItemHeaders.getHeader("Content-Type"), "text/plain"); assertEquals(mutableFileItemHeaders.getHeader("content-type"), "text/plain"); assertEquals(mutableFileItemHeaders.getHeader("TestHeader"), "headerValue1"); assertNull(mutableFileItemHeaders.getHeader("DummyHeader")); Iterator headerValueEnumeration; headerValueEnumeration = mutableFileItemHeaders.getHeaders("Content-Type"); assertTrue(headerValueEnumeration.hasNext()); assertEquals(headerValueEnumeration.next(), "text/plain"); assertFalse(headerValueEnumeration.hasNext()); headerValueEnumeration = mutableFileItemHeaders.getHeaders("content-type"); assertTrue(headerValueEnumeration.hasNext()); assertEquals(headerValueEnumeration.next(), "text/plain"); assertFalse(headerValueEnumeration.hasNext()); headerValueEnumeration = mutableFileItemHeaders.getHeaders("TestHeader"); assertTrue(headerValueEnumeration.hasNext()); assertEquals(headerValueEnumeration.next(), "headerValue1"); assertTrue(headerValueEnumeration.hasNext()); assertEquals(headerValueEnumeration.next(), "headerValue2"); assertTrue(headerValueEnumeration.hasNext()); assertEquals(headerValueEnumeration.next(), "headerValue3"); assertTrue(headerValueEnumeration.hasNext()); assertEquals(headerValueEnumeration.next(), "headerValue4"); assertFalse(headerValueEnumeration.hasNext()); headerValueEnumeration = mutableFileItemHeaders.getHeaders("DummyHeader"); assertFalse(headerValueEnumeration.hasNext()); } } ././@LongLink0000644000000000000000000000020600000000000011601 Lustar rootrootlibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-core/src/test/java/org/apache/commons/fileupload2/core/DiskFileItemTest.javalibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-core/src/test/java/org/apache/commons/fileu0000644000175000017500000002311615142145735032120 0ustar zigozigo/* * 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 * * https://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.core; 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.assertSame; import java.io.IOException; import java.io.OutputStream; import java.io.UncheckedIOException; import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.util.function.Consumer; import java.util.function.IntConsumer; import org.apache.commons.fileupload2.core.DeferrableOutputStream.State; import org.apache.commons.fileupload2.core.FileItemFactory.AbstractFileItemBuilder; import org.junit.jupiter.api.Test; /** * Tests for {@link DiskFileItem}. */ class DiskFileItemTest { @SuppressWarnings("deprecation") protected void assertState(final DiskFileItem dfi, final State state, final boolean inMemory, final Path parentDir, String testString) throws IOException { final DeferrableOutputStream dos = (DeferrableOutputStream) dfi.getOutputStream(); assertEquals(state, dos.getState()); assertEquals(inMemory, dfi.isInMemory()); assertEquals(inMemory, dos.isInMemory()); if (parentDir == null) { assertNull(dos.getPath()); } else { assertNotNull(dos.getPath()); assertEquals(parentDir, dos.getPath().getParent()); } if (testString != null) { assertEquals(testString.length(), dfi.getSize()); assertEquals(testString.length(), dos.getSize()); assertEquals(testString, dfi.getString()); assertArrayEquals(testString.getBytes(), dfi.get()); } else { assertNull(dfi.get()); assertNull(dfi.getString()); } } @Test void testBuilderHeaders() { final var builder = DiskFileItem.builder(); assertNotNull(builder.getFileItemHeaders()); final var fileItem = builder.get(); assertNotNull(fileItem.getHeaders(), "Missing default headers (empty)"); assertFalse(fileItem.getHeaders().getHeaderNames().hasNext()); assertNotNull(fileItem.getHeaders()); final var fileItemHeaders = AbstractFileItemBuilder.newFileItemHeaders(); assertNotNull(fileItemHeaders); fileItem.setHeaders(fileItemHeaders); assertSame(fileItemHeaders, fileItem.getHeaders()); } /** * Test for FILEUPLOAD-29: * A {@link #DiskFileItem} with threshold 0 must always create a file, as soon as data comes in. */ @Test void testStateModelWithPositiveThreshold() { final IntConsumer tester = (numBytes) -> { try { final Path testDir = Paths.get("target/unit-tests/" + DiskFileItemTest.class.getSimpleName()); Files.createDirectories(testDir); final Path tempTestDir = Files.createTempDirectory(testDir, "testDir"); final DiskFileItemFactory dfif = DiskFileItemFactory.builder() .setThreshold(numBytes) .setPath(tempTestDir) .setCharset(StandardCharsets.UTF_8) .get(); assertEquals(numBytes, dfif.getThreshold()); final DiskFileItem dfi = dfif.fileItemBuilder() .get(); // Make sure, that the threshold has not been tampered with. assertEquals(numBytes, dfi.getThreshold()); // We haven't written any data. So, the output file is null. assertState(dfi, State.initialized, true, null, null); // Write some data. final StringBuilder sb = new StringBuilder(); try (OutputStream os = dfi.getOutputStream()) { for (int i = 0; i < numBytes-1; i++) { os.write('.'); sb.append('.'); assertState(dfi, State.opened, true, null, null); } /* * Write another byte. This should hit the threshold, * thus trigger persisting the in memory data. */ os.write(','); sb.append(','); assertState(dfi, State.persisted, false, tempTestDir, null); } // The output stream is closed now, so the state has changed again. assertState(dfi, State.closed, false, tempTestDir, sb.toString()); } catch (IOException ioe) { throw new UncheckedIOException(ioe); } }; tester.accept(5); tester.accept(8193); // Typical buffer size +1 } /** * Test for FILEUPLOAD-29: * A {@link #DiskFileItem} with threshold -1 must always create a (possibly empty) file. */ @Test void testStateModelWithThresholdMinusOne() { final Consumer tester = (ts) -> { try { final Path testDir = Paths.get("target/unit-tests/" + DiskFileItemTest.class.getSimpleName()); Files.createDirectories(testDir); final Path tempTestDir = Files.createTempDirectory(testDir, "testDir"); final DiskFileItemFactory dfif = DiskFileItemFactory.builder() .setBufferSize(-1) .setPath(tempTestDir) .setCharset(StandardCharsets.UTF_8) .get(); // Make sure, that the threshold has not been tampered with. assertEquals(-1, dfif.getThreshold()); final DiskFileItem dfi = dfif.fileItemBuilder() .get(); // Make sure, that the threshold has not been tampered with. assertEquals(-1, dfi.getThreshold()); // We haven't written any data. Yet, the output file already exists (threshold=-1) assertState(dfi, State.persisted, false, tempTestDir, null); try (OutputStream out = dfi.getOutputStream()) { out.write(ts.getBytes()); } // After writing some data, the output file does still exist, except that the size has changed. assertState(dfi, State.closed, false, tempTestDir, ts); } catch (IOException ioe) { throw new UncheckedIOException(ioe); } }; tester.accept("abcdef"); tester.accept("aAbBcCdDeEfF012345"); } /** * Test for FILEUPLOAD-29: * A {@link #DiskFileItem} with threshold 0 must always create a file, as soon as data comes in. */ @Test void testStateModelWithThresholdZero() { final IntConsumer tester = (numBytes) -> { try { final Path testDir = Paths.get("target/unit-tests/" + DiskFileItemTest.class.getSimpleName()); Files.createDirectories(testDir); final Path tempTestDir = Files.createTempDirectory(testDir, "testDir"); final DiskFileItemFactory dfif = DiskFileItemFactory.builder() .setBufferSize(0) .setPath(tempTestDir) .setCharset(StandardCharsets.UTF_8) .get(); assertEquals(0, dfif.getThreshold()); final DiskFileItem dfi = dfif.fileItemBuilder() .get(); // Make sure, that the threshold has not been tampered with. assertEquals(0, dfi.getThreshold()); // We haven't written any data. So, the output file is null. assertState(dfi, State.initialized, true, null, null); // Write some data. final StringBuilder sb = new StringBuilder(); try (OutputStream os = dfi.getOutputStream()) { for (int i = 0; i < numBytes; i++) { os.write('.'); sb.append('.'); assertState(dfi, State.persisted, false, tempTestDir, null); } os.write(','); sb.append(','); } // The output stream is closed now, so the state has changed again. assertState(dfi, State.closed, false, tempTestDir, sb.toString()); } catch (IOException ioe) { throw new UncheckedIOException(ioe); } }; tester.accept(5); tester.accept(8193); // Typical buffer size +1 } }././@LongLink0000644000000000000000000000022200000000000011577 Lustar rootrootlibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-core/src/test/java/org/apache/commons/fileupload2/core/AbstractProgressListenerTest.javalibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-core/src/test/java/org/apache/commons/fileu0000644000175000017500000001216615142145735032123 0ustar zigozigo/* * 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 * * https://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.core; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.nio.charset.StandardCharsets; import org.junit.jupiter.api.Test; /** * Tests the {@link ProgressListener}. * * @param The subclass of FileUpload. * @param The FileUpload request type. * @param The FileItem type. * @param The FileItemFactory type. */ public abstract class AbstractProgressListenerTest, R, I extends FileItem, F extends FileItemFactory> extends AbstractTest { protected static class ProgressListenerImpl implements ProgressListener { private final long expectedContentLength; private final int expectedItems; private Long bytesRead; private Integer items; ProgressListenerImpl(final long contentLength, final int itemCount) { expectedContentLength = contentLength; expectedItems = itemCount; } void checkFinished() { assertEquals(expectedContentLength, bytesRead.longValue()); assertEquals(expectedItems, items.intValue()); } @Override public void update(final long actualBytesRead, final long actualContentLength, final int actualItems) { assertTrue(actualBytesRead >= 0 && actualBytesRead <= expectedContentLength); assertTrue(actualContentLength == -1 || actualContentLength == expectedContentLength); assertTrue(actualItems >= 0 && actualItems <= expectedItems); assertTrue(bytesRead == null || actualBytesRead >= bytesRead.longValue()); bytesRead = Long.valueOf(actualBytesRead); assertTrue(items == null || actualItems >= items.intValue()); items = Integer.valueOf(actualItems); } } protected void runTest(final int itemCount, final long contentLength, final R request) throws FileUploadException, IOException { final var upload = newFileUpload(); final var listener = new ProgressListenerImpl(contentLength, itemCount); upload.setProgressListener(listener); final var iter = upload.getItemIterator(request); for (var i = 0; i < itemCount; i++) { final var idxI = i; final var fileItemInput = iter.next(); try (final var inputStream = fileItemInput.getInputStream()) { for (var j = 0; j < 16_384 + i; j++) { final var idxJ = j; // // This used to be assertEquals((byte) j, (byte) istream.read()); but this seems to trigger a bug in JRockit, so we express the same like // this: // final var b1 = (byte) j; final var b2 = (byte) inputStream.read(); assertEquals(b1, b2, () -> String.format("itemCount = %,d, i = %,d, j = %,d", itemCount, idxI, idxJ)); } assertEquals(-1, inputStream.read()); } } assertTrue(!iter.hasNext()); listener.checkFinished(); } /** * Parse a very long file upload by using a progress listener. * * @throws IOException Test failure. */ @Test void testProgressListener() throws IOException { final var numItems = 512; final var baos = new ByteArrayOutputStream(); for (var i = 0; i < numItems; i++) { final var header = "-----1234\r\n" + "Content-Disposition: form-data; name=\"field" + (i + 1) + "\"\r\n" + "\r\n"; baos.write(header.getBytes(StandardCharsets.US_ASCII)); for (var j = 0; j < 16384 + i; j++) { baos.write((byte) j); } baos.write("\r\n".getBytes(StandardCharsets.US_ASCII)); } baos.write("-----1234--\r\n".getBytes(StandardCharsets.US_ASCII)); final var requestBytes = baos.toByteArray(); var request = newMockHttpServletRequest(requestBytes, null, Constants.CONTENT_TYPE, null); runTest(numItems, requestBytes.length, request); request = newMockHttpServletRequest(requestBytes, -1L, Constants.CONTENT_TYPE, null); runTest(numItems, requestBytes.length, request); } } ././@LongLink0000644000000000000000000000021500000000000011601 Lustar rootrootlibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-core/src/test/java/org/apache/commons/fileupload2/core/DiskFileItemFactoryTest.javalibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-core/src/test/java/org/apache/commons/fileu0000644000175000017500000000354515142145735032124 0ustar zigozigo/* * 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 * * https://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.core; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertSame; import org.apache.commons.fileupload2.core.FileItemFactory.AbstractFileItemBuilder; import org.junit.jupiter.api.Test; /** * Tests for {@link DiskFileItem}. */ class DiskFileItemFactoryTest { @Test void testHeaders() { final var factory = DiskFileItemFactory.builder().get(); final var fileItemBuilder = factory.fileItemBuilder(); assertNotNull(fileItemBuilder.getFileItemHeaders()); final var fileItem = fileItemBuilder.get(); assertNotNull(fileItem.getHeaders(), "Missing default headers (empty)"); assertFalse(fileItem.getHeaders().getHeaderNames().hasNext()); final var fileItemHeaders = AbstractFileItemBuilder.newFileItemHeaders(); assertNotNull(fileItemHeaders); fileItem.setHeaders(fileItemHeaders); assertSame(fileItemHeaders, fileItem.getHeaders()); } } ././@LongLink0000644000000000000000000000021100000000000011575 Lustar rootrootlibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-core/src/test/java/org/apache/commons/fileupload2/core/ParameterParserTest.javalibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-core/src/test/java/org/apache/commons/fileu0000644000175000017500000001421715142145735032122 0ustar zigozigo/* * 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 * * https://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.core; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNull; import java.nio.charset.StandardCharsets; import org.junit.jupiter.api.Test; /** * Tests for {@link ParameterParser}. */ class ParameterParserTest { @Test void testContentTypeParsing() { final var s = "text/plain; Charset=UTF-8"; final var parser = new ParameterParser(); parser.setLowerCaseNames(true); final var params = parser.parse(s, ';'); assertEquals(StandardCharsets.UTF_8.name(), params.get("charset")); } // See: https://issues.apache.org/jira/browse/FILEUPLOAD-139 @Test void testFileUpload139() { final var parser = new ParameterParser(); var s = "Content-type: multipart/form-data , boundary=AaB03x"; var params = parser.parse(s, new char[] { ',', ';' }); assertEquals("AaB03x", params.get("boundary")); s = "Content-type: multipart/form-data, boundary=AaB03x"; params = parser.parse(s, new char[] { ';', ',' }); assertEquals("AaB03x", params.get("boundary")); s = "Content-type: multipart/mixed, boundary=BbC04y"; params = parser.parse(s, new char[] { ',', ';' }); assertEquals("BbC04y", params.get("boundary")); } /** * Test for FILEUPLOAD-199 */ @Test void testFileUpload199() { final var parser = new ParameterParser(); final var s = "Content-Disposition: form-data; name=\"file\"; filename=\"=?ISO-8859-" + "1?B?SWYgeW91IGNhbiByZWFkIHRoaXMgeW8=?= =?ISO-8859-2?B?dSB1bmRlcnN0YW5kIHRoZSBleGFtcGxlLg==?=\"\r\n"; final var params = parser.parse(s, new char[] { ',', ';' }); assertEquals("If you can read this you understand the example.", params.get("filename")); } /** * Test for FILEUPLOAD-274 */ @Test void testFileUpload274() { final var parser = new ParameterParser(); // Should parse a UTF-8 charset var s = "Content-Disposition: form-data; " + "name=\"file\"; filename*=UTF-8''%E3%81%93%E3%82%93%E3%81%AB%E3%81%A1%E3%81%AF\r\n"; var params = parser.parse(s, new char[] { ',', ';' }); assertEquals("\u3053\u3093\u306B\u3061\u306F", params.get("filename")); // filename = "こんにちは" in japanese // Should parse ISO-8859-1 charset s = "Content-Disposition: form-data; name=\"file\"; filename*=UTF-8''%70%C3%A2%74%C3%A9\r\n"; params = parser.parse(s, new char[] { ',', ';' }); assertEquals("\u0070\u00e2\u0074\u00e9", params.get("filename")); // filename = "pâté" in french // Should not decode if '*' is not at the end of param-name s = "Content-Disposition: form-data; name=\"file\"; file*name=UTF-8''%61%62%63\r\n"; params = parser.parse(s, new char[] { ',', ';' }); assertEquals("UTF-8''%61%62%63", params.get("file*name")); // Should not decode if param-value does not follow '' s = "Content-Disposition: form-data; name=\"file\"; filename*=a'bc\r\n"; params = parser.parse(s, new char[] { ',', ';' }); assertEquals("a'bc", params.get("filename")); // Should not decode if param-name doesn't have '*' at end s = "Content-Disposition: form-data; name=\"file\"; filename=a'b'c\r\n"; params = parser.parse(s, new char[] { ',', ';' }); assertEquals("a'b'c", params.get("filename")); } @Test void testParsing() { var s = "test; test1 = stuff ; test2 = \"stuff; stuff\"; test3=\"stuff"; final var parser = new ParameterParser(); var params = parser.parse(s, ';'); assertNull(params.get("test")); assertEquals("stuff", params.get("test1")); assertEquals("stuff; stuff", params.get("test2")); assertEquals("\"stuff", params.get("test3")); params = parser.parse(s, new char[] { ',', ';' }); assertNull(params.get("test")); assertEquals("stuff", params.get("test1")); assertEquals("stuff; stuff", params.get("test2")); assertEquals("\"stuff", params.get("test3")); s = " test , test1=stuff , , test2=, test3, "; params = parser.parse(s, ','); assertNull(params.get("test")); assertEquals("stuff", params.get("test1")); assertNull(params.get("test2")); assertNull(params.get("test3")); s = " test"; params = parser.parse(s, ';'); assertNull(params.get("test")); s = " "; params = parser.parse(s, ';'); assertEquals(0, params.size()); s = " = stuff "; params = parser.parse(s, ';'); assertEquals(0, params.size()); } @Test void testParsingEscapedChars() { var s = "param = \"stuff\\\"; more stuff\""; final var parser = new ParameterParser(); var params = parser.parse(s, ';'); assertEquals(1, params.size()); assertEquals("stuff\\\"; more stuff", params.get("param")); s = "param = \"stuff\\\\\"; anotherparam"; params = parser.parse(s, ';'); assertEquals(2, params.size()); assertEquals("stuff\\\\", params.get("param")); assertNull(params.get("anotherparam")); } } ././@LongLink0000644000000000000000000000021400000000000011600 Lustar rootrootlibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-core/src/test/java/org/apache/commons/fileupload2/core/RFC2231UtilityTestCase.javalibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-core/src/test/java/org/apache/commons/fileu0000644000175000017500000000644715142145735032130 0ustar zigozigo/* * 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 * * https://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.core; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.UnsupportedEncodingException; import org.junit.jupiter.api.Test; /** * The expected characters are encoded in UTF16, while the actual characters may be encoded in UTF-8/ISO-8859-1 * * RFC 5987 recommends to support both UTF-8 and ISO 8859-1. Test values are taken from https://tools.ietf.org/html/rfc5987#section-3.2.2 */ public final class RFC2231UtilityTestCase { private static void assertEncoded(final String expected, final String encoded) throws Exception { assertEquals(expected, RFC2231Utils.decodeText(encoded)); } @Test void testDecodeInvalidEncoding() throws Exception { assertThrows(UnsupportedEncodingException.class, () -> RFC2231Utils.decodeText("abc'en'hello")); } @Test void testDecodeIso88591() throws Exception { assertEncoded("\u00A3 rate", "iso-8859-1'en'%A3%20rate"); // "£ rate" } @Test void testDecodeUtf8() throws Exception { assertEncoded("\u00a3 \u0061\u006e\u0064 \u20ac \u0072\u0061\u0074\u0065\u0073", "UTF-8''%c2%a3%20and%20%e2%82%ac%20rates"); // "£ and € rates" } @Test void testHasEncodedValue() { final var nameWithAsteriskAtEnd = "paramname*"; assertTrue(RFC2231Utils.hasEncodedValue(nameWithAsteriskAtEnd)); final var nameWithAsteriskNotAtEnd = "param*name"; assertFalse(RFC2231Utils.hasEncodedValue(nameWithAsteriskNotAtEnd)); final var nameWithoutAsterisk = "paramname"; assertFalse(RFC2231Utils.hasEncodedValue(nameWithoutAsterisk)); } @Test void testNoNeedToDecode() throws Exception { assertEncoded("abc", "abc"); } @Test void testStripDelimiter() { final var nameWithAsteriskAtEnd = "paramname*"; assertEquals("paramname", RFC2231Utils.stripDelimiter(nameWithAsteriskAtEnd)); final var nameWithAsteriskNotAtEnd = "param*name"; assertEquals("param*name", RFC2231Utils.stripDelimiter(nameWithAsteriskNotAtEnd)); final var nameWithTwoAsterisks = "param*name*"; assertEquals("param*name", RFC2231Utils.stripDelimiter(nameWithTwoAsterisks)); final var nameWithoutAsterisk = "paramname"; assertEquals("paramname", RFC2231Utils.stripDelimiter(nameWithoutAsterisk)); } } ././@LongLink0000644000000000000000000000021400000000000011600 Lustar rootrootlibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-core/src/test/java/org/apache/commons/fileupload2/core/MockRequestContextTest.javalibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-core/src/test/java/org/apache/commons/fileu0000644000175000017500000001422015142145735032114 0ustar zigozigo/* * 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 * * https://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.core; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.InputStream; import java.nio.charset.StandardCharsets; import java.nio.charset.UnsupportedCharsetException; import java.util.function.Function; import java.util.function.LongSupplier; import org.junit.jupiter.api.Test; /** * Tests for {@link AbstractRequestContext} */ class MockRequestContextTest { private static final class MockRequestContext extends AbstractRequestContext { private final String characterEncoding; private final String contentType; private final InputStream inputStream; private MockRequestContext(final Function contentLengthString, final LongSupplier contentLengthDefault, final Object request, final String characterEncoding, final String contentType, final InputStream inputStream) { super(contentLengthString, contentLengthDefault, request); this.characterEncoding = characterEncoding; this.contentType = contentType; this.inputStream = inputStream; } /** * Gets the character encoding for the request. * * @return The character encoding for the request. */ @Override public String getCharacterEncoding() { return characterEncoding; } /** * Gets the content type of the request. * * @return The content type of the request. */ @Override public String getContentType() { return contentType; } /** * Gets the input stream for the request. * * @return The input stream for the request. */ @Override public InputStream getInputStream() { return inputStream; } } /** * Test if the given {@code character-encoding} is a valid CharEncoding */ @Test public void getCharset() { final RequestContext request = new MockRequestContext( x -> "1234", () -> 5678L, "Request", "US-ASCII", "text/plain", null); assertEquals(StandardCharsets.US_ASCII, request.getCharset()); } /** * Test if the {@code content-length} Value is numeric. */ @Test public void getContentLengthByParsing() { final RequestContext request = new MockRequestContext( x -> "1234", () -> 5678L, "Request", "US-ASCII", "text/plain", null); assertEquals(1234L, request.getContentLength()); } /** * Test if the {@code content-length} Value is not numeric * and the Default will be taken. */ @Test public void getContentLengthDefaultBecauseOfInvalidNumber() { final RequestContext request = new MockRequestContext( x -> "not-a-number", () -> 5678L, "Request", "US-ASCII", "text/plain", null); assertEquals(5678L, request.getContentLength()); } /** * Test if the given {@code character-encoding} is an invalid CharEncoding * and leads to {@link UnsupportedCharsetException} */ @Test public void getInvalidCharset() { final RequestContext request = new MockRequestContext( x -> "1234", () -> 5678L, "Request", "invalid-charset", "text/plain", null); assertThrows(UnsupportedCharsetException.class, request::getCharset); } /** * Test if the {@code content-type} is {@code multipart/related} */ @Test void testIsMultipartRelated() { final RequestContext request = new MockRequestContext( x -> "1234", () -> 5678L, "Request", "US-ASCII", "multipart/related; boundary=---1234; type=\"application/xop+xml\"; start-info=\"application/soap+xml\"", null); assertTrue(request.isMultipartRelated()); } /** * Test if the {@code content-type} is not {@code multipart/related} */ @Test void testIsNotMultipartRelated() { final RequestContext request = new MockRequestContext( x -> "1234", () -> 5678L, "Request", "US-ASCII", "text/plain", null); assertFalse(request.isMultipartRelated()); } /** * Test the {@code toString()} Output */ @Test void testToString() { final RequestContext request = new MockRequestContext( x -> "1234", () -> 5678L, "Request", "US-ASCII", "text/plain", null); assertEquals("MockRequestContext [ContentLength=1234, ContentType=text/plain]", request.toString()); } } libcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-core/src/main/0000755000175000017500000000000015142145735024427 5ustar zigozigolibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-core/src/main/java/0000755000175000017500000000000015142145735025350 5ustar zigozigolibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-core/src/main/java/org/0000755000175000017500000000000015142145735026137 5ustar zigozigolibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-core/src/main/java/org/apache/0000755000175000017500000000000015142145735027360 5ustar zigozigolibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-core/src/main/java/org/apache/commons/0000755000175000017500000000000015142145735031033 5ustar zigozigo././@LongLink0000644000000000000000000000015400000000000011603 Lustar rootrootlibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-core/src/main/java/org/apache/commons/fileupload2/libcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-core/src/main/java/org/apache/commons/fileu0000755000175000017500000000000015142145735032060 5ustar zigozigo././@LongLink0000644000000000000000000000016100000000000011601 Lustar rootrootlibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-core/src/main/java/org/apache/commons/fileupload2/core/libcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-core/src/main/java/org/apache/commons/fileu0000755000175000017500000000000015227714536032065 5ustar zigozigo././@LongLink0000644000000000000000000000021500000000000011601 Lustar rootrootlibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-core/src/main/java/org/apache/commons/fileupload2/core/FileUploadSizeException.javalibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-core/src/main/java/org/apache/commons/fileu0000644000175000017500000000411515142145735032063 0ustar zigozigo/* * 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 * * https://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.core; /** * Signals that a requests permitted size is exceeded. */ public class FileUploadSizeException extends FileUploadException { /** * Serial version UID, being used, if serialized. */ private static final long serialVersionUID = 2; /** * The actual size of the request. */ private final long actual; /** * The maximum permitted size of the request. */ private final long permitted; /** * Constructs an instance. * * @param message The detail message (which is saved for later retrieval by the {@link #getMessage()} method) * @param permitted The requests size limit. * @param actual The actual values for the request. */ public FileUploadSizeException(final String message, final long permitted, final long actual) { super(message); this.permitted = permitted; this.actual = actual; } /** * Gets the actual size of the request. * * @return The actual size of the request. */ public long getActualSize() { return actual; } /** * Gets the limit size of the request. * * @return The limit size of the request. */ public long getPermitted() { return permitted; } } ././@LongLink0000644000000000000000000000020700000000000011602 Lustar rootrootlibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-core/src/main/java/org/apache/commons/fileupload2/core/FileItemInputImpl.javalibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-core/src/main/java/org/apache/commons/fileu0000644000175000017500000001504015142145735032062 0ustar zigozigo/* * 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 * * https://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.core; import java.io.IOException; import java.io.InputStream; import java.nio.file.InvalidPathException; import org.apache.commons.io.input.BoundedInputStream; /** * Default implementation of {@link FileItemInput}. */ class FileItemInputImpl implements FileItemInput { /** * The File Item iterator implementation. * * @see FileItemInputIteratorImpl */ private final FileItemInputIteratorImpl fileItemInputIteratorImpl; /** * The file items content type. */ private final String contentType; /** * The file items field name. */ private final String fieldName; /** * The file items file name. */ private final String fileName; /** * Whether the file item is a form field. */ private final boolean formField; /** * The file items input stream. */ private final InputStream inputStream; /** * The file items input stream closed flag. */ private boolean inputStreamClosed; /** * The headers, if any. */ private FileItemHeaders headers; /** * Creates a new instance. * * @param fileItemIterator The {@link FileItemInputIteratorImpl iterator}, which returned this file item. * @param fileName The items file name, or null. * @param fieldName The items field name. * @param contentType The items content type, or null. * @param formField Whether the item is a form field. * @param contentLength The items content length, if known, or -1 * @throws IOException Creating the file item failed. * @throws FileUploadException Parsing the incoming data stream failed. */ FileItemInputImpl(final FileItemInputIteratorImpl fileItemIterator, final String fileName, final String fieldName, final String contentType, final boolean formField, final long contentLength) throws FileUploadException, IOException { this.fileItemInputIteratorImpl = fileItemIterator; this.fileName = fileName; this.fieldName = fieldName; this.contentType = contentType; this.formField = formField; final var fileSizeMax = fileItemInputIteratorImpl.getFileSizeMax(); if (fileSizeMax != -1 && contentLength != -1 && contentLength > fileSizeMax) { throw new FileUploadByteCountLimitException(String.format("The field %s exceeds its maximum permitted size of %s bytes.", fieldName, fileSizeMax), contentLength, fileSizeMax, fileName, fieldName); } // OK to construct stream now final var itemInputStream = fileItemInputIteratorImpl.getMultiPartInput().newInputStream(); InputStream istream = itemInputStream; if (fileSizeMax != -1) { // onMaxLength will be called when the length is greater than _or equal to_ the supplied maxLength. // Because we only want to throw an exception when the length is greater than fileSizeMax, we // increment fileSizeMax by 1. // @formatter:off istream = BoundedInputStream.builder() .setInputStream(istream) .setMaxCount(fileSizeMax + 1) .setOnMaxCount((max, count) -> { itemInputStream.close(true); throw new FileUploadByteCountLimitException( String.format("The field %s exceeds its maximum permitted size of %s bytes.", fieldName, fileSizeMax), count, fileSizeMax, fileName, fieldName); }) .get(); // @formatter:on } this.inputStream = istream; } /** * Closes the file item. * * @throws IOException An I/O error occurred. */ public void close() throws IOException { inputStream.close(); inputStreamClosed = true; } /** * Gets the content type, or null. * * @return Content type, if known, or null. */ @Override public String getContentType() { return contentType; } /** * Gets the items field name. * * @return Field name. */ @Override public String getFieldName() { return fieldName; } /** * Gets the headers. * * @return The items header object */ @Override public FileItemHeaders getHeaders() { return headers; } /** * Gets the input stream, which may be used to read the items contents. * * @return Opened input stream. * @throws IOException An I/O error occurred. */ @Override public InputStream getInputStream() throws IOException { if (inputStreamClosed) { throw new FileItemInput.ItemSkippedException("getInputStream()"); } return inputStream; } /** * Gets the file name. * * @return File name, if known, or null. * @throws InvalidPathException The file name is invalid, for example it contains a NUL character, which might be an indicator of a security attack. If you * intend to use the file name anyways, catch the exception and use InvalidPathException#getInput(). */ @Override public String getName() { return DiskFileItem.checkFileName(fileName); } /** * Tests whether this is a form field. * * @return True, if the item is a form field, otherwise false. */ @Override public boolean isFormField() { return formField; } /** * Sets the file item headers. * * @param headers The items header object */ @Override public FileItemInputImpl setHeaders(final FileItemHeaders headers) { this.headers = headers; return this; } } ././@LongLink0000644000000000000000000000020500000000000011600 Lustar rootrootlibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-core/src/main/java/org/apache/commons/fileupload2/core/ParameterParser.javalibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-core/src/main/java/org/apache/commons/fileu0000644000175000017500000002346515142145735032074 0ustar zigozigo/* * 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 * * https://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.core; import java.io.UnsupportedEncodingException; import java.util.HashMap; import java.util.Locale; import java.util.Map; /** * A simple parser intended to parse sequences of name/value pairs. *

* Parameter values are expected to be enclosed in quotes if they contain unsafe characters, such as '=' characters or separators. Parameter values are optional * and can be omitted. *

*

* {@code param1 = value; param2 = "anything goes; really"; param3} *

*/ public class ParameterParser { /** * String to be parsed. */ private char[] chars; /** * Current position in the string. */ private int pos; /** * Maximum position in the string. */ private int len; /** * Start of a token. */ private int i1; /** * End of a token. */ private int i2; /** * Whether names stored in the map should be converted to lower case. */ private boolean lowerCaseNames; /** * Default ParameterParser constructor. */ public ParameterParser() { } /** * A helper method to process the parsed token. This method removes leading and trailing blanks as well as enclosing quotation marks, when necessary. * * @param quoted {@code true} if quotation marks are expected, {@code false} otherwise. * @return the token */ private String getToken(final boolean quoted) { // Trim leading white spaces while (i1 < i2 && Character.isWhitespace(chars[i1])) { i1++; } // Trim trailing white spaces while (i2 > i1 && Character.isWhitespace(chars[i2 - 1])) { i2--; } // Strip away quotation marks if necessary if (quoted && i2 - i1 >= 2 && chars[i1] == '"' && chars[i2 - 1] == '"') { i1++; i2--; } String result = null; if (i2 > i1) { result = new String(chars, i1, i2 - i1); } return result; } /** * Tests if there any characters left to parse. * * @return {@code true} if there are unparsed characters, {@code false} otherwise. */ private boolean hasChar() { return this.pos < this.len; } /** * Tests {@code true} if parameter names are to be converted to lower case when name/value pairs are parsed. * * @return {@code true} if parameter names are to be converted to lower case when name/value pairs are parsed. Otherwise returns {@code false} */ public boolean isLowerCaseNames() { return this.lowerCaseNames; } /** * Tests if the given character is present in the array of characters. * * @param ch the character to test for presence in the array of characters * @param charray the array of characters to test against * @return {@code true} if the character is present in the array of characters, {@code false} otherwise. */ private boolean isOneOf(final char ch, final char[] charray) { var result = false; for (final char element : charray) { if (ch == element) { result = true; break; } } return result; } /** * Parses a map of name/value pairs from the given array of characters. Names are expected to be unique. * * @param charArray the array of characters that contains a sequence of name/value pairs * @param separator the name/value pairs separator * @return a map of name/value pairs */ public Map parse(final char[] charArray, final char separator) { if (charArray == null) { return new HashMap<>(); } return parse(charArray, 0, charArray.length, separator); } /** * Parses a map of name/value pairs from the given array of characters. Names are expected to be unique. * * @param charArray the array of characters that contains a sequence of name/value pairs * @param offset the initial offset. * @param length the length. * @param separator the name/value pairs separator * @return a map of name/value pairs */ public Map parse(final char[] charArray, final int offset, final int length, final char separator) { if (charArray == null) { return new HashMap<>(); } final var params = new HashMap(); this.chars = charArray.clone(); this.pos = offset; this.len = length; String paramName; String paramValue; while (hasChar()) { paramName = parseToken(new char[] { '=', separator }); paramValue = null; if (hasChar() && charArray[pos] == '=') { pos++; // skip '=' paramValue = parseQuotedToken(new char[] { separator }); if (paramValue != null) { try { paramValue = RFC2231Utils.hasEncodedValue(paramName) ? RFC2231Utils.decodeText(paramValue) : MimeUtils.decodeText(paramValue); } catch (final UnsupportedEncodingException ignored) { // let's keep the original value in this case } } } if (hasChar() && charArray[pos] == separator) { pos++; // skip separator } if (paramName != null && !paramName.isEmpty()) { paramName = RFC2231Utils.stripDelimiter(paramName); if (this.lowerCaseNames) { paramName = paramName.toLowerCase(Locale.ROOT); } params.put(paramName, paramValue); } } return params; } /** * Parses a map of name/value pairs from the given string. Names are expected to be unique. * * @param str the string that contains a sequence of name/value pairs * @param separator the name/value pairs separator * @return a map of name/value pairs */ public Map parse(final String str, final char separator) { if (str == null) { return new HashMap<>(); } return parse(str.toCharArray(), separator); } /** * Parses a map of name/value pairs from the given string. Names are expected to be unique. Multiple separators may be specified and the earliest found in * the input string is used. * * @param str the string that contains a sequence of name/value pairs * @param separators the name/value pairs separators * @return a map of name/value pairs */ public Map parse(final String str, final char[] separators) { if (separators == null || separators.length == 0) { return new HashMap<>(); } var separator = separators[0]; if (str != null) { var idx = str.length(); for (final char separator2 : separators) { final var tmp = str.indexOf(separator2); if (tmp != -1 && tmp < idx) { idx = tmp; separator = separator2; } } } return parse(str, separator); } /** * Parses out a token until any of the given terminators is encountered outside the quotation marks. * * @param terminators the array of terminating characters. Any of these characters when encountered outside the quotation marks signify the end of the token * @return the token */ private String parseQuotedToken(final char[] terminators) { char ch; i1 = pos; i2 = pos; var quoted = false; var charEscaped = false; while (hasChar()) { ch = chars[pos]; if (!quoted && isOneOf(ch, terminators)) { break; } if (!charEscaped && ch == '"') { quoted = !quoted; } charEscaped = !charEscaped && ch == '\\'; i2++; pos++; } return getToken(true); } /** * Parses out a token until any of the given terminators is encountered. * * @param terminators the array of terminating characters. Any of these characters when encountered signify the end of the token * @return the token */ private String parseToken(final char[] terminators) { char ch; i1 = pos; i2 = pos; while (hasChar()) { ch = chars[pos]; if (isOneOf(ch, terminators)) { break; } i2++; pos++; } return getToken(false); } /** * Sets the flag if parameter names are to be converted to lower case when name/value pairs are parsed. * * @param lowerCaseNames {@code true} if parameter names are to be converted to lower case when name/value pairs are parsed. {@code false} otherwise. */ public void setLowerCaseNames(final boolean lowerCaseNames) { this.lowerCaseNames = lowerCaseNames; } } ././@LongLink0000644000000000000000000000021400000000000011600 Lustar rootrootlibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-core/src/main/java/org/apache/commons/fileupload2/core/QuotedPrintableDecoder.javalibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-core/src/main/java/org/apache/commons/fileu0000644000175000017500000001013315142145735032060 0ustar zigozigo/* * 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 * * https://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.core; import java.io.IOException; import java.io.OutputStream; /** */ final class QuotedPrintableDecoder { /** * The shift value required to create the upper nibble from the first of 2 byte values converted from ASCII hex. */ private static final int UPPER_NIBBLE_SHIFT = Byte.SIZE / 2; /** * Decodes the encoded byte data writing it to the given output stream. * * @param data The array of byte data to decode. * @param out The output stream used to return the decoded data. * @return the number of bytes produced. * @throws IOException if an IO error occurs */ public static int decode(final byte[] data, final OutputStream out) throws IOException { var off = 0; final var length = data.length; final var endOffset = off + length; var bytesWritten = 0; while (off < endOffset) { final var ch = data[off++]; // space characters were translated to '_' on encode, so we need to translate them back. if (ch == '_') { out.write(' '); } else if (ch == '=') { // we found an encoded character. Reduce the 3 char sequence to one. // but first, make sure we have two characters to work with. if (off + 1 >= endOffset) { throw new IOException("Invalid quoted printable encoding; truncated escape sequence"); } final var b1 = data[off++]; final var b2 = data[off++]; // we've found an encoded carriage return. The next char needs to be a newline if (b1 == '\r') { if (b2 != '\n') { throw new IOException("Invalid quoted printable encoding; CR must be followed by LF"); } // this was a soft linebreak inserted by the encoding. We just toss this away // on decode. } else { // this is a hex pair we need to convert back to a single byte. final var c1 = hexToBinary(b1); final var c2 = hexToBinary(b2); out.write(c1 << UPPER_NIBBLE_SHIFT | c2); // 3 bytes in, one byte out bytesWritten++; } } else { // simple character, just write it out. out.write(ch); bytesWritten++; } } return bytesWritten; } /** * Converts a hexadecimal digit to the binary value it represents. * * @param b the ASCII hexadecimal byte to convert (0-0, A-F, a-f) * @return the int value of the hexadecimal byte, 0-15 * @throws IOException if the byte is not a valid hexadecimal digit. */ private static int hexToBinary(final byte b) throws IOException { // CHECKSTYLE IGNORE MagicNumber FOR NEXT 1 LINE final var i = Character.digit((char) b, 16); if (i == -1) { throw new IOException("Invalid quoted printable encoding: not a valid hex digit: " + b); } return i; } /** * Hidden constructor, this class must not be instantiated. */ private QuotedPrintableDecoder() { // do nothing } } ././@LongLink0000644000000000000000000000021000000000000011574 Lustar rootrootlibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-core/src/main/java/org/apache/commons/fileupload2/core/AbstractFileUpload.javalibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-core/src/main/java/org/apache/commons/fileu0000644000175000017500000005602115142145735032066 0ustar zigozigo/* * 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 * * https://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.core; import java.io.IOException; import java.nio.charset.Charset; 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; import java.util.Objects; import org.apache.commons.fileupload2.core.FileItemFactory.AbstractFileItemBuilder; import org.apache.commons.io.IOUtils; /** * High level API for processing file uploads. *

* This class handles multiple files per single HTML widget, sent using {@code multipart/mixed} encoding type, as specified by * RFC 1867. Use {@link #parseRequest(RequestContext)} to acquire a list of {@link FileItem}s associated with * a given HTML widget. *

*

* 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. *

* * @param The request context type. * @param The FileItem type. * @param the FileItemFactory type. */ public abstract class AbstractFileUpload, F extends FileItemFactory> { /** * Boundary parameter key. */ private static final String BOUNDARY_KEY = "boundary"; /** * Name parameter key. */ private static final String NAME_KEY = "name"; /** * File name parameter key. */ private static final String FILENAME_KEY = "filename"; /** * Constant for HTTP POST method. */ private static final String POST_METHOD = "POST"; /** * Constant for HTTP PUT method. */ private static final String PUT_METHOD = "PUT"; /** * Constant for HTTP PATCH method. */ private static final String PATCH_METHOD = "PATCH"; /** * HTTP content type header name. */ public static final String CONTENT_TYPE = "Content-type"; /** * HTTP content disposition header name. */ public static final String CONTENT_DISPOSITION = "Content-disposition"; /** * HTTP content length header name. */ public static final String CONTENT_LENGTH = "Content-length"; /** * Content-disposition value for form data. */ public static final String FORM_DATA = "form-data"; /** * Content-disposition value for file attachment. */ public static final String ATTACHMENT = "attachment"; /** * Part of HTTP content type header. */ public static final String MULTIPART = "multipart/"; /** * HTTP content type header for multipart forms. */ public static final String MULTIPART_FORM_DATA = "multipart/form-data"; /** * HTTP content type header for multiple uploads. */ public static final String MULTIPART_MIXED = "multipart/mixed"; /** * Utility method that determines whether the request contains multipart content. *

* NOTE: 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. *

* * @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 var contentType = ctx.getContentType(); if (contentType == null) { return false; } return contentType.toLowerCase(Locale.ROOT).startsWith(MULTIPART); } /** * Checks if a given request method is a valid multipart request method. * * @param method The request method verb. * @return {@code true} if the request method supports multipart request payloads; {@code false} otherwise. * @since 2.0.0-M5 */ protected static boolean isMultipartRequestMethod(final String method) { return POST_METHOD.equalsIgnoreCase(method) || PUT_METHOD.equalsIgnoreCase(method) || PATCH_METHOD.equalsIgnoreCase(method); } /** * The maximum size permitted for the complete request, as opposed to {@link #maxFileSize}. A value of -1 indicates no maximum. */ private long maxSize = -1; /** * The maximum size permitted for a single uploaded file, as opposed to {@link #maxSize}. A value of -1 indicates no maximum. */ private long maxFileSize = -1; /** * The maximum permitted number of files that may be uploaded in a single request. A value of -1 indicates no maximum. */ private long maxFileCount = -1; /** * The maximum permitted size of the headers provided with a single part in bytes. */ private int maxPartHeaderSize = MultipartInput.DEFAULT_PART_HEADER_SIZE_MAX; /** * The content encoding to use when reading part headers. */ private Charset headerCharset; /** * The progress listener. */ private ProgressListener progressListener = ProgressListener.NOP; /** * The factory to use to create new form items. */ private F fileItemFactory; /** * Constructs a new instance for subclasses. */ public AbstractFileUpload() { // empty } /** * Gets the boundary from the {@code Content-type} header. * * @param contentType The value of the content type header from which to extract the boundary value. * @return The boundary, as a byte array. */ public byte[] getBoundary(final String contentType) { final var parser = new ParameterParser(); parser.setLowerCaseNames(true); // Parameter parser can handle null input final var params = parser.parse(contentType, new char[] { ';', ',' }); final var boundaryStr = params.get(BOUNDARY_KEY); return boundaryStr != null ? boundaryStr.getBytes(StandardCharsets.ISO_8859_1) : null; } /** * Gets the field name from the {@code Content-disposition} header. * * @param headers A {@code Map} containing the HTTP request headers. * @return The field name for the current {@code encapsulation}. */ public String getFieldName(final FileItemHeaders headers) { return getFieldName(headers.getHeader(CONTENT_DISPOSITION)); } /** * Gets the field name, which is given by the content-disposition header. * * @param contentDisposition The content-dispositions header value. * @return The field name. */ private String getFieldName(final String contentDisposition) { String fieldName = null; if (contentDisposition != null && contentDisposition.toLowerCase(Locale.ROOT).startsWith(FORM_DATA)) { final var parser = new ParameterParser(); parser.setLowerCaseNames(true); // Parameter parser can handle null input final var params = parser.parse(contentDisposition, ';'); fieldName = params.get(NAME_KEY); if (fieldName != null) { fieldName = fieldName.trim(); } } return fieldName; } /** * Gets the factory class used when creating file items. * * @return The factory class for new file items. */ public F getFileItemFactory() { return fileItemFactory; } /** * Gets the file name from the {@code Content-disposition} header. * * @param headers The HTTP headers object. * @return The file name for the current {@code encapsulation}. */ public String getFileName(final FileItemHeaders headers) { return getFileName(headers.getHeader(CONTENT_DISPOSITION)); } /** * Gets the given content-disposition headers file name. * * @param contentDisposition The content-disposition headers value. * @return The file name */ private String getFileName(final String contentDisposition) { String fileName = null; if (contentDisposition != null) { final var cdl = contentDisposition.toLowerCase(Locale.ROOT); if (cdl.startsWith(FORM_DATA) || cdl.startsWith(ATTACHMENT)) { final var parser = new ParameterParser(); parser.setLowerCaseNames(true); // Parameter parser can handle null input final var params = parser.parse(contentDisposition, ';'); if (params.containsKey(FILENAME_KEY)) { fileName = params.get(FILENAME_KEY); if (fileName != null) { fileName = fileName.trim(); } else { // Even if there is no value, the parameter is present, // so we return an empty file name rather than no file // name. fileName = ""; } } } } return fileName; } /** * Gets the character encoding used when reading the headers of an individual part. When not specified, or {@code null}, the request encoding is used. If * that is also not specified, or {@code null}, the platform default encoding is used. * * @return The encoding used to read part headers. */ public Charset getHeaderCharset() { return headerCharset; } /** * Gets a file item iterator. * * @param request The servlet request to be parsed. * @return An iterator to instances of {@code FileItemInput} 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 abstract FileItemInputIterator getItemIterator(R request) throws FileUploadException, IOException; /** * Gets an RFC 1867 compliant {@code multipart/form-data} stream. * * @param requestContext The context for the request to be parsed. * @return An iterator to instances of {@code FileItemInput} 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 FileItemInputIterator getItemIterator(final RequestContext requestContext) throws FileUploadException, IOException { return new FileItemInputIteratorImpl(this, requestContext); } /** * Gets the maximum number of files allowed in a single request. * * @return The maximum number of files allowed in a single request. */ public long getMaxFileCount() { return maxFileCount; } /** * Gets the maximum allowed size of a single uploaded file, as opposed to {@link #getMaxSize()}. * * @see #setMaxFileSize(long) * @return Maximum size of a single uploaded file. */ public long getMaxFileSize() { return maxFileSize; } /** * Gets the per part size limit for headers. * * @return The maximum size of the headers for a single part in bytes. * * @since 2.0.0-M5 */ public int getMaxPartHeaderSize() { return maxPartHeaderSize; } /** * Gets the maximum allowed size of a complete request, as opposed to {@link #getMaxFileSize()}. * * @return The maximum allowed size, in bytes. The default value of -1 indicates, that there is no limit. * @see #setMaxSize(long) */ public long getMaxSize() { return maxSize; } /** * Parses the {@code header-part} and returns as key/value pairs. *

* If there are multiple headers of the same names, the name will map to a comma-separated list containing the values. *

* * @param headerPart The {@code header-part} of the current {@code encapsulation}. * @return A {@code Map} containing the parsed HTTP request headers. */ public FileItemHeaders getParsedHeaders(final String headerPart) { final var len = headerPart.length(); final var headers = newFileItemHeaders(); var start = 0; for (;;) { var end = parseEndOfLine(headerPart, start); if (start == end) { break; } final var header = new StringBuilder(headerPart.substring(start, end)); start = end + 2; while (start < len) { var nonWs = start; while (nonWs < len) { final var c = headerPart.charAt(nonWs); if (c != ' ' && c != '\t') { break; } ++nonWs; } if (nonWs == start) { break; } // Continuation line found end = parseEndOfLine(headerPart, nonWs); header.append(' ').append(headerPart, nonWs, end); start = end + 2; } parseHeaderLine(headers, header.toString()); } return headers; } /** * Gets the progress listener. * * @return The progress listener, if any, or null. */ public ProgressListener getProgressListener() { return progressListener; } /** * Creates a new instance of {@link FileItemHeaders}. * * @return The new instance. */ protected FileItemHeaders newFileItemHeaders() { return AbstractFileItemBuilder.newFileItemHeaders(); } /** * Skips bytes until the end of the current line. * * @param headerPart The headers, which are being parsed. * @param end Index of the last byte, which has yet been processed. * @return Index of the \r\n sequence, which indicates end of line. */ private int parseEndOfLine(final String headerPart, final int end) { var index = end; for (;;) { final var offset = headerPart.indexOf('\r', index); if (offset == -1 || offset + 1 >= headerPart.length()) { throw new IllegalStateException("Expected headers to be terminated by an empty line."); } if (headerPart.charAt(offset + 1) == '\n') { return offset; } index = offset + 1; } } /** * Parses the next header line. * * @param headers String with all headers. * @param header Map where to store the current header. */ private void parseHeaderLine(final FileItemHeaders headers, final String header) { final var colonOffset = header.indexOf(':'); if (colonOffset == -1) { // This header line is malformed, skip it. return; } final var headerName = header.substring(0, colonOffset).trim(); final var headerValue = header.substring(colonOffset + 1).trim(); headers.addHeader(headerName, headerValue); } /** * Parses an RFC 1867 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. */ public abstract Map> parseParameterMap(R request) throws FileUploadException; /** * Parses an RFC 1867 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. */ public Map> parseParameterMap(final RequestContext ctx) throws FileUploadException { final var items = parseRequest(ctx); final Map> itemsMap = new HashMap<>(items.size()); for (final I fileItem : items) { final var fieldName = fileItem.getFieldName(); final var mappedItems = itemsMap.computeIfAbsent(fieldName, k -> new ArrayList<>()); mappedItems.add(fileItem); } return itemsMap; } /** * Parses an RFC 1867 compliant {@code multipart/form-data} stream. * * @param request 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. */ public abstract List parseRequest(R request) throws FileUploadException; /** * Parses an RFC 1867 compliant {@code multipart/form-data} stream. * * @param requestContext The context for the 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. */ public List parseRequest(final RequestContext requestContext) throws FileUploadException { final List itemList = new ArrayList<>(); var successful = false; try { final var fileItemFactory = Objects.requireNonNull(getFileItemFactory(), "No FileItemFactory has been set."); final var buffer = new byte[IOUtils.DEFAULT_BUFFER_SIZE]; getItemIterator(requestContext).forEachRemaining(fileItemInput -> { final int size = itemList.size(); if (size == maxFileCount) { // The next item will exceed the limit. throw new FileUploadFileCountLimitException( String.format("Request '%s' failed: Maximum file count %,d exceeded.", MULTIPART_FORM_DATA, Long.valueOf(maxFileCount)), getMaxFileCount(), size); } // Don't use getName() here to prevent an InvalidFileNameException. // @formatter:off final var fileItem = fileItemFactory.fileItemBuilder() .setFieldName(fileItemInput.getFieldName()) .setContentType(fileItemInput.getContentType()) .setFormField(fileItemInput.isFormField()) .setFileName(fileItemInput.getName()) .setFileItemHeaders(fileItemInput.getHeaders()) .get(); // @formatter:on itemList.add(fileItem); try (var inputStream = fileItemInput.getInputStream(); var outputStream = fileItem.getOutputStream()) { IOUtils.copyLarge(inputStream, outputStream, buffer); } catch (final FileUploadException e) { throw e; } catch (final IOException e) { throw new FileUploadException(String.format("Request '%s' failed: %s", MULTIPART_FORM_DATA, e.getMessage()), e); } }); successful = true; return itemList; } catch (final FileUploadException e) { throw e; } catch (final IOException e) { throw new FileUploadException(e.getMessage(), e); } finally { if (!successful) { for (final I fileItem : itemList) { try { fileItem.delete(); } catch (final Exception ignored) { // ignored TODO perhaps add to tracker delete failure list somehow? } } } } } /** * Sets the factory class to use when creating file items. * * @param factory The factory class for new file items. */ public void setFileItemFactory(final F factory) { this.fileItemFactory = factory; } /** * Specifies the character encoding to be used when reading the headers of individual part. When not specified, or {@code null}, the request encoding is * used. If that is also not specified, or {@code null}, the platform default encoding is used. * * @param headerCharset The encoding used to read part headers. */ public void setHeaderCharset(final Charset headerCharset) { this.headerCharset = headerCharset; } /** * Sets the maximum number of files allowed per request. * * @param fileCountMax The new limit. {@code -1} means no limit. */ public void setMaxFileCount(final long fileCountMax) { this.maxFileCount = fileCountMax; } /** * Sets the maximum allowed size of a single uploaded file, as opposed to {@link #getMaxSize()}. * * @see #getMaxFileSize() * @param fileSizeMax Maximum size of a single uploaded file. */ public void setMaxFileSize(final long fileSizeMax) { this.maxFileSize = fileSizeMax; } /** * Sets the per part size limit for headers. * * @param partHeaderSizeMax The maximum size of the headers in bytes. * * @since 2.0.0-M5 */ public void setMaxPartHeaderSize(final int partHeaderSizeMax) { this.maxPartHeaderSize = partHeaderSizeMax; } /** * Sets the maximum allowed size of a complete request, as opposed to {@link #setMaxFileSize(long)}. * * @param sizeMax The maximum allowed size, in bytes. The default value of -1 indicates, that there is no limit. * @see #getMaxSize() */ public void setMaxSize(final long sizeMax) { this.maxSize = sizeMax; } /** * Sets the progress listener. * * @param progressListener The progress listener, if any. Defaults to null. */ public void setProgressListener(final ProgressListener progressListener) { this.progressListener = progressListener != null ? progressListener : ProgressListener.NOP; } } ././@LongLink0000644000000000000000000000021400000000000011600 Lustar rootrootlibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-core/src/main/java/org/apache/commons/fileupload2/core/DeferrableOutputStream.javalibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-core/src/main/java/org/apache/commons/fileu0000644000175000017500000003712415142145735032071 0ustar zigozigo/* * 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 * * https://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.core; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.nio.file.Files; import java.nio.file.Path; import java.util.function.Supplier; /** * An {@link OutputStream}, which keeps its data in memory, until a configured * threshold is reached. If that is the case, a temporary file is being created, * and the in-memory data is transferred to that file. All following data will * be written to that file, too. * * In other words: If an uploaded file is small, then it will be kept completely * in memory. On the other hand, if the uploaded file's size exceeds the * configured threshold, it it considered a large file, and the data is kept * in a temporary file. * * More precisely, this output stream supports three modes of operation: *
    *
  1. {@code threshold=-1}: Always create a temporary file, even if * the uploaded file is empty.
  2. *
  3. {@code threshold=0}: Don't create empty, temporary files. (Create a * temporary file, as soon as the first byte is written.)
  4. *
  5. {@code threshold>0}: Create a temporary file, if the size exceeds the * threshold, otherwise keep the file in memory.
  6. *
* * Technically, this is similar to * {@link org.apache.commons.io.output.DeferredFileOutputStream}, which has * been used in the past, except that this implementation observes * a precisely specified behavior, and semantics, that match the needs of the * {@link DiskFileItem}. * * Background: Over the various versions of commons-io, the * {@link org.apache.commons.io.output.DeferredFileOutputStream} has changed * semantics, and behavior more than once. * (For details, see * FILEUPLOAD-295) */ public class DeferrableOutputStream extends OutputStream { /** * Interface of a listener object, that wishes to be notified about * state changes. */ public interface Listener { /** * Called, after {@link #persist()} has been invoked, * and the temporary file has been created. * @param path Path of the temporary file, that has been * created. All in-memory data has been transferred to * that file, but it is still opened. */ default void persisted(final Path path) { } } /** * This enumeration represents the possible states of the {@link DeferrableOutputStream}. */ public enum State { /** * The stream object has been created with a non-negative threshold, * but so far no data has been written. */ initialized, /** * The stream object has been created with a non-negative threshold, * and some data has been written, but the threshold is not yet exceeded, * and the data is still kept in memory. */ opened, /** * Either of the following conditions is given: *
    *
  1. The stream object has been created with a threshold of -1, or
  2. *
  3. the stream object has been created with a non-negative threshold, * and some data has been written. The number of bytes, that have * been written, exceeds the configured threshold.
  4. *
* In either case, a temporary file has been created, and all data has been * written to the temporary file, erasing all existing data from memory. */ persisted, /** * The stream has been closed, and data can no longer be written. It is * now valid to invoke {@link DeferrableOutputStream#getInputStream()}. */ closed } /** * The configured threshold, as an integer. This variable isn't actually * used. Instead {@link #longThreshold} is used. * @see #longThreshold */ private final int threshold; /** * The configured threshold, as a long integer. (Using a long integer * enables proper handling of the threshold, when the file size is * approaching {@link Integer#MAX_VALUE}. * @see #threshold */ private final long longThreshold; /** * This supplier will be invoked, if the temporary file is created, * t * determine the temporary file's location. * @see #path */ private final Supplier pathSupplier; /** * If a temporary file has been created: Path of the temporary * file. Otherwise null. * @see #pathSupplier */ private Path path; /** * If no temporary file was created: A stream, to which the * incoming data is being written, until the threshold is reached. * Otherwise null. */ private ByteArrayOutputStream baos; /** * If no temporary file was created, and the stream is closed: * The in-memory data, that was written to the stream. Otherwise null. */ private byte[] bytes; /** * If a temporary file has been created: An open stream * for writing to that file. Otherwise null. */ private OutputStream out; /** * The streams current state. */ private State state; /** * True, if the stream has ever been in state {@link State#persisted}. * Or, in other words: True, if a temporary file has been created. */ private boolean wasPersisted; /** * Number of bytes, that have been written to this stream so far. */ private long size; /** * The configured {@link Listener}, if any, or null. */ private final Listener listener; /** * Creates a new instance with the given threshold, and the given supplier for a * temporary files path. * If the threshold is -1, then the temporary file will be created immediately, and * no in-memory data will be kept, at all. * If the threshold is 0, then the temporary file will be created, as soon as the * first byte will be written, but no in-memory data will be kept. * If the threshold is > 0, then the temporary file will be created, as soon as that * number of bytes have been written. Up to that point, data will be kept in an * in-memory buffer. * * @param threshold Either of -1 (Create the temporary file immediately), 0 (Create * the temporary file, as soon as data is being written for the first time), or >0 * (Keep data in memory, as long as the given number of bytes is reached, then * create a temporary file, and continue using that). * @param pathSupplier A supplier for the temporary files path. This supplier must * not return null. The file's directory will be created, if necessary, by * invoking {@link Files#createDirectories(Path, java.nio.file.attribute.FileAttribute...)}. * @param listener An optional listener, which is being notified about important state * changes. * @throws IOException Creating the temporary file (in the case of threshold -1) * has failed. */ public DeferrableOutputStream(final int threshold, final Supplier pathSupplier, final Listener listener) throws IOException { if (threshold < 0) { this.threshold = -1; } else { this.threshold = threshold; } longThreshold = (long) threshold; this.pathSupplier = pathSupplier; this.listener = listener; checkThreshold(0); } /** * Called to check, whether the threshold will be exceeded, if the given number * of bytes are written to the stream. If so, persists the in-memory data by * creating a new, temporary file, and writing the in-memory data to the file. * @param numberOfIncomingBytes The number of bytes, which are about to be written. * @return The actual output stream, to which the incoming data may be written. * If the threshold is not yet exceeded, then this will be an internal * {@link ByteArrayOutputStream}, otherwise a stream, which is writing to the * temporary output file. * @throws IOException Persisting the in-memory data to a temporary file * has failed. */ protected OutputStream checkThreshold(final int numberOfIncomingBytes) throws IOException { if (state == null) { // Called from the constructor, state is unspecified. if (threshold == -1) { return persist(); } else { baos = new ByteArrayOutputStream(); bytes = null; state = State.initialized; return baos; } } else { switch (state) { case initialized: case opened: final int bytesWritten = baos.size(); if ((long) bytesWritten + (long) numberOfIncomingBytes >= longThreshold) { return persist(); } if (numberOfIncomingBytes > 0) { state = State.opened; } return baos; case persisted: // Do nothing, we're staying in the current state. return out; case closed: // Do nothing, we're staying in the current state. return null; default: throw illegalStateError(); } } } @Override public void close() throws IOException { switch (state) { case initialized: case opened: bytes = baos.toByteArray(); baos = null; state = State.closed; break; case persisted: bytes = null; out.close(); state = State.closed; break; case closed: // Already closed, do nothing. break; default: throw illegalStateError(); } } /** * Returns the data, that has been written, if the stream has * been closed, and the stream is still in memory * ({@link #isInMemory()} returns true). Otherwise, returns null. * @return If the stream is closed (no more data can be written), * and the data is still in memory (no temporary file has been * created), returns the data, that has been written. Otherwise, * returns null. */ public byte[] getBytes() { return bytes; } /** * If the stream is closed: Returns an {@link InputStream} on the * data, that has been written to this stream. Otherwise, throws * an {@link IllegalStateException}. * @return An {@link InputStream} on the data, that has been * written. Never null. * @throws IllegalStateException The stream has not yet been * closed. * @throws IOException Creating the {@link InputStream} has * failed. */ public InputStream getInputStream() throws IOException { if (state == State.closed) { if (bytes != null) { return new ByteArrayInputStream(bytes); } else { return Files.newInputStream(path); } } else { throw new IllegalStateException("This stream isn't yet closed."); } } /** * Returns the output file, that has been created, if any, or null. * The latter is the case, if {@link #isInMemory()} returns true. * @return The output file, that has been created, if any, or null. */ public Path getPath() { return path; } /** * Returns the number of bytes, that have been written to this stream. * @return The number of bytes, that have been written to this stream. */ public long getSize() { return size; } /** * Returns the streams current state. * @return The streams current state. */ public State getState() { return state; } /** * Returns the streams configured threshold. * @return The streams configured threshold. */ public int getThreshold() { return threshold; } /** * Returns the path of the output file, if such a file has * been created. That is the case, if {@link #isInMemory()} * returns false. Otherwise, returns null. * @return Path of the created output file, if any, or null. */ private IllegalStateException illegalStateError() { throw new IllegalStateException("Expected state initialized|opened|persisted|closed, got " + state.name()); } /** * Returns true, if this stream was never persisted, * and no output file has been created. * @return True, if the stream was never in state * {@link State#persisted}, otherwise false. */ public boolean isInMemory() { switch (state) { case initialized: case opened: return true; case persisted: return false; case closed: return !wasPersisted; default: throw illegalStateError(); } } /** * Create the output file, change the state to {@code persisted}, and * return an {@link OutputStream}, which is writing to that file. * @return The {@link OutputStream}, which is writing to the created, * temporary file. * @throws IOException Creating the temporary file has failed. */ protected OutputStream persist() throws IOException { final Path p = pathSupplier.get(); final Path dir = p.getParent(); if (dir != null) { Files.createDirectories(dir); } final OutputStream os = Files.newOutputStream(p); if (baos != null) { baos.writeTo(os); } /** * At this point, the output file has been successfully created, * and we can safely switch state. */ state = State.persisted; wasPersisted = true; path = p; out = os; baos = null; bytes = null; if (listener != null) { listener.persisted(p); } return os; } @Override public void write(final byte[] buffer) throws IOException { write(buffer, 0, buffer.length); } @Override public void write(final byte[] buffer, final int offset, final int len) throws IOException { if (len > 0) { final OutputStream os = checkThreshold(len); if (os == null) { throw new IOException("This stream has already been closed."); } bytes = null; os.write(buffer, offset, len); size += len; } } @Override public void write(final int b) throws IOException { final OutputStream os = checkThreshold(1); if (os == null) { throw new IOException("This stream has already been closed."); } bytes = null; os.write(b); size++; } } ././@LongLink0000644000000000000000000000021700000000000011603 Lustar rootrootlibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-core/src/main/java/org/apache/commons/fileupload2/core/FileItemInputIteratorImpl.javalibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-core/src/main/java/org/apache/commons/fileu0000644000175000017500000003153415142145735032070 0ustar zigozigo/* * 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 * * https://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.core; import java.io.IOException; import java.io.InputStream; import java.util.Iterator; import java.util.Locale; import java.util.NoSuchElementException; import java.util.Objects; import org.apache.commons.fileupload2.core.MultipartInput.FileUploadBoundaryException; import org.apache.commons.io.Charsets; import org.apache.commons.io.IOUtils; import org.apache.commons.io.input.BoundedInputStream; /** * The iterator returned by {@link AbstractFileUpload#getItemIterator(RequestContext)}. */ class FileItemInputIteratorImpl implements FileItemInputIterator { /** * The file uploads processing utility. * * @see AbstractFileUpload */ private final AbstractFileUpload fileUpload; /** * The request context. * * @see RequestContext */ private final RequestContext requestContext; /** * The maximum allowed size of a complete request. */ private long sizeMax; /** * The maximum allowed size of a single uploaded file. */ private long fileSizeMax; /** * The multi part stream to process. */ private MultipartInput multiPartInput; /** * The notifier, which used for triggering the {@link ProgressListener}. */ private MultipartInput.ProgressNotifier progressNotifier; /** * The boundary, which separates the various parts. */ private byte[] multiPartBoundary; /** * The item, which we currently process. */ private FileItemInputImpl currentItem; /** * The current items field name. */ private String currentFieldName; /** * Whether we are currently skipping the preamble. */ private boolean skipPreamble; /** * Whether the current item may still be read. */ private boolean itemValid; /** * Whether we have seen the end of the file. */ private boolean eof; /** * Is the Request of type {@code multipart/related}. */ private final boolean multipartRelated; /** * Constructs a new instance. * * @param fileUploadBase Main processor. * @param requestContext The request context. * @throws FileUploadException An error occurred while parsing the request. * @throws IOException An I/O error occurred. */ FileItemInputIteratorImpl(final AbstractFileUpload fileUploadBase, final RequestContext requestContext) throws FileUploadException, IOException { this.fileUpload = fileUploadBase; this.sizeMax = fileUploadBase.getMaxSize(); this.fileSizeMax = fileUploadBase.getMaxFileSize(); this.requestContext = Objects.requireNonNull(requestContext, "requestContext"); this.multipartRelated = this.requestContext.isMultipartRelated(); this.skipPreamble = true; findNextItem(); } /** * Finds the next item, if any. * * @return True, if an next item was found, otherwise false. * @throws IOException An I/O error occurred. */ private boolean findNextItem() throws FileUploadException, IOException { if (eof) { return false; } if (currentItem != null) { currentItem.close(); currentItem = null; } final var multi = getMultiPartInput(); for (;;) { final boolean nextPart; if (skipPreamble) { nextPart = multi.skipPreamble(); } else { nextPart = multi.readBoundary(); } if (!nextPart) { if (currentFieldName == null) { // Outer multipart terminated -> No more data eof = true; return false; } // Inner multipart terminated -> Return to parsing the outer multi.setBoundary(multiPartBoundary); currentFieldName = null; continue; } final var headers = fileUpload.getParsedHeaders(multi.readHeaders()); if (multipartRelated) { currentFieldName = ""; currentItem = new FileItemInputImpl( this, null, null, headers.getHeader(AbstractFileUpload.CONTENT_TYPE), false, getContentLength(headers)); currentItem.setHeaders(headers); progressNotifier.noteItem(); itemValid = true; return true; } if (currentFieldName == null) { // We're parsing the outer multipart final var fieldName = fileUpload.getFieldName(headers); if (fieldName != null) { final var subContentType = headers.getHeader(AbstractFileUpload.CONTENT_TYPE); if (subContentType != null && subContentType.toLowerCase(Locale.ROOT).startsWith(AbstractFileUpload.MULTIPART_MIXED)) { currentFieldName = fieldName; // Multiple files associated with this field name final var subBoundary = fileUpload.getBoundary(subContentType); if (subBoundary == null) { throw new FileUploadBoundaryException("The request was rejected because no boundary token was defined for a multipart/mixed part"); } multi.setBoundary(subBoundary); skipPreamble = true; continue; } final var fileName = fileUpload.getFileName(headers); currentItem = new FileItemInputImpl(this, fileName, fieldName, headers.getHeader(AbstractFileUpload.CONTENT_TYPE), fileName == null, getContentLength(headers)); currentItem.setHeaders(headers); progressNotifier.noteItem(); itemValid = true; return true; } } else { final var fileName = fileUpload.getFileName(headers); if (fileName != null) { currentItem = new FileItemInputImpl(this, fileName, currentFieldName, headers.getHeader(AbstractFileUpload.CONTENT_TYPE), false, getContentLength(headers)); currentItem.setHeaders(headers); progressNotifier.noteItem(); itemValid = true; return true; } } multi.discardBodyData(); } } private long getContentLength(final FileItemHeaders headers) { try { return Long.parseLong(headers.getHeader(AbstractFileUpload.CONTENT_LENGTH)); } catch (final Exception e) { return -1; } } @Override public long getFileSizeMax() { return fileSizeMax; } public MultipartInput getMultiPartInput() throws FileUploadException, IOException { if (multiPartInput == null) { init(fileUpload, requestContext); } return multiPartInput; } @Override public long getSizeMax() { return sizeMax; } /** * Tests whether another instance of {@link FileItemInput} is available. * * @throws FileUploadException Parsing or processing the file item failed. * @throws IOException Reading the file item failed. * @return True, if one or more additional file items are available, otherwise false. */ @Override public boolean hasNext() throws IOException { if (eof) { return false; } if (itemValid) { return true; } return findNextItem(); } protected void init(final AbstractFileUpload fileUploadBase, final RequestContext initContext) throws FileUploadException, IOException { final var contentType = requestContext.getContentType(); if (null == contentType || !contentType.toLowerCase(Locale.ROOT).startsWith(AbstractFileUpload.MULTIPART)) { throw new FileUploadContentTypeException(String.format("the request doesn't contain a %s or %s stream, content type header is %s", AbstractFileUpload.MULTIPART_FORM_DATA, AbstractFileUpload.MULTIPART_MIXED, contentType), contentType); } final var contentLengthInt = requestContext.getContentLength(); // @formatter:off final var requestSize = RequestContext.class.isAssignableFrom(requestContext.getClass()) // Inline conditional is OK here CHECKSTYLE:OFF ? requestContext.getContentLength() : contentLengthInt; // CHECKSTYLE:ON // @formatter:on final InputStream inputStream; // This is eventually closed in MultipartInput processing if (sizeMax >= 0) { if (requestSize != -1 && requestSize > sizeMax) { throw new FileUploadSizeException( String.format("the request was rejected because its size (%s) exceeds the configured maximum (%s)", requestSize, sizeMax), sizeMax, requestSize); } // This is eventually closed in MultipartInput processing // @formatter:off inputStream = BoundedInputStream.builder() .setInputStream(requestContext.getInputStream()) .setMaxCount(sizeMax) .setOnMaxCount((max, count) -> { throw new FileUploadSizeException( String.format("The request was rejected because its size (%s) exceeds the configured maximum (%s)", count, max), max, count); }) .get(); // @formatter:on } else { inputStream = requestContext.getInputStream(); } final var charset = Charsets.toCharset(fileUploadBase.getHeaderCharset(), requestContext.getCharset()); multiPartBoundary = fileUploadBase.getBoundary(contentType); if (multiPartBoundary == null) { IOUtils.closeQuietly(inputStream); // avoid possible resource leak throw new FileUploadException("the request was rejected because no multipart boundary was found"); } progressNotifier = new MultipartInput.ProgressNotifier(fileUploadBase.getProgressListener(), requestSize); try { multiPartInput = MultipartInput.builder() .setInputStream(inputStream) .setBoundary(multiPartBoundary) .setProgressNotifier(progressNotifier) .setMaxPartHeaderSize(fileUploadBase.getMaxPartHeaderSize()) .get(); } catch (final IllegalArgumentException e) { IOUtils.closeQuietly(inputStream); // avoid possible resource leak throw new FileUploadContentTypeException(String.format("The boundary specified in the %s header is too long", AbstractFileUpload.CONTENT_TYPE), e); } multiPartInput.setHeaderCharset(charset); } /** * Returns the next available {@link FileItemInput}. * * @throws java.util.NoSuchElementException No more items are available. Use {@link #hasNext()} to prevent this exception. * @throws FileUploadException Parsing or processing the file item failed. * @throws IOException Reading the file item failed. * @return FileItemInput instance, which provides access to the next file item. */ @Override public FileItemInput next() throws IOException { if (eof || !itemValid && !hasNext()) { throw new NoSuchElementException(); } itemValid = false; return currentItem; } @Override public void setFileSizeMax(final long fileSizeMax) { this.fileSizeMax = fileSizeMax; } @Override public void setSizeMax(final long sizeMax) { this.sizeMax = sizeMax; } @Override public Iterator unwrap() { // TODO Something better? return (Iterator) this; } } ././@LongLink0000644000000000000000000000020200000000000011575 Lustar rootrootlibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-core/src/main/java/org/apache/commons/fileupload2/core/package-info.javalibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-core/src/main/java/org/apache/commons/fileu0000644000175000017500000000733315142145735032070 0ustar zigozigo/* * 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 * * https://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. */ /** *

* A component for handling HTML file uploads as specified by RFC 1867. This component * provides support for uploads within both servlets (JSR 53) and portlets (JSR 168). *

*

* While this package provides the generic functionality for file uploads, these classes are not typically used directly. Instead, normal usage involves one of * the provided extensions of {@link org.apache.commons.fileupload2.core.AbstractFileUpload} such as * {@code org.apache.commons.fileupload2.core.servlet.ServletFileUpload ServletFileUpload} or * {@code org.apache.commons.fileupload2.core.portlet.PortletFileUpload PortletFileUpload}, together with a factory for * {@link org.apache.commons.fileupload2.core.FileItem} instances, such as {@link org.apache.commons.fileupload2.core.DiskFileItemFactory}. *

*

* The following is a brief example of typical usage in a servlet, storing the uploaded files on disk. *

* *
{@code
 * public void doPost(HttpServletRequest req, HttpServletResponse res) {
 *   DiskFileItemFactory factory = new DiskFileItemFactory.builder()
 *     // maximum size that will be stored in memory
 *     .setSizeThreshold(4096);
 *     // the location for saving data that is larger than getSizeThreshold()
 *     .setPath(Paths.get("/tmp"))
 *     // build it
 *     .get();
 *
 *   ServletFileUpload upload = new ServletFileUpload(factory);
 *   // maximum size before a FileUploadException will be thrown
 *   upload.setSizeMax(1000000);
 *
 *   List fileItems = upload.parseRequest(req);
 *   // assume we know there are two files. The first file is a small
 *   // text file, the second is unknown and is written to a file on
 *   // the server
 *   Iterator i = fileItems.iterator();
 *   String comment = ((FileItem)i.next()).getString();
 *   FileItem fi = (FileItem)i.next();
 *   // file name on the client
 *   String fileName = fi.getName();
 *   // save comment and file name to database
 *   ...
 *   // write the file
 *   fi.write(new File("/www/uploads/", fileName));
 * }
 * }
*

* In the example above, the first file is loaded into memory as a {@code String}. Before calling the {@code getString} method, the data may have been in memory * or on disk depending on its size. The second file we assume it will be large and therefore never explicitly load it into memory, though if it is less than * 4096 bytes it will be in memory before it is written to its final location. When writing to the final location, if the data is larger than the threshold, an * attempt is made to rename the temporary file to the given location. If it cannot be renamed, it is streamed to the new location. *

*

* Please see the FileUpload User Guide for further details and examples of how to * use this package. *

*/ package org.apache.commons.fileupload2.core; ././@LongLink0000644000000000000000000000021500000000000011601 Lustar rootrootlibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-core/src/main/java/org/apache/commons/fileupload2/core/FileItemHeadersProvider.javalibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-core/src/main/java/org/apache/commons/fileu0000644000175000017500000000320215142145735032057 0ustar zigozigo/* * 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 * * https://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.core; /** * Provides access to headers. * * @param The FileItemHeadersProvider type. * @see FileItem * @see FileItemInput */ public interface FileItemHeadersProvider> { /** * Gets the collection of headers defined locally within this item. * * @return the {@link FileItemHeaders} present for this item. */ FileItemHeaders getHeaders(); /** * Sets the headers read from within an item. Implementations of {@link FileItem} or {@link FileItemInput} should implement this interface to be able to get * the raw headers found within the item header block. * * @param headers the instance that holds onto the headers for this instance. * @return {@code this} instance. */ T setHeaders(FileItemHeaders headers); } ././@LongLink0000644000000000000000000000020300000000000011576 Lustar rootrootlibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-core/src/main/java/org/apache/commons/fileupload2/core/FileItemInput.javalibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-core/src/main/java/org/apache/commons/fileu0000644000175000017500000000766115142145735032074 0ustar zigozigo/* * 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 * * https://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.core; import java.io.IOException; import java.io.InputStream; /** * Provides access to a file or form item that was received within a {@code multipart/form-data} POST request. *

* The items contents are retrieved by calling {@link #getInputStream()}. *

*

* Instances of this class are created by accessing the iterator, returned by {@link AbstractFileUpload#getItemIterator(RequestContext)}. *

*

* Note: There is an interaction between the iterator and its associated instances of {@link FileItemInput}: By invoking * {@link java.util.Iterator#hasNext()} on the iterator, you discard all data, which hasn't been read so far from the previous data. *

*/ public interface FileItemInput extends FileItemHeadersProvider { /** * This exception is thrown, if an attempt is made to read data from the {@link InputStream}, which has been returned by * {@link FileItemInput#getInputStream()}, after {@link java.util.Iterator#hasNext()} has been invoked on the iterator, which created the * {@link FileItemInput}. */ class ItemSkippedException extends FileUploadException { /** * The exceptions serial version UID, which is being used when serializing an exception instance. */ private static final long serialVersionUID = 2; /** * Constructs an instance with a given detail message. * * @param message The detail message (which is saved for later retrieval by the {@link #getMessage()} method) */ ItemSkippedException(final String message) { super(message); } } /** * Gets the content type passed by the browser or {@code null} if not defined. * * @return The content type passed by the browser or {@code null} if not defined. */ String getContentType(); /** * Gets the name of the field in the multipart form corresponding to this file item. * * @return The name of the form field. */ String getFieldName(); /** * Opens an {@link InputStream}, which allows to read the items contents. * * @return The input stream, from which the items data may be read. * @throws IllegalStateException The method was already invoked on this item. It is not possible to recreate the data stream. * @throws IOException An I/O error occurred. * @see ItemSkippedException */ InputStream getInputStream() throws IOException; /** * Gets the original file name in the client's file system, as provided by the browser (or other client software). In most cases, this will be the base file * name, without path information. However, some clients, such as the Opera browser, do include path information. * * @return The original file name in the client's file system. */ String getName(); /** * Tests whether or not a {@code FileItem} instance represents a simple form field. * * @return {@code true} if the instance represents a simple form field; {@code false} if it represents an uploaded file. */ boolean isFormField(); } ././@LongLink0000644000000000000000000000020200000000000011575 Lustar rootrootlibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-core/src/main/java/org/apache/commons/fileupload2/core/RFC2231Utils.javalibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-core/src/main/java/org/apache/commons/fileu0000644000175000017500000001357515142145735032075 0ustar zigozigo/* * 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 * * https://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.core; import java.io.ByteArrayOutputStream; import java.io.UnsupportedEncodingException; /** * Utility class to decode/encode character set on HTTP Header fields based on RFC 2231. This implementation adheres to RFC 5987 in particular, which was * defined for HTTP headers *

* RFC 5987 builds on RFC 2231, but has lesser scope like mandatory charset definition and * no parameter continuation *

* * @see RFC 2231 * @see RFC 5987 */ final class RFC2231Utils { /** * The Hexadecimal values char array. */ private static final char[] HEX_DIGITS = "0123456789ABCDEF".toCharArray(); /** * The Hexadecimal representation of 127. */ private static final byte MASK = 0x7f; /** * The Hexadecimal representation of 128. */ private static final int MASK_128 = 0x80; /** * The Hexadecimal decode value. */ private static final byte[] HEX_DECODE = new byte[MASK_128]; // create a ASCII decoded array of Hexadecimal values static { for (var i = 0; i < HEX_DIGITS.length; i++) { HEX_DECODE[HEX_DIGITS[i]] = (byte) i; HEX_DECODE[Character.toLowerCase(HEX_DIGITS[i])] = (byte) i; } } /** * Decodes a string of text obtained from a HTTP header as per RFC 2231 * * Eg 1. {@code us-ascii'en-us'This%20is%20%2A%2A%2Afun%2A%2A%2A} will be decoded to {@code This is ***fun***} * * Eg 2. {@code iso-8859-1'en'%A3%20rate} will be decoded to {@code £ rate}. * * Eg 3. {@code UTF-8''%c2%a3%20and%20%e2%82%ac%20rates} will be decoded to {@code £ and € rates}. * * @param encodedText Text to be decoded has a format of {@code ''} and ASCII only * @return Decoded text based on charset encoding * @throws UnsupportedEncodingException The requested character set wasn't found. */ static String decodeText(final String encodedText) throws UnsupportedEncodingException { final var langDelimitStart = encodedText.indexOf('\''); if (langDelimitStart == -1) { // missing charset return encodedText; } final var mimeCharset = encodedText.substring(0, langDelimitStart); final var langDelimitEnd = encodedText.indexOf('\'', langDelimitStart + 1); if (langDelimitEnd == -1) { // missing language return encodedText; } final var bytes = fromHex(encodedText.substring(langDelimitEnd + 1)); return new String(bytes, getJavaCharset(mimeCharset)); } /** * Converts {@code text} to their corresponding Hex value. * * @param text ASCII text input * @return Byte array of characters decoded from ASCII table */ private static byte[] fromHex(final String text) { final var shift = 4; final var out = new ByteArrayOutputStream(text.length()); for (var i = 0; i < text.length();) { final var c = text.charAt(i++); if (c == '%') { if (i > text.length() - 2) { break; // unterminated sequence } final var b1 = HEX_DECODE[text.charAt(i++) & MASK]; final var b2 = HEX_DECODE[text.charAt(i++) & MASK]; out.write(b1 << shift | b2); } else { out.write((byte) c); } } return out.toByteArray(); } private static String getJavaCharset(final String mimeCharset) { // good enough for standard values return mimeCharset; } /** * Tests if asterisk (*) at the end of parameter name to indicate, if it has charset and language information to decode the value. * * @param paramName The parameter, which is being checked. * @return {@code true}, if encoded as per RFC 2231, {@code false} otherwise */ static boolean hasEncodedValue(final String paramName) { if (paramName != null) { return paramName.lastIndexOf('*') == paramName.length() - 1; } return false; } /** * If {@code paramName} has Asterisk (*) at the end, it will be stripped off, else the passed value will be returned. * * @param paramName The parameter, which is being inspected. * @return stripped {@code paramName} of Asterisk (*), if RFC2231 encoded */ static String stripDelimiter(final String paramName) { if (hasEncodedValue(paramName)) { final var paramBuilder = new StringBuilder(paramName); paramBuilder.deleteCharAt(paramName.lastIndexOf('*')); return paramBuilder.toString(); } return paramName; } /** * Private constructor so that no instances can be created. This class contains only static utility methods. */ private RFC2231Utils() { } } ././@LongLink0000644000000000000000000000017700000000000011610 Lustar rootrootlibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-core/src/main/java/org/apache/commons/fileupload2/core/MimeUtils.javalibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-core/src/main/java/org/apache/commons/fileu0000644000175000017500000002517115142145735032070 0ustar zigozigo/* * 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 * * https://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.core; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.UnsupportedEncodingException; import java.nio.charset.StandardCharsets; import java.text.ParseException; import java.util.Base64; import java.util.HashMap; import java.util.Locale; import java.util.Map; /** * Utility class to decode MIME texts. */ final class MimeUtils { /** * The marker to indicate text is encoded with BASE64 algorithm. */ private static final String BASE64_ENCODING_MARKER = "B"; /** * The marker to indicate text is encoded with QuotedPrintable algorithm. */ private static final String QUOTEDPRINTABLE_ENCODING_MARKER = "Q"; /** * If the text contains any encoded tokens, those tokens will be marked with "=?". */ private static final String ENCODED_TOKEN_MARKER = "=?"; /** * If the text contains any encoded tokens, those tokens will terminate with "=?". */ private static final String ENCODED_TOKEN_FINISHER = "?="; /** * The linear whitespace chars sequence. */ private static final String LINEAR_WHITESPACE = " \t\r\n"; /** * Mappings between MIME and Java charset. */ private static final Map MIME2JAVA = new HashMap<>(); static { MIME2JAVA.put("iso-2022-cn", "ISO2022CN"); MIME2JAVA.put("iso-2022-kr", "ISO2022KR"); MIME2JAVA.put("utf-8", "UTF8"); MIME2JAVA.put("utf8", "UTF8"); MIME2JAVA.put("ja_jp.iso2022-7", "ISO2022JP"); MIME2JAVA.put("ja_jp.eucjp", "EUCJIS"); MIME2JAVA.put("euc-kr", "KSC5601"); MIME2JAVA.put("euckr", "KSC5601"); MIME2JAVA.put("us-ascii", StandardCharsets.ISO_8859_1.name()); MIME2JAVA.put("x-us-ascii", StandardCharsets.ISO_8859_1.name()); } /** * Decodes a string of text obtained from a mail header into its proper form. The text generally will consist of a string of tokens, some of which may be * encoded using base64 encoding. * * @param text The text to decode. * @return The decoded text string. * @throws UnsupportedEncodingException if the detected encoding in the input text is not supported. */ static String decodeText(final String text) throws UnsupportedEncodingException { // if the text contains any encoded tokens, those tokens will be marked with "=?". If the // source string doesn't contain that sequent, no decoding is required. if (!text.contains(ENCODED_TOKEN_MARKER)) { return text; } var offset = 0; final var endOffset = text.length(); var startWhiteSpace = -1; var endWhiteSpace = -1; final var decodedText = new StringBuilder(text.length()); var previousTokenEncoded = false; while (offset < endOffset) { var ch = text.charAt(offset); // is this a whitespace character? if (LINEAR_WHITESPACE.indexOf(ch) != -1) { // whitespace found startWhiteSpace = offset; while (offset < endOffset) { // step over the white space characters. ch = text.charAt(offset); if (LINEAR_WHITESPACE.indexOf(ch) == -1) { // record the location of the first non lwsp and drop down to process the // token characters. endWhiteSpace = offset; break; } offset++; } } else { // we have a word token. We need to scan over the word and then try to parse it. final var wordStart = offset; while (offset < endOffset) { // step over the non white space characters. ch = text.charAt(offset); if (LINEAR_WHITESPACE.indexOf(ch) != -1) { break; } offset++; // NB: Trailing whitespace on these header strings will just be discarded. } // pull out the word token. final var word = text.substring(wordStart, offset); // is the token encoded? decode the word if (word.startsWith(ENCODED_TOKEN_MARKER)) { try { // if this gives a parsing failure, treat it like a non-encoded word. final var decodedWord = decodeWord(word); // are any whitespace characters significant? Append 'em if we've got 'em. if (!previousTokenEncoded && startWhiteSpace != -1) { decodedText.append(text, startWhiteSpace, endWhiteSpace); startWhiteSpace = -1; } // this is definitely a decoded token. previousTokenEncoded = true; // and add this to the text. decodedText.append(decodedWord); // we continue parsing from here...we allow parsing errors to fall through // and get handled as normal text. continue; } catch (final ParseException ignored) { // just ignore it, skip to next word } } // this is a normal token, so it doesn't matter what the previous token was. Add the white space // if we have it. if (startWhiteSpace != -1) { decodedText.append(text, startWhiteSpace, endWhiteSpace); startWhiteSpace = -1; } // this is not a decoded token. previousTokenEncoded = false; decodedText.append(word); } } return decodedText.toString(); } /** * Decodes a string using the RFC 2047 rules for an "encoded-word" type. This encoding has the syntax: * * encoded-word = "=?" charset "?" encoding "?" encoded-text "?=" * * @param word The possibly encoded word value. * @return The decoded word. * @throws ParseException in case of a parse error of the RFC 2047. * @throws UnsupportedEncodingException Thrown when Invalid RFC 2047 encoding was found. */ private static String decodeWord(final String word) throws ParseException, UnsupportedEncodingException { // encoded words start with the characters "=?". If this not an encoded word, we throw a // ParseException for the caller. final var etmPos = word.indexOf(ENCODED_TOKEN_MARKER); if (etmPos != 0) { throw new ParseException("Invalid RFC 2047 encoded-word: " + word, etmPos); } final var charsetPos = word.indexOf('?', 2); if (charsetPos == -1) { throw new ParseException("Missing charset in RFC 2047 encoded-word: " + word, charsetPos); } // pull out the character set information (this is the MIME name at this point). final var charset = word.substring(2, charsetPos).toLowerCase(Locale.ROOT); // now pull out the encoding token the same way. final var encodingPos = word.indexOf('?', charsetPos + 1); if (encodingPos == -1) { throw new ParseException("Missing encoding in RFC 2047 encoded-word: " + word, encodingPos); } final var encoding = word.substring(charsetPos + 1, encodingPos); // and finally the encoded text. final var encodedTextPos = word.indexOf(ENCODED_TOKEN_FINISHER, encodingPos + 1); if (encodedTextPos == -1) { throw new ParseException("Missing encoded text in RFC 2047 encoded-word: " + word, encodedTextPos); } final var encodedText = word.substring(encodingPos + 1, encodedTextPos); // seems a bit silly to encode a null string, but easy to deal with. if (encodedText.isEmpty()) { return ""; } try { // the decoder writes directly to an output stream. final var out = new ByteArrayOutputStream(encodedText.length()); final var encodedData = encodedText.getBytes(StandardCharsets.US_ASCII); // Base64 encoded? if (encoding.equals(BASE64_ENCODING_MARKER)) { out.write(Base64.getMimeDecoder().decode(encodedData)); } else if (encoding.equals(QUOTEDPRINTABLE_ENCODING_MARKER)) { // maybe quoted printable. QuotedPrintableDecoder.decode(encodedData, out); } else { throw new UnsupportedEncodingException("Unknown RFC 2047 encoding: " + encoding); } // get the decoded byte data and convert into a string. final var decodedData = out.toByteArray(); return new String(decodedData, javaCharset(charset)); } catch (final IOException e) { throw new UnsupportedEncodingException("Invalid RFC 2047 encoding"); } } /** * Translate a MIME standard character set name into the Java equivalent. * * @param charset The MIME standard name. * @return The Java equivalent for this name. */ private static String javaCharset(final String charset) { // nothing in, nothing out. if (charset == null) { return null; } final var mappedCharset = MIME2JAVA.get(charset.toLowerCase(Locale.ROOT)); // if there is no mapping, then the original name is used. Many of the MIME character set // names map directly back into Java. The reverse isn't necessarily true. return mappedCharset == null ? charset : mappedCharset; } /** * Hidden constructor, this class must not be instantiated. */ private MimeUtils() { // do nothing } } ././@LongLink0000644000000000000000000000020400000000000011577 Lustar rootrootlibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-core/src/main/java/org/apache/commons/fileupload2/core/MultipartInput.javalibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-core/src/main/java/org/apache/commons/fileu0000644000175000017500000010300315142145735032057 0ustar zigozigo/* * 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 * * https://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.core; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.UnsupportedEncodingException; import java.nio.charset.Charset; import org.apache.commons.fileupload2.core.FileItemInput.ItemSkippedException; import org.apache.commons.io.Charsets; import org.apache.commons.io.IOUtils; import org.apache.commons.io.build.AbstractOrigin; import org.apache.commons.io.build.AbstractStreamBuilder; import org.apache.commons.io.output.NullOutputStream; /** * Low-level API for processing file uploads. * *

* This class can be used to process data streams conforming to MIME 'multipart' format as defined in RFC * 1867. Arbitrarily large amounts of data in the stream can be processed under constant memory usage. *

*

* The format of the stream is defined in the following way: *

*
 *   multipart-body := preamble 1*encapsulation close-delimiter epilogue
* encapsulation := delimiter body CRLF
* delimiter := "--" boundary CRLF
* close-delimiter := "--" boundary "--"
* preamble := <ignore>
* epilogue := <ignore>
* body := header-part CRLF body-part
* header-part := 1*header CRLF
* header := header-name ":" header-value
* header-name := <printable ASCII characters except ":">
* header-value := <any ASCII characters except CR & LF>
* body-data := <arbitrary data>
*
* *

* Note that body-data can contain another mulipart entity. There is limited support for single pass processing of such nested streams. The nested stream is * required to have a boundary token of the same length as the parent stream (see {@link #setBoundary(byte[])}). *

*

* Here is an example of usage of this class: *

* *
 * try {
 *     MultipartInput multipartStream = MultipartInput.builder()
 *             .setBoundary(boundary)
 *             .setInputStream(input)
 *             .get();
 *     boolean nextPart = multipartStream.skipPreamble();
 *     OutputStream output;
 *     while (nextPart) {
 *         String header = multipartStream.readHeaders();
 *         // process headers
 *         // create some output stream
 *         multipartStream.readBodyData(output);
 *         nextPart = multipartStream.readBoundary();
 *     }
 * } catch (MultipartInput.MalformedStreamException e) {
 *     // the stream failed to follow required syntax
 * } catch (IOException e) {
 *     // a read or write error occurred
 * }
 * 
*/ public final class MultipartInput { /** * Builds a new {@link MultipartInput} instance. *

* For example: *

* *
{@code
     * MultipartInput factory = MultipartInput.builder().setPath(path).setBufferSize(DEFAULT_THRESHOLD).get();
     * }
     * 
*/ public static class Builder extends AbstractStreamBuilder { /** * Boundary. */ private byte[] boundary; /** * Progress notifier. */ private ProgressNotifier progressNotifier; /** * The per part size limit for headers. */ private int maxPartHeaderSize = DEFAULT_PART_HEADER_SIZE_MAX; /** * Constructs a new instance. */ public Builder() { setBufferSizeDefault(DEFAULT_BUFSIZE); } /** * Constructs a new instance. *

* This builder uses the InputStream, buffer size, boundary and progress notifier aspects. *

*

* You must provide an origin that can be converted to a Reader by this builder, otherwise, this call will throw an * {@link UnsupportedOperationException}. *

* * @return a new instance. * @throws IOException if an I/O error occurs. * @throws UnsupportedOperationException if the origin cannot provide a Path. * @see AbstractOrigin#getReader(Charset) */ @Override public MultipartInput get() throws IOException { return new MultipartInput(this); } /** * Gets the per part size limit for headers. * * @return The maximum size of the headers in bytes. * @since 2.0.0-M5 */ public int getMaxPartHeaderSize() { return maxPartHeaderSize; } /** * Sets the boundary. * * @param boundary the boundary. * @return {@code this} instance. */ public Builder setBoundary(final byte[] boundary) { this.boundary = boundary; return this; } /** * Sets the per part size limit for headers. * @param partHeaderSizeMax The maximum size of the headers in bytes. * @return This builder. * @since 2.0.0-M5 */ public Builder setMaxPartHeaderSize(final int partHeaderSizeMax) { this.maxPartHeaderSize = partHeaderSizeMax; return this; } /** * Sets the progress notifier. * * @param progressNotifier progress notifier. * @return {@code this} instance. */ public Builder setProgressNotifier(final ProgressNotifier progressNotifier) { this.progressNotifier = progressNotifier; return this; } } /** * Signals an attempt to set an invalid boundary token. */ public static class FileUploadBoundaryException extends FileUploadException { /** * The UID to use when serializing this instance. */ private static final long serialVersionUID = 2; /** * Constructs an instance with the specified detail message. * * @param message The detail message (which is saved for later retrieval by the {@link #getMessage()} method) */ public FileUploadBoundaryException(final String message) { super(message); } } /** * An {@link InputStream} for reading an items contents. */ public class ItemInputStream extends InputStream { /** * Offset when converting negative bytes to integers. */ private static final int BYTE_POSITIVE_OFFSET = 256; /** * The number of bytes, which have been read so far. */ private long total; /** * The number of bytes, which must be hold, because they might be a part of the boundary. */ private int pad; /** * The current offset in the buffer. */ private int pos; /** * Whether the stream is already closed. */ private boolean closed; /** * Creates a new instance. */ ItemInputStream() { findSeparator(); } /** * Returns the number of bytes, which are currently available, without blocking. * * @throws IOException An I/O error occurs. * @return Number of bytes in the buffer. */ @Override public int available() throws IOException { if (pos == -1) { return tail - head - pad; } return pos - head; } private void checkOpen() throws ItemSkippedException { if (closed) { throw new FileItemInput.ItemSkippedException("checkOpen()"); } } /** * Closes the input stream. * * @throws IOException An I/O error occurred. */ @Override public void close() throws IOException { close(false); } /** * Closes the input stream. * * @param closeUnderlying Whether to close the underlying stream (hard close) * @throws IOException An I/O error occurred. */ public void close(final boolean closeUnderlying) throws IOException { if (closed) { return; } if (closeUnderlying) { closed = true; input.close(); } else { for (;;) { var avail = available(); if (avail == 0) { avail = makeAvailable(); if (avail == 0) { break; } } if (skip(avail) != avail) { // TODO What to do? } } } closed = true; } /** * Called for finding the separator. */ private void findSeparator() { pos = MultipartInput.this.findSeparator(); if (pos == -1) { if (tail - head > keepRegion) { pad = keepRegion; } else { pad = tail - head; } } } /** * Gets the number of bytes, which have been read by the stream. * * @return Number of bytes, which have been read so far. */ public long getBytesRead() { return total; } /** * Tests whether this instance is closed. * * @return whether this instance is closed. */ public boolean isClosed() { return closed; } /** * Attempts to read more data. * * @return Number of available bytes * @throws IOException An I/O error occurred. */ private int makeAvailable() throws IOException { if (pos != -1) { return 0; } // Move the data to the beginning of the buffer. total += tail - head - pad; System.arraycopy(buffer, tail - pad, buffer, 0, pad); // Refill buffer with new data. head = 0; tail = pad; for (;;) { final var bytesRead = input.read(buffer, tail, bufSize - tail); if (bytesRead == -1) { // The last pad amount is left in the buffer. // Boundary can't be in there so signal an error // condition. final var msg = "Stream ended unexpectedly"; throw new MalformedStreamException(msg); } if (notifier != null) { notifier.noteBytesRead(bytesRead); } tail += bytesRead; findSeparator(); final var av = available(); if (av > 0 || pos != -1) { return av; } } } /** * Reads the next byte in the stream. * * @return The next byte in the stream, as a non-negative integer, or -1 for EOF. * @throws IOException An I/O error occurred. */ @Override public int read() throws IOException { checkOpen(); if (available() == 0 && makeAvailable() == 0) { return -1; } ++total; final int b = buffer[head++]; if (b >= 0) { return b; } return b + BYTE_POSITIVE_OFFSET; } /** * Reads bytes into the given buffer. * * @param b The destination buffer, where to write to. * @param off Offset of the first byte in the buffer. * @param len Maximum number of bytes to read. * @return Number of bytes, which have been actually read, or -1 for EOF. * @throws IOException An I/O error occurred. */ @Override public int read(final byte[] b, final int off, final int len) throws IOException { checkOpen(); if (len == 0) { return 0; } var res = available(); if (res == 0) { res = makeAvailable(); if (res == 0) { return -1; } } res = Math.min(res, len); System.arraycopy(buffer, head, b, off, res); head += res; total += res; return res; } /** * Skips the given number of bytes. * * @param bytes Number of bytes to skip. * @return The number of bytes, which have actually been skipped. * @throws IOException An I/O error occurred. */ @Override public long skip(final long bytes) throws IOException { checkOpen(); var available = available(); if (available == 0) { available = makeAvailable(); if (available == 0) { return 0; } } // Fix "Implicit narrowing conversion in compound assignment" // https://github.com/apache/commons-fileupload/security/code-scanning/118 // Math.min always returns an int because available is an int. final var res = Math.toIntExact(Math.min(available, bytes)); head += res; return res; } } /** * Signals that the input stream fails to follow the required syntax. */ public static class MalformedStreamException extends FileUploadException { /** * The UID to use when serializing this instance. */ private static final long serialVersionUID = 2; /** * Constructs an {@code MalformedStreamException} with the specified detail message. * * @param message The detail message. */ public MalformedStreamException(final String message) { super(message); } /** * Constructs an {@code MalformedStreamException} with the specified detail message. * * @param message The detail message. * @param cause The cause (which is saved for later retrieval by the {@link #getCause()} method). (A null value is permitted, and indicates that the * cause is nonexistent or unknown.) */ public MalformedStreamException(final String message, final Throwable cause) { super(message, cause); } } /** * Internal class, which is used to invoke the {@link ProgressListener}. */ public static class ProgressNotifier { /** * The listener to invoke. */ private final ProgressListener progressListener; /** * Number of expected bytes, if known, or -1. */ private final long contentLength; /** * Number of bytes, which have been read so far. */ private long bytesRead; /** * Number of items, which have been read so far. */ private int items; /** * Creates a new instance with the given listener and content length. * * @param progressListener The listener to invoke. * @param contentLength The expected content length. */ public ProgressNotifier(final ProgressListener progressListener, final long contentLength) { this.progressListener = progressListener != null ? progressListener : ProgressListener.NOP; this.contentLength = contentLength; } /** * Called to indicate that bytes have been read. * * @param byteCount Number of bytes, which have been read. */ void noteBytesRead(final int byteCount) { // // Indicates, that the given number of bytes have been read from the input stream. // bytesRead += byteCount; notifyListener(); } /** * Called to indicate, that a new file item has been detected. */ public void noteItem() { ++items; notifyListener(); } /** * Called for notifying the listener. */ private void notifyListener() { progressListener.update(bytesRead, contentLength, items); } } /** * The Carriage Return ASCII character value. */ public static final byte CR = 0x0D; /** * The Line Feed ASCII character value. */ public static final byte LF = 0x0A; /** * The dash (-) ASCII character value. */ public static final byte DASH = 0x2D; /** * The default length of the buffer used for processing a request. */ static final int DEFAULT_BUFSIZE = 4096; /** * Default per part header size limit in bytes. * @since 2.0.0-M4 */ public static final int DEFAULT_PART_HEADER_SIZE_MAX = 512; /** * A byte sequence that marks the end of {@code header-part} ({@code CRLFCRLF}). */ static final byte[] HEADER_SEPARATOR = { CR, LF, CR, LF }; /** * A byte sequence that that follows a delimiter that will be followed by an encapsulation ({@code CRLF}). */ static final byte[] FIELD_SEPARATOR = { CR, LF }; /** * A byte sequence that that follows a delimiter of the last encapsulation in the stream ({@code --}). */ static final byte[] STREAM_TERMINATOR = { DASH, DASH }; /** * A byte sequence that precedes a boundary ({@code CRLF--}). */ static final byte[] BOUNDARY_PREFIX = { CR, LF, DASH, DASH }; /** * Compares {@code count} first bytes in the arrays {@code a} and {@code b}. * * @param a The first array to compare. * @param b The second array to compare. * @param count How many bytes should be compared. * @return {@code true} if {@code count} first bytes in arrays {@code a} and {@code b} are equal. */ static boolean arrayEquals(final byte[] a, final byte[] b, final int count) { for (var i = 0; i < count; i++) { if (a[i] != b[i]) { return false; } } return true; } /** * Constructs a new {@link Builder}. * * @return a new {@link Builder}. */ public static Builder builder() { return new Builder(); } /** * The input stream from which data is read. */ private final InputStream input; /** * The length of the boundary token plus the leading {@code CRLF--}. */ private int boundaryLength; /** * The amount of data, in bytes, that must be kept in the buffer in order to detect delimiters reliably. */ private final int keepRegion; /** * The byte sequence that partitions the stream. */ private final byte[] boundary; /** * The table for Knuth-Morris-Pratt search algorithm. */ private final int[] boundaryTable; /** * The length of the buffer used for processing the request. */ private final int bufSize; /** * The buffer used for processing the request. */ private final byte[] buffer; /** * The index of first valid character in the buffer.
* 0 <= head < bufSize */ private int head; /** * The index of last valid character in the buffer + 1.
* 0 <= tail <= bufSize */ private int tail; /** * The content encoding to use when reading headers. */ private Charset headerCharset; /** * The progress notifier, if any, or null. */ private final ProgressNotifier notifier; /** * The maximum size of the headers in bytes. */ private final int maxPartHeaderSize; /** * Constructs a {@code MultipartInput} with a custom size buffer. *

* Note that the buffer must be at least big enough to contain the boundary string, plus 4 characters for CR/LF and double dash, plus at least one byte of * data. Too small a buffer size setting will degrade performance. *

* * @param input The {@code InputStream} to serve as a data source. * @param boundary The token used for dividing the stream into {@code encapsulations}. * @param bufferSize The size of the buffer to be used, in bytes. * @param notifier The notifier, which is used for calling the progress listener, if any. * @throws IOException Thrown if an I/O error occurs. * @throws IllegalArgumentException If the buffer size is too small. */ private MultipartInput(final Builder builder) throws IOException { if (builder.boundary == null) { throw new IllegalArgumentException("boundary may not be null"); } // We prepend CR/LF to the boundary to chop trailing CR/LF from // body-data tokens. this.boundaryLength = builder.boundary.length + BOUNDARY_PREFIX.length; if (builder.getBufferSize() < this.boundaryLength + 1) { throw new IllegalArgumentException("The buffer size specified for the MultipartInput is too small"); } this.input = builder.getInputStream(); this.bufSize = Math.max(builder.getBufferSize(), boundaryLength * 2); this.buffer = new byte[this.bufSize]; this.notifier = builder.progressNotifier; this.maxPartHeaderSize = builder.getMaxPartHeaderSize(); this.boundary = new byte[this.boundaryLength]; this.boundaryTable = new int[this.boundaryLength + 1]; this.keepRegion = this.boundary.length; System.arraycopy(BOUNDARY_PREFIX, 0, this.boundary, 0, BOUNDARY_PREFIX.length); System.arraycopy(builder.boundary, 0, this.boundary, BOUNDARY_PREFIX.length, builder.boundary.length); computeBoundaryTable(); head = 0; tail = 0; } /** * Computes the table used for Knuth-Morris-Pratt search algorithm. */ private void computeBoundaryTable() { var position = 2; var candidate = 0; boundaryTable[0] = -1; boundaryTable[1] = 0; while (position <= boundaryLength) { if (boundary[position - 1] == boundary[candidate]) { boundaryTable[position] = candidate + 1; candidate++; position++; } else if (candidate > 0) { candidate = boundaryTable[candidate]; } else { boundaryTable[position] = 0; position++; } } } /** * Reads {@code body-data} from the current {@code encapsulation} and discards it. *

* Use this method to skip encapsulations you don't need or don't understand. *

* * @return The amount of data discarded. * @throws MalformedStreamException if the stream ends unexpectedly. * @throws IOException if an i/o error occurs. */ public long discardBodyData() throws MalformedStreamException, IOException { return readBodyData(NullOutputStream.INSTANCE); } /** * 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 (var 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}. * * @return The position of the boundary found, counting from the beginning of the {@code buffer}, or {@code -1} if not found. */ protected int findSeparator() { var bufferPos = this.head; var tablePos = 0; while (bufferPos < this.tail) { while (tablePos >= 0 && buffer[bufferPos] != boundary[tablePos]) { tablePos = boundaryTable[tablePos]; } bufferPos++; tablePos++; if (tablePos == boundaryLength) { return bufferPos - boundaryLength; } } return -1; } /** * Gets the character encoding used when reading the headers of an individual part. When not specified, or {@code null}, the platform default encoding is * used. * * @return The encoding used to read part headers. */ public Charset getHeaderCharset() { return headerCharset; } /** * Returns the per part size limit for headers. * * @return The maximum size of the headers in bytes. * @since 2.0.0-M5 */ public int getMaxPartHeaderSize() { return maxPartHeaderSize; } /** * Creates a new {@link ItemInputStream}. * * @return A new instance of {@link ItemInputStream}. */ public ItemInputStream newInputStream() { return new ItemInputStream(); } /** * Reads {@code body-data} from the current {@code encapsulation} and writes its contents into the output {@code Stream}. *

* Arbitrary large amounts of data can be processed by this method using a constant size buffer. (see {@link MultipartInput#builder()}). *

* * @param output The {@code Stream} to write data into. May be null, in which case this method is equivalent to {@link #discardBodyData()}. * @return the amount of data written. * @throws MalformedStreamException if the stream ends unexpectedly. * @throws IOException if an i/o error occurs. */ public long readBodyData(final OutputStream output) throws MalformedStreamException, IOException { try (var inputStream = newInputStream()) { return IOUtils.copyLarge(inputStream, output); } } /** * Skips a {@code boundary} token, and checks whether more {@code encapsulations} are contained in the stream. * * @return {@code true} if there are more encapsulations in this stream; {@code false} otherwise. * @throws FileUploadSizeException if the bytes read from the stream exceeded the size limits * @throws MalformedStreamException if the stream ends unexpectedly or fails to follow required syntax. */ public boolean readBoundary() throws FileUploadSizeException, MalformedStreamException { final var marker = new byte[2]; final boolean nextChunk; head += boundaryLength; try { marker[0] = readByte(); if (marker[0] == LF) { // Work around IE5 Mac bug with input type=image. // Because the boundary delimiter, not including the trailing // CRLF, must not appear within any file (RFC 2046, section // 5.1.1), we know the missing CR is due to a buggy browser // rather than a file containing something similar to a // boundary. return true; } marker[1] = readByte(); if (arrayEquals(marker, STREAM_TERMINATOR, 2)) { nextChunk = false; } else if (arrayEquals(marker, FIELD_SEPARATOR, 2)) { nextChunk = true; } else { throw new MalformedStreamException("Unexpected characters follow a boundary"); } } catch (final FileUploadSizeException e) { throw e; } catch (final IOException e) { throw new MalformedStreamException("Stream ended unexpectedly", e); } return nextChunk; } /** * Reads a byte from the {@code buffer}, and refills it as necessary. * * @return The next byte from the input stream. * @throws IOException if there is no more data available. */ public byte readByte() throws IOException { // Buffer depleted ? if (head == tail) { head = 0; // Refill. tail = input.read(buffer, head, bufSize); if (tail == -1) { // No more data available. throw new IOException("No more data is available"); } if (notifier != null) { notifier.noteBytesRead(tail); } } return buffer[head++]; } /** * Reads the {@code header-part} of the current {@code encapsulation}. *

* Headers are returned verbatim to the input stream, including the trailing {@code CRLF} marker. Parsing is left to the application. *

*

* TODO allow limiting maximum header size to protect against abuse. *

* * @return The {@code header-part} of the current encapsulation. * @throws FileUploadSizeException if the bytes read from the stream exceeded the size limits. * @throws MalformedStreamException if the stream ends unexpectedly. */ public String readHeaders() throws FileUploadSizeException, MalformedStreamException { var i = 0; byte b; // to support multi-byte characters final var baos = new ByteArrayOutputStream(); var size = 0; while (i < HEADER_SEPARATOR.length) { try { b = readByte(); } catch (final FileUploadSizeException e) { // wraps a FileUploadSizeException, re-throw as it will be unwrapped later throw e; } catch (final IOException e) { throw new MalformedStreamException("Stream ended unexpectedly", e); } final int phsm = getMaxPartHeaderSize(); if (phsm != -1 && ++size > phsm) { throw new FileUploadSizeException( String.format("Header section has more than %s bytes (maybe it is not properly terminated)", Integer.valueOf(phsm)), phsm, size); } if (b == HEADER_SEPARATOR[i]) { i++; } else { i = 0; } baos.write(b); } try { return baos.toString(Charsets.toCharset(headerCharset, Charset.defaultCharset()).name()); } catch (final UnsupportedEncodingException e) { // not possible throw new IllegalStateException(e); } } /** * Changes the boundary token used for partitioning the stream. *

* This method allows single pass processing of nested multipart streams. *

*

* The boundary token of the nested stream is {@code required} to be of the same length as the boundary token in parent stream. *

*

* Restoring the parent stream boundary token after processing of a nested stream is left to the application. *

* * @param boundary The boundary to be used for parsing of the nested stream. * @throws FileUploadBoundaryException if the {@code boundary} has a different length than the one being currently parsed. */ public void setBoundary(final byte[] boundary) throws FileUploadBoundaryException { if (boundary.length != boundaryLength - BOUNDARY_PREFIX.length) { throw new FileUploadBoundaryException("The length of a boundary token cannot be changed"); } System.arraycopy(boundary, 0, this.boundary, BOUNDARY_PREFIX.length, boundary.length); computeBoundaryTable(); } /** * Sets the character encoding to be used when reading the headers of individual parts. When not specified, or {@code null}, the platform default encoding * is used. * * @param headerCharset The encoding used to read part headers. */ public void setHeaderCharset(final Charset headerCharset) { this.headerCharset = headerCharset; } /** * Finds the beginning of the first {@code encapsulation}. * * @return {@code true} if an {@code encapsulation} was found in the stream. * @throws IOException if an i/o error occurs. */ public boolean skipPreamble() throws IOException { // First delimiter may be not preceded with a CRLF. System.arraycopy(boundary, 2, boundary, 0, boundary.length - 2); boundaryLength = boundary.length - 2; computeBoundaryTable(); try { // Discard all data up to the delimiter. discardBodyData(); // Read boundary - if succeeded, the stream contains an // encapsulation. return readBoundary(); } catch (final MalformedStreamException e) { return false; } finally { // Restore delimiter. System.arraycopy(boundary, 0, boundary, 2, boundary.length - 2); boundaryLength = boundary.length; boundary[0] = CR; boundary[1] = LF; computeBoundaryTable(); } } } ././@LongLink0000644000000000000000000000020200000000000011575 Lustar rootrootlibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-core/src/main/java/org/apache/commons/fileupload2/core/DiskFileItem.javalibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-core/src/main/java/org/apache/commons/fileu0000644000175000017500000006436715142145735032102 0ustar zigozigo/* * 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 * * https://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.core; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStream; import java.io.Reader; import java.io.UncheckedIOException; import java.io.UnsupportedEncodingException; import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; import java.nio.file.CopyOption; import java.nio.file.Files; import java.nio.file.InvalidPathException; import java.nio.file.Path; import java.nio.file.Paths; import java.nio.file.StandardCopyOption; import java.util.UUID; import java.util.concurrent.atomic.AtomicInteger; import java.util.function.Supplier; import org.apache.commons.fileupload2.core.DeferrableOutputStream.Listener; import org.apache.commons.fileupload2.core.DeferrableOutputStream.State; import org.apache.commons.fileupload2.core.FileItemFactory.AbstractFileItemBuilder; import org.apache.commons.io.Charsets; import org.apache.commons.io.FileCleaningTracker; import org.apache.commons.io.build.AbstractOrigin; import org.apache.commons.io.file.PathUtils; /** * The default implementation of the {@link FileItem FileItem} interface. * *

After retrieving an instance of this class from a {@link DiskFileItemFactory} instance (see * {@code org.apache.commons.fileupload2.core.servlet.ServletFileUpload * #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.

* *

State model: Instances of {@link DiskFileItem} are subject to a carefully designed state model. * Depending on the so-called {@link #getThreshold() threshold}, either of the three models are possible:

*
    *
  1. threshold = -1 * Uploaded data is never kept in memory. Instead, a temporary file is being created immediately. * * {@link #isInMemory()} will always return false, {@link #getPath()} will always return the path * of an existing file. The temporary file may be empty.
  2. *
  3. threshold = 0 * Uploaded data is never kept in memory. (Same as threshold=-1.) However, the temporary file is * only created, if data was uploaded. Or, in other words: The uploaded file will never be * empty. * * {@link #isInMemory()} will return true, if no data was uploaded, otherwise it will be false. * In the former case {@link #getPath()} will return null, but in the latter case it returns * the path of an existing, non-empty file.
  4. *
  5. threshold > 0 * Uploaded data will be kept in memory, if the size is below the threshold. If the size * is equal to, or above the threshold, then a temporary file has been created, and all * uploaded data has been transferred to that file. * * {@link #isInMemory()} returns true, if the size of the uploaded data is below the threshold. * If so, {@link #getPath()} returns null. Otherwise, {@link #isInMemory()} returns false, * and {@link #getPath()} returns the path of an existing, temporary file. The size * of the temporary file is equal to, or above the threshold.
  6. *
* *

Temporary files, which are created for file items, should be deleted later on. The best way to do this is using a * {@link org.apache.commons.io.FileCleaningTracker}, which you can set on the {@link DiskFileItemFactory}. However, if you do use such a tracker, then you must * consider the following: Temporary files are automatically deleted as soon as they are no longer needed. (More precisely, when the corresponding instance of * {@link java.io.File} is garbage collected.) This is done by the so-called reaper thread, which is started and stopped automatically by the * {@link org.apache.commons.io.FileCleaningTracker} when there are files to be tracked. It might make sense to terminate that thread, for example, if your web * application ends. See the section on "Resource cleanup" in the users guide of Commons FileUpload.

*/ public final class DiskFileItem implements FileItem { /** * Builds a new {@link DiskFileItem} instance. *

* For example: *

* *
{@code
     * final FileItem fileItem = fileItemFactory.fileItemBuilder()
     *   .setFieldName("FieldName")
     *   .setContentType("ContentType")
     *   .setFormField(true)
     *   .setFileName("FileName")
     *   .setFileItemHeaders(...)
     *   .get();
     * }
     * 
*/ public static class Builder extends AbstractFileItemBuilder { /** * The threshold. We do maintain this separate from the {@link #getBufferSize()}, * because the parent class might change the value in {@link #setBufferSize(int)}. */ private int threshold; /** * Constructs a new instance. */ public Builder() { setBufferSize(DiskFileItemFactory.DEFAULT_THRESHOLD); setPath(PathUtils.getTempDirectory()); setCharset(DEFAULT_CHARSET); setCharsetDefault(DEFAULT_CHARSET); } /** * Constructs a new instance. *

* You must provide an origin that can be converted to a Reader by this builder, otherwise, this call will throw an * {@link UnsupportedOperationException}. *

* * @return a new instance. * @throws UnsupportedOperationException if the origin cannot provide a Path. * @see AbstractOrigin#getReader(Charset) */ @Override public DiskFileItem get() { final var diskFileItem = new DiskFileItem(this); final var tracker = getFileCleaningTracker(); if (tracker != null) { diskFileItem.setFileCleaningTracker(tracker); } return diskFileItem; } /** * Equivalent to {@link #getThreshold()}. * @return The threshold, which is being used. * @see #getThreshold() * @deprecated Since 2.0.0, use {@link #getThreshold()} instead. */ public int getBufferSize() { return getThreshold(); } /** * Returns the threshold. * @return The threshold. */ public int getThreshold() { return threshold; } /** * Equivalent to {@link #setThreshold(int)}. * @param bufferSize The threshold, which is being used. * @see #setThreshold(int) * @return This builder. * @deprecated Since 2.0.0, use {@link #setThreshold(int)} instead. */ @Override public Builder setBufferSize(final int bufferSize) { return setThreshold(bufferSize); } /** * Sets the threshold. The uploaded data is typically kept in memory, until * a certain number of bytes (the threshold) is reached. At this point, the * incoming data is transferred to a temporary file, and the in-memory data * is removed. * @param threshold The threshold, which is being used. * @return This builder. */ public Builder setThreshold(final int threshold) { this.threshold = threshold; return this; } } /** * Default content charset to be used when no explicit charset parameter is provided by the sender. Media subtypes of the "text" type are defined to have a * default charset value of "ISO-8859-1" when received via HTTP. */ public static final Charset DEFAULT_CHARSET = StandardCharsets.ISO_8859_1; /** * UID used in unique file name generation. */ private static final String UID = UUID.randomUUID().toString().replace('-', '_'); /** * Counter used in unique identifier generation. */ private static final AtomicInteger COUNTER = new AtomicInteger(); /** * Constructs a new {@link Builder}. * * @return a new {@link Builder}. */ public static Builder builder() { return new Builder(); } /** * Tests if the file name is valid. For example, if it contains a NUL characters, it's invalid. If the file name is valid, it will be returned without any * modifications. Otherwise, throw an {@link InvalidPathException}. * * @param fileName The file name to check * @return Unmodified file name, if valid. * @throws InvalidPathException The file name is invalid. */ public static String checkFileName(final String fileName) { if (fileName != null) { // Specific NUL check to build a better exception message. final var indexOf0 = fileName.indexOf(0); if (indexOf0 != -1) { final var sb = new StringBuilder(); for (var i = 0; i < fileName.length(); i++) { final var c = fileName.charAt(i); if (c == 0) { sb.append("\\0"); } else { sb.append(c); } } throw new InvalidPathException(fileName, sb.toString(), indexOf0); } // Throws InvalidPathException on invalid file names Paths.get(fileName); } return fileName; } /** * Gets an identifier that is unique within the class loader used to load this class, but does not have random-like appearance. * * @return A String with the non-random looking instance identifier. */ private static String getUniqueId() { final var limit = 100_000_000; final var current = COUNTER.getAndIncrement(); var id = Integer.toString(current); // If you manage to get more than 100 million of ids, you'll // start getting ids longer than 8 characters. if (current < limit) { id = ("00000000" + id).substring(id.length()); } return id; } /** * The name of the form field as provided by the browser. */ private String fieldName; /** * The content type passed by the browser, or {@code null} if not defined. */ private final String contentType; /** * Whether or not this item is a simple form field. */ private volatile boolean isFormField; /** * The original file name in the user's file system. */ private final String fileName; /** * The threshold above which uploads will be stored on disk. */ private final int threshold; /** * The directory in which uploaded files will be stored, if stored on disk, never null. */ private final Path repository; /** * Output stream for this item. */ private DeferrableOutputStream dos; /** * The file items headers. */ private FileItemHeaders fileItemHeaders; /** * Default content Charset to be used when no explicit Charset parameter is provided by the sender. */ private Charset charsetDefault = DEFAULT_CHARSET; /** * The {@link FileCleaningTracker}, which is being used to remove * temporary files. */ private FileCleaningTracker fileCleaningTracker; /** * Constructs a new {@code DiskFileItem} instance. * * @param builder The DiskFileItem builder. */ private DiskFileItem(final Builder builder) { this.fieldName = builder.getFieldName(); this.contentType = builder.getContentType(); this.charsetDefault = builder.getCharset(); this.isFormField = builder.isFormField(); this.fileName = builder.getFileName(); this.fileItemHeaders = builder.getFileItemHeaders(); this.threshold = builder.getThreshold(); this.repository = builder.getPath() != null ? builder.getPath() : PathUtils.getTempDirectory(); } /** * Deletes the underlying storage for a file item, including deleting any associated temporary disk file. This method can be used to ensure that this is * done at an earlier time, thus preserving system resources. * * @throws IOException if an error occurs. */ @Override public DiskFileItem delete() throws IOException { if (dos != null) { final Path path = dos.getPath(); if (path != null) { Files.deleteIfExists(path); } } return this; } /** * Gets the contents of the file as an array of bytes. If the contents of the file were not yet cached in memory, they will be loaded from the disk storage * and cached. * * @return The contents of the file as an array of bytes or {@code null} if the data cannot be read. * @throws IOException if an I/O error occurs. * @throws OutOfMemoryError See {@link Files#readAllBytes(Path)}: If an array of the required size cannot be allocated, for example the file is larger * than {@code 2GB}. If so, you should use {@link #getInputStream()}. * @see #getInputStream() * @deprecated Since 2.0.0, use {@link #getInputStream()}, or {@link #getReader()}, instead. */ @Override public byte[] get() throws IOException { if (dos != null) { final byte[] bytes = dos.getBytes(); if (bytes != null) { return bytes; } final Path path = dos.getPath(); if (path != null && dos.getState() == State.closed) { return Files.readAllBytes(path); } } return null; } /** * Gets the content charset passed by the agent or {@code null} if not defined. * * @return The content charset passed by the agent or {@code null} if not defined. */ public Charset getCharset() { final var parser = new ParameterParser(); parser.setLowerCaseNames(true); // Parameter parser can handle null input final var params = parser.parse(getContentType(), ';'); return Charsets.toCharset(params.get("charset"), charsetDefault); } /** * Gets the default charset for use when no explicit charset parameter is provided by the sender. * * @return the default charset */ public Charset getCharsetDefault() { return charsetDefault; } /** * Gets the content type passed by the agent or {@code null} if not defined. * * @return The content type passed by the agent or {@code null} if not defined. */ @Override public String getContentType() { return contentType; } /** * Gets the name of the field in the multipart form corresponding to this file item. * * @return The name of the form field. * @see #setFieldName(String) */ @Override public String getFieldName() { return fieldName; } /** * Returns the {@link FileCleaningTracker}, which is being used to remove * temporary files. * @return The {@link FileCleaningTracker}, which is being used to remove * temporary files. */ public FileCleaningTracker getFileCleaningTracker() { return fileCleaningTracker; } /** * Gets the file item headers. * * @return The file items headers. */ @Override public FileItemHeaders getHeaders() { return fileItemHeaders; } /** * Gets an {@link java.io.InputStream InputStream} that can be used to retrieve the contents of the file. * * @return An {@link java.io.InputStream InputStream} that can be used to retrieve the contents of the file. * @throws IOException if an error occurs. */ @Override public InputStream getInputStream() throws IOException { if (dos != null && dos.getState() == State.closed) { return dos.getInputStream(); } throw new IllegalStateException("The file item has not been fully read."); } /** * Gets the original file name in the client's file system. * * @return The original file name in the client's file system. * @throws InvalidPathException The file name contains a NUL character, which might be an indicator of a security attack. If you intend to use the file name * anyways, catch the exception and use {@link InvalidPathException#getInput()}. */ @Override public String getName() { return checkFileName(fileName); } /** * Gets an {@link java.io.OutputStream OutputStream} that can be used for storing the contents of the file. * * @return An {@link java.io.OutputStream OutputStream} that can be used for storing the contents of the file. */ @Override public OutputStream getOutputStream() { if (dos == null) { final Supplier pathSupplier = () -> this.repository.resolve(String.format("upload_%s_%s.tmp", UID, getUniqueId())); try { final Listener persistenceListener = new Listener() { @Override public void persisted(final Path pPath) { Listener.super.persisted(pPath); final FileCleaningTracker fct = getFileCleaningTracker(); if (fct != null) { fct.track(getPath(), this); } } }; dos = new DeferrableOutputStream(threshold, pathSupplier, persistenceListener); } catch (final IOException ioe) { throw new UncheckedIOException(ioe); } } return dos; } /** * Gets the {@link Path} for the {@code FileItem}'s data's temporary location on the disk. Note that for {@code FileItem}s that have their data stored in * memory, this method will return {@code null}. When handling large files, you can use {@link Files#move(Path,Path,CopyOption...)} to move the file to a * new location without copying the data, if the source and destination locations reside within the same logical volume. * * @return The data file, or {@code null} if the data is stored in memory. */ public Path getPath() { return dos == null ? null : dos.getPath(); } /** * Returns the contents of the file as a {@link Reader}, using the specified * {@link #getCharset()}. If the contents are not yet available, returns null. * This is the case, for example, if the underlying output stream has not yet * been closed. * @return The contents of the file as a {@link Reader} * @throws UnsupportedEncodingException The character set, which is * specified in the files "content-type" header, is invalid. * @throws IOException An I/O error occurred, while the * underlying {@link #getInputStream() input stream} was created. */ public Reader getReader() throws IOException, UnsupportedEncodingException { final InputStream is = getInputStream(); final var parser = new ParameterParser(); parser.setLowerCaseNames(true); // Parameter parser can handle null input final var params = parser.parse(getContentType(), ';'); final Charset cs = Charsets.toCharset(params.get("charset"), charsetDefault); return new InputStreamReader(is, cs); } /** * Gets the size of the file. * * @return The size of the file, in bytes. */ @Override public long getSize() { return dos == null ? 0L : dos.getSize(); } /** * Gets the contents of the file as a String, using the default character encoding. This method uses {@link #get()} to retrieve the contents of the file. * * @return The contents of the file, as a string, if available, or null. * @throws IOException if an I/O error occurs * @throws OutOfMemoryError See {@link Files#readAllBytes(Path)}: If a string of the required size cannot be allocated, * for example the file is larger than {@code 2GB}. If so, you should use {@link #getReader()}. * @throws UnsupportedEncodingException The character set, which is * specified in the files "content-type" header, is invalid. * @deprecated Since 2.0.0, use {@link #getReader()} instead. */ @Override public String getString() throws IOException, UnsupportedEncodingException, OutOfMemoryError { final byte[] bytes = get(); return bytes == null ? null : new String(bytes, getCharset()); } /** * Gets the contents of the file as a String, using the specified encoding. This method uses {@link #get()} to retrieve the contents of the file. * * @param charset The charset to use. * @return The contents of the file, as a string. * @throws IOException if an I/O error occurs */ @Override public String getString(final Charset charset) throws IOException { return new String(get(), Charsets.toCharset(charset, charsetDefault)); } /** * Returns the file items threshold. * @return The threshold. */ public int getThreshold() { return threshold; } /** * Tests whether or not a {@code FileItem} instance represents a simple form field. * * @return {@code true} if the instance represents a simple form field; {@code false} if it represents an uploaded file. * @see #setFormField(boolean) */ @Override public boolean isFormField() { return isFormField; } /** * Provides a hint as to whether or not the file contents will be read from memory. * * @return {@code true} if the file contents will be read from memory; {@code false} otherwise. */ @Override public boolean isInMemory() { return dos == null || dos.isInMemory(); } /** * Sets the default charset for use when no explicit charset parameter is provided by the sender. * * @param charset the default charset * @return {@code this} instance. */ public DiskFileItem setCharsetDefault(final Charset charset) { charsetDefault = charset; return this; } /** * Sets the field name used to reference this file item. * * @param fieldName The name of the form field. * @see #getFieldName() */ @Override public DiskFileItem setFieldName(final String fieldName) { this.fieldName = fieldName; return this; } /** * Sets the {@link FileCleaningTracker}, which is being used to remove * temporary files. * @param fileCleaningTracker The {@link FileCleaningTracker}, which is being used to * remove temporary files. */ public void setFileCleaningTracker(final FileCleaningTracker fileCleaningTracker) { this.fileCleaningTracker = fileCleaningTracker; } /** * Specifies whether or not a {@code FileItem} instance represents a simple form field. * * @param state {@code true} if the instance represents a simple form field; {@code false} if it represents an uploaded file. * @see #isFormField() */ @Override public DiskFileItem setFormField(final boolean state) { isFormField = state; return this; } /** * Sets the file item headers. * * @param headers The file items headers. */ @Override public DiskFileItem setHeaders(final FileItemHeaders headers) { this.fileItemHeaders = headers; return this; } /** * Returns a string representation of this object. * * @return a string representation of this object. */ @Override public String toString() { return String.format("name=%s, StoreLocation=%s, size=%s bytes, isFormField=%s, FieldName=%s", getName(), getPath(), getSize(), isFormField(), getFieldName()); } /** * Writes an uploaded item to disk. *

* The client code is not concerned with whether or not the item is stored in memory, or on disk in a temporary location. They just want to write the * uploaded item to a file. *

*

* This implementation first attempts to rename the uploaded item to the specified destination file, if the item was originally written to disk. Otherwise, * the data will be copied to the specified file. *

*

* This method is only guaranteed to work once, the first time it is invoked for a particular item. This is because, in the event that the method * renames a temporary file, that file will no longer be available to copy or rename again at a later time. *

* * @param file The {@code File} into which the uploaded item should be stored. * @throws IOException if an error occurs. */ @Override public DiskFileItem write(final Path file) throws IOException { if (isInMemory()) { try (var fout = Files.newOutputStream(file)) { fout.write(get()); } catch (final IOException e) { throw new IOException("Unexpected output data", e); } } else { final var outputFile = getPath(); if (outputFile == null) { /* * For whatever reason we cannot write the file to disk. */ throw new FileUploadException("Cannot write uploaded file to disk."); } // // The uploaded file is being stored on disk in a temporary location so move it to the desired file. // Files.move(outputFile, file, StandardCopyOption.REPLACE_EXISTING); } return this; } } ././@LongLink0000644000000000000000000000022700000000000011604 Lustar rootrootlibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-core/src/main/java/org/apache/commons/fileupload2/core/FileUploadFileCountLimitException.javalibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-core/src/main/java/org/apache/commons/fileu0000644000175000017500000000270615142145735032067 0ustar zigozigo/* * 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 * * https://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.core; /** * Signals that a request contains more files than the specified limit. */ public class FileUploadFileCountLimitException extends FileUploadSizeException { private static final long serialVersionUID = 2; /** * Constructs an instance. * * @param message The detail message (which is saved for later retrieval by the {@link #getMessage()} method) * @param limit The limit that was exceeded. * @param actual The actual value. */ public FileUploadFileCountLimitException(final String message, final long limit, final long actual) { super(message, limit, actual); } } ././@LongLink0000644000000000000000000000020400000000000011577 Lustar rootrootlibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-core/src/main/java/org/apache/commons/fileupload2/core/RequestContext.javalibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-core/src/main/java/org/apache/commons/fileu0000644000175000017500000000477715142145735032101 0ustar zigozigo/* * 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 * * https://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.core; import java.io.IOException; import java.io.InputStream; import java.nio.charset.Charset; import java.nio.charset.UnsupportedCharsetException; import org.apache.commons.io.Charsets; /** * Abstracts access to the request information needed for file uploads. *

* This interface should be implemented for each type of request that may be handled by FileUpload, such as servlets and portlets. *

*/ public interface RequestContext { /** * Gets the character encoding for the request. * * @return The character encoding for the request. */ String getCharacterEncoding(); /** * Gets the character encoding for the request or null if unspecified. * * @return The character encoding for the request or null. * @throws UnsupportedCharsetException If the named Charset is unavailable. */ default Charset getCharset() throws UnsupportedCharsetException { return Charsets.toCharset(getCharacterEncoding(), null); } /** * Gets the content length of the request. * * @return The content length of the request. */ long getContentLength(); /** * Gets the content type of the request. * * @return The content type of the request. */ String getContentType(); /** * Gets the input stream for the request. * * @return The input stream for the request. * @throws IOException if a problem occurs. */ InputStream getInputStream() throws IOException; /** * Is the Request of type {@code multipart/related}? * * @return the Request is of type {@code multipart/related} * @since 2.0.0 */ boolean isMultipartRelated(); } ././@LongLink0000644000000000000000000000021100000000000011575 Lustar rootrootlibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-core/src/main/java/org/apache/commons/fileupload2/core/FileItemHeadersImpl.javalibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-core/src/main/java/org/apache/commons/fileu0000644000175000017500000000522115142145735032062 0ustar zigozigo/* * 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 * * https://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.core; import java.util.ArrayList; import java.util.Collections; import java.util.Iterator; import java.util.LinkedHashMap; import java.util.List; import java.util.Locale; import java.util.Map; /** * Default implementation of the {@link FileItemHeaders} interface. */ class FileItemHeadersImpl implements FileItemHeaders { /** * Map of {@code String} keys to a {@code List} of {@code String} instances. */ private final Map> headerNameToValueListMap = new LinkedHashMap<>(); /** * Method to add header values to this instance. * * @param name name of this header * @param value value of this header */ @Override public synchronized void addHeader(final String name, final String value) { headerNameToValueListMap.computeIfAbsent(toLowerCase(name), k -> new ArrayList<>()).add(value); } /** * {@inheritDoc} */ @Override public String getHeader(final String name) { final var headerValueList = getList(name); if (null == headerValueList) { return null; } return headerValueList.get(0); } /** * {@inheritDoc} */ @Override public Iterator getHeaderNames() { return headerNameToValueListMap.keySet().iterator(); } /** * {@inheritDoc} */ @Override public Iterator getHeaders(final String name) { var headerValueList = getList(name); if (null == headerValueList) { headerValueList = Collections.emptyList(); } return headerValueList.iterator(); } private List getList(final String name) { return headerNameToValueListMap.get(toLowerCase(name)); } private String toLowerCase(final String value) { return value.toLowerCase(Locale.ROOT); } } ././@LongLink0000644000000000000000000000022400000000000011601 Lustar rootrootlibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-core/src/main/java/org/apache/commons/fileupload2/core/FileUploadContentTypeException.javalibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-core/src/main/java/org/apache/commons/fileu0000644000175000017500000000415015142145735032062 0ustar zigozigo/* * 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 * * https://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.core; /** * Signals that a request is not a multipart request. */ public class FileUploadContentTypeException extends FileUploadException { /** * The exceptions UID, for serializing an instance. */ private static final long serialVersionUID = 2; /** * The guilty content type. */ private String contentType; /** * Constructs an instance with the specified detail message. * * @param message The detail message (which is saved for later retrieval by the {@link #getMessage()} method) * @param contentType The guilty content type. */ public FileUploadContentTypeException(final String message, final String contentType) { super(message); this.contentType = contentType; } /** * Constructs an instance with the specified detail message and cause. * * @param message The detail message (which is saved for later retrieval by the {@link #getMessage()} method) * @param cause the original cause */ public FileUploadContentTypeException(final String message, final Throwable cause) { super(message, cause); } /** * Gets the content type. * * @return the content type. */ public String getContentType() { return contentType; } } ././@LongLink0000644000000000000000000000017600000000000011607 Lustar rootrootlibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-core/src/main/java/org/apache/commons/fileupload2/core/FileItem.javalibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-core/src/main/java/org/apache/commons/fileu0000644000175000017500000001605715142145735032073 0ustar zigozigo/* * 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 * * https://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.core; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.nio.charset.Charset; import java.nio.file.InvalidPathException; import java.nio.file.Path; /** *

* This class represents a file or form item that was received within a {@code multipart/form-data} POST request. *

*

* After retrieving an instance of this class from a {@link AbstractFileUpload FileUpload} instance (see * {@code org.apache.commons.fileupload2.core.servlet.ServletFileUpload #parseRequest(javax.servlet.http.HttpServletRequest)}), you may either request all * contents of the file at once using {@link #get()} or request an {@link InputStream} with {@link #getInputStream()} and process the file without attempting to * load it into memory, which may come handy with large files. *

*

* While this interface does not extend {@code javax.activation.DataSource} (to avoid a seldom used dependency), several of the defined methods are specifically * defined with the same signatures as methods in that interface. This allows an implementation of this interface to also implement * {@code javax.activation.DataSource} with minimal additional work. *

* * @param The FileItem type. */ public interface FileItem> extends FileItemHeadersProvider { /** * Deletes the underlying storage for a file item, including deleting any associated temporary disk file. Use this method to ensure that this is done at an * earlier time, to preserve resources. * * @return {@code this} instance. * @throws IOException if an error occurs. */ F delete() throws IOException; /** * Gets the contents of the file item as a byte array. * * @return The contents of the file item as a byte array. * @throws IOException if an I/O error occurs */ byte[] get() throws IOException; /** * Gets the content type passed by the browser or {@code null} if not defined. * * @return The content type passed by the browser or {@code null} if not defined. */ String getContentType(); /** * Gets the name of the field in the multipart form corresponding to this file item. * * @return The name of the form field. */ String getFieldName(); /** * Gets an {@link java.io.InputStream InputStream} that can be used to retrieve the contents of the file. * * @return An {@link java.io.InputStream InputStream} that can be used to retrieve the contents of the file. * @throws IOException if an error occurs. */ InputStream getInputStream() throws IOException; /** * Gets the original file name in the client's file system, as provided by the browser (or other client software). In most cases, this will be the base file * name, without path information. However, some clients, such as the Opera browser, do include path information. * * @return The original file name in the client's file system. * @throws InvalidPathException The file name contains a NUL character, which might be an indicator of a security attack. If you intend to use the file name * anyways, catch the exception and use InvalidFileNameException#getName(). */ String getName(); /** * Gets an {@link java.io.OutputStream OutputStream} that can be used for storing the contents of the file. * * @return An {@link java.io.OutputStream OutputStream} that can be used for storing the contents of the file. * @throws IOException if an error occurs. */ OutputStream getOutputStream() throws IOException; /** * Gets the size of the file item. * * @return The size of the file item, in bytes. */ long getSize(); /** * Gets the contents of the file item as a String, using the default character encoding. This method uses {@link #get()} to retrieve the contents of the * item. * * @return The contents of the item, as a string. * * @throws IOException if an I/O error occurs */ String getString() throws IOException; /** * Gets the contents of the file item as a String, using the specified encoding. This method uses {@link #get()} to retrieve the contents of the item. * * @param toCharset The character encoding to use. * @return The contents of the item, as a string. * @throws IOException if an I/O error occurs */ String getString(Charset toCharset) throws IOException; /** * Tests whether or not a {@code FileItem} instance represents a simple form field. * * @return {@code true} if the instance represents a simple form field; {@code false} if it represents an uploaded file. */ boolean isFormField(); /** * Tests a hint as to whether or not the file contents will be read from memory. * * @return {@code true} if the file contents will be read from memory; {@code false} otherwise. */ boolean isInMemory(); /** * Sets the field name used to reference this file item. * * @param name The name of the form field. * @return {@code this} instance. */ F setFieldName(String name); /** * Sets whether or not a {@code FileItem} instance represents a simple form field. * * @param state {@code true} if the instance represents a simple form field; {@code false} if it represents an uploaded file. * @return {@code this} instance. */ F setFormField(boolean state); /** * Writes an uploaded item to disk. *

* The client code is not concerned with whether or not the item is stored in memory, or on disk in a temporary location. They just want to write the * uploaded item to a file. *

*

* This method is not guaranteed to succeed if called more than once for the same item. This allows a particular implementation to use, for example, file * renaming, where possible, rather than copying all of the underlying data, thus gaining a significant performance benefit. *

* * @param file The {@code File} into which the uploaded item should be stored. * @throws IOException if an error occurs. * @return {@code this} instance. */ F write(Path file) throws IOException; } ././@LongLink0000644000000000000000000000020500000000000011600 Lustar rootrootlibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-core/src/main/java/org/apache/commons/fileupload2/core/FileItemFactory.javalibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-core/src/main/java/org/apache/commons/fileu0000644000175000017500000001430115142145735032061 0ustar zigozigo/* * 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 * * https://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.core; import org.apache.commons.io.FileCleaningTracker; import org.apache.commons.io.build.AbstractStreamBuilder; import org.apache.commons.io.file.PathUtils; /** * Creates {@link FileItem} instances. *

* Factories can provide their own custom configuration, over and above that provided by the default file upload implementation. *

* * @param The {@link FileItem} type this factory creates. */ public interface FileItemFactory> { /** * Abstracts building for subclasses. * * @param the type of {@link FileItem} to build. * @param the type of builder subclass. */ abstract class AbstractFileItemBuilder, B extends AbstractFileItemBuilder> extends AbstractStreamBuilder { /** * Create a new FileItemHeaders implementation. * * @return a new FileItemHeaders implementation. */ public static FileItemHeaders newFileItemHeaders() { return new FileItemHeadersImpl(); } /** * Field name. */ private String fieldName; /** * Content type. */ private String contentType; /** * Is this a form field. */ private boolean isFormField; /** * File name. */ private String fileName; /** * File item headers. */ private FileItemHeaders fileItemHeaders = newFileItemHeaders(); /** * The instance of {@link FileCleaningTracker}, which is responsible for deleting temporary files. *

* May be null, if tracking files is not required. *

*/ private FileCleaningTracker fileCleaningTracker; /** * Constructs a new instance. */ public AbstractFileItemBuilder() { setBufferSize(DiskFileItemFactory.DEFAULT_THRESHOLD); setPath(PathUtils.getTempDirectory()); } /** * Gets the content type. * * @return the content type. */ public String getContentType() { return contentType; } /** * Gets the field name. * * @return the field name. */ public String getFieldName() { return fieldName; } /** * Gets the file cleaning tracker. * * @return the file cleaning tracker. */ public FileCleaningTracker getFileCleaningTracker() { return fileCleaningTracker; } /** * Gets the field item headers. * * @return the field item headers. */ public FileItemHeaders getFileItemHeaders() { return fileItemHeaders; } /** * Gets the file name. * * @return the file name. */ public String getFileName() { return fileName; } /** * Tests whether this is a form field. * * @return whether this is a form field. */ public boolean isFormField() { return isFormField; } /** * Sets the content type. * * @param contentType the content type. * @return {@code this} instance. */ public B setContentType(final String contentType) { this.contentType = contentType; return asThis(); } /** * Sets the field name. * * @param fieldName the field name. * @return {@code this} instance. */ public B setFieldName(final String fieldName) { this.fieldName = fieldName; return asThis(); } /** * Sets the file cleaning tracker. * * @param fileCleaningTracker the file cleaning tracker. * @return {@code this} instance. */ public B setFileCleaningTracker(final FileCleaningTracker fileCleaningTracker) { this.fileCleaningTracker = fileCleaningTracker; return asThis(); } /** * Sets the file item headers. * * @param fileItemHeaders the item headers. * @return {@code this} instance. */ public B setFileItemHeaders(final FileItemHeaders fileItemHeaders) { this.fileItemHeaders = fileItemHeaders != null ? fileItemHeaders : newFileItemHeaders(); return asThis(); } /** * Sets the file name. * * @param fileName the file name. * @return {@code this} instance. */ public B setFileName(final String fileName) { this.fileName = fileName; return asThis(); } /** * Sets whether this is a form field. * * @param isFormField whether this is a form field. * @return {@code this} instance. */ public B setFormField(final boolean isFormField) { this.isFormField = isFormField; return asThis(); } } /** * Creates a new AbstractFileItemBuilder. * * @param The type of AbstractFileItemBuilder. * @return a new AbstractFileItemBuilder. */ > AbstractFileItemBuilder fileItemBuilder(); } ././@LongLink0000644000000000000000000000022700000000000011604 Lustar rootrootlibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-core/src/main/java/org/apache/commons/fileupload2/core/FileUploadByteCountLimitException.javalibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-core/src/main/java/org/apache/commons/fileu0000644000175000017500000000474015142145735032067 0ustar zigozigo/* * 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 * * https://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.core; /** * Signals that a file size exceeds the configured maximum. */ public class FileUploadByteCountLimitException extends FileUploadSizeException { /** * The exceptions UID, for serializing an instance. */ private static final long serialVersionUID = 2; /** * File name of the item, which caused the exception. */ private final String fileName; /** * Field name of the item, which caused the exception. */ private final String fieldName; /** * Constructs an instance with the specified detail message, and actual and permitted sizes. * * @param message The detail message (which is saved for later retrieval by the {@link #getMessage()} method) * @param actual The actual request size. * @param permitted The maximum permitted request size. * @param fileName File name of the item, which caused the exception. * @param fieldName Field name of the item, which caused the exception. */ public FileUploadByteCountLimitException(final String message, final long actual, final long permitted, final String fileName, final String fieldName) { super(message, permitted, actual); this.fileName = fileName; this.fieldName = fieldName; } /** * Gets the field name of the item, which caused the exception. * * @return Field name, if known, or null. */ public String getFieldName() { return fieldName; } /** * Gets the file name of the item, which caused the exception. * * @return File name, if known, or null. */ public String getFileName() { return fileName; } } ././@LongLink0000644000000000000000000000021400000000000011600 Lustar rootrootlibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-core/src/main/java/org/apache/commons/fileupload2/core/AbstractRequestContext.javalibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-core/src/main/java/org/apache/commons/fileu0000644000175000017500000000672215142145735032071 0ustar zigozigo/* * 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 * * https://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.core; import java.util.Objects; import java.util.function.Function; import java.util.function.LongSupplier; import java.util.regex.Pattern; /** * Abstracts a RequestContext for implementations. * * @param The request type. */ public abstract class AbstractRequestContext implements RequestContext { /** * The Content-Type Pattern for multipart/related Requests. */ private static final Pattern MULTIPART_RELATED = Pattern.compile("^\\s*multipart/related.*", Pattern.CASE_INSENSITIVE); /** * Supplies the content length default. */ private final LongSupplier contentLengthDefault; /** * Supplies the content length string. */ private final Function contentLengthString; /** * The request. */ private final T request; /** * Constructs a new instance. * * @param contentLengthString How to get the content length string. * @param contentLengthDefault How to get the content length default. * @param request The request. */ protected AbstractRequestContext(final Function contentLengthString, final LongSupplier contentLengthDefault, final T request) { this.contentLengthString = Objects.requireNonNull(contentLengthString, "contentLengthString"); this.contentLengthDefault = Objects.requireNonNull(contentLengthDefault, "contentLengthDefault"); this.request = Objects.requireNonNull(request, "request"); } /** * Gets the content length of the request. * * @return The content length of the request. */ @Override public long getContentLength() { try { return Long.parseLong(contentLengthString.apply(AbstractFileUpload.CONTENT_LENGTH)); } catch (final NumberFormatException e) { return contentLengthDefault.getAsLong(); } } /** * Gets the request. * * @return the request. */ public T getRequest() { return request; } /** * Tests whether the Request of type {@code multipart/related}? * * @return whether the Request is of type {@code multipart/related} * @since 2.0.0 */ @Override public boolean isMultipartRelated() { return MULTIPART_RELATED.matcher(getContentType()).matches(); } /** * Returns a string representation of this object. * * @return a string representation of this object. */ @Override public String toString() { return String.format("%s [ContentLength=%s, ContentType=%s]", getClass().getSimpleName(), getContentLength(), getContentType()); } } ././@LongLink0000644000000000000000000000021300000000000011577 Lustar rootrootlibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-core/src/main/java/org/apache/commons/fileupload2/core/FileItemInputIterator.javalibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-core/src/main/java/org/apache/commons/fileu0000644000175000017500000001127615142145735032071 0ustar zigozigo/* * 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 * * https://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.core; import java.io.IOException; import javax.naming.SizeLimitExceededException; import org.apache.commons.io.function.IOIterator; /** * An iterator, as returned by {@link AbstractFileUpload#getItemIterator(RequestContext)}. */ public interface FileItemInputIterator extends IOIterator { /** * Gets the maximum size of a single file. An {@link FileUploadByteCountLimitException} will be thrown, if there is an uploaded file, which is exceeding * this value. By default, this value will be copied from the {@link AbstractFileUpload#getMaxFileSize() FileUploadBase} object, however, the user may * replace the default value with a request specific value by invoking {@link #setFileSizeMax(long)} on this object. * * @return The maximum size of a single, uploaded file. The value -1 indicates "unlimited". */ long getFileSizeMax(); /** * Gets the maximum size of the complete HTTP request. A {@link SizeLimitExceededException} will be thrown, if the HTTP request will exceed this value. By * default, this value will be copied from the {@link AbstractFileUpload#getMaxSize() FileUploadBase} object, however, the user may replace the default * value with a request specific value by invoking {@link #setSizeMax(long)} on this object. * * @return The maximum size of the complete HTTP request. The value -1 indicates "unlimited". */ long getSizeMax(); /** * Tests whether another instance of {@link FileItemInput} is available. * * @throws FileUploadException Parsing or processing the file item failed. * @throws IOException Reading the file item failed. * @return True, if one or more additional file items are available, otherwise false. */ @Override boolean hasNext() throws IOException; /** * Returns the next available {@link FileItemInput}. * * @throws java.util.NoSuchElementException No more items are available. Use {@link #hasNext()} to prevent this exception. * @throws FileUploadException Parsing or processing the file item failed. * @throws IOException Reading the file item failed. * @return FileItemInput instance, which provides access to the next file item. */ @Override FileItemInput next() throws IOException; /** * Sets the maximum size of a single file. An {@link FileUploadByteCountLimitException} will be thrown, if there is an uploaded file, which is exceeding * this value. By default, this value will be copied from the {@link AbstractFileUpload#getMaxFileSize() FileUploadBase} object, however, the user may * replace the default value with a request specific value by invoking {@link #setFileSizeMax(long)} on this object, so there is no need to configure it * here. *

* Note: Changing this value doesn't affect files, that have already been uploaded. *

* * @param fileSizeMax The maximum size of a single, uploaded file. The value -1 indicates "unlimited". */ void setFileSizeMax(long fileSizeMax); /** * Sets the maximum size of the complete HTTP request. A {@link SizeLimitExceededException} will be thrown, if the HTTP request will exceed this value. By * default, this value will be copied from the {@link AbstractFileUpload#getMaxSize() FileUploadBase} object, however, the user may replace the default * value with a request specific value by invoking {@link #setSizeMax(long)} on this object. *

* Note: Setting the maximum size on this object will work only, if the iterator is not yet initialized. In other words: If the methods * {@link #hasNext()}, {@link #next()} have not yet been invoked. *

* * @param sizeMax The maximum size of the complete HTTP request. The value -1 indicates "unlimited". */ void setSizeMax(long sizeMax); } ././@LongLink0000644000000000000000000000021100000000000011575 Lustar rootrootlibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-core/src/main/java/org/apache/commons/fileupload2/core/FileUploadException.javalibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-core/src/main/java/org/apache/commons/fileu0000644000175000017500000000365215142145735032070 0ustar zigozigo/* * 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 * * https://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.core; import java.io.IOException; /** * Signals errors encountered while processing the request. */ public class FileUploadException extends IOException { /** * Serial version UID, being used, if the exception is serialized. */ private static final long serialVersionUID = 2; /** * Constructs an instance with a given detail message. * * @param message The detail message (which is saved for later retrieval by the {@link #getMessage()} method) */ public FileUploadException(final String message) { super(message); } /** * Constructs an instance with the given detail message and cause. * * @param message The detail message (which is saved for later retrieval by the {@link #getMessage()} method) * @param cause The cause (which is saved for later retrieval by the {@link #getCause()} method). (A null value is permitted, and indicates that the cause * is nonexistent or unknown.) */ public FileUploadException(final String message, final Throwable cause) { super(message, cause); } } ././@LongLink0000644000000000000000000000021100000000000011575 Lustar rootrootlibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-core/src/main/java/org/apache/commons/fileupload2/core/DiskFileItemFactory.javalibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-core/src/main/java/org/apache/commons/fileu0000644000175000017500000002561315142145735032071 0ustar zigozigo/* * 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 * * https://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.core; import java.nio.charset.Charset; import java.nio.file.Path; import org.apache.commons.io.FileCleaningTracker; import org.apache.commons.io.build.AbstractOrigin; import org.apache.commons.io.build.AbstractStreamBuilder; import org.apache.commons.io.file.PathUtils; /** * The default {@link FileItemFactory} implementation. *

* This implementation creates {@link 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. *

*

* If not otherwise configured, the default configuration values are as follows: *

*
    *
  • Size threshold is 10 KB.
  • *
  • Repository is the system default temporary directory, as returned by {@code System.getProperty("java.io.tmpdir")}.
  • *
*

State model: The created instances of {@link DiskFileItem} are subject to a carefully designed state model, * which is also controlled by the threshold. Therefore, it is strongly recommended to set the threshold explicitly, using * {@link Builder#setThreshold(int)}. Details * on the state model can be found {@link DiskFileItem here}.

*

* NOTE: Files are created in the system default temporary directory with predictable names. This means that a local attacker with write access * to that directory can perform a TOUTOC attack to replace any uploaded file with a file of the attackers choice. The implications of this will depend on how * the uploaded file is used, but could be significant. When using this implementation in an environment with local, untrusted users, * {@link Builder#setPath(Path)} MUST be used to configure a repository location that is not publicly writable. In a Servlet container the location identified * by the ServletContext attribute {@code javax.servlet.context.tempdir} may be used. *

*

* Temporary files, which are created for file items, should be deleted later on. The best way to do this is using a {@link FileCleaningTracker}, which you can * set on the {@link DiskFileItemFactory}. However, if you do use such a tracker, then you must consider the following: Temporary files are automatically * deleted as soon as they are no longer needed. (More precisely, when the corresponding instance of {@link java.io.File} is garbage collected.) This is done by * the so-called reaper thread, which is started and stopped automatically by the {@link FileCleaningTracker} when there are files to be tracked. It might make * sense to terminate that thread, for example, if your web application ends. See the section on "Resource cleanup" in the users guide of Commons FileUpload. *

* * @see Builder * @see Builder#get() */ public final class DiskFileItemFactory implements FileItemFactory { /** * Builds a new {@link DiskFileItemFactory} instance. *

* For example: *

* *
{@code
     * DiskFileItemFactory factory = DiskFileItemFactory.builder().setPath(path).setBufferSize(DEFAULT_THRESHOLD).get();
     * }
     * 
*/ public static class Builder extends AbstractStreamBuilder { /** * The instance of {@link FileCleaningTracker}, which is responsible for deleting temporary files. *

* May be null, if tracking files is not required. *

*/ private FileCleaningTracker fileCleaningTracker; /** * The threshold. We do maintain this separate from the {@link #getBufferSize()}, * because the parent class might change the value in {@link #setBufferSize(int)}. */ private int threshold; /** * Constructs a new instance. */ public Builder() { setBufferSize(DEFAULT_THRESHOLD); setPath(PathUtils.getTempDirectory()); setCharset(DiskFileItem.DEFAULT_CHARSET); setCharsetDefault(DiskFileItem.DEFAULT_CHARSET); } /** * Constructs a new instance. *

* This builder use the aspects Path and buffer size. *

*

* You must provide an origin that can be converted to a Reader by this builder, otherwise, this call will throw an * {@link UnsupportedOperationException}. *

* * @return a new instance. * @throws UnsupportedOperationException if the origin cannot provide a Path. * @see AbstractOrigin#getReader(Charset) */ @Override public DiskFileItemFactory get() { return new DiskFileItemFactory(this); } /** * Equivalent to {@link #getThreshold()}. * @return The threshold, which is being used. * @see #getThreshold() * @deprecated Since 2.0.0, use {@link #getThreshold()} instead. */ public int getBufferSize() { return getThreshold(); } /** * Returns the threshold. * @return The threshold. */ public int getThreshold() { return threshold; } /** * Equivalent to {@link #setThreshold(int)}. * @param bufferSize The threshold, which is being used. * @see #setThreshold(int) * @return This builder. * @deprecated Since 2.0.0, use {@link #setThreshold(int)} instead. */ @Override public Builder setBufferSize(final int bufferSize) { return setThreshold(bufferSize); } /** * Sets the tracker, which is responsible for deleting temporary files. * * @param fileCleaningTracker Callback to track files created, or null (default) to disable tracking. * @return {@code this} instance. */ public Builder setFileCleaningTracker(final FileCleaningTracker fileCleaningTracker) { this.fileCleaningTracker = fileCleaningTracker; return this; } /** * Sets the threshold. The uploaded data is typically kept in memory, until * a certain number of bytes (the threshold) is reached. At this point, the * incoming data is transferred to a temporary file, and the in-memory data * is removed. * * The threshold will also control the state model of the created * instances of {@link DiskFileItem}. Details on the state model can be * found {@link DiskFileItem here}. * @param threshold The threshold, which is being used. * @return This builder. */ public Builder setThreshold(final int threshold) { this.threshold = threshold; return this; } } /** * The default threshold in bytes above which uploads will be stored on disk. */ public static final int DEFAULT_THRESHOLD = 10_240; /** * Constructs a new {@link Builder}. * * @return a new {@link Builder}. */ public static Builder builder() { return new Builder(); } /** * The directory in which uploaded files will be stored, if stored on disk. */ private final Path repository; /** * The threshold above which uploads will be stored on disk. */ private final int threshold; /** * The instance of {@link FileCleaningTracker}, which is responsible for deleting temporary files. *

* May be null, if tracking files is not required. *

*/ private final FileCleaningTracker fileCleaningTracker; /** * Default content Charset to be used when no explicit Charset parameter is provided by the sender. */ private final Charset charsetDefault; /** * Constructs a preconfigured instance of this class. * * @param repository The data repository, which is the directory in which files will be created, should the item size exceed the threshold. * @param threshold The threshold, in bytes, below which items will be retained in memory and above which they will be stored as a file. * @param charsetDefault Sets the default charset for use when no explicit charset parameter is provided by the sender. * @param fileCleaningTracker Callback to track files created, or null (default) to disable tracking. */ private DiskFileItemFactory(final Builder builder) { this.threshold = builder.threshold; this.repository = builder.getPath(); this.charsetDefault = builder.getCharset(); this.fileCleaningTracker = builder.fileCleaningTracker; } @SuppressWarnings("unchecked") @Override public DiskFileItem.Builder fileItemBuilder() { // @formatter:off return DiskFileItem.builder() .setThreshold(threshold) .setCharset(charsetDefault) .setFileCleaningTracker(fileCleaningTracker) .setPath(repository); // @formatter:on } /** * Gets the default charset for use when no explicit charset parameter is provided by the sender. * * @return the default charset */ public Charset getCharsetDefault() { return charsetDefault; } /** * Gets the tracker, which is responsible for deleting temporary files. * * @return An instance of {@link FileCleaningTracker}, or null (default), if temporary files aren't tracked. */ public FileCleaningTracker getFileCleaningTracker() { return fileCleaningTracker; } /** * Gets the directory used to temporarily store files that are larger than the configured size threshold. * * @return The directory in which temporary files will be located. */ public Path getRepository() { return repository; } /** * Gets the size threshold beyond which files are written directly to disk. The default value is {@value #DEFAULT_THRESHOLD} bytes. * * @return The size threshold in bytes. */ public int getThreshold() { return threshold; } } ././@LongLink0000644000000000000000000000020500000000000011600 Lustar rootrootlibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-core/src/main/java/org/apache/commons/fileupload2/core/FileItemHeaders.javalibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-core/src/main/java/org/apache/commons/fileu0000644000175000017500000000525215142145735032066 0ustar zigozigo/* * 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 * * https://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.core; import java.util.Iterator; /** * This class provides support for accessing the headers for a file or form item that was received within a {@code multipart/form-data} POST request. */ public interface FileItemHeaders { /** * Adds a header. * * @param name name * @param value value. */ void addHeader(String name, String value); /** * Gets the value of the specified part header as a {@code String}. *

* If the part did not include a header of the specified name, this method return {@code null}. If there are multiple headers with the same name, this * method returns the first header in the item. The header name is case insensitive. *

* * @param name a {@code String} specifying the header name * @return a {@code String} containing the value of the requested header, or {@code null} if the item does not have a header of that name */ String getHeader(String name); /** * Gets an {@code Iterator} of all the header names. * * @return an {@code Iterator} containing all of the names of headers provided with this file item. If the item does not have any headers return an empty * {@code Iterator} */ Iterator getHeaderNames(); /** * Gets all the values of the specified item header as an {@code Iterator} of {@code String} objects. *

* If the item did not include any headers of the specified name, this method returns an empty {@code Iterator}. The header name is case insensitive. *

* * @param name a {@code String} specifying the header name * @return an {@code Iterator} containing the values of the requested header. If the item does not have any headers of that name, return an empty * {@code Iterator} */ Iterator getHeaders(String name); } ././@LongLink0000644000000000000000000000020600000000000011601 Lustar rootrootlibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-core/src/main/java/org/apache/commons/fileupload2/core/ProgressListener.javalibcommons-fileupload2-java-2.0.0~M5/commons-fileupload2-core/src/main/java/org/apache/commons/fileu0000644000175000017500000000307715142145735032071 0ustar zigozigo/* * 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 * * https://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.core; /** * Receives progress information. May be used to display a progress bar. */ @FunctionalInterface public interface ProgressListener { /** * Nop implementation. */ ProgressListener NOP = (bytesRead, contentLength, items) -> { // nop }; /** * Updates the listeners status information. * * @param bytesRead The total number of bytes, which have been read so far. * @param contentLength The total number of bytes, which are being read. May be -1, if this number is unknown. * @param items The number of the field, which is currently being read. (0 = no item so far, 1 = first item is being read, ...) */ void update(long bytesRead, long contentLength, int items); } libcommons-fileupload2-java-2.0.0~M5/.gitattributes0000644000175000017500000000151315142145735021002 0ustar zigozigo# 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 # # https://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. * text=auto *.patch -text libcommons-fileupload2-java-2.0.0~M5/.asf.yaml0000644000175000017500000000306615142145735017627 0ustar zigozigo# 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 # # https://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. github: description: "Apache Commons FileUpload is a robust, high-performance, file upload capability to your servlets and web applications" homepage: https://commons.apache.org/fileupload/ labels: - java - fileupload - upload - apache notifications: commits: commits@commons.apache.org issues: issues@commons.apache.org pullrequests: issues@commons.apache.org jira_options: link label jobs: notifications@commons.apache.org # commits_bot_dependabot: dependabot@commons.apache.org issues_bot_dependabot: dependabot@commons.apache.org pullrequests_bot_dependabot: dependabot@commons.apache.org issues_bot_codecov-commenter: notifications@commons.apache.org pullrequests_bot_codecov-commenter: notifications@commons.apache.org libcommons-fileupload2-java-2.0.0~M5/src/0000755000175000017500000000000015142145735016676 5ustar zigozigolibcommons-fileupload2-java-2.0.0~M5/src/media/0000755000175000017500000000000015227714536017762 5ustar zigozigolibcommons-fileupload2-java-2.0.0~M5/src/media/logo.xcf0000644000175000017500000006132415142145735021425 0ustar zigozigogimp xcf file,dBB! gimp-commentCreated with The GIMPgimp-image-grid(style solid) (fgcolor (color-rgba 0 0 0 1)) (bgcolor (color-rgba 1 1 1 1)) (xspacing 10) (yspacing 10) (spacing-unit inches) (xoffset 0) (yoffset 0) (offset-unit inches) rA5C` TM!? "     T%$#gimp-text-layer(text "TM") (font "Sitka Small Bold") (font-size 12) (font-size-unit pixels) (antialias yes) (language "en-us") (base-direction ltr) (color (color-rgb 0 0 0)) (justify left) (box-mode dynamic) (box-unit pixels) (hinting yes) s  'tv*렬R$$P%Ӆ$Pk{&P$P{P$P,P$]'fDdp`;, Text Layer#2!? "     S0%$#>,Z,v    U8 U"q8U8U88qU88UqU88888U UUU8 U8 q 8 8qUUUUU q U8U U UqU U UU UU U U U UU q U  Uqq U UUU Uq qƪq qq UqƍUUU8qq888 U U8 U8U8   ? U UU 88 8UU888  U U U U U U UU8 UUUU U8UUUUq8UUUUqUUUUUUUUU UU UU U UUqU8UU8Uq U Uq q qqq8q UU Uq8 UU 8U8U8UU8 U$U:U:U:U:U:U:U97UqU83 q   8<U<U<U<U<U<U<U<U<U<U<U UU8UU qq  8UUUqUUU8 qUUqUUqU8Uq88UqU 88U qUƪqUU U qU  8U qq8U 8UU qUUq qUUUU 8888U Uq8UqUqU8UU8UU8ƪƪ8U8qUƍUq8 8qqU U88UUU UU8qUUUUUUUU8UUqUUUUUUUUUUUU8UqU88UU}f3 <Drop-Shadow#2h!> "     O,%$#<55<4L(i1/        !!  !     $).1332001342,$ #(+)$   '-28=BFGFDCEGHE=1$ *5=@>6*  %.5;?DJPUWWVUVYYUJ<,+:HSWTI9(&2=CFHKOV\`aa`acc]RB1"$4FXflhZG1 $3AKOOLKNSZ_ab\QA0!'9Ndt|xhQ9# /APYZUMGFIOTWXWRG9*&9Qi|qY>'  ':N^ecYLA;BEE .D^y}eO=/'#$)3@LTUOC3#+D`zzaE,$,27;?DJQVY ,B\w{bK9-%#'/=N]hjcS?++D`zzaE-(2:?ACEJQZci(=Wsu\E3'! &2CWjwzr`I2,DazzaF/! *6AHJIHGKR]jt #7QmoU=*#0D[q}iP7",DazzaG1%#*7EPUUPKGIP\ky2LhiN5#,AZrnT9$,DazzbH4)*5DT^a]UMGGMYiy.Hd}}eI0(=WqqV;%,DazzcI6.2?QakleZOHFKVdt ,Fb{{bF- $9SnqW<%,Daz{cK939I\lusj]PHEHP\i +DazzaE+ !6PkqW<&,Daz{dL<7?Qeu|xl]ND@AGOY *D`zz`D*  4OjqW<&,Daz{dM>;DWl{ykYJ>87:@F *D`zz`D* 3NiqW<&,Daz{eN?=H[pyhTB5-*+.2 *D`zz`D* 3MiqW<&,Daz{eN@>J]szgQ<-$! *D`zz`D* 3MiqW<&,Daz{eN@>J^t|hQ:) +DazzaD+ 3NiqW<&,Daz{eN?>I^tmU>* +DazzaD+ 3NiqW<&,Eaz{dM>;F[rv_G2# +Ea{{bE,  4OjrX='-Eaz{dM=9BVnkU@/$ -Gc||dG.  6PksY?)/Gc||eM<6=Og}zfSB6.++/Ie}}eJ0 #8Rlt[@+!1Id||eM;37F\swfWKB=;2Ke|}fL3 %:Smt\B- $4Ke{{fM:01>;3*!",4;=<7/&!)29==91($-5;>?>:4- "&))'" #'('$!&((%!  %')(%!                         &*-/.+&    $'(&#  &/9@EGE@90&  %.5:;93+"  $1?MX`c`YM@1$  $0BCB@ACHMRUTOG;."WOD5&-HggG, +:FIC7)$0?LV\\YVTUZ`fklh`SC2#jeXG5%.HhgG, +:FIC7* !,=Oantsngbadjqx}|vjXD2ywkYD0! /HhgG, +:FIC7*!$2F\q|riddiq{}lWAygP:( "0IhgG, +:FIC7*!%4Jcztf]Z]fs}hPoX@-#$1IhgG, +:FIC7* $3Jd}p]PJLUctu]~oYB/$%2IhgG, +:FIC7)!0Gb|~gRA99AQezgtxtfS>-#$1IhgG, +:EHB6(-C_yw_G4*)0?UmoaeaWG6( #1IggG, +:EHB6'*@[vqW>*#1GaztLNKC8+  /HfhH, +:EHB5&(>YsmR8$'=Wrv5750) .FeiI- ,:EGA4%'=XrjO5 !6Pkv#%$",DbjK/ ,,;EG?2$&0"&ED;. &CB:.!%1(#!"$)/6=BB=4' %6,!*>Uk{zl\NB941136;?BB?7,  %2.1:EPWWPC4OG>4( /CXiuywoeZPHC@??ACDC?8.#  %7.$  %JTZ\[XTPMJHEC?:4,#  $ZtpV=(   (@[uoU<' +C]vpW>().E^upX@+*.D[o}{kV@- ) -?SdptnbP>, )'6FT\_[RD6( ) +6@FHE?5+  ) %,01/+% +  +  -041 0  / !'**& / &1:??9." .%4COVUM>. . -?Rbjj_M8% .  1F\ozynYA+ . 2IavwaG/./Gax|fK1 ,D_whL2 )A\uiM3   &>YsiM3     %<JQROJGGKRXZUJ:*).#"+>XriO6%'4BMSRLC<76;DP\fkh^O>0''.;JV\ZSKEELV`fdZI6&*7:+&.@YriO8("'4DS]_YM@5-,0;IZitvpbP?307CR]`\RGAAIVeopgUA/%#+7FE3+0AYrjP:,)1ASbjg\K:,# $/?Rgw~r`M>847DYmz|q]E.*?YrxcN@;>EKLH@86:GZnnYG>AM^k[D77E[skS@8GXm~ucUR[lS?46DZrkTB;ATllP5  )@[tp_USX`ed\PC;;DUj}vdVR[lK903CZrkTA8=Nf~rW<& +B[rzk^Y\eouqfUF<:CUj}xfWRZkC3,2BZskS?58F]uw^E./E\ozzqd[Zbp|}p]K@>FXm{iYSXg{:-)0B[tlT>22>Ri}zfN8&$4H\kroeZUXevzgUIFM]rm\SVcu0'&0C\tmT>0-5F[o}zjVB1&!$,:KZdgaWNKRbvraUQVdvq_TS\l~'!#/C\tlT=.(,9K_nvuk\K<1,-4?KU[YQG@@I[q{l`[^hwsaTOS`q "/C[q|jS=,#$,;L\gjg]QE;66;BINNI@713=Oezrf``fq~q_QHIRa .AVivzrcN:)!,9HSZ\XPH@<;<@CC@90'#&0@Uixxnd\Y]eowysgXI?JRTPF9,#,39;;97420.+'""/=IQTRMF?::=CILJC9.% !' $.7<=;4+! "'*,+*)&$!  )28;:61+(')-143/' $(('"    #%%"             `      !"    &.462+!  (5BJLG<.  #3DT_b[M;( (;Pcptl[E/*?Vl{xfM5 )?XplS8")?XqpU:#  *?XqqW;$  !.BZsrW;$  !)6H_vsW<$ "%(-4@Qg|tX<$ !',0247>IZnuY<$ &/59;=CO_tvY<$ 4=CDB?<=CO`uwZ=$ CKMJD=87=I\rwZ=$ QVTLA7/-3@TkvY<$ ]_XK<.%#(5Jc|uY<$ heYH5&,B\utX<$ piYD0&;UpsX<$ wmYA+"7QlrW<$ |oY@) 4OjrW<$ r[@) 4NiqW;$ v^C* 3NiqW;$ {cG. 4OjrX<$ 莁jO5""6PlsY=% 葇rY?+';Uov[?' 蒌|eM8*#%/B[ty^B* r]I:22;Lbz|bF-狐~l[LDCIWk}dI1瀉xk^VSWaqzcI2 p}}tjb^_fp|r\E0 [isxxsmfa`bhpuvobP<*ES^ehgd_ZWVY]_^XM?0! 0;EMRTRNJFDDFFE@7-" '/5:<<9630/-)$ !%''%#      bn7 Text Layer!? "      %$#67CC7:=A8qU8Uq8q8q q UU88U U8qUqUUUqUUUqUUq8U8 U U 8q8 U8 q   8U 8U UU UU UU 8UU U8 88 U q 8888 q8 q8q UUUUqU U UUU U 8qU qq8UqUU8qU 8q8U88UqU8q qq88qqUUqUUqƪUqUUU8Uqq q8UUU 88UUqq UUUU UUUU UUUU UUUU UUUU UUUU UUUU UUUU UUUU UUUU UUUU UUUU UUUU UUUU UUUU  qUq qUqU8qU88qU8UƍUUUU8q qq q8  8qUU88qU 88 8UU UUUU8U8UUUUUUU UU8q 8UqUUU UUUUU 8UUUU UUUUU UUUU UUUU UUUUUU UUUUUU UUUUU UUUUUU UUUUU8 UUUU qUUUUq UUUUq 8UUUUUUUUqUqU88U UqqU8q8qUU 8Uq8 q 8VVV UU ⪪ 88888Uqqq88 q 8 qU qU  q q8qƪq888UUk 5$ Drop-ShadowD!> "      %$# D$D5``$DQL Th\   L           &.49<=<80% &-38<>=:4," & +7BJOTX\_^WI7%   -:CJOSWZ]]ZQE5% #1@L &8HTZ\\]bkwu_D*  )beD( ;eQ*=e]9 &BhoD$*Ky0V}zT0 )LtrI'.TwK'*Mzȳ\3 >m BmoD"  3QlxoV7 >ji<  8dŢrC  6f+Sd8 0BJE5"'M~_2)QϴR) 3c5b\0  $" /[ȷX, CuԿ^1 2b ?oX,   6e̸V*8iƝh8 2b !GxW+ ;lѺW+1_ʣn<2b $L¶Z-  >pԾZ-,Yʤp>2b%NǼa3 >o×a2*UȢn<2b %Mßl<  ;kɠj:)TÝh8 2b "I|ʬ}K& 6cΪvD +Vʼ_1 2b Bsѻa7  0YҴP(.[ıS) 2b8gɨ{O-  !,/*)K|Ӿ`35cuE! 2b-WӾpJ. )7@?2" =iŢrC!  @n`6 2b !EtϷpQ;-%#%,7EPQF2-SȰX1 *NzuJ&3c3[ͷgVLHJQZabXC+ m*Krƻs[@' -Lo|aI:35>Ocu|t]@% )Jw .MpĽw^C*  -IgveWPPV_hleT<% !8X~ -Gd~oX?)  )?Vjvyume`][SF4!  )A\z &:Napz~|uiYG4"   1AOY]][WSNH@5( (<82+# +7AIM !##       !$&      ?   @         !! (   ! )&(4>DE@6(  ,8AFFA6) !(*% ,8AFD=2# PI:+%*8HYgqtoaM6#,=N^ksuoaM5  (6EOOE4'%-mѽ`4  #5YʰW2 3Yʹ]6ĶnI, 6V~ƺuO1 6U}ĶpL2%$.Deb?&&AdıhEmO5!(>ZysU:&)>ZxnR<0/9LgcF-.GeiLzm[F1!'9Nbs~|q_K7&'9Nbs}zm[I90/7EWiw~vgT?,,@ViwykXDNLF<1$)5@HMOMG?4')5@HMNLF=3*%$)1;DJNNJC9-  -:DJNNKE;0&%# !$&$  !$&&%# #%&&%" "%&&%#         ?   A      "       "$0;CGE>2#  #+17;=><7/&  $+.+"%1$ .Hfmceo|acgn{a6 %A`y}kTA516CXra?$1MpʸnfejtOHEHTlwG"  <`yZ='&9Uw^9)DiãfTJHN_z6)$&1JpdzU+ 1WjD' 7Z~R.4ZuR:,'+;Y 3Zȼa3 #FrY1 !@kɽk? (M~Һb<#"@l&Lžj:1ZyJ$,T˰Q*"ExͱR+  1^  Fxţp??mo?  Bsҿb5 CuɫzH" +W  CvƦsA &K}i85cɣp? CuȨvD )T  BuƦtB",UÜf6,WέzG$!CuǧuB (R  BuǧtC#0[ƞg6&NвL'!CuǧuB (R  BuǧtC#2^ʢl: "H|гN("CuǧuB (R  BuǧuC#1^ͨs@  ExαL'!CuǧuB (R  BuǧuC#/YѰ}I"  DwʬzH$!CuǧuB (R  BuǧuC"*RԸS) FyĢp@ CuǧuB (R  BuǧuC!$Hza3 $K~ûc6 BuǧuB (R  BuǧuB 43:H\p|yfJ-  1X˰X3 "@k*'@cb@& &@]x{j[QOS\eki[E- "=b­c@'/Nu3!/GddG. "7Odsywpha^]]\WK:(  (CcdG/#7Sr0!-@Uhw~~vhU@-+=94.& *7CJNNJC:.!%2>G "%&&%"    "%&&%"  $      ?        -  &-13321/,)! U>' )8BGHJKNNI<) eE( 1FUZWRNMRZeljX< éf?  0LdmgXI@?GVj{~kI'W/&Fh}|hL6)'0B\upN*ɾm> 4[d@%+EaqhK)ȭ~K$ ?kf=  /I[XB%̷U* !EtsI( 3CE5 ̽\. Etc@'".0& `0 >leH1!a12\sXA.!b2%GrµlS=+ b2 0S{fL5" ˶b2 5UxȽx[?' b24PnŸeD(b2 .D^zf@"b2 %7MgĬ[3b2 )-$$,=XupM+ƾ}U4$@b|yeQB;;BPbquiP3 xX;$3Mcli_TLHINV^`YH2|}sbL5""3AHIGDCCEHJJD9*MOMH@4&"&()+-/121.' &$!     )p8 ,d Background!? "     %$#a,dbbbb,db8bDbPb\bhbtbbbb               0002K% libcommons-fileupload2-java-2.0.0~M5/src/changes/0000755000175000017500000000000015227714536020313 5ustar zigozigolibcommons-fileupload2-java-2.0.0~M5/src/changes/release-notes.vm0000644000175000017500000000715615142145735023431 0ustar zigozigo## 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 ## ## https://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. ${project.name} ${version} Release Notes ------------------------------------------------ The ${developmentTeam} is pleased to announce the release of ${project.name} ${version}. The Apache Commons FileUpload component provides a simple yet flexible means of adding support for multipart file upload functionality to Servlets and web applications. This version requires Java 11 or above. ## The available variables are described here: ## http://maven.apache.org/plugins/maven-changes-plugin/examples/using-a-custom-announcement-template.html ## ## Hack to improve layout: replace all pairs of spaces with a single new-line $release.description.replaceAll(" ", " ") ## set up indent sizes. Only change indent1 #set($props=${project.properties}) #set($jiralen=$props.get("commons.jira.id").length()) ## indent1 = POOL-nnnn: #set($blanklen=$jiralen+6)## +6 for "-nnnn:" ## must be at least as long as the longest JIRA id #set($blanks=" ") #set($indent1=$blanks.substring(0,$blanklen)) ## indent2 allows for issue wrapper #set($indent2="$indent1 ") ## #macro ( processaction ) ## Use replaceAll to fix up LF-only line ends on Windows. #set($action=$actionItem.getAction().replaceAll("\n"," ")) ## Fix up indentation for multi-line action descriptions #set($action=$action.replaceAll("(?m)^ +",$indent2)) #if ($actionItem.getIssue()) #set($issue="$actionItem.getIssue():") ## Pad shorter issue numbers #if ($issue.length() < $indent1.length())#set ($issue="$issue ")#end #if ($issue.length() < $indent1.length())#set ($issue="$issue ")#end #if ($issue.length() < $indent1.length())#set ($issue="$issue ")#end #else #set($issue=$indent1) #end #if ($actionItem.getDueTo()) #set($dueto=" Thanks to $actionItem.getDueTo().") #else #set($dueto="") #end o $issue ${action}$dueto #set($action="") #set($issue="") #set($dueto="") #end ## #if ($release.getActions().size() == 0) No changes defined in this version. #else Changes in version ${version} include: #if ($release.getActions('add').size() !=0) New features: #foreach($actionItem in $release.getActions('add')) #processaction() #end #end #if ($release.getActions('fix').size() !=0) Fixed Bugs: #foreach($actionItem in $release.getActions('fix')) #processaction() #end #end #if ($release.getActions('update').size() !=0) Changes: #foreach($actionItem in $release.getActions('update')) #processaction() #end #end #if ($release.getActions('remove').size() !=0) Removed: #foreach($actionItem in $release.getActions('remove')) #processaction() #end #end ## End of main loop #end For complete information on ${project.name}, including instructions on how to submit bug reports, patches, or suggestions for improvement, see the ${project.name} website: ${project.url} Download it from ${project.url}download_fileupload.cgi ------------------------------------------------------------------------------ libcommons-fileupload2-java-2.0.0~M5/src/changes/changes.xml0000644000175000017500000013560615142145735022453 0ustar zigozigo Apache Commons FileUpload Release Notes Apache Commons Developers Better exception message in org.apache.commons.fileupload2.core.AbstractFileUpload.parseRequest(RequestContext). Clarified the precise meaning of isInMemory(), get(), getPath(), etc. in DiskFileItem Better exception type and message if a multipart/mixed part is presented without a boundary defined Rename MultipartInput.Builder.[get|set]PartHeaderSizeMax() to [get|set]MaxPartHeaderSize(). Rename MultipartInput.getPartHeaderSizeMax() to getMaxPartHeaderSize(). Rename AbstractFileUpload.[get|set]SizeMax() to AbstractFileUpload.[get|set]MaxSize(). Rename AbstractFileUpload.[get|set]FileSizeMax() to AbstractFileUpload.[get|set]MaxFileSize(). Rename AbstractFileUpload.[get|set]FileCountMax() to AbstractFileUpload.[get|set]MaxFileCount(). Minor readability and cleanup improvements in DiskFileItem #458. Fix Apache RAT plugin console warnings. Add AbstractFileUpload support for a maximum part header size #429. Jakarta and Javax ServletFileUpload.isMultipartContent(HttpServletRequest) should allow PUT and PATCH request methods in addition to POST. Add AbstractFileUpload.isMultipartRequestMethod(String). Bump org.apache.commons:commons-parent from 84 to 96 #444, #459, #463. Bump org.apache.commons:commons-lang3 from 3.17.0 to 3.20.0 #427. Bump commons-io:commons-io from 2.19.0 to 2.21.0. Simplify exception handling in FileItem API #309. SECURITY - CVE-2025-48976. Add partHeaderSizeMax, a new limit that sets a maximum number of bytes for each individual multipart header. The default is 512 bytes. [site] Fix instantiation of DiskFileItemFactory in migration guide #273. [site] Update code example: Use IOUtils instead of Streams utils class. Replace internal use of Locale.ENGLISH with Locale.ROOT. Pick up JUnit version from parent POM. [site] Fix incorrect link to changes report in Commons FileUpload #357. Fix changes report link for new version of Maven Changes plugin from commons-parent 79 #388. Fix SpotBugs multithreading issues in DiskFileItem. Handle multipart/related Requests without content-disposition header. Bump org.apache.commons:commons-parent from 66 to 84 #283, #294, #335, #343, #345, #351, #356, #360, #368. Bump commons-io:commons-io from 2.16.0 to 2.19.0 #297, #352, #377. Bump org.apache.maven.plugins:maven-javadoc-plugin from 3.6.3 to 3.7.0 #319. Bump org.codehaus.mojo:taglist-maven-plugin from 3.0.0 to 3.1.0 #327. Bump org.apache.commons:commons-lang3 from 3.14.0 to 3.17.0 #331, #338, #346. Fix off-by-one error when checking fileSizeMax in FileItemInputImpl #235. NullPointerException in DiskFileItem#toString. Fail fast on null inputs to org.apache.commons.fileupload2.core.AbstractRequestContext.AbstractRequestContext(Function, LongSupplier, T). Complete refactoring in JakartaServletRequestContext. Fix "Implicit narrowing conversion in compound assignment" from https://github.com/apache/commons-fileupload/security/code-scanning/118. Pick up Maven Moditect plugin version from parent POM. Refactor to support Jakarta Servlet 5 and 6. Generate some OSGi metadata. Bump Java from 8 to 11. Bump commons-parent from 58 to 65. Bump commons-lang3 from 3.12.0 to 3.14.0. Bump commons-io from 2.13.0 to 2.16.0 #291. Changing Maven coordinates, and package name, due to binary incompatible changes. DiskFileItem.write(File) had been changed to use FileUtils.moveFile internally, preventing an existing file as the target. Performance gains by reusing an internal buffer. RFC 5987 compliance Slight optim: resuse the index position instead of recomputing it #49. Make commons-fileupload2 a JPMS module by adding module-info.class. Move Exception classes out of the impl package. Rework exceptions to use propagated exception causes (introduced in Java 1.4). All custom exception extend FileUploadException. All custom exceptions serialVersionUID value is now 2. FileUploadByteCountLimitException ctor switches fileName and fieldName parameters #216. [StepSecurity] ci: Harden GitHub Actions #224. Add github/codeql-action from #144. Add the package org.apache.fileupload2.jaksrvlt, for compliance with Jakarta Servlet API 5.0. Making FileUploadException a subclass of IOException. (Mibor API simplification.) Add a configurable limit (disabled by default) for the number of files to upload per request. Remove deprecated constructors in MultipartStream. Remove deprecated RequestContext.getContentLength(). Remove deprecated JakSrvltRequestContext.getContentLength(). Remove deprecated PortletRequestContext.getContentLength(). Remove deprecated ServletRequestContext.getContentLength(). Remove deprecated FileUploadBase.MAX_HEADER_SIZE. Remove deprecated FileUploadBase.createItem(Map, boolean). Remove deprecated FileUploadBase.getFieldName(Map). Remove deprecated FileUploadBase.getFileName(Map). Remove deprecated FileUploadBase.getHeader(Map, String). Remove deprecated FileUploadBase.parseHeaders(String). Replace org.apache.commons.fileupload2.util.mime.Base64Decoder with java.util.Base64. Replace LimitedInputStream with BoundedInputStream. FileItemHeadersImpl is no longer Serializable. Reuse Java's InvalidPathException instead of the custom InvalidFileNameException. Bump actions/cache from 2.1.6 to 3.0.8 #128, #140. Bump actions/checkout from 2.3.4 to 3.0.2 #125. Bump build actions/setup-java from 1.4.3 to 3.8.0 #142, #175, #180, #182. Bump Java compiler level to 1.8. Bump commons-io:commons-io 2.6 to 2.13.0, #104, #221. Bump junit-jupiter from 5.5.2 to 5.9.1 #31, #130, #156, #166. Bump maven-pmd-plugin from 3.13.0 to 3.19.0 #48, #162. Bump commons.japicmp.version from 0.13.0 to 0.16.0. Bump spotbugs-maven-plugin from 4.2.3 to 4.7.3.0 #103, #133, #141, #146, #155, #163, #179. Bump spotbugs from 4.2.3 to 4.7.3, ignore EI_EXPOSE_REP, and EI_EXPOSE_REP2, #152, #161, #174. Bump biz.aQute.bndlib from 6.0.0 to 6.4.0 #129, #181. Bump commons-parent from 52 to 58, #167, #183, #194. Bump maven-checkstyle-plugin from 3.1.2 to 3.2.0 #160. [1.x] Enable multipart/related on FileUpload #314. Add JApiCmp to the default Maven goal. Add partHeaderSizeMax, a new limit that sets a maximum number of bytes for each individual multipart header. The default is 512 bytes. Replace use of Locale.ENGLISH with Locale.ROOT. Remove unused exception from FileUploadBase.createItem(Map, boolean). Migrate from deprecated API in DiskFileItem.getOutputStream(). Use try-with-resources. Port to Java 1.4 Throwable APIs (!). Remove -nouses directive from maven-bundle-plugin. OSGi package imports now state 'uses' definitions for package imports, this doesn't affect JPMS (from org.apache.commons:commons-parent:80). DiskFileItem.getInputStream() now uses NIO. Last statement in DiskFileItem.finalize() method should be a call to super.finalize(). org.apache.commons.fileupload.FileUploadBase.FileUploadIOException is now a proper Java 1.4-style exception (propagates its cause to super). Use java.util.Base64 instead of custom code. Bump Java from 6 to 8. Bump org.apache.commons:commons-parent from 62 to 84, upgrades Doxia from 1 to 2. Bump commons-io from 2.11.0 to 2.19.0. Bump javax.servlet:servlet-api from 2.4 to 2.5. Bump JUnit from junit:junit:4.13.2 org.junit.vintage:junit-vintage-engine from parent POM. Bump Commons IO to 2.11.0 DiskFileItem.write(File) had been changed to use FileUtils.moveFile internally, preventing an existing file as the target Improve parsing speed Switch from Cobertura code coverage to Jacoco code coverage Add a configurable limit (disabled by default) for the number of files to upload per request Bump JUnit to 4.13.2 Don't create un-needed resources in FileUploadBase.java Upversion complier.source, compiler.target to 1.6 DiskFileItem#write() could lose original IO exception DiskFileItem#getStoreLocation() wrongly returned a File object for items stored in memory FileUploadBase - should not silently catch and ignore all Throwables Fix Javadoc 1.8.0 errors Fix section "Resource cleanup" of the user guide Fix streaming example: use FileItem.getInputStream() instead of openStream() DiskFileItem might suppress critical IOExceptions on rename - use FileUtil.move instead DiskFileItem#getTempFile() is broken FileUploadBase - potential resource leak - InputStream not closed on exception DiskFileItem.readObject fails to close FileInputStream FileUpload should use IOUtils.closeQuietly where relevant DiskFileItem.get() may not fully read the data Make some MultipartStream private fields final Site: added security report Improve performance for large multi-part boundaries Added the default character set to the DiskFileItem. Avoid using File.exists() on temporary files, if we know that the file has been created. Added .travis.yml, to fix build issues on Github. DiskDileItem can actually no longer be deserialized, unless a system property is set to true. SECURITY - CVE-2016-3092. Performance Improvement in MultipartStream. SECURITY - CVE-2016-3092. Specially crafted input can trigger a DoS, if the size of the MIME boundard is close to the size of the buffer in MultipartStream. (Similar to CVE-2014-0050.) SECURITY - CVE-2014-0050. Specially crafted input can trigger a DoS if the buffer used by the MultipartStream is not big enough. When constructing MultipartStream enforce the requirements for buffer size by throwing an IllegalArgumentException if the requested buffer size is too small. This prevents the DoS. When deserializing DiskFileItems ensure that the repository location, if any, is a valid one. Correct example in usage documentation so it compiles. SECURITY - CVE-2013-0248. Update the Javadoc and documentation to make it clear that setting a repository is required for a secure configuration if there are local, untrusted users. Update the project tree dirs according to default Maven conventions drop JDK1.3 support and update to Java5 Update version in POM upgrade tests to JUnit 4 replace package.html with package-info.java FileItemHeadersImpl can now use LinkedHashMap Mark @deprecated classes/methods with @Deprecated annotation Base64Decoder doesn't correctly implement RFC 4648 "Stream ended unexpectedly" when posting from a Flash client Manifest for OSGi has invalid syntax commons-io dependency does not get loaded by maven if only dependency to commons-fileupload is specified https://commons.apache.org/fileupload/index.html is out of date https://commons.apache.org/fileupload/index.html should not mention nightly builds DiskFileItemFactory use of FileCleaningTracker is documented or coded wrong - proposal submitted by Jan Novotný Error reading the file size larger than 2 gb - pull request from Gergely ServletFileUpload isMultipartContent method does not support HTTP PUT - thanks Roy T. Fielding and Jochen Wiedmann Uploads have unexpected results for files with non-ASCII names - support RFC2047 - thanks Thomas Neidhart Exceptions resulting from upload size limitations (fileSizeMax, sizeMax) are now correctly propagated to the caller (these could be encountered formerly as MalformedStreamException: "Stream ended unexpectedly"). FileItem.getHeaders() returns always null. The sizeMax parameter within FileUpload is now correctly enforced if no content length header is provided. ServletFileUpload only accepts POST requests (Servlet|Portlet)RequestContext#contentLength() must return request.getContentLength() if Content-length header is not available toLowerCase() is Locale-dependent; should use toLowerCase(Locale.ENGLISH) instead There are no unit tests for the new utils.mime classes Documentation: add simple HTML form example to fileupload user guide enhance file read/write performance - patch provided by frank Add Support for Generic Types Process HTTP Requests Into Maps Update commons-io dependency to latest version that supports JDK1.5 Avoid string concatenations while parsing headers, use buffers instead Replace java.rmi.server.UID() with java.util.UUID DiskFileItem.counter could be converted to AtomicInteger (or AtomicLong?) Private immutable fields which could be final Update to JDK 1.5 and bump IO dependency to 2.0.1 version 1.3 improvement tasks Added a check for file names containing a NULL characters. Such file names are now triggering an InvalidFileNameException since the file name cannot be used as provided to create the file since it will be truncated at the NUL character on most (all?) operating systems. E.g. a file name like "test.foo0.bar" would result in "test.foo" being created. Temporary files have not been deleted, if an error occurred in FileUploadBase.parseRequest(); Fixed example in MultipartStream Javadocs. Ensured, that the ProgressListener is called for all items. Made the ProgressNotifier public. Multiple documentation fixes. Fixed the error message for FileSizeLimitExceededException from "too many characters" to "too many bytes". A FileSizeLimitExceededException does now contain the file and field name of the item, which caused the problem. The FileItemHeader stuff hasn't been actually working. Upgrade to commons-io-1.4-SNAPSHOT, in order to use the new FileCleaningTracker and fix issues with FileCleaner. Made the MockHttpServletRequest comply to the servlet 2.4 specification by applying http://www.sourcelabs.com/dashboards/sash-1.2/patches/commons-fileupload-1.1-1/SUP-520.diff Added support for accessing the file item headers. A MalformedStreamException is now thrown, if the size of an items headers exceeds HEADER_PART_SIZE_MAX; DiskFileItem.toString() could throw an NPE. Short files could cause an unexpected end of the item stream. A FileSizeLimitExceededException was deferred until the complete file has been uploaded. Additionally, the FileSizeLimitException is now thrown immediately, if the attachments headers contain a content-length value, which exceeds the configured limit. Fixed a classpath problem when building with Sun JDK 1.3.1 and Ant. Made Streams.asString static. Eliminated duplicate code. Added a streaming API. Eliminated the necessity of a content-length header. Eliminated the limitation of a maximum size for a single header line. (The total size of all headers is already limited, so there's no need for another limit.) Added the ProgressListener, which allows to implement a progress bar. Added support for header continuation lines. It is now possible to limit the actual file size and not the request size. Added the FileCleanerCleanup as an example for how to close down the FileCleaner's reaper thread nicely. A descriptive NPE is now thrown, if the FileItemFactory has not been set. Cache disk file item size when it is moved to a new location. File names were being inadvertently converted to lower case. Updates for FileUpload 1.1-RC1. Added release notes for FileUpload 1.1. Update the User Guide to document the "right" way of using FileUpload 1.1, rather than the older, and thus deprecated, ways that are compatible with FileUpload 1.0. Add this change log, including all changes since the Commons FileUpload 1.0 release. Update Commons IO dependency to version 1.1. Add custom PMD configuration. Make inner exception classes static, which they should have been all along. Fix Checkstyle warnings. Remove Javadoc warnings. Build updates: (1) Include NOTICE.txt in the jar file and distributions. (2) Include xdocs in source distribution. (3) Create MD5 checksums for distributions. Add custom Checkstyle configuration. Update dependencies in POM, and add comments and scope. Standardise on @throws instead of having a mixture of that and @exception. Make DiskFileItem serializable. Thanks to Niall Pemberton for the suggestion and patch. Make the temporary file names unique across class loaders, not just within them, by including a UID in the file name. Include the actual and permitted sizes in both the exception message and the exception itself. If an explicit header encoding is not specified, use the one from the appropriate context (i.e. ServletRequest or ActionRequest). Add getCharacterEncoding to the request context. Null check and case insensitivity fixes. Web site updates: (1) Add detail pages for Source Repository and Issue Tracking, based on those for IO and Validator. (2) Improvements to FileUpload home page, based on similar recent changes to IO and Validator home pages. (3) The Bugzilla component name has a space in it. Fix the URLs. (4) Add an FAQ page, using the Maven plugin to generate it. Fixes to POMs Setting source and target for Java 1.3 Fix typos in Javadoc code examples. Fix typos in exception messages. Obtain request content type from container instead of headers. New mock objects from Jetspeed-2, and new FileUpload test cases. added toString() methods Fix up the existing package.html file and add new ones for the newly introduced packages. Fairly minimal, but with a link to the user guide. Substantial refactoring and additions: (1) The core package is now independent of servlet / portlet / other distinctions, as well as persistence schemes, other than deprecated classes and methods retained for backwards compatibility. (2) Servlet specific functionality has been moved to a new 'servlet' package. Existing users should migrate to this as soon as possible, since the servlet specific functionality in the generic package will be removed in the release after FileUpload 1.1. (3) Support for portlets (JSR 168) has been added, in a new 'portlet' package. This is not well tested at this point, and feedback would be very much appreciated. (This also resolves bug #23620.) (4) The disk-based file item implementation has been moved into a 'disk' package, and renamed from Default* to Disk* to reflect what it really is. The Default* classes have been retained in the top level package for backwards compatibility, but are now deprecated, and will be removed in the release after FileUpload 1.1. (5) The isMultipartRequest method is an unfortunate casualty of this refactoring. That method should really be moved to ServletFileUpload, but since the method is static, it can only exist in either FileUploadBase or ServletFileUpload. Backwards compatibility dictates the former for now, but the latter is the desired state, which implies some future breakage. Fair warning... Specify the encoding (ISO-8859-1) when converting the boundary to a byte array. Convert to Sun coding guidelines. DeferredFileOutputStream moved to Commons IO. Workaround for Mac IE5 bug. Thanks to Justin Sampson for the patch and tests for this vexing issue. Handle unquoted header parameters. Some documentation on interaction with virus scanners. More unit tests from Justin Sampson. Use FileCleaner from Commons IO to clean up temp files, rather than File.deleteOnExit(), which can cause serious problems in long-running processes. Check that HTTP method is POST as part of multipart check. Switch to Commons IO version of DeferredFileOutputStream. Adding IO as a dependency will allow us to take advantage of other classes in that component to fix additional FileUpload bugs. handle quoted boundary specification. use case-independent comparisons for encoding types. Fix comments to avoid break iterator complaints. Fix typos in comments. Add support for character sets specified for individual parts. Change to Apache License 2.0 Correct the comment for the no-args constructor to reflect the fact that a factory needs to be set before parsing uploads. Collapse some all but duplicated code. Fix example showing FileItem.write to use a File object. Check for null before attempting to close streams in write(). Correction to sample code in the docs. libcommons-fileupload2-java-2.0.0~M5/src/site/0000755000175000017500000000000015227714536017647 5ustar zigozigolibcommons-fileupload2-java-2.0.0~M5/src/site/xdoc/0000755000175000017500000000000015227714536020604 5ustar zigozigolibcommons-fileupload2-java-2.0.0~M5/src/site/xdoc/issue-tracking.xml0000644000175000017500000001370515142145735024257 0ustar zigozigo Apache Commons FileUpload Issue tracking Apache Commons Team

Apache Commons FileUpload uses ASF JIRA for tracking issues. See the Apache Commons FileUpload JIRA project page.

To use JIRA you may need to create an account (if you have previously created/updated Commons issues using Bugzilla an account will have been automatically created and you can use the Forgot Password page to get a new password).

If you would like to report a bug, or raise an enhancement request with Apache Commons FileUpload please do the following:

  1. Search existing open bugs. If you find your issue listed then please add a comment with your details.
  2. Search the mailing list archive(s). You may find your issue or idea has already been discussed.
  3. Decide if your issue is a bug or an enhancement.
  4. Submit either a bug report or enhancement request.

Please also remember these points:

  • the more information you provide, the better we can help you
  • test cases are vital, particularly for any proposed enhancements
  • the developers of Apache Commons FileUpload are all unpaid volunteers

For more information on creating patches see the Apache Contributors Guide.

You may also find these links useful:

libcommons-fileupload2-java-2.0.0~M5/src/site/xdoc/streaming.xml0000644000175000017500000000657515142145735023327 0ustar zigozigo The Streaming API

The traditional API, which is described in the User Guide, assumes that file items must be stored somewhere before they are actually accessable by the user. This approach is convenient, because it allows easy access to an items contents. On the other hand, it is memory and time consuming.

The streaming API allows you to trade a little bit of convenience for optimal performance and a low memory profile. Additionally, the API is more lightweight, thus easier to understand.

Again, the FileUpload class is used for accessing the form fields and fields in the order in which they have been sent by the client. However, the FileItemFactory is completely ignored.

First of all, do not forget to ensure that a request actually is a a file upload request. This is typically done using the same static method, which you already know from the traditional API.

Now we are ready to parse the request into its constituent items. Here's how we do it:

{ String name = item.getFieldName(); InputStream stream = item.getInputStream(); if (item.isFormField()) { System.out.println("Form field " + name + " with value " + IOUtils.toString(stream, Charset.defaultCharset()) + " detected."); } else { System.out.println("File field " + name + " with file name " + item.getName() + " detected."); // Process the input stream ... } });]]>

That's all that's needed. Really!

libcommons-fileupload2-java-2.0.0~M5/src/site/xdoc/mail-lists.xml0000644000175000017500000002171715142145735023407 0ustar zigozigo Apache Commons FileUpload Mailing Lists Apache Commons Team

Apache Commons FileUpload shares mailing lists with all the other Commons Components. To make it easier for people to only read messages related to components they are interested in, the convention in Commons is to prefix the subject line of messages with the component's name, for example:

  • [fileupload] Problem with the ...

Questions related to the usage of Apache Commons FileUpload should be posted to the User List.
The Developer List is for questions and discussion related to the development of Apache Commons FileUpload.
Please do not cross-post; developers are also subscribed to the user list.
You must be subscribed to post to the mailing lists. Follow the Subscribe links below to subscribe.

Note: please don't send patches or attachments to any of the mailing lists; most of the lists are set up to drop attachments. Patches are best handled via the Issue Tracking system. If you have a GitHub account, most components also accept PRs (pull requests). Otherwise, please upload the file to a public server and include the URL in the mail.

Please prefix the subject line of any messages for Apache Commons FileUpload with [fileupload] - thanks!

Name Subscribe Unsubscribe Post Archive Other Archives
Commons User List

Questions on using Apache Commons FileUpload.

Subscribe Unsubscribe Post lists.apache.org www.mail-archive.com
Commons Developer List

Discussion of development of Apache Commons FileUpload.

Subscribe Unsubscribe Post lists.apache.org www.mail-archive.com
Commons Issues List

Only for e-mails automatically generated by the issue tracking system.

Subscribe Unsubscribe read only lists.apache.org www.mail-archive.com
Commons Commits List

Only for e-mails automatically generated by the source control system.

Subscribe Unsubscribe read only lists.apache.org www.mail-archive.com

Other mailing lists which you may find useful include:

Name Subscribe Unsubscribe Post Archive Other Archives
Apache Announce List

General announcements of Apache project releases.

Subscribe Unsubscribe read only lists.apache.org www.mail-archive.com
libcommons-fileupload2-java-2.0.0~M5/src/site/xdoc/index.xml0000644000175000017500000000767015142145735022442 0ustar zigozigo Home Martin Cooper

The Commons FileUpload package makes it easy to add robust, high-performance, file upload capability to your servlets and web applications.

FileUpload parses HTTP requests which conform to RFC 1867, "Form-based File Upload in HTML". That is, if an HTTP request is submitted using the POST method, and with a content type of "multipart/form-data", then FileUpload can parse that request, and make the results available in a manner easily used by the caller.

Starting with version 1.3, FileUpload handles RFC 2047 encoded header values.

The simplest way to send a multipart/form-data request to a server is via a web form, i.e.

File to upload:
Notes about the file:

to upload the file! ]]>

The following documentation is available:

You can also browse the Git repository.

  • Download the binary and source distributions from the download site.

The Apache Commons mailing lists act as the main support forum. The user list is suitable for most library usage queries. The dev list is intended for development discussion. Please remember that the lists are shared between all commons components, so prefix your e-mail subject line with [fileupload].

Issues may be reported via ASF JIRA.

libcommons-fileupload2-java-2.0.0~M5/src/site/xdoc/security.xml0000644000175000017500000002300615142145735023171 0ustar zigozigo Commons FileUpload Security Reports Apache Commons Team

This page lists all security vulnerabilities fixed in released versions of Apache Commons FileUpload. Each vulnerability is given a security impact rating by the development team - please note that this rating may vary from platform to platform. We also list the versions of Commons FileUpload the flaw is known to affect, and where a flaw has not been verified list the version with a question mark.

Please note that binary patches are never provided. If you need to apply a source code patch, use the building instructions for the Commons FileUpload version that you are using.

If you need help on building Commons FileUpload or other help on following the instructions to mitigate the known vulnerabilities listed here, please send your questions to the public Commons Users mailing list.

If you have encountered an unlisted security vulnerability or other unexpected behavior that has security impact, or if the descriptions here are incomplete, please report them privately to the Apache Security Team. Thank you.

For information about reporting or asking questions about security problems, please see the security page of the Apache Commons project.

Important: Denial of Service CVE-2025-48976

Apache Commons FileUpload 2.x before 2.0.0-M4 provides a hard-coded limit of 10kB for the size of the headers associated with a multipart request. A specially crafted request that used a large number of parts with large headers could trigger excessive memory usage on the server leading to a DoS. This limit is now configurable (FileUploadBase#setPartHeaderSizeMax) with a default of 512 bytes.

This was fixed in commit e5b5543b.

Affects: 2.0.0-M1 - 2.0.0-M4

Starting in version 2.0.0-M1, no FileUpload classes implement Serializable.

Important: Denial of Service CVE-2025-48976

Apache Commons FileUpload 1.x before 1.6.0 provides a hard-coded limit of 10kB for the size of the headers associated with a multipart request. A specially crafted request that used a large number of parts with large headers could trigger excessive memory usage on the server leading to a DoS. This limit is now configurable (FileUploadBase#setPartHeaderSizeMax) with a default of 512 bytes.

This was fixed in commit 2108495a.

Affects: 1.0 - 1.5

Important: Denial of Service CVE-2023-24998

Apache Commons FileUpload before 1.5 does not provide an option to limit the number of request parts to be processed resulting in the possibility of an attacker triggering a DoS with a malicious upload or series of uploads. Note that, like all of the file upload limits, the new configuration option (FileUploadBase#setFileCountMax) is not enabled by default and must be explicitly configured.

This was fixed in commit e20c0499.

Affects: 1.0? - 1.4

Up to, and including version 1.3.2, the class org.apache.commons.fileupload2.disk.DiskFileItem can be serialized and deserialized. A malicious attacker can abuse this feature to arbitrarily create files with any content, assuming the required permissions for a given file location. If an attacker gets the opportunity to provide maliciously crafted data and an application puts no limitations on classes being deserialized, that data can then be deserialized by a Java application.

We hold the view that the actual problem is not the DiskFileItem class, but that a Java application should carefully consider which classes can be deserialized. A typical approach would be, for example, to provide a deny list, or an accept list of packages, and/or classes, which may, or may not be deserialized.

We acknowledge that the likelihood of application container vendors taking such a simple security measure is extremely low. In order to better support Commons FileUpload users, we chose a different approach.

Starting with version 1.3.3, the class DiskFileItem still implements the interface java.io.Serializable but attempts to deserialize an instance of DiskFileItem will trigger an Exception. In the unlikely case, that your application depends on the deserialization of DiskFileItems, you can revert to the previous behavior by setting the system property "org.apache.commons.fileupload.disk.DiskFileItem.serializable" to "true".

Low: Denial of Service CVE-2016-3092

Specially crafted input can trigger a DoS (slow uploads), if the size of the MIME boundary is close to the size of the buffer in MultipartStream. This is also fixed for Apache Tomcat.

This was fixed in revision 1743480.

Affects: 1.0? - 1.3.1

Low: Denial of Service CVE-2014-0050

MultipartStream.java in Apache Commons FileUpload before 1.3.1, as used in Apache Tomcat, JBoss Web, and other products, allows remote attackers to cause a denial of service (infinite loop and CPU consumption) via a crafted Content-Type header that bypasses a loop's intended exit conditions.

This was fixed in revision 1565143.

Affects: 1.0? - 1.3

Low: Improved Documentation for Multitenancy CVE-2013-0248

Update the Javadoc and documentation to make it clear that setting a repository is required for a secure configuration if there are local, untrusted users.

This was fixed in revision 1453273.

Affects: 1.0 - 1.2.2

Please report any errors or omissions to the dev mailing list.

libcommons-fileupload2-java-2.0.0~M5/src/site/xdoc/customizing.xml0000644000175000017500000000244415142145735023700 0ustar zigozigo Customizing FileUpload Martin Cooper

TODO: Document usage of factories and subclassing for customization.

libcommons-fileupload2-java-2.0.0~M5/src/site/xdoc/download_fileupload.xml0000644000175000017500000002507515142145735025345 0ustar zigozigo Download Apache Commons FileUpload Apache Commons Team

We recommend you use a mirror to download our release builds, but you must verify the integrity of the downloaded files using signatures downloaded from our main distribution directories. Recent releases (48 hours) may not yet be available from all the mirrors.

You are currently using [preferred]. If you encounter a problem with this mirror, please select another mirror. If all mirrors are failing, there are backup mirrors (at the end of the mirrors list) that should be available.

[if-any logo]Logo[end]

Other mirrors:

It is essential that you verify the integrity of downloaded files, preferably using the PGP signature (*.asc files); failing that using the SHA512 hash (*.sha512 checksum files).

The KEYS file contains the public PGP keys used by Apache Commons developers to sign releases.

commons-fileupload2-2.0.0-M5-bin.tar.gz sha512 pgp
commons-fileupload2-2.0.0-M5-bin.zip sha512 pgp
commons-fileupload2-2.0.0-M5-src.tar.gz sha512 pgp
commons-fileupload2-2.0.0-M5-src.zip sha512 pgp
commons-fileupload-1.6.0-bin.tar.gz sha512 pgp
commons-fileupload-1.6.0-bin.zip sha512 pgp
commons-fileupload-1.6.0-src.tar.gz sha512 pgp
commons-fileupload-1.6.0-src.zip sha512 pgp

Older releases can be obtained from the archives.

libcommons-fileupload2-java-2.0.0~M5/src/site/xdoc/overview.xml0000644000175000017500000000424315142145735023172 0ustar zigozigo FileUpload Overview Robert Burrell Donkin

Your application should detect whether or not FileUpload should be invoked, based on the HTTP method and the content type of the request.

Assuming that you have decided that FileUpload should be invoked, you might write the following code to handle a file upload request: items = upload.parseRequest(request); // Process the uploaded fields for (DiskFileItem item :items) { if (item.isFormField()) { processTextParameter(request, item); } else { processFileParameter(request, item); } } ]]>

libcommons-fileupload2-java-2.0.0~M5/src/site/xdoc/using.xml0000644000175000017500000005050415142145735022452 0ustar zigozigo Using FileUpload Martin Cooper Gary Gregory

FileUpload can be used in a number of different ways, depending upon the requirements of your application. In the simplest case, you will call a single method to parse the servlet request, and then process the list of items as they apply to your application. At the other end of the scale, you might decide to customize FileUpload to take full control of the way in which individual items are stored; for example, you might decide to stream the content into a database.

Here, we will describe the basic principles of FileUpload, and illustrate some of the simpler - and most common - usage patterns. Customization of FileUpload is described elsewhere.

FileUpload depends on Commons IO, so make sure you have the version mentioned on the dependencies page in your classpath before continuing.

A file upload request comprises an ordered list of items that are encoded according to RFC 1867, "Form-based File Upload in HTML". FileUpload can parse such a request and provide your application with a list of the individual uploaded items. Each such item implements the FileItem interface, regardless of its underlying implementation.

This page describes the traditional API of the commons fileupload library. The traditional API is a convenient approach. However, for ultimate performance, you might prefer the faster Streaming API.

Each file item has a number of properties that might be of interest for your application. For example, every item has a name and a content type, and can provide an InputStream to access its data. On the other hand, you may need to process items differently, depending upon whether the item is a regular form field - that is, the data came from an ordinary text box or similar HTML field - or an uploaded file. The FileItem interface provides the methods to make such a determination, and to access the data in the most appropriate manner.

FileUpload creates new file items using a FileItemFactory. This is what gives FileUpload most of its flexibility. The factory has ultimate control over how each item is created. The factory implementation that currently ships with FileUpload stores the item's data in memory or on disk, depending on the size of the item (i.e. bytes of data). However, this behavior can be customized to suit your application.

Starting with version 1.1, FileUpload supports file upload requests in both servlet and portlet environments. The usage is almost identical in the two environments, so the remainder of this document refers only to the servlet environment.

If you are building a portlet application, the following are the two distinctions you should make as you read this document:

  • Where you see references to the JakartaServletFileUpload class, substitute the JavaxPortletFileUpload class.
  • Where you see references to the HttpServletRequest class, substitute the ActionRequest class.

Version 2 of FileUpload introduces support for the Jakarta Servlet API 5. (This API is the successor to the classic servlet environment, which basically renames the javax.servlet package to jakarta.servlet). If you are building a Jakarta Servlet application, keep the following in mind, as you read this document:

  • Where you see references to the ServletFileUpload class, substitute the JakartaServletFileUpload class.
  • Likewise, references to the FileCleanerCleanup class should be substituted with the JakartaServletFileCleaner class.
  • Where you see references to the HttpServletRequest class (as in javax.servlet.http.HttpServletRequest), then substitute the jakarta.servlet.http.HttpServletRequest class. This could be as simple as changing a single import statement.

Before you can work with the uploaded items, of course, you need to parse the request itself. Ensuring that the request is actually a file upload request is straightforward, but FileUpload makes it simplicity itself, by providing a static method to do just that.

Now we are ready to parse the request into its constituent items.

The simplest usage scenario is the following:

  • Uploaded items should be retained in memory as long as they are reasonably small.
  • Larger items should be written to a temporary file on disk.
  • Very large upload requests should not be permitted.
  • The built-in defaults for the maximum size of an item to be retained in memory, the maximum permitted size of an upload request, and the location of temporary files are acceptable.

Handling a request in this scenario couldn't be much simpler:

items = upload.parseRequest(request);]]>

That's all that's needed. Really!

The result of the parse is a List of file items, each of which implements the FileItem interface. Processing these items is discussed below.

If your usage scenario is close to the simplest case, described above, but you need a little more control, you can easily customize the behavior of the upload handler or the file item factory or both. The following example shows several configuration options:

items = upload.parseRequest(request);]]>

Of course, each of the configuration methods is independent of the others, but if you want to configure the factory all at once, you can do that with an alternative constructor, like this:

Should you need further control over the parsing of the request, such as storing the items elsewhere - for example, in a database - you will need to look into customizing FileUpload.

Once the parse has completed, you will have a List of file items that you need to process. In most cases, you will want to handle file uploads differently from regular form fields, so you might process the list like this:

For a regular form field, you will most likely be interested only in the name of the item, and its String value. As you might expect, accessing these is very simple.

For a file upload, there are several different things you might want to know before you process the content. Here is an example of some of the methods you might be interested in.

With uploaded files, you generally will not want to access them via memory, unless they are small, or unless you have no other alternative. Rather, you will want to process the content as a stream, or write the entire file to its ultimate location. FileUpload provides simple means of accomplishing both of these.

Note that, in the default implementation of FileUpload, write() will attempt to rename the file to the specified destination, if the data is already in a temporary file. Actually copying the data is only done if the the rename fails, for some reason, or if the data was in memory.

If you do need to access the uploaded data in memory, you need simply call the get() method to obtain the data as an array of bytes.

This section applies only, if you are using the DiskFileItem. In other words, it applies, if your uploaded files are written to temporary files before processing them.

Such temporary files are deleted automatically, if they are no longer used (more precisely, if the corresponding instance of DiskFileItem is garbage collected. This is done silently by the org.apache.commons.io.FileCleanerTracker class, which starts a reaper thread.

This reaper thread should be stopped, if it is no longer needed. In a servlet environment, this is done by using a special servlet context listener, called JakartaFileCleaner. To do so, add a section like the following to your web.xml:

... org.apache.commons.fileupload2.jakarta.JakartaFileCleaner ... ]]>

The JakartaFileCleaner provides an instance of org.apache.commons.io.FileCleaningTracker. This instance must be used when creating a org.apache.commons.fileupload2.core.DiskFileItemFactory. This should be done by calling a method like the following:

To disable tracking of temporary files, you may set the FileCleaningTracker to null. Consequently, created files will no longer be tracked. In particular, they will no longer be deleted automatically.

Virus scanners running on the same system as the web container can cause some unexpected behaviors for applications using FileUpload. This section describes some of the behaviors that you might encounter, and provides some ideas for how to handle them.

The default implementation of FileUpload will cause uploaded items above a certain size threshold to be written to disk. As soon as such a file is closed, any virus scanner on the system will wake up and inspect it, and potentially quarantine the file - that is, move it to a special location where it will not cause problems. This, of course, will be a surprise to the application developer, since the uploaded file item will no longer be available for processing. On the other hand, uploaded items below that same threshold will be held in memory, and therefore will not be seen by virus scanners. This allows for the possibility of a virus being retained in some form (although if it is ever written to disk, the virus scanner would locate and inspect it).

One commonly used solution is to set aside one directory on the system into which all uploaded files will be placed, and to configure the virus scanner to ignore that directory. This ensures that files will not be ripped out from under the application, but then leaves responsibility for virus scanning up to the application developer. Scanning the uploaded files for viruses can then be performed by an external process, which might move clean or cleaned files to an "approved" location, or by integrating a virus scanner within the application itself. The details of configuring an external process or integrating virus scanning into an application are outside the scope of this document.

If you expect really large file uploads, then it would be nice to report to your users, how much is already received. Even HTML pages allow to implement a progress bar by returning a multipart/replace response, or something like that.

Watching the upload progress may be done by supplying a progress listener:

Do yourself a favour and implement your first progress listener just like the above, because it shows you a pitfall: The progress listener is called quite frequently. Depending on the servlet engine and other environment factory, it may be called for any network packet! In other words, your progress listener may become a performance problem! A typical solution might be, to reduce the progress listeners activity. For example, you might emit a message only, if the number of megabytes has changed:

Hopefully this page has provided you with a good idea of how to use FileUpload in your own applications. For more detail on the methods introduced here, as well as other available methods, you should refer to the Javadocs.

The usage described here should satisfy a large majority of file upload needs. However, should you have more complex requirements, FileUpload should still be able to help you, with it's flexible customization capabilities.

libcommons-fileupload2-java-2.0.0~M5/src/site/resources/0000755000175000017500000000000015227714536021661 5ustar zigozigolibcommons-fileupload2-java-2.0.0~M5/src/site/resources/images/0000755000175000017500000000000015227714536023126 5ustar zigozigolibcommons-fileupload2-java-2.0.0~M5/src/site/resources/images/logo.png0000644000175000017500000003602215142145735024572 0ustar zigozigoPNG  IHDR,d< iCCPICC profile(}=H@_SR*V␡:Ŋ8*Bi+`r41$).kŪ "%/)=BT/edSIP\ s yx{zYJdO$N0ݰ׉g6->qU%xҠ ?r]vsag|v8L,VzXaV5Ti⨢j/\V8oqV ֹ'a-Ns )," Dh:,hH1?3U#<6Br[rBIŶ?Ɓ.nmO3pu-`fWCuW`I ɑ4rx?o*÷@p O]-D<=ۿg:ڊrubKGD pHYs  tIME 9hutEXtCommentCreated with The GIMPd%n IDATx}y|UE7 Ϩ@Htz$@$ (-&@ЖidU`mGPYd!a,@ ,amey ABSSnݷ$!zs?ǭ[۩osSI&d?0Ƙ9 &d?C`I&eI&dI&dI&d X&dI&`dI&`dI&eI&dI&dI&d X&dI&`dI?i ~PVT<:D=kRcg]僚cMNI5;wjի}֭[͛X3]}5|M͛7{)p:w޺zܹvɓ'(v͚5|l66ai&a6fe{ 6hv͛74~z6fiXΝ;DZ;vdSXX֬Yn>שٳ֭[)ulƍlݺuO>޻w.:ysKIIaΝ;cEEE\jп %8\^^gܸq,--mܸʹdN}wT%nx5련Hkaa!+**bofņ7%fcg=+**b,??w1CDDcnRNXI;ofӓÒtuݛwrJ6g]={2gagEEE|q9NN8ҥK9`o@[TTٍ7YDD~˜N'Yiid].PJP_egg[nRoܿۿq5k hsssŋeoܸ ٽ{ph*99ݹsj.sss˕ r$SQQsBctiVXXn޼ Xnn.bbbt/^rrr8ʒVffF{.W~~>s:Bv7`Nݾ}R{׿5ӰZ(//Gee%\. BPPrJwѬY3j  D`` tuCyy9***uP٤$l۶ ż_͛u܀JltfҴʕ+x饗zjDDD1 ˅*޽{8o@=b <#*\.n1cǎiv1N={t^{ n^Bv퐞l\rK,/XYY)۲eK/e1tP|s mڴCBBP^^*n200O>$޽sÍ7гgOA.Mqq1ΝcǢ~|ީon-[Dzz‹/Ѡ ^ gϞ_4&_/_c񜗃5Z4hGiif Պ-Z ..NAII 810e{FBii)JKKQQQ ϪUtuJJJ7I=FDGGc̙(++`).`X,[Wm۶x)]5.eeeqzjo] 1:- _"M2ݺuCii)/OI:h9NV#Â 4`շo_<補g+ϥjŌ38~8Fee%n7L4 ]v(nAAAX,GDD܅ 4cRUUbiy1ƿM} A9}ӤZ,4+4DEE|q<. ҋ/RΘX,: ų>crӉ+VpغQF\*$PgՕmذ!*** ^z CΝue: ߪ6h@#Q{aZy*WSO>D^<,XygϞ1 ,hy.CCCѧO]3fPnv"Ɔ@\_ll\AA*++58bŊ| Wh~ҦoXlJT dq9::Z V!!!|h7o˗/DOLpBM:tP."Eׯn#?q!@z8HTEHUu*h(./$$DYN:n ò234&\|ZV%K>ׯ_HBS”|@j5(A>sL[9m..ۑ#GfnX8hUKEN~D|ס݄@bhlp F%= wE:)UL~EG,# U*qv"ň*X 6SpQ*T6mp裏j%S~CsN:is3g$ƓӧOk6q#ԩӔ`8qB $@e8wYzGP^=XV#??_W/IȨN:)QCU"~ ¢@Ig|'1*<}Q vsF_U9#ѽ'ێ|`+7 *ily%:0fa„ ϟ?#11uHQSˤZ'O&P:F*cz#~_>W5 w7ER-\. )??'CESj቏Qe<<)+yd4M4䪚,Vg.ͅ4gWYٳhӦ Nk׮ڷL KE"UhP )JXF⸸+`TjW&mC񷜯[=ձȱs.q1Y2OߓUgjOcm66m¨Q [|9^x̟?_c?TMR1u`_$-Dr:tH #R"a´;Vu6/%ΥQd/3gbϞ=hܸ򽼼<SO=oK= w Dv2d W?O/?u*[] w 'Ni _5&=@RD*?rW;C6m~t&PrrGj]54TscoѣgW^1wyW^d&~_ 99qr\)eІr+((9sp84oFLH`X]HnW#9rDs|F>|85jap4~x<}q/tEDD`ذa:'W?Go ve Nj/Xj -[Dvv6N>]v)DڷoݎTb`Ϟ=8uᢤ:_z%ǣK.hժBBB|*D4oޜ$=z4x, { %%%@vv6 q%l۷/fZYY K4nfPD?y"&S ŜF4"hȉ`kbPEaaaT ITv#(({ʒdII,11KvݚMi1S{ldܥCQYX'XJŲrb h. EjTS?18TTe'HGAlt2HWiQp7D0D`vkj/e^(F ~Kn ˩}TV٩NX/BOVĹA}FL-WɥFȷ_&4E2ɉL;V- LhuU&OѹOLJ]Dc rd)P>$p%eCBBt/ļAAAdԩ;i1(+.>OꥺUb(#$TkUs)#_?qlT6 *~Pev5ZV U6-9S'OcpFoRd)DN+˫2WIxFezEiKVeyY=r/eUi(8|ˆU^FmT|GQ<ޒ_T %Jj%f 'ۗdQ&\%yqSJF/UVVt-ݎV0jWyQz+kc$]M)`]V }ퟑJiU'7UL2Wv.2j䄪OYY/1:޾j /z4.̉ĵL%«[?à- _e`v۪&sX Xu9g&`Tp8(c  1xnn.-ZÁI&n+wxORTzz2b]?RPAm9y$tu~jު3G&`!-X@-nǖ-[jJ#>>^gtmzz:7"$&j+zRdvر#l6!wم=H)?==G/8l۶M:-*==GaRՙ`F<۶mC||<{9JNBV_"++KĻpBlܸ='OĢEp)%c'1!X@999|ȔH4nXy00l6M:M醲Hdff*ë9T\\S'OSŲ{q1SNp87orÇ^dP8~2XƍQVVmsHIIABB.\ 奢cim:)&$$`ǎd:w̜?mRs/}vdff=~a̙{-@m.%~qA,hʔ)@Nr\;LɓyVoʒО={0b޽{1c ##{ADD.Xz)tUS^^.7XHn xtQd(1AnTTΝ;LQ$_C_ľhBVBRR蜦uno,WE?μ6QSz' ѣ݋GxQQQEaG=Cyy&LDuյTcU Yxꩧp}{E ~W^<~OeYSzk 5Ex(m՟ӓ,Q c<IY$H2h׮ڶmd駟F6m4v(bzUja\VVc D/oўPLM3HdMg_~ӟkA y)h))KYnX._8a2`)v]4:?"Z$IHE -byUS-g[@%Bu(mV'55TIDAT]TgXVgܫ3]_lb~6{ LJOO(߿bdӧO#..N[ OF+c<ů!gUQe0R U !8 2E.^6MM'ڗ,;]ؖq]9b@gujsBB"##}꫷ L tL:(//}HKK-P)9/T4qD?ɩZ|YĪ0_B4T}S*!KJv¶m8ڵ ohِ0͍UxZ ,x)fÄ Clz;m胔̙3wU}+tlG2"3a-<29s'Nq)\xW\z}VV,Y^xO>$~i3.A>,:uꄨ(l۶ [nŖ-[8EЪU+رCsӱxRS+*,++ ӦMC-0x`[I!C(srruo5waf͚aʔ)`a֭(++Cii)\6 999x뭷saΝ|;:6m  ** [nw|?~<`hٲ%N8lcaРAԩ2331w\\v{ӦMEnG՚y”]VID O,gi]d uҷ41N*fs=ǃv5ګW/Çeߠ 3.Z*Oh共dG2d?6Lnn.wlM\QW/2rl٢9EkԨF^z!11ݻwcÆ R4,ZSLg}7Rۍ bp\XlW^Qߔ36k M4mz^z^޽{ #0{z]K~֮]cƍ7nlYYq[5vsE5έ$%%aњrWlѵuA\/_ƽ{p;w}999Xt)zm߾}"//o6n7cl66mdħ5BFF]{Ň~Aoܸ 5p޽{ U͛7 z軕Xjn,=6!0#)*vsuA*w*رc`Exk3->Hs͛|kҏ-FDD۹s' ¯+o߮m֬Yk׮qI:t({ܸq:O _r;tc 8qSN{nÆ 5feei. 7! СCM6\. |lڰhXuf+HwzP(//_"z iQo^ wS> >G6L6 OS۠AL:UW{.]mJGØ<3ӧOCƍ5DFFjJQ`J퐥EXWd7^1mX ZeHUz #'P ~fq-Θ.߻v2dd:񊈈@~~>QթbSmXyWڝstrϟGYY_;̒%K$9]޽{ܹsl\~6K.ڵl2DFFw9,OTt 5111R)iӦ~կ~"1|/ŋadddwʃ!z?((UUU-""BZ" ČܓĴa'QuѫQ8Wa}L]y:Sgt:r_|BBB`Z3֋u'.~nӧUUU[xBٳѡC+%,y:{RBUYV*!U௑zmf̙3x"m n&Vm]y2iaR/Oꌸ}1Z^^?U],D+++5QPP+WbʕIJeСCCrtid"F&㏽:Xn8 %Ou%ܬ,3< 鏽. FVaa.p^u ,_{5. /It(z{:Te(a/3^Yp!91o@@كaÆaĉke}74 b EdvLtnGlla.LDk:`E*L8sr3|pPWʕ+5a4+ UBqo\ d_O*z&QFӺv֭غu+ڵkHC"kעGɥK?ǔ)S]4aXp!rrr`pQO̓5o</NÇGÆ qQlذM4c o65/_F>}н{w$%%!$$EEEؿ?N>6m --ͣԥ<01}I$СC1vX@HHP~}!443_Νu"#00V<P^=`ҥ6mɓ1p@bAXX`Zш#p׷o_[N'թ%O]e˖iʊ(@Ϝ9d̞=7I~IZ/Pݸqc8NiC ARRp['={6F/E9 ZZ(**Btt/m۶ŪUTz<ѭԕرc)<<CE^ТE ԫW| ? ''vׯG x!ԄUTT]zD;hҤ Wֽ3x`L2E㮒qiшȋ~Ĉpt ?<9cZUm-*jӦ Ѯ];ǣe˖ í[pY>}'OTO?ݻChѢ+\pEկ~h >>9~ɓ9sF-G9r$yEq1B9h]v k׮Ç5ꙊпJj$-<̙J,ZHi;v,ƎTUU&q-\t fhim۶E^4ȿ]VVիWx[5kbccr4bDNZx74|MSBh$ & 553mUU֬Y4?? =1116lv&`Z7^ڴ=I&`2`EJLF4x'8`;wOҢ @мys|W(**X ..fRUU'p)22111DKyE#f>K. /_͛75tKȴ*[xz):2ƔչsgTUU/w}Պf͚cǎX,vSn… 4P<8$"`k )¡CX6m Dɲ NQYY_hذ!k 'c /K''ϟf} p~CzDe<1Đ%%%<[%(X, ,ry 퀤UTThԉ )z⤫dpHݒZU"%WEKu1]VolJ2X*R3*.bHQHiajߗ73ꛑI¤l9)uĸI89Hv˒hNRitODPI*#nɶ"SB1zO ɧj{RS~W>9S}2T2RUUdZr.1<%OD'A;T]!Ε,^W8C6yT@el1ߋF|yni79f9 a'?:]@KTD4ATTa0Tb䦒/o6((HC S&j r5dYJ ov8ʎrr?DRh*XVpq>3$m!AbvPUH( PG=*A|+9Ih"`6SӭI6b0MHޙD[e@d:;I 0rpppAU}Oe0AKl*)JY:%P嫯dɑC#.zq/UYOQSIo4*9=# { 6m1 Xt2SIb:T02ੀʉLlXtW)U+#RQ|`iM%)zW^BFuq˹].򄬦rPrkY,+3D@7-qG ñ>}qvƌ2e W__nذ TrqMUzQFH\5U*uvʀeO)qJZS4+BTjQN,U} n 8gdm@FR} 0Jmw BZZ郤$?~ϟGӦMѺuk+(//7DG6m{n<vV]ڮDHԗ%19I["p̤2ne133-Z@PPq8N|WHMMѣG_O>$v r n߾nb# CT(nK ͡CLN͛7߇Bݱfz ǎCDDΝy[ X&Hc)Nb?bĘ9ФLФ$"NM,LрJ #d0=M2$ȑ(n1,L3)Kc=ͭit7Hnfv%I?n^(sIENDB`libcommons-fileupload2-java-2.0.0~M5/src/site/resources/profile.jacoco0000644000175000017500000000166215142145735024501 0ustar zigozigo# 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 # # https://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. # ----------------------------------------------------------------------------- # # Empty file used to automatically trigger JaCoCo profile from commons parent pom libcommons-fileupload2-java-2.0.0~M5/src/site/site.xml0000644000175000017500000000520015142145735021325 0ustar zigozigo Commons FileUpload /images/logo.png /index.html libcommons-fileupload2-java-2.0.0~M5/src/site/apt/0000755000175000017500000000000015227714536020433 5ustar zigozigolibcommons-fileupload2-java-2.0.0~M5/src/site/apt/migration.apt.vm0000644000175000017500000002262515142145735023555 0ustar zigozigo~~ ~~ 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 ~~ ~~ https://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. ~~ --------- Migrating --------- Migrating This document provides advice for migration between versions of Commons FileUpload, and between versions of the underlying Servlet API. * Migrating to Commons FileUpload 2 Commons FileUpload 2 breaks binary and source compatibility with version 1. To use version 2, you must to update your projects as follows: [[1]] Use Java 8 or above. [[2]] Add one or more these dependencies with the <<>> <>, and set the <<>> to: [[A]] <> to use Jakarta Servlets 5. [[B]] <> to use Jakarta Servlets 6. [[C]] <> to use Javax Servlets. [[D]] <> to use Javax Portlets. [[E]] All of the above automatically depends on <>. [[3]] The dependency version is <<${project.version}>> [[4]] Change your imports from the root <> to <>. For example, change: +------------------------------------------- import org.apache.commons.fileupload.servlet.ServletFileUpload; +------------------------------------------- to: +------------------------------------------- import org.apache.commons.fileupload2.jakarta.servlet5.JakartaServletFileUpload; +------------------------------------------- or: +------------------------------------------- import org.apache.commons.fileupload2.jakarta.servlet6.JakartaServletFileUpload; +------------------------------------------- or: +------------------------------------------- import org.apache.commons.fileupload2.javax.JavaxServletFileUpload; +------------------------------------------- [[4]] Change some catch clauses, for example: +------------------------------------------- try { // Parse a FileUpload request here. } catch (IOException e) { // Handle the IOException } catch (FileUploadException e) { // Handle the FileUploadException } +------------------------------------------- In FileUpload 2, this is invalid because <<>> is a subclass of <<>>. To address this, switch the catch order, and handle the <<>> in the first catch, and the <<>> in the second. * Migrating to Jakarta Servlet API, Version 5, or later. Most existing projects Commons FileUpload 1 are based on the Javax Servlet API version 2 or later. In Jakarta EE 9, this is replaced with the Jakarta Servlet API version 5. User code should now import the <> package instead of the <> package. For applications using Commons FileUpload, this means, that you need to [[1]] Upgrade Commons FileUpload to version 2, or later. [[2]] Replace the classes from <> to either <> or <>. *------------------------------------------------------------- *------------------------------------------------------------------------------* | <> | <> | *------------------------------------------------------------- *------------------------------------------------------------------------------* | org.apache.commons.fileupload.servlet.ServletFileUpload | org.apache.commons.fileupload2.jakarta.servlet5.JakartaServletFileUpload | *------------------------------------------------------------- *------------------------------------------------------------------------------* | org.apache.commons.fileupload.servlet.ServletRequestContext | org.apache.commons.fileupload2.jakarta.servlet5.JakartaServletRequestContext | *--------------------------------------------------------------*------------------------------------------------------------------------------* | org.apache.commons.fileupload2.servlet.FileCleanerCleanup | org.apache.commons.fileupload2.jakarta.servlet5.JakartaServletFileCleaner | *--------------------------------------------------------------*------------------------------------------------------------------------------* *------------------------------------------------------------- *------------------------------------------------------------------------------* | <> | <> | *------------------------------------------------------------- *------------------------------------------------------------------------------* | org.apache.commons.fileupload.servlet.ServletFileUpload | org.apache.commons.fileupload2.jakarta.servlet6.JakartaServletFileUpload | *------------------------------------------------------------- *------------------------------------------------------------------------------* | org.apache.commons.fileupload.servlet.ServletRequestContext | org.apache.commons.fileupload2.jakarta.servlet6.JakartaServletRequestContext | *--------------------------------------------------------------*------------------------------------------------------------------------------* | org.apache.commons.fileupload2.servlet.FileCleanerCleanup | org.apache.commons.fileupload2.jakarta.servlet6.JakartaServletFileCleaner | *--------------------------------------------------------------*------------------------------------------------------------------------------* *------------------------------------------------------------- *---------------------------------------------------------------------* | <> | <> | *------------------------------------------------------------- *---------------------------------------------------------------------* | org.apache.commons.fileupload.servlet.ServletFileUpload | org.apache.commons.fileupload2.javax.JavaxServletFileUpload | *------------------------------------------------------------- *---------------------------------------------------------------------* | org.apache.commons.fileupload.servlet.ServletRequestContext | org.apache.commons.fileupload2.javax.JavaxServletRequestContext | *--------------------------------------------------------------*---------------------------------------------------------------------* | org.apache.commons.fileupload2.servlet.FileCleanerCleanup | org.apache.commons.fileupload2.javax.JavaxServletFileCleaner | *--------------------------------------------------------------*---------------------------------------------------------------------* * Example The following example demonstrates, how to use Commons FileUpload with the Jakarta Servlet API, version 6: +------------------------------------------- import java.io.IOException; import java.util.List; import org.apache.commons.fileupload2.FileItem; import org.apache.commons.fileupload2.FileItemFactory; import org.apache.commons.fileupload2.FileUpload; import org.apache.commons.fileupload2.FileUploadException; import org.apache.commons.fileupload2.DiskFileItemFactory; import org.apache.commons.fileupload2.jakarta.servlet6.JakartaServletFileUpload; import org.apache.commons.fileupload2.jakarta.servlet6.JakartaServletRequestContext; import jakarta.servlet.ServletException; import jakarta.servlet.http.HttpServlet; import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; public class SampleServlet extends HttpServlet { private static final long serialVersionUID = 2; @Override protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { if (JakartaServletFileUpload.isMultipartContent(req)) { final DiskFileItemFactory fileItemfactory = DiskFileItemFactory.builder().get(); final JakartaServletFileUpload fileUpload = new JakartaServletFileUpload(fileItemfactory); final List items; try { items = fileUpload.parseRequest(new JavaxServletRequestContext(req)); } catch (FileUploadException e) { throw new ServletException(e); } // Process the uploaded file items here... } } } +------------------------------------------- * Using Commons FileUpload 2 as a JPMS Module The library provides <> that defines the required modules and exported packages. libcommons-fileupload2-java-2.0.0~M5/src/site/fml/0000755000175000017500000000000015227714536020425 5ustar zigozigolibcommons-fileupload2-java-2.0.0~M5/src/site/fml/faq.fml0000644000175000017500000002246715142145735021702 0ustar zigozigo General Why is parseRequest() returning no items? This most commonly happens when the request has already been parsed, or processed in some other way. Since the input stream has aleady been consumed by that earlier process, it is no longer available for parsing by Commons FileUpload. Why am I getting "Read timed out" exceptions while parsing? The most common cause of these exceptions is when FileUpload is being used on a site that is using the Tomcat ISAPI redirector. There was a bug in earlier versions of that component that caused problems with multipart requests. The bug was fixed some time ago, so you probably just need to pick up a newer version. See the Tomcat bug report for full details. Why is NoClassDefFoundError being thrown?

There are two common causes for this error.

Firstly, it might simply mean that you do not have the Commons IO jar in your classpath. FileUpload depends on IO (see dependencies) - you can tell if this is the case if the missing class is within the org.apache.commons.io package.

Secondly this happens when attempting to rely on a shared copy of the Commons FileUpload jar file provided by your web container. The solution is to include the FileUpload jar file as part of your own web application, instead of relying on the container. The same may hold for FileUpload's IO dependency.

Why does FileItem.getName() return the whole path, and not just the file name? Internet Explorer provides the entire path to the uploaded file and not just the base file name. Since FileUpload provides exactly what was supplied by the client (browser), you may want to remove this path information in your application. You can do that using the following method from Commons IO (which you already have, since it is used by FileUpload).
    String fileName = item.getName();
    if (fileName != null) {
        filename = FilenameUtils.getName(filename);
    }
        
FileUpload and Struts 1 I'm using FileUpload in an Action, but it's not working. Why? Struts 1 recognises multipart requests, and parses them automatically, presenting the request parameters to your code in the same manner as if they were regular request parameters. Since Struts has already processed the request, and made it available in your form bean, the input stream is no longer available for parsing, so attempting to do so with FileUpload will fail. But I need to parse the request myself. How can I do that? Struts 1 parses multipart a request as a part of the process of populating your form bean from that request. If, for some reason, you need to have full control over the multipart parsing, you can do so by configuring your action mapping without an associated form bean. (A better way of doing this, however, is to replace the default multipart handler with your own. See the Struts 1 documentation for details.) FileUpload and Flash I'm using FileUpload to receive an upload from flash, but FileUpload will always throw an Exception "Stream ended unexpectedly". What can I do?

At least as of version 8, Flash contains a known bug: The multipart stream it produces is broken, because the final boundary doesn't contain the suffix "--", which ought to indicate, that no more items are following. Consequently, FileUpload waits for the next item (which it doesn't get) and throws an exception.

The problems details and a possible workaround are outlined in Bug 143 . The workaround suggests to use the streaming API and catch the exception. The resulting code could look like this:

 items = new ArrayList();

HttpServletRequest servletRequest = [...];
RequestContext ctx = new ServletRequestContext(servletRequest);

FileItemFactory fileItemFactory = new DiskFileItemFactory();

ServletFileUpload upload = new ServletFileUpload();
FileItemIterator iter = upload.getItemIterator(ctx);
try {
    while (iter.hasNext()) {
        FileItemStream item = iter.next();
        FileItem fileItem = fileItemFactory.createItem(item.getFieldName(),
                                                       item.getContentType(),
                                                       item.isFormField(),
                                                       item.getName());
        Streams.copy(item.openStream(), fileItem.getOutputStream(), true);
        items.add(fileItem);
    }
} catch (MalformedStreamException e) {
    // Ignore this
}]]>
FileUpload and Flash I have read, that there is a security problem in Commons FileUpload, because there is a class called DiskFileItem, which can be used for malicious attacks.

Starting in version 2.0.0-M1, no FileUpload classes implement Serializable.

It is true, that this class exists, and can be serialized/deserialized in FileUpload versions, up to, and including 1.3.2. It is also true, that a malicious attacker can abuse this possibility to create arbitrarily located files (assuming the required permissions) with arbitrary contents, if he gets the opportunity to provide specially crafted data, which is being deserialized by a Java application, which has either of the above versions of Commons FileUpload in the classpath, and which puts no limitations on the classes being deserialized.

That being said, we (the Apache Commons team) hold the view, that the actual problem is not the DiskFileItem class, but the "if" in the previous sentence. A Java application should carefully consider, which classes can be deserialized. A typical approach would be, for example, to provide a blacklist, or whitelist of packages, and/or classes, which may, or may not be deserialized.

On the other hand, we acknowledge, that the likelyhood of application container vendors taking such a simple security measure is extremely low. So, in order to support the Commons FileUpload users, we have decided to choose a different approach:

Beginning with 1.3.3, the class DiskFileItem is still implementing the interface java.io.Serializable. In other words, it still declares itself as serializable, and deserializable to the JVM. In practice, however, an attempt to deserialize an instance of DiskFileItem will trigger an Exception. In the unlikely case, that your application depends on the deserialization of DiskFileItems, you can revert to the previous behavior by setting the system property "org.apache.commons.fileupload.DiskFileItem.serializable" to "true".

libcommons-fileupload2-java-2.0.0~M5/src/checkstyle/0000755000175000017500000000000015227714536021041 5ustar zigozigolibcommons-fileupload2-java-2.0.0~M5/src/checkstyle/checkstyle-suppressions.xml0000644000175000017500000000205115142145735026465 0ustar zigozigo libcommons-fileupload2-java-2.0.0~M5/src/checkstyle/license-header.txt0000644000175000017500000000153715142145735024453 0ustar zigozigo/\*\s* \*\s*Licensed to the Apache Software Foundation \(ASF\) under one or more \*\s*contributor license agreements. See the NOTICE file distributed with \*\s*this work for additional information regarding copyright ownership\. \*\s*The ASF licenses this file to You under the Apache License, Version 2\.0 \*\s*\(the "License"\); you may not use this file except in compliance with \*\s*the License\. You may obtain a copy of the License at \*\s* \*\s*http://www\.apache\.org/licenses/LICENSE\-2\.0 \*\s* \*\s*Unless required by applicable law or agreed to in writing, software \*\s*distributed under the License is distributed on an "AS IS" BASIS, \*\s*WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied\. \*\s*See the License for the specific language governing permissions and \*\s*limitations under the License\. \*/\s* libcommons-fileupload2-java-2.0.0~M5/src/checkstyle/fileupload_checks.xml0000644000175000017500000002123315142145735025223 0ustar zigozigo libcommons-fileupload2-java-2.0.0~M5/src/conf/0000755000175000017500000000000015227714536017630 5ustar zigozigolibcommons-fileupload2-java-2.0.0~M5/src/conf/pmd-ruleset.xml0000644000175000017500000001175715142145735022621 0ustar zigozigo This ruleset checks the code for discouraged programming constructs. libcommons-fileupload2-java-2.0.0~M5/src/main/0000755000175000017500000000000015142145735017622 5ustar zigozigolibcommons-fileupload2-java-2.0.0~M5/src/main/assembly/0000755000175000017500000000000015227714536021446 5ustar zigozigolibcommons-fileupload2-java-2.0.0~M5/src/main/assembly/bin.xml0000644000175000017500000000336515142145735022742 0ustar zigozigo bin tar.gz zip ${project.build.finalName}-bin true LICENSE.txt NOTICE.txt RELEASE-NOTES.txt target *.jar target/site/apidocs apidocs libcommons-fileupload2-java-2.0.0~M5/src/main/assembly/src.xml0000644000175000017500000000331415142145735022753 0ustar zigozigo src tar.gz zip ${project.build.finalName}-src ${basedir} **/.classpath **/.project **/.settings/ **/.checkstyle/ **/doap_*.rdf **/bin/ **/.externalToolBuilders/ **/${project.build.directory}/ **/download*.cgi libcommons-fileupload2-java-2.0.0~M5/.github/0000755000175000017500000000000015227714536017454 5ustar zigozigolibcommons-fileupload2-java-2.0.0~M5/.github/workflows/0000755000175000017500000000000015227714536021511 5ustar zigozigolibcommons-fileupload2-java-2.0.0~M5/.github/workflows/maven.yml0000644000175000017500000000354215142145735023341 0ustar zigozigo# 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 # # https://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. name: Java CI on: push: branches: [ master ] pull_request: branches: [ master ] permissions: contents: read jobs: build: runs-on: ubuntu-latest continue-on-error: ${{ matrix.experimental }} strategy: max-parallel: 20 matrix: java: [ 11, 17, 21, 25 ] experimental: [false] include: - java: 26-ea experimental: true steps: - uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 with: persist-credentials: false - uses: actions/cache@9255dc7a253b0ccc959486e2bca901246202afeb # v5.0.1 with: path: ~/.m2/repository key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} restore-keys: | ${{ runner.os }}-maven- - name: Set up JDK ${{ matrix.java }} uses: actions/setup-java@be666c2fcd27ec809703dec50e508c2fdc7f6654 # v5.2.0 with: distribution: 'temurin' java-version: ${{ matrix.java }} - name: Build with Maven run: mvn --errors --show-version --batch-mode --no-transfer-progress libcommons-fileupload2-java-2.0.0~M5/.github/workflows/scorecards-analysis.yml0000644000175000017500000000474415142145735026211 0ustar zigozigo# 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 # # https://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. name: "Scorecards supply-chain security" on: branch_protection_rule: schedule: - cron: "30 1 * * 6" # Weekly on Saturdays push: branches: [ "master" ] permissions: read-all jobs: analysis: name: "Scorecards analysis" runs-on: ubuntu-latest permissions: # Needed to upload the results to the code-scanning dashboard. security-events: write actions: read id-token: write # This is required for requesting the JWT contents: read # This is required for actions/checkout steps: - name: "Checkout code" uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 with: persist-credentials: false - name: "Run analysis" uses: ossf/scorecard-action@4eaacf0543bb3f2c246792bd56e8cdeffafb205a # 2.4.3 with: results_file: results.sarif results_format: sarif # A read-only PAT token, which is sufficient for the action to function. # The relevant discussion: https://github.com/ossf/scorecard-action/issues/188 repo_token: ${{ secrets.GITHUB_TOKEN }} # Publish the results for public repositories to enable scorecard badges. # For more details: https://github.com/ossf/scorecard-action#publishing-results publish_results: true - name: "Upload artifact" uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f # 6.0.0 with: name: SARIF file path: results.sarif retention-days: 5 - name: "Upload to code-scanning" uses: github/codeql-action/upload-sarif@45cbd0c69e560cd9e7cd7f8c32362050c9b7ded2 # v4.32.2 with: sarif_file: results.sarif libcommons-fileupload2-java-2.0.0~M5/.github/workflows/codeql-analysis.yml0000644000175000017500000000620115142145735025316 0ustar zigozigo# 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 # # https://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. name: "CodeQL" on: push: branches: [ master ] pull_request: # The branches below must be a subset of the branches above branches: [ master ] schedule: - cron: '33 9 * * 4' permissions: contents: read jobs: analyze: name: Analyze runs-on: ubuntu-latest permissions: actions: read contents: read security-events: write strategy: max-parallel: 20 fail-fast: false matrix: language: [ 'java' ] # CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python', 'ruby' ] # Learn more about CodeQL language support at https://git.io/codeql-language-support steps: - name: Checkout repository uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 with: persist-credentials: false - uses: actions/cache@9255dc7a253b0ccc959486e2bca901246202afeb # v5.0.1 with: path: ~/.m2/repository key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} restore-keys: | ${{ runner.os }}-maven- # Initializes the CodeQL tools for scanning. - name: Initialize CodeQL uses: github/codeql-action/init@45cbd0c69e560cd9e7cd7f8c32362050c9b7ded2 # v4.32.2 with: languages: ${{ matrix.language }} # If you wish to specify custom queries, you can do so here or in a config file. # By default, queries listed here will override any specified in a config file. # Prefix the list here with "+" to use these queries and those in the config file. # queries: ./path/to/local/query, your-org/your-repo/queries@main # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). # If this step fails, then you should remove it and run the build manually (see below) - name: Autobuild uses: github/codeql-action/autobuild@45cbd0c69e560cd9e7cd7f8c32362050c9b7ded2 # v4.32.2 # ℹ️ Command-line programs to run using the OS shell. # 📚 https://git.io/JvXDl # ✏️ If the Autobuild fails above, remove it and uncomment the following three lines # and modify them (or add more) to build your code if your project # uses a compiled language #- run: | # make bootstrap # make release - name: Perform CodeQL Analysis uses: github/codeql-action/analyze@45cbd0c69e560cd9e7cd7f8c32362050c9b7ded2 # v4.32.2 libcommons-fileupload2-java-2.0.0~M5/.github/workflows/dependency-review.yml0000644000175000017500000000223515142145735025646 0ustar zigozigo# 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 # # https://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. name: 'Dependency Review' on: [pull_request] permissions: contents: read jobs: dependency-review: runs-on: ubuntu-latest steps: - name: 'Checkout Repository' uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 - name: 'Dependency Review PR' uses: actions/dependency-review-action@3c4e3dcb1aa7874d2c16be7d79418e9b7efd6261 # v4.8.2 libcommons-fileupload2-java-2.0.0~M5/.github/dependabot.yml0000644000175000017500000000174515142145735022306 0ustar zigozigo# 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 # # https://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. version: 2 updates: - package-ecosystem: "maven" directory: "/" schedule: interval: "quarterly" - package-ecosystem: "github-actions" directory: "/" schedule: interval: "quarterly" libcommons-fileupload2-java-2.0.0~M5/.github/GH-ROBOTS.txt0000644000175000017500000000163415142145735021520 0ustar zigozigo# 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 # # https://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. # Keeps on creating FUD PRs in test code # Does not follow Apache disclosure policies User-agent: JLLeitschuh/security-research Disallow: * libcommons-fileupload2-java-2.0.0~M5/.github/pull_request_template.md0000644000175000017500000000361015142145735024410 0ustar zigozigo Thanks for your contribution to [Apache Commons](https://commons.apache.org/)! Your help is appreciated! Before you push a pull request, review this list: - [ ] Read the [contribution guidelines](CONTRIBUTING.md) for this project. - [ ] Read the [ASF Generative Tooling Guidance](https://www.apache.org/legal/generative-tooling.html) if you use Artificial Intelligence (AI). - [ ] I used AI to create any part of, or all of, this pull request. Which AI tool was used to create this pull request, and to what extent did it contribute? - [ ] Run a successful build using the default [Maven](https://maven.apache.org/) goal with `mvn`; that's `mvn` on the command line by itself. - [ ] Write unit tests that match behavioral changes, where the tests fail if the changes to the runtime are not applied. This may not always be possible, but it is a best practice. - [ ] Write a pull request description that is detailed enough to understand what the pull request does, how, and why. - [ ] Each commit in the pull request should have a meaningful subject line and body. Note that a maintainer may squash commits during the merge process. libcommons-fileupload2-java-2.0.0~M5/CODE_OF_CONDUCT.md0000644000175000017500000000164215142145735020711 0ustar zigozigo The Apache code of conduct page is [https://www.apache.org/foundation/policies/conduct.html](https://www.apache.org/foundation/policies/conduct.html). libcommons-fileupload2-java-2.0.0~M5/NOTICE.txt0000644000175000017500000000026415142145735017633 0ustar zigozigoApache Commons FileUpload Copyright 2002-2026 The Apache Software Foundation This product includes software developed at The Apache Software Foundation (https://www.apache.org/). libcommons-fileupload2-java-2.0.0~M5/spotbugs-exclude-filter.xml0000644000175000017500000000532115142145735023412 0ustar zigozigo