You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2023/06/11 14:20:57 UTC
[commons-fileupload] 02/03: More accurate API name
This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-fileupload.git
commit e3f0f19ad1d8ee7c0c527bf885ade9bf1e65bd8a
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sun Jun 11 10:18:39 2023 -0400
More accurate API name
---
.../commons/fileupload2/AbstractFileUpload.java | 2 +-
.../apache/commons/fileupload2/FileItemStream.java | 24 +++++++++----------
.../commons/fileupload2/FileItemStreamImpl.java | 28 +++++++++++-----------
.../fileupload2/AbstractProgressListenerTest.java | 2 +-
.../commons/fileupload2/AbstractSizesTest.java | 4 ++--
5 files changed, 30 insertions(+), 30 deletions(-)
diff --git a/commons-fileupload2-core/src/main/java/org/apache/commons/fileupload2/AbstractFileUpload.java b/commons-fileupload2-core/src/main/java/org/apache/commons/fileupload2/AbstractFileUpload.java
index b7d25af..9909d3f 100644
--- a/commons-fileupload2-core/src/main/java/org/apache/commons/fileupload2/AbstractFileUpload.java
+++ b/commons-fileupload2-core/src/main/java/org/apache/commons/fileupload2/AbstractFileUpload.java
@@ -423,7 +423,7 @@ public abstract class AbstractFileUpload {
final FileItem fileItem = fileItemFactory.createFileItem(fileItemStream.getFieldName(), fileItemStream.getContentType(),
fileItemStream.isFormField(), fileName, fileItemStream.getHeaders());
itemList.add(fileItem);
- try (InputStream inputStream = fileItemStream.openStream();
+ try (InputStream inputStream = fileItemStream.getInputStream();
OutputStream outputStream = fileItem.getOutputStream()) {
IOUtils.copyLarge(inputStream, outputStream, buffer);
} catch (final FileUploadException e) {
diff --git a/commons-fileupload2-core/src/main/java/org/apache/commons/fileupload2/FileItemStream.java b/commons-fileupload2-core/src/main/java/org/apache/commons/fileupload2/FileItemStream.java
index e3ec176..a706099 100644
--- a/commons-fileupload2-core/src/main/java/org/apache/commons/fileupload2/FileItemStream.java
+++ b/commons-fileupload2-core/src/main/java/org/apache/commons/fileupload2/FileItemStream.java
@@ -22,7 +22,7 @@ import java.io.InputStream;
/**
* Provides access to a file or form item that was received within a {@code multipart/form-data} POST request.
* <p>
- * The items contents are retrieved by calling {@link #openStream()}.
+ * The items contents are retrieved by calling {@link #getInputStream()}.
* </p>
* <p>
* Instances of this class are created by accessing the iterator, returned by {@link AbstractFileUpload#getItemIterator(RequestContext)}.
@@ -36,7 +36,7 @@ public interface FileItemStream extends FileItemHeadersSupport {
/**
* This exception is thrown, if an attempt is made to read data from the {@link InputStream}, which has been returned by
- * {@link FileItemStream#openStream()}, after {@link java.util.Iterator#hasNext()} has been invoked on the iterator, which created the
+ * {@link FileItemStream#getInputStream()}, after {@link java.util.Iterator#hasNext()} has been invoked on the iterator, which created the
* {@link FileItemStream}.
*/
class ItemSkippedException extends IOException {
@@ -62,6 +62,16 @@ public interface FileItemStream extends FileItemHeadersSupport {
*/
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.
@@ -77,14 +87,4 @@ public interface FileItemStream extends FileItemHeadersSupport {
*/
boolean isFormField();
- /**
- * 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 openStream() throws IOException;
-
}
diff --git a/commons-fileupload2-core/src/main/java/org/apache/commons/fileupload2/FileItemStreamImpl.java b/commons-fileupload2-core/src/main/java/org/apache/commons/fileupload2/FileItemStreamImpl.java
index 4b7096c..0357d77 100644
--- a/commons-fileupload2-core/src/main/java/org/apache/commons/fileupload2/FileItemStreamImpl.java
+++ b/commons-fileupload2-core/src/main/java/org/apache/commons/fileupload2/FileItemStreamImpl.java
@@ -152,6 +152,20 @@ class FileItemStreamImpl implements FileItemStream {
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 FileItemStream.ItemSkippedException();
+ }
+ return inputStream;
+ }
+
/**
* Gets the file name.
*
@@ -174,20 +188,6 @@ class FileItemStreamImpl implements FileItemStream {
return formField;
}
- /**
- * 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 openStream() throws IOException {
- if (inputStreamClosed) {
- throw new FileItemStream.ItemSkippedException();
- }
- return inputStream;
- }
-
/**
* Sets the file item headers.
*
diff --git a/commons-fileupload2-core/src/test/java/org/apache/commons/fileupload2/AbstractProgressListenerTest.java b/commons-fileupload2-core/src/test/java/org/apache/commons/fileupload2/AbstractProgressListenerTest.java
index 6931268..c66f470 100644
--- a/commons-fileupload2-core/src/test/java/org/apache/commons/fileupload2/AbstractProgressListenerTest.java
+++ b/commons-fileupload2-core/src/test/java/org/apache/commons/fileupload2/AbstractProgressListenerTest.java
@@ -76,7 +76,7 @@ public abstract class AbstractProgressListenerTest<F extends FileUpload<R>, R> e
for (int i = 0; i < itemCount; i++) {
final int idxI = i;
final FileItemStream fileItemStream = iter.next();
- try (final InputStream inputStream = fileItemStream.openStream()) {
+ try (final InputStream inputStream = fileItemStream.getInputStream()) {
for (int j = 0; j < 16_384 + i; j++) {
final int idxJ = j;
//
diff --git a/commons-fileupload2-core/src/test/java/org/apache/commons/fileupload2/AbstractSizesTest.java b/commons-fileupload2-core/src/test/java/org/apache/commons/fileupload2/AbstractSizesTest.java
index e6f7f80..995b4ab 100644
--- a/commons-fileupload2-core/src/test/java/org/apache/commons/fileupload2/AbstractSizesTest.java
+++ b/commons-fileupload2-core/src/test/java/org/apache/commons/fileupload2/AbstractSizesTest.java
@@ -219,7 +219,7 @@ public abstract class AbstractSizesTest<F extends FileUpload<R>, R> extends Abst
{
try (final ByteArrayOutputStream baos = new ByteArrayOutputStream();
- final InputStream stream = item.openStream()) {
+ final InputStream stream = item.getInputStream()) {
IOUtils.copy(stream, baos);
}
@@ -232,7 +232,7 @@ public abstract class AbstractSizesTest<F extends FileUpload<R>, R> extends Abst
assertThrows(FileUploadException.class, () -> {
final FileItemStream item2 = it.next();
try (final ByteArrayOutputStream baos = new ByteArrayOutputStream();
- final InputStream stream = item2.openStream()) {
+ final InputStream stream = item2.getInputStream()) {
IOUtils.copy(stream, baos);
}
});