Package org.scijava.util
Class LineOutputStream
- java.lang.Object
-
- java.io.OutputStream
-
- org.scijava.util.LineOutputStream
-
- All Implemented Interfaces:
Closeable,Flushable,AutoCloseable
public abstract class LineOutputStream extends OutputStream
This class hides a line-based output behind anOutputStream.Only the abstract method
println(String)needs to be overridden; the other methods inOutputStreamare overridden in this class already to buffer lines until they are complete and then flush them.- Author:
- Johannes Schindelin
-
-
Constructor Summary
Constructors Constructor Description LineOutputStream()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidclose()Flushes the current line buffer if any bytes are left in it.protected voidensure(int length)Increases the size of the line buffer if necessary.voidflush()If any bytes are in the current line buffer, output the line viaprintln(String), stripping any trailing new-line characters.abstract voidprintln(String line)This method is all that needs to be implemented.voidwrite(byte[] buf)Adds bytes to the current line buffer.voidwrite(byte[] buf, int offset, int length)Adds bytes to the current line buffer.voidwrite(int b)Adds a single byte to the current line buffer, orflush()the current line if it is a new-line character.
-
-
-
Method Detail
-
println
public abstract void println(String line) throws IOException
This method is all that needs to be implemented.- Parameters:
line- the line to print- Throws:
IOException
-
write
public void write(int b) throws IOExceptionAdds a single byte to the current line buffer, orflush()the current line if it is a new-line character.- Specified by:
writein classOutputStream- Parameters:
b- the byte to write- Throws:
IOException
-
write
public void write(byte[] buf) throws IOExceptionAdds bytes to the current line buffer. Whenever a new-line character is encountered,flush()the current line buffer.- Overrides:
writein classOutputStream- Parameters:
buf- the bytes to write- Throws:
IOException
-
write
public void write(byte[] buf, int offset, int length) throws IOExceptionAdds bytes to the current line buffer. Whenever a new-line character is encountered,flush()the current line buffer.- Overrides:
writein classOutputStream- Parameters:
buf- the bytes to writeoffset- the offset into the bufferlength- how many bytes to add- Throws:
IOException
-
close
public void close() throws IOExceptionFlushes the current line buffer if any bytes are left in it.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classOutputStream- Throws:
IOException
-
flush
public void flush() throws IOExceptionIf any bytes are in the current line buffer, output the line viaprintln(String), stripping any trailing new-line characters.- Specified by:
flushin interfaceFlushable- Overrides:
flushin classOutputStream- Throws:
IOException
-
ensure
protected void ensure(int length)
Increases the size of the line buffer if necessary.- Parameters:
length- the required minimal length
-
-