iaik.me.utils
Class SysUtil

java.lang.Object
  |
  +--iaik.me.utils.SysUtil
Direct Known Subclasses:
SysUtilME, SysUtilTest.MySysUtil

public abstract class SysUtil
extends Object


Constructor Summary
SysUtil()
          The default constructor.
 
Method Summary
static Reader getLineReader(Reader reader)
          In case of the J2SE it turns the Reader into a BufferedReader.
static Writer getLineWriter(Writer writer)
          In case of the J2SE it turns the Writer into a PrintWriter.
static SysUtil getSysUtil()
          Returns the currently used SysUtil class.
static boolean loadLibrary(String libraryName)
          Loads a native code library.
static void nextBytes(Random random, byte[] data)
          Returns an array of random bytes, the CLDC spec. defines only functions for int- and long type arrays.
static InputStream openFileInputStream(String filename)
          Opens an InputStream to a given file.
static OutputStream openFileOutputStream(String filename)
          Opens an OutputStream to a given file.
static InputStream openURLInputStream(String protocolAndFilename)
          Opens an InputStream to a resource with a given URL.
static OutputStream openURLOutputStream(String protocolAndFilename)
          Opens an OutputStream to a resource with a given URL.
static void printLine(Writer writer)
          Writes a carriage return into the stream.
static void printLine(Writer writer, String msg)
          Writes a string with the specified writer.
static String readLine(Reader reader)
          Reads a line from an inputstream with a specific Reader.
static void setSysUtil(String className)
          Manually sets a specific SysUtil class that is used for fileoperations etc.
static void setSysUtil(SysUtil sysUtilParam)
          Manually sets a specific SysUtil class that is used for fileoperations etc.
abstract  Reader spiGetLineReader(Reader reader)
           
abstract  Writer spiGetLineWriter(Writer writer)
           
abstract  boolean spiLoadLibrary(String libraryName)
           
abstract  void spiNextBytes(Random random, byte[] data)
           
abstract  InputStream spiOpenFileInputStream(String filename)
           
abstract  OutputStream spiOpenFileOutputStream(String filename)
           
abstract  InputStream spiOpenURLInputStream(String filename)
           
abstract  OutputStream spiOpenURLOutputStream(String filename)
           
abstract  void spiPrintLine(Writer writer, String msg)
           
abstract  String spiReadLine(Reader reader)
           
abstract  void spiWaitKey()
           
static String toString(byte[] byteArray, int off, int len, String delimiter)
          Converts the specified subsequence of the given byte array into a hexadecimal string of the format: 01:23:34:56...
static void waitKey()
          Dummy Waikey function with no effect, because userinput depends on the device used.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SysUtil

public SysUtil()
The default constructor.
Method Detail

setSysUtil

public static void setSysUtil(String className)
                       throws InstantiationException
Manually sets a specific SysUtil class that is used for fileoperations etc. This class has to extend the SysUtil class and implement the according abstract functions from it.
Parameters:
classname - - the fully qualified name of the desired class.
Throws:
InstantiationException - if an instanciation exception occures (when the new class is not related to SysUtil or the class cannot be found)

setSysUtil

public static void setSysUtil(SysUtil sysUtilParam)
Manually sets a specific SysUtil class that is used for fileoperations etc. This class has to extend the SysUtil class and implement the according abstract functions from it.
Parameters:
SysUtilObject - a dynamicaly created SysUtil object

getSysUtil

public static SysUtil getSysUtil()
Returns the currently used SysUtil class.
Returns:
the class of the type SysUtil

loadLibrary

public static boolean loadLibrary(String libraryName)
                           throws Throwable
Loads a native code library.

The library is normaly searched for in the operatingsystems system directory. Check your operatingsystems documentation for further details.

Parameters:
libraryname -  
Returns:
true if library was succesfully loaded, false if not

openFileInputStream

public static InputStream openFileInputStream(String filename)
                                       throws IOException
Opens an InputStream to a given file. The file must already exist upon opening. This function uses the "file" protocol in the Connector class which may not be implemented on some platforms,

see the CLDC specification/documentation for further details.

For other protocols use openURLInputStream(String protocolAndFilename) instead.

Parameters:
filename - with path info
Returns:
InputStream to the file

openFileOutputStream

public static OutputStream openFileOutputStream(String filename)
                                         throws IOException
Opens an OutputStream to a given file. The file will be created if it does not exist. This function uses the "file" protocol in the Connector class which may not be implemented on some platforms,

see the CLDC specification/documentation for further details.

For other protocols use openURLOutputStream(String protocolAndFilename) instead.

Parameters:
filename - with path info
Returns:
OutputStream to the file

openURLInputStream

public static InputStream openURLInputStream(String protocolAndFilename)
                                      throws IOException
Opens an InputStream to a resource with a given URL. The resource must already exist upon opening. See J2ME documentation and RFC 2396 for more information about how a URL is defined. For example:

InputStream in = openURLInputStream("file://demo.txt");

or

InputStream in = openURLInputStream("http://www.server.com:80");

Parameters:
URL - to resource
Returns:
InputStream to the resource

openURLOutputStream

public static OutputStream openURLOutputStream(String protocolAndFilename)
                                        throws IOException
Opens an OutputStream to a resource with a given URL. See J2ME documentation and RFC 2396 for more information about how a URL is defined. For example:

OutputStream in = openURLOutputStream("file://demo.txt");

Parameters:
URL - to resource
Returns:
OutputStream to the resource

nextBytes

public static void nextBytes(Random random,
                             byte[] data)
Returns an array of random bytes, the CLDC spec. defines only functions for int- and long type arrays.
Parameters:
a - random number generator
a - byte array to put the result into

getLineReader

public static Reader getLineReader(Reader reader)
In case of the J2SE it turns the Reader into a BufferedReader. On then J2ME it does nothing with the Reader object, just return it.
Parameters:
a - Reader object
Returns:
a BufferedReader or just the Reader itself

readLine

public static String readLine(Reader reader)
                       throws IOException
Reads a line from an inputstream with a specific Reader. On J2SE it uses the BufferedReader on J2ME the standard Reader.
Parameters:
a - Reader object with an open stream.
Returns:
the read String

getLineWriter

public static Writer getLineWriter(Writer writer)
In case of the J2SE it turns the Writer into a PrintWriter. On then J2ME it does nothing with the Writer object, just return it.
Parameters:
a - Reader object
Returns:
PrintWriter or Writer object

printLine

public static void printLine(Writer writer)
Writes a carriage return into the stream. On J2SE it uses the PrintWriter on J2ME the standard Reader to write the string.
Parameters:
a - Writer object with an open stream.

printLine

public static void printLine(Writer writer,
                             String msg)
Writes a string with the specified writer. On J2SE it uses the PrintWriter on J2ME the standard Reader to write the string.
Parameters:
a - Writer object with an open stream.

waitKey

public static void waitKey()
Dummy Waikey function with no effect,

because userinput depends on the device used. There is only a text output.


toString

public static String toString(byte[] byteArray,
                              int off,
                              int len,
                              String delimiter)
Converts the specified subsequence of the given byte array into a hexadecimal string of the format: 01:23:34:56... .

Starting at off, len bytes will be converted and returned as hexadecimal string, e.g.:

 byte[] arr = ...;
 System.out.println(Util.toString(arr, 0, 3));
 
Parameters:
byteArray - the byte array containing the data
off - the offset indicating the start position within the given byte array; the following len bytes will be converted into a hexadecimal string
len - how many bytes shall be written
delimiter - the delimiter to be used for separating the hex values, e.g. ":" (specify "" for not using a delimiter)
Returns:
the string representation

spiLoadLibrary

public abstract boolean spiLoadLibrary(String libraryName)
                                throws Throwable

spiOpenFileInputStream

public abstract InputStream spiOpenFileInputStream(String filename)
                                            throws IOException

spiOpenFileOutputStream

public abstract OutputStream spiOpenFileOutputStream(String filename)
                                              throws IOException

spiOpenURLInputStream

public abstract InputStream spiOpenURLInputStream(String filename)
                                           throws IOException

spiOpenURLOutputStream

public abstract OutputStream spiOpenURLOutputStream(String filename)
                                             throws IOException

spiNextBytes

public abstract void spiNextBytes(Random random,
                                  byte[] data)

spiGetLineReader

public abstract Reader spiGetLineReader(Reader reader)

spiReadLine

public abstract String spiReadLine(Reader reader)
                            throws IOException

spiGetLineWriter

public abstract Writer spiGetLineWriter(Writer writer)

spiPrintLine

public abstract void spiPrintLine(Writer writer,
                                  String msg)

spiWaitKey

public abstract void spiWaitKey()

This Javadoc may contain text parts from IETF Internet Standard specifications, see copyright note) and RSA Data Security Public-Key Cryptography Standards (see copyright note).

IAIK-JCE ME 3.04, (c) 2002 IAIK, (c) 2003 to 2006 Stiftung SIC