1 5 6 package com.hp.hpl.jena.n3; 7 8 import java.io.* ; 9 import com.hp.hpl.jena.JenaRuntime ; 10 11 17 18 class IndentedWriter { 21 String lineSeparator = JenaRuntime.getLineSeparator() ; 22 23 Writer writer ; 24 int column ; 25 int row ; 26 int currentIndent ; 27 28 public IndentedWriter(Writer w) 29 { 30 writer = w ; 31 column = 0 ; 32 row = 0 ; 33 currentIndent = 0 ; 34 } 35 36 public Writer getWriter() { return writer ; } 37 38 public int getRow() { return row ; } 39 public int getCol() { return column ; } 40 public int getIndent() { return currentIndent ; } 41 42 public void incIndent(int x) { currentIndent += x ; } 43 public void decIndent(int x) { currentIndent -= x ; } 44 public void setIndent(int x) { currentIndent = x ; } 45 46 public void print(String s) 47 { 48 try { writer.write(s); column += s.length() ; } 49 catch (java.io.IOException ex) {} 50 } 51 52 public void println(String s) 53 { 54 try { writer.write(s); println() ; } 55 catch (java.io.IOException ex) { } 56 } 57 58 public void println() 59 { 60 try { 61 writer.write(lineSeparator); 62 writer.flush() ; 63 column = 0 ; 64 row++ ; 65 padTo() ; 66 } 67 catch (java.io.IOException ex) { } 68 } 69 70 public void padTo() throws IOException 71 { 72 StringBuffer sBuff = new StringBuffer () ; 73 for ( int i = 0 ; i < currentIndent ; i++ ) 74 writer.write(' ') ; 75 column = column + currentIndent ; 76 } 77 78 public void flush() { try { writer.flush() ; } catch (IOException ioEx) {} } 79 public void close() { try { writer.close() ; } catch (IOException ioEx) {} } 80 81 } 82 83 84 110 | Popular Tags |