Class SourceCompactor
- All Implemented Interfaces:
CharStreamSource
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.
-
Constructor Summary
ConstructorsConstructorDescriptionSourceCompactor(Segment segment) Constructs a newSourceCompactorbased on the specifiedSegment. -
Method Summary
Modifier and TypeMethodDescriptionvoidappendTo(Appendable appendable) Appends the output to the specifiedAppendableobject.longReturns the estimated maximum number of characters in the output, or-1if no estimate is available.Returns the string to be used to represent a newline in the output.setNewLine(String newLine) Sets the string to be used to represent a newline in the output.toString()Returns the output as a string.voidWrites the output to the specifiedWriter.
-
Constructor Details
-
SourceCompactor
-
-
Method Details
-
writeTo
Description copied from interface:CharStreamSourceWrites the output to the specifiedWriter.- Specified by:
writeToin interfaceCharStreamSource- Parameters:
writer- the destinationjava.io.Writerfor the output.- Throws:
IOException- if an I/O exception occurs.
-
appendTo
Description copied from interface:CharStreamSourceAppends the output to the specifiedAppendableobject.- Specified by:
appendToin interfaceCharStreamSource- Parameters:
appendable- the destinationjava.lang.Appendableobject for the output.- Throws:
IOException- if an I/O exception occurs.
-
getEstimatedMaximumOutputLength
public long getEstimatedMaximumOutputLength()Description copied from interface:CharStreamSourceReturns the estimated maximum number of characters in the output, or-1if no estimate is available.The returned value should be used as a guide for efficiency purposes only, for example to set an initial
StringBuildercapacity. 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.
- Specified by:
getEstimatedMaximumOutputLengthin interfaceCharStreamSource- Returns:
- the estimated maximum number of characters in the output, or
-1if no estimate is available.
-
toString
Description copied from interface:CharStreamSourceReturns the output as a string.- Specified by:
toStringin interfaceCharStreamSource- Overrides:
toStringin classObject- Returns:
- the output as a string.
-
setNewLine
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 staticConfig.NewLineproperty.Specifying a
nullargument resets the property to its default value, which is to use the same new line string as is used in the source document.- Parameters:
newLine- the string to be used to represent a newline in the output, may benull.- Returns:
- this
SourceFormatterinstance, allowing multiple property setting methods to be chained in a single statement. - See Also:
-
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.- Returns:
- the string to be used to represent a newline in the output.
-