 |
- Author:
- kris (IP: 17.228.23.90)
- Timestamp:
- 05/08/09 21:42:19 (4 years ago)
- Comment:
reflects recent IO updates
Legend:
- Unmodified
- Added
- Removed
- Modified
-
ChapterIoStreams
| v2 |
v3 |
|
| 3 | 3 | = Streams = |
|---|
| 4 | 4 | |
|---|
| 5 | | == !BufferedStream == |
|---|
| | 5 | == Buffered == |
|---|
| 6 | 6 | |
|---|
| 7 | 7 | Buffers the flow of data from a upstream input. A downstream |
|---|
| 15 | 15 | neighbour can locate and use this buffer instead of creating another instance of their own. |
|---|
| 16 | 16 | |
|---|
| 17 | | == !DataFileStream == |
|---|
| | 17 | == !DataFile == |
|---|
| 18 | 18 | !DataFileInput, !DataFileOutput composes a seekable file with buffer. A seek causes |
|---|
| 19 | 19 | the buffer to be cleared or flushed. |
|---|
| 20 | 20 | |
|---|
| 21 | | == !DataStream == |
|---|
| | 21 | == Data == |
|---|
| 22 | 22 | !DataInput[[br]] |
|---|
| 23 | 23 | A simple way to read binary data from an arbitrary !InputStream, such as a file: |
|---|
| 24 | 24 | {{{ |
|---|
| 25 | 25 | #!d |
|---|
| 26 | | auto input = new DataInput (new FileInput("path")); |
|---|
| 27 | | auto x = input.readInt; |
|---|
| 28 | | auto y = input.readDouble; |
|---|
| 29 | | input.read (new char[10]); |
|---|
| | 26 | auto input = new DataInput (new File("path")); |
|---|
| | 27 | auto x = input.int32; |
|---|
| | 28 | auto y = input.float64; |
|---|
| | 29 | input.array (new char[10]); |
|---|
| 30 | 30 | input.close; |
|---|
| 31 | 31 | }}} |
|---|
| 35 | 35 | {{{ |
|---|
| 36 | 36 | #!d |
|---|
| 37 | | auto output = new DataOutput (new FileOutput("path")); |
|---|
| 38 | | output.writeInt (1024); |
|---|
| 39 | | output.writeDouble (3.14159); |
|---|
| 40 | | output.write ("hello world"); |
|---|
| | 37 | auto output = new DataOutput (new File("path", File.WriteCreate)); |
|---|
| | 38 | output.int32 (1024); |
|---|
| | 39 | output.float64 (3.14159); |
|---|
| | 40 | output.array ("hello world"); |
|---|
| 41 | 41 | output.flush.close; |
|---|
| 42 | 42 | }}} |
|---|
| 43 | 43 | |
|---|
| 44 | | == !DigestStream == |
|---|
| | 44 | == Digest == |
|---|
| 45 | 45 | !DigestInput[[br]] |
|---|
| 46 | 46 | Inject a digest filter into an input stream, updating the digest as information flows through it |
|---|
| 51 | 51 | {{{ |
|---|
| 52 | 52 | #!d |
|---|
| 53 | | auto output = new DigestOutput(new FileOutput("output"), new Md5); |
|---|
| | 53 | auto output = new DigestOutput(new File("output", File.WriteCreate), new Md5); |
|---|
| 54 | 54 | output.copy (new FileInput("input")); |
|---|
| 55 | 55 | |
|---|
| 57 | 57 | }}} |
|---|
| 58 | 58 | |
|---|
| 59 | | == !EndianessStream == |
|---|
| | 59 | == Endian == |
|---|
| 60 | 60 | |
|---|
| 61 | 61 | Streams for swapping endian-order. The stream is treated as a set |
|---|
| 64 | 64 | !EndianInput and !EndianOutput |
|---|
| 65 | 65 | |
|---|
| 66 | | == !FileStream == |
|---|
| | 66 | == Format == |
|---|
| 67 | 67 | |
|---|
| 68 | | Trivial wrapper around a !FileConduit |
|---|
| 69 | | |
|---|
| 70 | | !FileInput and !FileOutput |
|---|
| 71 | | |
|---|
| 72 | | == !FormatStream == |
|---|
| 73 | | |
|---|
| 74 | | Simple way to hook up a utf8 formatter to an arbitrary !OutputStream, |
|---|
| | 68 | Simple way to hook up a text formatter to an arbitrary !OutputStream, |
|---|
| 75 | 69 | such as a file: |
|---|
| 76 | 70 | |
|---|
| 77 | 71 | {{{ |
|---|
| 78 | 72 | #!d |
|---|
| 79 | | auto output = new FormatOutput (new FileOutput("path")); |
|---|
| | 73 | auto output = new FormatOutput!(char) (new File("path", File.WriteCreate)); |
|---|
| 80 | 74 | output.formatln ("{} green bottles", 10); |
|---|
| 81 | | output.close; |
|---|
| | 75 | output.flush.close; |
|---|
| 82 | 76 | }}} |
|---|
| 83 | 77 | |
|---|
| 84 | | This is a trivial wrapper around the Print class, and is limited |
|---|
| 85 | | to emitting utf8 output. Use the Print class directly in order to |
|---|
| 86 | | generate utf16/32 output instead. |
|---|
| 87 | | |
|---|
| 88 | | Note that this class is a true instance of !OutputStream, by way of |
|---|
| 89 | | inheritance via the Print superclass. |
|---|
| 90 | | |
|---|
| 91 | | == !GreedyStream == |
|---|
| | 78 | == Greedy == |
|---|
| 92 | 79 | |
|---|
| 93 | 80 | !GreedyOutput[[br]] |
|---|
| 97 | 84 | A conduit filter that ensures its input is read in full |
|---|
| 98 | 85 | |
|---|
| 99 | | == !LineStream == |
|---|
| | 86 | == Lines == |
|---|
| 100 | 87 | |
|---|
| 101 | 88 | !LineInput[[br]] |
|---|
| 104 | 91 | {{{ |
|---|
| 105 | 92 | #!d |
|---|
| 106 | | auto input = new LineInput (new FileInput("path")); |
|---|
| | 93 | auto input = new LineInput (new File("path")); |
|---|
| 107 | 94 | foreach (line; input) |
|---|
| 108 | 95 | ... |
|---|
| 110 | 97 | }}} |
|---|
| 111 | 98 | |
|---|
| 112 | | Note that this is just a simple wrapper around !LineIterator, and |
|---|
| 113 | | supports utf8 lines only. Use !LineIterator directly for utf16/32 |
|---|
| 114 | | support, or use the other tango.text.stream classes directly for |
|---|
| 115 | | other tokenizing needs. |
|---|
| 116 | | |
|---|
| 117 | | Note that this class is a true instance of !InputStream, by way of |
|---|
| 118 | | inheritance via the Iterator superclass. |
|---|
| 119 | | |
|---|
| 120 | | == !MapStream == |
|---|
| | 99 | == Map == |
|---|
| 121 | 100 | |
|---|
| 122 | 101 | !MapInput!(T) |
|---|
| 130 | 109 | |
|---|
| 131 | 110 | |
|---|
| 132 | | == !SnoopStream == |
|---|
| | 111 | == Snoop == |
|---|
| 133 | 112 | |
|---|
| 134 | 113 | !SnoopInput, !SnoopOutput |
|---|
| 135 | 114 | Streams to expose call behaviour. By default, activity trace is sent to Cerr. |
|---|
| 136 | 115 | |
|---|
| 137 | | This is usefull for logging/debugging the stream calls. |
|---|
| | 116 | This is useful for logging/debugging the stream calls. |
|---|
| 138 | 117 | |
|---|
| 139 | | == !TextFileStream == |
|---|
| | 118 | == !TextFile == |
|---|
| 140 | 119 | |
|---|
| 141 | 120 | !TextFileInput and !TextFileOutput[[br]] |
|---|
| 142 | 121 | Composes a file with line-oriented input |
|---|
| 143 | 122 | |
|---|
| 144 | | == !TypedStream == |
|---|
| | 123 | == Typed == |
|---|
| 145 | 124 | |
|---|
| 146 | 125 | !TypedInput!(T) and !TypedOutput!(T)[[br]] |
|
 |
 |
|
 |
Copyright © 2006-2013 Tango. All Rights Reserved. | Page Width:
Static or
Dynamic