|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectjava.io.OutputStream
com.mucommander.io.RandomAccessOutputStream
com.mucommander.io.BufferedRandomOutputStream
public class BufferedRandomOutputStream
BufferedRandomOutputStream is a buffered output stream for RandomAccessOutputStream which, unlike a regular
java.io.BufferedOutputStream, makes it safe to seek in the underlying RandomAccessOutputStream.
This class uses BufferPool to create the internal buffer, to avoid excessive memory allocation and
garbage collection. The buffer is released when this stream is closed.
| Field Summary | |
|---|---|
static int |
DEFAULT_BUFFER_SIZE
The default buffer size if none is specified |
| Constructor Summary | |
|---|---|
BufferedRandomOutputStream(RandomAccessOutputStream raos)
Creates a new BufferedRandomOutputStream on top of the given RandomAccessOutputStream. |
|
BufferedRandomOutputStream(RandomAccessOutputStream raos,
int size)
Creates a new BufferedRandomOutputStream on top of the given RandomAccessOutputStream. |
|
| Method Summary | |
|---|---|
void |
close()
This method is overridden to release the internal buffer when this stream is closed. |
protected void |
finalize()
This method is overridden to release the internal buffer if close() has not been called, to avoid any
memory leak. |
void |
flush()
Flushes this buffered output stream. |
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 the specified byte array to this buffered output stream. |
void |
write(byte[] b,
int off,
int len)
Writes len bytes from the specified byte array starting at offset off to this
buffered output stream. |
void |
write(int b)
Writes the specified byte to this buffered output stream. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final int DEFAULT_BUFFER_SIZE
| Constructor Detail |
|---|
public BufferedRandomOutputStream(RandomAccessOutputStream raos)
BufferedRandomOutputStream on top of the given RandomAccessOutputStream.
An internal buffer of DEFAULT_BUFFER_SIZE bytes is created.
raos - the underlying RandomAccessOutputStream used by this buffered output stream
public BufferedRandomOutputStream(RandomAccessOutputStream raos,
int size)
BufferedRandomOutputStream on top of the given RandomAccessOutputStream.
An internal buffer of the specified size is created.
raos - the underlying RandomAccessOutputStream used by this buffered output streamsize - size of the buffer in bytes| Method Detail |
|---|
public void write(int b)
throws java.io.IOException
write in class java.io.OutputStreamb - the byte to be written
java.io.IOException - if an I/O error occurs
public void write(byte[] b)
throws java.io.IOException
write in class RandomAccessOutputStreamb - the bytes to be written
java.io.IOException - if an I/O error occurs
public void write(byte[] b,
int off,
int len)
throws java.io.IOException
len bytes from the specified byte array starting at offset off to this
buffered output stream.
Usually this method stores bytes from the given array into this
stream's buffer, flushing the buffer to the underlying output stream as
needed. However, if the requested data length is equal or larger than this stream's
buffer, then this method will flush the buffer and write the
bytes directly to the underlying output stream. Thus redundant
RandomBufferedOutputStreams will not copy data unnecessarily.
write in class RandomAccessOutputStreamb - the data.off - the start offset in the data.len - the number of bytes to write.
java.io.IOException - if an I/O error occurs.
public void flush()
throws java.io.IOException
flush in interface java.io.Flushableflush in class java.io.OutputStreamjava.io.IOException - if an I/O error occurs.
public long getOffset()
throws java.io.IOException
RandomAccess
java.io.IOException - if an I/O error occurs.
public void seek(long offset)
throws java.io.IOException
RandomAccess
offset - the new offset position, measured in bytes from the beginning of the file
java.io.IOException - if an I/O error occurs
public long getLength()
throws java.io.IOException
RandomAccess
java.io.IOException - if an I/O error occurs
public void setLength(long newLength)
throws java.io.IOException
RandomAccessOutputStreamIf 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.
setLength in class RandomAccessOutputStreamnewLength - the new file's length
java.io.IOException - If an I/O error occurred while trying to change the file's length
public void close()
throws java.io.IOException
close in interface RandomAccessclose in interface java.io.Closeableclose in class RandomAccessOutputStreamjava.io.IOException - if an I/O error occurs.
protected void finalize()
throws java.lang.Throwable
close() has not been called, to avoid any
memory leak.
finalize in class java.lang.Objectjava.lang.Throwable
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
This file is part of muCommander - Copyright (C) 2002-2008 Maxence Bernard