xlang v5.1 Release
程序设计语言基础库文档
载入中...
搜索中...
未找到
FileStream.x
浏览该文件的文档.
1
2@Version(value = "1.0.0.12")
3@SuppressWarnings
4package FileStream {
5//xlang
6 public static class FileInputStream : Stream{
7 long filehandler = -1;
8 public FileInputStream(String path, int mode) throws
11 {
12 if (path == nilptr){
13 throw new NullPointerException("path is nullpointer");
14 }
15 filehandler = _system_.open(path, _system_.READ | mode);
16 if (filehandler == -1){
17 throw new IllegalArgumentException("file " + path + " can not open");
18 }
19 }
20 public FileInputStream(@NotNilptr File file, int mode) throws
23 {
24 String path = file.getPath();
25 if (path == nilptr){
26 throw new NullPointerException("path is nilptr");
27 }
28 filehandler = _system_.open(path, _system_.READ | mode);
29 if (filehandler == -1){
30 throw new IllegalArgumentException("file " + path + " can not open");
31 }
32 }
33 public FileInputStream(String path) throws
36 {
37 if (path == nilptr){
38 throw new NullPointerException("path is nullpointer");
39 }
40 filehandler = _system_.open(path, _system_.READ);
41 if (filehandler == -1){
42 throw new IllegalArgumentException("file " + path + " can not open");
43 }
44 }
45 public FileInputStream(@NotNilptr File file) throws
48 {
49 String path = file.getPath();
50 if (path == nilptr){
51 throw new NullPointerException("path is nilptr");
52 }
53 filehandler = _system_.open(path, _system_.READ);
54 if (filehandler == -1){
55 throw new IllegalArgumentException("file " + path + " can not open");
56 }
57 }
58 public FileInputStream(@NotNilptr File dir,@NotNilptr String file) throws NullPointerException, IllegalArgumentException{
59 String path = dir.getPath();
60 if (path == nilptr){
61 throw new NullPointerException("path is nilptr");
62 }
63 path = path.appendPath(file);
64 filehandler = _system_.open(path, _system_.READ);
65 if (filehandler == -1){
66 throw new IllegalArgumentException("file " + path + " can not open");
67 }
68 }
69 public bool attach(String path) throws IllegalArgumentException{
70 if (filehandler != -1){
71 _system_.close(filehandler);
72 filehandler = -1;
73 }
74 if (path == nilptr){
75 return false;
76 }
77 filehandler = _system_.open(path, _system_.READ);
78 return filehandler != -1;
79 }
80
82 if (filehandler == -1){
83 throw new IllegalArgumentException("The Stream is not ready");
84 }
85 }
86 public long available(bool )override throws IllegalArgumentException{
87 return length() - getPosition();
88 }
89 public long seek(int type, long pos)override throws IllegalArgumentException{
90 checkValid();
91 return _system_.seek(filehandler, type, pos);
92 }
93
94 public long getPosition()override throws IllegalArgumentException{
95 checkValid();
96 return _system_.getSeek(filehandler);
97 }
98
99 public long length()override throws IllegalArgumentException{
100 checkValid();
101 return _system_.getLength(filehandler);
102 }
103
104 public int read(@NotNilptr byte [] data , int position, int length)override throws IllegalArgumentException, IndexOutOfBoundsException{
105 checkValid();
106 return _system_.read(filehandler, data, position, length);
107 }
108
109 public int write(@NotNilptr byte [] , int , int )override{
110 return 0;
111 }
112
113 public void close()override{
114 if (filehandler != -1){
115 _system_.close(filehandler);
116 filehandler = -1;
117 }
118 }
119 void flush()override{
120
121 }
122 void finalize(){
123 close();
124 }
125 };
126
127 public static class FileOutputStream : Stream{
130 if (path == nilptr){
131 throw new NullPointerException("path is nilptr");
132 }
133 filehandler = _system_.open(path, mode);
134 if (filehandler == -1){
135 throw new IllegalArgumentException("file " + path + " can not open");
136 }
137 }
139 if (path == nilptr){
140 throw new NullPointerException("path is nilptr");
141 }
142 filehandler = _system_.open(path, _system_.WRITE | _system_.CREATE | _system_.TRUNC);
143 if (filehandler == -1){
144 throw new IllegalArgumentException("file " + path + " can not open");
145 }
146 }
148 if (path == nilptr){
149 throw new NullPointerException("path is nilptr");
150 }
151 filehandler = _system_.open(path, append ? (_system_.WRITE | _system_.CREATE | _system_.APPEND) : (_system_.WRITE | _system_.CREATE | _system_.TRUNC));
152 if (filehandler == -1){
153 throw new IllegalArgumentException("file " + path + " can not open");
154 }
155 }
156
158 String path = file.getPath();
159 if (path == nilptr){
160 throw new NullPointerException("path is nilptr");
161 }
162 filehandler = _system_.open(path, _system_.WRITE | _system_.CREATE | _system_.TRUNC);
163 if (filehandler == -1){
164 throw new IllegalArgumentException("file " + path + " can not open");
165 }
166 }
167 public FileOutputStream(@NotNilptr File file, int mode) throws NullPointerException, IllegalArgumentException{
168 String path = file.getPath();
169 if (path == nilptr){
170 throw new NullPointerException("path is nilptr");
171 }
172 filehandler = _system_.open(path, mode);
173 if (filehandler == -1){
174 throw new IllegalArgumentException("file " + path + " can not open");
175 }
176 }
177 public FileOutputStream(@NotNilptr File file, bool append)throws NullPointerException, IllegalArgumentException{
178 String path = file.getPath();
179 if (path == nilptr){
180 throw new NullPointerException("path is nilptr");
181 }
182 filehandler = _system_.open(path, append ? (_system_.WRITE | _system_.CREATE | _system_.APPEND) : (_system_.WRITE | _system_.CREATE | _system_.TRUNC));
183 if (filehandler == -1){
184 throw new IllegalArgumentException("file " + path + " can not open");
185 }
186 }
187 public FileOutputStream(@NotNilptr File dir,@NotNilptr String file, bool append)throws NullPointerException, IllegalArgumentException{
188 String path = dir.getPath();
189 if (path == nilptr){
190 throw new NullPointerException("path is nilptr");
191 }
192 path = path.appendPath(file);
193 filehandler = _system_.open(path, append ? (_system_.WRITE | _system_.CREATE | _system_.APPEND) : (_system_.WRITE | _system_.CREATE | _system_.TRUNC));
194 if (filehandler == -1){
195 throw new IllegalArgumentException("file " + path + " can not open");
196 }
197 }
198 public bool attach(String path, bool append)throws NullPointerException, IllegalArgumentException{
199 if (filehandler != -1){
200 _system_.close(filehandler);
201 filehandler = -1;
202 }
203 if (path == nilptr){
204 throw new NullPointerException("path is nilptr");
205 }
206 filehandler = _system_.open(path, append ? (_system_.WRITE | _system_.CREATE | _system_.APPEND) : (_system_.WRITE | _system_.CREATE | _system_.TRUNC));
207 return filehandler != -1;
208 }
210 if (filehandler == -1){
211 throw new IllegalArgumentException("The Stream is not ready");
212 }
213 }
214 public long available(bool )override{
215 return 1;
216 }
217 public long seek(int , long )override{
218 return 0;
219 }
220
221 public long getPosition()override{
222 return 0;
223 }
224
225 public long length()override throws IllegalArgumentException{
226 checkValid();
227 return 0;
228 }
229
230 public int read(@NotNilptr byte [] , int , int )override{
231 return 0;
232 }
233
234 public long write(@NotNilptr byte [] data) throws IndexOutOfBoundsException , IllegalArgumentException{
235 checkValid();
236 return _system_.write(filehandler, data, 0, data.length);
237 }
238
239 public int write(byte [] data , int position, int length)override throws IndexOutOfBoundsException, IllegalArgumentException{
240 checkValid();
241 return _system_.write(filehandler, data, position, length);
242 }
243
244 public void close()override{
245 if (filehandler != -1){
246 _system_.close(filehandler);
247 filehandler = -1;
248 }
249 }
250 void flush()override{
251
252 }
253 void finalize(){
254 close();
255 }
256 };
257};
static final long read(long, byte[], long, long)
static const int CREATE
Definition _system_.x:235
static final long getLength(long)
static const int READ
Definition _system_.x:232
static const int TRUNC
Definition _system_.x:238
static final long open(String, int)
static const int APPEND
Definition _system_.x:239
static final long getSeek(long)
static const int WRITE
Definition _system_.x:233
static final long write(long, byte[], long, long)
static final long seek(long, int, long)
static final bool close(long)
Definition File.x:4
bool attach(String path)
Definition FileStream.x:69
void close() override
Definition FileStream.x:113
int read(@NotNilptr byte [] data , int position, int length) override
Definition FileStream.x:104
FileInputStream(@NotNilptr File file)
Definition FileStream.x:45
FileInputStream(@NotNilptr File file, int mode)
Definition FileStream.x:20
long length() override
Definition FileStream.x:99
FileInputStream(String path, int mode)
Definition FileStream.x:8
FileInputStream(@NotNilptr File dir,@NotNilptr String file)
Definition FileStream.x:58
long getPosition() override
Definition FileStream.x:94
FileInputStream(String path)
Definition FileStream.x:33
long seek(int type, long pos) override
Definition FileStream.x:89
int write(@NotNilptr byte [] , int , int ) override
Definition FileStream.x:109
long available(bool ) override
Definition FileStream.x:86
void flush() override
Definition FileStream.x:119
int write(byte [] data , int position, int length) override
Definition FileStream.x:239
FileOutputStream(@NotNilptr File file, int mode)
Definition FileStream.x:167
void close() override
Definition FileStream.x:244
FileOutputStream(@NotNilptr File dir,@NotNilptr String file, bool append)
Definition FileStream.x:187
long seek(int , long ) override
Definition FileStream.x:217
FileOutputStream(@NotNilptr File file, bool append)
Definition FileStream.x:177
long length() override
Definition FileStream.x:225
int read(@NotNilptr byte [] , int , int ) override
Definition FileStream.x:230
FileOutputStream(@NotNilptr File file)
Definition FileStream.x:157
FileOutputStream(String path, int mode)
Definition FileStream.x:129
long getPosition() override
Definition FileStream.x:221
FileOutputStream(String path, bool append)
Definition FileStream.x:147
long write(@NotNilptr byte [] data)
Definition FileStream.x:234
FileOutputStream(String path)
Definition FileStream.x:138
bool attach(String path, bool append)
Definition FileStream.x:198
long available(bool ) override
Definition FileStream.x:214
void flush() override
Definition FileStream.x:250
Definition Stream.x:6
void close()
Definition String.x:5
String appendPath(String)