1 24 package org.archive.util; 25 26 42 public final class PaddingStringBuffer { 43 StringBuffer buffer; 45 int linePos; 47 48 52 public PaddingStringBuffer() { 53 buffer = new StringBuffer (); 54 linePos=0; 55 } 56 57 61 public PaddingStringBuffer append(String string) { 62 buffer.append(string); 63 if ( string.indexOf('\n') == -1 ){ 64 linePos+=string.length(); 65 } else { 66 while ( string.indexOf('\n') == -1 ){ 67 string = string.substring(string.indexOf('\n')); 68 } 69 linePos=string.length(); 70 } 71 return this; 72 } 73 74 84 public PaddingStringBuffer raAppend(int col, String string) { 85 padTo(col-string.length()); 86 append(string); 87 return this; 88 } 89 90 95 public PaddingStringBuffer padTo(int col) { 96 while(linePos<col) { 97 buffer.append(" "); 98 linePos++; 99 } 100 return this; 101 } 102 103 107 public PaddingStringBuffer append(int i) { 108 append(Integer.toString(i)); 109 return this; 110 } 111 112 113 123 public PaddingStringBuffer raAppend(int col, int i) { 124 return raAppend(col,Integer.toString(i)); 125 } 126 127 131 public PaddingStringBuffer append(long lo) { 132 append(Long.toString(lo)); 133 return this; 134 } 135 136 144 public PaddingStringBuffer raAppend(int col, long lo) { 145 return raAppend(col,Long.toString(lo)); 146 } 147 148 149 public void reset() { 150 buffer = new StringBuffer (); 151 linePos = 0; 152 } 153 154 157 public String toString() { 158 return buffer.toString(); 159 } 160 161 164 public PaddingStringBuffer newline() { 165 buffer.append("\n"); 166 linePos = 0; 167 return this; 168 } 169 170 } 171 | Popular Tags |