Commit 54eb4dc
committed
feat: merge two input files into one using SequenceInputStream with character transformation
Overview
Introduced SCIO2 program to demonstrate the use of SequenceInputStream in Java for concatenating the content of multiple input streams.
The program reads from two source files (Source1.txt and Source3.txt) and writes the combined content into a destination file (Destination.txt).
While copying, it applies a simple transformation by converting uppercase letters to lowercase.
Implementation Details
Two input streams are created using FileInputStream, one for each source file.
A SequenceInputStream is then created to logically concatenate these two input streams, allowing sequential reading as if they were a single continuous stream.
An output stream (FileOutputStream) is opened for writing to Destination.txt.
The program reads one byte at a time from the sequence input stream. The loop continues until read() returns -1, which indicates that the end of both input files has been reached.
During processing, the program checks each byte. If the byte represents an ASCII value between 65 and 120, it adds 32 to convert uppercase alphabetic characters into lowercase. Otherwise, the byte is written as is.
The output stream writes the processed characters directly into the destination file.
All streams are explicitly closed at the end of execution to ensure proper release of resources.
Key Learning Points
Demonstrates the use of SequenceInputStream to merge multiple input streams into one logical sequence.
Shows how data can be transformed during the streaming process rather than after reading everything.
Highlights byte-level manipulation using ASCII values for uppercase-to-lowercase conversion.
Reinforces the importance of resource management by closing input and output streams.
Illustrates how sequential file content merging can be achieved with minimal code using Java I/O.
Signed-off-by: https://github.com/Someshdiwan <[email protected]>1 parent 9a63eb1 commit 54eb4dc
File tree
1 file changed
+23
-38
lines changed- Section24JavaGenerics/src/BoundedTypesinInterfaces
1 file changed
+23
-38
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
| 3 | + | |
| 4 | + | |
4 | 5 | | |
5 | 6 | | |
6 | | - | |
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
11 | | - | |
12 | | - | |
13 | | - | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
17 | | - | |
18 | 17 | | |
19 | 18 | | |
20 | 19 | | |
21 | | - | |
22 | 20 | | |
23 | 21 | | |
24 | 22 | | |
| |||
27 | 25 | | |
28 | 26 | | |
29 | 27 | | |
30 | | - | |
31 | 28 | | |
32 | 29 | | |
33 | 30 | | |
| |||
38 | 35 | | |
39 | 36 | | |
40 | 37 | | |
41 | | - | |
42 | 38 | | |
43 | 39 | | |
44 | 40 | | |
45 | | - | |
46 | | - | |
| 41 | + | |
47 | 42 | | |
48 | 43 | | |
49 | 44 | | |
50 | | - | |
51 | 45 | | |
52 | | - | |
53 | | - | |
| 46 | + | |
| 47 | + | |
54 | 48 | | |
55 | 49 | | |
56 | 50 | | |
57 | | - | |
| 51 | + | |
58 | 52 | | |
59 | 53 | | |
60 | 54 | | |
| |||
66 | 60 | | |
67 | 61 | | |
68 | 62 | | |
69 | | - | |
70 | 63 | | |
71 | 64 | | |
72 | 65 | | |
| |||
75 | 68 | | |
76 | 69 | | |
77 | 70 | | |
78 | | - | |
79 | 71 | | |
80 | 72 | | |
81 | | - | |
82 | | - | |
| 73 | + | |
83 | 74 | | |
84 | 75 | | |
85 | 76 | | |
86 | 77 | | |
87 | | - | |
| 78 | + | |
88 | 79 | | |
89 | | - | |
90 | | - | |
91 | | - | |
92 | | - | |
93 | | - | |
94 | | - | |
95 | | - | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
96 | 87 | | |
97 | 88 | | |
98 | 89 | | |
| |||
117 | 108 | | |
118 | 109 | | |
119 | 110 | | |
120 | | - | |
121 | 111 | | |
122 | 112 | | |
123 | 113 | | |
124 | 114 | | |
125 | 115 | | |
126 | | - | |
127 | 116 | | |
| 117 | + | |
| 118 | + | |
128 | 119 | | |
129 | | - | |
130 | | - | |
131 | | - | |
132 | | - | |
133 | | - | |
| 120 | + | |
134 | 121 | | |
135 | 122 | | |
136 | 123 | | |
137 | 124 | | |
138 | | - | |
139 | | - | |
140 | | - | |
141 | | - | |
| 125 | + | |
| 126 | + | |
0 commit comments