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.
19 # this module is used by `assets_and_resources` and `audio` for advanced purposes
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;
31 import android.util.Log;
34 extern class NativeFile in "Java" `{ java.io.File `}
36 redef type SELF: NativeFile
38 fun can_execute: Bool in "Java" `{ return recv.canExecute(); `}
39 fun can_read
: Bool in "Java" `{ return recv.canRead(); `}
40 fun can_write: Bool in "Java" `{ return recv.canWrite(); `}
41 fun create_file
: Bool in "Java" `{
43 return recv.createNewFile();
44 }catch(IOException e){
45 Log.e("Can't create file", e.getMessage());
50 fun delete
: Bool in "Java" `{ return recv.delete(); `}
51 fun delete_on_exit in "Java" `{ recv.deleteOnExit(); `}
52 fun exists
: Bool in "Java" `{ return recv.exists(); `}
53 fun absolute_file: NativeFile in "Java" `{ return recv.getAbsoluteFile(); `}
54 fun absolute_path
: JavaString in "Java" `{ return recv.getAbsolutePath(); `}
55 fun canonical_file: NativeFile in "Java" `{
57 return recv
.getCanonicalFile
();
58 }catch
(IOException e
){
59 Log.e
("Can't create file", e
.getMessage
());
64 fun free_space: Int in "Java" `{ return (int)recv.getFreeSpace(); `}
65 fun name
: JavaString in "Java" `{ return recv.getName(); `}
66 fun parent: JavaString in "Java" `{ return recv.getParent(); `}
67 fun parent_file
: NativeFile in "Java" `{ return recv.getParentFile(); `}
68 fun path: JavaString in "Java" `{ return recv.getPath(); `}
69 fun total_space
: Int in "Java" `{ return (int)recv.getTotalSpace(); `}
70 fun usable_space: Int in "Java" `{ return (int)recv.getUsableSpace(); `}
71 fun absolute
: Bool in "Java" `{ return recv.isAbsolute(); `}
72 fun is_directory: Bool in "Java" `{ return recv.isDirectory(); `}
73 fun is_file
: Bool in "Java" `{ return recv.isFile(); `}
74 fun is_hidden: Bool in "Java" `{ return recv.isHidden(); `}
75 fun last_modified
: Int in "Java" `{ return (int)recv.lastModified(); `}
76 fun length: Int in "Java" `{ return (int)recv.length(); `}
77 fun set_readable
(r
: Bool, owner_only
: Bool): Bool in "Java" `{ return recv.setReadable(r, owner_only); `}
78 fun set_writable(w: Bool, owner_only: Bool): Bool in "Java" `{ return recv.setWritable(w, owner_only); `}
81 extern class NativeFileInputStream in "Java" `{ java.io.FileInputStream `}
83 redef type SELF: NativeFileInputStream
85 fun available: Int in "Java" `{
87 return recv
.available
();
88 }catch
(IOException e
){
93 fun close in "Java" `{
96 }catch
(IOException e
){
100 fun read: Int in "Java" `{
103 }catch
(IOException e
){
108 fun skip(byte_count: Int): Int in "Java" `{
110 return (int
)recv
.skip
(byte_count
);
111 }catch
(IOException e
){
118 extern class NativeFileOutputStream in "Java" `{ java.io.FileOutputStream `}
120 redef type SELF: NativeFileOutputStream
122 fun close
in "Java" `{
125 }catch(IOException e){
129 fun write
(one_byte
: Int) in "Java" `{
131 recv.write((byte)one_byte);
132 }catch(IOException e){
136 fun flush
in "Java" `{
139 }catch(IOException e){
145 extern class NativeFileDescriptor in "Java" `{ java.io.FileDescriptor `}
147 redef type SELF: NativeFileDescriptor
148 fun sync in "Java" `{
151 }catch
(SyncFailedException e
){
155 fun valid: Bool in "Java" `{ return recv.valid(); `}
158 extern class NativeInputStream in "Java" `{ java.io.InputStream `}
160 redef type SELF: NativeInputStream
162 fun available: Int in "Java" `{
164 return recv
.available
();
165 }catch
(IOException e
){
171 fun close in "Java" `{
174 }catch
(IOException e
){