Debian Codegraph @

src/org/tukaani/xz/SeekableFileInputStream.java

raw symbols SCIP
1 // SPDX-License-Identifier: 0BSD
2 // SPDX-FileCopyrightText: The XZ for Java authors and contributors
3 // SPDX-FileContributor: Lasse Collin <[email protected]>
4
5 package org.tukaani.xz;
6
7 import java.io.File;
8 import java.io.RandomAccessFile;
9 import java.io.IOException;
10 import java.io.FileNotFoundException;
11
12 /**
13 * Wraps a {@link java.io.RandomAccessFile RandomAccessFile}
14 * in a SeekableInputStream.
15 */
16 public class SeekableFileInputStream extends SeekableInputStream {
17 /**
18 * The RandomAccessFile that has been wrapped
19 * into a SeekableFileInputStream.
20 */
21 protected RandomAccessFile randomAccessFile;
22
23 /**
24 * Creates a new seekable input stream that reads from the specified file.
25 */
26 public SeekableFileInputStream(File file) throws FileNotFoundException {
27 randomAccessFile = new RandomAccessFile(file, "r");
28 }
29
30 /**
31 * Creates a new seekable input stream that reads from a file with
32 * the specified name.
33 */
34 public SeekableFileInputStream(String name) throws FileNotFoundException {
35 randomAccessFile = new RandomAccessFile(name, "r");
36 }
37
38 /**
39 * Creates a new seekable input stream from an existing
40 * {@code RandomAccessFile} object.
41 */
42 public SeekableFileInputStream(RandomAccessFile randomAccessFile) {
43 this.randomAccessFile = randomAccessFile;
44 }
45
46 /**
47 * Calls {@link RandomAccessFile#read() randomAccessFile.read()}.
48 */
49 @Override
50 public int read() throws IOException {
51 return randomAccessFile.read();
52 }
53
54 /**
55 * Calls {@link RandomAccessFile#read(byte[]) randomAccessFile.read(buf)}.
56 */
57 @Override
58 public int read(byte[] buf) throws IOException {
59 return randomAccessFile.read(buf);
60 }
61
62 /**
63 * Calls
64 * {@link RandomAccessFile#read(byte[],int,int)
65 * randomAccessFile.read(buf, off, len)}.
66 */
67 @Override
68 public int read(byte[] buf, int off, int len) throws IOException {
69 return randomAccessFile.read(buf, off, len);
70 }
71
72 /**
73 * Calls {@link RandomAccessFile#close() randomAccessFile.close()}.
74 */
75 @Override
76 public void close() throws IOException {
77 randomAccessFile.close();
78 }
79
80 /**
81 * Calls {@link RandomAccessFile#length() randomAccessFile.length()}.
82 */
83 @Override
84 public long length() throws IOException {
85 return randomAccessFile.length();
86 }
87
88 /**
89 * Calls {@link RandomAccessFile#getFilePointer()
90 randomAccessFile.getFilePointer()}.
91 */
92 @Override
93 public long position() throws IOException {
94 return randomAccessFile.getFilePointer();
95 }
96
97 /**
98 * Calls {@link RandomAccessFile#seek(long) randomAccessFile.seek(long)}.
99 */
100 @Override
101 public void seek(long pos) throws IOException {
102 randomAccessFile.seek(pos);
103 }
104 }