1 16 package scriptella.driver.ldap.ldif; 17 18 import scriptella.expression.PropertiesSubstitutor; 19 import scriptella.spi.ParametersCallback; 20 21 import java.io.BufferedReader ; 22 import java.io.IOException ; 23 import java.io.Reader ; 24 import java.util.ArrayList ; 25 import java.util.List ; 26 27 35 public class SubstitutingLineReader extends BufferedReader { 36 private final PropertiesSubstitutor substitutor; 37 private List <String > lines; 38 private int len; 39 40 41 47 public SubstitutingLineReader(final Reader in, final ParametersCallback callback) { 48 super(in); 49 this.substitutor = new PropertiesSubstitutor(callback); 50 } 51 52 public String readLine() throws IOException { 53 String s = super.readLine(); 54 if (s==null || s.length()==0) { 55 return s; 56 } 57 s = substitutor.substitute(s); 58 if (lines!=null) { lines.add(s); len+=s.length()+1; } 62 return s; 63 } 64 65 68 public String getTrackedLines() { 69 if (lines==null) { throw new IllegalStateException ("Lines tracking must be switched on prior to calling this method"); 71 } 72 StringBuilder sb = new StringBuilder (len); 73 for (String s : lines) { 74 sb.append(s).append('\n'); 75 } 76 return sb.toString(); 77 } 78 79 84 public void trackLines() { 85 if (lines!=null) { 86 lines.clear(); 87 } else { 88 lines=new ArrayList <String >(); 89 } 90 len=0; 91 } 92 93 94 } 95 | Popular Tags |