### Using PrefixFileFilter with Classic IO Source: https://commons.apache.org/proper/commons-io/apidocs/org/apache/commons/io/filefilter/PrefixFileFilter.html Example demonstrating how to use PrefixFileFilter with classic Java IO to list files in a directory that start with a specific prefix. ```APIDOC ## Using Classic IO ```java File dir = FileUtils.current(); String[] files = dir.list(new PrefixFileFilter("Test")); for (String file : files) { System.out.println(file); } ``` ``` -------------------------------- ### Sorting Examples Source: https://commons.apache.org/proper/commons-io/apidocs/org/apache/commons/io/comparator/DefaultFileComparator.html Examples demonstrating how to use the DefaultFileComparator for sorting lists and arrays of files. ```APIDOC ## Examples ### Sorting a list of files using `DEFAULT_COMPARATOR` ```java List list = ... ((AbstractFileComparator) DefaultFileComparator.DEFAULT_COMPARATOR).sort(list); ``` ### Reverse sorting an array of files using `DEFAULT_REVERSE` ```java File[] array = ... ((AbstractFileComparator) DefaultFileComparator.DEFAULT_REVERSE).sort(array); ``` ``` -------------------------------- ### Example Usage Source: https://commons.apache.org/proper/commons-io/apidocs/org/apache/commons/io/comparator/CompositeFileComparator.html Example demonstrating how to use CompositeFileComparator to sort a list of files by type and then by name. ```APIDOC ## Example of sorting a list of files by type (directory or file) and then by name: ```java CompositeFileComparator comparator = new CompositeFileComparator( DirectoryFileComparator.DIRECTORY_COMPARATOR, NameFileComparator.NAME_COMPARATOR); List list = ... comparator.sort(list); ``` ``` -------------------------------- ### TailerListener Implementation Example Source: https://commons.apache.org/proper/commons-io/apidocs/org/apache/commons/io/input/Tailer.html Example of how to create a custom TailerListener implementation to handle lines read from a file. ```APIDOC ## TailerListener Implementation Example ### Description This example demonstrates how to create a `TailerListener` implementation to process lines from a file. The `TailerListenerAdapter` class is provided for convenience, allowing you to override only the necessary methods. ### Code Example ```java public class MyTailerListener extends TailerListenerAdapter { @Override public void handle(String line) { System.out.println(line); } } ``` ``` -------------------------------- ### Builder Usage Examples Source: https://commons.apache.org/proper/commons-io/apidocs/org/apache/commons/io/serialization/ValidatingObjectInputStream.Builder.html Examples demonstrating how to build ValidatingObjectInputStream using NIO and IO. ```APIDOC ## GET /api/users/{userId} ### Description Retrieves details for a specific user based on their ID. ### Method GET ### Endpoint /api/users/{userId} ### Parameters #### Path Parameters - **userId** (string) - Required - The unique identifier of the user to retrieve. ### Response #### Success Response (200) - **userId** (string) - The unique identifier of the user. - **username** (string) - The username of the user. - **email** (string) - The email address of the user. #### Response Example { "userId": "a1b2c3d4e5f6", "username": "testuser", "email": "test@example.com" } ``` -------------------------------- ### Handle Start of Processing Source: https://commons.apache.org/proper/commons-io/apidocs/src-html/org/apache/commons/io/DirectoryWalker.CancelException.html Callback method invoked at the start of the directory walk. Override in subclasses to perform initialization. ```java @SuppressWarnings("unused") // Possibly thrown from subclasses. protected void handleStart(final File startDirectory, final Collection results) throws IOException { // do nothing - overridable by subclass } ``` -------------------------------- ### FileSystemProviders.installed() Source: https://commons.apache.org/proper/commons-io/apidocs/org/apache/commons/io/file/spi/class-use/FileSystemProviders.html Retrieves the instance for the installed file system providers. ```APIDOC ## GET /org/apache/commons/io/file/spi/FileSystemProviders/installed ### Description Returns the instance for the installed file system providers. ### Method static ### Endpoint FileSystemProviders.installed() ### Response #### Success Response (200) - **FileSystemProviders** (object) - The instance for the installed providers. ``` -------------------------------- ### Builder Pattern Example Source: https://commons.apache.org/proper/commons-io/apidocs/org/apache/commons/io/build/AbstractSupplier.html An example demonstrating how to use AbstractSupplier to implement the builder pattern for a Foo class. ```APIDOC ## Example: Builder Pattern Implementation ### Builder Class ```java /** * Builds Foo instances. */ public static class Builder extends AbstractSupplier { private String bar1; private String bar2; private String bar3; /** * Builds a new Foo. */ @Override public Foo get() { return new Foo(bar1, bar2, bar3); } public Builder setBar1(final String bar1) { this.bar1 = bar1; return this; } public Builder setBar2(final String bar2) { this.bar2 = bar2; return this; } public Builder setBar3(final String bar3) { this.bar3 = bar3; return this; } } ``` ### Domain Class ```java /** * Domain class. */ public class Foo { public static Builder builder() { return new Builder(); } private final String bar1; private final String bar2; private final String bar3; private Foo(final String bar1, final String bar2, final String bar3) { this.bar1 = bar1; this.bar2 = bar2; this.bar3 = bar3; } public String getBar1() { return bar1; } public String getBar2() { return bar2; } public String getBar3() { return bar3; } } ``` ### Test Case ```java @Test public void test() { final Foo foo = Foo.builder() .setBar1("value1") .setBar2("value2") .setBar3("value3") .get(); assertEquals("value1", foo.getBar1()); assertEquals("value2", foo.getBar2()); assertEquals("value3", foo.getBar3()); } ``` ``` -------------------------------- ### Get Start Index of Character Sequence Source: https://commons.apache.org/proper/commons-io/apidocs/src-html/org/apache/commons/io/input/CharSequenceReader.html Calculates the starting index for reading within the character sequence, ensuring it does not exceed the sequence length. ```java private int start() { return Math.min(charSequence.length(), start); } ``` -------------------------------- ### Initialize and Run a Tailer Source: https://commons.apache.org/proper/commons-io/apidocs/src-html/org/apache/commons/io/input/Tailer.RandomAccessResourceBridge.html Demonstrates the three supported ways to initialize and execute a Tailer instance. ```java TailerListener listener = new MyTailerListener(); Tailer tailer = Tailer.builder() .setFile(file) .setTailerListener(listener) .setDelayDuration(delay) .get(); ``` ```java TailerListener listener = new MyTailerListener(); Tailer tailer = new Tailer(file, listener, delay); // stupid executor impl. for demo purposes Executor executor = new Executor() { public void execute(Runnable command) { command.run(); } }; executor.execute(tailer); ``` ```java TailerListener listener = new MyTailerListener(); Tailer tailer = new Tailer(file, listener, delay); Thread thread = new Thread(tailer); thread.setDaemon(true); // optional thread.start(); ``` -------------------------------- ### GET /file/tree/visit Source: https://commons.apache.org/proper/commons-io/apidocs/src-html/org/apache/commons/io/file/PathUtils.html Traverses a file tree starting from a directory using a provided FileVisitor. ```APIDOC ## GET /file/tree/visit ### Description Performs a walk of the file tree starting at the specified directory using a FileVisitor. ### Method GET ### Endpoint /file/tree/visit ### Parameters #### Query Parameters - **visitor** (FileVisitor) - Required - The visitor to use for traversal. - **directory** (Path) - Required - The starting directory path. - **options** (Set) - Optional - Options for file traversal. - **maxDepth** (int) - Optional - The maximum directory depth to visit. ### Response #### Success Response (200) - **visitor** (FileVisitor) - The visitor instance used for the traversal. ``` -------------------------------- ### Build BoundedInputStream instances Source: https://commons.apache.org/proper/commons-io/apidocs/src-html/org/apache/commons/io/input/BoundedInputStream.Builder.html Examples demonstrating how to initialize BoundedInputStream using NIO, standard IO, and pre-existing streams. ```java BoundedInputStream s = BoundedInputStream.builder() .setPath(Paths.get("MyFile.xml")) .setMaxCount(1024) .setPropagateClose(false) .get(); ``` ```java BoundedInputStream s = BoundedInputStream.builder() .setFile(new File("MyFile.xml")) .setMaxCount(1024) .setPropagateClose(false) .get(); ``` ```java InputStream in = ...; BoundedInputStream s = BoundedInputStream.builder() .setInputStream(in) .setCount(12) .setMaxCount(1024) .setPropagateClose(false) .get(); ``` -------------------------------- ### Iterate Over Lines in InputStream Source: https://commons.apache.org/proper/commons-io/apidocs/src-html/org/apache/commons/io/IOUtils.html Use this method to get an iterator for lines in an InputStream. Ensure the stream is closed after use, for example, using a try-finally block. ```java LineIterator it = IOUtils.lineIterator(stream, StandardCharsets.UTF_8.name()); while (it.hasNext()) { String line = it.nextLine(); /// do something with line } } finally { IOUtils.closeQuietly(stream); } ``` -------------------------------- ### Example Usage Source: https://commons.apache.org/proper/commons-io/apidocs/org/apache/commons/io/comparator/PathFileComparator.html Demonstrates how to use the PathFileComparator singletons for sorting files. ```APIDOC ## Example Usage ### Case-Sensitive File Path Sort ```java List list = ...; ((AbstractFileComparator) PathFileComparator.PATH_COMPARATOR).sort(list); ``` ### Reverse Case-Insensitive File Path Sort ```java File[] array = ...; ((AbstractFileComparator) PathFileComparator.PATH_INSENSITIVE_REVERSE).sort(array); ``` ``` -------------------------------- ### Walk Directory Tree using NIO (Full Depth) Source: https://commons.apache.org/proper/commons-io/apidocs/src-html/org/apache/commons/io/filefilter/DirectoryFileFilter.html This example shows how to traverse an entire directory tree using NIO's `Files.walkFileTree` and `AccumulatorPathVisitor` with the `DirectoryFileFilter`. It prints the path counters, directory list, and file list. ```java final Path dir = PathUtils.current(); final AccumulatorPathVisitor visitor = AccumulatorPathVisitor.withLongCounters(DirectoryFileFilter.INSTANCE); // Walk directory tree Files.walkFileTree(dir, visitor); System.out.println(visitor.getPathCounters()); System.out.println(visitor.getDirList()); System.out.println(visitor.getFileList()); ``` -------------------------------- ### Get String Representation of Character Sequence Source: https://commons.apache.org/proper/commons-io/apidocs/src-html/org/apache/commons/io/input/CharSequenceReader.html Returns a String representation of the underlying character sequence from the start index to the end index. Useful for debugging or displaying the relevant portion of the sequence. ```java @Override public String toString() { return charSequence.subSequence(start(), end()).toString(); } ``` -------------------------------- ### Create a Tailer with basic parameters Source: https://commons.apache.org/proper/commons-io/apidocs/src-html/org/apache/commons/io/input/Tailer.Tailable.html Creates and starts a Tailer for the given file using a listener. ```java public static Tailer create(final File file, final TailerListener tailerListener) { //@formatter:off return builder() .setFile(file) .setTailerListener(tailerListener) .get(); //@formatter:on } ``` -------------------------------- ### Get Portion of Origin as Byte Array Source: https://commons.apache.org/proper/commons-io/apidocs/src-html/org/apache/commons/io/build/AbstractOrigin.URIOrigin.html Retrieves a specific portion of the origin as a byte array, defined by a starting position and length. It includes checks for integer overflow and ensures the requested range is within the bounds of the data. Throws UnsupportedOperationException if the origin cannot be converted to a Path. ```java final byte[] bytes = getByteArray(); // Checks for int overflow. final int start = Math.toIntExact(position); if (start < 0 || length < 0 || start + length < 0 || start + length > bytes.length) { throw new IllegalArgumentException("Couldn't read array (start: " + start + ", length: " + length + ", data length: " + bytes.length + ")."); } return Arrays.copyOfRange(bytes, start, start + length); ``` -------------------------------- ### GET /file Source: https://commons.apache.org/proper/commons-io/apidocs/src-html/org/apache/commons/io/build/AbstractStreamBuilder.html Gets a File representation from the origin. ```APIDOC ## GET /file ### Description Gets a File from the origin. ### Response #### Success Response (200) - **File** (Object) - A File object. ### Errors - **IllegalStateException**: If the origin is null. - **UnsupportedOperationException**: If the origin cannot be converted to a File. ``` -------------------------------- ### Start File Monitoring Source: https://commons.apache.org/proper/commons-io/apidocs/src-html/org/apache/commons/io/monitor/FileAlterationMonitor.html Starts the file monitoring process. Throws an IllegalStateException if the monitor is already running. Initializes all registered observers before starting the monitoring thread. ```java public synchronized void start() throws Exception { if (running) { throw new IllegalStateException("Monitor is already running"); } for (final FileAlterationObserver observer : observers) { observer.initialize(); } running = true; if (threadFactory != null) { thread = threadFactory.newThread(this); } else { thread = new Thread(this); } thread.start(); } ``` -------------------------------- ### GET /origin/size Source: https://commons.apache.org/proper/commons-io/apidocs/src-html/org/apache/commons/io/build/AbstractOrigin.AbstractRandomAccessFileOrigin.html Gets the size of the origin in bytes or characters. ```APIDOC ## GET /origin/size ### Description Retrieves the size of the origin, if possible. ### Method GET ### Response #### Success Response (200) - **size** (long) - The size of the origin in bytes or characters. ### Errors - **IOException** - If an I/O error occurs. ``` -------------------------------- ### Walk Directory Tree using NIO (Limited Depth) Source: https://commons.apache.org/proper/commons-io/apidocs/src-html/org/apache/commons/io/filefilter/DirectoryFileFilter.html This example demonstrates walking a directory tree up to a specified depth (1 in this case) using NIO's `Files.walkFileTree` and `AccumulatorPathVisitor` with the `DirectoryFileFilter`. It prints the path counters and the list of files found. ```java final Path dir = PathUtils.current(); final AccumulatorPathVisitor visitor = AccumulatorPathVisitor.withLongCounters(DirectoryFileFilter.INSTANCE); // Walk one directory Files.walkFileTree(dir, Collections.emptySet(), 1, visitor); System.out.println(visitor.getPathCounters()); System.out.println(visitor.getFileList()); visitor.getPathCounters().reset(); ``` -------------------------------- ### Tailer Creation using Builder Source: https://commons.apache.org/proper/commons-io/apidocs/org/apache/commons/io/input/class-use/Tailer.html Demonstrates how to create a Tailer instance using the recommended Builder pattern. ```APIDOC ## Tailer.Builder.get() ### Description Builds a new `Tailer` instance using the builder pattern. ### Method `Tailer.Builder.get()` ### Endpoint N/A (Java method) ### Parameters None ### Request Body None ### Request Example ```java Tailer tailer = Tailer.builder().get(); ``` ### Response #### Success Response (Tailer Instance) - **Tailer** (Tailer) - A newly created Tailer object. #### Response Example ```json { "example": "Tailer instance created" } ``` ``` -------------------------------- ### GET /outputStream Source: https://commons.apache.org/proper/commons-io/apidocs/src-html/org/apache/commons/io/build/AbstractStreamBuilder.html Gets an OutputStream from the origin using configured OpenOptions. ```APIDOC ## GET /outputStream ### Description Gets an OutputStream from the origin with OpenOption[]. ### Response #### Success Response (200) - **OutputStream** (Object) - An OutputStream. ### Errors - **IllegalStateException**: If the origin is null. - **UnsupportedOperationException**: If the origin cannot be converted to an OutputStream. - **IOException**: If an I/O error occurs. ``` -------------------------------- ### Initialize WriterOutputStream with Builder Source: https://commons.apache.org/proper/commons-io/apidocs/src-html/org/apache/commons/io/output/WriterOutputStream.html Demonstrates how to configure and instantiate a WriterOutputStream using the builder pattern. ```java OutputStream out = ... Charset cs = ... OutputStreamWriter writer = new OutputStreamWriter(out, cs); WriterOutputStream out2 = WriterOutputStream.builder() .setWriter(writer) .setCharset(cs) .get(); ``` ```java WriterOutputStream s = WriterOutputStream.builder() .setPath(path) .setBufferSize(8192) .setCharset(StandardCharsets.UTF_8) .setWriteImmediately(false) .get(); ``` -------------------------------- ### GET /inputStream Source: https://commons.apache.org/proper/commons-io/apidocs/src-html/org/apache/commons/io/build/AbstractStreamBuilder.html Gets an InputStream from the origin using configured OpenOptions. ```APIDOC ## GET /inputStream ### Description Gets an InputStream from the origin with OpenOption[]. ### Response #### Success Response (200) - **InputStream** (Object) - An input stream. ### Errors - **IllegalStateException**: If the origin is null. - **UnsupportedOperationException**: If the origin cannot be converted to an InputStream. - **IOException**: If an I/O error occurs. ``` -------------------------------- ### Start Tailer with Builder Source: https://commons.apache.org/proper/commons-io/apidocs/org/apache/commons/io/input/Tailer.html Use the `Tailer.Builder` to construct a new `Tailer` instance. This is the recommended approach over deprecated constructors. ```java Tailer.Builder builder() { // Constructs a new Tailer.Builder. } ``` -------------------------------- ### QueueInputStream Usage Example Source: https://commons.apache.org/proper/commons-io/apidocs/src-html/org/apache/commons/io/input/QueueInputStream.Builder.html Demonstrates basic usage of QueueInputStream and its associated QueueOutputStream. ```APIDOC ## QueueInputStream Basic Usage ### Description This example shows how to create a `QueueInputStream` and its corresponding `QueueOutputStream` to write and read data between threads or components. ### Method N/A (Illustrative example) ### Endpoint N/A ### Parameters N/A ### Request Example ```java // Assume UTF_8 is defined elsewhere, e.g., StandardCharsets.UTF_8 // 1. Create a QueueInputStream QueueInputStream inputStream = new QueueInputStream(); // 2. Obtain the associated QueueOutputStream QueueOutputStream outputStream = inputStream.newQueueOutputStream(); // 3. Write data to the output stream (e.g., from a producer thread) outputStream.write("hello world".getBytes(UTF_8)); // 4. Read data from the input stream (e.g., in a consumer thread) int data = inputStream.read(); // Reads 'h' // ... further reads to consume the rest of the data // Note: Closing QueueInputStream has no effect. // outputStream.close(); // Closing the output stream might signal end-of-stream depending on implementation details not shown here. ``` ### Response N/A (Illustrative example) ``` -------------------------------- ### Get File Size Source: https://commons.apache.org/proper/commons-io/apidocs/src-html/org/apache/commons/io/file/FilesUncheck.html Gets the size of a file, delegating to Files.size and wrapping IOException in UncheckedIOException. ```APIDOC ## Get File Size ### Description Gets the size of a file in bytes. ### Method `public static long size(final Path path)` ### Endpoint N/A (This is a utility method, not a REST endpoint) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example N/A ### Response #### Success Response (200) - **long** - The size of the file in bytes. #### Response Example ```json 1024 ``` ``` -------------------------------- ### Tailer Creation using Thread Source: https://commons.apache.org/proper/commons-io/apidocs/org/apache/commons/io/input/Tailer.html Demonstrates how to create and run a Tailer instance using a `Thread`. ```APIDOC ## Tailer Creation using Thread ### Description This section explains how to create a `Tailer` and run it in its own `Thread`. This is a straightforward way to start the tailing process. ### Constructor `Tailer(File file, TailerListener listener, long delay)` ### Parameters - **file** (File) - Required - The file to monitor. - **listener** (TailerListener) - Required - The listener to handle file events. - **delay** (long) - Required - The delay in milliseconds between checks. ### Request Example ```java TailerListener listener = new MyTailerListener(); File file = new File("path/to/your/file.log"); long delay = 1000; Tailer tailer = new Tailer(file, listener, delay); Thread thread = new Thread(tailer); thread.setDaemon(true); // Optional: Set as daemon thread thread.start(); ``` ``` -------------------------------- ### TaggedOutputStream Usage Example Source: https://commons.apache.org/proper/commons-io/apidocs/org/apache/commons/io/output/TaggedOutputStream.html Example demonstrating how to use TaggedOutputStream to identify exceptions caused by the stream. ```APIDOC ## Usage Example ### Using `isCauseOf` ```java TaggedOutputStream stream = new TaggedOutputStream(...); try { // Processing that may throw an IOException either from this stream // or from some other IO activity like temporary files, etc. writeToStream(stream); } catch (IOException e) { if (stream.isCauseOf(e)) { // The exception was caused by this stream. // Use e.getCause() to get the original exception. } else { // The exception was caused by something else. } } ``` ### Using `throwIfCauseOf` ```java TaggedOutputStream stream = new TaggedOutputStream(...); try { writeToStream(stream); } catch (IOException e) { stream.throwIfCauseOf(e); // ... or process the exception that was caused by something else } ``` ``` -------------------------------- ### Create Tailer with Full Configuration Source: https://commons.apache.org/proper/commons-io/apidocs/src-html/org/apache/commons/io/input/Tailer.RandomAccessResourceBridge.html Creates and starts a Tailer with all configurable options set. Use the builder pattern for modern applications. ```java return builder() .setFile(file) .setTailerListener(tailerListener) .setDelayDuration(Duration.ofMillis(delayMillis)) .setTailFromEnd(end) .setReOpen(reOpen) .setBufferSize(bufferSize) .get(); ``` -------------------------------- ### CanReadFileFilter - Usage Examples Source: https://commons.apache.org/proper/commons-io/apidocs/org/apache/commons/io/filefilter/CanReadFileFilter.html Provides examples of how to use the CanReadFileFilter with Classic IO to filter files. ```APIDOC ## Using Classic IO **Example: Printing readable files** ```java File dir = FileUtils.current(); String[] files = dir.list(CanReadFileFilter.CAN_READ); for (String file : files) { System.out.println(file); } ``` **Example: Printing un-readable files** ```java File dir = FileUtils.current(); String[] files = dir.list(CanReadFileFilter.CANNOT_READ); for (String file : files) { System.out.println(file); } ``` **Example: Printing read-only files** ```java File dir = FileUtils.current(); String[] files = dir.list(CanReadFileFilter.READ_ONLY); for (String file : files) { System.out.println(file); } ``` ``` -------------------------------- ### Walk Directory Tree with Symbolic Link Filter using NIO Source: https://commons.apache.org/proper/commons-io/apidocs/src-html/org/apache/commons/io/filefilter/SymbolicLinkFileFilter.html Demonstrates walking a directory tree using NIO's Files.walkFileTree and the SymbolicLinkFileFilter. It shows how to count paths and list files/directories. ```java final Path dir = PathUtils.current(); final AccumulatorPathVisitor visitor = AccumulatorPathVisitor.withLongCounters(SymbolicLinkFileFilter.INSTANCE); // Walk one directory Files.walkFileTree(dir, Collections.emptySet(), 1, visitor); System.out.println(visitor.getPathCounters()); System.out.println(visitor.getFileList()); visitor.getPathCounters().reset(); // Walk directory tree Files.walkFileTree(dir, visitor); System.out.println(visitor.getPathCounters()); System.out.println(visitor.getDirList()); System.out.println(visitor.getFileList()); ``` -------------------------------- ### Build BufferedFileChannelInputStream Source: https://commons.apache.org/proper/commons-io/apidocs/src-html/org/apache/commons/io/input/BufferedFileChannelInputStream.html Examples showing how to instantiate the stream using either a File object or an NIO Path. ```java BufferedFileChannelInputStream s = BufferedFileChannelInputStream.builder() .setFile(file) .setBufferSize(4096) .get(); ``` ```java BufferedFileChannelInputStream s = BufferedFileChannelInputStream.builder() .setPath(path) .setBufferSize(4096) .get(); ``` -------------------------------- ### Tailer Creation using Executor Source: https://commons.apache.org/proper/commons-io/apidocs/org/apache/commons/io/input/Tailer.html Demonstrates how to create and run a Tailer instance using an `Executor`. ```APIDOC ## Tailer Creation using Executor ### Description This section illustrates how to create a `Tailer` and execute it using an `ExecutorService`. This approach is useful for managing threads within an existing execution framework. ### Constructor `Tailer(File file, TailerListener listener, long delay)` ### Parameters - **file** (File) - Required - The file to monitor. - **listener** (TailerListener) - Required - The listener to handle file events. - **delay** (long) - Required - The delay in milliseconds between checks. ### Request Example ```java TailerListener listener = new MyTailerListener(); File file = new File("path/to/your/file.log"); long delay = 1000; Tailer tailer = new Tailer(file, listener, delay); // Example Executor implementation Executor executor = new Executor() { @Override public void execute(Runnable command) { command.run(); } }; executor.execute(tailer); ``` ``` -------------------------------- ### Copy Directories and TXT Files with Filter Source: https://commons.apache.org/proper/commons-io/apidocs/src-html/org/apache/commons/io/FileUtils.html This example demonstrates copying directories and files with a specific extension (e.g., .txt) using a combination of file filters. ```java // Create a filter for ".txt" files IOFileFilter txtSuffixFilter = FileFilterUtils.suffixFileFilter(".txt"); IOFileFilter txtFiles = FileFilterUtils.andFileFilter(FileFileFilter.INSTANCE, txtSuffixFilter); // Create a filter for either directories or ".txt" files FileFilter filter = FileFilterUtils.orFileFilter(DirectoryFileFilter.DIRECTORY, txtFiles); // Copy using the filter FileUtils.copyDirectory(srcDir, destDir, filter); ``` -------------------------------- ### FileSystem Constructor Source: https://commons.apache.org/proper/commons-io/apidocs/src-html/org/apache/commons/io/FileSystem.html Initializes a new FileSystem instance with specific constraints such as block size, case sensitivity, and naming rules. ```APIDOC ## Constructor FileSystem ### Description Constructs a new instance of FileSystem with defined parameters for file system behavior and constraints. ### Parameters - **blockSize** (int) - Required - File allocation block size in bytes. - **caseSensitive** (boolean) - Required - Whether this file system is case-sensitive. - **casePreserving** (boolean) - Required - Whether this file system is case-preserving. - **maxFileLength** (int) - Required - The maximum length for file names. - **maxPathLength** (int) - Required - The maximum length of the path to a file. - **illegalFileNameChars** (int[]) - Required - Illegal characters for this file system. - **reservedFileNames** (String[]) - Required - The reserved file names. - **reservedFileNamesExtensions** (boolean) - Required - The reserved file name extensions. - **supportsDriveLetter** (boolean) - Required - Whether this file system support driver letters. - **nameSeparator** (char) - Required - The name separator (e.g., '\\' on Windows, '/' on Linux). - **nameLengthStrategy** (NameLengthStrategy) - Required - The strategy for measuring and truncating file and path names. ``` -------------------------------- ### Get Writer Source: https://commons.apache.org/proper/commons-io/apidocs/src-html/org/apache/commons/io/build/AbstractOrigin.URIOrigin.html Abstract method to get a Writer for the origin. Concrete implementations must override this to provide writer access. ```Java public Writer getWriter(final Charset charset) throws IOException { throw unsupportedOperation("getWriter"); } ``` -------------------------------- ### CanWriteFileFilter Usage Examples Source: https://commons.apache.org/proper/commons-io/apidocs/org/apache/commons/io/filefilter/CanWriteFileFilter.html Examples demonstrating how to use CanWriteFileFilter to find writable and unwritable files using classic Java IO. ```APIDOC ## Using Classic IO ### Description Example showing how to print out a list of the current directory's writable files. ### Method N/A (Illustrative Example) ### Endpoint N/A (Illustrative Example) ### Request Example ```java File dir = FileUtils.current(); String[] files = dir.list(CanWriteFileFilter.CAN_WRITE); for (String file : files) { System.out.println(file); } ``` ## Using Classic IO ### Description Example showing how to print out a list of the current directory's un-writable files. ### Method N/A (Illustrative Example) ### Endpoint N/A (Illustrative Example) ### Request Example ```java File dir = FileUtils.current(); String[] files = dir.list(CanWriteFileFilter.CANNOT_WRITE); for (String file : files) { System.out.println(file); } ``` ``` -------------------------------- ### Build AutoCloseInputStream instances Source: https://commons.apache.org/proper/commons-io/apidocs/org/apache/commons/io/input/AutoCloseInputStream.Builder.html Examples showing how to initialize an AutoCloseInputStream using either a file path or an existing InputStream. ```java AutoCloseInputStream s = AutoCloseInputStream.builder() .setPath(path) .get(); ``` ```java AutoCloseInputStream s = AutoCloseInputStream.builder() .setInputStream(inputStream) .get(); ``` -------------------------------- ### AgeFileFilter Usage Examples Source: https://commons.apache.org/proper/commons-io/apidocs/org/apache/commons/io/filefilter/AgeFileFilter.html Examples demonstrating how to use AgeFileFilter with both classic Java IO and NIO file operations to filter files based on their age. ```APIDOC ## AgeFileFilter Usage Examples ### Description Examples of using `AgeFileFilter` for filtering files by age. ### Using Classic IO ```java Path dir = PathUtils.current(); // We are interested in files older than one day Instant cutoff = Instant.now().minus(Duration.ofDays(1)); String[] files = dir.list(new AgeFileFilter(cutoff)); for (String file : files) { System.out.println(file); } ``` ### Using NIO ```java Path dir = PathUtils.current(); // We are interested in files older than one day Instant cutoff = Instant.now().minus(Duration.ofDays(1)); AccumulatorPathVisitor visitor = AccumulatorPathVisitor.withLongCounters(new AgeFileFilter(cutoff)); // // Walk one directoryectory Files.walkFileTree(dir, Collections.emptySet(), 1, visitor); System.out.println(visitor.getPathCounters()); System.out.println(visitor.getFileList()); // visitor.getPathCounters().reset(); // // Walk directory tree Files.walkFileTree(dir, visitor); System.out.println(visitor.getPathCounters()); System.out.println(visitor.getDirList()); System.out.println(visitor.getFileList()); ``` ``` -------------------------------- ### XmlStreamWriter Builder Get Method Source: https://commons.apache.org/proper/commons-io/apidocs/src-html/org/apache/commons/io/output/XmlStreamWriter.html The 'get' method of the XmlStreamWriter Builder, responsible for constructing and returning a new XmlStreamWriter instance. It requires an OutputStream and a Charset to be configured. ```java @Override public XmlStreamWriter get() throws IOException { return new XmlStreamWriter(this); } ``` -------------------------------- ### Building and Using File Filters Source: https://commons.apache.org/proper/commons-io/apidocs/src-html/org/apache/commons/io/DirectoryWalker.html Demonstrates how to construct complex FileFilters using utility methods for directory and file filtering, including combining filters with AND and OR logic. ```Java // Build up the filters and create the walker // Create a filter for Non-hidden directories IOFileFilter fooDirFilter = FileFilterUtils.andFileFilter(FileFilterUtils.directoryFileFilter, HiddenFileFilter.VISIBLE); // Create a filter for Files ending in ".txt" IOFileFilter fooFileFilter = FileFilterUtils.andFileFilter(FileFilterUtils.fileFileFilter, FileFilterUtils.suffixFileFilter(".txt")); // Combine the directory and file filters using an OR condition java.io.FileFilter fooFilter = FileFilterUtils.orFileFilter(fooDirFilter, fooFileFilter); // Use the filter to construct a DirectoryWalker implementation ``` -------------------------------- ### Pre-visit Directory Logic Source: https://commons.apache.org/proper/commons-io/apidocs/src-html/org/apache/commons/io/file/CopyDirectoryVisitor.html Handles directory creation at the target location before visiting contents. ```java @Override public FileVisitResult preVisitDirectory(final Path directory, final BasicFileAttributes attributes) throws IOException { final Path newTargetDir = resolveRelativeAsString(directory); if (Files.notExists(newTargetDir)) { Files.createDirectory(newTargetDir); } return super.preVisitDirectory(directory, attributes); } ``` -------------------------------- ### Get Channel with Options Source: https://commons.apache.org/proper/commons-io/apidocs/src-html/org/apache/commons/io/build/AbstractOrigin.AbstractRandomAccessFileOrigin.html Gets the origin as a Channel with specified open options. This method is intended to be overridden by subclasses. Throws UnsupportedOperationException if the origin cannot be converted to a channel. ```Java protected Channel getChannel(final OpenOption... options) throws IOException { throw unsupportedOperation("getChannel"); } ``` -------------------------------- ### Get Length of Char Array Source: https://commons.apache.org/proper/commons-io/apidocs/src-html/org/apache/commons/io/IOUtils.html Returns the length of a char array, returning 0 if the array is null. Provides a null-safe way to get the array's length. ```java public static int length(final char[] array) { return array == null ? 0 : array.length; } ``` -------------------------------- ### List files using Classic IO Source: https://commons.apache.org/proper/commons-io/apidocs/org/apache/commons/io/filefilter/FileFileFilter.html Demonstrates filtering a directory for files using the classic java.io.File API. ```java File dir = FileUtils.current(); String[] files = dir.list(FileFileFilter.INSTANCE); for (String file : files) { System.out.println(file); } ``` -------------------------------- ### Get Free Space in Bytes Source: https://commons.apache.org/proper/commons-io/apidocs/src-html/org/apache/commons/io/FileSystemUtils.html Retrieves the amount of free space in bytes for a given path. It uses java.nio.file APIs to get the usable space from the file store. ```java static long getFreeSpace(final String pathStr) throws IOException { final Path path = Paths.get(Objects.requireNonNull(pathStr, "pathStr")); if (Files.exists(path)) { // Need an absolute path for input like "" to work return Files.getFileStore(path.toAbsolutePath()).getUsableSpace(); // return path.toAbsolutePath().toFile().getUsableSpace(); } throw new IllegalArgumentException(path.toString()); } ``` -------------------------------- ### Build a WriterOutputStream instance Source: https://commons.apache.org/proper/commons-io/apidocs/org/apache/commons/io/output/WriterOutputStream.Builder.html Demonstrates the fluent builder pattern to configure and instantiate a WriterOutputStream. ```java WriterOutputStream s = WriterOutputStream.builder() .setPath(path) .setBufferSize(8192) .setCharset(StandardCharsets.UTF_8) .setWriteImmediately(false) .get(); ``` -------------------------------- ### System and Configuration Utilities Source: https://commons.apache.org/proper/commons-io/apidocs/index-all.html Methods for retrieving file system constraints and configuration settings. ```APIDOC ## FileSystem Configuration ### Description Retrieves constraints and separators for the underlying file system. ### Methods - getMaxFileNameLength(): Gets the maximum length for file names. - getMaxPathLength(): Gets the maximum length for file paths. - getNameSeparator(): Gets the name separator (e.g., '\\' on Windows, '/' on Linux). ``` -------------------------------- ### Get BOM Source: https://commons.apache.org/proper/commons-io/apidocs/src-html/org/apache/commons/io/input/BOMInputStream.Builder.html Gets the ByteOrderMark (Byte Order Mark) from the stream. Returns the BOM or null if none matched. Throws IOException if an error reading the first bytes occurs. ```java /** * Gets the ByteOrderMark (Byte Order Mark). * * @return The BOM or null if none matched. * @throws IOException * if an error reading the first bytes of the stream occurs. */ public ByteOrderMark getBOM() throws IOException { if (firstBytes == null) { byteOrderMark = readBom(); } return byteOrderMark; } ``` -------------------------------- ### Filter files by readability using Classic IO Source: https://commons.apache.org/proper/commons-io/apidocs/src-html/org/apache/commons/io/filefilter/CanReadFileFilter.html Examples demonstrating how to list readable, un-readable, and read-only files in the current directory. ```java File dir = FileUtils.current(); String[] files = dir.list(CanReadFileFilter.CAN_READ); for (String file : files) { System.out.println(file); } ``` ```java File dir = FileUtils.current(); String[] files = dir.list(CanReadFileFilter.CANNOT_READ); for (String file : files) { System.out.println(file); } ``` ```java File dir = FileUtils.current(); String[] files = dir.list(CanReadFileFilter.READ_ONLY); for (String file : files) { System.out.println(file); } ``` -------------------------------- ### Get Last Modified File Time (File) Source: https://commons.apache.org/proper/commons-io/apidocs/src-html/org/apache/commons/io/file/PathUtils.html Gets the last modified time of a File, providing a workaround for JDK-8177809 which affects OpenJDK 8 and 9. Throws IOException on error. ```java public static FileTime getLastModifiedFileTime(final File file) throws IOException { return getLastModifiedFileTime(file.toPath(), null, EMPTY_LINK_OPTION_ARRAY); } ``` -------------------------------- ### Get Channel with Specific Type Source: https://commons.apache.org/proper/commons-io/apidocs/src-html/org/apache/commons/io/build/AbstractOrigin.ByteArrayOrigin.html Retrieves the origin as a specific type of Channel, such as FileChannel or SeekableByteChannel. It first attempts to get a generic Channel and then checks if it's an instance of the requested type. ```APIDOC ## GET /origin/channel/{channelType} ### Description Retrieves the origin as a specific type of Channel. ### Method GET ### Endpoint `/origin/channel/{channelType}` ### Parameters #### Path Parameters - **channelType** (Class) - Required - The specific type of Channel to retrieve (e.g., `FileChannel.class`). #### Query Parameters - **options** (OpenOption...) - Optional - Options specifying how a file-based origin is opened. ### Response #### Success Response (200) - **C** (Channel) - A new Channel of the specified type on the origin. #### Error Response - **UnsupportedOperationException** - If this origin cannot be converted to the specified channel type. - **IOException** - If an I/O error occurs. ``` -------------------------------- ### Check if String Starts With Another (Case-Sensitive) Source: https://commons.apache.org/proper/commons-io/apidocs/src-html/org/apache/commons/io/IOCase.html Checks if one string starts with another using the case-sensitivity rule. Mimics String.startsWith but accounts for case sensitivity. Returns false if either input is null. ```java public boolean checkStartsWith(final String str, final String start) { return str != null && start != null && str.regionMatches(!sensitive, 0, start, 0, start.length()); } ``` -------------------------------- ### Tailer.create Source: https://commons.apache.org/proper/commons-io/apidocs/src-html/org/apache/commons/io/input/Tailer.RandomAccessResourceBridge.html Creates and starts a Tailer for a given file using specified parameters. ```APIDOC ## Static Method create ### Description Creates and starts a Tailer for the given file. This method is deprecated; use the builder pattern instead. ### Parameters - **file** (File) - Required - The file to follow. - **tailerListener** (TailerListener) - Required - The TailerListener to use. - **delayMillis** (long) - Required - The delay between checks of the file for new content in milliseconds. - **end** (boolean) - Required - Set to true to tail from the end of the file, false to tail from the beginning. - **bufferSize** (int) - Required - Buffer size. ### Response - **Tailer** - The new tailer instance. ``` -------------------------------- ### current Source: https://commons.apache.org/proper/commons-io/apidocs/org/apache/commons/io/file/PathUtils.html Gets the current directory. ```APIDOC ## GET /api/currentDirectory ### Description Gets the current directory. ### Method GET ### Endpoint /api/currentDirectory ### Parameters (No parameters required) ### Request Body (Not applicable for this method) ### Response #### Success Response (200) - **currentDirectory** (Path) - The current directory. #### Response Example (Example response structure would be defined here if available) ### Since 2.9.0 ``` -------------------------------- ### Copy directories with filters Source: https://commons.apache.org/proper/commons-io/apidocs/org/apache/commons/io/FileUtils.html Examples demonstrating how to use FileFilter to selectively copy directory contents. ```java IOFileFilter txtFiles = FileFilterUtils.andFileFilter(FileFileFilter.INSTANCE, txtSuffixFilter); // Create a filter for either directories or ".txt" files FileFilter filter = FileFilterUtils.orFileFilter(DirectoryFileFilter.DIRECTORY, txtFiles); // Copy using the filter FileUtils.copyDirectory(srcDir, destDir, filter, false); ``` ```java // only copy the directory structure FileUtils.copyDirectory(srcDir, destDir, DirectoryFileFilter.DIRECTORY, false); ``` ```java // Create a filter for ".txt" files IOFileFilter txtSuffixFilter = FileFilterUtils.suffixFileFilter(".txt"); IOFileFilter txtFiles = FileFilterUtils.andFileFilter(FileFileFilter.INSTANCE, txtSuffixFilter); // Create a filter for either directories or ".txt" files FileFilter filter = FileFilterUtils.orFileFilter(DirectoryFileFilter.DIRECTORY, txtFiles); // Copy using the filter FileUtils.copyDirectory(srcDir, destDir, filter, false); ``` -------------------------------- ### getRandomAccessFile Source: https://commons.apache.org/proper/commons-io/apidocs/org/apache/commons/io/build/AbstractStreamBuilder.html Gets a RandomAccessFile from the origin. ```APIDOC ### getRandomAccessFile public RandomAccessFile getRandomAccessFile() throws IOException Gets a RandomAccessFile from the origin. Returns: A RandomAccessFile Throws: `IllegalStateException` - if the `origin` is `null`. `UnsupportedOperationException` - if the origin cannot be converted to a `RandomAccessFile`. `IOException` - if an I/O error occurs. Since: 2.18.0 ``` -------------------------------- ### Filter files by prefix using NIO Source: https://commons.apache.org/proper/commons-io/apidocs/org/apache/commons/io/filefilter/PrefixFileFilter.html Demonstrates walking a directory tree and filtering files by prefix using the NIO Files.walkFileTree method and AccumulatorPathVisitor. ```java final Path dir = PathUtils.current(); final AccumulatorPathVisitor visitor = AccumulatorPathVisitor.withLongCounters(new PrefixFileFilter("Test")); // // Walk one directory Files.**walkFileTree**(dir, Collections.emptySet(), 1, visitor); System.out.println(visitor.getPathCounters()); System.out.println(visitor.getFileList()); // visitor.getPathCounters().reset(); // // Walk directory tree Files.**walkFileTree**(dir, visitor); System.out.println(visitor.getPathCounters()); System.out.println(visitor.getDirList()); System.out.println(visitor.getFileList()); ``` -------------------------------- ### getOpenOptions Source: https://commons.apache.org/proper/commons-io/apidocs/org/apache/commons/io/build/AbstractStreamBuilder.html Gets the OpenOption array. ```APIDOC ### getOpenOptions public OpenOption[] getOpenOptions() Gets the OpenOption array. Returns: the OpenOption array. ``` -------------------------------- ### Tailer.create Methods Source: https://commons.apache.org/proper/commons-io/apidocs/src-html/org/apache/commons/io/input/Tailer.RandomAccessResourceBridge.html Legacy static methods used to create and start a Tailer instance for file monitoring. ```APIDOC ## Static Method: create ### Description Creates and starts a Tailer for a given file. These methods are deprecated; it is recommended to use the Builder pattern instead. ### Parameters - **file** (File) - Required - The file to follow. - **tailerListener** (TailerListener) - Required - The listener to use for file events. - **delayMillis** (long) - Optional - The delay between checks in milliseconds. - **end** (boolean) - Optional - Set to true to tail from the end of the file, false to tail from the beginning. - **reOpen** (boolean) - Optional - Whether to close/reopen the file between chunks. - **bufferSize** (int) - Optional - The buffer size to use. ### Response - **Tailer** (Object) - The new Tailer instance. ``` -------------------------------- ### Handle Cancelled Callback Example Source: https://commons.apache.org/proper/commons-io/apidocs/src-html/org/apache/commons/io/DirectoryWalker.CancelException.html This example demonstrates how a subclass can implement cancellation logic. The `handleIsCancelled` method checks a volatile flag, and if true, the `handleCancelled` method is invoked. This pattern allows for external cancellation of the directory walk. ```Java public class FooDirectoryWalker extends DirectoryWalker { private volatile boolean cancelled = false; public void cancel() { cancelled = true; } private void handleIsCancelled(File file, int depth, Collection results) { return cancelled; } protected void handleCancelled(File startDirectory, Collection results, CancelException cancel) { // implement processing required when a cancellation occurs } } ``` -------------------------------- ### Create Parent Directories with LinkOption Source: https://commons.apache.org/proper/commons-io/apidocs/src-html/org/apache/commons/io/file/PathUtils.html Creates the parent directories for a given path, with control over symbolic link handling. If the parent directories already exist, they are returned. Supports optional file attributes. ```Java public static Path createParentDirectories(final Path path, final LinkOption linkOption, final FileAttribute... attrs) throws IOException { Path parent = getParent(path); parent = linkOption == LinkOption.NOFOLLOW_LINKS ? parent : readIfSymbolicLink(parent); if (parent == null) { return null; } final boolean exists = linkOption == null ? Files.exists(parent) : Files.exists(parent, linkOption); return exists ? parent : Files.createDirectories(parent, attrs); } ``` -------------------------------- ### Get Path Source: https://commons.apache.org/proper/commons-io/apidocs/src-html/org/apache/commons/io/build/AbstractOrigin.PathOrigin.html Retrieves the origin as a Path. ```APIDOC ## GET /origin/path ### Description Retrieves the origin as a Path. ### Method GET ### Endpoint /origin/path ### Response #### Success Response (200) - **path** (Path) - The origin as a Path. #### Error Response - **UnsupportedOperationException** - If this method is not implemented in a concrete subclass. ``` -------------------------------- ### Get File Source: https://commons.apache.org/proper/commons-io/apidocs/src-html/org/apache/commons/io/build/AbstractOrigin.PathOrigin.html Retrieves the origin as a File. ```APIDOC ## GET /origin/file ### Description Retrieves the origin as a File. ### Method GET ### Endpoint /origin/file ### Response #### Success Response (200) - **file** (File) - The origin as a File. #### Error Response - **UnsupportedOperationException** - If this method is not implemented in a concrete subclass. ``` -------------------------------- ### FileSystem Configuration Constructor Source: https://commons.apache.org/proper/commons-io/apidocs/src-html/org/apache/commons/io/FileSystem.html Initializes a FileSystem instance with specific constraints regarding naming, length, and character support. ```java FileSystem(final int blockSize, final boolean caseSensitive, final boolean casePreserving, final int maxFileLength, final int maxPathLength, final int[] illegalFileNameChars, final String[] reservedFileNames, final boolean reservedFileNamesExtensions, final boolean supportsDriveLetter, final char nameSeparator, final NameLengthStrategy nameLengthStrategy) { this.blockSize = blockSize; this.maxFileNameLength = maxFileLength; this.maxPathLength = maxPathLength; this.illegalFileNameChars = Objects.requireNonNull(illegalFileNameChars, "illegalFileNameChars"); this.reservedFileNames = Objects.requireNonNull(reservedFileNames, "reservedFileNames"); //Arrays.sort(this.reservedFileNames); this.reservedFileNamesExtensions = reservedFileNamesExtensions; this.caseSensitive = caseSensitive; this.casePreserving = casePreserving; this.supportsDriveLetter = supportsDriveLetter; ``` -------------------------------- ### List files using NIO Source: https://commons.apache.org/proper/commons-io/apidocs/org/apache/commons/io/filefilter/FileFileFilter.html Demonstrates filtering files using the NIO Files.walkFileTree method with an AccumulatorPathVisitor. ```java final Path dir = PathUtils.current(); final AccumulatorPathVisitor visitor = AccumulatorPathVisitor.withLongCounters(FileFileFilter.INSTANCE); // // Walk one directory Files.walkFileTree(dir, Collections.emptySet(), 1, visitor); System.out.println(visitor.getPathCounters()); System.out.println(visitor.getFileList()); // visitor.getPathCounters().reset(); // // Walk directory tree Files.walkFileTree(dir, visitor); System.out.println(visitor.getPathCounters()); System.out.println(visitor.getDirList()); System.out.println(visitor.getFileList()); ``` -------------------------------- ### getEncoding Source: https://commons.apache.org/proper/commons-io/apidocs/org/apache/commons/io/input/XmlStreamReader.html Gets the charset encoding of the XmlStreamReader. ```APIDOC ## getEncoding ### Description Gets the charset encoding of the `XmlStreamReader`. ### Method `public String getEncoding()` ### Endpoint N/A (Instance method) ### Parameters None ### Returns - **String** - charset encoding. ``` -------------------------------- ### Static Tailer Creation Source: https://commons.apache.org/proper/commons-io/apidocs/src-html/org/apache/commons/io/input/Tailer.html Methods for creating and starting a Tailer instance for a specific file. ```APIDOC ## Static Method: create ### Description Creates and starts a Tailer for the given file. Note that these methods are deprecated in favor of the Builder pattern. ### Parameters - **file** (File) - Required - The file to follow. - **tailerListener** (TailerListener) - Required - The TailerListener to use. - **delayMillis** (long) - Required - The delay between checks of the file for new content in milliseconds. - **end** (boolean) - Required - Set to true to tail from the end of the file, false to tail from the beginning. - **bufferSize** (int) - Required - The buffer size to use. ### Response - **Tailer** - The new tailer instance. ``` -------------------------------- ### getWriter Source: https://commons.apache.org/proper/commons-io/apidocs/org/apache/commons/io/build/AbstractStreamBuilder.html Gets a Writer from the origin with an OpenOption[]. ```APIDOC ### getWriter public Writer getWriter() throws IOException Gets a Writer from the origin with an OpenOption[]. Returns: An writer. Throws: `IllegalStateException` - if the `origin` is `null`. `UnsupportedOperationException` - if the origin cannot be converted to a `Writer`. `IOException` - if an I/O error occurs. Since: 2.13.0 See Also: * `AbstractOrigin.getWriter(OpenOption...)` * `getOpenOptions()` ``` -------------------------------- ### getReader Source: https://commons.apache.org/proper/commons-io/apidocs/org/apache/commons/io/build/AbstractStreamBuilder.html Gets a Reader from the origin with a Charset. ```APIDOC ### getReader public Reader getReader() throws IOException Gets a Reader from the origin with a Charset. Returns: A Reader Throws: `IllegalStateException` - if the `origin` is `null`. `UnsupportedOperationException` - if the origin cannot be converted to a `Reader`. `IOException` - if an I/O error occurs. Since: 2.16.0 See Also: * `AbstractOrigin.getReader(Charset)` * `getCharset()` ```