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 `}
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" `{
41 return self.createNewFile();
42 }catch(IOException e){
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" `{
54 return self.getCanonicalFile
();
55 }catch
(IOException e
){
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); `}
77 extern class NativeFileInputStream in "Java" `{ java.io.FileInputStream `}
80 fun available: Int in "Java" `{
82 return self.available
();
83 }catch
(IOException e
){
88 fun close in "Java" `{
91 }catch
(IOException e
){
95 fun read: Int in "Java" `{
98 }catch
(IOException e
){
103 fun skip(byte_count: Int): Int in "Java" `{
105 return (int
)self.skip
(byte_count
);
106 }catch
(IOException e
){
113 extern class NativeFileOutputStream in "Java" `{ java.io.FileOutputStream `}
116 fun close
in "Java" `{
119 }catch(IOException e){
123 fun write
(one_byte
: Int) in "Java" `{
125 self.write((byte)one_byte);
126 }catch(IOException e){
130 fun flush
in "Java" `{
133 }catch(IOException e){
139 extern class NativeFileDescriptor in "Java" `{ java.io.FileDescriptor `}
142 fun sync in "Java" `{
145 }catch
(SyncFailedException e
){
149 fun valid: Bool in "Java" `{ return self.valid(); `}
152 extern class NativeInputStream in "Java" `{ java.io.InputStream `}
155 fun available: Int in "Java" `{
157 return self.available
();
158 }catch
(IOException e
){
164 fun close in "Java" `{
167 }catch
(IOException e
){
173 redef fun new_global_ref import sys, Sys.jni_env `{
174 Sys sys
= NativeInputStream_sys(self);
175 JNIEnv *env
= Sys_jni_env(sys
);
176 return (*env
)->NewGlobalRef(env
, self);
179 redef fun pop_from_local_frame_with_env(jni_env) `{
180 return (*jni_env
)->PopLocalFrame(jni_env
, self);