KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > de > schlichtherle > io > rof > ReadOnlyFile


1 /*
2  * ReadOnlyFile.java
3  *
4  * Created on 5. Oktober 2005, 17:14
5  */

6 /*
7  * Copyright 2005 Schlichtherle IT Services
8  *
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  * http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  */

21
22 package de.schlichtherle.io.rof;
23
24 import java.io.IOException JavaDoc;
25
26 /**
27  * A minimal interface to allow random read only access to a file.
28  * This interface is required by the class {@link java.util.zip.ZipFile} to
29  * read a ZIP compatible file which may or may not be encrypted.
30  *
31  * @author Christian Schlichtherle
32  */

33 public interface ReadOnlyFile {
34
35     long length() throws IOException JavaDoc;
36
37     long getFilePointer() throws IOException JavaDoc;
38
39     /**
40      * Sets the file pointer offset, measured from the beginning of this
41      * file, at which the next read occurs.
42      * Whether the offset may be set beyond the end of the file is up to
43      * the implementor. For example, {@link java.io.RandomAccessFile}
44      * (which can be simply subclassed to implement this interface) does
45      * allow this, even if the file is opened read-only.
46      * However, this is not very meaningful on a read only file and thus
47      * not recommended.
48      *
49      * @param pos The offset position, measured in bytes from the beginning
50      * of the file, at which to set the file pointer.
51      * @throws IOException If <tt>pos</tt> is less than <tt>0</tt> or if
52      * an I/O error occurs.
53      */

54     void seek(long pos) throws IOException JavaDoc;
55
56     int read() throws IOException JavaDoc;
57
58     int read(byte[] b) throws IOException JavaDoc;
59
60     /**
61      * Reads up to <tt>len</tt> bytes of data from this read only file into
62      * the given array.
63      * This method blocks until at least one byte of input is available.
64      *
65      * @param b The buffer to fill with data.
66      * @param off The start offset of the data.
67      * @param len The maximum number of bytes to read.
68      *
69      * @return The total number of bytes read, or <tt>-1</tt> if there is
70      * no more data because the end of the file has been reached.
71      *
72      * @throws IOException On any I/O related issue.
73      */

74     int read(byte[] b, int off, int len) throws IOException JavaDoc;
75
76     void readFully(byte[] b) throws IOException JavaDoc;
77
78     void readFully(byte[] b, int off, int len) throws IOException JavaDoc;
79
80     int skipBytes(int n) throws IOException JavaDoc;
81
82     void close() throws IOException JavaDoc;
83 }
84
Popular Tags