KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openi > util > Util


1 /*********************************************************************************
2  * The contents of this file are subject to the OpenI Public License Version 1.0
3  * ("License"); You may not use this file except in compliance with the
4  * License. You may obtain a copy of the License at
5  * http://www.openi.org/docs/LICENSE.txt
6  *
7  * Software distributed under the License is distributed on an "AS IS" basis,
8  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
9  * the specific language governing rights and limitations under the License.
10  *
11  * The Original Code is: OpenI Open Source
12  *
13  * The Initial Developer of the Original Code is Loyalty Matrix, Inc.
14  * Portions created by Loyalty Matrix, Inc. are
15  * Copyright (C) 2005 Loyalty Matrix, Inc.; All Rights Reserved.
16  *
17  * Contributor(s): ______________________________________.
18  *
19  ********************************************************************************/

20 package org.openi.util;
21
22 import java.io.*;
23 import java.util.StringTokenizer JavaDoc;
24
25
26 /**
27  * @author Uddhab Pant
28  *
29  * Class contains common methods and fields.
30  *
31  */

32 public class Util {
33     public Util() {
34     }
35
36     /**
37      * Checks whether the item is in comma separated list of items.
38      *
39      * @param item String
40      * @param items String
41      * @return boolean
42      */

43     public static boolean isItemInList(String JavaDoc item, String JavaDoc items) {
44         if ((item == null) || (items == null)) {
45             return false;
46         }
47
48         StringTokenizer JavaDoc tokenizer = new StringTokenizer JavaDoc(items, ",");
49
50         while (tokenizer.hasMoreTokens()) {
51             if (item.equalsIgnoreCase(tokenizer.nextToken().trim())) {
52                 return true;
53             }
54         }
55
56         return false;
57     }
58
59     /**
60      * Fetch the entire contents of a text file, and return it in a String.
61      * @param fileNamePath is a file name including path which already exists and can be read.
62      * @return String
63      * @throws FileNotFoundException
64      * @throws IOException
65      */

66     static public String JavaDoc getFileContents(String JavaDoc fileNamePath) throws
67             FileNotFoundException, IOException {
68         StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
69         BufferedReader input = new BufferedReader(new InputStreamReader(new
70                 FileInputStream(fileNamePath)));
71         while (input.ready()) {
72             buffer.append(input.readLine());
73             buffer.append("\r\n");
74         }
75         return buffer.toString();
76     }
77 }
78
Popular Tags