KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > sapia > resource > StringResource


1 package org.sapia.resource;
2
3 import java.io.ByteArrayInputStream JavaDoc;
4 import java.io.IOException JavaDoc;
5 import java.io.InputStream JavaDoc;
6
7 /**
8  * Implements the <code>Resource</code> interface over a string.
9  *
10  * @author Yanick Duchesne
11  */

12 public class StringResource implements Resource {
13
14   private String JavaDoc _string, _uri;
15
16   public StringResource(String JavaDoc uri, String JavaDoc str) {
17     _string = str;
18     _uri = uri;
19   }
20
21   public long lastModified() {
22     return -1;
23   }
24
25   public InputStream JavaDoc getInputStream() throws IOException JavaDoc {
26     return new ByteArrayInputStream JavaDoc(_string.getBytes());
27   }
28
29   public String JavaDoc getURI() {
30     return _uri;
31   }
32
33   /**
34    * This method throws an <code>UnsupportedOperationException</code>.
35    */

36   public Resource getRelative(String JavaDoc uri) throws IOException JavaDoc {
37     throw new UnsupportedOperationException JavaDoc();
38   }
39 }
40
Popular Tags