File: java.io.FileInputStream

package info (click to toggle)
bock 0.20.2.1
  • links: PTS
  • area: main
  • in suites: woody
  • size: 1,228 kB
  • ctags: 1,370
  • sloc: ansic: 7,367; java: 5,553; yacc: 963; lex: 392; makefile: 243; sh: 90; perl: 42
file content (86 lines) | stat: -rw-r--r-- 1,935 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
// java.io.FileInputStream
// An implementation of the Java Language Specification section 22.4
// Written by Charles Briscoe-Smith; refer to the file LEGAL for details.

package java.io;

public class FileInputStream extends InputStream {

	public FileInputStream(String path)
			throws SecurityException, FileNotFoundException
	{
		SecurityManager man=System.getSecurityManager();
		if (man!=null) man.checkRead(path);
		fd=FileDescriptor.openread(path);
		this.path=path;
	}

	public FileInputStream(File f)
			throws SecurityException, FileNotFoundException
	{
		String path=f.getPath();
		SecurityManager man=System.getSecurityManager();
		if (man!=null) man.checkRead(path);
		fd=FileDescriptor.openread(path);
		this.path=path;
	}

	public FileInputStream(FileDescriptor fd) throws SecurityException
	{
		SecurityManager man=System.getSecurityManager();
		if (man!=null) man.checkRead(fd.fd());
		this.fd=fd;
	}

	private FileDescriptor fd;
	private String path;

	public final FileDescriptor getFD() throws IOException {
		return fd;
	}

	public int read() throws IOException
	{
		byte[] buffer=new byte[1];
		int read=fd.read(buffer, 0, 1);
		if (read==0) return -1;
		else if (read<0) Errno.throwError(path);
		else return buffer[0] & 0xff;
	}

	public int read(byte[] b, int off, int len)
			throws IOException, NullPointerException,
			       IndexOutOfBoundsException
	{
		if (off<0 || len<0 || off+len>b.length)
			throw new IndexOutOfBoundsException();
		if (len==0) return 0;
		int read=fd.read(b, off, len);
		if (read==0) return -1;
		if (read<0) Errno.throwError(path);
		return read;
	}

	public long skip(long n) throws IOException
	{
		// FIXME
		return read(new byte[(int) n]);
	}

	public int available() throws IOException
	{
		// FIXME
		return 0;
	}

	public void close() throws IOException
	{
		if (fd.close()<0) Errno.throwError(path);
	}

	protected void finalize() throws IOException
	{
		close();
	}

}