Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

32
LINES

< > BotCompany Repo | #1035760 // StringIO - read/writable using a StringHead

JavaX fragment (include) [tags: use-pretranspiled]

Libraryless. Click here for Pure Java version (12843L/74K).

1  
interface StringIO {
2  
  replace SomethingHead with StringHead.
3  
  
4  
  void readWrite(SomethingHead head);
5  
6  
  default S saveToString(SomethingHead head default new) {
7  
    var writer = stringWriter();
8  
    head.writer(writer);
9  
    readWrite(head);
10  
    head.finish();
11  
    ret str(writer);
12  
  }
13  
14  
  default File saveToTextFile(File file) {
15  
    temp Writer out = bufferedFileWriter(file);
16  
    var head = new SomethingHead(out);
17  
    readWrite(head);
18  
    head.finish();
19  
    ret file;
20  
  }
21  
  
22  
  default selfType load aka fromString(S data) {
23  
    readWrite(new SomethingHead(stringReader(data)));
24  
    this;
25  
  }
26  
  
27  
  default selfType loadTextFile(File file) {
28  
    temp var in = bufferedReader(file);
29  
    readWrite(new SomethingHead(in));
30  
    this;
31  
  }
32  
}

Author comment

Began life as a copy of #1035635

download  show line numbers  debug dex  old transpilations   

Travelled to 2 computer(s): elmgxqgtpvxh, mqqgnosmbjvj

No comments. add comment

Snippet ID: #1035760
Snippet name: StringIO - read/writable using a StringHead
Eternal ID of this version: #1035760/6
Text MD5: 095a29694301458fb80437df9af1cca7
Transpilation MD5: 02ed52f23a50ec075834258262a33cd0
Author: stefan
Category: javax / io
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2022-07-20 02:39:27
Source code size: 767 bytes / 32 lines
Pitched / IR pitched: No / No
Views / Downloads: 137 / 227
Version history: 5 change(s)
Referenced in: [show references]