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 OutputStreamWithBufferpublic int getBufferOffset()
getBufferOffset in class OutputStreamWithBufferpublic void setBufferOffset(int offset)
setBufferOffset in class OutputStreamWithBufferpublic int getBufferSize()
public int getRemaining()
public void setImplicitFlush(boolean implicitFlush)
public void write(int ch)
throws java.io.IOException
write in interface ByteAppendablewrite in class java.io.OutputStreamjava.io.IOExceptionpublic void write(byte[] buf,
int offset,
int length)
throws java.io.IOException
write in interface ByteAppendablewrite in class java.io.OutputStreamjava.io.IOExceptionpublic byte[] nextBuffer(int offset)
throws java.io.IOException
nextBuffer in class OutputStreamWithBufferjava.io.IOExceptionpublic void write(byte[] buf)
throws java.io.IOException
write in class java.io.OutputStreamjava.io.IOExceptionpublic void flush()
throws java.io.IOException
flush in interface java.io.Flushableflush in class java.io.OutputStreamjava.io.IOExceptionpublic void flushToDisk()
throws java.io.IOException
java.io.IOExceptionpublic final void flushBuffer()
throws java.io.IOException
java.io.IOExceptionpublic void seekStart(long pos)
throws java.io.IOException
java.io.IOExceptionpublic void seekEnd(long offset)
throws java.io.IOException
java.io.IOExceptionpublic void setEncoding(java.lang.String encoding)
throws java.io.UnsupportedEncodingException
java.io.UnsupportedEncodingExceptionpublic void setLocale(java.util.Locale locale)
throws java.io.UnsupportedEncodingException
java.io.UnsupportedEncodingExceptionpublic 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.IOExceptionpublic 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.IOExceptionpublic final void printUtf8(java.lang.String value,
int offset,
int length)
throws java.io.IOException
java.io.IOExceptionpublic final void print(char ch)
throws java.io.IOException
ch - charjava.io.IOExceptionpublic final void print(char[] buffer)
throws java.io.IOException
buffer - character buffer to writejava.io.IOExceptionpublic final void print(CharSegment segment) throws java.io.IOException
segment - character buffer to writejava.io.IOExceptionpublic final void print(java.lang.String string)
throws java.io.IOException
java.io.IOExceptionpublic final void printLatin1(java.lang.String string)
throws java.io.IOException
java.io.IOExceptionpublic 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.IOExceptionpublic final void printLatin1NoLf(java.lang.String string)
throws java.io.IOException
java.io.IOExceptionpublic 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.IOExceptionpublic final void print(boolean b)
throws java.io.IOException
java.io.IOExceptionpublic final void print(int i)
throws java.io.IOException
java.io.IOExceptionpublic final void print(long i)
throws java.io.IOException
java.io.IOExceptionpublic final void print(float f)
throws java.io.IOException
java.io.IOExceptionpublic final void print(double d)
throws java.io.IOException
java.io.IOExceptionpublic final void print(java.lang.Object o)
throws java.io.IOException
java.io.IOExceptionpublic final void println()
throws java.io.IOException
java.io.IOExceptionpublic final void println(char[] buf,
int offset,
int length)
throws java.io.IOException
java.io.IOExceptionpublic final void println(java.lang.String string)
throws java.io.IOException
java.io.IOExceptionpublic final void println(boolean b)
throws java.io.IOException
java.io.IOExceptionpublic final void println(char ch)
throws java.io.IOException
java.io.IOExceptionpublic final void println(int i)
throws java.io.IOException
java.io.IOExceptionpublic final void println(long l)
throws java.io.IOException
java.io.IOExceptionpublic final void println(float f)
throws java.io.IOException
java.io.IOExceptionpublic final void println(double d)
throws java.io.IOException
java.io.IOExceptionpublic final void println(java.lang.Object o)
throws java.io.IOException
java.io.IOExceptionpublic 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.IOExceptionpublic void writeStream(java.io.Reader reader)
throws java.io.IOException
source to the current stream.source - InputStream to read.java.io.IOExceptionpublic void writeStream(java.io.InputStream source,
int totalLength)
throws java.io.IOException
source to the current stream.source - InputStream to read.java.io.IOExceptionpublic void writeStream(StreamImpl source) throws java.io.IOException
source to the current stream.source - InputStream to read.java.io.IOExceptionpublic void writeFile(Path path) throws java.io.IOException
path - Path of the file to copy.java.io.IOExceptionpublic void setDisableClose(boolean disableClose)
public boolean getDisableClose()
public void setDisableCloseSource(boolean disableClose)
public final boolean isClosed()
isClosed in class OutputStreamWithBufferpublic final void close()
throws java.io.IOException
close in interface java.io.Closeableclose in interface java.lang.AutoCloseableclose in class java.io.OutputStreamjava.io.IOExceptionpublic final void free()
public java.lang.Object getAttribute(java.lang.String name)
throws java.io.IOException
java.io.IOExceptionpublic void setAttribute(java.lang.String name,
java.lang.Object value)
throws java.io.IOException
java.io.IOExceptionpublic void removeAttribute(java.lang.String name)
throws java.io.IOException
java.io.IOExceptionpublic java.util.Iterator<java.lang.String> getAttributeNames()
throws java.io.IOException
java.io.IOExceptionpublic 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)
LockableStreamlock in interface LockableStreampublic boolean unlock()
LockableStreamunlock in interface LockableStreampublic long getPosition()
public void clearPosition()
public boolean setPosition(long pos)
throws java.io.IOException
java.io.IOExceptionpublic boolean isMmapEnabled()
isMmapEnabled in interface SendfileOutputStreampublic boolean isSendfileEnabled()
isSendfileEnabled in interface SendfileOutputStreampublic void writeMmap(long mmapAddress,
long[] mmapBlocks,
long mmapOffset,
long mmapLength)
throws java.io.IOException
writeMmap in interface SendfileOutputStreamjava.io.IOExceptionpublic void writeSendfile(byte[] fileName,
int nameLength,
long fileLength)
throws java.io.IOException
writeSendfile in interface SendfileOutputStreamjava.io.IOExceptionpublic java.lang.String toString()
toString in class java.lang.Object