Package com.sun.javatest.util
Class WrapWriter
java.lang.Object
java.io.Writer
com.sun.javatest.util.WrapWriter
- All Implemented Interfaces:
Closeable
,Flushable
,Appendable
,AutoCloseable
A writer that will automatically word wrap lines to fit within
left and right margins.
-
Field Summary
-
Constructor Summary
ConstructorsConstructorDescriptionWrapWriter
(OutputStream out) Create a WrapWriter object that will write to a given stream.WrapWriter
(Writer out) Create a WrapWriter object that will write to a given stream. -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
void
flush()
int
Get the number of characters that have been written so far on the current line.int
Get the position for the left margin for the text stream.int
Get the position for the right margin for the text stream.void
setLeftMargin
(int m) Set the position for the left margin for the text stream.void
setRightMargin
(int m) Set the position for the right margin for the text stream.void
write
(char c) Write a character to the stream.void
write
(char[] cbuf, int off, int len)
-
Constructor Details
-
WrapWriter
Create a WrapWriter object that will write to a given stream.- Parameters:
out
- the stream to which the WrapWriter will write
-
WrapWriter
Create a WrapWriter object that will write to a given stream.- Parameters:
out
- the stream to which the WrapWriter will write
-
-
Method Details
-
getLeftMargin
public int getLeftMargin()Get the position for the left margin for the text stream.- Returns:
- the position for the left margin
- See Also:
-
setLeftMargin
public void setLeftMargin(int m) Set the position for the left margin for the text stream.- Parameters:
m
- the position for the left margin- Throws:
IllegalArgumentException
- if the value is negative or greater than the current value of the right margin- See Also:
-
getRightMargin
public int getRightMargin()Get the position for the right margin for the text stream.- Returns:
- the position for the right margin
- See Also:
-
setRightMargin
public void setRightMargin(int m) Set the position for the right margin for the text stream.- Parameters:
m
- the position for the right margin- Throws:
IllegalArgumentException
- if the value is less than the current value of the left margin- See Also:
-
getCharsOnLineSoFar
public int getCharsOnLineSoFar()Get the number of characters that have been written so far on the current line. This will not include any characters in the last word that have not yet been written. Use flush() or write a white space character to force out the last word written.- Returns:
- the number of characters that have been written so far on the line
-
close
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Specified by:
close
in classWriter
- Throws:
IOException
-
flush
- Specified by:
flush
in interfaceFlushable
- Specified by:
flush
in classWriter
- Throws:
IOException
-
write
- Specified by:
write
in classWriter
- Throws:
IOException
-
write
Write a character to the stream. Non-white-space characters will be buffered until a white space character is written. When a white space character is written, the buffered characters will be written on the current line, if they will fit before the right margin, otherwise a newline and spaces will be inserted so that the buffered characters appear on the next line starting at the left margin.- Parameters:
c
- the character to be written- Throws:
IOException
- if there is a problem writing to the underlying stream
-