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/05/03 23:47:57 UTC
[commons-io] branch master updated (c55f6380 -> dba4132f)
This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/commons-io.git
from c55f6380 Use builder (fix)
new 4cb04246 Format tweak
new bdb9f8b9 Use builder and deprecate some ctors
new b9300808 Pickup Maven enforcer plugin from parent POM
new 53507ac6 Javadoc
new 55b6211b Remove unused new method
new 1cc2913e Remove unused new method
new dba4132f Use builder and Javadoc
The 7 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
pom.xml | 52 +------
src/main/java/org/apache/commons/io/IOUtils.java | 2 +-
.../apache/commons/io/build/AbstractOrigin.java | 53 ++++++-
.../commons/io/build/AbstractOriginSupplier.java | 24 ++--
.../commons/io/build/AbstractStreamBuilder.java | 13 --
.../apache/commons/io/input/BOMInputStream.java | 5 +
.../io/input/BufferedFileChannelInputStream.java | 38 ++---
.../io/input/MemoryMappedFileInputStream.java | 23 +--
.../input/MessageDigestCalculatingInputStream.java | 5 +
.../io/input/RandomAccessFileInputStream.java | 5 +
.../commons/io/input/ReadAheadInputStream.java | 5 +
.../apache/commons/io/input/ReaderInputStream.java | 5 +
.../commons/io/input/ReversedLinesFileReader.java | 5 +
.../java/org/apache/commons/io/input/Tailer.java | 5 +
.../commons/io/input/UncheckedBufferedReader.java | 5 +
.../io/input/UncheckedFilterInputStream.java | 44 ++++--
.../commons/io/input/UncheckedFilterReader.java | 49 +++++--
.../io/input/UnixLineEndingInputStream.java | 49 +++----
.../input/UnsynchronizedBufferedInputStream.java | 139 +++++++++++-------
.../input/UnsynchronizedByteArrayInputStream.java | 106 ++++++++++++--
.../io/input/UnsynchronizedFilterInputStream.java | 69 +++++++--
.../apache/commons/io/input/XmlStreamReader.java | 5 +
.../io/output/AbstractByteArrayOutputStream.java | 7 +-
.../commons/io/output/FileWriterWithEncoding.java | 5 +
.../commons/io/output/LockableFileWriter.java | 5 +
.../io/output/UncheckedFilterOutputStream.java | 9 +-
.../commons/io/output/UncheckedFilterWriter.java | 49 +++++--
.../UnsynchronizedByteArrayOutputStream.java | 60 +++++++-
.../commons/io/output/WriterOutputStream.java | 7 +-
.../apache/commons/io/output/XmlStreamWriter.java | 5 +
.../io/input/MemoryMappedFileInputStreamTest.java | 34 +++--
.../io/input/UncheckedFilterInputStreamTest.java | 16 ++-
.../io/input/UncheckedFilterReaderTest.java | 21 +--
.../UnsynchronizedBufferedInputStreamTest.java | 22 +--
.../UnsynchronizedByteArrayInputStreamTest.java | 156 ++++++++++++---------
.../input/UnsynchronizedFilterInputStreamTest.java | 8 +-
.../io/output/UncheckedFilterWriterTest.java | 6 +-
37 files changed, 749 insertions(+), 367 deletions(-)
[commons-io] 06/07: Remove unused new method
Posted by gg...@apache.org.
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-io.git
commit 1cc2913eea3784532d45235c0d2fd474c4e8f098
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Wed May 3 14:18:47 2023 -0400
Remove unused new method
---
.../org/apache/commons/io/build/AbstractStreamBuilder.java | 13 -------------
1 file changed, 13 deletions(-)
diff --git a/src/main/java/org/apache/commons/io/build/AbstractStreamBuilder.java b/src/main/java/org/apache/commons/io/build/AbstractStreamBuilder.java
index c42aff52..e938b7eb 100644
--- a/src/main/java/org/apache/commons/io/build/AbstractStreamBuilder.java
+++ b/src/main/java/org/apache/commons/io/build/AbstractStreamBuilder.java
@@ -31,19 +31,6 @@ import org.apache.commons.io.IOUtils;
*/
public abstract class AbstractStreamBuilder<T, B extends AbstractStreamBuilder<T, B>> extends AbstractOriginSupplier<T, B> {
- /**
- * Throws {@link IllegalArgumentException} if the initialBufferSize is less than zero.
- *
- * @param initialBufferSize the value to test.
- * @return the input value.
- */
- protected static int checkBufferSize(final int initialBufferSize) {
- if (initialBufferSize < 0) {
- throw new IllegalArgumentException("Initial buffer size must be at least 0.");
- }
- return initialBufferSize;
- }
-
/**
* The buffer size, defaults to {@link IOUtils#DEFAULT_BUFFER_SIZE} ({@value IOUtils#DEFAULT_BUFFER_SIZE}).
*/
[commons-io] 07/07: Use builder and Javadoc
Posted by gg...@apache.org.
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-io.git
commit dba4132fdf77e66006f407a82b4ad6705bbe8a20
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Wed May 3 19:47:49 2023 -0400
Use builder and Javadoc
---
src/main/java/org/apache/commons/io/IOUtils.java | 2 +-
.../apache/commons/io/build/AbstractOrigin.java | 8 +++-
.../apache/commons/io/input/BOMInputStream.java | 5 +++
.../io/input/BufferedFileChannelInputStream.java | 38 ++++++++--------
.../io/input/MemoryMappedFileInputStream.java | 23 +++-------
.../input/MessageDigestCalculatingInputStream.java | 5 +++
.../io/input/RandomAccessFileInputStream.java | 5 +++
.../commons/io/input/ReadAheadInputStream.java | 5 +++
.../apache/commons/io/input/ReaderInputStream.java | 5 +++
.../commons/io/input/ReversedLinesFileReader.java | 5 +++
.../java/org/apache/commons/io/input/Tailer.java | 5 +++
.../commons/io/input/UncheckedBufferedReader.java | 5 +++
.../commons/io/input/UncheckedFilterReader.java | 5 +++
.../input/UnsynchronizedBufferedInputStream.java | 7 ++-
.../input/UnsynchronizedByteArrayInputStream.java | 26 ++++++-----
.../io/input/UnsynchronizedFilterInputStream.java | 9 ++--
.../apache/commons/io/input/XmlStreamReader.java | 5 +++
.../commons/io/output/FileWriterWithEncoding.java | 5 +++
.../commons/io/output/LockableFileWriter.java | 5 +++
.../io/output/UncheckedFilterOutputStream.java | 9 +++-
.../commons/io/output/UncheckedFilterWriter.java | 49 +++++++++++++++++----
.../UnsynchronizedByteArrayOutputStream.java | 50 +++++++++++++++++++++-
.../commons/io/output/WriterOutputStream.java | 7 ++-
.../apache/commons/io/output/XmlStreamWriter.java | 5 +++
.../io/input/MemoryMappedFileInputStreamTest.java | 34 +++++++++------
.../input/UnsynchronizedFilterInputStreamTest.java | 2 +-
.../io/output/UncheckedFilterWriterTest.java | 6 +--
27 files changed, 256 insertions(+), 79 deletions(-)
diff --git a/src/main/java/org/apache/commons/io/IOUtils.java b/src/main/java/org/apache/commons/io/IOUtils.java
index cada6f7f..194dceaa 100644
--- a/src/main/java/org/apache/commons/io/IOUtils.java
+++ b/src/main/java/org/apache/commons/io/IOUtils.java
@@ -2555,7 +2555,7 @@ public class IOUtils {
*/
public static byte[] toByteArray(final InputStream inputStream) throws IOException {
// We use a ThresholdingOutputStream to avoid reading AND writing more than Integer.MAX_VALUE.
- try (UnsynchronizedByteArrayOutputStream ubaOutput = new UnsynchronizedByteArrayOutputStream();
+ try (UnsynchronizedByteArrayOutputStream ubaOutput = UnsynchronizedByteArrayOutputStream.builder().get();
ThresholdingOutputStream thresholdOutput = new ThresholdingOutputStream(Integer.MAX_VALUE, os -> {
throw new IllegalArgumentException(String.format("Cannot read more than %,d into a byte array", Integer.MAX_VALUE));
}, os -> ubaOutput)) {
diff --git a/src/main/java/org/apache/commons/io/build/AbstractOrigin.java b/src/main/java/org/apache/commons/io/build/AbstractOrigin.java
index 82cafc0e..eadbb246 100644
--- a/src/main/java/org/apache/commons/io/build/AbstractOrigin.java
+++ b/src/main/java/org/apache/commons/io/build/AbstractOrigin.java
@@ -70,7 +70,7 @@ public abstract class AbstractOrigin<T, B extends AbstractOrigin<T, B>> extends
/**
* A {@link File} origin.
* <p>
- * Starting from this origin, you can get a byte array, a file, an input stream, an output stream, a path, a reader, and a writer.
+ * Starting from this origin, you can get a byte array, a file, an input stream, an output stream, a path, a reader, and a writer.
* </p>
*/
public static class FileOrigin extends AbstractOrigin<File, FileOrigin> {
@@ -150,7 +150,7 @@ public abstract class AbstractOrigin<T, B extends AbstractOrigin<T, B>> extends
/**
* A {@link Path} origin.
* <p>
- * Starting from this origin, you can get a byte array, a file, an input stream, an output stream, a path, a reader, and a writer.
+ * Starting from this origin, you can get a byte array, a file, an input stream, an output stream, a path, a reader, and a writer.
* </p>
*/
public static class PathOrigin extends AbstractOrigin<Path, PathOrigin> {
@@ -280,6 +280,7 @@ public abstract class AbstractOrigin<T, B extends AbstractOrigin<T, B>> extends
*
* @return this origin as a byte array, if possible.
* @throws IOException if an I/O error occurs.
+ * @throws UnsupportedOperationException if the origin cannot be converted to a Path.
*/
public byte[] getByteArray() throws IOException {
return Files.readAllBytes(getPath());
@@ -301,6 +302,7 @@ public abstract class AbstractOrigin<T, B extends AbstractOrigin<T, B>> extends
* @param options options specifying how the file is opened
* @return this origin as an InputStream, if possible.
* @throws IOException if an I/O error occurs.
+ * @throws UnsupportedOperationException if the origin cannot be converted to a Path.
*/
public InputStream getInputStream(final OpenOption... options) throws IOException {
return Files.newInputStream(getPath(), options);
@@ -312,6 +314,7 @@ public abstract class AbstractOrigin<T, B extends AbstractOrigin<T, B>> extends
* @param options options specifying how the file is opened
* @return this origin as an OutputStream, if possible.
* @throws IOException if an I/O error occurs.
+ * @throws UnsupportedOperationException if the origin cannot be converted to a Path.
*/
public OutputStream getOutputStream(final OpenOption... options) throws IOException {
return Files.newOutputStream(getPath(), options);
@@ -345,6 +348,7 @@ public abstract class AbstractOrigin<T, B extends AbstractOrigin<T, B>> extends
* @param options options specifying how the file is opened
* @return a new Writer on the origin.
* @throws IOException if an I/O error occurs opening or creating the file.
+ * @throws UnsupportedOperationException if the origin cannot be converted to a Path.
*/
public Writer getWriter(final Charset charset, final OpenOption... options) throws IOException {
return Files.newBufferedWriter(getPath(), charset, options);
diff --git a/src/main/java/org/apache/commons/io/input/BOMInputStream.java b/src/main/java/org/apache/commons/io/input/BOMInputStream.java
index b96bc72b..36b4e005 100644
--- a/src/main/java/org/apache/commons/io/input/BOMInputStream.java
+++ b/src/main/java/org/apache/commons/io/input/BOMInputStream.java
@@ -117,6 +117,11 @@ public class BOMInputStream extends ProxyInputStream {
private ByteOrderMark[] byteOrderMarks = DEFAULT;
+ /**
+ * Constructs a new instance.
+ *
+ * @throws UnsupportedOperationException if the origin cannot be converted to an InputStream.
+ */
@SuppressWarnings("resource")
@Override
public BOMInputStream get() throws IOException {
diff --git a/src/main/java/org/apache/commons/io/input/BufferedFileChannelInputStream.java b/src/main/java/org/apache/commons/io/input/BufferedFileChannelInputStream.java
index cfe13040..e514f985 100644
--- a/src/main/java/org/apache/commons/io/input/BufferedFileChannelInputStream.java
+++ b/src/main/java/org/apache/commons/io/input/BufferedFileChannelInputStream.java
@@ -28,13 +28,11 @@ import org.apache.commons.io.IOUtils;
import org.apache.commons.io.build.AbstractStreamBuilder;
/**
- * {@link InputStream} implementation which uses direct buffer to read a file to avoid extra copy of data between Java
- * and native memory which happens when using {@link java.io.BufferedInputStream}. Unfortunately, this is not something
- * already available in JDK, {@code sun.nio.ch.ChannelInputStream} supports reading a file using NIO, but does not
- * support buffering.
+ * {@link InputStream} implementation which uses direct buffer to read a file to avoid extra copy of data between Java and native memory which happens when
+ * using {@link java.io.BufferedInputStream}. Unfortunately, this is not something already available in JDK, {@code sun.nio.ch.ChannelInputStream} supports
+ * reading a file using NIO, but does not support buffering.
* <p>
- * This class was ported and adapted from Apache Spark commit 933dc6cb7b3de1d8ccaf73d124d6eb95b947ed19 where it was
- * called {@code NioBufferedFileInputStream}.
+ * This class was ported and adapted from Apache Spark commit 933dc6cb7b3de1d8ccaf73d124d6eb95b947ed19 where it was called {@code NioBufferedFileInputStream}.
* </p>
*
* @since 2.9.0
@@ -46,6 +44,7 @@ public final class BufferedFileChannelInputStream extends InputStream {
* <p>
* Using File IO:
* </p>
+ *
* <pre>{@code
* BufferedFileChannelInputStream s = BufferedFileChannelInputStream.builder()
* .setFile(file)
@@ -55,6 +54,7 @@ public final class BufferedFileChannelInputStream extends InputStream {
* <p>
* Using NIO Path:
* </p>
+ *
* <pre>{@code
* BufferedFileChannelInputStream s = BufferedFileChannelInputStream.builder()
* .setPath(path)
@@ -66,6 +66,11 @@ public final class BufferedFileChannelInputStream extends InputStream {
*/
public static class Builder extends AbstractStreamBuilder<BufferedFileChannelInputStream, Builder> {
+ /**
+ * Constructs a new instance.
+ *
+ * @throws UnsupportedOperationException if the origin cannot be converted to a Path.
+ */
@Override
public BufferedFileChannelInputStream get() throws IOException {
return new BufferedFileChannelInputStream(getOrigin().getPath(), getBufferSize());
@@ -102,7 +107,7 @@ public final class BufferedFileChannelInputStream extends InputStream {
/**
* Constructs a new instance for the given File and buffer size.
*
- * @param file The file to stream.
+ * @param file The file to stream.
* @param bufferSize buffer size.
* @throws IOException If an I/O error occurs
* @deprecated Use {@link #builder()}
@@ -127,7 +132,7 @@ public final class BufferedFileChannelInputStream extends InputStream {
/**
* Constructs a new instance for the given Path and buffer size.
*
- * @param path The path to stream.
+ * @param path The path to stream.
* @param bufferSize buffer size.
* @throws IOException If an I/O error occurs
* @deprecated Use {@link #builder()}
@@ -146,11 +151,10 @@ public final class BufferedFileChannelInputStream extends InputStream {
}
/**
- * Attempts to clean up a ByteBuffer if it is direct or memory-mapped. This uses an *unsafe* Sun API that will cause
- * errors if one attempts to read from the disposed buffer. However, neither the bytes allocated to direct buffers nor
- * file descriptors opened for memory-mapped buffers put pressure on the garbage collector. Waiting for garbage
- * collection may lead to the depletion of off-heap memory or huge numbers of open files. There's unfortunately no
- * standard API to manually dispose of these kinds of buffers.
+ * Attempts to clean up a ByteBuffer if it is direct or memory-mapped. This uses an *unsafe* Sun API that will cause errors if one attempts to read from the
+ * disposed buffer. However, neither the bytes allocated to direct buffers nor file descriptors opened for memory-mapped buffers put pressure on the garbage
+ * collector. Waiting for garbage collection may lead to the depletion of off-heap memory or huge numbers of open files. There's unfortunately no standard
+ * API to manually dispose of these kinds of buffers.
*
* @param buffer the buffer to clean.
*/
@@ -161,10 +165,10 @@ public final class BufferedFileChannelInputStream extends InputStream {
}
/**
- * In Java 8, the type of {@code sun.nio.ch.DirectBuffer.cleaner()} was {@code sun.misc.Cleaner}, and it was possible to
- * access the method {@code sun.misc.Cleaner.clean()} to invoke it. The type changed to {@code jdk.internal.ref.Cleaner}
- * in later JDKs, and the {@code clean()} method is not accessible even with reflection. However {@code sun.misc.Unsafe}
- * added an {@code invokeCleaner()} method in JDK 9+ and this is still accessible with reflection.
+ * In Java 8, the type of {@code sun.nio.ch.DirectBuffer.cleaner()} was {@code sun.misc.Cleaner}, and it was possible to access the method
+ * {@code sun.misc.Cleaner.clean()} to invoke it. The type changed to {@code jdk.internal.ref.Cleaner} in later JDKs, and the {@code clean()} method is not
+ * accessible even with reflection. However {@code sun.misc.Unsafe} added an {@code invokeCleaner()} method in JDK 9+ and this is still accessible with
+ * reflection.
*
* @param buffer the buffer to clean. must be a DirectBuffer.
*/
diff --git a/src/main/java/org/apache/commons/io/input/MemoryMappedFileInputStream.java b/src/main/java/org/apache/commons/io/input/MemoryMappedFileInputStream.java
index ef1d4b7c..77bcda79 100644
--- a/src/main/java/org/apache/commons/io/input/MemoryMappedFileInputStream.java
+++ b/src/main/java/org/apache/commons/io/input/MemoryMappedFileInputStream.java
@@ -54,7 +54,7 @@ import org.apache.commons.io.build.AbstractStreamBuilder;
*
* @since 2.12.0
*/
-public class MemoryMappedFileInputStream extends InputStream {
+public final class MemoryMappedFileInputStream extends InputStream {
/**
* Builds a new {@link MemoryMappedFileInputStream} instance.
@@ -77,6 +77,11 @@ public class MemoryMappedFileInputStream extends InputStream {
setBufferSize(DEFAULT_BUFFER_SIZE);
}
+ /**
+ * Constructs a new instance.
+ *
+ * @throws UnsupportedOperationException if the origin cannot be converted to a Path.
+ */
@Override
public MemoryMappedFileInputStream get() throws IOException {
return new MemoryMappedFileInputStream(getOrigin().getPath(), getBufferSize());
@@ -111,28 +116,14 @@ public class MemoryMappedFileInputStream extends InputStream {
*/
private long nextBufferPosition;
- /**
- * Constructs a new instance.
- *
- * @param file The path of the file to open.
- * @throws IOException If an I/O error occurs
- * @deprecated Use {@link #builder()}
- */
- @Deprecated
- public MemoryMappedFileInputStream(final Path file) throws IOException {
- this(file, DEFAULT_BUFFER_SIZE);
- }
-
/**
* Constructs a new instance.
*
* @param file The path of the file to open.
* @param bufferSize Size of the sliding buffer.
* @throws IOException If an I/O error occurs.
- * @deprecated Use {@link #builder()}
*/
- @Deprecated
- public MemoryMappedFileInputStream(final Path file, final int bufferSize) throws IOException {
+ private MemoryMappedFileInputStream(final Path file, final int bufferSize) throws IOException {
this.bufferSize = bufferSize;
this.channel = FileChannel.open(file, StandardOpenOption.READ);
}
diff --git a/src/main/java/org/apache/commons/io/input/MessageDigestCalculatingInputStream.java b/src/main/java/org/apache/commons/io/input/MessageDigestCalculatingInputStream.java
index 4bf401c8..dea07395 100644
--- a/src/main/java/org/apache/commons/io/input/MessageDigestCalculatingInputStream.java
+++ b/src/main/java/org/apache/commons/io/input/MessageDigestCalculatingInputStream.java
@@ -67,6 +67,11 @@ public class MessageDigestCalculatingInputStream extends ObservableInputStream {
}
}
+ /**
+ * Constructs a new instance.
+ *
+ * @throws UnsupportedOperationException if the origin cannot be converted to an InputStream.
+ */
@SuppressWarnings("resource")
@Override
public MessageDigestCalculatingInputStream get() throws IOException {
diff --git a/src/main/java/org/apache/commons/io/input/RandomAccessFileInputStream.java b/src/main/java/org/apache/commons/io/input/RandomAccessFileInputStream.java
index b2f3624f..02737b80 100644
--- a/src/main/java/org/apache/commons/io/input/RandomAccessFileInputStream.java
+++ b/src/main/java/org/apache/commons/io/input/RandomAccessFileInputStream.java
@@ -51,6 +51,11 @@ public class RandomAccessFileInputStream extends InputStream {
private RandomAccessFile randomAccessFile;
private boolean closeOnClose;
+ /**
+ * Constructs a new instance.
+ *
+ * @throws UnsupportedOperationException if the origin cannot be converted to a File.
+ */
@SuppressWarnings("resource") // Caller closes depending on settings
@Override
public RandomAccessFileInputStream get() throws IOException {
diff --git a/src/main/java/org/apache/commons/io/input/ReadAheadInputStream.java b/src/main/java/org/apache/commons/io/input/ReadAheadInputStream.java
index 4de83cc9..4f1d5a19 100644
--- a/src/main/java/org/apache/commons/io/input/ReadAheadInputStream.java
+++ b/src/main/java/org/apache/commons/io/input/ReadAheadInputStream.java
@@ -62,6 +62,11 @@ public class ReadAheadInputStream extends InputStream {
private ExecutorService executorService;
+ /**
+ * Constructs a new instance.
+ *
+ * @throws UnsupportedOperationException if the origin cannot be converted to an InputStream.
+ */
@SuppressWarnings("resource")
@Override
public ReadAheadInputStream get() throws IOException {
diff --git a/src/main/java/org/apache/commons/io/input/ReaderInputStream.java b/src/main/java/org/apache/commons/io/input/ReaderInputStream.java
index 39d05ef0..e816acc6 100644
--- a/src/main/java/org/apache/commons/io/input/ReaderInputStream.java
+++ b/src/main/java/org/apache/commons/io/input/ReaderInputStream.java
@@ -96,6 +96,11 @@ public class ReaderInputStream extends InputStream {
private CharsetEncoder charsetEncoder = super.getCharset().newEncoder();
+ /**
+ * Constructs a new instance.
+ *
+ * @throws UnsupportedOperationException if the origin cannot be converted to a Reader.
+ */
@SuppressWarnings("resource")
@Override
public ReaderInputStream get() throws IOException {
diff --git a/src/main/java/org/apache/commons/io/input/ReversedLinesFileReader.java b/src/main/java/org/apache/commons/io/input/ReversedLinesFileReader.java
index fe0eff0a..467450f0 100644
--- a/src/main/java/org/apache/commons/io/input/ReversedLinesFileReader.java
+++ b/src/main/java/org/apache/commons/io/input/ReversedLinesFileReader.java
@@ -68,6 +68,11 @@ public class ReversedLinesFileReader implements Closeable {
setBufferSize(DEFAULT_BLOCK_SIZE);
}
+ /**
+ * Constructs a new instance.
+ *
+ * @throws UnsupportedOperationException if the origin cannot be converted to a Path.
+ */
@Override
public ReversedLinesFileReader get() throws IOException {
return new ReversedLinesFileReader(getOrigin().getPath(), getBufferSize(), getCharset());
diff --git a/src/main/java/org/apache/commons/io/input/Tailer.java b/src/main/java/org/apache/commons/io/input/Tailer.java
index d29cb2bc..d5050c70 100644
--- a/src/main/java/org/apache/commons/io/input/Tailer.java
+++ b/src/main/java/org/apache/commons/io/input/Tailer.java
@@ -205,6 +205,11 @@ public class Tailer implements Runnable, AutoCloseable {
return this;
}
+ /**
+ * Sets the origin.
+ *
+ * @throws UnsupportedOperationException if the origin cannot be converted to a Path.
+ */
@Override
protected Builder setOrigin(final AbstractOrigin<?, ?> origin) {
setTailable(new TailablePath(origin.getPath()));
diff --git a/src/main/java/org/apache/commons/io/input/UncheckedBufferedReader.java b/src/main/java/org/apache/commons/io/input/UncheckedBufferedReader.java
index 588cb328..78524736 100644
--- a/src/main/java/org/apache/commons/io/input/UncheckedBufferedReader.java
+++ b/src/main/java/org/apache/commons/io/input/UncheckedBufferedReader.java
@@ -61,6 +61,11 @@ public final class UncheckedBufferedReader extends BufferedReader {
*/
public static class Builder extends AbstractStreamBuilder<UncheckedBufferedReader, Builder> {
+ /**
+ * Constructs a new instance.
+ *
+ * @throws UnsupportedOperationException if the origin cannot be converted to a Reader.
+ */
@Override
public UncheckedBufferedReader get() {
// This an unchecked class, so this method is as well.
diff --git a/src/main/java/org/apache/commons/io/input/UncheckedFilterReader.java b/src/main/java/org/apache/commons/io/input/UncheckedFilterReader.java
index ab219c2c..0dede00d 100644
--- a/src/main/java/org/apache/commons/io/input/UncheckedFilterReader.java
+++ b/src/main/java/org/apache/commons/io/input/UncheckedFilterReader.java
@@ -57,6 +57,11 @@ public final class UncheckedFilterReader extends FilterReader {
*/
public static class Builder extends AbstractStreamBuilder<UncheckedFilterReader, Builder> {
+ /**
+ * Constructs a new instance.
+ *
+ * @throws UnsupportedOperationException if the origin cannot be converted to a Reader.
+ */
@Override
public UncheckedFilterReader get() {
// This an unchecked class, so this method is as well.
diff --git a/src/main/java/org/apache/commons/io/input/UnsynchronizedBufferedInputStream.java b/src/main/java/org/apache/commons/io/input/UnsynchronizedBufferedInputStream.java
index fc90c3f3..2c438500 100644
--- a/src/main/java/org/apache/commons/io/input/UnsynchronizedBufferedInputStream.java
+++ b/src/main/java/org/apache/commons/io/input/UnsynchronizedBufferedInputStream.java
@@ -71,6 +71,11 @@ public final class UnsynchronizedBufferedInputStream extends UnsynchronizedFilte
*/
public static class Builder extends AbstractStreamBuilder<UnsynchronizedBufferedInputStream, Builder> {
+ /**
+ * Constructs a new instance.
+ *
+ * @throws UnsupportedOperationException if the origin cannot be converted to an InputStream.
+ */
@SuppressWarnings("resource") // Caller closes.
@Override
public UnsynchronizedBufferedInputStream get() throws IOException {
@@ -312,7 +317,7 @@ public final class UnsynchronizedBufferedInputStream extends UnsynchronizedFilte
if (fillBuffer(localIn, localBuf) == IOUtils.EOF) {
return required == length ? IOUtils.EOF : length - required;
}
- // localBuf may have been invalidated by fillbuf
+ // localBuf may have been invalidated by fillBuffer()
if (localBuf != buffer) {
localBuf = buffer;
if (localBuf == null) {
diff --git a/src/main/java/org/apache/commons/io/input/UnsynchronizedByteArrayInputStream.java b/src/main/java/org/apache/commons/io/input/UnsynchronizedByteArrayInputStream.java
index 4d84c655..740e7290 100644
--- a/src/main/java/org/apache/commons/io/input/UnsynchronizedByteArrayInputStream.java
+++ b/src/main/java/org/apache/commons/io/input/UnsynchronizedByteArrayInputStream.java
@@ -26,9 +26,8 @@ import java.util.Objects;
import org.apache.commons.io.build.AbstractStreamBuilder;
/**
- * This is an alternative to {@link java.io.ByteArrayInputStream}
- * which removes the synchronization overhead for non-concurrent
- * access; as such this class is not thread-safe.
+ * This is an alternative to {@link java.io.ByteArrayInputStream} which removes the synchronization overhead for non-concurrent access; as such this class is
+ * not thread-safe.
*
* @see ByteArrayInputStream
* @since 2.7
@@ -41,6 +40,7 @@ public class UnsynchronizedByteArrayInputStream extends InputStream {
* <p>
* Using a Byte Array:
* </p>
+ *
* <pre>{@code
* UnsynchronizedByteArrayInputStream s = UnsynchronizedByteArrayInputStream.builder()
* .setByteArray(byteArray)
@@ -51,6 +51,7 @@ public class UnsynchronizedByteArrayInputStream extends InputStream {
* <p>
* Using File IO:
* </p>
+ *
* <pre>{@code
* UnsynchronizedByteArrayInputStream s = UnsynchronizedByteArrayInputStream.builder()
* .setFile(file)
@@ -61,6 +62,7 @@ public class UnsynchronizedByteArrayInputStream extends InputStream {
* <p>
* Using NIO Path:
* </p>
+ *
* <pre>{@code
* UnsynchronizedByteArrayInputStream s = UnsynchronizedByteArrayInputStream.builder()
* .setPath(path)
@@ -74,18 +76,23 @@ public class UnsynchronizedByteArrayInputStream extends InputStream {
private int offset;
private int length;
+ /**
+ * Constructs a new instance.
+ *
+ * @throws UnsupportedOperationException if the origin cannot be converted to a byte array.
+ */
@Override
public UnsynchronizedByteArrayInputStream get() throws IOException {
return new UnsynchronizedByteArrayInputStream(getOrigin().getByteArray(), offset, length);
}
@Override
- public Builder setByteArray(byte[] origin) {
+ public Builder setByteArray(final byte[] origin) {
length = Objects.requireNonNull(origin, "origin").length;
return super.setByteArray(origin);
}
- public Builder setLength(int length) {
+ public Builder setLength(final int length) {
if (length < 0) {
throw new IllegalArgumentException("length cannot be negative");
}
@@ -93,7 +100,7 @@ public class UnsynchronizedByteArrayInputStream extends InputStream {
return this;
}
- public Builder setOffset(int offset) {
+ public Builder setOffset(final int offset) {
if (offset < 0) {
throw new IllegalArgumentException("offset cannot be negative");
}
@@ -125,8 +132,7 @@ public class UnsynchronizedByteArrayInputStream extends InputStream {
/**
* End Of Data.
*
- * Similar to data.length,
- * i.e. the last readable offset + 1.
+ * Similar to data.length, i.e. the last readable offset + 1.
*/
private final int eod;
@@ -157,7 +163,7 @@ public class UnsynchronizedByteArrayInputStream extends InputStream {
/**
* Creates a new byte array input stream.
*
- * @param data the buffer
+ * @param data the buffer
* @param offset the offset into the buffer
*
* @throws IllegalArgumentException if the offset is less than zero
@@ -178,7 +184,7 @@ public class UnsynchronizedByteArrayInputStream extends InputStream {
/**
* Creates a new byte array input stream.
*
- * @param data the buffer
+ * @param data the buffer
* @param offset the offset into the buffer
* @param length the length of the buffer
*
diff --git a/src/main/java/org/apache/commons/io/input/UnsynchronizedFilterInputStream.java b/src/main/java/org/apache/commons/io/input/UnsynchronizedFilterInputStream.java
index 918c1b19..3113c5a8 100644
--- a/src/main/java/org/apache/commons/io/input/UnsynchronizedFilterInputStream.java
+++ b/src/main/java/org/apache/commons/io/input/UnsynchronizedFilterInputStream.java
@@ -48,7 +48,6 @@ public class UnsynchronizedFilterInputStream extends InputStream {
* <pre>{@code
* UnsynchronizedFilterInputStream s = UnsynchronizedFilterInputStream.builder()
* .setFile(file)
- * .setBufferSize(8192)
* .get()}
* </pre>
* <p>
@@ -57,12 +56,16 @@ public class UnsynchronizedFilterInputStream extends InputStream {
* <pre>{@code
* UnsynchronizedFilterInputStream s = UnsynchronizedFilterInputStream.builder()
* .setPath(path)
- * .setBufferSize(8192)
* .get()}
* </pre>
*/
public static class Builder extends AbstractStreamBuilder<UnsynchronizedFilterInputStream, Builder> {
+ /**
+ * Constructs a new instance.
+ *
+ * @throws UnsupportedOperationException if the origin cannot be converted to an InputStream.
+ */
@SuppressWarnings("resource") // Caller closes.
@Override
public UnsynchronizedFilterInputStream get() throws IOException {
@@ -90,7 +93,7 @@ public class UnsynchronizedFilterInputStream extends InputStream {
*
* @param inputStream the non-null InputStream to filter reads on.
*/
- protected UnsynchronizedFilterInputStream(final InputStream inputStream) {
+ UnsynchronizedFilterInputStream(final InputStream inputStream) {
this.inputStream = inputStream;
}
diff --git a/src/main/java/org/apache/commons/io/input/XmlStreamReader.java b/src/main/java/org/apache/commons/io/input/XmlStreamReader.java
index e5924eac..7fa756d2 100644
--- a/src/main/java/org/apache/commons/io/input/XmlStreamReader.java
+++ b/src/main/java/org/apache/commons/io/input/XmlStreamReader.java
@@ -116,6 +116,11 @@ public class XmlStreamReader extends Reader {
private boolean lenient = true;
private String httpContentType;
+ /**
+ * Constructs a new instance.
+ *
+ * @throws UnsupportedOperationException if the origin cannot be converted to an InputStream.
+ */
@SuppressWarnings("resource")
@Override
public XmlStreamReader get() throws IOException {
diff --git a/src/main/java/org/apache/commons/io/output/FileWriterWithEncoding.java b/src/main/java/org/apache/commons/io/output/FileWriterWithEncoding.java
index 429508d4..c2bb1750 100644
--- a/src/main/java/org/apache/commons/io/output/FileWriterWithEncoding.java
+++ b/src/main/java/org/apache/commons/io/output/FileWriterWithEncoding.java
@@ -77,6 +77,11 @@ public class FileWriterWithEncoding extends ProxyWriter {
private CharsetEncoder charsetEncoder = super.getCharset().newEncoder();
+ /**
+ * Constructs a new instance.
+ *
+ * @throws UnsupportedOperationException if the origin cannot be converted to a File.
+ */
@SuppressWarnings("resource")
@Override
public FileWriterWithEncoding get() throws IOException {
diff --git a/src/main/java/org/apache/commons/io/output/LockableFileWriter.java b/src/main/java/org/apache/commons/io/output/LockableFileWriter.java
index c784f51d..4905cfd6 100644
--- a/src/main/java/org/apache/commons/io/output/LockableFileWriter.java
+++ b/src/main/java/org/apache/commons/io/output/LockableFileWriter.java
@@ -72,6 +72,11 @@ public class LockableFileWriter extends Writer {
setBufferSize(AbstractByteArrayOutputStream.DEFAULT_SIZE);
}
+ /**
+ * Constructs a new instance.
+ *
+ * @throws UnsupportedOperationException if the origin cannot be converted to a File.
+ */
@Override
public LockableFileWriter get() throws IOException {
return new LockableFileWriter(getOrigin().getFile(), getCharset(), append, lockDirectory.getFile().toString());
diff --git a/src/main/java/org/apache/commons/io/output/UncheckedFilterOutputStream.java b/src/main/java/org/apache/commons/io/output/UncheckedFilterOutputStream.java
index fe7223ac..840c3124 100644
--- a/src/main/java/org/apache/commons/io/output/UncheckedFilterOutputStream.java
+++ b/src/main/java/org/apache/commons/io/output/UncheckedFilterOutputStream.java
@@ -33,7 +33,7 @@ import org.apache.commons.io.function.Uncheck;
* @see UncheckedIOException
* @since 2.12.0
*/
-public class UncheckedFilterOutputStream extends FilterOutputStream {
+public final class UncheckedFilterOutputStream extends FilterOutputStream {
/**
* Builds a new {@link UncheckedFilterOutputStream} instance.
@@ -56,6 +56,11 @@ public class UncheckedFilterOutputStream extends FilterOutputStream {
*/
public static class Builder extends AbstractStreamBuilder<UncheckedFilterOutputStream, Builder> {
+ /**
+ * Constructs a new instance.
+ *
+ * @throws UnsupportedOperationException if the origin cannot be converted to an OutputStream.
+ */
@SuppressWarnings("resource")
@Override
public UncheckedFilterOutputStream get() throws IOException {
@@ -79,7 +84,7 @@ public class UncheckedFilterOutputStream extends FilterOutputStream {
* @param outputStream the underlying output stream, or {@code null} if this instance is to be created without an
* underlying stream.
*/
- public UncheckedFilterOutputStream(final OutputStream outputStream) {
+ private UncheckedFilterOutputStream(final OutputStream outputStream) {
super(outputStream);
}
diff --git a/src/main/java/org/apache/commons/io/output/UncheckedFilterWriter.java b/src/main/java/org/apache/commons/io/output/UncheckedFilterWriter.java
index e64a4ced..3fe885f0 100644
--- a/src/main/java/org/apache/commons/io/output/UncheckedFilterWriter.java
+++ b/src/main/java/org/apache/commons/io/output/UncheckedFilterWriter.java
@@ -22,6 +22,7 @@ import java.io.IOException;
import java.io.UncheckedIOException;
import java.io.Writer;
+import org.apache.commons.io.build.AbstractStreamBuilder;
import org.apache.commons.io.function.Uncheck;
/**
@@ -32,17 +33,49 @@ import org.apache.commons.io.function.Uncheck;
* @see UncheckedIOException
* @since 2.12.0
*/
-public class UncheckedFilterWriter extends FilterWriter {
+public final class UncheckedFilterWriter extends FilterWriter {
/**
- * Creates a new filtered writer.
+ * Builds a new {@link UncheckedFilterWriter} instance.
+ * <p>
+ * Using File IO:
+ * </p>
+ * <pre>{@code
+ * UncheckedFilterWriter s = UncheckedFilterWriter.builder()
+ * .setFile(file)
+ * .get()}
+ * </pre>
+ * <p>
+ * Using NIO Path:
+ * </p>
+ * <pre>{@code
+ * UncheckedFilterWriter s = UncheckedFilterWriter.builder()
+ * .setPath(path)
+ * .get()}
+ * </pre>
+ */
+ public static class Builder extends AbstractStreamBuilder<UncheckedFilterWriter, Builder> {
+
+ /**
+ * Constructs a new instance.
+ *
+ * @throws UnsupportedOperationException if the origin cannot be converted to a Writer.
+ */
+ @SuppressWarnings("resource")
+ @Override
+ public UncheckedFilterWriter get() throws IOException {
+ return new UncheckedFilterWriter(getOrigin().getWriter(getCharset()));
+ }
+
+ }
+
+ /**
+ * Constructs a new {@link Builder}.
*
- * @param writer a Writer object providing the underlying stream.
- * @return a new UncheckedFilterReader.
- * @throws NullPointerException if {@code writer} is {@code null}.
+ * @return a new {@link Builder}.
*/
- public static UncheckedFilterWriter on(final Writer writer) {
- return new UncheckedFilterWriter(writer);
+ public static Builder builder() {
+ return new Builder();
}
/**
@@ -51,7 +84,7 @@ public class UncheckedFilterWriter extends FilterWriter {
* @param writer a Writer object providing the underlying stream.
* @throws NullPointerException if {@code writer} is {@code null}.
*/
- protected UncheckedFilterWriter(final Writer writer) {
+ private UncheckedFilterWriter(final Writer writer) {
super(writer);
}
diff --git a/src/main/java/org/apache/commons/io/output/UnsynchronizedByteArrayOutputStream.java b/src/main/java/org/apache/commons/io/output/UnsynchronizedByteArrayOutputStream.java
index 6f8ee73e..31f57244 100644
--- a/src/main/java/org/apache/commons/io/output/UnsynchronizedByteArrayOutputStream.java
+++ b/src/main/java/org/apache/commons/io/output/UnsynchronizedByteArrayOutputStream.java
@@ -21,6 +21,7 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
+import org.apache.commons.io.build.AbstractStreamBuilder;
import org.apache.commons.io.function.Uncheck;
import org.apache.commons.io.input.UnsynchronizedByteArrayInputStream;
@@ -32,6 +33,48 @@ import org.apache.commons.io.input.UnsynchronizedByteArrayInputStream;
//@NotThreadSafe
public final class UnsynchronizedByteArrayOutputStream extends AbstractByteArrayOutputStream {
+ /**
+ * Builds a new {@link UnsynchronizedByteArrayOutputStream} instance.
+ * <p>
+ * Using File IO:
+ * </p>
+ * <pre>{@code
+ * UnsynchronizedByteArrayOutputStream s = UnsynchronizedByteArrayOutputStream.builder()
+ * .setBufferSize(8192)
+ * .get()}
+ * </pre>
+ * <p>
+ * Using NIO Path:
+ * </p>
+ * <pre>{@code
+ * UnsynchronizedByteArrayOutputStream s = UnsynchronizedByteArrayOutputStream.builder()
+ * .setBufferSize(8192)
+ * .get()}
+ * </pre>
+ */
+ public static class Builder extends AbstractStreamBuilder<UnsynchronizedByteArrayOutputStream, Builder> {
+
+ /**
+ * Constructs a new instance.
+ *
+ * Only uses the buffer size attribute.
+ */
+ @Override
+ public UnsynchronizedByteArrayOutputStream get() {
+ return new UnsynchronizedByteArrayOutputStream(getBufferSize());
+ }
+
+ }
+
+ /**
+ * Constructs a new {@link Builder}.
+ *
+ * @return a new {@link Builder}.
+ */
+ public static Builder builder() {
+ return new Builder();
+ }
+
/**
* Fetches entire contents of an {@link InputStream} and represent same data as result InputStream.
* <p>
@@ -73,7 +116,7 @@ public final class UnsynchronizedByteArrayOutputStream extends AbstractByteArray
*/
public static InputStream toBufferedInputStream(final InputStream input, final int size) throws IOException {
// It does not matter if a ByteArrayOutputStream is not closed as close() is a no-op
- try (UnsynchronizedByteArrayOutputStream output = new UnsynchronizedByteArrayOutputStream(size)) {
+ try (UnsynchronizedByteArrayOutputStream output = builder().setBufferSize(size).get()) {
output.write(input);
return output.toInputStream();
}
@@ -81,8 +124,11 @@ public final class UnsynchronizedByteArrayOutputStream extends AbstractByteArray
/**
* Creates a new byte array output stream. The buffer capacity is initially
+ *
* {@value AbstractByteArrayOutputStream#DEFAULT_SIZE} bytes, though its size increases if necessary.
+ * @deprecated Use {@link #builder()}.
*/
+ @Deprecated
public UnsynchronizedByteArrayOutputStream() {
this(DEFAULT_SIZE);
}
@@ -92,7 +138,9 @@ public final class UnsynchronizedByteArrayOutputStream extends AbstractByteArray
*
* @param size the initial size
* @throws IllegalArgumentException if size is negative
+ * @deprecated Use {@link #builder()}.
*/
+ @Deprecated
public UnsynchronizedByteArrayOutputStream(final int size) {
if (size < 0) {
throw new IllegalArgumentException("Negative initial size: " + size);
diff --git a/src/main/java/org/apache/commons/io/output/WriterOutputStream.java b/src/main/java/org/apache/commons/io/output/WriterOutputStream.java
index 06d5ccd6..e201f69b 100644
--- a/src/main/java/org/apache/commons/io/output/WriterOutputStream.java
+++ b/src/main/java/org/apache/commons/io/output/WriterOutputStream.java
@@ -95,6 +95,11 @@ public class WriterOutputStream extends OutputStream {
this.charsetDecoder = getCharset().newDecoder();
}
+ /**
+ * Constructs a new instance.
+ *
+ * @throws UnsupportedOperationException if the origin cannot be converted to a Writer.
+ */
@SuppressWarnings("resource")
@Override
public WriterOutputStream get() throws IOException {
@@ -157,7 +162,7 @@ public class WriterOutputStream extends OutputStream {
}
/**
- * Check if the JDK in use properly supports the given charset.
+ * Checks if the JDK in use properly supports the given charset.
*
* @param charset the charset to check the support for
*/
diff --git a/src/main/java/org/apache/commons/io/output/XmlStreamWriter.java b/src/main/java/org/apache/commons/io/output/XmlStreamWriter.java
index d0f659d1..1142c70e 100644
--- a/src/main/java/org/apache/commons/io/output/XmlStreamWriter.java
+++ b/src/main/java/org/apache/commons/io/output/XmlStreamWriter.java
@@ -65,6 +65,11 @@ public class XmlStreamWriter extends Writer {
setCharset(StandardCharsets.UTF_8);
}
+ /**
+ * Constructs a new instance.
+ *
+ * @throws UnsupportedOperationException if the origin cannot be converted to an OutputStream.
+ */
@SuppressWarnings("resource")
@Override
public XmlStreamWriter get() throws IOException {
diff --git a/src/test/java/org/apache/commons/io/input/MemoryMappedFileInputStreamTest.java b/src/test/java/org/apache/commons/io/input/MemoryMappedFileInputStreamTest.java
index ce3c2d61..a26b46a8 100644
--- a/src/test/java/org/apache/commons/io/input/MemoryMappedFileInputStreamTest.java
+++ b/src/test/java/org/apache/commons/io/input/MemoryMappedFileInputStreamTest.java
@@ -62,6 +62,14 @@ public class MemoryMappedFileInputStreamTest {
return Files.write(Files.createTempFile(tempDir, null, null), RandomUtils.nextBytes(size));
}
+ private MemoryMappedFileInputStream newStream(final Path file) throws IOException {
+ return MemoryMappedFileInputStream.builder().setPath(file).get();
+ }
+
+ private MemoryMappedFileInputStream newStream(final Path file, final int bufferSize) throws IOException {
+ return MemoryMappedFileInputStream.builder().setPath(file).setBufferSize(bufferSize).get();
+ }
+
@Test
void testAlternateBufferSize() throws IOException {
// setup
@@ -69,7 +77,7 @@ public class MemoryMappedFileInputStreamTest {
final byte[] expectedData = Files.readAllBytes(file);
// test
- try (InputStream inputStream = new MemoryMappedFileInputStream(file, 1024)) {
+ try (InputStream inputStream = newStream(file, 1024)) {
// verify
assertArrayEquals(expectedData, IOUtils.toByteArray(inputStream));
}
@@ -80,7 +88,7 @@ public class MemoryMappedFileInputStreamTest {
// setup
final Path file = createTestFile(0);
// test
- try (InputStream inputStream = new MemoryMappedFileInputStream(file)) {
+ try (InputStream inputStream = newStream(file)) {
// verify
assertArrayEquals(EMPTY_BYTE_ARRAY, IOUtils.toByteArray(inputStream));
}
@@ -93,7 +101,7 @@ public class MemoryMappedFileInputStreamTest {
final byte[] expectedData = Files.readAllBytes(file);
// test
- try (InputStream inputStream = new MemoryMappedFileInputStream(file)) {
+ try (InputStream inputStream = newStream(file)) {
// verify
assertArrayEquals(expectedData, IOUtils.toByteArray(inputStream));
}
@@ -105,7 +113,7 @@ public class MemoryMappedFileInputStreamTest {
final Path file = createTestFile(1 * 1024 * 1024);
// test
- try (InputStream inputStream = new MemoryMappedFileInputStream(file, 1024)) {
+ try (InputStream inputStream = newStream(file, 1024)) {
inputStream.close();
// verify
Assertions.assertThrows(IOException.class, () -> IOUtils.toByteArray(inputStream));
@@ -118,7 +126,7 @@ public class MemoryMappedFileInputStreamTest {
final Path file = createTestFile(2);
final byte[] expectedData = Files.readAllBytes(file);
// test
- try (InputStream inputStream = new MemoryMappedFileInputStream(file, 1024)) {
+ try (InputStream inputStream = newStream(file, 1024)) {
final int b1 = inputStream.read();
final int b2 = inputStream.read();
assertEquals(-1, inputStream.read());
@@ -134,7 +142,7 @@ public class MemoryMappedFileInputStreamTest {
final byte[] expectedData = Files.readAllBytes(file);
// test
- try (InputStream inputStream = new MemoryMappedFileInputStream(file, 10)) {
+ try (InputStream inputStream = newStream(file, 10)) {
assertEquals(1, inputStream.skip(1));
final byte[] data = IOUtils.toByteArray(inputStream);
// verify
@@ -147,7 +155,7 @@ public class MemoryMappedFileInputStreamTest {
// setup
final Path file = createTestFile(0);
// test
- try (InputStream inputStream = new MemoryMappedFileInputStream(file)) {
+ try (InputStream inputStream = newStream(file)) {
assertEquals(0, inputStream.skip(5));
// verify
assertArrayEquals(EMPTY_BYTE_ARRAY, IOUtils.toByteArray(inputStream));
@@ -161,7 +169,7 @@ public class MemoryMappedFileInputStreamTest {
final byte[] expectedData = Files.readAllBytes(file);
// test
- try (InputStream inputStream = new MemoryMappedFileInputStream(file, 10)) {
+ try (InputStream inputStream = newStream(file, 10)) {
IOUtils.toByteArray(inputStream, 5);
assertEquals(3, inputStream.skip(3));
final byte[] data = IOUtils.toByteArray(inputStream);
@@ -177,7 +185,7 @@ public class MemoryMappedFileInputStreamTest {
final Path file = createTestFile(10);
final byte[] expectedData = Files.readAllBytes(file);
// test
- try (InputStream inputStream = new MemoryMappedFileInputStream(file)) {
+ try (InputStream inputStream = newStream(file)) {
assertEquals(0, inputStream.skip(amountToSkip));
// verify
assertArrayEquals(expectedData, IOUtils.toByteArray(inputStream));
@@ -191,7 +199,7 @@ public class MemoryMappedFileInputStreamTest {
final byte[] expectedData = Files.readAllBytes(file);
// test
- try (InputStream inputStream = new MemoryMappedFileInputStream(file, 10)) {
+ try (InputStream inputStream = newStream(file, 10)) {
IOUtils.toByteArray(inputStream, 5);
assertEquals(6, inputStream.skip(6));
final byte[] data = IOUtils.toByteArray(inputStream);
@@ -206,7 +214,7 @@ public class MemoryMappedFileInputStreamTest {
final Path file = createTestFile(100);
// test
- try (InputStream inputStream = new MemoryMappedFileInputStream(file, 10)) {
+ try (InputStream inputStream = newStream(file, 10)) {
IOUtils.toByteArray(inputStream, 5);
assertEquals(95, inputStream.skip(96));
// verify
@@ -221,7 +229,7 @@ public class MemoryMappedFileInputStreamTest {
final byte[] expectedData = Files.readAllBytes(file);
// test
- try (InputStream inputStream = new MemoryMappedFileInputStream(file, 10)) {
+ try (InputStream inputStream = newStream(file, 10)) {
IOUtils.toByteArray(inputStream, 5);
assertEquals(5, inputStream.skip(5));
final byte[] data = IOUtils.toByteArray(inputStream);
@@ -267,7 +275,7 @@ public class MemoryMappedFileInputStreamTest {
final byte[] expectedData = Files.readAllBytes(file);
// test
- try (InputStream inputStream = new MemoryMappedFileInputStream(file)) {
+ try (InputStream inputStream = newStream(file)) {
// verify
assertArrayEquals(expectedData, IOUtils.toByteArray(inputStream));
}
diff --git a/src/test/java/org/apache/commons/io/input/UnsynchronizedFilterInputStreamTest.java b/src/test/java/org/apache/commons/io/input/UnsynchronizedFilterInputStreamTest.java
index 818e3eef..ab4e3d94 100644
--- a/src/test/java/org/apache/commons/io/input/UnsynchronizedFilterInputStreamTest.java
+++ b/src/test/java/org/apache/commons/io/input/UnsynchronizedFilterInputStreamTest.java
@@ -57,7 +57,7 @@ public class UnsynchronizedFilterInputStreamTest {
protected void setUp() throws IOException {
fileName = Files.createTempFile(getClass().getSimpleName(), ".tst");
Files.write(fileName, DATA.getBytes("UTF-8"));
- is = new UnsynchronizedFilterInputStream(Files.newInputStream(fileName));
+ is = UnsynchronizedFilterInputStream.builder().setInputStream(Files.newInputStream(fileName)).get();
}
/**
diff --git a/src/test/java/org/apache/commons/io/output/UncheckedFilterWriterTest.java b/src/test/java/org/apache/commons/io/output/UncheckedFilterWriterTest.java
index 10b0ee3c..d9c1e323 100644
--- a/src/test/java/org/apache/commons/io/output/UncheckedFilterWriterTest.java
+++ b/src/test/java/org/apache/commons/io/output/UncheckedFilterWriterTest.java
@@ -39,10 +39,10 @@ public class UncheckedFilterWriterTest {
@SuppressWarnings("resource")
@BeforeEach
- public void setUp() {
+ public void setUp() throws IOException {
exception = new IOException("test exception");
- brokenWriter = UncheckedFilterWriter.on(new BrokenWriter(exception));
- stringWriter = UncheckedFilterWriter.on(new StringWriter());
+ brokenWriter = UncheckedFilterWriter.builder().setWriter(new BrokenWriter(exception)).get();
+ stringWriter = UncheckedFilterWriter.builder().setWriter(new StringWriter()).get();
}
@SuppressWarnings("resource")
[commons-io] 02/07: Use builder and deprecate some ctors
Posted by gg...@apache.org.
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-io.git
commit bdb9f8b9095004703666675591c3c3de30e7c03a
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Wed May 3 14:05:41 2023 -0400
Use builder and deprecate some ctors
---
.../apache/commons/io/build/AbstractOrigin.java | 43 +++++-
.../commons/io/build/AbstractOriginSupplier.java | 21 +++
.../io/input/UncheckedFilterInputStream.java | 44 ++++--
.../commons/io/input/UncheckedFilterReader.java | 44 ++++--
.../io/input/UnixLineEndingInputStream.java | 49 +++----
.../input/UnsynchronizedBufferedInputStream.java | 132 ++++++++++-------
.../input/UnsynchronizedByteArrayInputStream.java | 86 +++++++++++-
.../io/input/UnsynchronizedFilterInputStream.java | 66 +++++++--
.../io/output/AbstractByteArrayOutputStream.java | 4 +-
.../UnsynchronizedByteArrayOutputStream.java | 10 +-
.../io/input/UncheckedFilterInputStreamTest.java | 16 ++-
.../io/input/UncheckedFilterReaderTest.java | 21 +--
.../UnsynchronizedBufferedInputStreamTest.java | 22 +--
.../UnsynchronizedByteArrayInputStreamTest.java | 156 ++++++++++++---------
.../input/UnsynchronizedFilterInputStreamTest.java | 8 +-
15 files changed, 498 insertions(+), 224 deletions(-)
diff --git a/src/main/java/org/apache/commons/io/build/AbstractOrigin.java b/src/main/java/org/apache/commons/io/build/AbstractOrigin.java
index 1f4b69d3..46a008ec 100644
--- a/src/main/java/org/apache/commons/io/build/AbstractOrigin.java
+++ b/src/main/java/org/apache/commons/io/build/AbstractOrigin.java
@@ -45,6 +45,28 @@ import java.util.Objects;
*/
public abstract class AbstractOrigin<T, B extends AbstractOrigin<T, B>> extends AbstractSupplier<T, B> {
+ /**
+ * A {@link File} origin.
+ */
+ public static class ByteArrayOrigin extends AbstractOrigin<byte[], ByteArrayOrigin> {
+
+ /**
+ * Constructs a new instance for the given origin.
+ *
+ * @param origin The origin.
+ */
+ public ByteArrayOrigin(final byte[] origin) {
+ super(origin);
+ }
+
+ @Override
+ public byte[] getByteArray() {
+ // No conversion
+ return get();
+ }
+
+ }
+
/**
* A {@link File} origin.
*/
@@ -61,6 +83,7 @@ public abstract class AbstractOrigin<T, B extends AbstractOrigin<T, B>> extends
@Override
public File getFile() {
+ // No conversion
return get();
}
@@ -90,6 +113,7 @@ public abstract class AbstractOrigin<T, B extends AbstractOrigin<T, B>> extends
@Override
public InputStream getInputStream(final OpenOption... options) {
+ // No conversion
return get();
}
@@ -114,6 +138,7 @@ public abstract class AbstractOrigin<T, B extends AbstractOrigin<T, B>> extends
@Override
public OutputStream getOutputStream(final OpenOption... options) {
+ // No conversion
return get();
}
@@ -140,6 +165,7 @@ public abstract class AbstractOrigin<T, B extends AbstractOrigin<T, B>> extends
@Override
public Path getPath() {
+ // No conversion
return get();
}
@@ -164,6 +190,7 @@ public abstract class AbstractOrigin<T, B extends AbstractOrigin<T, B>> extends
@Override
public Reader getReader(final Charset charset) throws IOException {
+ // No conversion
return get();
}
}
@@ -182,11 +209,6 @@ public abstract class AbstractOrigin<T, B extends AbstractOrigin<T, B>> extends
super(origin);
}
- @Override
- public URI get() {
- return origin;
- }
-
@Override
public File getFile() {
return getPath().toFile();
@@ -218,6 +240,7 @@ public abstract class AbstractOrigin<T, B extends AbstractOrigin<T, B>> extends
@Override
public Writer getWriter(final Charset charset, final OpenOption... options) throws IOException {
+ // No conversion
return get();
}
}
@@ -246,6 +269,16 @@ public abstract class AbstractOrigin<T, B extends AbstractOrigin<T, B>> extends
return origin;
}
+ /**
+ * Gets this origin as a byte array, if possible.
+ *
+ * @return this origin as a byte array, if possible.
+ * @throws IOException if an I/O error occurs.
+ */
+ public byte[] getByteArray() throws IOException {
+ return Files.readAllBytes(getPath());
+ }
+
/**
* Gets this origin as a Path, if possible.
*
diff --git a/src/main/java/org/apache/commons/io/build/AbstractOriginSupplier.java b/src/main/java/org/apache/commons/io/build/AbstractOriginSupplier.java
index 9f2c599a..e6ed6db4 100644
--- a/src/main/java/org/apache/commons/io/build/AbstractOriginSupplier.java
+++ b/src/main/java/org/apache/commons/io/build/AbstractOriginSupplier.java
@@ -27,6 +27,7 @@ import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Objects;
+import org.apache.commons.io.build.AbstractOrigin.ByteArrayOrigin;
import org.apache.commons.io.build.AbstractOrigin.FileOrigin;
import org.apache.commons.io.build.AbstractOrigin.InputStreamOrigin;
import org.apache.commons.io.build.AbstractOrigin.OutputStreamOrigin;
@@ -57,6 +58,16 @@ public abstract class AbstractOriginSupplier<T, B extends AbstractOriginSupplier
return initialBufferSize;
}
+ /**
+ * Creates a new byte array origin for a byte array.
+ *
+ * @param origin the file.
+ * @return a new file origin
+ */
+ protected static ByteArrayOrigin newByteArrayOrigin(final byte[] origin) {
+ return new ByteArrayOrigin(origin);
+ }
+
/**
* Creates a new file origin for a file.
*
@@ -180,6 +191,16 @@ public abstract class AbstractOriginSupplier<T, B extends AbstractOriginSupplier
return origin != null;
}
+ /**
+ * Sets a new origin.
+ *
+ * @param origin the new origin.
+ * @return this
+ */
+ public B setByteArray(final byte[] origin) {
+ return setOrigin(newByteArrayOrigin(origin));
+ }
+
/**
* Sets a new origin.
*
diff --git a/src/main/java/org/apache/commons/io/input/UncheckedFilterInputStream.java b/src/main/java/org/apache/commons/io/input/UncheckedFilterInputStream.java
index b69602b8..d2deaf6d 100644
--- a/src/main/java/org/apache/commons/io/input/UncheckedFilterInputStream.java
+++ b/src/main/java/org/apache/commons/io/input/UncheckedFilterInputStream.java
@@ -23,6 +23,7 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.UncheckedIOException;
+import org.apache.commons.io.build.AbstractStreamBuilder;
import org.apache.commons.io.function.Uncheck;
/**
@@ -33,17 +34,44 @@ import org.apache.commons.io.function.Uncheck;
* @see UncheckedIOException
* @since 2.12.0
*/
-public class UncheckedFilterInputStream extends FilterInputStream {
+public final class UncheckedFilterInputStream extends FilterInputStream {
/**
- * Creates a {@link UncheckedFilterInputStream}.
+ * Builds a new {@link UncheckedFilterInputStream} instance.
+ * <p>
+ * Using File IO:
+ * </p>
+ * <pre>{@code
+ * UncheckedFilterInputStream s = UncheckedFilterInputStream.builder()
+ * .setFile(file)
+ * .get()}
+ * </pre>
+ * <p>
+ * Using NIO Path:
+ * </p>
+ * <pre>{@code
+ * UncheckedFilterInputStream s = UncheckedFilterInputStream.builder()
+ * .setPath(path)
+ * .get()}
+ * </pre>
+ */
+ public static class Builder extends AbstractStreamBuilder<UncheckedFilterInputStream, Builder> {
+
+ @Override
+ public UncheckedFilterInputStream get() {
+ // This an unchecked class, so this method is as well.
+ return Uncheck.get(() -> new UncheckedFilterInputStream(getOrigin().getInputStream()));
+ }
+
+ }
+
+ /**
+ * Constructs a new {@link Builder}.
*
- * @param inputStream the underlying input stream, or {@code null} if this instance is to be created without an
- * underlying stream.
- * @return a new UncheckedFilterInputStream.
+ * @return a new {@link Builder}.
*/
- public static UncheckedFilterInputStream on(final InputStream inputStream) {
- return new UncheckedFilterInputStream(inputStream);
+ public static Builder builder() {
+ return new Builder();
}
/**
@@ -52,7 +80,7 @@ public class UncheckedFilterInputStream extends FilterInputStream {
* @param inputStream the underlying input stream, or {@code null} if this instance is to be created without an
* underlying stream.
*/
- public UncheckedFilterInputStream(final InputStream inputStream) {
+ private UncheckedFilterInputStream(final InputStream inputStream) {
super(inputStream);
}
diff --git a/src/main/java/org/apache/commons/io/input/UncheckedFilterReader.java b/src/main/java/org/apache/commons/io/input/UncheckedFilterReader.java
index 794630a0..ab219c2c 100644
--- a/src/main/java/org/apache/commons/io/input/UncheckedFilterReader.java
+++ b/src/main/java/org/apache/commons/io/input/UncheckedFilterReader.java
@@ -23,6 +23,7 @@ import java.io.Reader;
import java.io.UncheckedIOException;
import java.nio.CharBuffer;
+import org.apache.commons.io.build.AbstractStreamBuilder;
import org.apache.commons.io.function.Uncheck;
/**
@@ -33,17 +34,44 @@ import org.apache.commons.io.function.Uncheck;
* @see UncheckedIOException
* @since 2.12.0
*/
-public class UncheckedFilterReader extends FilterReader {
+public final class UncheckedFilterReader extends FilterReader {
/**
- * Creates a new filtered reader.
+ * Builds a new {@link UncheckedFilterReader} instance.
+ * <p>
+ * Using File IO:
+ * </p>
+ * <pre>{@code
+ * UncheckedFilterReader s = UncheckedFilterReader.builder()
+ * .setFile(file)
+ * .get()}
+ * </pre>
+ * <p>
+ * Using NIO Path:
+ * </p>
+ * <pre>{@code
+ * UncheckedFilterReader s = UncheckedFilterReader.builder()
+ * .setPath(path)
+ * .get()}
+ * </pre>
+ */
+ public static class Builder extends AbstractStreamBuilder<UncheckedFilterReader, Builder> {
+
+ @Override
+ public UncheckedFilterReader get() {
+ // This an unchecked class, so this method is as well.
+ return Uncheck.get(() -> new UncheckedFilterReader(getOrigin().getReader(getCharset())));
+ }
+
+ }
+
+ /**
+ * Constructs a new {@link Builder}.
*
- * @param reader a Reader object providing the underlying stream.
- * @return a new UncheckedFilterReader.
- * @throws NullPointerException if {@code reader} is {@code null}.
+ * @return a new {@link Builder}.
*/
- public static UncheckedFilterReader on(final Reader reader) {
- return new UncheckedFilterReader(reader);
+ public static Builder builder() {
+ return new Builder();
}
/**
@@ -52,7 +80,7 @@ public class UncheckedFilterReader extends FilterReader {
* @param reader a Reader object providing the underlying stream.
* @throws NullPointerException if {@code reader} is {@code null}.
*/
- public UncheckedFilterReader(final Reader reader) {
+ private UncheckedFilterReader(final Reader reader) {
super(reader);
}
diff --git a/src/main/java/org/apache/commons/io/input/UnixLineEndingInputStream.java b/src/main/java/org/apache/commons/io/input/UnixLineEndingInputStream.java
index 40dd6925..35a68493 100644
--- a/src/main/java/org/apache/commons/io/input/UnixLineEndingInputStream.java
+++ b/src/main/java/org/apache/commons/io/input/UnixLineEndingInputStream.java
@@ -30,11 +30,11 @@ import java.io.InputStream;
*/
public class UnixLineEndingInputStream extends InputStream {
- private boolean slashNSeen;
+ private boolean atSlashLf;
- private boolean slashRSeen;
+ private boolean atSlashCr;
- private boolean eofSeen;
+ private boolean atEos;
private final InputStream target;
@@ -43,11 +43,11 @@ public class UnixLineEndingInputStream extends InputStream {
/**
* Creates an input stream that filters another stream
*
- * @param in The input stream to wrap
+ * @param inputStream The input stream to wrap
* @param ensureLineFeedAtEndOfFile true to ensure that the file ends with LF
*/
- public UnixLineEndingInputStream(final InputStream in, final boolean ensureLineFeedAtEndOfFile) {
- this.target = in;
+ public UnixLineEndingInputStream(final InputStream inputStream, final boolean ensureLineFeedAtEndOfFile) {
+ this.target = inputStream;
this.ensureLineFeedAtEndOfFile = ensureLineFeedAtEndOfFile;
}
@@ -62,16 +62,17 @@ public class UnixLineEndingInputStream extends InputStream {
}
/**
- * Handles the EOF-handling at the end of the stream
- * @param previousWasSlashR Indicates if the last seen was a \r
- * @return The next char to output to the stream
+ * Handles the end of stream condition.
+ *
+ * @param previousWasSlashCr Indicates if the last seen was a {@code \r}.
+ * @return The next char to output to the stream.
*/
- private int eofGame(final boolean previousWasSlashR) {
- if (previousWasSlashR || !ensureLineFeedAtEndOfFile) {
+ private int handleEos(final boolean previousWasSlashCr) {
+ if (previousWasSlashCr || !ensureLineFeedAtEndOfFile) {
return EOF;
}
- if (!slashNSeen) {
- slashNSeen = true;
+ if (!atSlashLf) {
+ atSlashLf = true;
return LF;
}
return EOF;
@@ -90,19 +91,19 @@ public class UnixLineEndingInputStream extends InputStream {
*/
@Override
public int read() throws IOException {
- final boolean previousWasSlashR = slashRSeen;
- if (eofSeen) {
- return eofGame(previousWasSlashR);
+ final boolean previousWasSlashR = atSlashCr;
+ if (atEos) {
+ return handleEos(previousWasSlashR);
}
final int target = readWithUpdate();
- if (eofSeen) {
- return eofGame(previousWasSlashR);
+ if (atEos) {
+ return handleEos(previousWasSlashR);
}
- if (slashRSeen) {
+ if (atSlashCr) {
return LF;
}
- if (previousWasSlashR && slashNSeen) {
+ if (previousWasSlashR && atSlashLf) {
return read();
}
@@ -116,12 +117,12 @@ public class UnixLineEndingInputStream extends InputStream {
*/
private int readWithUpdate() throws IOException {
final int target = this.target.read();
- eofSeen = target == EOF;
- if (eofSeen) {
+ atEos = target == EOF;
+ if (atEos) {
return target;
}
- slashNSeen = target == LF;
- slashRSeen = target == CR;
+ atSlashLf = target == LF;
+ atSlashCr = target == CR;
return target;
}
}
diff --git a/src/main/java/org/apache/commons/io/input/UnsynchronizedBufferedInputStream.java b/src/main/java/org/apache/commons/io/input/UnsynchronizedBufferedInputStream.java
index 2352d9eb..fc90c3f3 100644
--- a/src/main/java/org/apache/commons/io/input/UnsynchronizedBufferedInputStream.java
+++ b/src/main/java/org/apache/commons/io/input/UnsynchronizedBufferedInputStream.java
@@ -22,6 +22,7 @@ import java.io.IOException;
import java.io.InputStream;
import org.apache.commons.io.IOUtils;
+import org.apache.commons.io.build.AbstractStreamBuilder;
/**
* An unsynchronized version of {@link BufferedInputStream}, not thread-safe.
@@ -45,11 +46,43 @@ import org.apache.commons.io.IOUtils;
* @since 2.12.0
*/
//@NotThreadSafe
-public class UnsynchronizedBufferedInputStream extends UnsynchronizedFilterInputStream {
+public final class UnsynchronizedBufferedInputStream extends UnsynchronizedFilterInputStream {
+
+ /**
+ * Builds a new {@link UnsynchronizedBufferedInputStream} instance.
+ * <p>
+ * Using File IO:
+ * </p>
+ * <pre>{@code
+ * UnsynchronizedBufferedInputStream s = UnsynchronizedBufferedInputStream.builder()
+ * .setFile(file)
+ * .setBufferSize(8192)
+ * .get()}
+ * </pre>
+ * <p>
+ * Using NIO Path:
+ * </p>
+ * <pre>{@code
+ * UnsynchronizedBufferedInputStream s = UnsynchronizedBufferedInputStream.builder()
+ * .setPath(path)
+ * .setBufferSize(8192)
+ * .get()}
+ * </pre>
+ */
+ public static class Builder extends AbstractStreamBuilder<UnsynchronizedBufferedInputStream, Builder> {
+
+ @SuppressWarnings("resource") // Caller closes.
+ @Override
+ public UnsynchronizedBufferedInputStream get() throws IOException {
+ return new UnsynchronizedBufferedInputStream(getOrigin().getInputStream(), getBufferSize());
+ }
+
+ }
+
/**
* The buffer containing the current bytes read from the target InputStream.
*/
- protected volatile byte[] buf;
+ protected volatile byte[] buffer;
/**
* The total number of bytes inside the byte array {@code buf}.
@@ -59,29 +92,18 @@ public class UnsynchronizedBufferedInputStream extends UnsynchronizedFilterInput
/**
* The current limit, which when passed, invalidates the current mark.
*/
- protected int marklimit;
+ protected int markLimit;
/**
* The currently marked position. -1 indicates no mark has been set or the mark has been invalidated.
*/
- protected int markpos = IOUtils.EOF;
+ protected int markPos = IOUtils.EOF;
/**
* The current position within the byte array {@code buf}.
*/
protected int pos;
- /**
- * Constructs a new {@code BufferedInputStream} on the {@link InputStream} {@code in}. The default buffer size (8 KB) is allocated and all reads can now be
- * filtered through this stream.
- *
- * @param in the InputStream the buffer reads from.
- */
- public UnsynchronizedBufferedInputStream(final InputStream in) {
- super(in);
- buf = new byte[IOUtils.DEFAULT_BUFFER_SIZE];
- }
-
/**
* Constructs a new {@code BufferedInputStream} on the {@link InputStream} {@code in}. The buffer size is specified by the parameter {@code size} and all
* reads are now filtered through this stream.
@@ -90,12 +112,12 @@ public class UnsynchronizedBufferedInputStream extends UnsynchronizedFilterInput
* @param size the size of buffer to allocate.
* @throws IllegalArgumentException if {@code size < 0}.
*/
- public UnsynchronizedBufferedInputStream(final InputStream in, final int size) {
+ private UnsynchronizedBufferedInputStream(final InputStream in, final int size) {
super(in);
if (size <= 0) {
throw new IllegalArgumentException("Size must be > 0");
}
- buf = new byte[size];
+ buffer = new byte[size];
}
/**
@@ -107,8 +129,8 @@ public class UnsynchronizedBufferedInputStream extends UnsynchronizedFilterInput
*/
@Override
public int available() throws IOException {
- final InputStream localIn = in; // 'in' could be invalidated by close()
- if (buf == null || localIn == null) {
+ final InputStream localIn = inputStream; // 'in' could be invalidated by close()
+ if (buffer == null || localIn == null) {
throw new IOException("Stream is closed");
}
return count - pos + localIn.available();
@@ -121,47 +143,51 @@ public class UnsynchronizedBufferedInputStream extends UnsynchronizedFilterInput
*/
@Override
public void close() throws IOException {
- buf = null;
- final InputStream localIn = in;
- in = null;
+ buffer = null;
+ final InputStream localIn = inputStream;
+ inputStream = null;
if (localIn != null) {
localIn.close();
}
}
- private int fillbuf(final InputStream localIn, byte[] localBuf) throws IOException {
- if (markpos == IOUtils.EOF || pos - markpos >= marklimit) {
+ private int fillBuffer(final InputStream localIn, byte[] localBuf) throws IOException {
+ if (markPos == IOUtils.EOF || pos - markPos >= markLimit) {
/* Mark position not set or exceeded readlimit */
final int result = localIn.read(localBuf);
if (result > 0) {
- markpos = IOUtils.EOF;
+ markPos = IOUtils.EOF;
pos = 0;
count = result;
}
return result;
}
- if (markpos == 0 && marklimit > localBuf.length) {
+ if (markPos == 0 && markLimit > localBuf.length) {
/* Increase buffer size to accommodate the readlimit */
int newLength = localBuf.length * 2;
- if (newLength > marklimit) {
- newLength = marklimit;
+ if (newLength > markLimit) {
+ newLength = markLimit;
}
final byte[] newbuf = new byte[newLength];
System.arraycopy(localBuf, 0, newbuf, 0, localBuf.length);
// Reassign buf, which will invalidate any local references
// FIXME: what if buf was null?
- localBuf = buf = newbuf;
- } else if (markpos > 0) {
- System.arraycopy(localBuf, markpos, localBuf, 0, localBuf.length - markpos);
+ localBuf = buffer = newbuf;
+ } else if (markPos > 0) {
+ System.arraycopy(localBuf, markPos, localBuf, 0, localBuf.length - markPos);
}
/* Set the new position and mark position */
- pos -= markpos;
- count = markpos = 0;
+ pos -= markPos;
+ count = markPos = 0;
final int bytesread = localIn.read(localBuf, pos, localBuf.length - pos);
count = bytesread <= 0 ? pos : pos + bytesread;
return bytesread;
}
+ byte[] getBuffer() {
+ return buffer;
+ }
+
/**
* Sets a mark position in this stream. The parameter {@code readlimit} indicates how many bytes can be read before a mark is invalidated. Calling
* {@code reset()} will reposition the stream back to the marked position if {@code readlimit} has not been surpassed. The underlying buffer may be
@@ -172,8 +198,8 @@ public class UnsynchronizedBufferedInputStream extends UnsynchronizedFilterInput
*/
@Override
public void mark(final int readlimit) {
- marklimit = readlimit;
- markpos = pos;
+ markLimit = readlimit;
+ markPos = pos;
}
/**
@@ -199,19 +225,19 @@ public class UnsynchronizedBufferedInputStream extends UnsynchronizedFilterInput
public int read() throws IOException {
// Use local refs since buf and in may be invalidated by an
// unsynchronized close()
- byte[] localBuf = buf;
- final InputStream localIn = in;
+ byte[] localBuf = buffer;
+ final InputStream localIn = inputStream;
if (localBuf == null || localIn == null) {
throw new IOException("Stream is closed");
}
/* Are there buffered bytes available? */
- if (pos >= count && fillbuf(localIn, localBuf) == IOUtils.EOF) {
+ if (pos >= count && fillBuffer(localIn, localBuf) == IOUtils.EOF) {
return IOUtils.EOF; /* no, fill buffer */
}
// localBuf may have been invalidated by fillbuf
- if (localBuf != buf) {
- localBuf = buf;
+ if (localBuf != buffer) {
+ localBuf = buffer;
if (localBuf == null) {
throw new IOException("Stream is closed");
}
@@ -241,7 +267,7 @@ public class UnsynchronizedBufferedInputStream extends UnsynchronizedFilterInput
public int read(final byte[] buffer, int offset, final int length) throws IOException {
// Use local ref since buf may be invalidated by an unsynchronized
// close()
- byte[] localBuf = buf;
+ byte[] localBuf = buffer;
if (localBuf == null) {
throw new IOException("Stream is closed");
}
@@ -252,7 +278,7 @@ public class UnsynchronizedBufferedInputStream extends UnsynchronizedFilterInput
if (length == 0) {
return 0;
}
- final InputStream localIn = in;
+ final InputStream localIn = inputStream;
if (localIn == null) {
throw new IOException("Stream is closed");
}
@@ -277,18 +303,18 @@ public class UnsynchronizedBufferedInputStream extends UnsynchronizedFilterInput
/*
* If we're not marked and the required size is greater than the buffer, simply read the bytes directly bypassing the buffer.
*/
- if (markpos == IOUtils.EOF && required >= localBuf.length) {
+ if (markPos == IOUtils.EOF && required >= localBuf.length) {
read = localIn.read(buffer, offset, required);
if (read == IOUtils.EOF) {
return required == length ? IOUtils.EOF : length - required;
}
} else {
- if (fillbuf(localIn, localBuf) == IOUtils.EOF) {
+ if (fillBuffer(localIn, localBuf) == IOUtils.EOF) {
return required == length ? IOUtils.EOF : length - required;
}
// localBuf may have been invalidated by fillbuf
- if (localBuf != buf) {
- localBuf = buf;
+ if (localBuf != buffer) {
+ localBuf = buffer;
if (localBuf == null) {
throw new IOException("Stream is closed");
}
@@ -318,13 +344,13 @@ public class UnsynchronizedBufferedInputStream extends UnsynchronizedFilterInput
*/
@Override
public void reset() throws IOException {
- if (buf == null) {
+ if (buffer == null) {
throw new IOException("Stream is closed");
}
- if (IOUtils.EOF == markpos) {
+ if (IOUtils.EOF == markPos) {
throw new IOException("Mark has been invalidated");
}
- pos = markpos;
+ pos = markPos;
}
/**
@@ -338,8 +364,8 @@ public class UnsynchronizedBufferedInputStream extends UnsynchronizedFilterInput
public long skip(final long amount) throws IOException {
// Use local refs since buf and in may be invalidated by an
// unsynchronized close()
- final byte[] localBuf = buf;
- final InputStream localIn = in;
+ final byte[] localBuf = buffer;
+ final InputStream localIn = inputStream;
if (localBuf == null) {
throw new IOException("Stream is closed");
}
@@ -357,8 +383,8 @@ public class UnsynchronizedBufferedInputStream extends UnsynchronizedFilterInput
long read = count - pos;
pos = count;
- if (markpos != IOUtils.EOF && amount <= marklimit) {
- if (fillbuf(localIn, localBuf) == IOUtils.EOF) {
+ if (markPos != IOUtils.EOF && amount <= markLimit) {
+ if (fillBuffer(localIn, localBuf) == IOUtils.EOF) {
return read;
}
if (count - pos >= amount - read) {
diff --git a/src/main/java/org/apache/commons/io/input/UnsynchronizedByteArrayInputStream.java b/src/main/java/org/apache/commons/io/input/UnsynchronizedByteArrayInputStream.java
index cd90b8c5..4d84c655 100644
--- a/src/main/java/org/apache/commons/io/input/UnsynchronizedByteArrayInputStream.java
+++ b/src/main/java/org/apache/commons/io/input/UnsynchronizedByteArrayInputStream.java
@@ -19,9 +19,12 @@ package org.apache.commons.io.input;
import static java.lang.Math.min;
import java.io.ByteArrayInputStream;
+import java.io.IOException;
import java.io.InputStream;
import java.util.Objects;
+import org.apache.commons.io.build.AbstractStreamBuilder;
+
/**
* This is an alternative to {@link java.io.ByteArrayInputStream}
* which removes the synchronization overhead for non-concurrent
@@ -33,11 +36,87 @@ import java.util.Objects;
//@NotThreadSafe
public class UnsynchronizedByteArrayInputStream extends InputStream {
+ /**
+ * Builds a new {@link UnsynchronizedByteArrayInputStream} instance.
+ * <p>
+ * Using a Byte Array:
+ * </p>
+ * <pre>{@code
+ * UnsynchronizedByteArrayInputStream s = UnsynchronizedByteArrayInputStream.builder()
+ * .setByteArray(byteArray)
+ * .setOffset(0)
+ * .setLength(byteArray.length)
+ * .get()}
+ * </pre>
+ * <p>
+ * Using File IO:
+ * </p>
+ * <pre>{@code
+ * UnsynchronizedByteArrayInputStream s = UnsynchronizedByteArrayInputStream.builder()
+ * .setFile(file)
+ * .setOffset(0)
+ * .setLength(byteArray.length)
+ * .get()}
+ * </pre>
+ * <p>
+ * Using NIO Path:
+ * </p>
+ * <pre>{@code
+ * UnsynchronizedByteArrayInputStream s = UnsynchronizedByteArrayInputStream.builder()
+ * .setPath(path)
+ * .setOffset(0)
+ * .setLength(byteArray.length)
+ * .get()}
+ * </pre>
+ */
+ public static class Builder extends AbstractStreamBuilder<UnsynchronizedByteArrayInputStream, Builder> {
+
+ private int offset;
+ private int length;
+
+ @Override
+ public UnsynchronizedByteArrayInputStream get() throws IOException {
+ return new UnsynchronizedByteArrayInputStream(getOrigin().getByteArray(), offset, length);
+ }
+
+ @Override
+ public Builder setByteArray(byte[] origin) {
+ length = Objects.requireNonNull(origin, "origin").length;
+ return super.setByteArray(origin);
+ }
+
+ public Builder setLength(int length) {
+ if (length < 0) {
+ throw new IllegalArgumentException("length cannot be negative");
+ }
+ this.length = length;
+ return this;
+ }
+
+ public Builder setOffset(int offset) {
+ if (offset < 0) {
+ throw new IllegalArgumentException("offset cannot be negative");
+ }
+ this.offset = offset;
+ return this;
+ }
+
+ }
+
/**
* The end of stream marker.
*/
public static final int END_OF_STREAM = -1;
+ /**
+ * Constructs a new {@link Builder}.
+ *
+ * @return a new {@link Builder}.
+ */
+ public static Builder builder() {
+ return new Builder();
+ }
+
/**
* The underlying data buffer.
*/
@@ -65,7 +144,9 @@ public class UnsynchronizedByteArrayInputStream extends InputStream {
* Creates a new byte array input stream.
*
* @param data the buffer
+ * @deprecated Use {@link #builder()}.
*/
+ @Deprecated
public UnsynchronizedByteArrayInputStream(final byte[] data) {
this.data = Objects.requireNonNull(data, "data");
this.offset = 0;
@@ -80,7 +161,9 @@ public class UnsynchronizedByteArrayInputStream extends InputStream {
* @param offset the offset into the buffer
*
* @throws IllegalArgumentException if the offset is less than zero
+ * @deprecated Use {@link #builder()}.
*/
+ @Deprecated
public UnsynchronizedByteArrayInputStream(final byte[] data, final int offset) {
Objects.requireNonNull(data, "data");
if (offset < 0) {
@@ -92,7 +175,6 @@ public class UnsynchronizedByteArrayInputStream extends InputStream {
this.markedOffset = this.offset;
}
-
/**
* Creates a new byte array input stream.
*
@@ -101,7 +183,9 @@ public class UnsynchronizedByteArrayInputStream extends InputStream {
* @param length the length of the buffer
*
* @throws IllegalArgumentException if the offset or length less than zero
+ * @deprecated Use {@link #builder()}.
*/
+ @Deprecated
public UnsynchronizedByteArrayInputStream(final byte[] data, final int offset, final int length) {
if (offset < 0) {
throw new IllegalArgumentException("offset cannot be negative");
diff --git a/src/main/java/org/apache/commons/io/input/UnsynchronizedFilterInputStream.java b/src/main/java/org/apache/commons/io/input/UnsynchronizedFilterInputStream.java
index b76c668e..918c1b19 100644
--- a/src/main/java/org/apache/commons/io/input/UnsynchronizedFilterInputStream.java
+++ b/src/main/java/org/apache/commons/io/input/UnsynchronizedFilterInputStream.java
@@ -21,6 +21,8 @@ import java.io.FilterInputStream;
import java.io.IOException;
import java.io.InputStream;
+import org.apache.commons.io.build.AbstractStreamBuilder;
+
/**
* An unsynchronized version of {@link FilterInputStream}, not thread-safe.
* <p>
@@ -38,18 +40,58 @@ import java.io.InputStream;
//@NotThreadSafe
public class UnsynchronizedFilterInputStream extends InputStream {
+ /**
+ * Builds a new {@link UnsynchronizedFilterInputStream} instance.
+ * <p>
+ * Using File IO:
+ * </p>
+ * <pre>{@code
+ * UnsynchronizedFilterInputStream s = UnsynchronizedFilterInputStream.builder()
+ * .setFile(file)
+ * .setBufferSize(8192)
+ * .get()}
+ * </pre>
+ * <p>
+ * Using NIO Path:
+ * </p>
+ * <pre>{@code
+ * UnsynchronizedFilterInputStream s = UnsynchronizedFilterInputStream.builder()
+ * .setPath(path)
+ * .setBufferSize(8192)
+ * .get()}
+ * </pre>
+ */
+ public static class Builder extends AbstractStreamBuilder<UnsynchronizedFilterInputStream, Builder> {
+
+ @SuppressWarnings("resource") // Caller closes.
+ @Override
+ public UnsynchronizedFilterInputStream get() throws IOException {
+ return new UnsynchronizedFilterInputStream(getOrigin().getInputStream());
+ }
+
+ }
+
+ /**
+ * Constructs a new {@link Builder}.
+ *
+ * @return a new {@link Builder}.
+ */
+ public static Builder builder() {
+ return new Builder();
+ }
+
/**
* The source input stream that is filtered.
*/
- protected volatile InputStream in;
+ protected volatile InputStream inputStream;
/**
* Constructs a new {@code FilterInputStream} with the specified input stream as source.
*
- * @param in the non-null InputStream to filter reads on.
+ * @param inputStream the non-null InputStream to filter reads on.
*/
- protected UnsynchronizedFilterInputStream(final InputStream in) {
- this.in = in;
+ protected UnsynchronizedFilterInputStream(final InputStream inputStream) {
+ this.inputStream = inputStream;
}
/**
@@ -60,7 +102,7 @@ public class UnsynchronizedFilterInputStream extends InputStream {
*/
@Override
public int available() throws IOException {
- return in.available();
+ return inputStream.available();
}
/**
@@ -70,7 +112,7 @@ public class UnsynchronizedFilterInputStream extends InputStream {
*/
@Override
public void close() throws IOException {
- in.close();
+ inputStream.close();
}
/**
@@ -86,7 +128,7 @@ public class UnsynchronizedFilterInputStream extends InputStream {
@SuppressWarnings("sync-override") // by design.
@Override
public void mark(final int readlimit) {
- in.mark(readlimit);
+ inputStream.mark(readlimit);
}
/**
@@ -100,7 +142,7 @@ public class UnsynchronizedFilterInputStream extends InputStream {
*/
@Override
public boolean markSupported() {
- return in.markSupported();
+ return inputStream.markSupported();
}
/**
@@ -112,7 +154,7 @@ public class UnsynchronizedFilterInputStream extends InputStream {
*/
@Override
public int read() throws IOException {
- return in.read();
+ return inputStream.read();
}
/**
@@ -141,7 +183,7 @@ public class UnsynchronizedFilterInputStream extends InputStream {
*/
@Override
public int read(final byte[] buffer, final int offset, final int count) throws IOException {
- return in.read(buffer, offset, count);
+ return inputStream.read(buffer, offset, count);
}
/**
@@ -155,7 +197,7 @@ public class UnsynchronizedFilterInputStream extends InputStream {
@SuppressWarnings("sync-override") // by design.
@Override
public void reset() throws IOException {
- in.reset();
+ inputStream.reset();
}
/**
@@ -170,6 +212,6 @@ public class UnsynchronizedFilterInputStream extends InputStream {
*/
@Override
public long skip(final long count) throws IOException {
- return in.skip(count);
+ return inputStream.skip(count);
}
}
diff --git a/src/main/java/org/apache/commons/io/output/AbstractByteArrayOutputStream.java b/src/main/java/org/apache/commons/io/output/AbstractByteArrayOutputStream.java
index c4304c6b..6e47aa39 100644
--- a/src/main/java/org/apache/commons/io/output/AbstractByteArrayOutputStream.java
+++ b/src/main/java/org/apache/commons/io/output/AbstractByteArrayOutputStream.java
@@ -70,13 +70,13 @@ public abstract class AbstractByteArrayOutputStream extends OutputStream {
/**
* Constructs an InputStream subclass.
*
- * @param buf the buffer
+ * @param buffer the buffer
* @param offset the offset into the buffer
* @param length the length of the buffer
*
* @return the InputStream subclass.
*/
- T construct(final byte[] buf, final int offset, final int length);
+ T construct(final byte[] buffer, final int offset, final int length);
}
static final int DEFAULT_SIZE = 1024;
diff --git a/src/main/java/org/apache/commons/io/output/UnsynchronizedByteArrayOutputStream.java b/src/main/java/org/apache/commons/io/output/UnsynchronizedByteArrayOutputStream.java
index f48d0435..6f8ee73e 100644
--- a/src/main/java/org/apache/commons/io/output/UnsynchronizedByteArrayOutputStream.java
+++ b/src/main/java/org/apache/commons/io/output/UnsynchronizedByteArrayOutputStream.java
@@ -21,6 +21,7 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
+import org.apache.commons.io.function.Uncheck;
import org.apache.commons.io.input.UnsynchronizedByteArrayInputStream;
/**
@@ -119,7 +120,14 @@ public final class UnsynchronizedByteArrayOutputStream extends AbstractByteArray
@Override
public InputStream toInputStream() {
- return toInputStream(UnsynchronizedByteArrayInputStream::new);
+ // @formatter:off
+ return toInputStream((buffer, offset, length) -> Uncheck
+ .get(() -> UnsynchronizedByteArrayInputStream.builder()
+ .setByteArray(buffer)
+ .setOffset(offset)
+ .setLength(length)
+ .get()));
+ // @formatter:on
}
@Override
diff --git a/src/test/java/org/apache/commons/io/input/UncheckedFilterInputStreamTest.java b/src/test/java/org/apache/commons/io/input/UncheckedFilterInputStreamTest.java
index 2da41b5f..3a77acd0 100644
--- a/src/test/java/org/apache/commons/io/input/UncheckedFilterInputStreamTest.java
+++ b/src/test/java/org/apache/commons/io/input/UncheckedFilterInputStreamTest.java
@@ -22,6 +22,7 @@ import static org.junit.jupiter.api.Assertions.assertThrows;
import java.io.BufferedInputStream;
import java.io.IOException;
+import java.io.InputStream;
import java.io.UncheckedIOException;
import org.apache.commons.io.IOUtils;
@@ -40,9 +41,9 @@ public class UncheckedFilterInputStreamTest {
@SuppressWarnings("resource")
@BeforeEach
public void beforeEach() {
- stringInputStream = UncheckedFilterInputStream.on(new BufferedInputStream(new StringInputStream("01")));
+ stringInputStream = UncheckedFilterInputStream.builder().setInputStream(new BufferedInputStream(new StringInputStream("01"))).get();
exception = new IOException("test exception");
- brokenInputStream = UncheckedFilterInputStream.on(new BrokenInputStream(exception));
+ brokenInputStream = UncheckedFilterInputStream.builder().setInputStream(new BrokenInputStream(exception)).get();
}
@Test
@@ -66,7 +67,8 @@ public class UncheckedFilterInputStreamTest {
@Test
public void testRead() {
- try (UncheckedFilterInputStream uncheckedReader = UncheckedFilterInputStream.on(stringInputStream)) {
+ final InputStream inputStream = stringInputStream;
+ try (UncheckedFilterInputStream uncheckedReader = UncheckedFilterInputStream.builder().setInputStream(inputStream).get()) {
assertEquals('0', uncheckedReader.read());
assertEquals('1', uncheckedReader.read());
assertEquals(IOUtils.EOF, uncheckedReader.read());
@@ -76,7 +78,8 @@ public class UncheckedFilterInputStreamTest {
@Test
public void testReadByteArray() {
- try (UncheckedFilterInputStream uncheckedReader = UncheckedFilterInputStream.on(stringInputStream)) {
+ final InputStream inputStream = stringInputStream;
+ try (UncheckedFilterInputStream uncheckedReader = UncheckedFilterInputStream.builder().setInputStream(inputStream).get()) {
final byte[] array = new byte[1];
assertEquals(1, uncheckedReader.read(array));
assertEquals('0', array[0]);
@@ -93,7 +96,8 @@ public class UncheckedFilterInputStreamTest {
@Test
public void testReadByteArrayIndexed() {
- try (UncheckedFilterInputStream uncheckedReader = UncheckedFilterInputStream.on(stringInputStream)) {
+ final InputStream inputStream = stringInputStream;
+ try (UncheckedFilterInputStream uncheckedReader = UncheckedFilterInputStream.builder().setInputStream(inputStream).get()) {
final byte[] array = new byte[1];
assertEquals(1, uncheckedReader.read(array, 0, 1));
assertEquals('0', array[0]);
@@ -125,7 +129,7 @@ public class UncheckedFilterInputStreamTest {
@Test
public void testResetThrows() {
- try (UncheckedFilterInputStream closedReader = UncheckedFilterInputStream.on(ClosedInputStream.INSTANCE)) {
+ try (UncheckedFilterInputStream closedReader = UncheckedFilterInputStream.builder().setInputStream(ClosedInputStream.INSTANCE).get()) {
closedReader.close();
assertThrows(UncheckedIOException.class, () -> brokenInputStream.reset());
}
diff --git a/src/test/java/org/apache/commons/io/input/UncheckedFilterReaderTest.java b/src/test/java/org/apache/commons/io/input/UncheckedFilterReaderTest.java
index 1c75795f..45262263 100644
--- a/src/test/java/org/apache/commons/io/input/UncheckedFilterReaderTest.java
+++ b/src/test/java/org/apache/commons/io/input/UncheckedFilterReaderTest.java
@@ -21,6 +21,7 @@ import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.IOException;
+import java.io.Reader;
import java.io.StringReader;
import java.io.UncheckedIOException;
import java.nio.CharBuffer;
@@ -41,9 +42,9 @@ public class UncheckedFilterReaderTest {
@SuppressWarnings("resource")
@BeforeEach
public void beforeEach() {
- ucStringReader = UncheckedFilterReader.on(new StringReader("01"));
+ ucStringReader = UncheckedFilterReader.builder().setReader(new StringReader("01")).get();
exception = new IOException("test exception");
- ucBrokenReader = UncheckedFilterReader.on(new BrokenReader(exception));
+ ucBrokenReader = UncheckedFilterReader.builder().setReader(new BrokenReader(exception)).get();
}
@Test
@@ -67,7 +68,7 @@ public class UncheckedFilterReaderTest {
@Test
public void testMarkThrows() {
- try (UncheckedFilterReader closedReader = UncheckedFilterReader.on(ClosedReader.INSTANCE)) {
+ try (UncheckedFilterReader closedReader = UncheckedFilterReader.builder().setReader(ClosedReader.INSTANCE).get()) {
closedReader.close();
assertThrows(UncheckedIOException.class, () -> closedReader.mark(1));
}
@@ -75,7 +76,8 @@ public class UncheckedFilterReaderTest {
@Test
public void testRead() {
- try (UncheckedFilterReader uncheckedReader = UncheckedFilterReader.on(ucStringReader)) {
+ final Reader reader = ucStringReader;
+ try (UncheckedFilterReader uncheckedReader = UncheckedFilterReader.builder().setReader(reader).get()) {
assertEquals('0', uncheckedReader.read());
assertEquals('1', uncheckedReader.read());
assertEquals(IOUtils.EOF, uncheckedReader.read());
@@ -85,7 +87,8 @@ public class UncheckedFilterReaderTest {
@Test
public void testReadCharArray() {
- try (UncheckedFilterReader uncheckedReader = UncheckedFilterReader.on(ucStringReader)) {
+ final Reader reader = ucStringReader;
+ try (UncheckedFilterReader uncheckedReader = UncheckedFilterReader.builder().setReader(reader).get()) {
final char[] array = new char[1];
assertEquals(1, uncheckedReader.read(array));
assertEquals('0', array[0]);
@@ -102,7 +105,8 @@ public class UncheckedFilterReaderTest {
@Test
public void testReadCharArrayIndexed() {
- try (UncheckedFilterReader uncheckedReader = UncheckedFilterReader.on(ucStringReader)) {
+ final Reader reader = ucStringReader;
+ try (UncheckedFilterReader uncheckedReader = UncheckedFilterReader.builder().setReader(reader).get()) {
final char[] array = new char[1];
assertEquals(1, uncheckedReader.read(array, 0, 1));
assertEquals('0', array[0]);
@@ -129,7 +133,8 @@ public class UncheckedFilterReaderTest {
@Test
public void testReadCharBuffer() {
- try (UncheckedFilterReader uncheckedReader = UncheckedFilterReader.on(ucStringReader)) {
+ final Reader reader = ucStringReader;
+ try (UncheckedFilterReader uncheckedReader = UncheckedFilterReader.builder().setReader(reader).get()) {
final CharBuffer buffer = CharBuffer.wrap(new char[1]);
assertEquals(1, uncheckedReader.read(buffer));
buffer.flip();
@@ -170,7 +175,7 @@ public class UncheckedFilterReaderTest {
@Test
public void testResetThrows() {
- try (UncheckedFilterReader closedReader = UncheckedFilterReader.on(ClosedReader.INSTANCE)) {
+ try (UncheckedFilterReader closedReader = UncheckedFilterReader.builder().setReader(ClosedReader.INSTANCE).get()) {
closedReader.close();
assertThrows(UncheckedIOException.class, () -> ucBrokenReader.reset());
}
diff --git a/src/test/java/org/apache/commons/io/input/UnsynchronizedBufferedInputStreamTest.java b/src/test/java/org/apache/commons/io/input/UnsynchronizedBufferedInputStreamTest.java
index 54d676e6..02951f89 100644
--- a/src/test/java/org/apache/commons/io/input/UnsynchronizedBufferedInputStreamTest.java
+++ b/src/test/java/org/apache/commons/io/input/UnsynchronizedBufferedInputStreamTest.java
@@ -18,7 +18,6 @@
package org.apache.commons.io.input;
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.assertTrue;
@@ -44,20 +43,6 @@ import org.junit.jupiter.api.Test;
*/
public class UnsynchronizedBufferedInputStreamTest {
- static class MyUnsynchronizedBufferedInputStream extends UnsynchronizedBufferedInputStream {
- static byte[] buf;
-
- MyUnsynchronizedBufferedInputStream(final InputStream is) {
- super(is);
- buf = super.buf;
- }
-
- MyUnsynchronizedBufferedInputStream(final InputStream is, final int size) {
- super(is, size);
- buf = super.buf;
- }
- }
-
private static final int BUFFER_SIZE = 4096;
public static final String DATA = StringUtils.repeat("This is a test.", 500);
@@ -203,12 +188,7 @@ public class UnsynchronizedBufferedInputStreamTest {
// is.read should now throw an exception because it will have to be filled.
assertThrows(IOException.class, () -> is.read());
- // regression test for harmony-2407
- new MyUnsynchronizedBufferedInputStream(null);
- assertNotNull(MyUnsynchronizedBufferedInputStream.buf);
- MyUnsynchronizedBufferedInputStream.buf = null;
- new MyUnsynchronizedBufferedInputStream(null, 100);
- assertNotNull(MyUnsynchronizedBufferedInputStream.buf);
+ assertThrows(NullPointerException.class, () -> UnsynchronizedBufferedInputStream.builder().setInputStream(null).setBufferSize(100).get());
}
/**
diff --git a/src/test/java/org/apache/commons/io/input/UnsynchronizedByteArrayInputStreamTest.java b/src/test/java/org/apache/commons/io/input/UnsynchronizedByteArrayInputStreamTest.java
index 6f13b4eb..866c833b 100644
--- a/src/test/java/org/apache/commons/io/input/UnsynchronizedByteArrayInputStreamTest.java
+++ b/src/test/java/org/apache/commons/io/input/UnsynchronizedByteArrayInputStreamTest.java
@@ -21,6 +21,7 @@ import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
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.IOException;
@@ -32,19 +33,46 @@ import org.junit.jupiter.api.Test;
*/
public class UnsynchronizedByteArrayInputStreamTest {
+ private UnsynchronizedByteArrayInputStream newStream(final byte[] buffer) {
+ try {
+ return UnsynchronizedByteArrayInputStream.builder().setByteArray(buffer).get();
+ } catch (IOException e) {
+ fail("Should never happen because no conversion is needed.", e);
+ return null;
+ }
+ }
+
+ private UnsynchronizedByteArrayInputStream newStream(final byte[] buffer, final int offset) {
+ try {
+ return UnsynchronizedByteArrayInputStream.builder().setByteArray(buffer).setOffset(offset).get();
+ } catch (IOException e) {
+ fail("Should never happen because no conversion is needed.", e);
+ return null;
+ }
+ }
+
+ private UnsynchronizedByteArrayInputStream newStream(final byte[] buffer, final int offset, final int length) {
+ try {
+ return UnsynchronizedByteArrayInputStream.builder().setByteArray(buffer).setOffset(offset).setLength(length).get();
+ } catch (IOException e) {
+ fail("Should never happen because no conversion is needed.", e);
+ return null;
+ }
+ }
+
@Test
public void testConstructor1() throws IOException {
final byte[] empty = IOUtils.EMPTY_BYTE_ARRAY;
final byte[] one = new byte[1];
final byte[] some = new byte[25];
- try (UnsynchronizedByteArrayInputStream is = new UnsynchronizedByteArrayInputStream(empty)) {
+ try (UnsynchronizedByteArrayInputStream is = newStream(empty)) {
assertEquals(empty.length, is.available());
}
- try (UnsynchronizedByteArrayInputStream is = new UnsynchronizedByteArrayInputStream(one)) {
+ try (UnsynchronizedByteArrayInputStream is = newStream(one)) {
assertEquals(one.length, is.available());
}
- try (UnsynchronizedByteArrayInputStream is = new UnsynchronizedByteArrayInputStream(some)) {
+ try (UnsynchronizedByteArrayInputStream is = newStream(some)) {
assertEquals(some.length, is.available());
}
}
@@ -56,25 +84,25 @@ public class UnsynchronizedByteArrayInputStreamTest {
final byte[] one = new byte[1];
final byte[] some = new byte[25];
- UnsynchronizedByteArrayInputStream is = new UnsynchronizedByteArrayInputStream(empty, 0);
+ UnsynchronizedByteArrayInputStream is = newStream(empty, 0);
assertEquals(empty.length, is.available());
- is = new UnsynchronizedByteArrayInputStream(empty, 1);
+ is = newStream(empty, 1);
assertEquals(0, is.available());
- is = new UnsynchronizedByteArrayInputStream(one, 0);
+ is = newStream(one, 0);
assertEquals(one.length, is.available());
- is = new UnsynchronizedByteArrayInputStream(one, 1);
+ is = newStream(one, 1);
assertEquals(0, is.available());
- is = new UnsynchronizedByteArrayInputStream(one, 2);
+ is = newStream(one, 2);
assertEquals(0, is.available());
- is = new UnsynchronizedByteArrayInputStream(some, 0);
+ is = newStream(some, 0);
assertEquals(some.length, is.available());
- is = new UnsynchronizedByteArrayInputStream(some, 1);
+ is = newStream(some, 1);
assertEquals(some.length - 1, is.available());
- is = new UnsynchronizedByteArrayInputStream(some, 10);
+ is = newStream(some, 10);
assertEquals(some.length - 10, is.available());
- is = new UnsynchronizedByteArrayInputStream(some, some.length);
+ is = newStream(some, some.length);
assertEquals(0, is.available());
}
@@ -85,72 +113,72 @@ public class UnsynchronizedByteArrayInputStreamTest {
final byte[] one = new byte[1];
final byte[] some = new byte[25];
- UnsynchronizedByteArrayInputStream is = new UnsynchronizedByteArrayInputStream(empty, 0);
+ UnsynchronizedByteArrayInputStream is = newStream(empty, 0);
assertEquals(empty.length, is.available());
- is = new UnsynchronizedByteArrayInputStream(empty, 1);
+ is = newStream(empty, 1);
assertEquals(0, is.available());
- is = new UnsynchronizedByteArrayInputStream(empty, 0,1);
+ is = newStream(empty, 0, 1);
assertEquals(0, is.available());
- is = new UnsynchronizedByteArrayInputStream(empty, 1,1);
+ is = newStream(empty, 1, 1);
assertEquals(0, is.available());
- is = new UnsynchronizedByteArrayInputStream(one, 0);
+ is = newStream(one, 0);
assertEquals(one.length, is.available());
- is = new UnsynchronizedByteArrayInputStream(one, 1);
+ is = newStream(one, 1);
assertEquals(one.length - 1, is.available());
- is = new UnsynchronizedByteArrayInputStream(one, 2);
+ is = newStream(one, 2);
assertEquals(0, is.available());
- is = new UnsynchronizedByteArrayInputStream(one, 0, 1);
+ is = newStream(one, 0, 1);
assertEquals(1, is.available());
- is = new UnsynchronizedByteArrayInputStream(one, 1, 1);
+ is = newStream(one, 1, 1);
assertEquals(0, is.available());
- is = new UnsynchronizedByteArrayInputStream(one, 0, 2);
+ is = newStream(one, 0, 2);
assertEquals(1, is.available());
- is = new UnsynchronizedByteArrayInputStream(one, 2, 1);
+ is = newStream(one, 2, 1);
assertEquals(0, is.available());
- is = new UnsynchronizedByteArrayInputStream(one, 2, 2);
+ is = newStream(one, 2, 2);
assertEquals(0, is.available());
- is = new UnsynchronizedByteArrayInputStream(some, 0);
+ is = newStream(some, 0);
assertEquals(some.length, is.available());
- is = new UnsynchronizedByteArrayInputStream(some, 1);
+ is = newStream(some, 1);
assertEquals(some.length - 1, is.available());
- is = new UnsynchronizedByteArrayInputStream(some, 10);
+ is = newStream(some, 10);
assertEquals(some.length - 10, is.available());
- is = new UnsynchronizedByteArrayInputStream(some, some.length);
+ is = newStream(some, some.length);
assertEquals(0, is.available());
- is = new UnsynchronizedByteArrayInputStream(some, some.length, some.length);
+ is = newStream(some, some.length, some.length);
assertEquals(0, is.available());
- is = new UnsynchronizedByteArrayInputStream(some, some.length - 1, some.length);
+ is = newStream(some, some.length - 1, some.length);
assertEquals(1, is.available());
- is = new UnsynchronizedByteArrayInputStream(some, 0, 7);
+ is = newStream(some, 0, 7);
assertEquals(7, is.available());
- is = new UnsynchronizedByteArrayInputStream(some, 7, 7);
+ is = newStream(some, 7, 7);
assertEquals(7, is.available());
- is = new UnsynchronizedByteArrayInputStream(some, 0, some.length * 2);
+ is = newStream(some, 0, some.length * 2);
assertEquals(some.length, is.available());
- is = new UnsynchronizedByteArrayInputStream(some, some.length - 1, 7);
+ is = newStream(some, some.length - 1, 7);
assertEquals(1, is.available());
}
@Test
public void testInvalidConstructor2OffsetUnder() {
assertThrows(IllegalArgumentException.class, () -> {
- new UnsynchronizedByteArrayInputStream(IOUtils.EMPTY_BYTE_ARRAY, -1);
+ newStream(IOUtils.EMPTY_BYTE_ARRAY, -1);
});
}
@Test
public void testInvalidConstructor3LengthUnder() {
assertThrows(IllegalArgumentException.class, () -> {
- new UnsynchronizedByteArrayInputStream(IOUtils.EMPTY_BYTE_ARRAY, 0, -1);
+ newStream(IOUtils.EMPTY_BYTE_ARRAY, 0, -1);
});
}
@Test
public void testInvalidConstructor3OffsetUnder() {
assertThrows(IllegalArgumentException.class, () -> {
- new UnsynchronizedByteArrayInputStream(IOUtils.EMPTY_BYTE_ARRAY, -1, 1);
+ newStream(IOUtils.EMPTY_BYTE_ARRAY, -1, 1);
});
}
@@ -158,7 +186,7 @@ public class UnsynchronizedByteArrayInputStreamTest {
@SuppressWarnings("resource") // not necessary to close these resources
public void testInvalidReadArrayExplicitLenUnder() {
final byte[] buf = IOUtils.EMPTY_BYTE_ARRAY;
- final UnsynchronizedByteArrayInputStream is = new UnsynchronizedByteArrayInputStream(new byte[] {(byte)0xa, (byte)0xb, (byte)0xc});
+ final UnsynchronizedByteArrayInputStream is = newStream(new byte[] { (byte) 0xa, (byte) 0xb, (byte) 0xc });
assertThrows(IndexOutOfBoundsException.class, () -> {
is.read(buf, 0, -1);
});
@@ -168,7 +196,7 @@ public class UnsynchronizedByteArrayInputStreamTest {
public void testInvalidReadArrayExplicitOffsetUnder() {
final byte[] buf = IOUtils.EMPTY_BYTE_ARRAY;
@SuppressWarnings("resource") // not necessary to close these resources
- final UnsynchronizedByteArrayInputStream is = new UnsynchronizedByteArrayInputStream(new byte[] {(byte)0xa, (byte)0xb, (byte)0xc});
+ final UnsynchronizedByteArrayInputStream is = newStream(new byte[] { (byte) 0xa, (byte) 0xb, (byte) 0xc });
assertThrows(IndexOutOfBoundsException.class, () -> {
is.read(buf, -1, 1);
});
@@ -178,7 +206,7 @@ public class UnsynchronizedByteArrayInputStreamTest {
public void testInvalidReadArrayExplicitRangeOver() {
final byte[] buf = IOUtils.EMPTY_BYTE_ARRAY;
@SuppressWarnings("resource") // not necessary to close these resources
- final UnsynchronizedByteArrayInputStream is = new UnsynchronizedByteArrayInputStream(new byte[] {(byte)0xa, (byte)0xb, (byte)0xc});
+ final UnsynchronizedByteArrayInputStream is = newStream(new byte[] { (byte) 0xa, (byte) 0xb, (byte) 0xc });
assertThrows(IndexOutOfBoundsException.class, () -> {
is.read(buf, 0, 1);
});
@@ -188,7 +216,7 @@ public class UnsynchronizedByteArrayInputStreamTest {
public void testInvalidReadArrayNull() {
final byte[] buf = null;
@SuppressWarnings("resource") // not necessary to close these resources
- final UnsynchronizedByteArrayInputStream is = new UnsynchronizedByteArrayInputStream(new byte[] {(byte)0xa, (byte)0xb, (byte)0xc});
+ final UnsynchronizedByteArrayInputStream is = newStream(new byte[] { (byte) 0xa, (byte) 0xb, (byte) 0xc });
assertThrows(NullPointerException.class, () -> {
is.read(buf);
});
@@ -197,7 +225,7 @@ public class UnsynchronizedByteArrayInputStreamTest {
@Test
public void testInvalidSkipNUnder() {
@SuppressWarnings("resource") // not necessary to close these resources
- final UnsynchronizedByteArrayInputStream is = new UnsynchronizedByteArrayInputStream(new byte[] {(byte)0xa, (byte)0xb, (byte)0xc});
+ final UnsynchronizedByteArrayInputStream is = newStream(new byte[] { (byte) 0xa, (byte) 0xb, (byte) 0xc });
assertThrows(IllegalArgumentException.class, () -> {
is.skip(-1);
});
@@ -206,7 +234,7 @@ public class UnsynchronizedByteArrayInputStreamTest {
@Test
public void testMarkReset() {
@SuppressWarnings("resource") // not necessary to close these resources
- final UnsynchronizedByteArrayInputStream is = new UnsynchronizedByteArrayInputStream(new byte[] {(byte)0xa, (byte)0xb, (byte)0xc});
+ final UnsynchronizedByteArrayInputStream is = newStream(new byte[] { (byte) 0xa, (byte) 0xb, (byte) 0xc });
assertTrue(is.markSupported());
assertEquals(0xa, is.read());
assertTrue(is.markSupported());
@@ -232,19 +260,18 @@ public class UnsynchronizedByteArrayInputStreamTest {
@Test
public void testReadArray() {
byte[] buf = new byte[10];
- @SuppressWarnings("resource") // not necessary to close these resources
- UnsynchronizedByteArrayInputStream is = new UnsynchronizedByteArrayInputStream(IOUtils.EMPTY_BYTE_ARRAY);
+ UnsynchronizedByteArrayInputStream is = newStream(IOUtils.EMPTY_BYTE_ARRAY);
int read = is.read(buf);
assertEquals(END_OF_STREAM, read);
assertArrayEquals(new byte[10], buf);
buf = IOUtils.EMPTY_BYTE_ARRAY;
- is = new UnsynchronizedByteArrayInputStream(new byte[]{(byte) 0xa, (byte) 0xb, (byte) 0xc});
+ is = newStream(new byte[] { (byte) 0xa, (byte) 0xb, (byte) 0xc });
read = is.read(buf);
assertEquals(0, read);
buf = new byte[10];
- is = new UnsynchronizedByteArrayInputStream(new byte[]{(byte) 0xa, (byte) 0xb, (byte) 0xc});
+ is = newStream(new byte[] { (byte) 0xa, (byte) 0xb, (byte) 0xc });
read = is.read(buf);
assertEquals(3, read);
assertEquals(0xa, buf[0]);
@@ -253,7 +280,7 @@ public class UnsynchronizedByteArrayInputStreamTest {
assertEquals(0, buf[3]);
buf = new byte[2];
- is = new UnsynchronizedByteArrayInputStream(new byte[]{(byte) 0xa, (byte) 0xb, (byte) 0xc});
+ is = newStream(new byte[] { (byte) 0xa, (byte) 0xb, (byte) 0xc });
read = is.read(buf);
assertEquals(2, read);
assertEquals(0xa, buf[0]);
@@ -266,31 +293,30 @@ public class UnsynchronizedByteArrayInputStreamTest {
@Test
public void testReadArrayExplicit() {
byte[] buf = new byte[10];
- @SuppressWarnings("resource") // not necessary to close these resources
- UnsynchronizedByteArrayInputStream is = new UnsynchronizedByteArrayInputStream(IOUtils.EMPTY_BYTE_ARRAY);
+ UnsynchronizedByteArrayInputStream is = newStream(IOUtils.EMPTY_BYTE_ARRAY);
int read = is.read(buf, 0, 10);
assertEquals(END_OF_STREAM, read);
assertArrayEquals(new byte[10], buf);
buf = new byte[10];
- is = new UnsynchronizedByteArrayInputStream(IOUtils.EMPTY_BYTE_ARRAY);
+ is = newStream(IOUtils.EMPTY_BYTE_ARRAY);
read = is.read(buf, 4, 2);
assertEquals(END_OF_STREAM, read);
assertArrayEquals(new byte[10], buf);
buf = new byte[10];
- is = new UnsynchronizedByteArrayInputStream(IOUtils.EMPTY_BYTE_ARRAY);
+ is = newStream(IOUtils.EMPTY_BYTE_ARRAY);
read = is.read(buf, 4, 6);
assertEquals(END_OF_STREAM, read);
assertArrayEquals(new byte[10], buf);
buf = IOUtils.EMPTY_BYTE_ARRAY;
- is = new UnsynchronizedByteArrayInputStream(new byte[]{(byte) 0xa, (byte) 0xb, (byte) 0xc});
- read = is.read(buf, 0,0);
+ is = newStream(new byte[] { (byte) 0xa, (byte) 0xb, (byte) 0xc });
+ read = is.read(buf, 0, 0);
assertEquals(0, read);
buf = new byte[10];
- is = new UnsynchronizedByteArrayInputStream(new byte[]{(byte) 0xa, (byte) 0xb, (byte) 0xc});
+ is = newStream(new byte[] { (byte) 0xa, (byte) 0xb, (byte) 0xc });
read = is.read(buf, 0, 2);
assertEquals(2, read);
assertEquals(0xa, buf[0]);
@@ -303,11 +329,10 @@ public class UnsynchronizedByteArrayInputStreamTest {
@Test
public void testReadSingle() {
- @SuppressWarnings("resource") // not necessary to close these resources
- UnsynchronizedByteArrayInputStream is = new UnsynchronizedByteArrayInputStream(IOUtils.EMPTY_BYTE_ARRAY);
+ UnsynchronizedByteArrayInputStream is = newStream(IOUtils.EMPTY_BYTE_ARRAY);
assertEquals(END_OF_STREAM, is.read());
- is = new UnsynchronizedByteArrayInputStream(new byte[] {(byte)0xa, (byte)0xb, (byte)0xc});
+ is = newStream(new byte[] { (byte) 0xa, (byte) 0xb, (byte) 0xc });
assertEquals(0xa, is.read());
assertEquals(0xb, is.read());
assertEquals(0xc, is.read());
@@ -316,8 +341,7 @@ public class UnsynchronizedByteArrayInputStreamTest {
@Test
public void testSkip() {
- @SuppressWarnings("resource") // not necessary to close these resources
- UnsynchronizedByteArrayInputStream is = new UnsynchronizedByteArrayInputStream(new byte[] {(byte)0xa, (byte)0xb, (byte)0xc});
+ UnsynchronizedByteArrayInputStream is = newStream(new byte[] { (byte) 0xa, (byte) 0xb, (byte) 0xc });
assertEquals(3, is.available());
is.skip(1);
@@ -328,30 +352,26 @@ public class UnsynchronizedByteArrayInputStreamTest {
assertEquals(0, is.available());
assertEquals(END_OF_STREAM, is.read());
-
- is = new UnsynchronizedByteArrayInputStream(new byte[] {(byte)0xa, (byte)0xb, (byte)0xc});
+ is = newStream(new byte[] { (byte) 0xa, (byte) 0xb, (byte) 0xc });
assertEquals(3, is.available());
is.skip(0);
assertEquals(3, is.available());
assertEquals(0xa, is.read());
-
- is = new UnsynchronizedByteArrayInputStream(new byte[] {(byte)0xa, (byte)0xb, (byte)0xc});
+ is = newStream(new byte[] { (byte) 0xa, (byte) 0xb, (byte) 0xc });
assertEquals(3, is.available());
is.skip(2);
assertEquals(1, is.available());
assertEquals(0xc, is.read());
assertEquals(END_OF_STREAM, is.read());
-
- is = new UnsynchronizedByteArrayInputStream(new byte[] {(byte)0xa, (byte)0xb, (byte)0xc});
+ is = newStream(new byte[] { (byte) 0xa, (byte) 0xb, (byte) 0xc });
assertEquals(3, is.available());
is.skip(3);
assertEquals(0, is.available());
assertEquals(END_OF_STREAM, is.read());
-
- is = new UnsynchronizedByteArrayInputStream(new byte[] {(byte)0xa, (byte)0xb, (byte)0xc});
+ is = newStream(new byte[] { (byte) 0xa, (byte) 0xb, (byte) 0xc });
assertEquals(3, is.available());
is.skip(999);
assertEquals(0, is.available());
diff --git a/src/test/java/org/apache/commons/io/input/UnsynchronizedFilterInputStreamTest.java b/src/test/java/org/apache/commons/io/input/UnsynchronizedFilterInputStreamTest.java
index eb9a9786..818e3eef 100644
--- a/src/test/java/org/apache/commons/io/input/UnsynchronizedFilterInputStreamTest.java
+++ b/src/test/java/org/apache/commons/io/input/UnsynchronizedFilterInputStreamTest.java
@@ -39,12 +39,6 @@ import org.junit.jupiter.api.Test;
*/
public class UnsynchronizedFilterInputStreamTest {
- static class MyUnsynchronizedFilterInputStream extends UnsynchronizedFilterInputStream {
- public MyUnsynchronizedFilterInputStream(final InputStream is) {
- super(is);
- }
- }
-
public static final String DATA = StringUtils.repeat("This is a test.", 500);
private Path fileName;
@@ -63,7 +57,7 @@ public class UnsynchronizedFilterInputStreamTest {
protected void setUp() throws IOException {
fileName = Files.createTempFile(getClass().getSimpleName(), ".tst");
Files.write(fileName, DATA.getBytes("UTF-8"));
- is = new MyUnsynchronizedFilterInputStream(Files.newInputStream(fileName));
+ is = new UnsynchronizedFilterInputStream(Files.newInputStream(fileName));
}
/**
[commons-io] 03/07: Pickup Maven enforcer plugin from parent POM
Posted by gg...@apache.org.
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-io.git
commit b9300808f21d09959d35caf9e2c0d7bc0f0fd5f2
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Wed May 3 14:06:29 2023 -0400
Pickup Maven enforcer plugin from parent POM
---
pom.xml | 52 ++--------------------------------------------------
1 file changed, 2 insertions(+), 50 deletions(-)
diff --git a/pom.xml b/pom.xml
index 296d508c..455e50ee 100644
--- a/pom.xml
+++ b/pom.xml
@@ -52,7 +52,7 @@ file comparators, endian transformation classes, and much more.
<connection>scm:git:https://gitbox.apache.org/repos/asf/commons-io.git</connection>
<developerConnection>scm:git:https://gitbox.apache.org/repos/asf/commons-io.git</developerConnection>
<url>https://gitbox.apache.org/repos/asf?p=commons-io.git</url>
- <tag>rel/commons-io-2.11.0</tag>
+ <tag>rel/commons-io-2.12.0</tag>
</scm>
<developers>
@@ -293,7 +293,7 @@ file comparators, endian transformation classes, and much more.
<maven.compiler.target>1.8</maven.compiler.target>
<commons.componentid>io</commons.componentid>
<commons.module.name>org.apache.commons.io</commons.module.name>
- <commons.rc.version>RC1</commons.rc.version>
+ <commons.rc.version>RC2</commons.rc.version>
<commons.bc.version>2.11.0</commons.bc.version>
<commons.release.version>2.12.0</commons.release.version>
<commons.release.desc>(requires Java 8)</commons.release.desc>
@@ -323,7 +323,6 @@ file comparators, endian transformation classes, and much more.
<commons.scmPubUrl>https://svn.apache.org/repos/infra/websites/production/commons/content/proper/commons-io/</commons.scmPubUrl>
<commons.scmPubCheckoutDirectory>site-content</commons.scmPubCheckoutDirectory>
<commons.javadoc.java.link>${commons.javadoc8.java.link}</commons.javadoc.java.link>
- <commons.enforcer.version>3.3.0</commons.enforcer.version>
<commons.moditect.version>1.0.0.RC3</commons.moditect.version>
<jmh.version>1.36</jmh.version>
<japicmp.skip>false</japicmp.skip>
@@ -363,26 +362,6 @@ file comparators, endian transformation classes, and much more.
</plugins>
</pluginManagement>
<plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-enforcer-plugin</artifactId>
- <version>${commons.enforcer.version}</version>
- <executions>
- <execution>
- <id>enforce-maven</id>
- <goals>
- <goal>enforce</goal>
- </goals>
- <configuration>
- <rules>
- <requireMavenVersion>
- <version>3.0.5</version>
- </requireMavenVersion>
- </rules>
- </configuration>
- </execution>
- </executions>
- </plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
@@ -622,32 +601,5 @@ file comparators, endian transformation classes, and much more.
</plugins>
</build>
</profile>
- <profile>
- <id>release</id>
- <build>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-enforcer-plugin</artifactId>
- <version>${commons.enforcer.version}</version>
- <executions>
- <execution>
- <id>enforce-versions</id>
- <goals>
- <goal>enforce</goal>
- </goals>
- <configuration>
- <rules>
- <requireJavaVersion>
- <version>9</version>
- </requireJavaVersion>
- </rules>
- </configuration>
- </execution>
- </executions>
- </plugin>
- </plugins>
- </build>
- </profile>
</profiles>
</project>
[commons-io] 05/07: Remove unused new method
Posted by gg...@apache.org.
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-io.git
commit 55b6211bdb0062365aa1f96d002d42e669b7614a
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Wed May 3 14:18:14 2023 -0400
Remove unused new method
---
.../org/apache/commons/io/build/AbstractOriginSupplier.java | 13 -------------
1 file changed, 13 deletions(-)
diff --git a/src/main/java/org/apache/commons/io/build/AbstractOriginSupplier.java b/src/main/java/org/apache/commons/io/build/AbstractOriginSupplier.java
index e6ed6db4..706ec285 100644
--- a/src/main/java/org/apache/commons/io/build/AbstractOriginSupplier.java
+++ b/src/main/java/org/apache/commons/io/build/AbstractOriginSupplier.java
@@ -45,19 +45,6 @@ import org.apache.commons.io.build.AbstractOrigin.WriterOrigin;
*/
public abstract class AbstractOriginSupplier<T, B extends AbstractOriginSupplier<T, B>> extends AbstractSupplier<T, B> {
- /**
- * Throws {@link IllegalArgumentException} if the initialBufferSize is less than zero.
- *
- * @param initialBufferSize the value to test.
- * @return the input value.
- */
- protected static int checkBufferSize(final int initialBufferSize) {
- if (initialBufferSize < 0) {
- throw new IllegalArgumentException("Initial buffer size must be at least 0.");
- }
- return initialBufferSize;
- }
-
/**
* Creates a new byte array origin for a byte array.
*
[commons-io] 04/07: Javadoc
Posted by gg...@apache.org.
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-io.git
commit 53507ac6fb2ba5c52292af7fef2687ea8df9db51
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Wed May 3 14:17:06 2023 -0400
Javadoc
---
src/main/java/org/apache/commons/io/build/AbstractOrigin.java | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/src/main/java/org/apache/commons/io/build/AbstractOrigin.java b/src/main/java/org/apache/commons/io/build/AbstractOrigin.java
index 46a008ec..82cafc0e 100644
--- a/src/main/java/org/apache/commons/io/build/AbstractOrigin.java
+++ b/src/main/java/org/apache/commons/io/build/AbstractOrigin.java
@@ -69,6 +69,9 @@ public abstract class AbstractOrigin<T, B extends AbstractOrigin<T, B>> extends
/**
* A {@link File} origin.
+ * <p>
+ * Starting from this origin, you can get a byte array, a file, an input stream, an output stream, a path, a reader, and a writer.
+ * </p>
*/
public static class FileOrigin extends AbstractOrigin<File, FileOrigin> {
@@ -146,6 +149,9 @@ public abstract class AbstractOrigin<T, B extends AbstractOrigin<T, B>> extends
/**
* A {@link Path} origin.
+ * <p>
+ * Starting from this origin, you can get a byte array, a file, an input stream, an output stream, a path, a reader, and a writer.
+ * </p>
*/
public static class PathOrigin extends AbstractOrigin<Path, PathOrigin> {
[commons-io] 01/07: Format tweak
Posted by gg...@apache.org.
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-io.git
commit 4cb04246c0946f70abd40eaf047d8d95587543c6
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Wed May 3 11:00:51 2023 -0400
Format tweak
---
.../org/apache/commons/io/output/AbstractByteArrayOutputStream.java | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/src/main/java/org/apache/commons/io/output/AbstractByteArrayOutputStream.java b/src/main/java/org/apache/commons/io/output/AbstractByteArrayOutputStream.java
index dd8b0e42..c4304c6b 100644
--- a/src/main/java/org/apache/commons/io/output/AbstractByteArrayOutputStream.java
+++ b/src/main/java/org/apache/commons/io/output/AbstractByteArrayOutputStream.java
@@ -236,8 +236,7 @@ public abstract class AbstractByteArrayOutputStream extends OutputStream {
* @since 2.7
*/
@SuppressWarnings("resource") // The result InputStream MUST be managed by the call site.
- protected <T extends InputStream> InputStream toInputStream(
- final InputStreamConstructor<T> isConstructor) {
+ protected <T extends InputStream> InputStream toInputStream(final InputStreamConstructor<T> isConstructor) {
int remaining = count;
if (remaining == 0) {
return ClosedInputStream.INSTANCE;