KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > packtag > strategy > AbstractPackStrategy


1 /**
2  * Project pack:tag >> http://packtag.sf.net
3  *
4  * This software is published under the terms of the LGPL
5  * License version 2.1, a copy of which has been included with this
6  * distribution in the 'lgpl.txt' file.
7  *
8  * Last author: $Author: danielgalan $
9  * Last modified: $Date: 2007/04/22 19:04:23 $
10  * Revision: $Revision: 1.1 $
11  *
12  * $Log: AbstractPackStrategy.java,v $
13  * Revision 1.1 2007/04/22 19:04:23 danielgalan
14  * pack.tag moved from subversion to good old CVS
15  *
16  */

17 package net.sf.packtag.strategy;
18
19 import java.io.BufferedReader JavaDoc;
20 import java.io.InputStream JavaDoc;
21 import java.io.InputStreamReader JavaDoc;
22
23
24
25 /**
26  * A super Strategy with supporting methods.
27  *
28  * @author Daniel Galán y Martins
29  * @version $Revision: 1.1 $
30  */

31 public abstract class AbstractPackStrategy implements PackStrategy {
32     
33     protected static final String JavaDoc LINE_SEPARATOR = System.getProperty("line.separator");
34
35     protected String JavaDoc resourceToString(InputStream JavaDoc resourceAsStream) throws PackException {
36         StringBuffer JavaDoc result = new StringBuffer JavaDoc();
37         BufferedReader JavaDoc br = new BufferedReader JavaDoc(new InputStreamReader JavaDoc(resourceAsStream));
38         try {
39             boolean firstLine = true;
40             String JavaDoc line = br.readLine();
41             while(line != null) {
42                 if (firstLine) {
43                     firstLine = false;
44                 }
45                 else {
46                     result.append(LINE_SEPARATOR);
47                 }
48                 result.append(line);
49                 line = br.readLine();
50             }
51             br.close();
52         }
53         catch (Exception JavaDoc ex) {
54             throw new PackException(ex);
55         }
56         return result.toString();
57     }
58
59 }
60
Popular Tags