Source Code Cross Referenced for StreamLogger.java in  » Portal » Open-Portal » com » sun » portal » fabric » 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 » Portal » Open Portal » com.sun.portal.fabric.util 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * $Id: StreamLogger.java,v 1.6 2006/09/04 11:15:13 mr161608 Exp $
003:         * Copyright 2004 Sun Microsystems, Inc. All
004:         * rights reserved. Use of this product is subject
005:         * to license terms. Federal Acquisitions:
006:         * Commercial Software -- Government Users
007:         * Subject to Standard License Terms and
008:         * Conditions.
009:         *
010:         * Sun, Sun Microsystems, the Sun logo, and Sun ONE
011:         * are trademarks or registered trademarks of Sun Microsystems,
012:         * Inc. in the United States and other countries.
013:         */package com.sun.portal.fabric.util;
014:
015:        import java.io.BufferedReader;
016:        import java.io.InputStream;
017:        import java.io.InputStreamReader;
018:        import java.util.logging.Level;
019:        import java.util.logging.Logger;
020:        import java.util.logging.LogRecord;
021:
022:        import com.sun.portal.log.common.PortalLogger;
023:
024:        /**
025:         * This class implements the logic for reading an Input Stream
026:         * that contains data being pushed from a process output or error streams. 
027:         * The data is read from the stream and logged using a the logger
028:         */
029:        class StreamLogger implements  Runnable {
030:
031:            static final String nl = System.getProperty("line.separator");
032:
033:            private InputStreamReader isr = null;
034:            private StringBuffer result = null;
035:            private static Logger logger = PortalLogger
036:                    .getLogger(StreamLogger.class);
037:            private String sname = null;
038:
039:            /**
040:             * Constructor for the StreamLogger class
041:             *
042:             * @param is Input Stream object passed by the caller to be read and logged.
043:             * @param streamName  A String that will be used as a Tag when logging the 
044:             *                    output.
045:             * @param storeContent This boolean flag is used by this class to determine
046:             *                     if the content in the Stream should be preserved and
047:             *                     returned as a String. This flag should be used with
048:             *                     caution. If it is set to <B>true</B> and the Stream
049:             *                     contains a lot of data, the size of the StringBuffer
050:             *                     that stores the output will grow very large and can
051:             *                     cause out of memory conditions.
052:             */
053:            public StreamLogger(InputStream is, String streamName,
054:                    boolean storeContent) {
055:
056:                isr = new InputStreamReader(is);
057:                sname = streamName;
058:                result = storeContent ? new StringBuffer() : null;
059:            }
060:
061:            /**
062:             * Returns the content in the stream as a String
063:             * @return Content of this stream as a String.
064:             * Returns a null if storeContent is set to false
065:             */
066:            public String getContent() {
067:                return (result != null) ? result.toString() : null;
068:            }
069:
070:            /**
071:             * Implements the run method of the Runnable interface.
072:             * This method reads the InputStream in a Buffered Reader and logs the
073:             * each line in the BufferedReader into the Logger object.
074:             */
075:            public void run() {
076:                try {
077:
078:                    BufferedReader br = new BufferedReader(isr);
079:                    String str = null;
080:
081:                    while ((str = br.readLine()) != null) {
082:
083:                        String[] args0 = new String[] { sname, str };
084:                        logger.log(Level.FINEST, "PSFB_CSPFU0004", args0);
085:
086:                        if (result != null) {
087:                            result.append(str);
088:                            result.append(nl);
089:
090:                        }
091:
092:                    }
093:
094:                    if (result != null) {
095:                        result.append(nl);
096:                    }
097:
098:                    // Close the Buffered Reader
099:                    br.close();
100:                } catch (Exception e) {
101:
102:                    if (logger.isLoggable(Level.WARNING)) {
103:                        LogRecord record = new LogRecord(Level.WARNING,
104:                                "PSFB_CSPFU0002");
105:                        record.setParameters(new String[] { sname });
106:                        record.setThrown(e);
107:                        record.setLoggerName(logger.getName());
108:                        logger.log(record);
109:                    }
110:                }
111:            }
112:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.