com.Ostermiller.util
Class Tabs

java.lang.Object
  extended by com.Ostermiller.util.Tabs

public class Tabs
extends java.lang.Object

Stream editor to alter the line separators on text to match that of a given platform. More information about this class is available from ostermiller.org.

Since:
ostermillerutils 1.00.00

Field Summary
protected static java.util.ResourceBundle labels
          Locale specific strings displayed to the user.
static int TABS
          Can be passed instead of a spaces argument to use tabs instead.
static java.lang.String version
          Version number of this program
 
Constructor Summary
Tabs()
           
 
Method Summary
static boolean convert(java.io.File f)
          Change the tabs at the beginning of each line of the file to four spaces.
static boolean convert(java.io.File f, int inputTabWidth)
          Change the tabs at the beginning of each line of the file to the specified number of spaces.
static boolean convert(java.io.File f, int inputTabWidth, int outputTabWidth)
          Change the tabs at the beginning of each line of the file to the specified number of spaces or the other way around.
static boolean convert(java.io.File f, int inputTabWidth, int outputTabWidth, boolean binaryException)
          Change the tabs at the beginning of each line of the file to the specified number of spaces or the other way around.
static boolean convert(java.io.InputStream in, java.io.OutputStream out)
          Read form the input stream, changing the tabs at the beginning of each line to four spaces, write the result to the output stream.
static boolean convert(java.io.InputStream in, java.io.OutputStream out, int inputTabWidth)
          Read form the input stream, changing the tabs at the beginning of each line to the specified number of spaces, write the result to the output stream.
static boolean convert(java.io.InputStream in, java.io.OutputStream out, int inputTabWidth, int outputTabWidth)
          Read form the input stream, changing the tabs at the beginning of each line to the specified number of spaces or the other way around, write the result to the output stream.
static boolean convert(java.io.InputStream in, java.io.OutputStream out, int inputTabWidth, int outputTabWidth, boolean binaryException)
          Read form the input stream, changing the tabs at the beginning of each line to the specified number of spaces or the other way around, write the result to the output stream.
static int guessTabWidth(java.io.InputStream in)
          Guess the number of spaces per tab at the beginning of each line.
static void main(java.lang.String[] args)
          Converts the tabs in files, or standard input.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

version

public static final java.lang.String version
Version number of this program

Since:
ostermillerutils 1.00.00
See Also:
Constant Field Values

labels

protected static java.util.ResourceBundle labels
Locale specific strings displayed to the user.

Since:
ostermillerutils 1.00.00

TABS

public static final int TABS
Can be passed instead of a spaces argument to use tabs instead.

Since:
ostermillerutils 1.00.00
See Also:
Constant Field Values
Constructor Detail

Tabs

public Tabs()
Method Detail

main

public static void main(java.lang.String[] args)
Converts the tabs in files, or standard input. Run with --help argument for more information.

Parameters:
args - Command line arguments.
Since:
ostermillerutils 1.00.00

convert

public static boolean convert(java.io.InputStream in,
                              java.io.OutputStream out)
                       throws java.io.IOException
Read form the input stream, changing the tabs at the beginning of each line to four spaces, write the result to the output stream.

Parameters:
in - stream that contains the text which needs line number conversion.
out - stream where converted text is written.
Returns:
true if the output was modified from the input, false if it is exactly the same
Throws:
BinaryDataException - if non-text data is encountered.
java.io.IOException - if an input or output error occurs.
Since:
ostermillerutils 1.00.00

convert

public static boolean convert(java.io.InputStream in,
                              java.io.OutputStream out,
                              int inputTabWidth)
                       throws java.io.IOException
Read form the input stream, changing the tabs at the beginning of each line to the specified number of spaces, write the result to the output stream.

Parameters:
in - stream that contains the text which needs line number conversion.
out - stream where converted text is written.
inputTabWidth - number of spaces used instead of a tab in the input.
Returns:
true if the output was modified from the input, false if it is exactly the same
Throws:
BinaryDataException - if non-text data is encountered.
java.io.IOException - if an input or output error occurs.
java.lang.IllegalArgumentException - if tab widths are not between 1 and 20 or TABS.
Since:
ostermillerutils 1.00.00

convert

public static boolean convert(java.io.InputStream in,
                              java.io.OutputStream out,
                              int inputTabWidth,
                              int outputTabWidth)
                       throws java.io.IOException
Read form the input stream, changing the tabs at the beginning of each line to the specified number of spaces or the other way around, write the result to the output stream. The current system's line separator is used.

Parameters:
in - stream that contains the text which needs line number conversion.
out - stream where converted text is written.
inputTabWidth - number of spaces used instead of a tab in the input.
outputTabWidth - TABS if tabs should be used, otherwise, number of spaces to use.
Returns:
true if the output was modified from the input, false if it is exactly the same
Throws:
BinaryDataException - if non-text data is encountered.
java.io.IOException - if an input or output error occurs.
Since:
ostermillerutils 1.00.00

convert

public static boolean convert(java.io.InputStream in,
                              java.io.OutputStream out,
                              int inputTabWidth,
                              int outputTabWidth,
                              boolean binaryException)
                       throws java.io.IOException
Read form the input stream, changing the tabs at the beginning of each line to the specified number of spaces or the other way around, write the result to the output stream. The current system's line separator is used.

Parameters:
in - stream that contains the text which needs line number conversion.
out - stream where converted text is written.
inputTabWidth - number of spaces used instead of a tab in the input.
outputTabWidth - TABS if tabs should be used, otherwise, number of spaces to use.
binaryException - throw an exception and abort the operation if binary data is encountered and binaryExcepion is false.
Returns:
true if the output was modified from the input, false if it is exactly the same.
Throws:
BinaryDataException - if non-text data is encountered.
java.io.IOException - if an input or output error occurs.
Since:
ostermillerutils 1.00.00

convert

public static boolean convert(java.io.File f)
                       throws java.io.IOException
Change the tabs at the beginning of each line of the file to four spaces. Guess the tab width of the input file.

Parameters:
f - File to be converted.
Returns:
true if the file was modified, false if it was already in the correct format
Throws:
BinaryDataException - if non-text data is encountered.
java.io.IOException - if an input or output error occurs.
Since:
ostermillerutils 1.00.00

convert

public static boolean convert(java.io.File f,
                              int inputTabWidth)
                       throws java.io.IOException
Change the tabs at the beginning of each line of the file to the specified number of spaces.

Parameters:
f - File to be converted.
inputTabWidth - number of spaces used instead of a tab in the input, or TAB to guess.
Returns:
true if the output was modified from the input, false if it is exactly the same
Throws:
BinaryDataException - if non-text data is encountered.
java.io.IOException - if an input or output error occurs.
java.lang.IllegalArgumentException - if tab widths are not between 1 and 20 or TABS.
Since:
ostermillerutils 1.00.00

convert

public static boolean convert(java.io.File f,
                              int inputTabWidth,
                              int outputTabWidth)
                       throws java.io.IOException
Change the tabs at the beginning of each line of the file to the specified number of spaces or the other way around.

Parameters:
f - File to be converted.
inputTabWidth - number of spaces used instead of a tab in the input, or TAB to guess.
outputTabWidth - true if tabs should be used, false if spaces should be used.
Returns:
true if the output was modified from the input, false if it is exactly the same
Throws:
BinaryDataException - if non-text data is encountered.
java.io.IOException - if an input or output error occurs.
Since:
ostermillerutils 1.00.00

convert

public static boolean convert(java.io.File f,
                              int inputTabWidth,
                              int outputTabWidth,
                              boolean binaryException)
                       throws java.io.IOException
Change the tabs at the beginning of each line of the file to the specified number of spaces or the other way around.

Parameters:
f - File to be converted.
inputTabWidth - number of spaces used instead of a tab in the input, or TABS to guess.
outputTabWidth - true if tabs should be used, false if spaces should be used.
binaryException - throw an exception and abort the operation if binary data is encountered and binaryExcepion is false.
Returns:
true if the file was modified, false if it was already in the correct format
Throws:
BinaryDataException - if non-text data is encountered.
java.io.IOException - if an input or output error occurs.
java.lang.IllegalArgumentException - if tab widths are not between 1 and 20 or TABS.
Since:
ostermillerutils 1.00.00

guessTabWidth

public static int guessTabWidth(java.io.InputStream in)
                         throws java.io.IOException
Guess the number of spaces per tab at the beginning of each line.

Parameters:
in - Input stream for which to guess tab width
Returns:
the least value (two or greater) which has some line that starts with n times spaces for n zero to max spaces starting a line.
Throws:
java.io.IOException - if an input or output error occurs.
Since:
ostermillerutils 1.00.00