au.id.jericho.lib.html
Class SourceCompactor
java.lang.Object
au.id.jericho.lib.html.SourceCompactor
- CharStreamSource
public final class SourceCompactor
extends java.lang.Object
Compacts HTML source by removing all unnecessary white space.
Use one of the following methods to obtain the output:
The output text is functionally equivalent to the original source and should be rendered identically.
Compacting an entire
Source
object performs a
full sequential parse automatically.
SourceCompactor
public SourceCompactor(Segment segment)
Constructs a new
SourceFormatter
based on the specified
Segment
.
segment
- the segment containing the HTML to be formatted.
getEstimatedMaximumOutputLength
public long getEstimatedMaximumOutputLength()
Returns the estimated maximum number of characters in the output, or
-1
if no estimate is available.
The returned value should be used as a guide for efficiency purposes only, for example to set an initial
StringBuffer
capacity.
There is no guarantee that the length of the output is indeed less than this value,
as classes implementing this method often use assumptions based on typical usage to calculate the estimate.
Although implementations of this method should never return a value less than -1, users of this method must not assume that this will always be the case.
Standard practice is to interpret any negative value as meaning that no estimate is available.
- getEstimatedMaximumOutputLength in interface CharStreamSource
- the estimated maximum number of characters in the output, or
-1
if no estimate is available.
getNewLine
public String getNewLine()
Returns the string to be used to represent a
newline in the output.
See the
setNewLine(String)
method for a full description of this property.
- the string to be used to represent a newline in the output.
setNewLine
public SourceCompactor setNewLine(String newLine)
Sets the string to be used to represent a
newline in the output.
The default is to use the same new line string as is used in the source document, which is determined via the
Source.getNewLine()
method.
If the source document does not contain any new lines, a "best guess" is made by either taking the new line string of a previously parsed document,
or using the value from the static
Config.NewLine
property.
Specifying a
null
argument resets the property to its default value, which is to use the same new line string as is used in the source document.
newLine
- the string to be used to represent a newline in the output, may be null
.
- this
SourceFormatter
instance, allowing multiple property setting methods to be chained in a single statement.
writeTo
public void writeTo(Writer writer)
throws IOException
Writes the output to the specified Writer
.
- writeTo in interface CharStreamSource
writer
- the destination java.io.Writer
for the output.