132
|
1 /*******************************************************************************
|
|
2
|
|
3 copyright: Copyright (c) 2007 Kris Bell. All rights reserved
|
|
4
|
|
5 license: BSD style: $(LICENSE)
|
|
6
|
|
7 version: Initial release: Nov 2007
|
|
8
|
|
9 author: Kris
|
|
10
|
|
11 *******************************************************************************/
|
|
12
|
|
13 module tango.io.stream.DataFileStream;
|
|
14
|
|
15 private import tango.io.FileConduit;
|
|
16
|
|
17 private import tango.io.stream.DataStream;
|
|
18
|
|
19 /*******************************************************************************
|
|
20
|
|
21 Composes a seekable file with buffered binary input. A seek causes
|
|
22 the input buffer to be cleared
|
|
23
|
|
24 *******************************************************************************/
|
|
25
|
|
26 class DataFileInput : DataInput
|
|
27 {
|
|
28 private FileConduit conduit;
|
|
29
|
|
30 /***********************************************************************
|
|
31
|
|
32 Wrap a FileConduit instance
|
|
33
|
|
34 ***********************************************************************/
|
|
35
|
|
36 this (FileConduit file, uint buffer=uint.max)
|
|
37 {
|
|
38 super (conduit = file, buffer);
|
|
39 }
|
|
40
|
|
41 /***********************************************************************
|
|
42
|
|
43 Set the file seek position to the specified offset, and
|
|
44 clear the input buffer
|
|
45
|
|
46 ***********************************************************************/
|
|
47
|
|
48 final long seek (long offset)
|
|
49 {
|
|
50 host.clear;
|
|
51 return conduit.seek (offset);
|
|
52 }
|
|
53
|
|
54 /***********************************************************************
|
|
55
|
|
56 Return the underlying conduit
|
|
57
|
|
58 ***********************************************************************/
|
|
59
|
|
60 final FileConduit file ()
|
|
61 {
|
|
62 return conduit;
|
|
63 }
|
|
64 }
|
|
65
|
|
66
|
|
67 /*******************************************************************************
|
|
68
|
|
69 Composes a seekable file with buffered binary output. A seek causes
|
|
70 the output buffer to be flushed first
|
|
71
|
|
72 *******************************************************************************/
|
|
73
|
|
74 class DataFileOutput : DataOutput
|
|
75 {
|
|
76 private FileConduit conduit;
|
|
77
|
|
78 /***********************************************************************
|
|
79
|
|
80 Wrap a FileConduit instance
|
|
81
|
|
82 ***********************************************************************/
|
|
83
|
|
84 this (FileConduit file, uint buffer=uint.max)
|
|
85 {
|
|
86 super (conduit = file, buffer);
|
|
87 }
|
|
88
|
|
89 /***********************************************************************
|
|
90
|
|
91 Set the file seek position to the specified offset, after
|
|
92 flushing the output buffer
|
|
93
|
|
94 ***********************************************************************/
|
|
95
|
|
96 final long seek (long offset)
|
|
97 {
|
|
98 host.flush;
|
|
99 return conduit.seek (offset);
|
|
100 }
|
|
101
|
|
102 /***********************************************************************
|
|
103
|
|
104 Return the underlying conduit
|
|
105
|
|
106 ***********************************************************************/
|
|
107
|
|
108 final FileConduit file ()
|
|
109 {
|
|
110 return conduit;
|
|
111 }
|
|
112 }
|
|
113
|
|
114
|
|
115 /*******************************************************************************
|
|
116
|
|
117 *******************************************************************************/
|
|
118
|
|
119 debug (UnitTest)
|
|
120 {
|
|
121 }
|