Package org.apache.tools.ant.util
Class LineOrientedOutputStream
- java.lang.Object
-
- java.io.OutputStream
-
- org.apache.tools.ant.util.LineOrientedOutputStream
-
- All Implemented Interfaces:
java.io.Closeable,java.io.Flushable,java.lang.AutoCloseable
- Direct Known Subclasses:
LineOrientedOutputStreamRedirector,LogOutputStream
public abstract class LineOrientedOutputStream extends java.io.OutputStreamInvokesprocessLinewhenever a full line has been written to this stream.Tries to be smart about line separators.
-
-
Constructor Summary
Constructors Constructor Description LineOrientedOutputStream()
-
Method Summary
Modifier and Type Method Description voidclose()Writes all remainingvoidflush()Flush this log streamprotected voidprocessBuffer()Converts the buffer to a byte[] and sends it toprocessLineprotected voidprocessLine(byte[] line)Processes a line.protected abstract voidprocessLine(java.lang.String line)Processes a line.voidwrite(byte[] b, int off, int len)Write a block of characters to the output streamvoidwrite(int cc)Write the data to the buffer and flush the buffer, if a line separator is detected.
-
-
-
Method Detail
-
write
public final void write(int cc) throws java.io.IOExceptionWrite the data to the buffer and flush the buffer, if a line separator is detected.- Specified by:
writein classjava.io.OutputStream- Parameters:
cc- data to log (byte).- Throws:
java.io.IOException- if there is an error.
-
flush
public void flush() throws java.io.IOExceptionFlush this log stream- Specified by:
flushin interfacejava.io.Flushable- Overrides:
flushin classjava.io.OutputStream- Throws:
java.io.IOException- if there is an error.
-
processBuffer
protected void processBuffer() throws java.io.IOExceptionConverts the buffer to a byte[] and sends it toprocessLine- Throws:
java.io.IOException- if there is an error.
-
processLine
protected abstract void processLine(java.lang.String line) throws java.io.IOExceptionProcesses a line.- Parameters:
line- the line to log.- Throws:
java.io.IOException- if there is an error.
-
processLine
protected void processLine(byte[] line) throws java.io.IOExceptionProcesses a line.This implementations invokes the string-arg version converting the byte array using the default encoding. Subclasses are encouraged to override this method (and provide a dummy implementation of the String-arg version) so they don't interfere with the encoding of the underlying stream.
- Parameters:
line- the line to log.- Throws:
java.io.IOException- if there is an error.- Since:
- Ant 1.8.3
-
close
public void close() throws java.io.IOExceptionWrites all remaining- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Overrides:
closein classjava.io.OutputStream- Throws:
java.io.IOException- if there is an error.
-
write
public final void write(byte[] b, int off, int len) throws java.io.IOExceptionWrite a block of characters to the output stream- Overrides:
writein classjava.io.OutputStream- Parameters:
b- the array containing the dataoff- the offset into the array where data startslen- the length of block- Throws:
java.io.IOException- if the data cannot be written into the stream.
-
-