public class WriteStream extends OutputStreamWithBuffer implements LockableStream, SendfileOutputStream
OutputStream and Writers are combined. The write
routines
write bytes and the print
routines write characters.
Most applications will use the Path routines to create their own streams. Specialized applications, like servers, need the capability of recycling streams.
Constructor and Description |
---|
WriteStream()
Creates an uninitialized stream.
|
WriteStream(StreamImpl source)
Creates a stream and initializes with a specified source.
|
Modifier and Type | Method and Description |
---|---|
boolean |
canWrite()
Returns true if the buffer allows writes.
|
void |
clearPosition()
Clears the position for statistics cases like a socket stream.
|
void |
clearWrite()
Clears the write buffer
|
void |
close()
Close the stream, first flushing the write buffer.
|
void |
flush()
Flushes the buffer to the source.
|
void |
flushBuffer()
Flushes the buffer to the source.
|
void |
flushToDisk()
Flushes the buffer to the disk
|
void |
free()
Frees the buffer
|
java.lang.Object |
getAttribute(java.lang.String name)
Returns a named attribute.
|
java.util.Iterator<java.lang.String> |
getAttributeNames()
Lists all named attributes.
|
byte[] |
getBuffer()
Returns the write buffer.
|
int |
getBufferOffset()
Returns the write offset.
|
int |
getBufferSize()
Returns the write size.
|
boolean |
getDisableClose() |
java.lang.String |
getEncoding()
Returns the mime-encoding used for writing.
|
java.lang.String |
getJavaEncoding() |
java.lang.String |
getNewlineString()
Returns the current string used for println newlines
|
Path |
getPath()
Returns the Path which opened this stream.
|
long |
getPosition()
Returns the write position.
|
java.io.PrintWriter |
getPrintWriter()
Returns a printWriter writing to this stream.
|
int |
getRemaining()
Returns the bytes remaining in the buffer.
|
StreamImpl |
getSource()
Returns the underlying source for the stream.
|
java.lang.String |
getUserPath()
Returns the user path which opened this stream.
|
void |
init(StreamImpl source)
Initializes the stream with a given source.
|
boolean |
isClosed()
Returns true if the stream is closed.
|
boolean |
isMmapEnabled() |
boolean |
isSendfileEnabled() |
boolean |
lock(boolean shared,
boolean block)
Lock the shared advisory lock.
|
void |
log(java.lang.String string)
Logs a line to the stream.
|
void |
log(java.lang.Throwable exn) |
byte[] |
nextBuffer(int offset)
Flushes and writes the buffer
|
void |
print(boolean b)
Prints a boolean.
|
void |
print(char ch)
Prints the character buffer to the stream.
|
void |
print(char[] buffer)
Prints the character buffer to the stream.
|
void |
print(char[] buffer,
int offset,
int length)
Prints the character buffer to the stream.
|
void |
print(CharSegment segment)
Prints the character buffer to the stream.
|
void |
print(double d)
Prints an double
|
void |
print(float f)
Prints a float.
|
void |
print(int i)
Prints an integer.
|
void |
print(long i)
Prints a long.
|
void |
print(java.lang.Object o)
Prints a double, converted by String.valueOf()
|
void |
print(java.lang.String string)
Prints a string.
|
void |
print(java.lang.String string,
int offset,
int length)
Prints a substring.
|
void |
printLatin1(char[] buffer,
int offset,
int length)
Prints the character buffer to the stream encoded as latin1.
|
void |
printLatin1(java.lang.String string)
Prints a string.
|
void |
printLatin1NoLf(java.lang.String string)
Prints a string.
|
void |
println()
Prints a newline
|
void |
println(boolean b)
Prints a boolean followed by a newline.
|
void |
println(char ch)
Prints a char followed by a newline.
|
void |
println(char[] buf,
int offset,
int length)
Prints a character buffer followed by a newline.
|
void |
println(double d)
Prints a double followed by a newline.
|
void |
println(float f)
Prints a float followed by a newline.
|
void |
println(int i)
Prints an integer followed by a newline.
|
void |
println(long l)
Prints a long followed by a newline.
|
void |
println(java.lang.Object o)
Prints an object, converted to a string, followed by a newline.
|
void |
println(java.lang.String string)
Prints a string buffer followed by a newline.
|
void |
printUtf8(java.lang.String value,
int offset,
int length) |
void |
pushFilter(StreamFilter filter)
Pushes a filter on the top of the stream stack.
|
void |
removeAttribute(java.lang.String name)
Removes a named attribute.
|
void |
seekEnd(long offset)
Seeks based on the end
|
void |
seekStart(long pos)
Seeks based on the start
|
void |
setAttribute(java.lang.String name,
java.lang.Object value)
Sets a named attribute.
|
void |
setBufferOffset(int offset)
Sets the write offset.
|
void |
setDisableClose(boolean disableClose)
Disables close.
|
void |
setDisableCloseSource(boolean disableClose)
Disables close of the underlying source.
|
void |
setEncoding(java.lang.String encoding)
Sets the character encoding for writing to this stream.
|
void |
setFlushOnNewline(boolean flushOnNewline)
Some streams, like log streams, should be flushed on every println
call.
|
void |
setImplicitFlush(boolean implicitFlush) |
void |
setLocale(java.util.Locale locale) |
void |
setNewlineString(java.lang.String newline)
Sets the string to use for println newlines
|
void |
setPath(Path path)
Sets a path name associated with the stream.
|
boolean |
setPosition(long pos)
Sets the current write position.
|
void |
setReuseBuffer(boolean reuse) |
void |
setSysNewline() |
static void |
setSystemNewline(java.lang.String newline)
For testing, sets the system newlines.
|
java.lang.String |
toString() |
boolean |
unlock()
Unlock the advisory lock.
|
void |
write(byte[] buf)
Writes a byte array.
|
void |
write(byte[] buf,
int offset,
int length)
Writes a byte array
|
void |
write(int ch)
Writes a byte.
|
void |
writeFile(Path path)
Copies a file to the stream.
|
void |
writeMmap(long mmapAddress,
long[] mmapBlocks,
long mmapOffset,
long mmapLength) |
void |
writeSendfile(byte[] fileName,
int nameLength,
long fileLength) |
long |
writeStream(java.io.InputStream source)
Writes the contents of a JDK stream.
|
void |
writeStream(java.io.InputStream source,
int totalLength)
Writes the contents of a JDK stream.
|
void |
writeStream(java.io.Reader reader)
Writes the contents of a JDK reader.
|
void |
writeStream(StreamImpl source)
Writes the contents of a JDK stream.
|
void |
XprintLatin1NoLf(java.lang.String string)
Prints the character buffer to the stream encoded as latin1.
|
public WriteStream()
init
to initialize.public WriteStream(StreamImpl source)
source
- Underlying source for the stream.public void init(StreamImpl source)
source
- Underlying source for the stream.public void setSysNewline()
public StreamImpl getSource()
public void pushFilter(StreamFilter filter)
filter
- the filter to be added.public boolean canWrite()
LogStreams, used for debugging, use this feature to
test if they should write with very little overhead.
if (dbg.canWrite())
dbg.log("some debug value " + expensiveDebugCalculation(foo));
public void clearWrite()
public void setReuseBuffer(boolean reuse)
public byte[] getBuffer()
getBuffer
in class OutputStreamWithBuffer
public int getBufferOffset()
getBufferOffset
in class OutputStreamWithBuffer
public void setBufferOffset(int offset)
setBufferOffset
in class OutputStreamWithBuffer
public int getBufferSize()
public int getRemaining()
public void setImplicitFlush(boolean implicitFlush)
public void write(int ch) throws java.io.IOException
write
in interface ByteAppendable
write
in class java.io.OutputStream
java.io.IOException
public void write(byte[] buf, int offset, int length) throws java.io.IOException
write
in interface ByteAppendable
write
in class java.io.OutputStream
java.io.IOException
public byte[] nextBuffer(int offset) throws java.io.IOException
nextBuffer
in class OutputStreamWithBuffer
java.io.IOException
public void write(byte[] buf) throws java.io.IOException
write
in class java.io.OutputStream
java.io.IOException
public void flush() throws java.io.IOException
flush
in interface java.io.Flushable
flush
in class java.io.OutputStream
java.io.IOException
public void flushToDisk() throws java.io.IOException
java.io.IOException
public final void flushBuffer() throws java.io.IOException
java.io.IOException
public void seekStart(long pos) throws java.io.IOException
java.io.IOException
public void seekEnd(long offset) throws java.io.IOException
java.io.IOException
public void setEncoding(java.lang.String encoding) throws java.io.UnsupportedEncodingException
java.io.UnsupportedEncodingException
public void setLocale(java.util.Locale locale) throws java.io.UnsupportedEncodingException
java.io.UnsupportedEncodingException
public java.lang.String getEncoding()
public java.lang.String getJavaEncoding()
public void setFlushOnNewline(boolean flushOnNewline)
flushOnNewline
- set to true if println flushes.public java.lang.String getNewlineString()
public void setNewlineString(java.lang.String newline)
public final void print(char[] buffer, int offset, int length) throws java.io.IOException
buffer
- character buffer to writeoffset
- offset into the buffer to start writeslength
- number of characters to writejava.io.IOException
public final void printLatin1(char[] buffer, int offset, int length) throws java.io.IOException
buffer
- character buffer to writeoffset
- offset into the buffer to start writeslength
- number of characters to writejava.io.IOException
public final void printUtf8(java.lang.String value, int offset, int length) throws java.io.IOException
java.io.IOException
public final void print(char ch) throws java.io.IOException
ch
- charjava.io.IOException
public final void print(char[] buffer) throws java.io.IOException
buffer
- character buffer to writejava.io.IOException
public final void print(CharSegment segment) throws java.io.IOException
segment
- character buffer to writejava.io.IOException
public final void print(java.lang.String string) throws java.io.IOException
java.io.IOException
public final void printLatin1(java.lang.String string) throws java.io.IOException
java.io.IOException
public final void XprintLatin1NoLf(java.lang.String string) throws java.io.IOException
buffer
- character buffer to writeoffset
- offset into the buffer to start writeslength
- number of characters to writejava.io.IOException
public final void printLatin1NoLf(java.lang.String string) throws java.io.IOException
java.io.IOException
public final void print(java.lang.String string, int offset, int length) throws java.io.IOException
string
- the string to printoffset
- starting offset into the stringlength
- length of the substring to print.java.io.IOException
public final void print(boolean b) throws java.io.IOException
java.io.IOException
public final void print(int i) throws java.io.IOException
java.io.IOException
public final void print(long i) throws java.io.IOException
java.io.IOException
public final void print(float f) throws java.io.IOException
java.io.IOException
public final void print(double d) throws java.io.IOException
java.io.IOException
public final void print(java.lang.Object o) throws java.io.IOException
java.io.IOException
public final void println() throws java.io.IOException
java.io.IOException
public final void println(char[] buf, int offset, int length) throws java.io.IOException
java.io.IOException
public final void println(java.lang.String string) throws java.io.IOException
java.io.IOException
public final void println(boolean b) throws java.io.IOException
java.io.IOException
public final void println(char ch) throws java.io.IOException
java.io.IOException
public final void println(int i) throws java.io.IOException
java.io.IOException
public final void println(long l) throws java.io.IOException
java.io.IOException
public final void println(float f) throws java.io.IOException
java.io.IOException
public final void println(double d) throws java.io.IOException
java.io.IOException
public final void println(java.lang.Object o) throws java.io.IOException
java.io.IOException
public java.io.PrintWriter getPrintWriter()
public final void log(java.lang.String string)
public final void log(java.lang.Throwable exn)
public long writeStream(java.io.InputStream source) throws java.io.IOException
source
to the current stream.source
- InputStream to read.java.io.IOException
public void writeStream(java.io.Reader reader) throws java.io.IOException
source
to the current stream.source
- InputStream to read.java.io.IOException
public void writeStream(java.io.InputStream source, int totalLength) throws java.io.IOException
source
to the current stream.source
- InputStream to read.java.io.IOException
public void writeStream(StreamImpl source) throws java.io.IOException
source
to the current stream.source
- InputStream to read.java.io.IOException
public void writeFile(Path path) throws java.io.IOException
path
- Path of the file to copy.java.io.IOException
public void setDisableClose(boolean disableClose)
public boolean getDisableClose()
public void setDisableCloseSource(boolean disableClose)
public final boolean isClosed()
isClosed
in class OutputStreamWithBuffer
public final void close() throws java.io.IOException
close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable
close
in class java.io.OutputStream
java.io.IOException
public final void free()
public java.lang.Object getAttribute(java.lang.String name) throws java.io.IOException
java.io.IOException
public void setAttribute(java.lang.String name, java.lang.Object value) throws java.io.IOException
java.io.IOException
public void removeAttribute(java.lang.String name) throws java.io.IOException
java.io.IOException
public java.util.Iterator<java.lang.String> getAttributeNames() throws java.io.IOException
java.io.IOException
public Path getPath()
public java.lang.String getUserPath()
Parsing routines typically use this for error reporting.
public void setPath(Path path)
public static void setSystemNewline(java.lang.String newline)
public boolean lock(boolean shared, boolean block)
LockableStream
lock
in interface LockableStream
public boolean unlock()
LockableStream
unlock
in interface LockableStream
public long getPosition()
public void clearPosition()
public boolean setPosition(long pos) throws java.io.IOException
java.io.IOException
public boolean isMmapEnabled()
isMmapEnabled
in interface SendfileOutputStream
public boolean isSendfileEnabled()
isSendfileEnabled
in interface SendfileOutputStream
public void writeMmap(long mmapAddress, long[] mmapBlocks, long mmapOffset, long mmapLength) throws java.io.IOException
writeMmap
in interface SendfileOutputStream
java.io.IOException
public void writeSendfile(byte[] fileName, int nameLength, long fileLength) throws java.io.IOException
writeSendfile
in interface SendfileOutputStream
java.io.IOException
public java.lang.String toString()
toString
in class java.lang.Object