1 | void readWrite(SomethingHead head); |
2 | |
3 | default byte[] saveToByteArray aka saveAsByteArray aka toByteArray(SomethingHead head default new) { |
4 | var baos = byteArrayOutputStream(); |
5 | head.outputStream(baos); |
6 | readWrite(head); |
7 | head.finish(); |
8 | ret baos.toByteArray(); |
9 | } |
10 | |
11 | default S toHexString() { |
12 | ret main toHexString(toByteArray()); |
13 | } |
14 | |
15 | default File saveToFile(File file) { |
16 | temp OutputStream out = bufferedFileOutputStream(file); |
17 | var head = new SomethingHead(out); |
18 | readWrite(head); |
19 | head.finish(); |
20 | ret file; |
21 | } |
22 | |
23 | default selfType load aka fromByteArray(byte[] data) { |
24 | readWrite(new SomethingHead(new ByteArrayInputStream(data))); |
25 | this; |
26 | } |
27 | |
28 | default selfType load(File file) { |
29 | temp InputStream in = bufferedInputStream(file); |
30 | readWrite(new SomethingHead(in)); |
31 | this; |
32 | } |
33 | |
34 | default long byteIOLength() { |
35 | new JustCountingOutputStream out; |
36 | var head = new SomethingHead(out); |
37 | readWrite(head); |
38 | head.finish(); |
39 | ret out!; |
40 | } |
Began life as a copy of #1035635
download show line numbers debug dex old transpilations
Travelled to 4 computer(s): elmgxqgtpvxh, mowyntqkapby, mqqgnosmbjvj, wnsclhtenguj
No comments. add comment
Snippet ID: | #1035662 |
Snippet name: | ByteIO/BitIO helpers |
Eternal ID of this version: | #1035662/12 |
Text MD5: | 1142e628a93e8d78c8b267f0fda4affb |
Author: | stefan |
Category: | javax / io |
Type: | JavaX (incomplete) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2022-08-07 00:12:55 |
Source code size: | 975 bytes / 40 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 168 / 293 |
Version history: | 11 change(s) |
Referenced in: | [show references] |