1 17 package net.sf.packtag.strategy; 18 19 import java.io.BufferedReader ; 20 import java.io.InputStream ; 21 import java.io.InputStreamReader ; 22 23 24 25 31 public abstract class AbstractPackStrategy implements PackStrategy { 32 33 protected static final String LINE_SEPARATOR = System.getProperty("line.separator"); 34 35 protected String resourceToString(InputStream resourceAsStream) throws PackException { 36 StringBuffer result = new StringBuffer (); 37 BufferedReader br = new BufferedReader (new InputStreamReader (resourceAsStream)); 38 try { 39 boolean firstLine = true; 40 String 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 ex) { 54 throw new PackException(ex); 55 } 56 return result.toString(); 57 } 58 59 } 60 | Popular Tags |