1 20 package org.objectweb.modfact.corba.generator; 21 22 import java.io.FileOutputStream ; 23 import java.io.IOException ; 24 import java.io.OutputStream ; 25 import java.io.PrintWriter ; 26 27 34 public abstract class PrintGenerator implements Generator { 35 36 37 protected PrintWriter out; 38 39 40 protected String filename = new String (); 41 42 43 protected final String TABULATION = new String (" "); 44 45 46 protected int level = 0; 47 48 49 protected boolean newLine = true; 50 51 52 58 public void setOutput(String file) throws IOException { 59 out = new PrintWriter (new FileOutputStream (file), true); 60 filename = file; 61 } 62 63 69 public void setOutput(java.io.File file) throws IOException { 70 out = new PrintWriter (new FileOutputStream (file), true); 71 filename = file.getName(); 72 } 73 74 78 public void setOutput(OutputStream stream) throws IOException { 79 out = new PrintWriter (stream); 80 } 81 82 87 protected void output(String outputString) { 88 int index = outputString.indexOf("\n"); 89 if (index != -1 && index != outputString.length() - 1) { 90 java.util.StringTokenizer token = new java.util.StringTokenizer (outputString, "\n"); 92 while (token.hasMoreTokens()) { 93 String next = token.nextToken(); 94 if (!token.hasMoreTokens()) { 95 if (outputString.endsWith("\n")) 96 outputln(next); 97 else 98 output(next); 99 } else { 100 outputln(next); 101 } 102 } 103 } else { 104 out.print(outputString); 105 if (outputString.trim().endsWith("\n")) 106 newLine = true; 107 else 108 newLine = false; 109 } 110 } 111 112 115 protected void outputln() { 116 out.println(); 117 newLine = true; 118 } 119 120 124 protected void outputln(String outputString) { 125 output(outputString); 126 outputln(); 127 } 128 129 132 public void flushFile() { 133 out.flush(); 134 } 135 136 } 137 | Popular Tags |