package org.cumulus4j.testutil; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.io.ObjectStreamClass; import java.io.OutputStream; import java.io.PrintWriter; import java.io.Serializable; import java.io.StringWriter; import java.io.UnsupportedEncodingException; import java.lang.reflect.Field; import java.lang.reflect.Method; import java.net.MalformedURLException; import java.net.URI; import java.net.URISyntaxException; import java.net.URL; import java.nio.charset.Charset; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Properties; import java.util.Random; import java.util.Set; import java.util.SortedSet; import java.util.TreeSet; import java.util.zip.ZipOutputStream; /** * This is a collection of utility functions. All methods * of this class are static. * @author Alex Bieber, Marc Klinger, Marco Schulze, Niklas Schiffler * @version 1.4 ;-) */ public abstract class Util { /** * Specifies usage of the MD5 algorithm in {@link #hash(byte[], String)} (or one of the other hash methods). */ public static final String HASH_ALGORITHM_MD5 = "MD5"; /** * Specifies usage of the SHA algorithm in {@link #hash(byte[], String)} (or one of the other hash methods). */ public static final String HASH_ALGORITHM_SHA = "SHA"; // private static final Logger logger = Logger.getLogger(Util.class); /** * Check two objects for equality. *

* This method is a convenience reducing code: * obj0 == obj1 || (obj0 != null && obj0.equals(obj1)) * will be replaced by Utils.equals(obj0, obj1) * and you do not need to worry about null anymore. *

* Additionally if you pass two arrays to this method * (whose equals method only checks for equality [TODO doesn't this mean "identity" instead of "equality"?]) * this method will consult {@link Arrays#equals(Object[], Object[])} * for equality of the parameters instead, of course after a null check. * * @param obj0 One object to check for equality * @param obj1 The other object to check for equality * @return true if both objects are null or * if they are equal or if both objects are Object arrays * and equal according to {@link Arrays#equals(Object[], Object[])} - * false otherwise */ public static boolean equals(Object obj0, Object obj1) { if (obj0 instanceof Object[] && obj1 instanceof Object[]) return obj0 == obj1 || Arrays.equals((Object[])obj0, (Object[])obj1); return obj0 == obj1 || (obj0 != null && obj0.equals(obj1)); } /** * Check two longs for equality. *

* In order to provide the same API for Object and long * which both are often used as IDs, it is recommended to use this method * instead of writing id0 == id1. *

*

* To write id0 == id1 is considered more error-prone if refactorings happen: * Imagine, you create an object with a long unique id. Later on, you decide that a String id * is better. You won't recognize that some old code id0 == id1 is broken. * When using this method instead, the compiler will automatically switch to {@link #equals(Object, Object)} * and a correct result will be calculated. *

*

* Even though Java 5 (and higher) implicitely converts simple datatypes to their corresponding object * (e.g. long to java.lang.Long), it's unnecessary to perform this conversion * and better to have this method instead. *

* * @param l0 One long to check. * @param l1 The other long to check. * @return the result of: l0 == l1. * @see #equals(Object, Object) */ public static boolean equals(long l0, long l1) { return l0 == l1; } /** * Check two ints for equality. *

* This method does the same for ints as {@link #equals(long, long)} * does for longs. *

* * @param i0 One int to check. * @param i1 The other int to check. * @return the result of: i0 == i1. * @see #equals(long, long) */ public static boolean equals(int i0, int i1) { return i0 == i1; } /** * @param l The long number for which to calculate the hashcode. * @return the same as new Long(l).hashCode() would do, but * without the overhead of creating a Long instance. */ public static int hashCode(long l) { return (int)(l ^ (l >>> 32)); } /** * Get a hash code for an object. This method also handles * null-Objects. * @param obj An object or null * @return 0 if obj == null - * obj.hashCode() otherwise */ public static int hashCode(Object obj) { return obj == null ? 0 : obj.hashCode(); } /** * Returns a String with zeros prefixing * the given base. The returned String will * have at least a length of the given strLength. *

* This method calls {@link #addLeadingChars(String, int, char)} with '0' as * fillChar. *

* * @param base The base String to prefix. * @param strLength The length of the resulting String * @return A string with zeros prefixing the given base. */ public static String addLeadingZeros(String base, int strLength) { return addLeadingChars(base, strLength, '0'); } /** * This method adds the character passed as fillChar * to the front of the string s until the total length * of the string reaches length. If the given string * s is longer or exactly as long as defined by * length, no characters will be added. * * @param s The string to which characters are appended (before). * @param length The minimum length of the result. * @param fillChar The character that will be added. * @return the resulting string with as many fillChar characters added to it as necessary. */ public static String addLeadingChars(String s, int length, char fillChar) { if (s != null && s.length() >= length) return s; StringBuilder sb = new StringBuilder(length); int l = s == null ? length : length - s.length(); while (sb.length() < l) sb.append(fillChar); if (s != null) sb.append(s); return sb.toString(); } /** * This method adds the character passed as fillChar * to the end of the string s until the total length * of the string reaches length. If the given string * s is longer or exactly as long as defined by * length, no characters will be added. * * @param s The string to which characters are appended (after). * @param length The minimum length of the result. * @param fillChar The character that will be added. * @return the resulting string with as many fillChar characters added to it as necessary. */ public static String addTrailingChars(String s, int length, char fillChar) { if (s != null && s.length() >= length) return s; StringBuilder sb = new StringBuilder(length); if (s != null) sb.append(s); while (sb.length() < length) sb.append(fillChar); return sb.toString(); } /** * Returns a String with spaces prefixing * the given base. The returned String will * have at least a length of the given strLength. *

* This method calls {@link #addLeadingChars(String, int, char)} with spaces (' ') as * fillChar. *

* * @param base The base String to prefix. * @param strLength The length of the resulting String * @return A string with zeros prefixing the given base. */ public static String addLeadingSpaces(String base, int strLength) { return addLeadingChars(base, strLength, ' '); } /** * This method encodes a byte array into a human readable hex string. For each byte, * two hex digits are produced. They are concatted without any separators. *

* This is a convenience method for encodeHexStr(buf, 0, buf.length) * * @param buf The byte array to translate into human readable text. * @return a human readable string like "fa3d70" for a byte array with 3 bytes and these values. * @see #encodeHexStr(byte[], int, int) * @see #decodeHexStr(String) */ public static String encodeHexStr(byte[] buf) { return encodeHexStr(buf, 0, buf.length); } /** * Encode a byte array into a human readable hex string. For each byte, * two hex digits are produced. They are concatted without any separators. * * @param buf The byte array to translate into human readable text. * @param pos The start position (0-based). * @param len The number of bytes that shall be processed beginning at the position specified by pos. * @return a human readable string like "fa3d70" for a byte array with 3 bytes and these values. * @see #encodeHexStr(byte[]) * @see #decodeHexStr(String) */ public static String encodeHexStr(byte[] buf, int pos, int len) { StringBuffer hex = new StringBuffer(); while (len-- > 0) { byte ch = buf[pos++]; int d = (ch >> 4) & 0xf; hex.append((char)(d >= 10 ? 'a' - 10 + d : '0' + d)); d = ch & 0xf; hex.append((char)(d >= 10 ? 'a' - 10 + d : '0' + d)); } return hex.toString(); } /** * Decode a string containing two hex digits for each byte. * @param hex The hex encoded string * @return The byte array represented by the given hex string * @see #encodeHexStr(byte[]) * @see #encodeHexStr(byte[], int, int) */ public static byte[] decodeHexStr(String hex) { if (hex.length() % 2 != 0) throw new IllegalArgumentException("The hex string must have an even number of characters!"); byte[] res = new byte[hex.length() / 2]; int m = 0; for (int i = 0; i < hex.length(); i += 2) { res[m++] = (byte) Integer.parseInt(hex.substring(i, i + 2), 16); } return res; } /** * Get a 32 character MD5 hash in hex notation for the given input string. * @param clear The input string to build the hash on * @return The MD5 encoded hex string. * @throws NoSuchAlgorithmException */ public static String getMD5HexString(String clear) throws NoSuchAlgorithmException { byte[] enc = MessageDigest.getInstance("MD5").digest(clear.getBytes()); // System.out.println(new String(enc)); return encodeHexStr(enc, 0, enc.length); } /** * Hash a byte array with the given algorithm. * * @param data The data to hash * @param algorithm The name of the hash alogorithm (e.g. MD5, SHA) as supported by {@link MessageDigest}. If using one of these * algorithms, you should use the appropriate constant: {@link #HASH_ALGORITHM_MD5} or {@link #HASH_ALGORITHM_SHA}. * @return the array of bytes for the resulting hash value. * @throws NoSuchAlgorithmException if the algorithm is not available in the caller's environment. * * @see #hash(File, String) * @see #hash(InputStream, long, String) * @see #encodeHexStr(byte[]) */ public static byte[] hash(byte[] data, String algorithm) throws NoSuchAlgorithmException { MessageDigest md = MessageDigest.getInstance(algorithm); md.update(data); return md.digest(); } /** * Hash an {@link InputStream} with the given algorithm. * * @param in The {@link InputStream} which will be read. This stream is not closed, but read until its end or until the number of bytes specified * in bytesToRead has been read. * @param bytesToRead If -1, the {@link InputStream} in will be read till its end is reached. Otherwise, the amount of bytes specified by * this parameter is read. If the {@link InputStream} ends before having read the specified amount of bytes, an {@link IOException} will be thrown. * @param algorithm The name of the hash alogorithm (e.g. MD5, SHA) as supported by {@link MessageDigest}. If using one of these * algorithms, you should use the appropriate constant: {@link #HASH_ALGORITHM_MD5} or {@link #HASH_ALGORITHM_SHA}. * @return the array of bytes for the resulting hash value. * @throws NoSuchAlgorithmException if the algorithm is not available in the caller's environment. * @throws IOException if reading from the {@link InputStream} fails. * * @see #hash(byte[], String) * @see #encodeHexStr(byte[]) */ public static byte[] hash(InputStream in, long bytesToRead, String algorithm) throws NoSuchAlgorithmException, IOException { if (bytesToRead < 0 && bytesToRead != -1) throw new IllegalArgumentException("bytesToRead < 0 && bytesToRead != -1"); long bytesReadTotal = 0; MessageDigest md = MessageDigest.getInstance(algorithm); byte[] data = new byte[10240]; while (true) { int len; if(bytesToRead < 0) len = data.length; else { len = (int)Math.min(data.length, bytesToRead - bytesReadTotal); if (len < 1) break; } int bytesRead = in.read(data, 0, len); if (bytesRead < 0) { if (bytesToRead >= 0) throw new IOException("Unexpected EndOfStream! bytesToRead==" + bytesToRead + " but only " + bytesReadTotal + " bytes could be read from InputStream!"); break; } bytesReadTotal += bytesRead; if (bytesRead > 0) md.update(data, 0, bytesRead); } return md.digest(); } /** * This methods reads a given file and calls {@link #hash(InputStream, long, String)}. * * @param file The file to read an hash. * @param algorithm The algorithm to use. * @return The result of {@link #hash(InputStream, long, String)}. * @throws NoSuchAlgorithmException if the algorithm is not available in the caller's environment. * @throws IOException if reading the file fails. * * @see #hash(byte[], String) * @see #encodeHexStr(byte[]) */ public static byte[] hash(File file, String algorithm) throws NoSuchAlgorithmException, IOException { FileInputStream in = new FileInputStream(file); try { return hash(in, -1, algorithm); } finally { in.close(); } } // public static void main(String[] args) // { // File f = new File("/home/marco/workspaces/jfire/JFireTrade/dist/JFireTrade.jar"); // try { // System.out.println(byteArrayToHexString(hash(f, HASH_ALGORITHM_MD5))); // // byte[] data = new byte[(int)f.length()]; // RandomAccessFile raf = new RandomAccessFile(f, "r"); // raf.read(data); // System.out.println(byteArrayToHexString(hash(data, HASH_ALGORITHM_MD5))); // // } catch (Exception e) { // e.printStackTrace(); // } // } /** * Truncates a double value at the given decimal position. * E.g. d = 9.45935436363463 and numDigits = 2 * will return 9.45. * * @param d the double to shorten * @param numDigits the number of decimal places after the decimal separator. * @return the shorted double */ public static double truncateDouble(double d, int numDigits) { double multiplier = Math.pow(10, numDigits); return ((int) (d * multiplier)) / multiplier; } /** * Makes a Double out of Integer. The parameter numDigits * determines where the decimal separator should be, seen from the end. * E.g. value = 135 and numDigits = 2 will * return 1.35. * * @param value the integer to transform into a double * @param numDigits determines where the decimal separator should be, * seen from the end * @return the transformed double */ public static double getDouble(int value, int numDigits) { double multiplier = Math.pow(10, numDigits); return (value) / multiplier; } public static Collection cloneSerializableAll(Collection originalCollection) { return cloneSerializableAll(originalCollection, null); } public static Collection cloneSerializableAll(Collection originalCollection, ClassLoader classLoader) { if (originalCollection == null) throw new IllegalArgumentException("originalCollection must not be null!"); Collection result; if (originalCollection instanceof List) result = new ArrayList(originalCollection.size()); else if (originalCollection instanceof SortedSet) result = new TreeSet(); else if (originalCollection instanceof Set) result = new HashSet(originalCollection.size()); else result = new ArrayList(originalCollection.size()); for (T original : originalCollection) { result.add(cloneSerializable(original, classLoader)); } Collection res = CollectionUtil.castCollection(result); return res; } /** * Helper method to clone an object that implements the {@link Cloneable} * interface. * * @param a class that implements {@link Cloneable}. * @param original the instance that shall be cloned. * @return the clone. */ public static T cloneCloneable(T original) { Method cloneMethod = null; try { cloneMethod = Object.class.getDeclaredMethod("clone"); } catch (SecurityException e) { throw e; } catch (NoSuchMethodException e) { throw new IllegalStateException("Why the hell does the clone() method not exist?!"); } try { return (T) cloneMethod.invoke(original); } catch (Exception e) { throw new RuntimeException(e); } } /** * This method clones a given object by serializing it (into a DataBuffer) * and deserializing it again. It uses java native serialization, thus the object needs * to implement {@link Serializable}. * * @param Any class. It is not defined as "<T extends Serializable>" in order to allow * interfaces (e.g. java.util.Map) that don't extend {@link Serializable} but whose * implementations usually do. * @param original The original object. It will be serialized and therefore needs to implement Serializable. * @return The copy (deserialized clone) of the given original. */ public static T cloneSerializable(T original) { if (original == null) return null; return cloneSerializable(original, original.getClass().getClassLoader()); // DataBuffer db; // try { // db = new DataBuffer(10240); // ObjectOutputStream out = new ObjectOutputStream(db.createOutputStream()); // try { // out.writeObject(original); // } finally { // out.close(); // } // } catch (IOException x) { // there should never be a problem (under normal circumstances) as the databuffer should nearly always work in RAM only. // throw new RuntimeException(x); // } // // try { // ObjectInputStream in = new ObjectInputStream(db.createInputStream()); // try { // return (T) in.readObject(); // } finally { // in.close(); // } // } catch (ClassNotFoundException x) { // we deserialize an object of the same type as our parameter => the class should always be known // throw new RuntimeException(x); // } catch (IOException x) { // there should never be a problem (under normal circumstances) as the databuffer should nearly always work in RAM only. // throw new RuntimeException(x); // } } /** * An {@link ObjectInputStream} instance that uses the given * {@link ClassLoader} to resolve classes that are to be deserialized. * @author Marc Klinger - marc[at]nightlabs[dot]de */ private static class ClassLoaderObjectInputStream extends ObjectInputStream { private ClassLoader classLoader; public ClassLoaderObjectInputStream(InputStream in, ClassLoader classLoader) throws IOException { super(in); this.classLoader = classLoader; } /* (non-Javadoc) * @see java.io.ObjectInputStream#resolveClass(java.io.ObjectStreamClass) */ @Override protected Class resolveClass(ObjectStreamClass desc) throws IOException, ClassNotFoundException { if(classLoader == null) return super.resolveClass(desc); String name = desc.getName(); try { return Class.forName(name, false, classLoader); } catch (ClassNotFoundException ex) { return super.resolveClass(desc); } } } /** * This method clones a given object by serializing it (into a DataBuffer) * and deserializing it again. It uses java native serialization, thus the object needs * to implement {@link Serializable}. * * @param Any class. It is not defined as "<T extends Serializable>" in order to allow * interfaces (e.g. java.util.Map) that don't extend {@link Serializable} but whose * implementations usually do. * @param original The original object. It will be serialized and therefore needs to implement Serializable. * @param classLoader The class loader to use to resolve loaded classes or null to use the * default lookup mechanism. * @return The copy (deserialized clone) of the given original. */ @SuppressWarnings("unchecked") public static T cloneSerializable(T original, final ClassLoader classLoader) { if (original == null) return null; byte[] buffer; try { ByteArrayOutputStream bout = new ByteArrayOutputStream(); ObjectOutputStream out = new ObjectOutputStream(bout); try { out.writeObject(original); } finally { out.close(); } buffer = bout.toByteArray(); } catch (IOException x) { // there should never be a problem (under normal circumstances) as the ByteArrayOutputStream works in RAM only. throw new RuntimeException(x); } try { ObjectInputStream in = classLoader == null ? new ObjectInputStream(new ByteArrayInputStream(buffer)) : new ClassLoaderObjectInputStream(new ByteArrayInputStream(buffer), classLoader); try { return (T) in.readObject(); } finally { in.close(); } } catch (ClassNotFoundException x) { // we deserialize an object of the same type as our parameter => the class should always be known throw new RuntimeException(x); } catch (IOException x) { // there should never be a problem (under normal circumstances) as the databuffer should nearly always work in RAM only. throw new RuntimeException(x); } } /** * Get the stack trace representation of a Throwable * as string. * @param t The Throwable * @return The stack trace as string. */ public static String getStackTraceAsString(Throwable t) { StringWriter sw = new StringWriter(); t.printStackTrace(new PrintWriter(sw)); return sw.toString(); } /** * Append a field string representation for an Oject to * a {@link StringBuffer}. * @param o The Object to represent * @param s A {@link StringBuffer} to append the string. */ public static void toFieldString(Object o, StringBuffer s) { final Field fields[] = o.getClass().getDeclaredFields(); for (Field element : fields) { s.append(","); s.append(element.getName()); s.append("="); try { element.setAccessible(true); s.append(element.get(o)); } catch (IllegalAccessException ex) { s.append("*private*"); } } } /** * Get a field string representation for an Oject. * @param o The Object to represent * @return The field string representation. */ public static String toFieldString(Object o) { StringBuffer s = new StringBuffer(); toFieldString(o, s); return s.toString(); } /** * A generic reflection-based toString method. * @param o The Object to represent * @return The string representation of the object. */ public static String toString(Object o) { StringBuffer s = new StringBuffer(); s.append(o.getClass().getName()); s.append("@"); s.append(Integer.toHexString(o.hashCode())); s.append("["); toFieldString(o, s); s.append("]"); return s.toString(); } /** * Convert an URL to an URI. * @param url The URL to cenvert * @return The URI * @throws MalformedURLException if the given URL is malformed */ public static URI urlToUri(URL url) throws MalformedURLException { if (url == null) return null; try { return new URI(url.getProtocol(), url.getAuthority(), url.getPath(), url .getQuery(), url.getRef()); } catch (URISyntaxException e) { MalformedURLException newEx = new MalformedURLException("URL " + url + " was malformed"); newEx.initCause(e); throw newEx; } } /** * Get a string representation of the elapsed time. * @param start The elapsed time in millis * @return The elapsed time as string representation */ public static String getTimeString(long millis) { if(millis < 0) return "n/a"; long seconds = millis/1000; long minutes = seconds/60; long hours = minutes/60; StringBuffer sb = new StringBuffer(); if(hours > 0) { minutes -= hours*60; seconds -= hours*60*60; millis -= hours*60*60*1000; sb.append(hours); sb.append("h"); } if(minutes > 0) { seconds -= minutes*60; millis -= minutes*60*1000; if(sb.length() > 0) sb.append(" "); sb.append(minutes); sb.append("m"); } if(seconds > 0) { millis -= seconds*1000; if(sb.length() > 0) sb.append(" "); sb.append(seconds); sb.append("s"); } if(sb.length() == 0 || millis > 0) { if(sb.length() > 0) sb.append(" "); sb.append(millis); sb.append("ms"); } return sb.toString(); } /** * Get a string representation of the elapsed time between start and now. * @param start The start time in millis * @return The elapsed time as string representation */ public static String getTimeDiffString(long start) { return getTimeDiffString(start, System.currentTimeMillis()); } /** * Get a string representation of the elapsed time between start and end. * @param start The start time in millis * @param end The end time in millis * @return The elapsed time as string representation */ public static String getTimeDiffString(long start, long end) { return getTimeString(end-start); } /** * Create a random string out of the given alphabet. * @param alphabet The alphabet to chose characters from * @param minLen The minimum length (included). * @param maxLen The maximum length (included). * @return The newly created random string */ public static String createRandomString(CharSequence alphabet, int minLen, int maxLen) { if(alphabet == null || alphabet.length() < 1) throw new IllegalArgumentException("The password alphabet is empty"); if(minLen < 0) throw new IllegalArgumentException("Invalid minLen (<0): "+minLen); if(maxLen < 0) throw new IllegalArgumentException("Invalid maxLen (<0): "+maxLen); if(maxLen < minLen) throw new IllegalArgumentException("Invalid minLen/maxLen combination (maxLenfile from the given baseDir. *

* If it is not possible to denote file relative to baseDir, * the absolute path of file will be returned. *

* See {@link IOUtil#getRelativePath(File, String)} for examples. * * @param baseDir This directory is used as start for the relative path. It can be seen as the working directory * from which to point to file. * @param file The file to point to. * @return the path to file relative to baseDir or the absolute path, * if a relative path cannot be formulated (i.e. they have no directory in common). * @throws IOException In case of an error * @deprecated Use {@link IOUtil#getRelativePath(String,String)} instead */ @Deprecated public static String getRelativePath(String baseDir, String file) throws IOException { return IOUtil.getRelativePath(baseDir, file); } /** * This method finds - if possible - a relative path for addressing * the given file from the given baseDir. *

* If it is not possible to denote file relative to baseDir, * the absolute path of file will be returned. *

* See {@link IOUtil#getRelativePath(File, String)} for examples. * * @param baseDir This directory is used as start for the relative path. It can be seen as the working directory * from which to point to file. * @param file The file to point to. * @return the path to file relative to baseDir or the absolute path, * if a relative path cannot be formulated (i.e. they have no directory in common). * @throws IOException In case of an error * @deprecated Use {@link IOUtil#getRelativePath(File,File)} instead */ @Deprecated public static String getRelativePath(File baseDir, File file) throws IOException { return IOUtil.getRelativePath(baseDir, file); } /** * This method finds - if possible - a relative path for addressing * the given file from the given baseDir. *

* If it is not possible to denote file relative to baseDir, * the absolute path of file will be returned. *

*

* Examples: *

    *
  • * baseDir="/home/marco"
    * file="temp/jfire/jboss/bin/run.sh"
    * or
    * file="/home/marco/temp/jfire/jboss/bin/run.sh"
    * result="temp/jfire/jboss/bin/run.sh" *
  • *
  • * baseDir="/home/marco/workspace.jfire/JFireBase"
    * file="/home/marco/temp/jfire/jboss/bin/run.sh"
    * or
    * file="../../temp/jfire/jboss/bin/run.sh"
    * result="../../temp/jfire/jboss/bin/run.sh" *
  • *
  • * baseDir="/tmp/workspace.jfire/JFireBase"
    * file="/home/marco/temp/jfire/jboss/bin/run.sh"
    * result="/home/marco/temp/jfire/jboss/bin/run.sh" (absolute, because relative is not possible) *
  • *
*

* * @param baseDir This directory is used as start for the relative path. It can be seen as the working directory * from which to point to file. * @param file The file to point to. * @return the path to file relative to baseDir or the absolute path, * if a relative path cannot be formulated (i.e. they have no directory in common). * @throws IOException In case of an error * @deprecated Use {@link IOUtil#getRelativePath(File,String)} instead */ @Deprecated public static String getRelativePath(File baseDir, String file) throws IOException { return IOUtil.getRelativePath(baseDir, file); } /** * This method removes double slashes, single-dot-directories and double-dot-directories * from a path. This means, it does nearly the same as File.getCanonicalPath, but * it does not resolve symlinks. This is essential for the method getRelativePath, * because this method first tries it with a simplified path before using the canonical path * (prevents problems with iteration through directories, where there are symlinks). *

* Please note that this method makes the given path absolute! * * @param path A path to simplify, e.g. "/../opt/java/jboss/../jboss/./bin/././../server/default/lib/." * @return the simplified string (absolute path), e.g. "/opt/java/jboss/server/default/lib" * @deprecated Use {@link IOUtil#simplifyPath(File)} instead */ @Deprecated public static String simplifyPath(File path) { return IOUtil.simplifyPath(path); } /** * Transfer all available data from an {@link InputStream} to an {@link OutputStream}. *

* This is a convenience method for transferStreamData(in, out, 0, -1) * @param in The stream to read from * @param out The stream to write to * @return The number of bytes transferred * @throws IOException In case of an error * @deprecated Use {@link IOUtil#transferStreamData(InputStream, OutputStream)} instead */ @Deprecated public static long transferStreamData(java.io.InputStream in, java.io.OutputStream out) throws java.io.IOException { return IOUtil.transferStreamData(in, out, 0, -1); } /** * This method deletes the given directory recursively. If the given parameter * specifies a file and no directory, it will be deleted anyway. If one or more * files or subdirectories cannot be deleted, the method still continues and tries * to delete as many files/subdirectories as possible. * * @param dir The directory or file to delete * @return True, if the file or directory does not exist anymore. This means it either * was not existing already before or it has been successfully deleted. False, if the * directory could not be deleted. * @deprecated Use {@link IOUtil#deleteDirectoryRecursively(String)} instead */ @Deprecated public static boolean deleteDirectoryRecursively(String dir) { return IOUtil.deleteDirectoryRecursively(dir); } /** * This method deletes the given directory recursively. If the given parameter * specifies a file and no directory, it will be deleted anyway. If one or more * files or subdirectories cannot be deleted, the method still continues and tries * to delete as many files/subdirectories as possible. * * @param dir The directory or file to delete * @return true if the file or directory does not exist anymore. * This means it either was not existing already before or it has been * successfully deleted. false if the directory could not be * deleted. * @deprecated Use {@link IOUtil#deleteDirectoryRecursively(File)} instead */ @Deprecated public static boolean deleteDirectoryRecursively(File dir) { return IOUtil.deleteDirectoryRecursively(dir); } /** * Tries to find a unique, not existing folder name under the given root folder with a random * number (in hex format) added to the given prefix. When found, the directory will be created. *

* This is a convenience method for {@link IOUtil#createUniqueRandomFolder(File, String, long, long)} * and calls it with 10000 as maxIterations and 10000 as number range. *

* Note that this method might throw a {@link IOException} * if it will not find a unique name within 10000 iterations. *

* Note that the creation of the directory is not completely safe. This method is * synchronized, but other processes could "steal" the unique filename. * * @param rootFolder The rootFolder to find a unique subfolder for * @param prefix A prefix for the folder that has to be found. * @return A File pointing to an unique (non-existing) Folder under the given rootFolder and with the given prefix * @throws IOException in case of an error * @deprecated Use {@link IOUtil#createUniqueRandomFolder(File,String)} instead */ @Deprecated public static File createUniqueRandomFolder(File rootFolder, final String prefix) throws IOException { return IOUtil.createUniqueRandomFolder(rootFolder, prefix); } /** * Tries to find a unique, not existing folder name under the given root folder with a random * number (in hex format) added to the given prefix. When found, the directory will be created. *

* The method will try to find a name for maxIterations number * of itarations and use random numbers from 0 to uniqueOutOf. *

* Note that the creation of the directory is not completely safe. This method is * synchronized, but other processes could "steal" the unique filename. * * @param rootFolder The rootFolder to find a unique subfolder for * @param prefix A prefix for the folder that has to be found. * @param maxIterations The maximum number of itarations this method shoud do. * If after them still no unique folder could be found, a {@link IOException} * is thrown. * @param uniqueOutOf The range of random numbers to apply (0 - given value) * * @return A File pointing to an unique folder under the given rootFolder and with the given prefix * @throws IOException in case of an error * @deprecated Use {@link IOUtil#createUniqueRandomFolder(File,String,long,long)} instead */ @Deprecated public static synchronized File createUniqueRandomFolder(File rootFolder, final String prefix, long maxIterations, long uniqueOutOf) throws IOException { return IOUtil.createUniqueRandomFolder(rootFolder, prefix, maxIterations, uniqueOutOf); } /** * Tries to find a unique, not existing folder name under the given root folder * suffixed with a number. When found, the directory will be created. * It will start with 0 and make Integer.MAX_VALUE number * of iterations maximum. The first not existing foldername will be returned. * If no foldername could be found after the maximum iterations a {@link IOException} * will be thrown. *

* Note that the creation of the directory is not completely safe. This method is * synchronized, but other processes could "steal" the unique filename. * * @param rootFolder The rootFolder to find a unique subfolder for * @param prefix A prefix for the folder that has to be found. * @return A File pointing to an unique (not existing) Folder under the given rootFolder and with the given prefix * @throws IOException in case of an error * @deprecated Use {@link IOUtil#createUniqueIncrementalFolder(File,String)} instead */ @Deprecated public static synchronized File createUniqueIncrementalFolder(File rootFolder, final String prefix) throws IOException { return IOUtil.createUniqueIncrementalFolder(rootFolder, prefix); } /** * Transfer data between streams * @param in The input stream * @param out The output stream * @param inputOffset How many bytes to skip before transferring * @param inputLen How many bytes to transfer. -1 = all * @return The number of bytes transferred * @throws IOException if an error occurs. * @deprecated Use {@link IOUtil#transferStreamData(java.io.InputStream,java.io.OutputStream,long,long)} instead */ @Deprecated public static long transferStreamData(java.io.InputStream in, java.io.OutputStream out, long inputOffset, long inputLen) throws java.io.IOException { return IOUtil.transferStreamData(in, out, inputOffset, inputLen); } /** * Copy a resource loaded by the class loader of a given class to a file. *

* This is a convenience method for copyResource(sourceResClass, sourceResName, new File(destinationFilename)). * @param sourceResClass The class whose class loader to use. If the class * was loaded using the bootstrap class loaderClassloader.getSystemResourceAsStream * will be used. See {@link Class#getResourceAsStream(String)} for details. * @param sourceResName The name of the resource * @param destinationFilename Where to copy the contents of the resource * @throws IOException in case of an error * @deprecated Use {@link IOUtil#copyResource(Class,String,String)} instead */ @Deprecated public static void copyResource(Class sourceResClass, String sourceResName, String destinationFilename) throws IOException { IOUtil.copyResource(sourceResClass, sourceResName, destinationFilename); } /** * Copy a resource loaded by the class loader of a given class to a file. * @param sourceResClass The class whose class loader to use. If the class * was loaded using the bootstrap class loaderClassloader.getSystemResourceAsStream * will be used. See {@link Class#getResourceAsStream(String)} for details. * @param sourceResName The name of the resource * @param destinationFile Where to copy the contents of the resource * @throws IOException in case of an error * @deprecated Use {@link IOUtil#copyResource(Class, String, File)} instead */ @Deprecated public static void copyResource(Class sourceResClass, String sourceResName, File destinationFile) throws IOException { IOUtil.copyResource(sourceResClass, sourceResName, destinationFile); } /** * Copy a file. *

* This is a convenience method for copyFile(new File(sourceFilename), new File(destinationFilename)) * @param sourceFilename The source file to copy * @param destinationFilename To which file to copy the source * @throws IOException in case of an error * @deprecated Use {@link IOUtil#copyFile(String,String)} instead */ @Deprecated public static void copyFile(String sourceFilename, String destinationFilename) throws IOException { IOUtil.copyFile(sourceFilename, destinationFilename); } /** * Copy a file. * @param sourceFile The source file to copy * @param destinationFile To which file to copy the source * @throws IOException in case of an error * @deprecated Use {@link IOUtil#copyFile(File, File)} instead */ @Deprecated public static void copyFile(File sourceFile, File destinationFile) throws IOException { IOUtil.copyFile(sourceFile, destinationFile); } /** * Copy a directory recursively. * @param sourceDirectory The source directory * @param destinationDirectory The destination directory * @throws IOException in case of an error * @deprecated Use {@link IOUtil#copyDirectory(File,File)} instead */ @Deprecated public static void copyDirectory(File sourceDirectory, File destinationDirectory) throws IOException { IOUtil.copyDirectory(sourceDirectory, destinationDirectory); } /** * Get a file object from a base directory and a list of subdirectories or files. * @param file The base directory * @param subDirs The subdirectories or files * @return The new file instance * @deprecated Use {@link IOUtil#getFile(File,String...)} instead */ @Deprecated public static File getFile(File file, String ... subDirs) { return IOUtil.getFile(file, subDirs); } /** * Write text to a file using UTF-8 encoding. * @param file The file to write the text to * @param text The text to write * @throws IOException in case of an io error * @throws FileNotFoundException if the file exists but is a directory * rather than a regular file, does not exist but cannot * be created, or cannot be opened for any other reason * @deprecated Use {@link IOUtil#writeTextFile(File,String)} instead */ @Deprecated public static void writeTextFile(File file, String text) throws IOException, FileNotFoundException, UnsupportedEncodingException { IOUtil.writeTextFile(file, text); } /** * Write text to a file. * @param file The file to write the text to * @param text The text to write * @param encoding The caracter set to use as file encoding (e.g. "UTF-8") * @throws IOException in case of an io error * @throws FileNotFoundException if the file exists but is a directory * rather than a regular file, does not exist but cannot * be created, or cannot be opened for any other reason * @throws UnsupportedEncodingException If the named encoding is not supported * @deprecated Use {@link IOUtil#writeTextFile(File,String,String)} instead */ @Deprecated public static void writeTextFile(File file, String text, String encoding) throws IOException, FileNotFoundException, UnsupportedEncodingException { IOUtil.writeTextFile(file, text, encoding); } /** * Read a UTF-8 encoded text file and return the contents as string. *

For other encodings, use {@link IOUtil#readTextFile(File, String)}. * @param f The file to read, maximum size 1 GB * @throws FileNotFoundException if the file was not found * @throws IOException in case of an io error * @return The contents of the text file * @deprecated Use {@link IOUtil#readTextFile(File)} instead */ @Deprecated public static String readTextFile(File f) throws FileNotFoundException, IOException { return IOUtil.readTextFile(f); } /** * Read a text file and return the contents as string. * @param f The file to read, maximum size 1 GB * @param encoding The file encoding, e.g. "UTF-8" * @throws FileNotFoundException if the file was not found * @throws IOException in case of an io error * @throws UnsupportedEncodingException If the named encoding is not supported * @return The contents of the text file * @deprecated Use {@link IOUtil#readTextFile(File,String)} instead */ @Deprecated public static String readTextFile(File f, String encoding) throws FileNotFoundException, IOException, UnsupportedEncodingException { return IOUtil.readTextFile(f, encoding); } /** * Read a text file from an {@link InputStream} using * UTF-8 encoding. *

* This method does NOT close the input stream! * @param in The stream to read from. It will not be closed by this operation. * @return The contents of the input stream file * @deprecated Use {@link IOUtil#readTextFile(InputStream)} instead */ @Deprecated public static String readTextFile(InputStream in) throws FileNotFoundException, IOException { return IOUtil.readTextFile(in); } /** * Read a text file from an {@link InputStream} using * the given encoding. *

* This method does NOT close the input stream! * @param in The stream to read from. It will not be closed by this operation. * @param encoding The charset used for decoding, e.g. "UTF-8" * @return The contents of the input stream file * @deprecated Use {@link IOUtil#readTextFile(InputStream,String)} instead */ @Deprecated public static String readTextFile(InputStream in, String encoding) throws FileNotFoundException, IOException { return IOUtil.readTextFile(in, encoding); } /** * Get the extension of a filename. * @param fileName A file name (might contain the full path) or null. * @return null, if the given fileName doesn't contain * a dot (".") or if the given fileName is null. Otherwise, * returns all AFTER the last dot. * @deprecated Use {@link IOUtil#getFileExtension(String)} instead */ @Deprecated public static String getFileExtension(String fileName) { return IOUtil.getFileExtension(fileName); } /** * Get a filename without extension. * @param fileName A file name (might contain the full path) or null. * @return all before the last dot (".") or the full fileName if no dot exists. * Returns null, if the given fileName is null. * @deprecated Use {@link IOUtil#getFileNameWithoutExtension(String)} instead */ @Deprecated public static String getFileNameWithoutExtension(String fileName) { return IOUtil.getFileNameWithoutExtension(fileName); } /** * Get the temporary directory. * * FIXME: it seems not to be a good practise to create * a temp file just to get the directory. accessing * the system temp dir property would work without * hd access and without throwing an IOException. * See File.getTempDir() (private) (Marc) * * @return The temporary directory. * @throws IOException In case of an error * @deprecated Use {@link IOUtil#getTempDir()} instead */ @Deprecated public static File getTempDir() throws IOException { return IOUtil.getTempDir(); } /** * Compares two InputStreams. * * @param in1 the first InputStream * @param in2 the second InputStream * @param length the length to read from each InputStream * @return true if both InputStreams contain the identical data or false if not * @throws IOException if an I/O error occurs while reading length bytes * from one of the input streams. * @deprecated Use {@link IOUtil#compareInputStreams(InputStream,InputStream,int)} instead */ @Deprecated public static boolean compareInputStreams(InputStream in1, InputStream in2, int length) throws IOException { return IOUtil.compareInputStreams(in1, in2, length); } /** * Recursively zips all entries of the given zipInputFolder to * a zipFile defined by zipOutputFile. * * @param zipOutputFile The file to write to (will be deleted if existent). * @param zipInputFolder The inputFolder to zip. * @deprecated Use {@link IOUtil#zipFolder(File,File)} instead */ @Deprecated public static void zipFolder(File zipOutputFile, File zipInputFolder) throws IOException { IOUtil.zipFolder(zipOutputFile, zipInputFolder); } /** * Recursively writes all found files as entries into the given ZipOutputStream. * * @param out The ZipOutputStream to write to. * @param zipOutputFile the output zipFile. optional. if it is null, this method cannot check whether * your current output file is located within the zipped directory tree. You must not locate * your zip-output file within the source directory, if you leave this null. * @param files The files to zip (optional, defaults to all files recursively). It must not be null, * if entryRoot is null. * @param entryRoot The root folder of all entries. Entries in subfolders will be * added relative to this. If entryRoot==null, all given files will be * added without any path (directly into the zip's root). entryRoot and files must not * both be null at the same time. * @throws IOException in case of an I/O error. * @deprecated Use {@link IOUtil#zipFilesRecursively(ZipOutputStream,File,File[],File)} instead */ @Deprecated public static void zipFilesRecursively(ZipOutputStream out, File zipOutputFile, File[] files, File entryRoot) throws IOException { IOUtil.zipFilesRecursively(out, zipOutputFile, files, entryRoot); } /** * Unzip the given archive into the given folder. * * @param zipArchive The zip file to unzip. * @param unzipRootFolder The folder to unzip to. * @throws IOException in case of an I/O error. * @deprecated Use {@link IOUtil#unzipArchive(File,File)} instead */ @Deprecated public static void unzipArchive(File zipArchive, File unzipRootFolder) throws IOException { IOUtil.unzipArchive(zipArchive, unzipRootFolder); } /** * Add a trailing file separator character to the * given directory name if it does not already * end with one. * @see File#separator * @param directory A directory name * @return the directory name anding with a file seperator * @deprecated Use {@link IOUtil#addFinalSlash(String)} instead */ @Deprecated public static String addFinalSlash(String directory) { return IOUtil.addFinalSlash(directory); } /** * Generate a file from a template. The template file can contain variables which are formatted "${variable}". * All those variables will be replaced, for which a value has been passed in the map variables. *

* Example:
*

	 * ***
	 * Dear ${receipient.fullName},
	 * this is a spam mail trying to sell you ${product.name} for a very cheap price.
	 * Best regards, ${sender.fullName}
	 * ***
	 * 
*
* In order to generate a file from the above template, the map variables needs to contain values for these keys: *
    *
  • receipient.fullName
  • *
  • product.name
  • *
  • sender.fullName
  • *
*

*

* If a key is missing in the map, the variable will not be replaced but instead written as-is into the destination file (a warning will be * logged). *

* * @param destinationFile The file (absolute!) that shall be created out of the template. * @param templateFile The template file to use. Must not be null. * @param variables This map defines what variable has to be replaced by what value. The * key is the variable name (without '$' and brackets '{', '}'!) and the value is the * value for the variable to replace. This must not be null. * @deprecated Use {@link IOUtil#replaceTemplateVariables(File, File, Map, String)} instead. This mehtod * will delegate to that using {@link Charset#defaultCharset()}. */ @Deprecated public static void replaceTemplateVariables(File destinationFile, File templateFile, Map variables) throws IOException { IOUtil.replaceTemplateVariables(destinationFile, templateFile, Charset.defaultCharset().name(), variables); } // ################################################ // ################################################ // ##### DEPRECATED COLLECTION ##### // ################################################ // ################################################ /** * This method calls {@link #array2ArrayList(Object[], boolean)} with * canReturnNull = true. * * @param objects An array of objects - can be null. * @return an ArrayList (or null if objects == null). * @deprecated Use {@link CollectionUtil#array2ArrayList(T[])} instead */ @Deprecated public static ArrayList array2ArrayList(T[] objects) { return CollectionUtil.array2ArrayList(objects); } /** * @param canReturnNull If false, the result will never be null, * but an empty list if objects is null. * @param objects An array of objects - can be null. * @return an ArrayList - never null. * The ArrayList is empty if objects is null and * canReturnNull is false. If canReturnNull == true * and objects == null, the result will be null. * @deprecated Use {@link CollectionUtil#array2ArrayList(T[],boolean)} instead */ @Deprecated public static ArrayList array2ArrayList(T[] objects, boolean canReturnNull) { return CollectionUtil.array2ArrayList(objects, canReturnNull); } /** * This method calls {@link #array2HashSet(Object[], boolean)} with * canReturnNull = true. * * @param objects An array of objects - can be null. * @return an ArrayList (or null, if objects == null). * @deprecated Use {@link CollectionUtil#array2HashSet(T[])} instead */ @Deprecated public static HashSet array2HashSet(T[] objects) { return CollectionUtil.array2HashSet(objects); } /** * @param canReturnNull If false, the result will never be null, * but an empty list if objects is null. * @param objects An array of objects - can be null. * @return an ArrayList - never null. * The ArrayList is empty if objects is null and * canReturnNull is false. If canReturnNull == true * and objects == null, the result will be null. * @deprecated Use {@link CollectionUtil#array2HashSet(T[],boolean)} instead */ @Deprecated public static HashSet array2HashSet(T[] objects, boolean canReturnNull) { return CollectionUtil.array2HashSet(objects, canReturnNull); } /** * This method calls {@link #collection2TypedArray(Collection, Class, boolean)} with * canReturnNull = true. * * @param c Either null or a Collection with instances of the type specified by clazz (or descendants of it). * @param clazz The type of the elements of the returned object-array (e.g. String.class for the returned type String[]). * @return a typed object array (or null, if c == null). * @deprecated Use {@link CollectionUtil#collection2TypedArray(Collection,Class)} instead */ @Deprecated public static T[] collection2TypedArray(Collection c, Class clazz) { return CollectionUtil.collection2TypedArray(c, clazz); } /** * @param c Either null or a Collection with instances of the type specified by clazz (or descendants of it). * @param clazz The type of the elements of the returned object-array (e.g. String.class for the returned type String[]). * @param canReturnNull If false, the result will never be null, * but an empty array if c == null. * * @return a typed object array (or null, if c == null && canReturnNull). * If canReturnNull is false and c == null, an empty array will be returned. * @deprecated Use {@link CollectionUtil#collection2TypedArray(Collection,Class,boolean)} instead */ @Deprecated public static T[] collection2TypedArray(Collection c, Class clazz, boolean canReturnNull) { return CollectionUtil.collection2TypedArray(c, clazz, canReturnNull); } /** * Moves the given element up in the given list. * * @param list The list * @param element The element * @deprecated Use {@link CollectionUtil#moveListElementUp(List,Object)} instead */ @Deprecated public static void moveListElementUp(List list, T element) { CollectionUtil.moveListElementUp(list, element); } /** * Moves the given element down in the given list. * @param list The list * @param element The element * @deprecated Use {@link CollectionUtil#moveListElementDown(List,Object)} instead */ @Deprecated public static void moveListElementDown(List list, T element) { CollectionUtil.moveListElementDown(list, element); } // ################################################ // ################################################ // ##### DEPRECATED OTHER ##### // ################################################ // ################################################ /** * @deprecated Use String.format("%0{minDigits}d", i) instead */ @Deprecated public static String int2StringMinDigits(int i, int minDigits) { String s = Integer.toString(i); if (s.length() < minDigits) { StringBuffer sBuf = new StringBuffer(s); while (sBuf.length() < minDigits) sBuf.insert(0, '0'); s = sBuf.toString(); } return s; } /** * @deprecated FIXME: This method has the wrong name. It does in fact encode - not decode. Use * {@link #encodeHexStr(byte[], int, int)} or {@link #encodeHexStr(byte[])}. */ @Deprecated public static String decodeHexStr(byte[] buf, int pos, int len) { return encodeHexStr(buf, pos, len); } /** * @deprecated FIXME: this method has a misleading name. * It is a mixture of something like htmlEntities * (but not complete), nl2br (but nox XHTML conform) * and tab2spaces. (Marc) */ @Deprecated public static String htmlEncode(String s) { if (s == null) return ""; StringBuffer sb = new StringBuffer(); for (int i = 0; i < s.length(); i++) { char ch = s.charAt(i); if (ch == '\n') sb.append("
"); else if (ch == '<') sb.append("<"); else if (ch == '>') sb.append(">"); else if (ch == '\t') sb.append("    "); else sb.append(ch); } // for (int i = 0; i < bytesRead; i++) { return sb.toString(); } /** * @deprecated This method has a wrong name. It does not create a * unique key, but hashes the input value. Use {@link #hash(byte[], String)} * instead. * * Hash a byte array with the given algorithm. * * @param imageData the data to generate a unique key for * @param algorithm the name of the alogorithm (e.g. MD5, SHA) * @return a unique key for the given byte[] */ @Deprecated public static byte[] generateUniqueKey(byte[] data, String algorithm) { try { return hash(data, algorithm); } catch (NoSuchAlgorithmException e) { throw new RuntimeException(e); } } /** * @deprecated Use {@link Arrays#equals(byte[], byte[])}. * * compares two byte[]s * * @param b1 the first byte[] * @param b2 the second byte[] * @return true if both byte[]s contain the identical data or false if not */ @Deprecated public static boolean compareByteArrays(byte[] b1, byte[] b2) { return Arrays.equals(b1, b2); } /** * @deprecated Use {@link CollectionUtil#enum2List(Enum)} instead */ @Deprecated public static > List enum2List(Enum e) { return CollectionUtil.enum2List(e); } /** * @deprecated Misleading name: Use {@link #truncateDouble(double, int)}. */ @Deprecated public static double shortenDouble(double d, int numDigits) { return truncateDouble(d, numDigits); } /** * @deprecated Use {@link #getStackTraceAsString(Throwable)} instead */ @Deprecated public static String getStacktraceAsString(Throwable t) { return getStackTraceAsString(t); } /** * Get a byte array as hex string. *

* This method used upper-case "A"..."F" till version 1.2 of this class. From version 1.3 of this class on, * it uses "a"..."f" because it now delegates to {@link #encodeHexStr(byte[])}. *

* @param in The source byte array * @return the hex string. * @deprecated Use {@link #encodeHexStr(byte[])} instead. */ @Deprecated public static String byteArrayToHexString(byte in[]) { return encodeHexStr(in); } /** * Rotates value n bits left through the sign. * (source: http://mindprod.com/jgloss/rotate.html) * * @param value Value to rotated. * @param n how many bits to rotate left. * must be in range 0..31 * @return Value rotated. */ public static int rotateLeft ( int value, int n ) { return( value << n ) | ( value >>> (32 - n) ); } /** * Rotates value n bits right through the sign. * (source: http://mindprod.com/jgloss/rotate.html) * * @param value Value to rotated. * @param n how many bits to rotate night. * must be in range 0..31 * @return Value rotated. */ public static int rotateRight ( int value, int n ) { return( value >>> n ) | ( value << (32- n) ); } /** * Rotates value n bits left through the sign. * (source: http://mindprod.com/jgloss/rotate.html) * * @param value Value to rotated. * @param n how many bits to rotate left. * must be in range 0..63 * @return Value rotated. */ public static long rotateLeft ( long value, int n ) { return( value << n ) | ( value >>> (64 - n) ); } /** * Rotates value n bits right through the sign. * (source: http://mindprod.com/jgloss/rotate.html) * * @param value Value to rotated. * @param n how many bits to rotate night. * must be in range 0..63 * @return Value rotated. */ public static long rotateRight ( long value, int n ) { return( value >>> n ) | ( value << (64- n) ); } /** * Get the user name of the user who is currently authenticated at the operating system. * This method simply calls System.getProperty("user.name");. * * @return the user name of the current operating system user. */ public static String getUserName() { return System.getProperty("user.name"); //$NON-NLS-1$ } // /** // * Get all system properties and encode the values cause they might contain illegal characters (in windows) // * @return the encoded system properties. // */ // public static java.util.Properties getEncodedSystemProperties(Set encodedProperties) { // Properties sysProps = System.getProperties(); // for(Map.Entry entry : sysProps.entrySet()) { // if (encodedProperties.contains(entry.getKey())) { // ParameterCoder pc = new ParameterCoderMinusHexExt(); // String newValue = pc.encode(String.valueOf(entry.getValue())); // entry.setValue(newValue); // } // } // return sysProps; // } // // /** // * Get all system property map and encode the values cause they might contain illegal characters (in windows) // * @return the encoded system property map. // */ // public static Map getEncodedSystemPropertyMap() { // Set encodedProperties = new HashSet(); // encodedProperties.add("user.name"); // Properties encodedSysProps = getEncodedSystemProperties(encodedProperties); // Map propMap = new HashMap(); // for(Map.Entry entry : encodedSysProps.entrySet()) { // propMap.put(String.valueOf(entry.getKey()), String.valueOf(entry.getValue())); // } // return propMap; // } }