xlang v4.0 Release
程序设计语言基础库文档
载入中...
搜索中...
未找到
FileStream.xcs
浏览该文件的文档.
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 public @NotNilptr byte[] read() throws IllegalArgumentException, IndexOutOfBoundsException{
103 checkValid();
104 byte[] data = new byte[length()];
105 _system_.read(filehandler, data, 0, data.length);
106 return data;
107 }
108
109 public int read(@NotNilptr byte [] data , int position, int length)override throws IllegalArgumentException, IndexOutOfBoundsException{
110 checkValid();
111 return _system_.read(filehandler, data, position, length);
112 }
113
114 public int write(@NotNilptr byte [] , int , int )override{
115 return 0;
116 }
117
118 public void close()override{
119 if (filehandler != -1){
120 _system_.close(filehandler);
121 filehandler = -1;
122 }
123 }
124 void flush()override{
125
126 }
127 void finalize(){
128 close();
129 }
130 };
131
132 public static class FileOutputStream : Stream{
133 long filehandler;
135 if (path == nilptr){
136 throw new NullPointerException("path is nilptr");
137 }
138 filehandler = XPlatform.openSystemFile(path, mode);
139 if (filehandler == -1){
140 throw new IllegalArgumentException("file " + path + " can not open");
141 }
142 }
144 if (path == nilptr){
145 throw new NullPointerException("path is nilptr");
146 }
147 filehandler = XPlatform.openSystemFile(path, _system_.WRITE | _system_.CREATE | _system_.TRUNC);
148 if (filehandler == -1){
149 throw new IllegalArgumentException("file " + path + " can not open");
150 }
151 }
153 if (path == nilptr){
154 throw new NullPointerException("path is nilptr");
155 }
156 filehandler = XPlatform.openSystemFile(path, append ? (_system_.CREATE | _system_.APPEND) : (_system_.WRITE | _system_.CREATE | _system_.TRUNC));
157 if (filehandler == -1){
158 throw new IllegalArgumentException("file " + path + " can not open");
159 }
160 }
161
163 String path = file.getPath();
164 if (path == nilptr){
165 throw new NullPointerException("path is nilptr");
166 }
167 filehandler = XPlatform.openSystemFile(path, _system_.WRITE | _system_.CREATE | _system_.TRUNC);
168 if (filehandler == -1){
169 throw new IllegalArgumentException("file " + path + " can not open");
170 }
171 }
172 public FileOutputStream(@NotNilptr File file, int mode) throws NullPointerException, IllegalArgumentException{
173 String path = file.getPath();
174 if (path == nilptr){
175 throw new NullPointerException("path is nilptr");
176 }
177 filehandler = XPlatform.openSystemFile(path, mode);
178 if (filehandler == -1){
179 throw new IllegalArgumentException("file " + path + " can not open");
180 }
181 }
182 public FileOutputStream(@NotNilptr File file, bool append)throws NullPointerException, IllegalArgumentException{
183 String path = file.getPath();
184 if (path == nilptr){
185 throw new NullPointerException("path is nilptr");
186 }
187 filehandler = XPlatform.openSystemFile(path, append ? (_system_.CREATE | _system_.APPEND) : (_system_.WRITE | _system_.CREATE | _system_.TRUNC));
188 if (filehandler == -1){
189 throw new IllegalArgumentException("file " + path + " can not open");
190 }
191 }
192 public FileOutputStream(@NotNilptr File dir,@NotNilptr String file, bool append)throws NullPointerException, IllegalArgumentException{
193 String path = dir.getPath();
194 if (path == nilptr){
195 throw new NullPointerException("path is nilptr");
196 }
197 path = path.appendPath(file);
198 filehandler = XPlatform.openSystemFile(path, append ? (_system_.CREATE | _system_.APPEND) : (_system_.WRITE | _system_.CREATE | _system_.TRUNC));
199 if (filehandler == -1){
200 throw new IllegalArgumentException("file " + path + " can not open");
201 }
202 }
203 public bool attach(String path, bool append)throws NullPointerException, IllegalArgumentException{
204 if (filehandler != -1){
205 _system_.close(filehandler);
206 filehandler = -1;
207 }
208 if (path == nilptr){
209 throw new NullPointerException("path is nilptr");
210 }
211 filehandler = XPlatform.openSystemFile(path, append ? (_system_.CREATE | _system_.APPEND) : (_system_.WRITE | _system_.CREATE | _system_.TRUNC));
212 return filehandler != -1;
213 }
215 if (filehandler == -1){
216 throw new IllegalArgumentException("The Stream is not ready");
217 }
218 }
219 public long available(bool )override{
220 return 1;
221 }
222 public long seek(int , long )override{
223 return 0;
224 }
225
226 public long getPosition()override{
227 return 0;
228 }
229
230 public long length()override throws IllegalArgumentException{
231 checkValid();
232 return 0;
233 }
234
235 public byte[] read(){
236 return nilptr;
237 }
238
239 public int read(@NotNilptr byte [] , int , int )override{
240 return 0;
241 }
242
243 public long write(@NotNilptr byte [] data) throws IndexOutOfBoundsException , IllegalArgumentException{
244 checkValid();
245 return _system_.write(filehandler, data, 0, data.length);
246 }
247
248 public int write(byte [] data , int position, int length)override throws IndexOutOfBoundsException, IllegalArgumentException{
249 checkValid();
250 return _system_.write(filehandler, data, position, length);
251 }
252
253 public void close()override{
254 if (filehandler != -1){
255 _system_.close(filehandler);
256 filehandler = -1;
257 }
258 }
259 void flush()override{
260
261 }
262 void finalize(){
263 close();
264 }
265 };
266};
系统和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)
int read(@NotNilptr byte [] data , int position, int length) override
FileInputStream(@NotNilptr File file)
FileInputStream(@NotNilptr File file, int mode)
long length() override
FileInputStream(String path, int mode)
Definition FileStream.xcs:6
FileInputStream(@NotNilptr File dir,@NotNilptr String file)
long getPosition() override
long seek(int type, long pos) override
int write(@NotNilptr byte [] , int , int ) override
long available(bool ) override
int write(byte [] data , int position, int length) override
FileOutputStream(@NotNilptr File file, int mode)
FileOutputStream(@NotNilptr File dir,@NotNilptr String file, bool append)
long seek(int , long ) override
FileOutputStream(@NotNilptr File file, bool append)
int read(@NotNilptr byte [] , int , int ) override
FileOutputStream(@NotNilptr File file)
FileOutputStream(String path, int mode)
long getPosition() override
FileOutputStream(String path, bool append)
long write(@NotNilptr byte [] data)
bool attach(String path, bool append)
long available(bool ) override
流接口
void close()
字符串类
String appendPath(String)