blob: 8299af86c098d98a3447f8ea319efd4a97d9e271 [file] [log] [blame]
Stuart McCulloch5ec302d2008-12-04 07:58:07 +00001package aQute.lib.osgi;
2
3import java.io.*;
4
5public class PreprocessResource extends AbstractResource {
6 final Resource resource;
7 final Processor processor;
8
9 public PreprocessResource(Processor processor, Resource r) {
10 super(r.lastModified());
11 this.processor = processor;
12 this.resource = r;
13 extra = resource.getExtra();
14 }
15
16 protected byte[] getBytes() throws IOException {
17 ByteArrayOutputStream bout = new ByteArrayOutputStream(2000);
18 OutputStreamWriter osw = new OutputStreamWriter(bout);
19 PrintWriter pw = new PrintWriter(osw);
20 InputStream in = resource.openInputStream();
21 try {
22 BufferedReader rdr = new BufferedReader(new InputStreamReader(in));
23 String line = rdr.readLine();
24 while (line != null) {
25 line = processor.getReplacer().process(line);
26 pw.println(line);
27 line = rdr.readLine();
28 }
29 pw.flush();
30 byte [] data= bout.toByteArray();
31 return data;
32
33 } finally {
34 in.close();
35 }
36 }
37}