@@ -37,7 +37,7 @@ public abstract class GenericFileInputStreamSuite {
3737
3838 protected File inputFile ;
3939
40- protected InputStream inputStream ;
40+ protected InputStream [] inputStreams ;
4141
4242 @ Before
4343 public void setUp () throws IOException {
@@ -54,77 +54,91 @@ public void tearDown() {
5454
5555 @ Test
5656 public void testReadOneByte () throws IOException {
57- for (int i = 0 ; i < randomBytes .length ; i ++) {
58- assertEquals (randomBytes [i ], (byte ) inputStream .read ());
57+ for (InputStream inputStream : inputStreams ) {
58+ for (int i = 0 ; i < randomBytes .length ; i ++) {
59+ assertEquals (randomBytes [i ], (byte ) inputStream .read ());
60+ }
5961 }
6062 }
6163
6264 @ Test
6365 public void testReadMultipleBytes () throws IOException {
64- byte [] readBytes = new byte [8 * 1024 ];
65- int i = 0 ;
66- while (i < randomBytes .length ) {
67- int read = inputStream .read (readBytes , 0 , 8 * 1024 );
68- for (int j = 0 ; j < read ; j ++) {
69- assertEquals (randomBytes [i ], readBytes [j ]);
70- i ++;
66+ for (InputStream inputStream : inputStreams ) {
67+ byte [] readBytes = new byte [8 * 1024 ];
68+ int i = 0 ;
69+ while (i < randomBytes .length ) {
70+ int read = inputStream .read (readBytes , 0 , 8 * 1024 );
71+ for (int j = 0 ; j < read ; j ++) {
72+ assertEquals (randomBytes [i ], readBytes [j ]);
73+ i ++;
74+ }
7175 }
7276 }
7377 }
7478
7579 @ Test
7680 public void testBytesSkipped () throws IOException {
77- assertEquals (1024 , inputStream .skip (1024 ));
78- for (int i = 1024 ; i < randomBytes .length ; i ++) {
79- assertEquals (randomBytes [i ], (byte ) inputStream .read ());
81+ for (InputStream inputStream : inputStreams ) {
82+ assertEquals (1024 , inputStream .skip (1024 ));
83+ for (int i = 1024 ; i < randomBytes .length ; i ++) {
84+ assertEquals (randomBytes [i ], (byte ) inputStream .read ());
85+ }
8086 }
8187 }
8288
8389 @ Test
8490 public void testBytesSkippedAfterRead () throws IOException {
85- for (int i = 0 ; i < 1024 ; i ++) {
86- assertEquals (randomBytes [i ], (byte ) inputStream .read ());
87- }
88- assertEquals (1024 , inputStream .skip (1024 ));
89- for (int i = 2048 ; i < randomBytes .length ; i ++) {
90- assertEquals (randomBytes [i ], (byte ) inputStream .read ());
91+ for (InputStream inputStream : inputStreams ) {
92+ for (int i = 0 ; i < 1024 ; i ++) {
93+ assertEquals (randomBytes [i ], (byte ) inputStream .read ());
94+ }
95+ assertEquals (1024 , inputStream .skip (1024 ));
96+ for (int i = 2048 ; i < randomBytes .length ; i ++) {
97+ assertEquals (randomBytes [i ], (byte ) inputStream .read ());
98+ }
9199 }
92100 }
93101
94102 @ Test
95103 public void testNegativeBytesSkippedAfterRead () throws IOException {
96- for (int i = 0 ; i < 1024 ; i ++) {
97- assertEquals (randomBytes [i ], (byte ) inputStream .read ());
98- }
99- // Skipping negative bytes should essential be a no-op
100- assertEquals (0 , inputStream .skip (-1 ));
101- assertEquals (0 , inputStream .skip (-1024 ));
102- assertEquals (0 , inputStream .skip (Long .MIN_VALUE ));
103- assertEquals (1024 , inputStream .skip (1024 ));
104- for (int i = 2048 ; i < randomBytes .length ; i ++) {
105- assertEquals (randomBytes [i ], (byte ) inputStream .read ());
104+ for (InputStream inputStream : inputStreams ) {
105+ for (int i = 0 ; i < 1024 ; i ++) {
106+ assertEquals (randomBytes [i ], (byte ) inputStream .read ());
107+ }
108+ // Skipping negative bytes should essential be a no-op
109+ assertEquals (0 , inputStream .skip (-1 ));
110+ assertEquals (0 , inputStream .skip (-1024 ));
111+ assertEquals (0 , inputStream .skip (Long .MIN_VALUE ));
112+ assertEquals (1024 , inputStream .skip (1024 ));
113+ for (int i = 2048 ; i < randomBytes .length ; i ++) {
114+ assertEquals (randomBytes [i ], (byte ) inputStream .read ());
115+ }
106116 }
107117 }
108118
109119 @ Test
110120 public void testSkipFromFileChannel () throws IOException {
111- // Since the buffer is smaller than the skipped bytes, this will guarantee
112- // we skip from underlying file channel.
113- assertEquals (1024 , inputStream .skip (1024 ));
114- for (int i = 1024 ; i < 2048 ; i ++) {
115- assertEquals (randomBytes [i ], (byte ) inputStream .read ());
116- }
117- assertEquals (256 , inputStream .skip (256 ));
118- assertEquals (256 , inputStream .skip (256 ));
119- assertEquals (512 , inputStream .skip (512 ));
120- for (int i = 3072 ; i < randomBytes .length ; i ++) {
121- assertEquals (randomBytes [i ], (byte ) inputStream .read ());
121+ for (InputStream inputStream : inputStreams ) {
122+ // Since the buffer is smaller than the skipped bytes, this will guarantee
123+ // we skip from underlying file channel.
124+ assertEquals (1024 , inputStream .skip (1024 ));
125+ for (int i = 1024 ; i < 2048 ; i ++) {
126+ assertEquals (randomBytes [i ], (byte ) inputStream .read ());
127+ }
128+ assertEquals (256 , inputStream .skip (256 ));
129+ assertEquals (256 , inputStream .skip (256 ));
130+ assertEquals (512 , inputStream .skip (512 ));
131+ for (int i = 3072 ; i < randomBytes .length ; i ++) {
132+ assertEquals (randomBytes [i ], (byte ) inputStream .read ());
133+ }
122134 }
123135 }
124136
125137 @ Test
126138 public void testBytesSkippedAfterEOF () throws IOException {
127- assertEquals (randomBytes .length , inputStream .skip (randomBytes .length + 1 ));
128- assertEquals (-1 , inputStream .read ());
139+ for (InputStream inputStream : inputStreams ) {
140+ assertEquals (randomBytes .length , inputStream .skip (randomBytes .length + 1 ));
141+ assertEquals (-1 , inputStream .read ());
142+ }
129143 }
130144}
0 commit comments