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