KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > columba > mail > folder > FolderTstHelper


1 // The contents of this file are subject to the Mozilla Public License Version
2
// 1.1
3
//(the "License"); you may not use this file except in compliance with the
4
//License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
5
//
6
//Software distributed under the License is distributed on an "AS IS" basis,
7
//WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
8
//for the specific language governing rights and
9
//limitations under the License.
10
//
11
//The Original Code is "The Columba Project"
12
//
13
//The Initial Developers of the Original Code are Frederik Dietz and Timo
14
// Stich.
15
//Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
16
//
17
//All Rights Reserved.
18
package org.columba.mail.folder;
19
20 import java.io.BufferedReader JavaDoc;
21 import java.io.ByteArrayInputStream JavaDoc;
22 import java.io.File JavaDoc;
23 import java.io.InputStream JavaDoc;
24 import java.io.InputStreamReader JavaDoc;
25
26 import org.columba.core.io.DiskIO;
27
28 /**
29  * Convenience methods for folder testcases.
30  *
31  * @author fdietz
32  */

33 public final class FolderTstHelper {
34
35     /**
36      * This directory is used to create mail folders
37      */

38     public static String JavaDoc homeDirectory = System.getProperties().getProperty(
39             "user.dir");
40
41     /**
42      * Read message " <number>.eml" into String.
43      *
44      * @param number
45      * number of message
46      * @return string containing message source
47      * @throws Exception
48      */

49     public static String JavaDoc getString(int number) throws Exception JavaDoc {
50         return DiskIO.readFileInString(new File JavaDoc(new String JavaDoc(
51                 "mail/src/test/java/org/columba/mail/folder/" + number + ".eml"))).replaceAll("\n", "\r\n");
52     }
53     
54     /**
55      * Read string from file.
56      *
57      * @param filename name of file
58      * @return string containing file contents
59      * @throws Exception
60      */

61     public static String JavaDoc getString(String JavaDoc filename) throws Exception JavaDoc {
62         return DiskIO.readFileInString(new File JavaDoc(new String JavaDoc(
63                 "mail/src/test/java/org/columba/mail/folder/" + filename))).replaceAll("\n", "\r\n");
64     }
65
66     /**
67      * Create ByteArrayInputStream from String.
68      *
69      * @param s
70      * String
71      * @return ByteArrayInputStream
72      */

73     public static ByteArrayInputStream JavaDoc getByteArrayInputStream(String JavaDoc s) {
74         return new ByteArrayInputStream JavaDoc(s.getBytes());
75     }
76
77     /**
78      * Create String from InputStream.
79      *
80      * @param is
81      * inputstream
82      * @return string
83      * @throws Exception
84      */

85     public static String JavaDoc getStringFromInputStream(InputStream JavaDoc is)
86             throws Exception JavaDoc {
87         StringBuffer JavaDoc result = new StringBuffer JavaDoc();
88         BufferedReader JavaDoc reader = new BufferedReader JavaDoc(new InputStreamReader JavaDoc(is));
89         String JavaDoc nextLine = reader.readLine();
90
91         while (nextLine != null) {
92             result.append(nextLine);
93             result.append("\r\n");
94             nextLine = reader.readLine();
95         }
96
97         return result.toString();
98     }
99 }
100
Popular Tags