Libraryless. Click here for Pure Java version (12408L/70K).
1 | sS limitedStruct(int limit, O o) { |
2 | var baos = new ByteArrayOutputStream(); |
3 | var out = new LimitedOutputStream(baos, limit); |
4 | var writer = printWriter(out); |
5 | |
6 | embedded void failMe() { |
7 | fail("Struct exceeds limit of " + n2(limit) + " bytes: " + shorten(fromUtf8(baos.toByteArray()), limit)); |
8 | } |
9 | |
10 | try { |
11 | structureToPrintWriter(o, writer); |
12 | } catch e { |
13 | writer.close(); |
14 | failMe(); |
15 | } |
16 | writer.close(); |
17 | S struct = fromUtf8(baos.toByteArray()); |
18 | if (l(struct) > limit) |
19 | failMe(); |
20 | ret struct; |
21 | } |
download show line numbers debug dex old transpilations
Travelled to 2 computer(s): mqqgnosmbjvj, wnsclhtenguj
No comments. add comment
Snippet ID: | #1036593 |
Snippet name: | limitedStruct - struct() but limited to a certain number of bytes |
Eternal ID of this version: | #1036593/7 |
Text MD5: | b1467923e855f5eb359d73490e2c5030 |
Transpilation MD5: | 0828e72e8c63b2ef9b890e165c8476a4 |
Author: | stefan |
Category: | javax |
Type: | JavaX fragment (include) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2023-04-02 20:18:13 |
Source code size: | 541 bytes / 21 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 158 / 234 |
Version history: | 6 change(s) |
Referenced in: | [show references] |