PMII - JAVA-Packages - Principia Mathematica II

com.meyling.principia.io
Class Utility

java.lang.Object
  |
  +--com.meyling.principia.io.Utility

public class Utility
extends Object

A collection of usefull static methods.

Version:
$Revision: 1.5 $
Author:
Michael Meyling

Method Summary
static StringBuffer getSpaces(int length)
          Get amount of spaces.
static boolean isLetterDigitString(String text)
          Tests if given String begins with a letter and contains only letters and digits.
static void loadFile(File file, StringBuffer buffer)
          Reads contents of a file into a string buffer.
static String loadFile(String filename)
          Reads a file and returns the contents as a String.
static void loadFile(String filename, StringBuffer buffer)
          Reads contents of a file into a string buffer.
static String quote(String unquoted)
          Quotes a String.
static String replace(String text, String search, String replace)
          Replaces all occurences of search in text by replace and returns the result.
static void saveFile(String filename, String text)
          Saves a String in a file.
static void saveFile(String filename, StringBuffer text)
          Saves a String in a file.
static void waitln()
          Waits til a '\n' was read from System.in.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

loadFile

public static final String loadFile(String filename)
                             throws IOException
Reads a file and returns the contents as a String.
Parameters:
filename - name of the file (could include path)
Returns:
contents of file
Throws:
IOException - if a file exception occured

loadFile

public static final void loadFile(String filename,
                                  StringBuffer buffer)
                           throws IOException
Reads contents of a file into a string buffer.
Parameters:
filename - name of the file (could include path)
buffer - buffer to fill with file contents
Throws:
IOException - if a file exception occured

loadFile

public static final void loadFile(File file,
                                  StringBuffer buffer)
                           throws IOException
Reads contents of a file into a string buffer.
Parameters:
file - this file will be loaded
buffer - buffer to fill with file contents
Throws:
IOException - if a file exception occured

saveFile

public static final void saveFile(String filename,
                                  String text)
                           throws IOException
Saves a String in a file. In case of an IO error a message is written to System.out.
Parameters:
filename - name of the file (could include path)
text - data to save in the file
Throws:
IOException - if a file exception occured

saveFile

public static final void saveFile(String filename,
                                  StringBuffer text)
                           throws IOException
Saves a String in a file. In case of an IO error a message is written to System.out.
Parameters:
filename - name of the file (could include path)
text - data to save in the file
Throws:
IOException - if a file exception occured

quote

public static final String quote(String unquoted)
Quotes a String. If no quotes exist in the String, a quote character is appended at the beginning and the end of the String.
Parameters:
unquoted - the ungequoted" String
Returns:
quoted String
Throws:
NullPointerException - if unquoted == null

isLetterDigitString

public static final boolean isLetterDigitString(String text)
Tests if given String begins with a letter and contains only letters and digits.
Parameters:
text - test this
Returns:
is text only made of letters and digits and has a leading letter?
Throws:
NullPointerException - if text == null

replace

public static final String replace(String text,
                                   String search,
                                   String replace)
Replaces all occurences of search in text by replace and returns the result.
Parameters:
text - text to work on
search - replace this text by replace
replace - replacement for search
Returns:
resulting string

waitln

public static final void waitln()
Waits til a '\n' was read from System.in.

getSpaces

public static final StringBuffer getSpaces(int length)
Get amount of spaces.
Parameters:
length - number of spaces
Returns:
String containig exactly number spaces

PMII - JAVA-Packages - Principia Mathematica II

©left GNU General Public Licence
All Rights Reserved.