1 19 20 package org.netbeans.core.output2; 21 22 import org.openide.windows.OutputWriter; 23 import org.openide.windows.OutputListener; 24 import java.io.IOException ; 25 import org.openide.util.Exceptions; 26 27 28 35 class NbWriter extends OutputWriter { 36 private final NbIO owner; 37 40 public NbWriter(OutWriter real, NbIO owner) { 41 super(real); 42 this.owner = owner; 43 } 44 45 public void println(String s, OutputListener l) throws IOException { 46 ((OutWriter) out).println (s, l); 47 } 48 49 50 public void println(String s, OutputListener l, boolean important) throws IOException { 51 ((OutWriter) out).println (s, l, important); 52 } 53 54 59 public void reset() throws IOException { 60 if (!((OutWriter) out).hasStorage() && !((OutWriter) out).isDisposed() || ((OutWriter) out).isEmpty()) { 61 if (!out().isDisposed()) { 63 if (Controller.LOG) Controller.log ("Extra call to Reset on " + this + " for " + out); 64 owner.setStreamClosed(false); 68 return; 69 } 70 } 71 synchronized (this) { 72 if (out != null) { 73 if (Controller.LOG) Controller.log ("Disposing old OutWriter"); 74 out().dispose(); 75 } 76 if (Controller.LOG) Controller.log ("NbWriter.reset() replacing old OutWriter"); 77 out = new OutWriter(owner); 78 lock = out; 79 if (err != null) { 80 err.setWrapped((OutWriter) out); 81 } 82 owner.reset(); 83 } 84 } 85 86 OutWriter out() { 87 return (OutWriter) out; 88 } 89 90 ErrWriter err() { 91 return err; 92 } 93 94 private ErrWriter err = null; 95 public synchronized ErrWriter getErr() { 96 if (err == null) { 97 err = new ErrWriter ((OutWriter) out, this); 98 } 99 return err; 100 } 101 102 public void close() { 103 boolean wasClosed = isClosed(); 104 if (Controller.LOG) Controller.log ("NbWriter.close wasClosed=" + wasClosed + " out is " + out + " out is closed " + ((OutWriter) out).isClosed()); 105 if (!wasClosed || !((OutWriter) out).isClosed()) { 106 synchronized (lock) { 107 try { 108 if (Controller.LOG) Controller.log ( "Now closing OutWriter"); 109 out.close(); 110 } catch (IOException ioe) { 111 Exceptions.printStackTrace(ioe); 112 } 113 } 114 } 115 boolean isClosed = isClosed(); 116 if (wasClosed != isClosed) { 117 if (Controller.LOG) Controller.log ("Setting streamClosed on InputOutput to " + isClosed); 118 owner.setStreamClosed(isClosed); 119 } 120 } 121 122 public boolean isClosed() { 123 OutWriter ow = (OutWriter) out; 124 synchronized (ow) { 125 boolean result = ow.isClosed(); 126 if (result && err != null && !(ow.checkError())) { 127 result &= err.isClosed(); 128 } 129 return result; 130 } 131 } 132 133 public void notifyErrClosed() { 134 if (isClosed()) { 135 if (Controller.LOG) Controller.log ("NbWriter.notifyErrClosed - error stream has been closed"); 136 owner.setStreamClosed(isClosed()); 137 } 138 } 139 140 143 public void println (String s) { 144 synchronized (lock) { 145 ((OutWriter) out).println(s); 146 } 147 } 148 } 149 | Popular Tags |