jena-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aj...@apache.org
Subject [02/50] jena git commit: Add a clone operation to produce a disconnected IndentedWriter.
Date Tue, 14 Feb 2017 14:39:17 GMT
Add a clone operation to produce a disconnected IndentedWriter.

This can be used with the stdout/stderr IndentedWriters to create
an isolated, mutable configuration IndentedWriter.

Project: http://git-wip-us.apache.org/repos/asf/jena/repo
Commit: http://git-wip-us.apache.org/repos/asf/jena/commit/e96d356d
Tree: http://git-wip-us.apache.org/repos/asf/jena/tree/e96d356d
Diff: http://git-wip-us.apache.org/repos/asf/jena/diff/e96d356d

Branch: refs/heads/ThreadPerGraphDataset
Commit: e96d356d03bc99711558fba53ba1f3e6514d5c38
Parents: 0874777
Author: Andy Seaborne <andy@apache.org>
Authored: Wed Jan 25 20:34:01 2017 +0000
Committer: Andy Seaborne <andy@apache.org>
Committed: Wed Jan 25 20:34:01 2017 +0000

----------------------------------------------------------------------
 .../apache/jena/atlas/io/IndentedWriter.java    | 40 ++++++++++++++++----
 1 file changed, 32 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/jena/blob/e96d356d/jena-base/src/main/java/org/apache/jena/atlas/io/IndentedWriter.java
----------------------------------------------------------------------
diff --git a/jena-base/src/main/java/org/apache/jena/atlas/io/IndentedWriter.java b/jena-base/src/main/java/org/apache/jena/atlas/io/IndentedWriter.java
index a5ba784..ed8f08d 100644
--- a/jena-base/src/main/java/org/apache/jena/atlas/io/IndentedWriter.java
+++ b/jena-base/src/main/java/org/apache/jena/atlas/io/IndentedWriter.java
@@ -49,20 +49,23 @@ public class IndentedWriter extends AWriterBase implements AWriter, Closeable
     protected Writer out = null ;
     
     protected static final int INDENT = 2 ;
+    
+    // Configuration.
     protected int unitIndent = INDENT ;
-    protected int currentIndent = 0 ;
-    protected int column = 0 ;
-    protected int row = 1 ;
-    protected boolean lineNumbers = false ;
-    protected boolean startingNewLine = true ;
     private char padChar = ' ' ;
-    private String endOfLineMarker = null ;     // Null means none.
     private String padString = null ;
     private String linePrefix = null ;
-
-    
+    protected boolean lineNumbers = false ;
     protected boolean flatMode = false ;
     private boolean flushOnNewline = false ;
+
+    // Internal state.
+    protected boolean startingNewLine = true ;
+    private String endOfLineMarker = null ;
+    protected int currentIndent = 0 ;
+    protected int column = 0 ;
+    protected int row = 1 ;
+    
     
     /** Construct a UTF8 IndentedWriter around an OutputStream */
     public IndentedWriter(OutputStream outStream) { this(outStream, false) ; }
@@ -72,6 +75,27 @@ public class IndentedWriter extends AWriterBase implements AWriter, Closeable
         this(makeWriter(outStream), withLineNumbers) ;
     }
 
+    /** Create an independent copy of the {@code IndentedWriter}.
+     *  Changes to the configuration of the copy will not affect the original {@code IndentedWriter}.
+     *  This include indentation level.
+     *  <br/>Row and column counters are reset.
+     *  <br/>Indent is initially. zero.
+     *  <br/>They do share the underlying output {@link Writer}.  
+     *  @param other
+     *  @return IndentedWriter
+     */
+    public IndentedWriter clone(IndentedWriter other) {
+        IndentedWriter dup = new IndentedWriter(other.out);
+        dup.unitIndent      = other.unitIndent;
+        dup.padChar         = other.padChar;
+        dup.padString       = other.padString;
+        dup.linePrefix      = other.linePrefix;
+        dup.lineNumbers     = other.lineNumbers;
+        dup.flatMode        = other.flatMode;
+        dup.flushOnNewline  = other.flushOnNewline;
+        return dup;
+    }
+
     private static Writer makeWriter(OutputStream out) {
         // return BufferingWriter.create(out) ;
         return IO.asBufferedUTF8(out) ;


Mime
View raw message