1
/* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */
4
Part of the Processing project - http://processing.org
6
Copyright (c) 2004-06 Ben Fry and Casey Reas
7
Copyright (c) 2001-04 Massachusetts Institute of Technology
9
This program is free software; you can redistribute it and/or modify
10
it under the terms of the GNU General Public License as published by
11
the Free Software Foundation; either version 2 of the License, or
12
(at your option) any later version.
14
This program is distributed in the hope that it will be useful,
15
but WITHOUT ANY WARRANTY; without even the implied warranty of
16
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
GNU General Public License for more details.
19
You should have received a copy of the GNU General Public License
20
along with this program; if not, write to the Free Software Foundation,
21
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24
package processing.app.debug;
30
* Slurps up messages from compiler.
32
class MessageSiphon implements Runnable {
33
BufferedReader streamReader;
35
MessageConsumer consumer;
38
public MessageSiphon(InputStream stream, MessageConsumer consumer) {
39
this.streamReader = new BufferedReader(new InputStreamReader(stream));
40
this.consumer = consumer;
42
thread = new Thread(this);
43
// don't set priority too low, otherwise exceptions won't
44
// bubble up in time (i.e. compile errors have a weird delay)
45
//thread.setPriority(Thread.MIN_PRIORITY);
46
thread.setPriority(Thread.MAX_PRIORITY-1);
53
// process data until we hit EOF; this will happily block
54
// (effectively sleeping the thread) until new data comes in.
55
// when the program is finally done, null will come through.
58
while ((currentLine = streamReader.readLine()) != null) {
59
// \n is added again because readLine() strips it out
60
//EditorConsole.systemOut.println("messaging in");
61
consumer.message(currentLine + "\n");
62
//EditorConsole.systemOut.println("messaging out");
64
//EditorConsole.systemOut.println("messaging thread done");
67
} catch (NullPointerException npe) {
68
// Fairly common exception during shutdown
71
} catch (Exception e) {
72
// On Linux and sometimes on Mac OS X, a "bad file descriptor"
73
// message comes up when closing an applet that's run externally.
74
// That message just gets supressed here..
75
String mess = e.getMessage();
77
(mess.indexOf("Bad file descriptor") != -1)) {
78
//if (e.getMessage().indexOf("Bad file descriptor") == -1) {
79
//System.err.println("MessageSiphon err " + e);
80
//e.printStackTrace();