Source Code Cross Referenced for ICETracer.java in  » Source-Control » jcvsweb » com » ice » util » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Source Control » jcvsweb » com.ice.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         ** Copyright (c) 1997 by Timothy Gerard Endres
003:         ** 
004:         ** This program is free software.
005:         ** 
006:         ** You may redistribute it and/or modify it under the terms of the GNU
007:         ** General Public License as published by the Free Software Foundation.
008:         ** Version 2 of the license should be included with this distribution in
009:         ** the file LICENSE, as well as License.html. If the license is not
010:         ** included	with this distribution, you may find a copy at the FSF web
011:         ** site at 'www.gnu.org' or 'www.fsf.org', or you may write to the
012:         ** Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139 USA.
013:         **
014:         ** THIS SOFTWARE IS PROVIDED AS-IS WITHOUT WARRANTY OF ANY KIND,
015:         ** NOT EVEN THE IMPLIED WARRANTY OF MERCHANTABILITY. THE AUTHOR
016:         ** OF THIS SOFTWARE, ASSUMES _NO_ RESPONSIBILITY FOR ANY
017:         ** CONSEQUENCE RESULTING FROM THE USE, MODIFICATION, OR
018:         ** REDISTRIBUTION OF THIS SOFTWARE. 
019:         ** 
020:         */
021:
022:        package com.ice.util;
023:
024:        import java.io.*;
025:        import java.lang.*;
026:        import java.text.*;
027:        import java.util.*;
028:
029:        /**
030:         * The ICETracer class implements the a stack tracing mechanism
031:         * for debugging use. This is a <strong>strictly</strong> class
032:         * based interface. There are no instance methods.
033:         *
034:         * @version $Revision: 1.4 $
035:         * @author Timothy Gerard Endres,
036:         *    <a href="mailto:time@ice.com">time@ice.com</a>.
037:         *
038:         * @see com.ice.util.UserProperties
039:         *
040:         */
041:
042:        public class ICETracer extends Object {
043:            static public final String RCS_ID = "$Id: ICETracer.java,v 1.4 1998/04/29 16:30:13 time Exp $";
044:            static public final String RCS_REV = "$Revision: 1.4 $";
045:
046:            static private PrintWriter out = null;
047:
048:            static private boolean state = false;
049:            static private boolean ifOverOn = true;
050:
051:            static private int traceState = 0;
052:
053:            static private boolean outIsSystem = false;
054:
055:            static private boolean echoAccum = false;
056:            static private StringBuffer outBuffer = null;
057:
058:            static public void setTraceState(boolean state) {
059:                ICETracer.state = state;
060:            }
061:
062:            static public void setEchoAccumulation(boolean state) {
063:                ICETracer.echoAccum = state;
064:            }
065:
066:            static public void accumulateInBuffer(StringBuffer buffer) {
067:                ICETracer.outBuffer = buffer;
068:            }
069:
070:            static public void turnOffAccumulation() {
071:                ICETracer.outBuffer = null;
072:            }
073:
074:            static public StringBuffer getAccumulationBuffer() {
075:                return ICETracer.outBuffer;
076:            }
077:
078:            static public void println(String line) {
079:                if (line == null)
080:                    return;
081:
082:                if (ICETracer.outBuffer != null) {
083:                    ICETracer.outBuffer.append(line);
084:                    ICETracer.outBuffer.append("\n");
085:
086:                    if (!ICETracer.echoAccum)
087:                        return;
088:                }
089:
090:                if (out != null) {
091:                    ICETracer.out.println(line);
092:                } else {
093:                    System.err.println(line);
094:                }
095:            }
096:
097:            static public void trace(String line) {
098:                if (line == null)
099:                    return;
100:
101:                if (ICETracer.state) {
102:                    ICETracer.println(line);
103:                }
104:            }
105:
106:            static public void traceIf(boolean flag, String line) {
107:                if ((!flag) || (line == null))
108:                    return;
109:
110:                if (ICETracer.ifOverOn) {
111:                    ICETracer.println(line);
112:                }
113:            }
114:
115:            static public void traceWithStack(String line) {
116:                if (line == null)
117:                    return;
118:
119:                Throwable thrower = new Throwable(line);
120:
121:                if (ICETracer.state) {
122:                    ICETracer.println(line);
123:                }
124:
125:                if (ICETracer.out == null)
126:                    thrower.printStackTrace(System.err);
127:                else
128:                    thrower.printStackTrace(ICETracer.out);
129:            }
130:
131:            static public String getStackLines(Throwable thrower) {
132:                StringWriter sWrtr = new StringWriter();
133:                PrintWriter pWrtr = new PrintWriter(sWrtr);
134:                thrower.printStackTrace(pWrtr);
135:                return sWrtr.toString();
136:            }
137:
138:            static public String getStackLines(Throwable thrower, int maxLines) {
139:                if (maxLines == 0)
140:                    return ICETracer.getStackLines(thrower);
141:
142:                StringWriter sWrtr = new StringWriter();
143:                PrintWriter pWrtr = new PrintWriter(sWrtr);
144:
145:                thrower.printStackTrace(pWrtr);
146:
147:                String trcStr = sWrtr.getBuffer().toString();
148:
149:                String sep = System.getProperty("line.separator", "\n");
150:
151:                int offset = 0;
152:                int index = trcStr.length();
153:                for (int ln = 0; ln < maxLines; ++ln) {
154:                    int idx = trcStr.indexOf(sep, offset);
155:                    if (idx == -1)
156:                        break;
157:
158:                    index = idx;
159:                    offset = idx + 1;
160:                }
161:
162:                return trcStr.substring(0, index);
163:            }
164:
165:            static public void traceWithStack(int maxPrintLines, String line) {
166:                if (line == null || maxPrintLines < 1)
167:                    return;
168:
169:                Throwable thrower = new Throwable(line);
170:
171:                if (ICETracer.state) {
172:                    ICETracer.println(line);
173:                }
174:
175:                String outStr = ICETracer.getStackLines(thrower, maxPrintLines);
176:
177:                if (ICETracer.out == null)
178:                    System.err.println(outStr);
179:                else
180:                    ICETracer.out.println(outStr);
181:            }
182:
183:            static public void traceWithStack(Throwable thrower, String line) {
184:                if (thrower == null && line == null)
185:                    return;
186:
187:                if (line != null)
188:                    ICETracer.println(line);
189:
190:                String outStr = ICETracer.getStackLines(thrower, 0);
191:
192:                if (ICETracer.out == null)
193:                    System.err.println(outStr);
194:                else
195:                    ICETracer.out.println(outStr);
196:            }
197:
198:            static public void traceWithStack(Throwable thrower, int lines,
199:                    String line) {
200:                if (thrower == null && line == null)
201:                    return;
202:
203:                if (line != null)
204:                    ICETracer.println(line);
205:
206:                String outStr = ICETracer.getStackLines(thrower, lines);
207:
208:                if (ICETracer.out == null)
209:                    System.err.println(outStr);
210:                else
211:                    ICETracer.out.println(outStr);
212:            }
213:
214:            static private void checkClose() {
215:                if (ICETracer.out != null) {
216:                    if (!ICETracer.outIsSystem) {
217:                        ICETracer.out.close();
218:                        ICETracer.out = null;
219:                        ICETracer.outIsSystem = false;
220:                    }
221:                }
222:            }
223:
224:            /**
225:             * Sets the tracer's output writer to the BufferedWriter
226:             * passed in. The new writer <em>newOut</em> <strong>must never</strong>
227:             * be System.err or System.err, since the writer will be
228:             * closed at some point.
229:             *
230:             * @param newOut The new buffered writer to send trace output to.
231:             */
232:
233:            static public void setWriter(PrintWriter newOut) {
234:                ICETracer.checkClose();
235:
236:                ICETracer.out = newOut;
237:                ICETracer.outIsSystem = false;
238:
239:                ICETracer.outBuffer = null;
240:            }
241:
242:            static public void setWriterToStdout() {
243:                PrintWriter newOut = new PrintWriter(new OutputStreamWriter(
244:                        System.out));
245:
246:                if (newOut != null) {
247:                    ICETracer.checkClose();
248:                    ICETracer.out = newOut;
249:                    ICETracer.outIsSystem = true;
250:
251:                    ICETracer.outBuffer = null;
252:                }
253:            }
254:
255:            static public void setWriterToStderr() {
256:                PrintWriter newOut = new PrintWriter(new OutputStreamWriter(
257:                        System.err));
258:
259:                if (newOut != null) {
260:                    ICETracer.checkClose();
261:                    ICETracer.out = newOut;
262:                    ICETracer.outIsSystem = true;
263:
264:                    ICETracer.outBuffer = null;
265:                }
266:            }
267:
268:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.