Source Code Cross Referenced for AppendFile.java in  » Content-Management-System » webman » de » webman » anttasks » 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 » Content Management System » webman » de.webman.anttasks 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package de.webman.anttasks;
002:
003:        import java.io.*;
004:        import org.apache.tools.ant.BuildException;
005:        import org.apache.tools.ant.Task;
006:
007:        /**
008:         * ant task to append an input file to a output file
009:         * 
010:         * this task might be added to the build script with
011:         * <taskdef name="append-file" classname="de.webman.anttasks.AppendFile"/>
012:         * where the name of the task is unimportant
013:         *
014:         * usage:
015:         * <append-file file="inputfile" appendto="outputfile" failonerror=("true"|"false")/>
016:         * 
017:         *      inputfile      the name of the file to append to the output file
018:         *      outputfile     the name of the file the input file will be appended to
019:         *                     if the file does not exist, the input file will be
020:         *                     copied
021:         *              both files must be distinct 
022:         * 
023:         *      failonerror     optional argument,
024:         *                      Stop the buildprocess 
025:         *                      if the input file could not be read 
026:         *                      or the output file can not be written
027:         *              (default is true)
028:         */
029:        public class AppendFile extends Task {
030:
031:            private File infile;
032:            private File outfile;
033:            boolean failonerror = true;
034:
035:            // The method executing the task
036:            public void execute() throws BuildException {
037:                String msg = null;
038:                // file tests
039:                if (infile == null) {
040:                    msg = "argument file must be given";
041:                } else if (outfile == null) {
042:                    msg = "argument appendto must be given";
043:                } else if (!infile.exists()) {
044:                    msg = "file " + infile + " does not exist";
045:                } else if (!infile.isFile()) {
046:                    msg = "file " + infile + " is not a plain file";
047:                } else if (!infile.canRead()) {
048:                    msg = "file " + infile + " is not readable";
049:                } else if (infile.equals(outfile)) {
050:                    msg = "cannot append a file to itself";
051:                } else if (outfile.exists()) {
052:                    if (!outfile.isFile()) {
053:                        msg = "file " + outfile + " is not a plain file";
054:                    } else if (!outfile.canWrite()) {
055:                        msg = "file " + outfile + " is not writeable";
056:                    }
057:                }
058:                // throw msg
059:                if (msg != null) {
060:                    if (failonerror) {
061:                        throw new BuildException(msg);
062:                    } else {
063:                        System.out.println(msg);
064:                        return;
065:                    }
066:                }
067:                try {
068:                    // create file if it does not exist
069:                    if (outfile.createNewFile()) {
070:                        System.out.println("created file " + outfile);
071:                    }
072:                    // append now
073:                    FileInputStream fis = new FileInputStream(infile);
074:                    FileOutputStream fos = new FileOutputStream(outfile
075:                            .getPath(), true);
076:                    byte[] buff = new byte[1024];
077:                    int read;
078:                    while ((read = fis.read(buff)) > 0) {
079:                        fos.write(buff, 0, read);
080:                    }
081:                    fis.close();
082:                    fos.flush();
083:                    fos.close();
084:                    // report success
085:                    System.out.println("appended " + infile + " to " + outfile);
086:                } catch (IOException e) {
087:                    throw new BuildException(e);
088:                }
089:            }
090:
091:            /**
092:             *  the setter for the source file
093:             */
094:            public void setFile(File in) {
095:                infile = in;
096:            }
097:
098:            /**
099:             *  the setter for the target file
100:             */
101:            public void setAppendto(File out) {
102:                outfile = out;
103:            }
104:
105:            /**
106:             *  the setter for the failonerror argument
107:             */
108:            public void setFailonerror(boolean newValue) {
109:                failonerror = newValue;
110:            }
111:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.