18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package sun.rmi.log;
27
28 import java.io.*;
29
30 public
31 class LogInputStream extends InputStream {
32 private InputStream in;
33 private int length;
34
35 /**
36 * Creates a log input file with the specified system dependent
37 * file descriptor.
38 * @param fd the system dependent file descriptor
39 * @param length the total number of bytes allowed to be read
40 * @exception IOException If an I/O error has occurred.
41 */
42 public LogInputStream(InputStream in, int length) throws IOException {
43 this.in = in;
44 this.length = length;
45 }
46
47 /**
48 * Reads a byte of data. This method will block if no input is
49 * available.
50 * @return the byte read, or -1 if the end of the log or end of the
51 * stream is reached.
52 * @exception IOException If an I/O error has occurred.
53 */
54 public int read() throws IOException {
55 if (length == 0)
56 return -1;
57 int c = in.read();
58 length = (c != -1) ? length - 1 : 0;
|
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package sun.rmi.log;
27
28 import java.io.*;
29
30 public
31 class LogInputStream extends InputStream {
32 private InputStream in;
33 private int length;
34
35 /**
36 * Creates a log input file with the specified system dependent
37 * file descriptor.
38 * @param in the system dependent file descriptor
39 * @param length the total number of bytes allowed to be read
40 * @exception IOException If an I/O error has occurred.
41 */
42 public LogInputStream(InputStream in, int length) throws IOException {
43 this.in = in;
44 this.length = length;
45 }
46
47 /**
48 * Reads a byte of data. This method will block if no input is
49 * available.
50 * @return the byte read, or -1 if the end of the log or end of the
51 * stream is reached.
52 * @exception IOException If an I/O error has occurred.
53 */
54 public int read() throws IOException {
55 if (length == 0)
56 return -1;
57 int c = in.read();
58 length = (c != -1) ? length - 1 : 0;
|