Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## net.htmlparser.jericho
Class SourceCompactor

    java.lang.Object
      SourceCompactor

All Implemented Interfaces:
  CharStreamSource

    public final class SourceCompactor

extends java.lang.Object
implements CharStreamSource

Compacts HTML source by removing all unnecessary white space.

Use one of the following methods to obtain the output:

- `writeTo(Writer)`
- `appendTo(Appendable)`
- `toString()`
- `CharStreamSourceUtil.getReader(this)`

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
`SourceCompactor(Segment segment)` Constructs a new `SourceCompactor` based on the specified `Segment`.

Method Summary
`void` | `appendTo(java.lang.Appendable appendable)` Appends the output to the specified `Appendable` object.
`long` | `getEstimatedMaximumOutputLength()` Returns the estimated maximum number of characters in the output, or `-1` if no estimate is available.
`java.lang.String` | `getNewLine()` Returns the string to be used to represent a newline in the output.
`SourceCompactor` | `setNewLine(java.lang.String newLine)` Sets the string to be used to represent a newline in the output.
`java.lang.String` | `toString()` Returns the output as a string.
`void` | `writeTo(java.io.Writer writer)` Writes the output to the specified `Writer`.

Methods inherited from class java.lang.Object
`clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

Constructor Detail

### SourceCompactor

    public SourceCompactor(Segment segment)

  Constructs a new `SourceCompactor` based on the specified `Segment`.

  Parameters:
    `segment` - the segment containing the HTML to be compacted.

Method Detail

### writeTo

    public void writeTo(java.io.Writer writer)
                 throws java.io.IOException

  Description copied from interface: `CharStreamSource`
  Writes the output to the specified `Writer`.

  Specified by:
    `writeTo` in interface `CharStreamSource`
  Parameters:
    `writer` - the destination `java.io.Writer` for the output.
  Throws:
    `java.io.IOException` - if an I/O exception occurs.

### appendTo

    public void appendTo(java.lang.Appendable appendable)
                  throws java.io.IOException

  Description copied from interface: `CharStreamSource`
  Appends the output to the specified `Appendable` object.

  Specified by:
    `appendTo` in interface `CharStreamSource`
  Parameters:
    `appendable` - the destination `java.lang.Appendable` object for the output.
  Throws:
    `java.io.IOException` - if an I/O exception occurs.

### getEstimatedMaximumOutputLength

    public long getEstimatedMaximumOutputLength()

  Description copied from interface: `CharStreamSource`
  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 `StringBuilder` 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.

  Specified by:
    `getEstimatedMaximumOutputLength` in interface `CharStreamSource`
  Returns:
    the estimated maximum number of characters in the output, or `-1` if no estimate is available.

### toString

    public java.lang.String toString()

  Description copied from interface: `CharStreamSource`
  Returns the output as a string.

  Specified by:
    `toString` in interface `CharStreamSource`
  Overrides:
    `toString` in class `java.lang.Object`
  Returns:
    the output as a string.

### setNewLine

    public SourceCompactor setNewLine(java.lang.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.

  Parameters:
    `newLine` - the string to be used to represent a newline in the output, may be `null`.
  Returns:
    this `SourceFormatter` instance, allowing multiple property setting methods to be chained in a single statement.
  See Also:
    `getNewLine()`

### getNewLine

    public java.lang.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.

  Returns:
    the string to be used to represent a newline in the output.

Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD