abdera-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jmsn...@apache.org
Subject svn commit: r592572 - in /incubator/abdera/java/trunk: core/src/main/java/org/apache/abdera/util/ core/src/main/java/org/apache/abdera/writer/ parser/src/main/java/org/apache/abdera/parser/stax/
Date Tue, 06 Nov 2007 22:24:01 GMT
Author: jmsnell
Date: Tue Nov  6 14:23:59 2007
New Revision: 592572

URL: http://svn.apache.org/viewvc?rev=592572&view=rev
Log:
Optionally tell the streamwriter to autoflush or autoclose

Modified:
    incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/util/AbstractStreamWriter.java
    incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/writer/StreamWriter.java
    incubator/abdera/java/trunk/parser/src/main/java/org/apache/abdera/parser/stax/StaxStreamWriter.java

Modified: incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/util/AbstractStreamWriter.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/util/AbstractStreamWriter.java?rev=592572&r1=592571&r2=592572&view=diff
==============================================================================
--- incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/util/AbstractStreamWriter.java
(original)
+++ incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/util/AbstractStreamWriter.java
Tue Nov  6 14:23:59 2007
@@ -20,6 +20,8 @@
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
+import java.nio.channels.Channels;
+import java.nio.channels.WritableByteChannel;
 import java.util.Date;
 import java.util.HashMap;
 import java.util.Map;
@@ -38,9 +40,29 @@
   implements StreamWriter {
   
   protected final String name;
+  protected boolean autoflush = false;
+  protected boolean autoclose = false;
   
   protected AbstractStreamWriter(String name) {
     this.name = name;
+  }
+  
+  public StreamWriter setAutoflush(boolean auto) {
+    this.autoflush = auto;
+    return this;
+  }
+  
+  public StreamWriter setAutoclose(boolean auto) {
+    this.autoclose = auto;
+    return this;
+  }
+  
+  public StreamWriter setChannel(WritableByteChannel channel) {
+    return setOutputStream(Channels.newOutputStream(channel));
+  }
+
+  public StreamWriter setChannel(WritableByteChannel channel, String charset) {
+    return setWriter(Channels.newWriter(channel, charset));
   }
   
   public String getName() {

Modified: incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/writer/StreamWriter.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/writer/StreamWriter.java?rev=592572&r1=592571&r2=592572&view=diff
==============================================================================
--- incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/writer/StreamWriter.java
(original)
+++ incubator/abdera/java/trunk/core/src/main/java/org/apache/abdera/writer/StreamWriter.java
Tue Nov  6 14:23:59 2007
@@ -41,6 +41,16 @@
   extends NamedItem {
 
   /**
+   * True if the StreamWriter should autoclose the buffer after calling endDocument
+   */
+  StreamWriter setAutoclose(boolean auto);
+  
+  /**
+   * True if the StreamWriter should autoflush the buffer
+   */
+  StreamWriter setAutoflush(boolean auto);
+  
+  /**
    * Set the target java.io.Writer
    */
   StreamWriter setWriter(java.io.Writer writer);
@@ -54,6 +64,16 @@
    * Set the target java.io.OutputStream
    */
   StreamWriter setOutputStream(java.io.OutputStream out, String charset);
+  
+  /**
+   * Set the target WritableByteChannel
+   */
+  StreamWriter setChannel(java.nio.channels.WritableByteChannel channel);
+
+  /**
+   * Set the target WritableByteChannel
+   */
+  StreamWriter setChannel(java.nio.channels.WritableByteChannel channel, String charset);
   
   /**
    * Start the document

Modified: incubator/abdera/java/trunk/parser/src/main/java/org/apache/abdera/parser/stax/StaxStreamWriter.java
URL: http://svn.apache.org/viewvc/incubator/abdera/java/trunk/parser/src/main/java/org/apache/abdera/parser/stax/StaxStreamWriter.java?rev=592572&r1=592571&r2=592572&view=diff
==============================================================================
--- incubator/abdera/java/trunk/parser/src/main/java/org/apache/abdera/parser/stax/StaxStreamWriter.java
(original)
+++ incubator/abdera/java/trunk/parser/src/main/java/org/apache/abdera/parser/stax/StaxStreamWriter.java
Tue Nov  6 14:23:59 2007
@@ -108,6 +108,7 @@
   public StreamWriter endDocument() {
     try {
       writer.writeEndDocument();
+      if (autoclose) writer.close();
     } catch(XMLStreamException e) {
       throw new RuntimeException(e);
     }
@@ -118,6 +119,7 @@
     try {
       pop();
       writer.writeEndElement();
+      if (autoflush) writer.flush();
     } catch(XMLStreamException e) {
       throw new RuntimeException(e);
     }
@@ -154,6 +156,7 @@
             attributes.get(attr));
         }
       }
+      if (autoflush) writer.flush();
     } catch(XMLStreamException e) {
       throw new RuntimeException(e);
     }
@@ -163,6 +166,7 @@
   public StreamWriter writeElementText(String value) {
     try {
       writer.writeCharacters(value);
+      if (autoflush) writer.flush();
     } catch(XMLStreamException e) {
       throw new RuntimeException(e);
     }
@@ -172,6 +176,7 @@
   public StreamWriter writeComment(String value) {
     try {
       writer.writeComment(value);
+      if (autoflush) writer.flush();
     } catch(XMLStreamException e) {
       throw new RuntimeException(e);
     }
@@ -181,6 +186,7 @@
   public StreamWriter writePI(String value) {
     try {
       writer.writeProcessingInstruction(value);
+      if (autoflush) writer.flush();
     } catch(XMLStreamException e) {
       throw new RuntimeException(e);
     }
@@ -190,6 +196,7 @@
   public StreamWriter writePI(String value, String target) {
     try {
       writer.writeProcessingInstruction(value,target);
+      if (autoflush) writer.flush();
     } catch(XMLStreamException e) {
       throw new RuntimeException(e);
     }



Mime
View raw message