2 * Copyright (C) 2014, United States Government, as represented by the
3 * Administrator of the National Aeronautics and Space Administration.
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
10 * http://www.apache.org/licenses/LICENSE-2.0.
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.
21 import java.nio.channels.FileChannel;
24 * a simple model to read data w/o dragging the file system content into
27 public class FileInputStream extends InputStream {
30 private FileChannel fc = null;
32 public FileInputStream (String fname) throws FileNotFoundException {
34 fd = new FileDescriptor(fname, FileDescriptor.FD_READ);
35 } catch (IOException iox){
36 throw new FileNotFoundException(fname);
40 public FileInputStream (File file) throws FileNotFoundException {
41 this( file.getAbsolutePath());
44 public FileInputStream (FileDescriptor fd) {
49 public int read(byte b[]) throws IOException {
50 return read(b,0,b.length);
53 public FileChannel getChannel() {
55 this.fc = new FileChannel(fd);
60 //--- our native peer methods
62 boolean open (String fname) {
63 // this sets the FileDescriptor from the peer side
68 public int read() throws IOException {
73 public int read(byte b[], int off, int len) throws IOException {
74 return fd.read(b,off,len);
78 public long skip(long n) throws IOException {
83 public int available () throws IOException {
84 return fd.available();
88 public void close () throws IOException {