1 7 package java.rmi.server; 8 9 import java.io.*; 10 import java.util.*; 11 12 21 @Deprecated 22 public class LogStream extends PrintStream { 23 24 25 private static Hashtable known = new Hashtable(5); 26 27 private static PrintStream defaultStream = System.err; 28 29 30 private String name; 31 32 33 private OutputStream logOut; 34 35 36 private OutputStreamWriter logWriter; 37 38 39 private StringBuffer buffer = new StringBuffer (); 40 41 42 private ByteArrayOutputStream bufOut; 43 44 53 @Deprecated 54 private LogStream(String name, OutputStream out) 55 { 56 super(new ByteArrayOutputStream()); 57 bufOut = (ByteArrayOutputStream) super.out; 58 59 this.name = name; 60 setOutputStream(out); 61 } 62 63 72 @Deprecated 73 public static LogStream log(String name) { 74 LogStream stream; 75 synchronized (known) { 76 stream = (LogStream )known.get(name); 77 if (stream == null) { 78 stream = new LogStream (name, defaultStream); 79 } 80 known.put(name, stream); 81 } 82 return stream; 83 } 84 85 92 @Deprecated 93 public static synchronized PrintStream getDefaultStream() { 94 return defaultStream; 95 } 96 97 104 @Deprecated 105 public static synchronized void setDefaultStream(PrintStream newDefault) { 106 defaultStream = newDefault; 107 } 108 109 116 @Deprecated 117 public synchronized OutputStream getOutputStream() 118 { 119 return logOut; 120 } 121 122 129 @Deprecated 130 public synchronized void setOutputStream(OutputStream out) 131 { 132 logOut = out; 133 logWriter = new OutputStreamWriter(logOut); 136 } 137 138 146 @Deprecated 147 public void write(int b) 148 { 149 if (b == '\n') { 150 synchronized (this) { 152 synchronized (logOut) { 153 buffer.setLength(0);; 155 buffer.append( (new Date()).toString()); 157 buffer.append(':'); 158 buffer.append(name); buffer.append(':'); 160 buffer.append(Thread.currentThread().getName()); 161 buffer.append(':'); 163 try { 164 logWriter.write(buffer.toString()); 166 logWriter.flush(); 167 168 bufOut.writeTo(logOut); 171 logOut.write(b); 172 logOut.flush(); 173 } catch (IOException e) { 174 setError(); 175 } finally { 176 bufOut.reset(); 177 } 178 } 179 } 180 } 181 else 182 super.write(b); 183 } 184 185 190 @Deprecated 191 public void write(byte b[], int off, int len) 192 { 193 if (len < 0) 194 throw new ArrayIndexOutOfBoundsException (len); 195 for (int i = 0; i < len; ++ i) 196 write(b[off + i]); 197 } 198 199 205 @Deprecated 206 public String toString() 207 { 208 return name; 209 } 210 211 212 public static final int SILENT = 0; 213 214 public static final int BRIEF = 10; 215 216 public static final int VERBOSE = 20; 217 218 226 @Deprecated 227 public static int parseLevel(String s) 228 { 229 if ((s == null) || (s.length() < 1)) 230 return -1; 231 232 try { 233 return Integer.parseInt(s); 234 } catch (NumberFormatException e) { 235 } 236 if (s.length() < 1) 237 return -1; 238 239 if ("SILENT".startsWith(s.toUpperCase())) 240 return SILENT; 241 else if ("BRIEF".startsWith(s.toUpperCase())) 242 return BRIEF; 243 else if ("VERBOSE".startsWith(s.toUpperCase())) 244 return VERBOSE; 245 246 return -1; 247 } 248 } 249 | Popular Tags |