Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/flexstor/common/util/FlexUtil.java


1   /*
2    * FlexUtil.java
3    *
4    * Copyright $Date: 2003/08/11 02:22:31 $ FLEXSTOR.net Inc.
5    *
6    * This work is licensed for use and distribution under license terms found at
7    * http://www.flexstor.org/license.html
8    *
9    */
10  
11  package com.flexstor.common.util;
12  
13  //import java.net.InetAddress;
14  //import java.net.UnknownHostException;
15  //import java.util.Date;
16  //import java.io.File;
17  //import java.io.FileOutputStream;
18  //import java.io.PrintStream;
19  //import java.io.IOException;
20  //import com.flexstor.common.settings.Settings;
21  //import com.flexstor.common.util.Diagnostic;
22  
23  /*****************************************************
24   * This class contains utility methods.
25   * @Version: 1.0
26   ******************************************************/
27  public class FlexUtil
28  {
29  
30     /**
31      * Redirects standard output and standard error to a file.
32      */
33  /*   public static void redirectOutput ( )
34     {
35        if ( Settings.getBoolean ( Settings.CONFIG, Settings.REDIRECT_OUTPUT, false ) )
36        {
37           try
38           {
39              String sName = Settings.getString ( Settings.CONFIG,  Settings.REDIRECTION_PATH, "" ) +
40                             Settings.getString ( Settings.RUNTIME, Settings.IP_ADDRESS, "") +
41                             "_" +
42                             Math.abs ( (new Date()).getTime() ) +
43                             ".out";
44              
45              File f = new File ( sName );
46              System.out.println ( "Output being redirected to: " + f.getAbsolutePath() + "..." );
47              PrintStream ps = new PrintStream ( new FileOutputStream ( f ) );
48              System.setOut ( ps );
49              System.setErr ( ps );
50           }
51           catch ( IOException e )
52           {
53              System.out.println ( "Error opening output file." );
54              System.out.println ( e );
55           }
56        }
57     }
58  */
59  
60     /**
61     * arrayContains
62     * Determines if the array passed in contains the object of the second argument
63     * @return true if the object toFind exists in the array
64     **/
65     public static final boolean arrayContains( Object[] objData, Object toFind )
66     {
67        java.util.Vector v = new java.util.Vector();
68  
69        for(int x = 0; x < objData.length; x++)
70        {
71           v.addElement(objData[x]);
72        }
73  
74        return v.contains(toFind);
75  
76     }
77  
78     /**
79      * Returns true if nNum is in the int array naArray, else returns false.
80      * @param nNum the number being searched for.
81      * @param naArray the int array to check.
82      * @return true if nNum is found in naArray, else false.
83      */
84     public static boolean isIntInArray ( int nNum, int[] naArray )
85     {
86        int nLength = naArray.length;
87  
88        for ( int nLoop = 0; nLoop < nLength; nLoop++ )
89           if ( naArray[nLoop] == nNum )
90              return true;
91  
92        return false;
93     }
94  
95  
96     /**
97     * booleanToFlag - used Flag because ToString would be confusing
98     * Converts a boolean true to Y
99     * and a false to N
100    * @return A Y or N
101    **/
102    public final static String booleanToFlag(boolean b)
103    {
104       if(b)
105          return "Y";
106       else
107          return "N";
108    }
109 
110 /**
111 
112    This method does not work correctly under MRJ 2.0.  Instead of using this method we are
113    having the CGI return the IP Address on a ping.  This code should be saved in case this
114    is fixed unded MRJ 2.1.
115 
116    public static String getIPAddress()
117    {
118       String sIPAddress;
119 
120       try
121       {
122          sIPAddress = InetAddress.getLocalHost().getHostAddress();
123          //Diagnostic.println("Current IPAddress: " + sIPAddress);
124       }
125       catch(UnknownHostException e)
126       {
127          System.out.println("Cannot determine IP address.");
128          sIPAddress = "0.0.0.0";
129       }
130 
131       return sIPAddress;
132    }
133 */
134 }  // class
135