@@ -177,77 +177,77 @@ public boolean nextKeyValue() throws IOException {
177
177
vc .set (v );
178
178
return true ;
179
179
}
180
- }
181
-
182
- class BGZFLimitingStream extends InputStream {
183
180
184
- private final BlockCompressedInputStream bgzf ;
185
- private final long virtEnd ;
186
- private byte [] readBuf = new byte [1 ];
187
-
188
- public BGZFLimitingStream (BlockCompressedInputStream stream , long virtualEnd ) {
189
- bgzf = stream ;
190
- virtEnd = virtualEnd ;
191
- }
181
+ static class BGZFLimitingStream extends InputStream {
192
182
193
- @ Override
194
- public void close () throws IOException {
195
- bgzf .close ();
196
- }
183
+ private final BlockCompressedInputStream bgzf ;
184
+ private final long virtEnd ;
185
+ private byte [] readBuf = new byte [1 ];
197
186
198
- @ Override
199
- public int read () throws IOException {
200
- switch (read (readBuf )) {
201
- case 1 :
202
- return readBuf [0 ];
203
- case -1 :
204
- return -1 ;
205
- default :
206
- assert false ;
207
- return -1 ;
187
+ public BGZFLimitingStream (BlockCompressedInputStream stream , long virtualEnd ) {
188
+ bgzf = stream ;
189
+ virtEnd = virtualEnd ;
208
190
}
209
- }
210
191
211
- @ Override
212
- public int read (byte [] buf , int off , int len ) throws IOException {
213
-
214
- int totalRead = 0 ;
215
- long virt ;
216
-
217
- final int lastLen = (int ) virtEnd & 0xffff ;
218
-
219
- while ((virt = bgzf .getFilePointer ()) >>> 16 != virtEnd >>> 16 ) {
220
- // We're not in the last BGZF block yet. Unfortunately
221
- // BlockCompressedInputStream doesn't expose the length of the current
222
- // block, so we can't simply (possibly repeatedly) read the current
223
- // block to the end. Instead, we read at most virtEnd & 0xffff at a
224
- // time, which ensures that we can't overshoot virtEnd even if the
225
- // next block starts immediately.
226
- final int r = bgzf .read (buf , off , Math .min (len , lastLen ));
227
- if (r == -1 ) {
228
- return totalRead == 0 ? -1 : totalRead ;
229
- }
192
+ @ Override
193
+ public void close () throws IOException {
194
+ bgzf .close ();
195
+ }
230
196
231
- totalRead += r ;
232
- len -= r ;
233
- if (len == 0 ) {
234
- return totalRead ;
197
+ @ Override
198
+ public int read () throws IOException {
199
+ switch (read (readBuf )) {
200
+ case 1 :
201
+ return readBuf [0 ];
202
+ case -1 :
203
+ return -1 ;
204
+ default :
205
+ assert false ;
206
+ return -1 ;
235
207
}
236
- off += r ;
237
208
}
238
209
239
- // We're in the last BGZF block: read only up to lastLen.
240
- len = Math .min (len , ((int ) virt & 0xffff ) - lastLen );
241
- while (len > 0 ) {
242
- final int r = bgzf .read (buf , off , len );
243
- if (r == -1 ) {
244
- return totalRead == 0 ? -1 : totalRead ;
210
+ @ Override
211
+ public int read (byte [] buf , int off , int len ) throws IOException {
212
+
213
+ int totalRead = 0 ;
214
+ long virt ;
215
+
216
+ final int lastLen = (int ) virtEnd & 0xffff ;
217
+
218
+ while ((virt = bgzf .getFilePointer ()) >>> 16 != virtEnd >>> 16 ) {
219
+ // We're not in the last BGZF block yet. Unfortunately
220
+ // BlockCompressedInputStream doesn't expose the length of the current
221
+ // block, so we can't simply (possibly repeatedly) read the current
222
+ // block to the end. Instead, we read at most virtEnd & 0xffff at a
223
+ // time, which ensures that we can't overshoot virtEnd even if the
224
+ // next block starts immediately.
225
+ final int r = bgzf .read (buf , off , Math .min (len , lastLen ));
226
+ if (r == -1 ) {
227
+ return totalRead == 0 ? -1 : totalRead ;
228
+ }
229
+
230
+ totalRead += r ;
231
+ len -= r ;
232
+ if (len == 0 ) {
233
+ return totalRead ;
234
+ }
235
+ off += r ;
245
236
}
246
237
247
- totalRead += r ;
248
- len -= r ;
249
- off += r ;
238
+ // We're in the last BGZF block: read only up to lastLen.
239
+ len = Math .min (len , ((int ) virt & 0xffff ) - lastLen );
240
+ while (len > 0 ) {
241
+ final int r = bgzf .read (buf , off , len );
242
+ if (r == -1 ) {
243
+ return totalRead == 0 ? -1 : totalRead ;
244
+ }
245
+
246
+ totalRead += r ;
247
+ len -= r ;
248
+ off += r ;
249
+ }
250
+ return totalRead == 0 ? -1 : totalRead ;
250
251
}
251
- return totalRead == 0 ? -1 : totalRead ;
252
252
}
253
253
}
0 commit comments