lib/java: reorganize the java group to include the primitive arrays
[nit.git] / lib / 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 # Services from the `java.io` package
18 #
19 # This module is used by `android::assets_and_resources` and `android::audio`.
20 module io
21
22 import base
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 `}
32
33 extern class NativeFile in "Java" `{ java.io.File `}
34 super JavaObject
35
36 fun can_execute: Bool in "Java" `{ return self.canExecute(); `}
37 fun can_read: Bool in "Java" `{ return self.canRead(); `}
38 fun can_write: Bool in "Java" `{ return self.canWrite(); `}
39 fun create_file: Bool in "Java" `{
40 try {
41 return self.createNewFile();
42 }catch(IOException e){
43 e.printStackTrace();
44 return false;
45 }
46 `}
47 fun delete: Bool in "Java" `{ return self.delete(); `}
48 fun delete_on_exit in "Java" `{ self.deleteOnExit(); `}
49 fun exists: Bool in "Java" `{ return self.exists(); `}
50 fun absolute_file: NativeFile in "Java" `{ return self.getAbsoluteFile(); `}
51 fun absolute_path: JavaString in "Java" `{ return self.getAbsolutePath(); `}
52 fun canonical_file: NativeFile in "Java" `{
53 try {
54 return self.getCanonicalFile();
55 }catch(IOException e){
56 e.printStackTrace();
57 return null;
58 }
59 `}
60 fun free_space: Int in "Java" `{ return (int)self.getFreeSpace(); `}
61 fun name: JavaString in "Java" `{ return self.getName(); `}
62 fun parent: JavaString in "Java" `{ return self.getParent(); `}
63 fun parent_file: NativeFile in "Java" `{ return self.getParentFile(); `}
64 fun path: JavaString in "Java" `{ return self.getPath(); `}
65 fun total_space: Int in "Java" `{ return (int)self.getTotalSpace(); `}
66 fun usable_space: Int in "Java" `{ return (int)self.getUsableSpace(); `}
67 fun absolute: Bool in "Java" `{ return self.isAbsolute(); `}
68 fun is_directory: Bool in "Java" `{ return self.isDirectory(); `}
69 fun is_file: Bool in "Java" `{ return self.isFile(); `}
70 fun is_hidden: Bool in "Java" `{ return self.isHidden(); `}
71 fun last_modified: Int in "Java" `{ return (int)self.lastModified(); `}
72 fun length: Int in "Java" `{ return (int)self.length(); `}
73 fun set_readable(r: Bool, owner_only: Bool): Bool in "Java" `{ return self.setReadable(r, owner_only); `}
74 fun set_writable(w: Bool, owner_only: Bool): Bool in "Java" `{ return self.setWritable(w, owner_only); `}
75 end
76
77 extern class NativeFileInputStream in "Java" `{ java.io.FileInputStream `}
78 super JavaObject
79
80 fun available: Int in "Java" `{
81 try {
82 return self.available();
83 }catch(IOException e){
84 e.printStackTrace();
85 return -1;
86 }
87 `}
88 fun close in "Java" `{
89 try {
90 self.close();
91 }catch(IOException e){
92 e.printStackTrace();
93 }
94 `}
95 fun read: Int in "Java" `{
96 try {
97 return self.read();
98 }catch(IOException e){
99 e.printStackTrace();
100 return -1;
101 }
102 `}
103 fun skip(byte_count: Int): Int in "Java" `{
104 try {
105 return (int)self.skip(byte_count);
106 }catch(IOException e){
107 e.printStackTrace();
108 return -1;
109 }
110 `}
111 end
112
113 extern class NativeFileOutputStream in "Java" `{ java.io.FileOutputStream `}
114 super JavaObject
115
116 fun close in "Java" `{
117 try {
118 self.close();
119 }catch(IOException e){
120 e.printStackTrace();
121 }
122 `}
123 fun write(one_byte: Int) in "Java" `{
124 try {
125 self.write((byte)one_byte);
126 }catch(IOException e){
127 e.printStackTrace();
128 }
129 `}
130 fun flush in "Java" `{
131 try {
132 self.flush();
133 }catch(IOException e){
134 e.printStackTrace();
135 }
136 `}
137 end
138
139 extern class NativeFileDescriptor in "Java" `{ java.io.FileDescriptor `}
140 super JavaObject
141
142 fun sync in "Java" `{
143 try{
144 self.sync();
145 }catch(SyncFailedException e){
146 e.printStackTrace();
147 }
148 `}
149 fun valid: Bool in "Java" `{ return self.valid(); `}
150 end
151
152 extern class NativeInputStream in "Java" `{ java.io.InputStream `}
153 super JavaObject
154
155 fun available: Int in "Java" `{
156 try {
157 return self.available();
158 }catch(IOException e){
159 e.printStackTrace();
160 return -1;
161 }
162 `}
163
164 fun close in "Java" `{
165 try {
166 self.close();
167 }catch(IOException e){
168 e.printStackTrace();
169 }
170 `}
171 end