Source Code Cross Referenced for SerializedObject.java in  » Science » weka » weka » core » 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.core 
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:         *    SerializedObject.java
019:         *    Copyright (C) 2001 University of Waikato, Hamilton, New Zealand
020:         *
021:         */
022:
023:        package weka.core;
024:
025:        import java.io.BufferedInputStream;
026:        import java.io.BufferedOutputStream;
027:        import java.io.ByteArrayInputStream;
028:        import java.io.ByteArrayOutputStream;
029:        import java.io.ObjectInputStream;
030:        import java.io.ObjectOutputStream;
031:        import java.io.OutputStream;
032:        import java.io.Serializable;
033:        import java.util.zip.GZIPInputStream;
034:        import java.util.zip.GZIPOutputStream;
035:
036:        /**
037:         * Class for storing an object in serialized form in memory. It can be used 
038:         * to make deep copies of objects, and also allows compression to conserve
039:         * memory. <p>
040:         *
041:         * @author Richard Kirkby (rbk1@cs.waikato.ac.nz)
042:         * @version $Revision: 1.10 $ 
043:         */
044:        public class SerializedObject implements  Serializable {
045:
046:            /** for serialization */
047:            private static final long serialVersionUID = 6635502953928860434L;
048:
049:            /** The array storing the object. */
050:            private byte[] m_storedObjectArray;
051:
052:            /** Whether or not the object is compressed. */
053:            private boolean m_isCompressed;
054:
055:            /**
056:             * Creates a new serialized object (without compression).
057:             *
058:             * @param toStore the object to store
059:             * @exception Exception if the object couldn't be serialized
060:             */
061:            public SerializedObject(Object toStore) throws Exception {
062:
063:                this (toStore, false);
064:            }
065:
066:            /**
067:             * Creates a new serialized object.
068:             *
069:             * @param toStore the object to store
070:             * @param compress whether or not to use compression
071:             * @exception Exception if the object couldn't be serialized
072:             */
073:            public SerializedObject(Object toStore, boolean compress)
074:                    throws Exception {
075:
076:                ByteArrayOutputStream ostream = new ByteArrayOutputStream();
077:                OutputStream os = ostream;
078:                ObjectOutputStream p;
079:                if (!compress)
080:                    p = new ObjectOutputStream(new BufferedOutputStream(os));
081:                else
082:                    p = new ObjectOutputStream(new BufferedOutputStream(
083:                            new GZIPOutputStream(os)));
084:                p.writeObject(toStore);
085:                p.flush();
086:                p.close(); // used to be ostream.close() !
087:                m_storedObjectArray = ostream.toByteArray();
088:
089:                m_isCompressed = compress;
090:            }
091:
092:            /*
093:             * Checks to see whether this object is equal to another.
094:             *
095:             * @param compareTo the object to compare to
096:             * @return whether or not the objects are equal
097:             */
098:            public final boolean equals(Object compareTo) {
099:
100:                if (compareTo == null)
101:                    return false;
102:                if (!compareTo.getClass().equals(this .getClass()))
103:                    return false;
104:                byte[] compareArray = ((SerializedObject) compareTo).m_storedObjectArray;
105:                if (compareArray.length != m_storedObjectArray.length)
106:                    return false;
107:                for (int i = 0; i < compareArray.length; i++) {
108:                    if (compareArray[i] != m_storedObjectArray[i])
109:                        return false;
110:                }
111:                return true;
112:            }
113:
114:            /**
115:             * Returns a hashcode for this object.
116:             *
117:             * @return the hashcode
118:             */
119:            public int hashCode() {
120:
121:                return m_storedObjectArray.length;
122:            }
123:
124:            /**
125:             * Returns a serialized object.
126:             *
127:             * @return the restored object
128:             * @exception Exception if the object couldn't be restored
129:             */
130:            public Object getObject() {
131:
132:                try {
133:                    ByteArrayInputStream istream = new ByteArrayInputStream(
134:                            m_storedObjectArray);
135:                    ObjectInputStream p;
136:                    if (!m_isCompressed)
137:                        p = new ObjectInputStream(new BufferedInputStream(
138:                                istream));
139:                    else
140:                        p = new ObjectInputStream(new BufferedInputStream(
141:                                new GZIPInputStream(istream)));
142:                    Object toReturn = p.readObject();
143:                    istream.close();
144:                    return toReturn;
145:                } catch (Exception e) {
146:                    e.printStackTrace();
147:                    return null;
148:                }
149:            }
150:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.