(commons-io) 01/02: Sort members

2024-12-13 Thread ggregory
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 1c84539e0c2ebd85cdc6dce831573f768508a83c
Author: Gary Gregory 
AuthorDate: Fri Dec 13 08:03:58 2024 -0500

Sort members
---
 .../java/org/apache/commons/io/output/ProxyOutputStreamTest.java  | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git 
a/src/test/java/org/apache/commons/io/output/ProxyOutputStreamTest.java 
b/src/test/java/org/apache/commons/io/output/ProxyOutputStreamTest.java
index d5c86c67f..5f46a98a8 100644
--- a/src/test/java/org/apache/commons/io/output/ProxyOutputStreamTest.java
+++ b/src/test/java/org/apache/commons/io/output/ProxyOutputStreamTest.java
@@ -32,24 +32,24 @@ import org.junit.jupiter.api.Test;
  */
 public class ProxyOutputStreamTest {
 
-private final AtomicBoolean hit = new AtomicBoolean();
-
 private ByteArrayOutputStream original;
 
 private OutputStream proxied;
 
+private final AtomicBoolean hit = new AtomicBoolean();
+
 @BeforeEach
 public void setUp() {
 original = new ByteArrayOutputStream() {
 
 @Override
-public void write(final byte[] ba) {
+public synchronized void write(final int ba) {
 hit.set(true);
 super.write(ba);
 }
 
 @Override
-public synchronized void write(final int ba) {
+public void write(final byte[] ba) {
 hit.set(true);
 super.write(ba);
 }



(commons-io) 01/02: Sort members

2024-11-16 Thread ggregory
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 963986fe5399cd27680f2af3b12d2699360ac610
Author: Gary Gregory 
AuthorDate: Sat Nov 16 09:30:59 2024 -0500

Sort members
---
 .../java/org/apache/commons/io/FileUtilsTest.java  | 30 +++---
 1 file changed, 15 insertions(+), 15 deletions(-)

diff --git a/src/test/java/org/apache/commons/io/FileUtilsTest.java 
b/src/test/java/org/apache/commons/io/FileUtilsTest.java
index 4e1ef0b8e..f11dec5f1 100644
--- a/src/test/java/org/apache/commons/io/FileUtilsTest.java
+++ b/src/test/java/org/apache/commons/io/FileUtilsTest.java
@@ -1579,21 +1579,6 @@ public class FileUtilsTest extends AbstractTempDirTest {
 assertFalse(Files.exists(symlinkedDir), symlinkedDir::toString);
 }
 
-@Test
-public void testDeleteDirectorySymbolicLinkAbsentTarget() throws 
IOException {
-final ImmutablePair pair = 
createTempSymbolicLinkedRelativeDir();
-final Path symlinkedDir = pair.getLeft();
-final Path targetDir = pair.getRight();
-assertTrue(Files.exists(symlinkedDir), symlinkedDir::toString);
-// remove target directory, keeping symbolic link
-Files.delete(targetDir);
-assertFalse(Files.exists(targetDir), targetDir::toString);
-assertFalse(Files.exists(symlinkedDir), symlinkedDir::toString);
-// actual test
-FileUtils.deleteDirectory(symlinkedDir.toFile());
-assertFalse(Files.exists(symlinkedDir), symlinkedDir::toString);
-}
-
 @Test
 public void testDeleteDirectorySymbolicLinkAbsentDeepTarget() throws 
IOException {
 final ImmutablePair pair = 
createTempSymbolicLinkedRelativeDir();
@@ -1614,6 +1599,21 @@ public class FileUtilsTest extends AbstractTempDirTest {
 assertFalse(Files.exists(targetDir), targetDir::toString);
 }
 
+@Test
+public void testDeleteDirectorySymbolicLinkAbsentTarget() throws 
IOException {
+final ImmutablePair pair = 
createTempSymbolicLinkedRelativeDir();
+final Path symlinkedDir = pair.getLeft();
+final Path targetDir = pair.getRight();
+assertTrue(Files.exists(symlinkedDir), symlinkedDir::toString);
+// remove target directory, keeping symbolic link
+Files.delete(targetDir);
+assertFalse(Files.exists(targetDir), targetDir::toString);
+assertFalse(Files.exists(symlinkedDir), symlinkedDir::toString);
+// actual test
+FileUtils.deleteDirectory(symlinkedDir.toFile());
+assertFalse(Files.exists(symlinkedDir), symlinkedDir::toString);
+}
+
 @Test
 public void testDeleteQuietlyDir() throws IOException {
 final File testDirectory = new File(tempDirFile, 
"testDeleteQuietlyDir");



(commons-io) 01/02: Sort members

2024-11-11 Thread ggregory
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 2f18e22169757096469d693dc73db53825168a06
Author: Gary Gregory 
AuthorDate: Mon Nov 11 10:34:50 2024 -0500

Sort members
---
 src/main/java/org/apache/commons/io/IOUtils.java   | 28 +++
 .../commons/io/input/AutoCloseInputStream.java |  8 +-
 .../io/input/BufferedFileChannelInputStream.java   | 12 +--
 .../apache/commons/io/input/ProxyInputStream.java  | 24 +++---
 .../io/output/RandomAccessFileOutputStream.java| 10 +--
 .../commons/io/input/BoundedInputStreamTest.java   | 90 +++---
 .../io/input/UnsynchronizedBufferedReaderTest.java | 58 +++---
 .../output/RandomAccessFileOutputStreamTest.java   | 18 ++---
 8 files changed, 124 insertions(+), 124 deletions(-)

diff --git a/src/main/java/org/apache/commons/io/IOUtils.java 
b/src/main/java/org/apache/commons/io/IOUtils.java
index 15c0bdfd6..72bc4c4ca 100644
--- a/src/main/java/org/apache/commons/io/IOUtils.java
+++ b/src/main/java/org/apache/commons/io/IOUtils.java
@@ -2162,6 +2162,20 @@ public class IOUtils {
 }
 }
 
+/**
+ * Gets the contents of a {@link CharSequence} as a list of Strings, one 
entry per line.
+ *
+ * @param csq the {@link CharSequence} to read, not null
+ * @return the list of Strings, never null
+ * @throws UncheckedIOException if an I/O error occurs
+ * @since 2.18.0
+ */
+public static List readLines(final CharSequence csq) throws 
UncheckedIOException {
+try (CharSequenceReader reader = new CharSequenceReader(csq)) {
+return readLines(reader);
+}
+}
+
 /**
  * Gets the contents of an {@link InputStream} as a list of Strings,
  * one entry per line, using the default character encoding of the 
platform.
@@ -2244,20 +2258,6 @@ public class IOUtils {
 return toBufferedReader(reader).lines().collect(Collectors.toList());
 }
 
-/**
- * Gets the contents of a {@link CharSequence} as a list of Strings, one 
entry per line.
- *
- * @param csq the {@link CharSequence} to read, not null
- * @return the list of Strings, never null
- * @throws UncheckedIOException if an I/O error occurs
- * @since 2.18.0
- */
-public static List readLines(final CharSequence csq) throws 
UncheckedIOException {
-try (CharSequenceReader reader = new CharSequenceReader(csq)) {
-return readLines(reader);
-}
-}
-
 /**
  * Gets the contents of a resource as a byte array.
  * 
diff --git 
a/src/main/java/org/apache/commons/io/input/AutoCloseInputStream.java 
b/src/main/java/org/apache/commons/io/input/AutoCloseInputStream.java
index 2f70b6d2b..de7451fdd 100644
--- a/src/main/java/org/apache/commons/io/input/AutoCloseInputStream.java
+++ b/src/main/java/org/apache/commons/io/input/AutoCloseInputStream.java
@@ -97,6 +97,10 @@ public class AutoCloseInputStream extends ProxyInputStream {
 return new Builder();
 }
 
+private AutoCloseInputStream(final Builder builder) throws IOException {
+super(builder);
+}
+
 /**
  * Constructs an automatically closing proxy for the given input stream.
  *
@@ -109,10 +113,6 @@ public class AutoCloseInputStream extends ProxyInputStream 
{
 super(ClosedInputStream.ifNull(in));
 }
 
-private AutoCloseInputStream(final Builder builder) throws IOException {
-super(builder);
-}
-
 /**
  * Automatically closes the stream if the end of stream was reached.
  *
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 bede06b46..b92eba0ad 100644
--- 
a/src/main/java/org/apache/commons/io/input/BufferedFileChannelInputStream.java
+++ 
b/src/main/java/org/apache/commons/io/input/BufferedFileChannelInputStream.java
@@ -157,6 +157,12 @@ public final class BufferedFileChannelInputStream extends 
InputStream {
 this(file.toPath(), bufferSize);
 }
 
+private BufferedFileChannelInputStream(final FileChannel fileChannel, 
final int bufferSize) {
+this.fileChannel = Objects.requireNonNull(fileChannel, "path");
+byteBuffer = ByteBuffer.allocateDirect(bufferSize);
+byteBuffer.flip();
+}
+
 /**
  * Constructs a new instance for the given Path.
  *
@@ -183,12 +189,6 @@ public final class BufferedFileChannelInputStream extends 
InputStream {
 this(FileChannel.open(path, StandardOpenOption.READ), bufferSize);
 }
 
-private BufferedFileChannelInputStream(final FileChannel fileChannel, 
final int bufferSize) {
-this.fileChannel = Objects.requireNonNull(fileChannel, "path");
-byteBuffer = ByteBuffer.allocateDirect(bufferSize);
-byteBuffer.flip();
-}
-
 @Override
 pu

(commons-io) 01/02: Sort members

2024-06-02 Thread ggregory
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 e66e31a122c130fbb574475331191d4a812e13df
Author: Gary Gregory 
AuthorDate: Sun Jun 2 14:19:12 2024 -0400

Sort members
---
 src/main/java/org/apache/commons/io/build/AbstractOrigin.java | 10 +-
 1 file changed, 5 insertions(+), 5 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 fdaef97a9..744428e4b 100644
--- a/src/main/java/org/apache/commons/io/build/AbstractOrigin.java
+++ b/src/main/java/org/apache/commons/io/build/AbstractOrigin.java
@@ -399,11 +399,6 @@ public abstract class AbstractOrigin> extends
 return getPath().toFile();
 }
 
-@Override
-public Path getPath() {
-return Paths.get(get());
-}
-
 @Override
 public InputStream getInputStream(final OpenOption... options) throws 
IOException {
 final URI uri = get();
@@ -417,6 +412,11 @@ public abstract class AbstractOrigin> extends
 }
 return Files.newInputStream(getPath(), options);
 }
+
+@Override
+public Path getPath() {
+return Paths.get(get());
+}
 }
 
 /**



(commons-io) 01/02: Sort members

2024-04-04 Thread ggregory
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 a66cb84a1fcfdc060f38f57674bc80e3e4485f35
Author: Gary Gregory 
AuthorDate: Thu Apr 4 19:56:37 2024 -0400

Sort members
---
 .../commons/io/file/AbstractPathWrapper.java   |  10 +-
 .../io/output/DeferredFileOutputStreamTest.java|  44 
 .../io/output/ThresholdingOutputStreamTest.java| 114 ++---
 3 files changed, 84 insertions(+), 84 deletions(-)

diff --git a/src/test/java/org/apache/commons/io/file/AbstractPathWrapper.java 
b/src/test/java/org/apache/commons/io/file/AbstractPathWrapper.java
index 4c5857c49..ef7ba4190 100644
--- a/src/test/java/org/apache/commons/io/file/AbstractPathWrapper.java
+++ b/src/test/java/org/apache/commons/io/file/AbstractPathWrapper.java
@@ -81,11 +81,6 @@ public abstract class AbstractPathWrapper implements Path {
 return Objects.equals(path, other.path);
 }
 
-@Override
-public void forEach(final Consumer action) {
-path.forEach(action);
-}
-
 /**
  * Delegates to {@link Files#exists(Path, LinkOption...)}.
  *
@@ -96,6 +91,11 @@ public abstract class AbstractPathWrapper implements Path {
 return Files.exists(path, options);
 }
 
+@Override
+public void forEach(final Consumer action) {
+path.forEach(action);
+}
+
 /**
  * Gets the delegate Path.
  *
diff --git 
a/src/test/java/org/apache/commons/io/output/DeferredFileOutputStreamTest.java 
b/src/test/java/org/apache/commons/io/output/DeferredFileOutputStreamTest.java
index d4128455d..7cbeeedeb 100644
--- 
a/src/test/java/org/apache/commons/io/output/DeferredFileOutputStreamTest.java
+++ 
b/src/test/java/org/apache/commons/io/output/DeferredFileOutputStreamTest.java
@@ -104,28 +104,6 @@ public class DeferredFileOutputStreamTest extends 
AbstractTempDirTest {
 }
 }
 
-/**
- * Tests the case where the threshold is negative, and therefore the data 
is always written to disk. The actual data
- * written to disk is verified, as is the file itself.
- */
-@ParameterizedTest(name = "initialBufferSize = {0}")
-@MethodSource("data")
-public void testThresholdNegative(final int initialBufferSize) throws 
IOException {
-final File testFile = Files.createTempFile(tempDirPath, 
"testThresholdNegative", "dat").toFile();
-try (DeferredFileOutputStream dfos = DeferredFileOutputStream.builder()
-.setThreshold(-1)
-.setBufferSize(initialBufferSize)
-.setOutputFile(testFile)
-.get()) {
-dfos.write(testBytes, 0, testBytes.length);
-dfos.close();
-assertFalse(dfos.isInMemory());
-assertNull(dfos.getData());
-assertEquals(testFile.length(), dfos.getByteCount());
-verifyResultFile(testFile);
-}
-}
-
 /**
  * Tests the case where the amount of data is exactly the same as the 
threshold. The behavior should be the same as
  * that for the amount of data being below (i.e. not exceeding) the 
threshold.
@@ -299,6 +277,28 @@ public class DeferredFileOutputStreamTest extends 
AbstractTempDirTest {
 assertThrows(NullPointerException.class, () -> new 
DeferredFileOutputStream(testBytes.length - 5, prefix, suffix, tempDirFile));
 }
 
+/**
+ * Tests the case where the threshold is negative, and therefore the data 
is always written to disk. The actual data
+ * written to disk is verified, as is the file itself.
+ */
+@ParameterizedTest(name = "initialBufferSize = {0}")
+@MethodSource("data")
+public void testThresholdNegative(final int initialBufferSize) throws 
IOException {
+final File testFile = Files.createTempFile(tempDirPath, 
"testThresholdNegative", "dat").toFile();
+try (DeferredFileOutputStream dfos = DeferredFileOutputStream.builder()
+.setThreshold(-1)
+.setBufferSize(initialBufferSize)
+.setOutputFile(testFile)
+.get()) {
+dfos.write(testBytes, 0, testBytes.length);
+dfos.close();
+assertFalse(dfos.isInMemory());
+assertNull(dfos.getData());
+assertEquals(testFile.length(), dfos.getByteCount());
+verifyResultFile(testFile);
+}
+}
+
 /**
  * Tests the case where there are multiple writes beyond the threshold, to 
ensure that the
  * {@code thresholdReached()} method is only called once, as the threshold 
is crossed for the first time.
diff --git 
a/src/test/java/org/apache/commons/io/output/ThresholdingOutputStreamTest.java 
b/src/test/java/org/apache/commons/io/output/ThresholdingOutputStreamTest.java
index 43916438d..bf94520f7 100644
--- 
a/src/test/java/org/apache/commons/io/output/ThresholdingOutputStreamTest.java
++

(commons-io) 01/02: Sort members

2023-12-17 Thread ggregory
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 6258b40a1832cd46379210737ddbaddaaf6a1d28
Author: Gary Gregory 
AuthorDate: Sun Dec 17 16:22:10 2023 -0500

Sort members
---
 .../java/org/apache/commons/io/EndianUtils.java| 26 ++--
 .../org/apache/commons/io/EndianUtilsTest.java | 28 +++---
 .../io/input/CharSequenceInputStreamTest.java  | 22 -
 3 files changed, 38 insertions(+), 38 deletions(-)

diff --git a/src/main/java/org/apache/commons/io/EndianUtils.java 
b/src/main/java/org/apache/commons/io/EndianUtils.java
index ae7b1bd9..9a0cc9d8 100644
--- a/src/main/java/org/apache/commons/io/EndianUtils.java
+++ b/src/main/java/org/apache/commons/io/EndianUtils.java
@@ -41,19 +41,6 @@ import java.io.OutputStream;
  */
 public class EndianUtils {
 
-/**
- * Validates if the provided byte array have enough data.
- * @param data the input byte array
- * @param offset the input offset
- * @param byteNeeded the needed number of bytes
- * @throws IllegalArgumentException if the byte array does not have enough 
data
- */
-private static void validateByteArrayOffset(final byte[] data, final int 
offset, final int byteNeeded) {
-if (data.length < offset + byteNeeded) {
-throw new IllegalArgumentException("Data only has " + data.length 
+ "bytes, needed " + (offset + byteNeeded) + "bytes.");
-}
-}
-
 /**
  * Reads the next byte from the input stream.
  * @param input  the stream
@@ -313,6 +300,19 @@ public class EndianUtils {
 ((value >> 8 & 0xff) << 0));
 }
 
+/**
+ * Validates if the provided byte array have enough data.
+ * @param data the input byte array
+ * @param offset the input offset
+ * @param byteNeeded the needed number of bytes
+ * @throws IllegalArgumentException if the byte array does not have enough 
data
+ */
+private static void validateByteArrayOffset(final byte[] data, final int 
offset, final int byteNeeded) {
+if (data.length < offset + byteNeeded) {
+throw new IllegalArgumentException("Data only has " + data.length 
+ "bytes, needed " + (offset + byteNeeded) + "bytes.");
+}
+}
+
 /**
  * Writes a "double" value to a byte array at a given offset. The value is
  * converted to the opposed endian system while writing.
diff --git a/src/test/java/org/apache/commons/io/EndianUtilsTest.java 
b/src/test/java/org/apache/commons/io/EndianUtilsTest.java
index e93adac3..98a72c6a 100644
--- a/src/test/java/org/apache/commons/io/EndianUtilsTest.java
+++ b/src/test/java/org/apache/commons/io/EndianUtilsTest.java
@@ -43,6 +43,20 @@ public class EndianUtilsTest  {
 assertThrows(EOFException.class, () -> 
EndianUtils.readSwappedDouble(input));
 }
 
+@Test
+public void testInvalidOffset() throws IOException {
+final byte[] bytes = new byte[0];
+
+assertThrows(IllegalArgumentException.class, () -> 
EndianUtils.readSwappedInteger(bytes, 0));
+assertThrows(IllegalArgumentException.class, () -> 
EndianUtils.readSwappedLong(bytes, 0));
+assertThrows(IllegalArgumentException.class, () -> 
EndianUtils.readSwappedShort(bytes, 0));
+assertThrows(IllegalArgumentException.class, () -> 
EndianUtils.readSwappedUnsignedInteger(bytes, 0));
+assertThrows(IllegalArgumentException.class, () -> 
EndianUtils.readSwappedUnsignedShort(bytes, 0));
+assertThrows(IllegalArgumentException.class, () -> 
EndianUtils.writeSwappedInteger(bytes, 0, 0));
+assertThrows(IllegalArgumentException.class, () -> 
EndianUtils.writeSwappedLong(bytes, 0, 0l));
+assertThrows(IllegalArgumentException.class, () -> 
EndianUtils.writeSwappedShort(bytes, 0, (short) 0));
+}
+
 @Test
 public void testReadSwappedDouble() throws IOException {
 final byte[] bytes = { 0x08, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x01 
};
@@ -308,18 +322,4 @@ public class EndianUtilsTest  {
 assertEquals( 0x01, bytes[1] );
 }
 
-@Test
-public void testInvalidOffset() throws IOException {
-final byte[] bytes = new byte[0];
-
-assertThrows(IllegalArgumentException.class, () -> 
EndianUtils.readSwappedInteger(bytes, 0));
-assertThrows(IllegalArgumentException.class, () -> 
EndianUtils.readSwappedLong(bytes, 0));
-assertThrows(IllegalArgumentException.class, () -> 
EndianUtils.readSwappedShort(bytes, 0));
-assertThrows(IllegalArgumentException.class, () -> 
EndianUtils.readSwappedUnsignedInteger(bytes, 0));
-assertThrows(IllegalArgumentException.class, () -> 
EndianUtils.readSwappedUnsignedShort(bytes, 0));
-assertThrows(IllegalArgumentException.class, () -> 
EndianUtils.writeSwappedInteger(bytes, 0, 0));
-assertThrows(IllegalArgumentExcept

[commons-io] 01/02: Sort members

2022-06-14 Thread ggregory
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 a6593edc56271073c820ac7628fbe8c03336d777
Author: Gary Gregory 
AuthorDate: Tue Jun 14 14:45:14 2022 -0400

Sort members
---
 src/main/java/org/apache/commons/io/file/PathUtils.java | 14 +++---
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/src/main/java/org/apache/commons/io/file/PathUtils.java 
b/src/main/java/org/apache/commons/io/file/PathUtils.java
index ef45a8c5..2c56895a 100644
--- a/src/main/java/org/apache/commons/io/file/PathUtils.java
+++ b/src/main/java/org/apache/commons/io/file/PathUtils.java
@@ -199,13 +199,6 @@ public final class PathUtils {
  */
 public static final Path[] EMPTY_PATH_ARRAY = {};
 
-/**
- * Does allow to instantiate.
- */
-private PathUtils() {
-// do not instantiate.
-}
-
 /**
  * Accumulates file tree information in a {@link AccumulatorPathVisitor}.
  *
@@ -1704,4 +1697,11 @@ public final class PathUtils {
 return path;
 }
 
+/**
+ * Does allow to instantiate.
+ */
+private PathUtils() {
+// do not instantiate.
+}
+
 }



[commons-io] 01/02: Sort members.

2021-07-10 Thread ggregory
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 56881bbdb5bfb2e5c663be2356a0a006b9bbd97b
Author: Gary Gregory 
AuthorDate: Sat Jul 10 11:03:59 2021 -0400

Sort members.
---
 .../apache/commons/io/input/BrokenReaderTest.java  | 32 +++---
 1 file changed, 16 insertions(+), 16 deletions(-)

diff --git a/src/test/java/org/apache/commons/io/input/BrokenReaderTest.java 
b/src/test/java/org/apache/commons/io/input/BrokenReaderTest.java
index 5ad04b2..5844ca2 100644
--- a/src/test/java/org/apache/commons/io/input/BrokenReaderTest.java
+++ b/src/test/java/org/apache/commons/io/input/BrokenReaderTest.java
@@ -42,43 +42,43 @@ public class BrokenReaderTest {
 }
 
 @Test
-public void testRead() {
+public void testClose() {
 try {
-reader.read();
+reader.close();
 fail("Expected exception not thrown.");
 } catch (final IOException e) {
 assertEquals(exception, e);
 }
+}
 
+@Test
+public void testMark() {
 try {
-reader.read(new char[1]);
+reader.mark(1);
 fail("Expected exception not thrown.");
 } catch (final IOException e) {
 assertEquals(exception, e);
 }
+}
 
+@Test
+public void testRead() {
 try {
-reader.read(new char[1], 0, 1);
+reader.read();
 fail("Expected exception not thrown.");
 } catch (final IOException e) {
 assertEquals(exception, e);
 }
-}
 
-@Test
-public void testSkip() {
 try {
-reader.skip(1);
+reader.read(new char[1]);
 fail("Expected exception not thrown.");
 } catch (final IOException e) {
 assertEquals(exception, e);
 }
-}
 
-@Test
-public void testReady() {
 try {
-reader.ready();
+reader.read(new char[1], 0, 1);
 fail("Expected exception not thrown.");
 } catch (final IOException e) {
 assertEquals(exception, e);
@@ -86,9 +86,9 @@ public class BrokenReaderTest {
 }
 
 @Test
-public void testMark() {
+public void testReady() {
 try {
-reader.mark(1);
+reader.ready();
 fail("Expected exception not thrown.");
 } catch (final IOException e) {
 assertEquals(exception, e);
@@ -106,9 +106,9 @@ public class BrokenReaderTest {
 }
 
 @Test
-public void testClose() {
+public void testSkip() {
 try {
-reader.close();
+reader.skip(1);
 fail("Expected exception not thrown.");
 } catch (final IOException e) {
 assertEquals(exception, e);


[commons-io] 01/02: Sort members.

2021-01-21 Thread ggregory
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 e403b84597a4299d1cd2d1b93224eade2530128c
Author: Gary Gregory 
AuthorDate: Thu Jan 21 11:22:50 2021 -0500

Sort members.
---
 .../apache/commons/io/input/XmlStreamReader.java   | 708 ++---
 1 file changed, 354 insertions(+), 354 deletions(-)

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 d77d382..ee80736 100644
--- a/src/main/java/org/apache/commons/io/input/XmlStreamReader.java
+++ b/src/main/java/org/apache/commons/io/input/XmlStreamReader.java
@@ -110,24 +110,161 @@ public class XmlStreamReader extends Reader {
 new ByteOrderMark(EBCDIC,   0x4C, 0x6F, 0xA7, 0x94)
 };
 
-private final Reader reader;
+private static final Pattern CHARSET_PATTERN = Pattern
+.compile("charset=[\"']?([.[^; \"']]*)[\"']?");
 
-private final String encoding;
+/**
+ * Pattern capturing the encoding of the "xml" processing instruction.
+ */
+public static final Pattern ENCODING_PATTERN = Pattern.compile(
+"<\\?xml.*encoding[\\s]*=[\\s]*((?:\".[^\"]*\")|(?:'.[^']*'))",
+Pattern.MULTILINE);
 
-private final String defaultEncoding;
+private static final String RAW_EX_1 =
+"Invalid encoding, BOM [{0}] XML guess [{1}] XML prolog [{2}] encoding 
mismatch";
+
+private static final String RAW_EX_2 =
+"Invalid encoding, BOM [{0}] XML guess [{1}] XML prolog [{2}] unknown 
BOM";
+
+private static final String HTTP_EX_1 =
+"Invalid encoding, CT-MIME [{0}] CT-Enc [{1}] BOM [{2}] XML guess 
[{3}] XML prolog [{4}], BOM must be NULL";
+
+private static final String HTTP_EX_2 =
+"Invalid encoding, CT-MIME [{0}] CT-Enc [{1}] BOM [{2}] XML guess 
[{3}] XML prolog [{4}], encoding mismatch";
+
+private static final String HTTP_EX_3 =
+"Invalid encoding, CT-MIME [{0}] CT-Enc [{1}] BOM [{2}] XML guess 
[{3}] XML prolog [{4}], Invalid MIME";
 
 /**
- * Returns the default encoding to use if none is set in HTTP content-type,
- * XML prolog and the rules based on content-type are not adequate.
- * 
- * If it is NULL the content-type based rules are used.
+ * Returns charset parameter value, NULL if not present, NULL if
+ * httpContentType is NULL.
  *
- * @return the default encoding to use.
+ * @param httpContentType the HTTP content type
+ * @return The content type encoding (upcased)
  */
-public String getDefaultEncoding() {
-return defaultEncoding;
+static String getContentTypeEncoding(final String httpContentType) {
+String encoding = null;
+if (httpContentType != null) {
+final int i = httpContentType.indexOf(";");
+if (i > -1) {
+final String postMime = httpContentType.substring(i + 1);
+final Matcher m = CHARSET_PATTERN.matcher(postMime);
+encoding = m.find() ? m.group(1) : null;
+encoding = encoding != null ? 
encoding.toUpperCase(Locale.ROOT) : null;
+}
+}
+return encoding;
+}
+
+/**
+ * Returns MIME type or NULL if httpContentType is NULL.
+ *
+ * @param httpContentType the HTTP content type
+ * @return The mime content type
+ */
+static String getContentTypeMime(final String httpContentType) {
+String mime = null;
+if (httpContentType != null) {
+final int i = httpContentType.indexOf(";");
+if (i >= 0) {
+mime = httpContentType.substring(0, i);
+} else {
+mime = httpContentType;
+}
+mime = mime.trim();
+}
+return mime;
+}
+
+/**
+ * Returns the encoding declared in the , NULL if none.
+ *
+ * @param inputStream InputStream to create the reader from.
+ * @param guessedEnc guessed encoding
+ * @return the encoding declared in the 
+ * @throws IOException thrown if there is a problem reading the stream.
+ */
+private static String getXmlProlog(final InputStream inputStream, final 
String guessedEnc)
+throws IOException {
+String encoding = null;
+if (guessedEnc != null) {
+final byte[] bytes = new byte[BUFFER_SIZE];
+inputStream.mark(BUFFER_SIZE);
+int offset = 0;
+int max = BUFFER_SIZE;
+int c = inputStream.read(bytes, offset, max);
+int firstGT = -1;
+String xmlProlog = ""; // avoid possible NPE warning (cannot 
happen; this just silences the warning)
+while (c != -1 && firstGT == -1 && offset < BUFFER_SIZE) {
+offset += c;
+max -= c;
+c = inputStream.