001package ca.bc.webarts.android;
002
003import java.io.ByteArrayOutputStream;
004import java.io.File;
005import java.io.IOException;
006import java.io.OutputStream;
007
008import android.util.Log;
009
010public class Util
011{
012  /**  A holder for this clients System File Separator.  */
013  public static final String SYSTEM_FILE_SEPERATOR = File.separator;
014
015  /**  A holder for this clients System line termination separator.  */
016  public static final String SYSTEM_LINE_SEPERATOR = System.getProperty("line.separator");
017
018  /**  The VM classpath (used in some methods)..  */
019  public static String CLASSPATH = System.getProperty("class.path");
020
021  /**  The users home ditrectory.  */
022  public static String USERHOME = System.getProperty("user.home");
023
024  /**  The users pwd ditrectory.  */
025  public static String USERDIR = System.getProperty("user.dir");
026
027  /**  A holder This classes name (used when logging).  */
028  private static String CLASSNAME = "ca.bc.webarts.android.Util";
029
030  /**
031   *  Returns the calling classes name.
032   * @return the calling methods name.
033   */
034  public static String getCurrentClassName()
035  {
036    Throwable t = new Throwable();
037    StackTraceElement[] es = t.getStackTrace();
038    StackTraceElement e = es[1];
039    return e.getClassName();
040    // return e.getLineNumber();
041    // return e.getMethodName();
042  }
043
044  /**
045   *  Returns the calling methods name.
046   * @return the calling methods name.
047   */
048  public static String getCurrentMethodName()
049  {
050    Throwable t = new Throwable();
051    StackTraceElement[] es = t.getStackTrace();
052    StackTraceElement e = es[1];
053    // return e.getClassName();
054    // return e.getLineNumber();
055    return e.getMethodName();
056  }
057
058  /**
059   *  A simple String token replacement routine. Replaces all occurences of the
060   *  token parameter with the replacement value in the passed in sentence
061   *  parameter.
062   *
063   * @param  sentence     The String to perform the token replacement on
064   * @param  token        the token String to seartch for and replace
065   * @param  replacement  the tokens replacement value
066   * @return              The new token replaced string
067   */
068  public static String tokenReplace(String sentence, String token, String replacement)
069  {
070    final String methodName = CLASSNAME + ": tokenReplace";
071    int a = 0;
072    String retVal = "";
073    while ((a = sentence.indexOf(token)) > -1)
074    {
075      retVal += sentence.substring(0, a) + replacement;
076      sentence = sentence.substring(a + token.length());
077      // System.out.println(wort);
078    }
079    // if a > -1
080    retVal += sentence;
081    return retVal;
082  }
083
084
085  /**
086   *  A method to simply abstract the Try/Catch required to put the current
087   *  thread to sleep for the specified time in ms.
088   *
089   * @param  waitTime  the sleep time in milli seconds (ms).
090   * @return           boolean value specifying if the sleep completed (true) or
091   *      was interupted (false).
092   */
093  public static boolean sleep(long waitTime)
094  {
095    final String methodName = CLASSNAME + ": sleep(Long)";
096    boolean retVal = true;
097    /*
098     *  BLOCK for the spec'd time
099     */
100    try
101    {
102      Thread.sleep(waitTime);
103    }
104    catch (InterruptedException iex)
105    {
106      retVal = false;
107    }
108    return retVal;
109  }
110
111
112 }
113