01: /*
02: * Copyright 2004,2004 The Apache Software Foundation.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16:
17: package org.apache.bsf.util;
18:
19: import java.io.BufferedReader;
20: import java.io.IOException;
21: import java.io.PrintWriter;
22: import java.io.Reader;
23: import java.io.StringWriter;
24:
25: /**
26: * This file is a collection of input/output utilities.
27: *
28: * @author Sanjiva Weerawarana
29: * @author Matthew J. Duftler
30: */
31: public class IOUtils {
32: // debug flag - generates debug stuff if true
33: static boolean debug = false;
34:
35: //////////////////////////////////////////////////////////////////////////
36:
37: public static String getStringFromReader(Reader reader)
38: throws IOException {
39: BufferedReader bufIn = new BufferedReader(reader);
40: StringWriter swOut = new StringWriter();
41: PrintWriter pwOut = new PrintWriter(swOut);
42: String tempLine;
43:
44: while ((tempLine = bufIn.readLine()) != null) {
45: pwOut.println(tempLine);
46: }
47:
48: pwOut.flush();
49:
50: return swOut.toString();
51: }
52: }
|