Source Code Cross Referenced for FileTarget.java in  » Net » openfire » org » jivesoftware » util » log » output » io » 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 » Net » openfire » org.jivesoftware.util.log.output.io 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright (C) The Apache Software Foundation. All rights reserved.
003:         *
004:         * This software is published under the terms of the Apache Software License
005:         * version 1.1, a copy of which has been included with this distribution in
006:         * the LICENSE file.
007:         */
008:        package org.jivesoftware.util.log.output.io;
009:
010:        import org.jivesoftware.util.log.format.Formatter;
011:        import java.io.File;
012:        import java.io.FileOutputStream;
013:        import java.io.IOException;
014:
015:        /**
016:         * A basic target that writes to a File.
017:         *
018:         * @author <a href="mailto:peter@apache.org">Peter Donald</a>
019:         */
020:        public class FileTarget extends StreamTarget {
021:
022:            ///File we are writing to
023:            private File m_file;
024:
025:            ///Flag indicating whether or not file should be appended to
026:            private boolean m_append;
027:
028:            /**
029:             * Construct file target to send to a file with a formatter.
030:             *
031:             * @param file      the file to send to
032:             * @param append    true if file is to be appended to, false otherwise
033:             * @param formatter the Formatter
034:             * @throws IOException if an error occurs
035:             */
036:            public FileTarget(final File file, final boolean append,
037:                    final Formatter formatter) throws IOException {
038:                super (null, formatter);
039:
040:                if (null != file) {
041:                    setFile(file, append);
042:                    openFile();
043:                }
044:            }
045:
046:            /**
047:             * Set the file for this target.
048:             *
049:             * @param file   the file to send to
050:             * @param append true if file is to be appended to, false otherwise
051:             * @throws IOException if directories can not be created or file can not be opened
052:             */
053:            protected synchronized void setFile(final File file,
054:                    final boolean append) throws IOException {
055:                if (null == file) {
056:                    throw new NullPointerException(
057:                            "file property must not be null");
058:                }
059:
060:                if (isOpen()) {
061:                    throw new IOException("target must be closed before "
062:                            + "file property can be set");
063:                }
064:
065:                m_append = append;
066:                m_file = file;
067:            }
068:
069:            /**
070:             * Open underlying file and allocate resources.
071:             * This method will attempt to create directories below file and
072:             * append to it if specified.
073:             */
074:            protected synchronized void openFile() throws IOException {
075:                if (isOpen())
076:                    close();
077:
078:                final File file = getFile().getCanonicalFile();
079:
080:                final File parent = file.getParentFile();
081:                if (null != parent && !parent.exists()) {
082:                    parent.mkdir();
083:                }
084:
085:                final FileOutputStream outputStream = new FileOutputStream(file
086:                        .getPath(), m_append);
087:
088:                setOutputStream(outputStream);
089:                open();
090:            }
091:
092:            /**
093:             * Retrieve file associated with target.
094:             * This allows subclasses to access file object.
095:             *
096:             * @return the output File
097:             */
098:            protected synchronized File getFile() {
099:                return m_file;
100:            }
101:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.