|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--iaik.me.utils.Util
This class provides several, often used methods for string/byte conversion, stream operations etc. .
All methods are static
so this class needs not to be instantiated.
Method Summary | |
static byte[] |
concat(byte[] b1,
byte[] b2)
Concatenates two bytearrays and returns a new bytearray of the size form bytearray one plus the size from bytearray two. |
static byte[] |
decodeByteArray(String s)
Decodes a given Base64 coded string and returns the values in a byte array. |
static int[] |
decodeIntArray(String s)
Decodes a given Base64 coded string and returns the values in an integerarray. |
static boolean |
equals(Object a,
Object b)
Indicates whether some other object is "equal to" this one. |
static Reader |
getASCIIReader(InputStream in)
Fertches a reader that returns data from the stream assuming that ASCII encoding is used. |
static Writer |
getASCIIWriter(OutputStream out)
Fetches a writer that writes data to the stream in ASCII encoding. |
static int |
hashCode(byte[] data)
Generates a hashcode from a given bytearray. |
static int |
hashCode(Object obj)
Generates a hashcode for a given object. |
static byte[] |
increment(byte[] b)
Increments each value of a byte array (b[0]++, b[1]++ ...). |
static boolean |
isAvailable(String className)
Checks whether a given class is available or not. |
static boolean |
isNull(Object[] obj)
Checks if the objectarray is set to null. |
static Class |
loadClass(String className)
Loads a given class via the Class.forName(....) method.
|
static int |
max(int a,
int b)
Returns the bigger one of two integers. |
static int |
min(int a,
int b)
Returns the lower one of two integers. |
static byte[] |
readCompleteStream(InputStream in)
Read the contents of the stream into a bytearray. |
static int |
readN(InputStream in,
byte[] buffer)
Reads from an inputstream until the given buffer is full. |
static int |
readN(InputStream in,
byte[] buffer,
int offset,
int length)
Reads N bytes from an inputstream into a buffer and tries reading a view times before throwing an exception in case the stream blocks. |
static void |
setSeparator(String c)
Sets the seperator character (or String) for the 'toString()' methods. |
static byte[] |
toASCIIByteArray(String s)
Converts a string into a asciibytearray. |
static String |
toASCIIString(byte[] b)
Converts a bytearray into an asciistring. |
static int |
toByte(char c,
int radix)
Converts the given char to an int. |
static byte[] |
toByteArray(String s)
Converts the given string with hex values to a bytearray. |
static String |
toString(byte[] b)
Converts a given byte array into a formated hex-string. |
static String |
toString(byte[] b,
int ofs,
int len)
Converts a given byte array into a formated hex-string. |
static String |
toString(int i)
Turns an integer into a formatted Hex number. |
static byte[] |
toUTF8ByteArray(String s)
Converts an UTF8 string into a bytearray. |
static String |
toUTF8String(byte[] b)
Converts a bytearray into an UTF8 string. |
static void |
waitKey()
Wait for the user to press the return key on System.in .
|
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
public static Class loadClass(String className)
Class.forName(....)
method.
If you use this method within applets, pay attention to the fact that classes that are
not within the JAR file are serched on the server the applet was downloaded from.className
- the fully qualified name of the desired class, e.g.:
Class clazz = Utils.loadClass("java.lang.Thread");
Class.forName(String)
public static boolean isAvailable(String className)
className
- the classname of the class to be checkedtrue
if the class is available or false
if the class cannot be foundpublic static byte[] concat(byte[] b1, byte[] b2)
b1
- the first bytearrayb2
- the second bytearraypublic static String toString(byte[] b, int ofs, int len)
b
- the byte arrayofs
- startingpoint of the conversion within the arraylen
- number of bytes to be convertedpublic static String toString(byte[] b)
b
- the byte arraypublic static byte[] decodeByteArray(String s)
s
- the Base64 coded stringpublic static int[] decodeIntArray(String s)
s
- the Base64 coded stringpublic static boolean equals(Object a, Object b)
a
- the first objectb
- the second objecttrue
if the objects are equal (or both null) or false
if not.public static boolean isNull(Object[] obj)
obj
- the objectarraytrue
if the objectarray or one of its items is nullpublic static String toString(int i)
i
- the number to convertpublic static byte[] increment(byte[] b)
b
- a byte arraypublic static void waitKey()
System.in
.
As System.in is not available on the J2ME platformpublic static int toByte(char c, int radix)
radix
-1 is returned.
Utils.toByte('A', 16);
(16 for hex numbers).c
- characterradix
- public static byte[] toByteArray(String s)
s
- stringpublic static byte[] readCompleteStream(InputStream in) throws IOException
in
- the InputStream to be readIOException
- if a error during reading of the stream occurs.public static int readN(InputStream in, byte[] buffer, int offset, int length) throws IOException
in
- the InputStreambuffer
- the buffer where to write the bytes tooffset
- where to start writing in the bufferlength
- how much bytes shall be readIOException
- if the stream can't be readpublic static int readN(InputStream in, byte[] buffer) throws IOException
in
- inputstreambuffer
- the buffer where to write the data intoIOException
- if stream can't be readpublic static int min(int a, int b)
a
- first intb
- second intpublic static int max(int a, int b)
a
- first intb
- second intpublic static int hashCode(byte[] data)
data
- the bytearraypublic static int hashCode(Object obj)
obj
- public static String toASCIIString(byte[] b)
byte
- arraypublic static String toUTF8String(byte[] b)
bytearray
- public static byte[] toASCIIByteArray(String s)
s
- the ASCII stringpublic static byte[] toUTF8ByteArray(String s)
s
- utf8 stringpublic static Reader getASCIIReader(InputStream in)
Reader r = Util.getASCIIReader( new FileInputStream("temp.txt") );
in
- the inputstreampublic static Writer getASCIIWriter(OutputStream out)
Writer r = Util.getASCIIWriter( new FileOutputStream("temp.txt") );
out
- the outputstreampublic static void setSeparator(String c)
c
- new seperator String
|
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). | ||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |