Stuart McCulloch | 39cc9ac | 2012-07-16 13:43:38 +0000 | [diff] [blame] | 1 | package aQute.bnd.osgi; |
Stuart McCulloch | bb01437 | 2012-06-07 21:57:32 +0000 | [diff] [blame] | 2 | |
| 3 | import java.io.*; |
| 4 | import java.util.*; |
| 5 | |
| 6 | public class CombinedResource extends WriteResource { |
Stuart McCulloch | 2286f23 | 2012-06-15 13:27:53 +0000 | [diff] [blame] | 7 | final List<Resource> resources = new ArrayList<Resource>(); |
| 8 | long lastModified = 0; |
| 9 | |
Stuart McCulloch | bb01437 | 2012-06-07 21:57:32 +0000 | [diff] [blame] | 10 | @Override |
| 11 | public void write(final OutputStream out) throws IOException, Exception { |
| 12 | OutputStream unclosable = new FilterOutputStream(out) { |
Stuart McCulloch | 55d4dfe | 2012-08-07 10:57:21 +0000 | [diff] [blame^] | 13 | @Override |
Stuart McCulloch | bb01437 | 2012-06-07 21:57:32 +0000 | [diff] [blame] | 14 | public void close() { |
| 15 | // Ignore |
| 16 | } |
| 17 | }; |
Stuart McCulloch | 2286f23 | 2012-06-15 13:27:53 +0000 | [diff] [blame] | 18 | for (Resource r : resources) { |
Stuart McCulloch | bb01437 | 2012-06-07 21:57:32 +0000 | [diff] [blame] | 19 | r.write(unclosable); |
| 20 | unclosable.flush(); |
| 21 | } |
| 22 | } |
| 23 | |
| 24 | @Override |
| 25 | public long lastModified() { |
| 26 | return lastModified; |
| 27 | } |
| 28 | |
| 29 | public void addResource(Resource r) { |
| 30 | lastModified = Math.max(lastModified, r.lastModified()); |
| 31 | resources.add(r); |
| 32 | } |
| 33 | |
Stuart McCulloch | bb01437 | 2012-06-07 21:57:32 +0000 | [diff] [blame] | 34 | } |