Source Code Cross Referenced for DebuggingPrintWriter.java in  » Ajax » dwr » org » directwebremoting » 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 » Ajax » dwr » org.directwebremoting.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2005 Joe Walker
003:         *
004:         * Licensed under the Apache License, Version 2.0 (the "License");
005:         * you may not use this file except in compliance with the License.
006:         * You may obtain a copy of the License at
007:         *
008:         *     http://www.apache.org/licenses/LICENSE-2.0
009:         *
010:         * Unless required by applicable law or agreed to in writing, software
011:         * distributed under the License is distributed on an "AS IS" BASIS,
012:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013:         * See the License for the specific language governing permissions and
014:         * limitations under the License.
015:         */
016:        package org.directwebremoting.util;
017:
018:        import java.io.BufferedWriter;
019:        import java.io.OutputStream;
020:        import java.io.OutputStreamWriter;
021:        import java.io.PrintWriter;
022:        import java.io.Writer;
023:
024:        import org.apache.commons.logging.LogFactory;
025:        import org.apache.commons.logging.Log;
026:
027:        /**
028:         * A PrintWriter that also sends its output to a log stream
029:         * @author Joe Walker [joe at getahead dot ltd dot uk]
030:         */
031:        public class DebuggingPrintWriter extends PrintWriter {
032:            /**
033:             * Create a new PrintWriter, without automatic line flushing.
034:             * @param prefix A tag to prefix lines with for debugging purposes
035:             * @param out A character-output stream
036:             */
037:            public DebuggingPrintWriter(String prefix, Writer out) {
038:                super (out, false);
039:                this .prefix = prefix;
040:            }
041:
042:            /**
043:             * Create a new PrintWriter.
044:             * @param prefix A tag to prefix lines with for debugging purposes
045:             * @param out A character-output stream
046:             * @param autoFlush A boolean; if true, the println() methods will flush the output buffer
047:             */
048:            public DebuggingPrintWriter(String prefix, Writer out,
049:                    boolean autoFlush) {
050:                super (out, autoFlush);
051:                this .prefix = prefix;
052:            }
053:
054:            /**
055:             * Create a new PrintWriter, without automatic line flushing, from an
056:             * existing OutputStream.  This convenience constructor creates the
057:             * necessary intermediate OutputStreamWriter, which will convert characters
058:             * into bytes using the default character encoding.
059:             * @param prefix A tag to prefix lines with for debugging purposes
060:             * @param out An output stream
061:             * @see java.io.OutputStreamWriter#OutputStreamWriter(java.io.OutputStream)
062:             */
063:            public DebuggingPrintWriter(String prefix, OutputStream out) {
064:                super (out, false);
065:                this .prefix = prefix;
066:            }
067:
068:            /**
069:             * Create a new PrintWriter from an existing OutputStream.  This convenience
070:             * constructor creates the necessary intermediate OutputStreamWriter, which
071:             * will convert characters into bytes using the default character encoding.
072:             * @param prefix A tag to prefix lines with for debugging purposes
073:             * @param out An output stream
074:             * @param autoFlush A boolean; if true, the println() methods will flush the output buffer
075:             * @see java.io.OutputStreamWriter#OutputStreamWriter(java.io.OutputStream)
076:             */
077:            public DebuggingPrintWriter(String prefix, OutputStream out,
078:                    boolean autoFlush) {
079:                super (new BufferedWriter(new OutputStreamWriter(out)),
080:                        autoFlush);
081:                this .prefix = prefix;
082:            }
083:
084:            /* (non-Javadoc)
085:             * @see java.io.PrintWriter#print(boolean)
086:             */
087:            @Override
088:            public void print(boolean x) {
089:                super .print(x);
090:                buffer.append(x);
091:            }
092:
093:            /* (non-Javadoc)
094:             * @see java.io.PrintWriter#print(char)
095:             */
096:            @Override
097:            public void print(char x) {
098:                super .print(x);
099:                buffer.append(x);
100:            }
101:
102:            /* (non-Javadoc)
103:             * @see java.io.PrintWriter#print(int)
104:             */
105:            @Override
106:            public void print(int x) {
107:                super .print(x);
108:                buffer.append(x);
109:            }
110:
111:            /* (non-Javadoc)
112:             * @see java.io.PrintWriter#print(long)
113:             */
114:            @Override
115:            public void print(long x) {
116:                super .print(x);
117:                buffer.append(x);
118:            }
119:
120:            /* (non-Javadoc)
121:             * @see java.io.PrintWriter#print(float)
122:             */
123:            @Override
124:            public void print(float x) {
125:                super .print(x);
126:                buffer.append(x);
127:            }
128:
129:            /* (non-Javadoc)
130:             * @see java.io.PrintWriter#print(double)
131:             */
132:            @Override
133:            public void print(double x) {
134:                super .print(x);
135:                buffer.append(x);
136:            }
137:
138:            /* (non-Javadoc)
139:             * @see java.io.PrintWriter#print(char[])
140:             */
141:            @Override
142:            public void print(char[] x) {
143:                super .print(x);
144:                buffer.append(x);
145:            }
146:
147:            /* (non-Javadoc)
148:             * @see java.io.PrintWriter#print(java.lang.String)
149:             */
150:            @Override
151:            public void print(String x) {
152:                super .print(x);
153:                buffer.append(x);
154:            }
155:
156:            /* (non-Javadoc)
157:             * @see java.io.PrintWriter#print(java.lang.Object)
158:             */
159:            @Override
160:            public void print(Object x) {
161:                super .print(x);
162:                buffer.append(x);
163:            }
164:
165:            /* (non-Javadoc)
166:             * @see java.io.PrintWriter#println()
167:             */
168:            @Override
169:            public void println() {
170:                synchronized (lock) {
171:                    printBuffer();
172:                    super .println();
173:                }
174:            }
175:
176:            /* (non-Javadoc)
177:             * @see java.io.PrintWriter#println(boolean)
178:             */
179:            @Override
180:            public void println(boolean x) {
181:                synchronized (lock) {
182:                    printBuffer();
183:                    super .println(x);
184:                }
185:            }
186:
187:            /* (non-Javadoc)
188:             * @see java.io.PrintWriter#println(char)
189:             */
190:            @Override
191:            public void println(char x) {
192:                synchronized (lock) {
193:                    printBuffer();
194:                    super .println(x);
195:                }
196:            }
197:
198:            /* (non-Javadoc)
199:             * @see java.io.PrintWriter#println(int)
200:             */
201:            @Override
202:            public void println(int x) {
203:                synchronized (lock) {
204:                    printBuffer();
205:                    super .println(x);
206:                }
207:            }
208:
209:            /* (non-Javadoc)
210:             * @see java.io.PrintWriter#println(long)
211:             */
212:            @Override
213:            public void println(long x) {
214:                synchronized (lock) {
215:                    printBuffer();
216:                    super .println(x);
217:                }
218:            }
219:
220:            /* (non-Javadoc)
221:             * @see java.io.PrintWriter#println(float)
222:             */
223:            @Override
224:            public void println(float x) {
225:                synchronized (lock) {
226:                    printBuffer();
227:                    super .println(x);
228:                }
229:            }
230:
231:            /* (non-Javadoc)
232:             * @see java.io.PrintWriter#println(double)
233:             */
234:            @Override
235:            public void println(double x) {
236:                synchronized (lock) {
237:                    printBuffer();
238:                    super .println(x);
239:                }
240:            }
241:
242:            /* (non-Javadoc)
243:             * @see java.io.PrintWriter#println(char[])
244:             */
245:            @Override
246:            public void println(char[] x) {
247:                synchronized (lock) {
248:                    printBuffer();
249:                    super .println(x);
250:                }
251:            }
252:
253:            /* (non-Javadoc)
254:             * @see java.io.PrintWriter#println(java.lang.String)
255:             */
256:            @Override
257:            public void println(String x) {
258:                synchronized (lock) {
259:                    printBuffer();
260:                    super .println(x);
261:                }
262:            }
263:
264:            /* (non-Javadoc)
265:             * @see java.io.PrintWriter#println(java.lang.Object)
266:             */
267:            @Override
268:            public void println(Object x) {
269:                synchronized (lock) {
270:                    printBuffer();
271:                    super .println(x);
272:                }
273:            }
274:
275:            /**
276:             * Write the characters in the print buffer out to the stream
277:             */
278:            private void printBuffer() {
279:                if (buffer.length() > 0) {
280:                    log.debug(prefix + buffer.toString());
281:                    buffer.setLength(0);
282:                }
283:            }
284:
285:            /**
286:             * How to we prefix all the debugging lines?
287:             * @return the prefix
288:             */
289:            public String getPrefix() {
290:                return prefix;
291:            }
292:
293:            /**
294:             * How to we prefix all the debugging lines?
295:             * @param prefix the prefix to set
296:             */
297:            public void setPrefix(String prefix) {
298:                this .prefix = prefix;
299:            }
300:
301:            /**
302:             * How to we prefix all the debugging lines?
303:             */
304:            private String prefix;
305:
306:            /**
307:             * A buffer where we store stuff before a newline
308:             */
309:            protected final StringBuffer buffer = new StringBuffer();
310:
311:            /**
312:             * The log stream
313:             */
314:            private static final Log log = LogFactory
315:                    .getLog(DebuggingPrintWriter.class);
316:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.