com.sun.jini.mercury
Class LogOutputStream

java.lang.Object
  extended by java.io.OutputStream
      extended by com.sun.jini.mercury.LogOutputStream
All Implemented Interfaces:
LogStream, Closeable, Flushable

 class LogOutputStream
extends OutputStream
implements LogStream

This class implements the interface for interacting with output log streams. It extends java.util.OutputStream and overrides its methods in order to provide buffered output as well as byte offset tracking, which is useful during recovery situations. The additional methods drain and sync allow for the flushing of any buffered data and synchronizing data buffers with the underlying device, respectively.

Since:
1.1
Author:
Sun Microsystems, Inc.

Field Summary
private  byte[] buf
          byte array buffer for written data
private static int BUFSIZE
          Holds value of the internal buffer size to allocate
private  StreamKey key
          Associated key for this stream object
private  long offset
          cumulative index/offset into this stream
private  FileOutputStream out
          Underlying output stream from which bytes are written
private  int pos
          index/offset into the internal write buffer
 
Constructor Summary
LogOutputStream(File file, StreamKey key, boolean append)
          Simple constructor that accepts a File, StreamKey and boolean arguments.
 
Method Summary
 void close()
          Closes this LogStream object and releases any associated resources.
(package private)  void drain()
          Writes any unwritten bytes to the underlying output stream.
 void flush()
           
 Object getKey()
          Returns the associated key for this LogStream.
(package private)  long getOffset()
          Returns the current "write" offset into this stream object.
(package private)  void sync()
          Synchronizes system buffers with underlying device.
 void write(byte[] b)
           
 void write(byte[] b, int off, int len)
           
 void write(int b)
           
 
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 for written data


pos

private int pos
index/offset into the internal write buffer


offset

private long offset
cumulative index/offset into this stream


out

private FileOutputStream out
Underlying output stream from which bytes are written


key

private StreamKey key
Associated key for this stream object

Constructor Detail

LogOutputStream

public LogOutputStream(File file,
                       StreamKey key,
                       boolean append)
                throws FileNotFoundException
Simple constructor that accepts a File, StreamKey and boolean arguments. The File and StreamKey arguments are assigned to their respective internal fields. The boolean argument is used to determine whether or not to append bytes to the underlying (file) output stream.

Parameters:
file - the File to used
key - the associated key for this object
append - determines whether or not to append to the underlying stream
Throws:
IllegalArgumentException - if either the file or key argument is 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

write

public void write(int b)
           throws IOException
Specified by:
write in class OutputStream
Throws:
IOException

write

public void write(byte[] b)
           throws IOException
Overrides:
write in class OutputStream
Throws:
IOException

write

public void write(byte[] b,
                  int off,
                  int len)
           throws IOException
Overrides:
write in class OutputStream
Throws:
IOException

flush

public void flush()
           throws IOException
Specified by:
flush in interface Flushable
Overrides:
flush in class OutputStream
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 OutputStream
Throws:
IOException - if an I/O error occured while attempting to close the LogStream.

getOffset

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


sync

void sync()
    throws IOException,
           SyncFailedException
Synchronizes system buffers with underlying device.

Throws:
IOException - if an I/O error occurs
SyncFailedException - if the buffers cannot be guaranteed to have synchronized with physical media

drain

void drain()
     throws IOException
Writes any unwritten bytes to the underlying output stream.

Throws:
IOException - if an I/O error occurs

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.