com.mucommander.io
Class FilteredRandomOutputStream

java.lang.Object
  extended by java.io.OutputStream
      extended by com.mucommander.io.RandomAccessOutputStream
          extended by com.mucommander.io.FilteredRandomOutputStream
All Implemented Interfaces:
RandomAccess, java.io.Closeable, java.io.Flushable

public class FilteredRandomOutputStream
extends RandomAccessOutputStream

FilteredRandomOutputStream is a filtered output stream for RandomAccessOutputStream subclasses, allowing to easily extend the functionality provided by the stream by overriding only a few methods. In a similar way to java.io.FilteredOutputStream, this class delegates all method calls to the specified RandomAccessOutputStream.

Author:
Maxence Bernard

Field Summary
protected  RandomAccessOutputStream raos
          The underlying RandomAccessOutputStream
 
Constructor Summary
FilteredRandomOutputStream(RandomAccessOutputStream raos)
          Creates a new FilteredRandomOutputStream that delegates all method calls to the specified RandomAccessOutputStream.
 
Method Summary
 void close()
          Closes this stream and releases any system resources associated with the stream.
 void flush()
           
 long getLength()
          Returns the length of the file, in bytes.
 long getOffset()
          Returns the offset (in bytes) from the beginning of the file at which the next read or write occurs.
 void seek(long offset)
          Sets the offset, measured from the beginning of the file, at which the next read or write occurs.
 void setLength(long newLength)
          Sets the length of the file.
 void write(byte[] b)
          Writes b.length bytes from the specified byte array to this file, starting at the current file offset.
 void write(byte[] b, int off, int len)
          Writes len bytes from the specified byte array starting at offset off to this file.
 void write(int b)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

raos

protected RandomAccessOutputStream raos
The underlying RandomAccessOutputStream

Constructor Detail

FilteredRandomOutputStream

public FilteredRandomOutputStream(RandomAccessOutputStream raos)
Creates a new FilteredRandomOutputStream that delegates all method calls to the specified RandomAccessOutputStream.

Parameters:
raos - the RandomAccessOutputStream to delegate method calls to
Method Detail

write

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

write

public void write(byte[] b)
           throws java.io.IOException
Description copied from class: RandomAccessOutputStream
Writes b.length bytes from the specified byte array to this file, starting at the current file offset.

Specified by:
write in class RandomAccessOutputStream
Parameters:
b - the data to write
Throws:
java.io.IOException - if an I/O error occurs

write

public void write(byte[] b,
                  int off,
                  int len)
           throws java.io.IOException
Description copied from class: RandomAccessOutputStream
Writes len bytes from the specified byte array starting at offset off to this file.

Specified by:
write in class RandomAccessOutputStream
Parameters:
b - the data to write
off - the start offset in the data array
len - the number of bytes to write
Throws:
java.io.IOException - if an I/O error occurs

setLength

public void setLength(long newLength)
               throws java.io.IOException
Description copied from class: RandomAccessOutputStream
Sets the length of the file.

If the present length of the file as returned by the RandomAccess.getLength() method is greater than the newLength argument then the file will be truncated. In this case, if the file offset as returned by the RandomAccess.getOffset() method is greater than newLength then the offset will be equal to newLength after this method returns .

If the present length of the file as returned by the RandomAccess.getLength() method is smaller than the newLength argument then the file will be extended. In this case, the contents of the extended portion of the file are not defined.

Specified by:
setLength in class RandomAccessOutputStream
Parameters:
newLength - the new file's length
Throws:
java.io.IOException - If an I/O error occurred while trying to change the file's length

getOffset

public long getOffset()
               throws java.io.IOException
Description copied from interface: RandomAccess
Returns the offset (in bytes) from the beginning of the file at which the next read or write occurs.

Returns:
the offset (in bytes) from the beginning of the file at which the next read or write occurs
Throws:
java.io.IOException - if an I/O error occurs.

getLength

public long getLength()
               throws java.io.IOException
Description copied from interface: RandomAccess
Returns the length of the file, in bytes.

Returns:
the length of the file, in bytes
Throws:
java.io.IOException - if an I/O error occurs

seek

public void seek(long offset)
          throws java.io.IOException
Description copied from interface: RandomAccess
Sets the offset, measured from the beginning of the file, at which the next read or write occurs. The offset may be set beyond the end of the file. Setting the offset beyond the end of the file does not change the file length. The file length will change only by writing after the offset has been set beyond the end of the file.

Parameters:
offset - the new offset position, measured in bytes from the beginning of the file
Throws:
java.io.IOException - if an I/O error occurs

flush

public void flush()
           throws java.io.IOException
Specified by:
flush in interface java.io.Flushable
Overrides:
flush in class java.io.OutputStream
Throws:
java.io.IOException

close

public void close()
           throws java.io.IOException
Description copied from class: RandomAccessOutputStream
Closes this stream and releases any system resources associated with the stream. A closed stream cannot perform output operations and cannot be reopened.

Specified by:
close in interface RandomAccess
Specified by:
close in interface java.io.Closeable
Specified by:
close in class RandomAccessOutputStream
Throws:
java.io.IOException - if an I/O error occurs.


This file is part of muCommander - Copyright (C) 2002-2008 Maxence Bernard