1 # This file is part of NIT ( http://www.nitlanguage.org ).
3 # Copyright 2014 Romain Chanoir <romain.chanoir@viacesi.fr>
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
9 # http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
17 # Services from the `java.io` package
19 # This module is used by `android::assets_and_resources` and `android::audio`.
26 import java.io.FileInputStream;
27 import java.io.FileOutputStream;
28 import java.io.FileDescriptor;
29 import java.io.IOException;
30 import java.io.SyncFailedException;
33 extern class NativeFile in "Java" `{ java.io.File `}
35 redef type SELF: NativeFile
37 fun can_execute: Bool in "Java" `{ return recv.canExecute(); `}
38 fun can_read
: Bool in "Java" `{ return recv.canRead(); `}
39 fun can_write: Bool in "Java" `{ return recv.canWrite(); `}
40 fun create_file
: Bool in "Java" `{
42 return recv.createNewFile();
43 }catch(IOException e){
48 fun delete
: Bool in "Java" `{ return recv.delete(); `}
49 fun delete_on_exit in "Java" `{ recv.deleteOnExit(); `}
50 fun exists
: Bool in "Java" `{ return recv.exists(); `}
51 fun absolute_file: NativeFile in "Java" `{ return recv.getAbsoluteFile(); `}
52 fun absolute_path
: JavaString in "Java" `{ return recv.getAbsolutePath(); `}
53 fun canonical_file: NativeFile in "Java" `{
55 return recv
.getCanonicalFile
();
56 }catch
(IOException e
){
61 fun free_space: Int in "Java" `{ return (int)recv.getFreeSpace(); `}
62 fun name
: JavaString in "Java" `{ return recv.getName(); `}
63 fun parent: JavaString in "Java" `{ return recv.getParent(); `}
64 fun parent_file
: NativeFile in "Java" `{ return recv.getParentFile(); `}
65 fun path: JavaString in "Java" `{ return recv.getPath(); `}
66 fun total_space
: Int in "Java" `{ return (int)recv.getTotalSpace(); `}
67 fun usable_space: Int in "Java" `{ return (int)recv.getUsableSpace(); `}
68 fun absolute
: Bool in "Java" `{ return recv.isAbsolute(); `}
69 fun is_directory: Bool in "Java" `{ return recv.isDirectory(); `}
70 fun is_file
: Bool in "Java" `{ return recv.isFile(); `}
71 fun is_hidden: Bool in "Java" `{ return recv.isHidden(); `}
72 fun last_modified
: Int in "Java" `{ return (int)recv.lastModified(); `}
73 fun length: Int in "Java" `{ return (int)recv.length(); `}
74 fun set_readable
(r
: Bool, owner_only
: Bool): Bool in "Java" `{ return recv.setReadable(r, owner_only); `}
75 fun set_writable(w: Bool, owner_only: Bool): Bool in "Java" `{ return recv.setWritable(w, owner_only); `}
78 extern class NativeFileInputStream in "Java" `{ java.io.FileInputStream `}
80 redef type SELF: NativeFileInputStream
82 fun available: Int in "Java" `{
84 return recv
.available
();
85 }catch
(IOException e
){
90 fun close in "Java" `{
93 }catch
(IOException e
){
97 fun read: Int in "Java" `{
100 }catch
(IOException e
){
105 fun skip(byte_count: Int): Int in "Java" `{
107 return (int
)recv
.skip
(byte_count
);
108 }catch
(IOException e
){
115 extern class NativeFileOutputStream in "Java" `{ java.io.FileOutputStream `}
117 redef type SELF: NativeFileOutputStream
119 fun close
in "Java" `{
122 }catch(IOException e){
126 fun write
(one_byte
: Int) in "Java" `{
128 recv.write((byte)one_byte);
129 }catch(IOException e){
133 fun flush
in "Java" `{
136 }catch(IOException e){
142 extern class NativeFileDescriptor in "Java" `{ java.io.FileDescriptor `}
144 redef type SELF: NativeFileDescriptor
145 fun sync in "Java" `{
148 }catch
(SyncFailedException e
){
152 fun valid: Bool in "Java" `{ return recv.valid(); `}
155 extern class NativeInputStream in "Java" `{ java.io.InputStream `}
157 redef type SELF: NativeInputStream
159 fun available: Int in "Java" `{
161 return recv
.available
();
162 }catch
(IOException e
){
168 fun close in "Java" `{
171 }catch
(IOException e
){