it.unimo.dbgroup.momis.tools
Class Tools

java.lang.Object
  extended byit.unimo.dbgroup.momis.tools.Tools

public class Tools
extends java.lang.Object

Collection of various useful static tools methods.

Author:
Alberto Corni, Gen 2000

Constructor Summary
Tools()
           
 
Method Summary
static java.lang.String bundedStringCreate(java.util.Collection c, java.lang.String boundary)
          Converts a Collection of strings in a single string formatted with a mime like formalism:
The first line contains a boundary that separates string
example:
static java.util.Vector bundedStringDecode(java.lang.String bounded)
          a single string formatted with a mime like formalism in a Vector of strings.
static java.lang.String getLastFieldBySeparator(java.lang.String s, char separator)
           
static java.lang.String getObjectInfo(java.lang.Object o)
          Return information about the given object
Information are:
- class name
- list of public methods
static boolean isReadable(java.lang.String fileName)
          Tests if a file exists and is redable.
static java.lang.String leggiFile(java.lang.String fileName)
          Reads a file and put it in a string using a StringBuffer.
static byte[] leggiFileB(java.lang.String fileName)
          Reads a file and put it into an array of Bytes.
static void main(java.lang.String[] args)
          Routine used to test the class.
static java.lang.Object mdeserialize(byte[] strm)
          Routine used for Object deserialization
static java.lang.Object mDeserialize64(java.lang.String strm)
          Routine used for Object deserialization
static byte[] mserialize(java.lang.Object ser)
          Routine used for Object serialization
static java.lang.String mSerialize64(java.lang.Object ser)
          Serializae an Object in a base64 String.
static java.util.Map readConfFile(java.lang.String fileName)
          Parse a simple configuration file.
static void scriviFile(java.lang.String fileName, byte[] buf)
          Write the content of an array of bytes in a file.
static void scriviFile(java.lang.String fileName, java.lang.String s)
          Write the content of a string in a file.
static java.util.Vector splitString(java.lang.String s, char separator)
          Split a string separated by the "separator" char in single strings.
static java.lang.String stringCenterAndPad(java.lang.String sinput, int length)
          Returns a string of the given length, centering the given string.
static java.lang.String stringInsertAnte(java.lang.String s, java.lang.String cante)
          Add characters before each line of a string.
static java.lang.String stringReplaceInString(java.lang.String sin, java.lang.String sold, java.lang.String snew)
          in a strings, replace a given pattern with one other.
static java.lang.String stringStackTrace(java.lang.Exception e)
          Return the stack trace of an exception in a string.
static java.lang.String stripAnsi(java.lang.String sin)
          Strips the ANSI char from a string.
static java.lang.String stripCrtlM(java.lang.String sin)
          Strips the ^M char in the given string.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Tools

public Tools()
Method Detail

leggiFile

public static java.lang.String leggiFile(java.lang.String fileName)
Reads a file and put it in a string using a StringBuffer.

Parameters:
fileName - name of the file to be read.
Returns:
the string with the file content.

scriviFile

public static void scriviFile(java.lang.String fileName,
                              java.lang.String s)
Write the content of a string in a file.

Parameters:
fileName - name of the file to be written.
s - file content.

leggiFileB

public static byte[] leggiFileB(java.lang.String fileName)
Reads a file and put it into an array of Bytes.

Parameters:
fileName - name of the file to be read.
Returns:
the string with the file content.

scriviFile

public static void scriviFile(java.lang.String fileName,
                              byte[] buf)
Write the content of an array of bytes in a file.

Parameters:
fileName - name of the file to be written.
buf - file content.

getObjectInfo

public static java.lang.String getObjectInfo(java.lang.Object o)
Return information about the given object
Information are:
- class name
- list of public methods


stripAnsi

public static java.lang.String stripAnsi(java.lang.String sin)
Strips the ANSI char from a string.

Parameters:
sin - string to be cleaned.

stripCrtlM

public static java.lang.String stripCrtlM(java.lang.String sin)
Strips the ^M char in the given string.

Parameters:
sin - string to be cleaned.

stringCenterAndPad

public static java.lang.String stringCenterAndPad(java.lang.String sinput,
                                                  int length)
Returns a string of the given length, centering the given string.

Parameters:
sinput - string to be centered.
length - length of the ouput string.

readConfFile

public static java.util.Map readConfFile(java.lang.String fileName)
Parse a simple configuration file.

Example of configuration file:

 #
 # Configuration file test
 #
 #
 param1=first parameter
 param2=10
 param3=test
 
 other1=o1
 other2=02
 stop=stop
 

Parameters:
fileName - name of the configuration file.
Returns:
a Map filled with the configuration content.

isReadable

public static boolean isReadable(java.lang.String fileName)
Tests if a file exists and is redable.

Parameters:
fileName - name of the file to be read.
Returns:
true if the file is readable.

mserialize

public static byte[] mserialize(java.lang.Object ser)
Routine used for Object serialization

Parameters:
ser - Object have to serialize
Returns:
String with the object content.

mdeserialize

public static java.lang.Object mdeserialize(byte[] strm)
Routine used for Object deserialization

[9 Mar 2000, Alberto Corni] removed deprecations

Parameters:
strm - Input string with serialized object

mSerialize64

public static java.lang.String mSerialize64(java.lang.Object ser)
Serializae an Object in a base64 String.

Parameters:
ser - Object to serialize
Returns:
Serialized object in a standard string.

mDeserialize64

public static java.lang.Object mDeserialize64(java.lang.String strm)
Routine used for Object deserialization

[9 Mar 2000, Alberto Corni] removed deprecations

Parameters:
strm - Input string with serialized object

stringInsertAnte

public static java.lang.String stringInsertAnte(java.lang.String s,
                                                java.lang.String cante)
Add characters before each line of a string.

Parameters:
s - string to convert.
cante - characters to antepone.
Returns:
The string with the anteponed chars.

stringStackTrace

public static java.lang.String stringStackTrace(java.lang.Exception e)
Return the stack trace of an exception in a string.


splitString

public static java.util.Vector splitString(java.lang.String s,
                                           char separator)
Split a string separated by the "separator" char in single strings.

Parameters:
s - the string to split
separator - the character separator of the various strings
Returns:
a vector of strings

stringReplaceInString

public static java.lang.String stringReplaceInString(java.lang.String sin,
                                                     java.lang.String sold,
                                                     java.lang.String snew)
in a strings, replace a given pattern with one other.

Parameters:
sin - string to be modified.
sold - The string to replace
snew - The string to replace with

bundedStringCreate

public static java.lang.String bundedStringCreate(java.util.Collection c,
                                                  java.lang.String boundary)
Converts a Collection of strings in a single string formatted with a mime like formalism:
The first line contains a boundary that separates string
example:
 ----thisIsTheBoundaryLine-------
 this is the string at the first position
 ----thisIsTheBoundaryLine-------
 this is the string at the Second position
 ----thisIsTheBoundaryLine-------
 this is the string at the last position
 


bundedStringDecode

public static java.util.Vector bundedStringDecode(java.lang.String bounded)
a single string formatted with a mime like formalism in a Vector of strings.
This reverses the bundedStringCreate method.


getLastFieldBySeparator

public static java.lang.String getLastFieldBySeparator(java.lang.String s,
                                                       char separator)

main

public static void main(java.lang.String[] args)
Routine used to test the class.

Tests the tools.



Universita' di Modena e Reggio Emilia