* All files: Updated copyright to reflect Cygnus purchase.
[official-gcc.git] / libjava / java / io / FileInputStream.java
blob3bcd1a36970b75c9dafaadb31ece0883eae8c5e2
1 /* Copyright (C) 1998, 1999 Red Hat, Inc.
3 This file is part of libgcj.
5 This software is copyrighted work licensed under the terms of the
6 Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
7 details. */
9 package java.io;
11 /**
12 * @author Warren Levy <warrenl@cygnus.com>
13 * @date October 28, 1998.
15 /* Written using "Java Class Libraries", 2nd edition, ISBN 0-201-31002-3
16 * "The Java Language Specification", ISBN 0-201-63451-1
17 * plus online API docs for JDK 1.2 beta from http://www.javasoft.com.
18 * Status: Believed complete and correct.
21 public class FileInputStream extends InputStream
23 /* Contains the file descriptor for referencing the actual file. */
24 private FileDescriptor fd;
26 public FileInputStream(String name) throws FileNotFoundException
28 SecurityManager s = System.getSecurityManager();
29 if (s != null)
30 s.checkRead(name);
31 fd = new FileDescriptor(name, FileDescriptor.READ);
34 public FileInputStream(File file) throws FileNotFoundException
36 this(file.getPath());
39 public FileInputStream(FileDescriptor fdObj)
41 SecurityManager s = System.getSecurityManager();
42 if (s != null)
43 s.checkRead(fdObj);
44 fd = fdObj;
47 public int available() throws IOException
49 return fd.available();
52 public void close() throws IOException
54 if (fd == null)
55 return;
57 fd.close();
58 fd = null;
61 protected void finalize() throws IOException
63 if (fd != null)
64 fd.finalize();
67 public final FileDescriptor getFD() throws IOException
69 if (!fd.valid())
70 throw new IOException();
71 return fd;
74 public int read() throws IOException
76 return fd.read();
79 public int read(byte[] b) throws IOException
81 return fd.read(b, 0, b.length);
84 public int read(byte[] b, int off, int len) throws IOException
86 if (off < 0 || len < 0 || off + len > b.length)
87 throw new ArrayIndexOutOfBoundsException();
89 return fd.read(b, off, len);
92 public long skip(long n) throws IOException
94 return fd.seek(n, FileDescriptor.CUR);