com.sun.jini.mercury
Class LogInputStream

java.lang.Object
  extended by java.io.InputStream
      extended by com.sun.jini.mercury.LogInputStream
All Implemented Interfaces:
LogStream, Closeable

 class LogInputStream
extends InputStream
implements LogStream

This class implements the interface for interacting with input log streams. It extends java.util.InputStream and overrides its methods in order to provide buffered input as well as byte offset tracking, which is useful during recovery situations.

Since:
1.1
Author:
Sun Microsystems, Inc.

Field Summary
private  byte[] buf
          byte array buffer to hold read data
private static int BUFSIZE
          Holds value of the internal buffer size to allocate
private  int count
          count of available bytes in the read buffer
private  FileInputStream in
          Underlying input stream from which bytes are read
private  StreamKey key
          Associated key for this stream object
private  long offset
          cumulative index/offset into this stream
private  int pos
          index/offset into the read buffer for the next set of bytes to read
 
Constructor Summary
LogInputStream(File file, StreamKey key)
          Simple constructor that accepts a File and StreamKey arguments.
 
Method Summary
 int available()
           
 void close()
          Closes this LogStream object and releases any associated resources.
 Object getKey()
          Returns the associated key for this LogStream.
 long getOffset()
          Returns the current "read" offset into this stream object.
 int read()
           
 int read(byte[] b)
           
 int read(byte[] b, int off, int len)
           
private  void refill()
          Refills the internal buffer with any available bytes.
 long skip(long n)
           
 
Methods inherited from class java.io.InputStream
mark, markSupported, reset
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

BUFSIZE

private static final int BUFSIZE
Holds value of the internal buffer size to allocate

See Also:
Constant Field Values

buf

private byte[] buf
byte array buffer to hold read data


count

private int count
count of available bytes in the read buffer


pos

private int pos
index/offset into the read buffer for the next set of bytes to read


offset

private long offset
cumulative index/offset into this stream


in

private FileInputStream in
Underlying input stream from which bytes are read


key

private StreamKey key
Associated key for this stream object

Constructor Detail

LogInputStream

public LogInputStream(File file,
                      StreamKey key)
               throws FileNotFoundException
Simple constructor that accepts a File and StreamKey arguments. The File and StreamKey arguments are assigned to their respective internal fields.

Parameters:
file - the File to used
key - the associated key for this object
Throws:
IllegalArgumentException - if either the file or key arguments are null.
FileNotFoundException - if the file exists but is a directory rather than a regular file, does not exist but cannot be created, or cannot be opened for any other reason.
Method Detail

read

public int read()
         throws IOException
Specified by:
read in class InputStream
Throws:
IOException

read

public int read(byte[] b)
         throws IOException
Overrides:
read in class InputStream
Throws:
IOException

read

public int read(byte[] b,
                int off,
                int len)
         throws IOException
Overrides:
read in class InputStream
Throws:
IOException

skip

public long skip(long n)
          throws IOException
Overrides:
skip in class InputStream
Throws:
IOException

available

public int available()
              throws IOException
Overrides:
available in class InputStream
Throws:
IOException

close

public void close()
           throws IOException
Description copied from interface: LogStream
Closes this LogStream object and releases any associated resources.

Specified by:
close in interface LogStream
Specified by:
close in interface Closeable
Overrides:
close in class InputStream
Throws:
IOException - if an I/O error occured while attempting to close the LogStream.

getOffset

public long getOffset()
Returns the current "read" offset into this stream object.


refill

private void refill()
             throws IOException
Refills the internal buffer with any available bytes. This method will block until either bytes have been read, or no more bytes can be read.

Throws:
IOException

getKey

public Object getKey()
Description copied from interface: LogStream
Returns the associated key for this LogStream. This key is intended to be used as the key in a java.util.Collection.

Specified by:
getKey in interface LogStream


Copyright 2007-2010, multiple authors.
Licensed under the Apache License, Version 2.0, see the NOTICE file for attributions.