utils
Class StringTools

java.lang.Object
  extended by utils.StringTools

public class StringTools
extends java.lang.Object

Tools working on Strings (d'oh)

          Copyright (c) 2006 Sebastian Erdweg
          Copyright (c) 2007 Dominik Schulz
          Copyright (c) 2006 Florian Lindner
          Copyright (c) 2006 Betim Berjani

          This file is part of FlexiCrypt.

          FlexiCrypt is free software; you can redistribute it and/or modify
          it under the terms of the GNU General Public License as published by
          the Free Software Foundation; either version 2 of the License, or
          (at your option) any later version.

          FlexiCrypt is distributed in the hope that it will be useful,
          but WITHOUT ANY WARRANTY; without even the implied warranty of
          MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
          GNU General Public License for more details.

          You should have received a copy of the GNU General Public License
          along with FlexiCrypt; if not, write to the Free Software
          Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 

Author:
Sebastian, Dominik

Constructor Summary
private StringTools()
          This class provides only static methods.
 
Method Summary
static java.lang.String arrayToString(java.lang.Object[] arr)
           
static java.lang.String arrayToString(java.lang.Object[] arr, java.lang.String delim)
           
static java.lang.String firstLetterUpperCaseOfEachWord(java.lang.String string)
          Change the frist letter of each word in the string to upper case.
static java.lang.String getFormatedStringOfBytes(byte[] b, java.lang.String type)
          Get a formated string of bytes.
static java.lang.String getFormatedStringOfBytes(byte[] b, java.lang.String type, int maxLength)
          Get a formated String of bytes with a given maximum length.
static java.lang.String getStringOfByte(byte b)
           
static java.lang.String lineBreakAfterNchars(java.lang.String text, int breakAfter)
           
static java.lang.String readFileIntoString(java.io.File file)
          Read a file into a String
static java.lang.String[] readFileIntoStringArray(java.lang.String filename)
          Almost the same a readFileIntoString with the difference that the input is split a newlines and put into an array.
static java.lang.String removeLineBreaks(java.lang.String text)
          Remove every line-break from the string
static java.lang.String removeLineBreaks(java.lang.String text, int maxLength)
          Remove every line-break from the string.
static java.lang.String[] stringToArray(java.lang.String msg)
          Convert a string to an string array.
static java.lang.String[] stringToArray(java.lang.String msg, java.lang.String delim)
          Convert a string to an string array.
static java.util.ArrayList<java.lang.String> stringToArrayList(java.lang.String msg)
          Convert a string to an ArrayList.
static java.util.ArrayList<java.lang.String> stringToArrayList(java.lang.String msg, java.lang.String delim)
          Splits a String at the given delimiters and puts the result into an ArrayList
static void writeStringIntoFile(java.lang.String text, java.io.File file)
          Write a string into a file.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StringTools

private StringTools()
This class provides only static methods. No need to instanciate.

Method Detail

arrayToString

public static java.lang.String arrayToString(java.lang.Object[] arr)
Parameters:
arr - the array to convert to a string line by line
Returns:
the string from the array, every line sperated by \n

arrayToString

public static java.lang.String arrayToString(java.lang.Object[] arr,
                                             java.lang.String delim)
Parameters:
arr - the array to convert to a string line by line
delim - the delimiter between the lines
Returns:
the string from the array, every line sperated by delim

firstLetterUpperCaseOfEachWord

public static java.lang.String firstLetterUpperCaseOfEachWord(java.lang.String string)
Change the frist letter of each word in the string to upper case.

Parameters:
string - the string to change
Returns:
the changed string

getFormatedStringOfBytes

public static java.lang.String getFormatedStringOfBytes(byte[] b,
                                                        java.lang.String type,
                                                        int maxLength)
Get a formated String of bytes with a given maximum length.

Parameters:
b -
type -
maxLength -
Returns:
the formated string

getFormatedStringOfBytes

public static java.lang.String getFormatedStringOfBytes(byte[] b,
                                                        java.lang.String type)
Get a formated string of bytes. Useful for debugging.

Parameters:
b - the byte array
type - box, dotted or other
Returns:
the formated string

getStringOfByte

public static java.lang.String getStringOfByte(byte b)
Parameters:
b - a byte
Returns:
the corresponding string

lineBreakAfterNchars

public static java.lang.String lineBreakAfterNchars(java.lang.String text,
                                                    int breakAfter)
Parameters:
text - - The String that will be broken up into lines of n chars
breakAfter - - The max. number of chars per line
Returns:
the broken string

readFileIntoString

public static java.lang.String readFileIntoString(java.io.File file)
                                           throws java.io.IOException
Read a file into a String

Parameters:
file - the file to read from
Returns:
the content of the file
Throws:
java.io.IOException

readFileIntoStringArray

public static java.lang.String[] readFileIntoStringArray(java.lang.String filename)
Almost the same a readFileIntoString with the difference that the input is split a newlines and put into an array.

Parameters:
filename -
Returns:
the content of the file

stringToArray

public static java.lang.String[] stringToArray(java.lang.String msg)
Convert a string to an string array. Split at newlines (\n).

Parameters:
msg - string to split up
Returns:
the string array

stringToArray

public static java.lang.String[] stringToArray(java.lang.String msg,
                                               java.lang.String delim)
Convert a string to an string array. Split at arbitrary delimiters.

Parameters:
msg - string to split up
delim - the delimiter, e.g. "\n" or "\r\n" or maybe " ".
Returns:
the string array

stringToArrayList

public static java.util.ArrayList<java.lang.String> stringToArrayList(java.lang.String msg)
Convert a string to an ArrayList. Split at "\n".

Parameters:
msg - string to split up
Returns:
the ArrayList

stringToArrayList

public static java.util.ArrayList<java.lang.String> stringToArrayList(java.lang.String msg,
                                                                      java.lang.String delim)
Splits a String at the given delimiters and puts the result into an ArrayList

Parameters:
msg - string to split up
delim - the delimiter, e.g. "\n" or "\r\n" or maybe " ".
Returns:
the ArrayList

writeStringIntoFile

public static void writeStringIntoFile(java.lang.String text,
                                       java.io.File file)
                                throws java.io.IOException
Write a string into a file.

Parameters:
text - the string to write to the file.
file - the output file.
Throws:
java.io.IOException - if an I/O error ocurs.

removeLineBreaks

public static java.lang.String removeLineBreaks(java.lang.String text)
Remove every line-break from the string

Parameters:
text - w/ or w/o line breaks
Returns:
the string w/o line breaks.

removeLineBreaks

public static java.lang.String removeLineBreaks(java.lang.String text,
                                                int maxLength)
Remove every line-break from the string. Cut at the given maxLength.

Parameters:
text - w/ or w/o line breaks
maxLength - the maximum length of the returned string
Returns:
the string w/o line breaks.