All Downloads are FREE. Search and download functionalities are using the official Maven repository.

aQute.lib.osgi.PreprocessResource Maven / Gradle / Ivy

There is a newer version: 2.0.0.20130123-133441
Show newest version
package aQute.lib.osgi;

import java.io.*;

public class PreprocessResource extends AbstractResource {
    final Resource  resource;
    final Processor processor;

    public PreprocessResource(Processor processor, Resource r) {
        super(r.lastModified());
        this.processor = processor;
        this.resource = r;
        extra = resource.getExtra();
    }

    protected byte[] getBytes() throws Exception {
        ByteArrayOutputStream bout = new ByteArrayOutputStream(2000);
        OutputStreamWriter osw = new OutputStreamWriter(bout, Constants.DEFAULT_CHARSET);
        PrintWriter pw = new PrintWriter(osw);
        InputStream in = resource.openInputStream();
        try {
            BufferedReader rdr = new BufferedReader(new InputStreamReader(in,"UTF8"));
            String line = rdr.readLine();
            while (line != null) {
                line = processor.getReplacer().process(line);
                pw.println(line);
                line = rdr.readLine();
            }
            pw.flush();
            byte [] data= bout.toByteArray();
            return data;
                
        } finally {
            in.close();
        }        
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy