Stuart McCulloch | 26e7a5a | 2011-10-17 10:31:43 +0000 | [diff] [blame^] | 1 | package aQute.lib.osgi; |
| 2 | |
| 3 | import java.io.*; |
| 4 | |
| 5 | import aQute.lib.io.*; |
| 6 | import aQute.lib.tag.*; |
| 7 | |
| 8 | public class TagResource implements Resource { |
| 9 | final Tag tag; |
| 10 | String extra; |
| 11 | |
| 12 | public TagResource(Tag tag) { |
| 13 | this.tag = tag; |
| 14 | } |
| 15 | |
| 16 | public InputStream openInputStream() throws Exception { |
| 17 | final PipedInputStream pin = new PipedInputStream(); |
| 18 | final PipedOutputStream pout = new PipedOutputStream(pin); |
| 19 | Processor.getExecutor().execute(new Runnable() { |
| 20 | public void run() { |
| 21 | try { |
| 22 | write(pout); |
| 23 | } catch (Exception e) { |
| 24 | e.printStackTrace(); |
| 25 | // ignore |
| 26 | } |
| 27 | IO.close(pout); |
| 28 | } |
| 29 | }); |
| 30 | return pin; |
| 31 | } |
| 32 | |
| 33 | public void write(OutputStream out) throws UnsupportedEncodingException { |
| 34 | OutputStreamWriter ow = new OutputStreamWriter(out, "UTF-8"); |
| 35 | PrintWriter pw = new PrintWriter(ow); |
| 36 | pw.println("<?xml version='1.1'?>"); |
| 37 | try { |
| 38 | tag.print(0, pw); |
| 39 | } finally { |
| 40 | pw.flush(); |
| 41 | } |
| 42 | } |
| 43 | |
| 44 | public long lastModified() { |
| 45 | return 0; |
| 46 | } |
| 47 | |
| 48 | public void setExtra(String extra) { |
| 49 | this.extra = extra; |
| 50 | } |
| 51 | |
| 52 | public String getExtra() { |
| 53 | return extra; |
| 54 | } |
| 55 | |
| 56 | } |