001: // The contents of this file are subject to the Mozilla Public License Version
002: // 1.1
003: //(the "License"); you may not use this file except in compliance with the
004: //License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
005: //
006: //Software distributed under the License is distributed on an "AS IS" basis,
007: //WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
008: //for the specific language governing rights and
009: //limitations under the License.
010: //
011: //The Original Code is "The Columba Project"
012: //
013: //The Initial Developers of the Original Code are Frederik Dietz and Timo
014: // Stich.
015: //Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
016: //
017: //All Rights Reserved.
018: package org.columba.mail.folder;
019:
020: import java.io.BufferedReader;
021: import java.io.ByteArrayInputStream;
022: import java.io.File;
023: import java.io.InputStream;
024: import java.io.InputStreamReader;
025:
026: import org.columba.core.io.DiskIO;
027:
028: /**
029: * Convenience methods for folder testcases.
030: *
031: * @author fdietz
032: */
033: public final class FolderTstHelper {
034:
035: /**
036: * This directory is used to create mail folders
037: */
038: public static String homeDirectory = System.getProperties()
039: .getProperty("user.dir");
040:
041: /**
042: * Read message " <number>.eml" into String.
043: *
044: * @param number
045: * number of message
046: * @return string containing message source
047: * @throws Exception
048: */
049: public static String getString(int number) throws Exception {
050: return DiskIO.readFileInString(
051: new File(new String(
052: "mail/src/test/java/org/columba/mail/folder/"
053: + number + ".eml"))).replaceAll("\n",
054: "\r\n");
055: }
056:
057: /**
058: * Read string from file.
059: *
060: * @param filename name of file
061: * @return string containing file contents
062: * @throws Exception
063: */
064: public static String getString(String filename) throws Exception {
065: return DiskIO.readFileInString(
066: new File(new String(
067: "mail/src/test/java/org/columba/mail/folder/"
068: + filename))).replaceAll("\n", "\r\n");
069: }
070:
071: /**
072: * Create ByteArrayInputStream from String.
073: *
074: * @param s
075: * String
076: * @return ByteArrayInputStream
077: */
078: public static ByteArrayInputStream getByteArrayInputStream(String s) {
079: return new ByteArrayInputStream(s.getBytes());
080: }
081:
082: /**
083: * Create String from InputStream.
084: *
085: * @param is
086: * inputstream
087: * @return string
088: * @throws Exception
089: */
090: public static String getStringFromInputStream(InputStream is)
091: throws Exception {
092: StringBuffer result = new StringBuffer();
093: BufferedReader reader = new BufferedReader(
094: new InputStreamReader(is));
095: String nextLine = reader.readLine();
096:
097: while (nextLine != null) {
098: result.append(nextLine);
099: result.append("\r\n");
100: nextLine = reader.readLine();
101: }
102:
103: return result.toString();
104: }
105: }
|