Class LogInputStream

java.lang.Object
java.io.InputStream
com.sun.jini.reliableLog.LogInputStream
All Implemented Interfaces:
Closeable, AutoCloseable

public class LogInputStream extends InputStream
This class extends the functionality of the java.io.InputStream class in order to provide an input mechanism that can be used by processes that perform logging operations; in particular, processes that store state in order to provide persistence.
Author:
Sun Microsystems, Inc.
See Also:
  • Constructor Details

    • LogInputStream

      public LogInputStream(InputStream in, int length) throws IOException
      Creates a log input file with the specified input stream.
      Parameters:
      in - the input stream
      length - the total number of bytes allowed to be read
      Throws:
      IOException - If an I/O error has occurred.
  • Method Details

    • read

      public int read() throws IOException, LogException
      Reads a byte of data. This method will block if no input is available.
      Specified by:
      read in class InputStream
      Returns:
      the byte read, or -1 if the end of the stream is reached
      Throws:
      LogException - Attempt to read past end of log.
      IOException - If an I/O error has occurred.
    • read

      public int read(byte[] b) throws IOException, LogException
      Reads data into an array of bytes. This method blocks until some input is available.
      Overrides:
      read in class InputStream
      Parameters:
      b - the buffer into which the data is read
      Returns:
      the actual number of bytes read, -1 is returned when the end of the stream is reached
      Throws:
      LogException - Attempt to read past end of log.
      IOException - If an I/O error has occurred.
    • read

      public int read(byte[] b, int off, int len) throws IOException, LogException
      Reads data into an array of bytes. This method blocks until some input is available.
      Overrides:
      read in class InputStream
      Parameters:
      b - the buffer into which the data is read
      off - the start offset of the data
      len - the maximum number of bytes read
      Returns:
      the actual number of bytes read, -1 is returned when the end of the stream is reached
      Throws:
      LogException - Attempt to read past end of log.
      IOException - If an I/O error has occurred.
    • skip

      public long skip(long n) throws IOException, LogException
      Skips n bytes of input.
      Overrides:
      skip in class InputStream
      Parameters:
      n - the number of bytes to be skipped
      Returns:
      the actual number of bytes skipped
      Throws:
      LogException - Attempt to read past end of log.
      IOException - If an I/O error has occurred.
    • available

      public int available()
      Returns the number of bytes that can be read without blocking.
      Overrides:
      available in class InputStream
      Returns:
      the number of available bytes, which is initially equal to the file size
    • close

      public void close()
      Closes the input stream. No further input can be read.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Overrides:
      close in class InputStream
    • finalize

      protected void finalize() throws IOException
      Closes the stream when garbage is collected.
      Overrides:
      finalize in class Object
      Throws:
      IOException