Commit 04247ce
committed
feat: add CharArrayReader example to read characters from array.
WHAT:
- Implemented `CharArrayReaderExample` demonstrating the use of `CharArrayReader`.
- Created a character array containing the English alphabet (a–z).
- Used `CharArrayReader` to sequentially read characters from the array.
- Printed each character to the console until end-of-stream (-1) was reached.
WHY:
- `CharArrayReader` is a specialized character stream in Java that allows
treating a character array as a source of input (like a file or network stream).
- Useful for testing, prototyping, or processing text data without needing
actual I/O resources.
HOW:
1. Defined a `char[]` array with values 'a' through 'z'.
2. Initialized `CharArrayReader` with the array, making it behave like a reader stream.
3. Invoked `read()` in a loop until `-1` (EOF) was returned.
4. Printed characters to verify proper reading.
REAL-WORLD USE CASES:
- Simulating file or network input when working with in-memory character data.
- Parsing strings or character arrays using APIs that expect a `Reader`.
- Testing algorithms that work on `Reader` streams without needing files.
- Useful in scenarios like templating engines or XML/JSON parsers where
in-memory text is processed as if it were a stream.
NOTES:
- Unlike `FileReader`, `CharArrayReader` does not involve any disk I/O.
- Supports `mark()` and `reset()` operations, allowing re-reading of sections.
- Often paired with `CharArrayWriter` when both reading and writing
in-memory character data is required.
Signed-off-by: https://github.com/Someshdiwan <[email protected]>1 parent 7ff578c commit 04247ce
1 file changed
+28
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
11 | | - | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
0 commit comments