[Mulgara-svn] r2013 - trunk/src/jar/resolver/java/org/mulgara/resolver

alexhall at mulgara.org alexhall at mulgara.org
Tue Jul 19 22:52:00 UTC 2011


Author: alexhall
Date: 2011-07-19 22:52:00 +0000 (Tue, 19 Jul 2011)
New Revision: 2013

Modified:
   trunk/src/jar/resolver/java/org/mulgara/resolver/StreamContent.java
Log:
Fix argument validation -- should be checking for null InputStream, not URI.

Modified: trunk/src/jar/resolver/java/org/mulgara/resolver/StreamContent.java
===================================================================
--- trunk/src/jar/resolver/java/org/mulgara/resolver/StreamContent.java	2011-07-19 21:38:40 UTC (rev 2012)
+++ trunk/src/jar/resolver/java/org/mulgara/resolver/StreamContent.java	2011-07-19 22:52:00 UTC (rev 2013)
@@ -38,7 +38,7 @@
 import org.mulgara.content.Content;
 
 /**
- * Wrapper around a {@link InputStream} to make it satisfy the {@link Content}
+ * Wrapper around a {@link InputStream} or {@link OutputStream} to make it satisfy the {@link Content}
  * interface. 
  *
  * @created 2004-10-20
@@ -57,6 +57,8 @@
 
   /** The wrapped inputStream containing the source content. */
   private final InputStream inputStream;
+  
+  private final OutputStream outputStream;
 
   /** The content type of the stream, if provided. */
   private final MimeType contentType;
@@ -72,18 +74,37 @@
    */
   StreamContent(InputStream inputStream, URI uri, MimeType contentType) {
     // Validate "file" parameter
-    if (uri == null) {
-      throw new IllegalArgumentException("Null \"uri\" parameter");
+    if (inputStream == null) {
+      throw new IllegalArgumentException("Null \"inputStream\" parameter");
     }
-    if (inputStream == null && contentType == null) {
+    if (uri == null && contentType == null) {
       throw new IllegalArgumentException("Must provide at least one of URI and contentType");
     }
     // Initialize fields
     this.uri = uri;
     this.contentType = contentType;
     this.inputStream = inputStream;
+    this.outputStream = null;
   }
 
+
+  /**
+   * Wrap a {@link OutputStream} as {@link Content}.
+   * Either a URI or a conten type must be supplied to help determine the content
+   * of the inputstream.  
+   */
+  StreamContent(OutputStream outputStream, URI uri, MimeType contentType) {
+    // Validate "outputStream" parameter
+    if (outputStream == null) {
+      throw new IllegalArgumentException("Null \"outputStream\" parameter");
+    }
+    // Initialize fields
+    this.uri = uri;
+    this.contentType = contentType;
+    this.inputStream = null;
+    this.outputStream = outputStream;
+  }
+  
   //
   // Methods implementing Content
   //
@@ -115,6 +136,7 @@
    * @see org.mulgara.content.Content#newInputStream()
    */
   public InputStream newInputStream() throws IOException {
+    if (inputStream == null) throw new IOException("No input provided for stream content.");
     return inputStream;
   }
 
@@ -127,7 +149,8 @@
    * @throws IOException always
    */
   public OutputStream newOutputStream() throws IOException {
-    throw new IOException("Stream resolver can't perform output");
+    if (outputStream == null) throw new IOException("No output provided for stream content.");
+    return outputStream;
   }
 
   /** @see org.mulgara.content.Content#getURIString() */



More information about the Mulgara-svn mailing list