niti: fix type in tool description
[nit.git] / lib / android / java_io.nit
1 # this file is part of NIT ( http://www.nitlanguage.org ).
2 #
3 # Copyright 2014 Romain Chanoir <romain.chanoir@viacesi.fr>
4 #
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
8 #
9 # http://www.apache.org/licenses/LICENSE-2.0
10 #
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.
16
17 # java io services
18 #
19 # this module is used by `assets_and_resources` and `audio` for advanced purposes
20 module java_io
21
22 import java
23
24 in "Java" `{
25 import java.io.File;
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;
32 `}
33
34 extern class NativeFile in "Java" `{ java.io.File `}
35 super JavaObject
36 redef type SELF: NativeFile
37
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" `{
42 try {
43 return recv.createNewFile();
44 }catch(IOException e){
45 Log.e("Can't create file", e.getMessage());
46 e.printStackTrace();
47 return false;
48 }
49 `}
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" `{
56 try {
57 return recv.getCanonicalFile();
58 }catch(IOException e){
59 Log.e("Can't create file", e.getMessage());
60 e.printStackTrace();
61 return null;
62 }
63 `}
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); `}
79 end
80
81 extern class NativeFileInputStream in "Java" `{ java.io.FileInputStream `}
82 super JavaObject
83 redef type SELF: NativeFileInputStream
84
85 fun available: Int in "Java" `{
86 try {
87 return recv.available();
88 }catch(IOException e){
89 e.printStackTrace();
90 return -1;
91 }
92 `}
93 fun close in "Java" `{
94 try {
95 recv.close();
96 }catch(IOException e){
97 e.printStackTrace();
98 }
99 `}
100 fun read: Int in "Java" `{
101 try {
102 return recv.read();
103 }catch(IOException e){
104 e.printStackTrace();
105 return -1;
106 }
107 `}
108 fun skip(byte_count: Int): Int in "Java" `{
109 try {
110 return (int)recv.skip(byte_count);
111 }catch(IOException e){
112 e.printStackTrace();
113 return -1;
114 }
115 `}
116 end
117
118 extern class NativeFileOutputStream in "Java" `{ java.io.FileOutputStream `}
119 super JavaObject
120 redef type SELF: NativeFileOutputStream
121
122 fun close in "Java" `{
123 try {
124 recv.close();
125 }catch(IOException e){
126 e.printStackTrace();
127 }
128 `}
129 fun write(one_byte: Int) in "Java" `{
130 try {
131 recv.write((byte)one_byte);
132 }catch(IOException e){
133 e.printStackTrace();
134 }
135 `}
136 fun flush in "Java" `{
137 try {
138 recv.flush();
139 }catch(IOException e){
140 e.printStackTrace();
141 }
142 `}
143 end
144
145 extern class NativeFileDescriptor in "Java" `{ java.io.FileDescriptor `}
146 super JavaObject
147 redef type SELF: NativeFileDescriptor
148 fun sync in "Java" `{
149 try{
150 recv.sync();
151 }catch(SyncFailedException e){
152 e.printStackTrace();
153 }
154 `}
155 fun valid: Bool in "Java" `{ return recv.valid(); `}
156 end
157
158 extern class NativeInputStream in "Java" `{ java.io.InputStream `}
159 super JavaObject
160 redef type SELF: NativeInputStream
161
162 fun available: Int in "Java" `{
163 try {
164 return recv.available();
165 }catch(IOException e){
166 e.printStackTrace();
167 return -1;
168 }
169 `}
170
171 fun close in "Java" `{
172 try {
173 recv.close();
174 }catch(IOException e){
175 e.printStackTrace();
176 }
177 `}
178 end