FileDocCategorySizeDatePackage
TabsToSpaces.javaAPI DocApache Ant 1.704539Wed Dec 13 06:16:22 GMT 2006org.apache.tools.ant.filters

TabsToSpaces

public final class TabsToSpaces extends BaseParamFilterReader implements ChainableReader
Converts tabs to spaces. Example:
<tabtospaces tablength="8"/>
Or:
<filterreader classname="org.apache.tools.ant.filters.TabsToSpaces">
<param name="tablength" value="8"/>
</filterreader>

Fields Summary
private static final int
DEFAULT_TAB_LENGTH
The default tab length.
private static final String
TAB_LENGTH_KEY
Parameter name for the length of a tab.
private int
tabLength
Tab length in this filter.
private int
spacesRemaining
The number of spaces still to be read to represent the last-read tab.
Constructors Summary
public TabsToSpaces()
Constructor for "dummy" instances.

see
BaseFilterReader#BaseFilterReader()


               
      
        super();
    
public TabsToSpaces(Reader in)
Creates a new filtered reader.

param
in A Reader object providing the underlying stream. Must not be null.

        super(in);
    
Methods Summary
public java.io.Readerchain(java.io.Reader rdr)
Creates a new TabsToSpaces using the passed in Reader for instantiation.

param
rdr A Reader object providing the underlying stream. Must not be null.
return
a new filter based on this configuration, but filtering the specified reader

        TabsToSpaces newFilter = new TabsToSpaces(rdr);
        newFilter.setTablength(getTablength());
        newFilter.setInitialized(true);
        return newFilter;
    
private intgetTablength()
Returns the tab length.

return
the number of spaces used when converting a tab

        return tabLength;
    
private voidinitialize()
Parses the parameters to set the tab length.

        Parameter[] params = getParameters();
        if (params != null) {
            for (int i = 0; i < params.length; i++) {
                if (params[i] != null) {
                    if (TAB_LENGTH_KEY.equals(params[i].getName())) {
                        tabLength =
                            new Integer(params[i].getValue()).intValue();
                        break;
                    }
                }
            }
        }
    
public intread()
Returns the next character in the filtered stream, converting tabs to the specified number of spaces.

return
the next character in the resulting stream, or -1 if the end of the resulting stream has been reached
exception
IOException if the underlying stream throws an IOException during reading

        if (!getInitialized()) {
            initialize();
            setInitialized(true);
        }

        int ch = -1;

        if (spacesRemaining > 0) {
            spacesRemaining--;
            ch = ' ";
        } else {
            ch = in.read();
            if (ch == '\t") {
                spacesRemaining = tabLength - 1;
                ch = ' ";
            }
        }
        return ch;
    
public voidsetTablength(int tabLength)
Sets the tab length.

param
tabLength the number of spaces to be used when converting a tab.

        this.tabLength = tabLength;