class LogOutputStream extends OutputStream implements LogStream
Modifier and Type | Field and Description |
---|---|
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 and Description |
---|
LogOutputStream(File file,
StreamKey key,
boolean append)
Simple constructor that accepts a File, StreamKey
and boolean arguments.
|
Modifier and Type | Method and Description |
---|---|
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) |
private static final int BUFSIZE
private byte[] buf
private int pos
private long offset
private FileOutputStream out
private StreamKey key
public LogOutputStream(File file, StreamKey key, boolean append) throws FileNotFoundException
file
- the File to usedkey
- the associated key for this objectappend
- determines whether or not to append to the
underlying streamIllegalArgumentException
- if either the file or
key argument is nullFileNotFoundException
- 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 reasonpublic void write(int b) throws IOException
write
in class OutputStream
IOException
public void write(byte[] b) throws IOException
write
in class OutputStream
IOException
public void write(byte[] b, int off, int len) throws IOException
write
in class OutputStream
IOException
public void flush() throws IOException
flush
in interface Flushable
flush
in class OutputStream
IOException
public void close() throws IOException
LogStream
close
in interface LogStream
close
in interface Closeable
close
in interface AutoCloseable
close
in class OutputStream
IOException
- if an I/O error occured while attempting
to close the LogStream.long getOffset()
void sync() throws IOException, SyncFailedException
IOException
- if an I/O error occursSyncFailedException
- if the buffers cannot be guaranteed to
have synchronized with physical mediavoid drain() throws IOException
IOException
- if an I/O error occursCopyright 2007-2013, multiple authors.
Licensed under the Apache License, Version 2.0, see the NOTICE file for attributions.