com.Ostermiller.util Java Utilities


com.Ostermiller.util
Class Tabs

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

public class Tabs
extends 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
Author:
Stephen Ostermiller http://ostermiller.org/contact.pl?regarding=Java+Utilities

Field Summary
static int TABS
          Can be passed instead of a spaces argument to use tabs instead.
static String version
          Version number of this program
 
Constructor Summary
Tabs()
           
 
Method Summary
static boolean convert(File f)
          Change the tabs at the beginning of each line of the file to four spaces.
static boolean convert(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(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(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(InputStream in, 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(InputStream in, 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(InputStream in, 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(InputStream in, 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(InputStream in)
          Guess the number of spaces per tab at the beginning of each line.
static void main(String[] args)
          Converts the tabs in files, or standard input.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

version

public static final String version
Version number of this program

Since:
ostermillerutils 1.00.00
See Also:
Constant Field Values

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(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(InputStream in,
                              OutputStream out)
                       throws 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.
IOException - if an input or output error occurs.
Since:
ostermillerutils 1.00.00

convert

public static boolean convert(InputStream in,
                              OutputStream out,
                              int inputTabWidth)
                       throws 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.
IOException - if an input or output error occurs.
IllegalArgumentException - if tab widths are not between 1 and 20 or TABS.
Since:
ostermillerutils 1.00.00

convert

public static boolean convert(InputStream in,
                              OutputStream out,
                              int inputTabWidth,
                              int outputTabWidth)
                       throws 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.
IOException - if an input or output error occurs.
Since:
ostermillerutils 1.00.00

convert

public static boolean convert(InputStream in,
                              OutputStream out,
                              int inputTabWidth,
                              int outputTabWidth,
                              boolean binaryException)
                       throws 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.
IOException - if an input or output error occurs.
Since:
ostermillerutils 1.00.00

convert

public static boolean convert(File f)
                       throws 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.
IOException - if an input or output error occurs.
Since:
ostermillerutils 1.00.00

convert

public static boolean convert(File f,
                              int inputTabWidth)
                       throws 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.
IOException - if an input or output error occurs.
IllegalArgumentException - if tab widths are not between 1 and 20 or TABS.
Since:
ostermillerutils 1.00.00

convert

public static boolean convert(File f,
                              int inputTabWidth,
                              int outputTabWidth)
                       throws 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.
IOException - if an input or output error occurs.
Since:
ostermillerutils 1.00.00

convert

public static boolean convert(File f,
                              int inputTabWidth,
                              int outputTabWidth,
                              boolean binaryException)
                       throws 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.
IOException - if an input or output error occurs.
IllegalArgumentException - if tab widths are not between 1 and 20 or TABS.
Since:
ostermillerutils 1.00.00

guessTabWidth

public static int guessTabWidth(InputStream in)
                         throws 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:
IOException - if an input or output error occurs.
Since:
ostermillerutils 1.00.00

com.Ostermiller.util Java Utilities


Copyright © 2001-2012 by Stephen Ostermiller