blob: 99f7dae837a79171b75c606002a34b07f499a6d3 [file] [log] [blame]
Stuart McCulloch26e7a5a2011-10-17 10:31:43 +00001package aQute.lib.osgi;
2
3import java.io.*;
4
5public abstract class WriteResource implements Resource {
6 long lastModified;
7 String extra;
8
9 public InputStream openInputStream() throws Exception {
10 PipedInputStream pin = new PipedInputStream();
11 final PipedOutputStream pout = new PipedOutputStream(pin);
12 Thread t = new Thread() {
13 public void run() {
14 try {
15 write(pout);
16 } catch (Exception e) {
17 e.printStackTrace();
18 } finally {
19 try {
20 pout.close();
21 } catch (IOException e) {
22 // Ignore
23 }
24 }
25 }
26 };
27 t.start();
28 return pin;
29 }
30
31 public abstract void write(OutputStream out) throws IOException, Exception;
32
33 public abstract long lastModified();
34
35 public String getExtra() {
36 return extra;
37 }
38
39 public void setExtra(String extra) {
40 this.extra = extra;
41 }
42}