Libraryless. Click here for Pure Java version (100L/1K).
1 | sclass CountingInputStream extends FilterInputStream { |
2 | long counter; |
3 | |
4 | *(InputStream in) { super(in); } |
5 | |
6 | @Override |
7 | public int read() throws IOException { |
8 | int c = in.read(); |
9 | if (c >= 0) ++counter; |
10 | ret c; |
11 | } |
12 | |
13 | @Override |
14 | public int read(byte[] b) throws IOException { |
15 | int n = in.read(b); |
16 | counter += max(n, 0); |
17 | ret n; |
18 | } |
19 | |
20 | @Override |
21 | public int read(byte[] b, int off, int len) throws IOException { |
22 | int n = in.read(b, off, len); |
23 | counter += max(n, 0); |
24 | ret n; |
25 | } |
26 | |
27 | long getFilePointer() { ret counter; } |
28 | } |
Began life as a copy of #1029366
download show line numbers debug dex old transpilations
Travelled to 7 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt, xrpafgyirdlv
No comments. add comment
Snippet ID: | #1029436 |
Snippet name: | CountingInputStream |
Eternal ID of this version: | #1029436/2 |
Text MD5: | dfb56a3d1ed855c2ca78fd52a9c10940 |
Transpilation MD5: | c61cfd02360a3e90dff274dbb4e34a5e |
Author: | stefan |
Category: | javax |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2020-08-06 12:39:34 |
Source code size: | 584 bytes / 28 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 219 / 495 |
Version history: | 1 change(s) |
Referenced in: | [show references] |