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/04/03 02:45:01 UTC
[commons-fileupload] branch master updated: Reuse java.io.Closeable instead of custom Closeable
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
The following commit(s) were added to refs/heads/master by this push:
new 5c1c9d1 Reuse java.io.Closeable instead of custom Closeable
5c1c9d1 is described below
commit 5c1c9d194f745f08392326b508a29a3fc9b7da7d
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sun Apr 2 22:44:57 2023 -0400
Reuse java.io.Closeable instead of custom Closeable
---
.../commons/fileupload2/MultipartStream.java | 21 ++++-------
.../fileupload2/impl/FileItemStreamImpl.java | 9 +++--
.../apache/commons/fileupload2/util/Closeable.java | 41 ----------------------
.../fileupload2/util/LimitedInputStream.java | 19 +---------
4 files changed, 15 insertions(+), 75 deletions(-)
diff --git a/src/main/java/org/apache/commons/fileupload2/MultipartStream.java b/src/main/java/org/apache/commons/fileupload2/MultipartStream.java
index 67769e7..ea9e417 100644
--- a/src/main/java/org/apache/commons/fileupload2/MultipartStream.java
+++ b/src/main/java/org/apache/commons/fileupload2/MultipartStream.java
@@ -25,7 +25,6 @@ import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import org.apache.commons.fileupload2.pub.FileUploadSizeException;
-import org.apache.commons.fileupload2.util.Closeable;
import org.apache.commons.fileupload2.util.Streams;
/**
@@ -83,7 +82,7 @@ import org.apache.commons.fileupload2.util.Streams;
public class MultipartStream {
/**
- * Thrown upon attempt of setting an invalid boundary token.
+ * Signals an attempt to set an invalid boundary token.
*/
public static class FileUploadBoundaryException extends FileUploadException {
@@ -106,7 +105,7 @@ public class MultipartStream {
/**
* An {@link InputStream} for reading an items contents.
*/
- public class ItemInputStream extends InputStream implements Closeable {
+ public class ItemInputStream extends InputStream {
/**
* Offset when converting negative bytes to integers.
@@ -167,14 +166,14 @@ public class MultipartStream {
/**
* Closes the input stream.
*
- * @param pCloseUnderlying Whether to close the underlying stream (hard close)
+ * @param closeUnderlying Whether to close the underlying stream (hard close)
* @throws IOException An I/O error occurred.
*/
- public void close(final boolean pCloseUnderlying) throws IOException {
+ public void close(final boolean closeUnderlying) throws IOException {
if (closed) {
return;
}
- if (pCloseUnderlying) {
+ if (closeUnderlying) {
closed = true;
input.close();
} else {
@@ -215,12 +214,6 @@ public class MultipartStream {
return total;
}
- /**
- * Returns, whether the stream is closed.
- *
- * @return True, if the stream is closed, otherwise false.
- */
- @Override
public boolean isClosed() {
return closed;
}
@@ -347,14 +340,14 @@ public class MultipartStream {
}
/**
- * Thrown to indicate that the input stream fails to follow the required syntax.
+ * Signals that the input stream fails to follow the required syntax.
*/
public static class MalformedStreamException extends IOException {
/**
* The UID to use when serializing this instance.
*/
- private static final long serialVersionUID = 6466926458059796677L;
+ private static final long serialVersionUID = 2;
/**
* Constructs an {@code MalformedStreamException} with the specified detail message.
diff --git a/src/main/java/org/apache/commons/fileupload2/impl/FileItemStreamImpl.java b/src/main/java/org/apache/commons/fileupload2/impl/FileItemStreamImpl.java
index 0d3d260..ce94b3f 100644
--- a/src/main/java/org/apache/commons/fileupload2/impl/FileItemStreamImpl.java
+++ b/src/main/java/org/apache/commons/fileupload2/impl/FileItemStreamImpl.java
@@ -27,7 +27,6 @@ import org.apache.commons.fileupload2.FileUploadException;
import org.apache.commons.fileupload2.InvalidFileNameException;
import org.apache.commons.fileupload2.MultipartStream.ItemInputStream;
import org.apache.commons.fileupload2.pub.FileUploadByteCountLimitException;
-import org.apache.commons.fileupload2.util.Closeable;
import org.apache.commons.fileupload2.util.LimitedInputStream;
import org.apache.commons.fileupload2.util.Streams;
@@ -67,6 +66,11 @@ public class FileItemStreamImpl implements FileItemStream {
*/
private final InputStream inputStream;
+ /**
+ * The file items input stream closed flag.
+ */
+ private boolean inputStreamClosed;
+
/**
* The headers, if any.
*/
@@ -120,6 +124,7 @@ public class FileItemStreamImpl implements FileItemStream {
*/
public void close() throws IOException {
inputStream.close();
+ inputStreamClosed = true;
}
/**
@@ -182,7 +187,7 @@ public class FileItemStreamImpl implements FileItemStream {
*/
@Override
public InputStream openStream() throws IOException {
- if (((Closeable) inputStream).isClosed()) {
+ if (inputStreamClosed) {
throw new FileItemStream.ItemSkippedException();
}
return inputStream;
diff --git a/src/main/java/org/apache/commons/fileupload2/util/Closeable.java b/src/main/java/org/apache/commons/fileupload2/util/Closeable.java
deleted file mode 100644
index dce76f8..0000000
--- a/src/main/java/org/apache/commons/fileupload2/util/Closeable.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.commons.fileupload2.util;
-
-import java.io.IOException;
-
-/**
- * Interface of an object, which may be closed.
- */
-public interface Closeable {
-
- /**
- * Closes the object.
- *
- * @throws IOException An I/O error occurred.
- */
- void close() throws IOException;
-
- /**
- * Returns, whether the object is already closed.
- *
- * @return True, if the object is closed, otherwise false.
- * @throws IOException An I/O error occurred.
- */
- boolean isClosed() throws IOException;
-
-}
diff --git a/src/main/java/org/apache/commons/fileupload2/util/LimitedInputStream.java b/src/main/java/org/apache/commons/fileupload2/util/LimitedInputStream.java
index ab02cd9..ccd77d7 100644
--- a/src/main/java/org/apache/commons/fileupload2/util/LimitedInputStream.java
+++ b/src/main/java/org/apache/commons/fileupload2/util/LimitedInputStream.java
@@ -24,7 +24,7 @@ import java.io.InputStream;
* An input stream, which limits its data size. This stream is
* used, if the content length is unknown.
*/
-public abstract class LimitedInputStream extends FilterInputStream implements Closeable {
+public abstract class LimitedInputStream extends FilterInputStream {
/**
* The maximum size of an item, in bytes.
@@ -36,11 +36,6 @@ public abstract class LimitedInputStream extends FilterInputStream implements Cl
*/
private long count;
- /**
- * Whether this stream is already closed.
- */
- private boolean closed;
-
/**
* Creates a new instance.
*
@@ -76,21 +71,9 @@ public abstract class LimitedInputStream extends FilterInputStream implements Cl
*/
@Override
public void close() throws IOException {
- closed = true;
super.close();
}
- /**
- * Returns, whether this stream is already closed.
- *
- * @return True, if the stream is closed, otherwise false.
- * @throws IOException An I/O error occurred.
- */
- @Override
- public boolean isClosed() throws IOException {
- return closed;
- }
-
/**
* Called to indicate, that the input streams limit has
* been exceeded.