Commit 819411e
committed
feat: merge multiple files using SequenceInputStream and transform character data
WHAT:
- Implemented SCIO2 class to demonstrate the use of `SequenceInputStream`.
- Combined data from two input files (`Source1.txt` and `Source3.txt`) into a single destination file.
- Applied transformation to convert certain characters (A–Z, a–x) by shifting ASCII values.
HOW:
1. Opened two `FileInputStream` objects for the source files.
2. Used `SequenceInputStream(fis, fis2)` to create a continuous input stream
that reads from the first file until EOF, then continues from the second file.
3. Read byte by byte (`sis.read()`), writing results into `Destination.txt`.
4. Transformation applied:
- If byte value is between 65 and 120 (inclusive), write `(b + 32)`.
- Else, write the byte unchanged.
5. Closed all streams to release system resources.
WHY:
- `SequenceInputStream` allows seamless concatenation of multiple input streams.
- This is useful when combining or merging files, such as concatenating logs,
combining chunks of data, or merging text segments.
- Demonstrates applying processing logic (case conversion / transformation) during file merging.
REAL-WORLD APPLICATIONS:
- Merging multiple small text or log files into a single output file.
- Preprocessing combined data with transformations (e.g., case conversion, encryption).
- Handling large file chunks sequentially when stored across different files.
NOTES:
- Transformation logic `(b + 32)` does not strictly map uppercase letters to lowercase
(since ASCII uppercase A–Z is 65–90 and lowercase is 97–122).
A more accurate transformation would use `Character.toLowerCase((char) b)`.
- Consider using `try-with-resources` for safer resource handling.
- For merging more than two files, `SequenceInputStream` can also take an `Enumeration<InputStream>`.
Signed-off-by: https://github.com/Someshdiwan <[email protected]>1 parent 89fee36 commit 819411e
File tree
2 files changed
+41
-10
lines changed- Section23JavaIOStreams/src
- MyJAVA
2 files changed
+41
-10
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | | - | |
8 | | - | |
| 7 | + | |
| 8 | + | |
9 | 9 | | |
10 | | - | |
11 | | - | |
| 10 | + | |
| 11 | + | |
12 | 12 | | |
13 | 13 | | |
14 | | - | |
15 | | - | |
16 | | - | |
| 14 | + | |
| 15 | + | |
17 | 16 | | |
18 | | - | |
| 17 | + | |
19 | 18 | | |
20 | 19 | | |
21 | 20 | | |
22 | 21 | | |
23 | 22 | | |
24 | | - | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
0 commit comments