Fixing a few bugs in the statistics printout.
[jpf-core.git] / src / classes / java / io / FileInputStream.java
1 /*
2  * Copyright (C) 2014, United States Government, as represented by the
3  * Administrator of the National Aeronautics and Space Administration.
4  * All rights reserved.
5  *
6  * The Java Pathfinder core (jpf-core) platform is licensed under the
7  * Apache License, Version 2.0 (the "License"); you may not use this file except
8  * in compliance with the License. You may obtain a copy of the License at
9  * 
10  *        http://www.apache.org/licenses/LICENSE-2.0. 
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and 
16  * limitations under the License.
17  */
18
19 package java.io;
20
21 import java.nio.channels.FileChannel;
22
23 /**
24  * a simple model to read data w/o dragging the file system content into
25  * the JPF memory
26  */
27 public class FileInputStream extends InputStream {
28
29   FileDescriptor fd;
30   private FileChannel fc = null;
31
32   public FileInputStream (String fname) throws FileNotFoundException {
33     try {
34       fd = new FileDescriptor(fname, FileDescriptor.FD_READ);
35     } catch (IOException iox){
36       throw new FileNotFoundException(fname);
37     }
38   }
39   
40   public FileInputStream (File file) throws FileNotFoundException {
41     this( file.getAbsolutePath());
42   }
43   
44   public FileInputStream (FileDescriptor fd) {
45     this.fd = fd;
46   }
47   
48   @Override
49   public int read(byte b[]) throws IOException {
50     return read(b,0,b.length);
51   }
52
53   public FileChannel getChannel() {
54     if(this.fc ==null){
55       this.fc = new FileChannel(fd);
56     }
57     return this.fc;
58   }
59   
60   //--- our native peer methods
61   
62   boolean open (String fname) {
63     // this sets the FileDescriptor from the peer side
64     return false;
65   }
66   
67   @Override
68   public int read() throws IOException {
69     return fd.read();
70   }
71
72   @Override
73   public int read(byte b[], int off, int len) throws IOException {
74     return fd.read(b,off,len);
75   }
76   
77   @Override
78   public long skip(long n) throws IOException {
79     return fd.skip(n);
80   }
81
82   @Override
83   public int available () throws IOException {
84     return fd.available();
85   }
86   
87   @Override
88   public void close () throws IOException {
89     fd.close();
90   }
91   
92   
93 }