Source Code Cross Referenced for OutputZipper.java in  » Science » weka » weka » experiment » 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 » Science » weka » weka.experiment 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *    This program is free software; you can redistribute it and/or modify
003:         *    it under the terms of the GNU General Public License as published by
004:         *    the Free Software Foundation; either version 2 of the License, or
005:         *    (at your option) any later version.
006:         *
007:         *    This program is distributed in the hope that it will be useful,
008:         *    but WITHOUT ANY WARRANTY; without even the implied warranty of
009:         *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
010:         *    GNU General Public License for more details.
011:         *
012:         *    You should have received a copy of the GNU General Public License
013:         *    along with this program; if not, write to the Free Software
014:         *    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
015:         */
016:
017:        /*
018:         *    OutputZipper.java
019:         *    Copyright (C) 2000 University of Waikato, Hamilton, New Zealand
020:         *
021:         */
022:
023:        package weka.experiment;
024:
025:        import java.io.DataOutputStream;
026:        import java.io.File;
027:        import java.io.FileOutputStream;
028:        import java.util.zip.GZIPOutputStream;
029:        import java.util.zip.ZipEntry;
030:        import java.util.zip.ZipOutputStream;
031:
032:        /**
033:         * OutputZipper writes output to either gzipped files or to a
034:         * multi entry zip file. If the destination file is a directory
035:         * each output string will be written to an individually named
036:         * gzip file. If the destination file is a file, then each
037:         * output string is appended as a named entry to the zip file until
038:         * finished() is called to close the file.
039:         *
040:         * @author Mark Hall (mhall@cs.waikato.ac.nz)
041:         * @version $Revision: 1.7 $
042:         */
043:        public class OutputZipper {
044:
045:            File m_destination;
046:            DataOutputStream m_zipOut = null;
047:            ZipOutputStream m_zs = null;
048:
049:            /**
050:             * Constructor.
051:             * 
052:             * @param destination a destination file or directory
053:             * @throws Exception if something goes wrong.
054:             */
055:            public OutputZipper(File destination) throws Exception {
056:
057:                m_destination = destination;
058:
059:                // if a directory is specified then use gzip format, otherwise
060:                // use zip
061:                if (!m_destination.isDirectory()) {
062:                    m_zs = new ZipOutputStream(new FileOutputStream(
063:                            m_destination));
064:                    m_zipOut = new DataOutputStream(m_zs);
065:                }
066:            }
067:
068:            /**
069:             * Saves a string to either an individual gzipped file or as
070:             * an entry in a zip file.
071:             * 
072:             * @param outString the output string to save
073:             * @param name the name of the file/entry to save it to
074:             * @throws Exception if something goes wrong
075:             */
076:            public void zipit(String outString, String name) throws Exception {
077:                File saveFile;
078:                ZipEntry ze;
079:
080:                if (m_zipOut == null) {
081:                    saveFile = new File(m_destination, name + ".gz");
082:                    DataOutputStream dout = new DataOutputStream(
083:                            new GZIPOutputStream(new FileOutputStream(saveFile)));
084:
085:                    dout.writeBytes(outString);
086:                    dout.close();
087:                } else {
088:                    ze = new ZipEntry(name);
089:                    m_zs.putNextEntry(ze);
090:                    m_zipOut.writeBytes(outString);
091:                    m_zs.closeEntry();
092:                }
093:            }
094:
095:            /**
096:             * Closes the zip file.
097:             * 
098:             * @throws Exception if something goes wrong
099:             */
100:            public void finished() throws Exception {
101:                if (m_zipOut != null) {
102:                    m_zipOut.close();
103:                }
104:            }
105:
106:            /**
107:             * Main method for testing this class
108:             */
109:            public static void main(String[] args) {
110:
111:                try {
112:                    File testF = new File(new File(System
113:                            .getProperty("user.dir")), "testOut.zip");
114:                    OutputZipper oz = new OutputZipper(testF);
115:
116:                    /*      OutputZipper oz = new OutputZipper(
117:                        new File(System.getProperty("user.dir"))); */
118:                    oz.zipit("Here is some test text to be zipped", "testzip");
119:                    oz.zipit("Here is a second entry to be zipped", "testzip2");
120:                    oz.finished();
121:                } catch (Exception ex) {
122:                    ex.printStackTrace();
123:                    System.err.println(ex.getMessage());
124:                }
125:            }
126:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.