Source Code Cross Referenced for RamFileData.java in  » Library » Apache-commons-vfs-20070724-src » org » apache » commons » vfs » provider » ram » 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 » Library » Apache commons vfs 20070724 src » org.apache.commons.vfs.provider.ram 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Licensed to the Apache Software Foundation (ASF) under one or more
003:         * contributor license agreements.  See the NOTICE file distributed with
004:         * this work for additional information regarding copyright ownership.
005:         * The ASF licenses this file to You under the Apache License, Version 2.0
006:         * (the "License"); you may not use this file except in compliance with
007:         * the License.  You may obtain a copy of the License at
008:         *
009:         *      http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         * Unless required by applicable law or agreed to in writing, software
012:         * distributed under the License is distributed on an "AS IS" BASIS,
013:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         * See the License for the specific language governing permissions and
015:         * limitations under the License.
016:         */
017:        package org.apache.commons.vfs.provider.ram;
018:
019:        import java.io.Serializable;
020:        import java.util.ArrayList;
021:        import java.util.Collection;
022:        import java.util.Collections;
023:
024:        import org.apache.commons.vfs.FileName;
025:        import org.apache.commons.vfs.FileSystemException;
026:        import org.apache.commons.vfs.FileType;
027:
028:        /**
029:         * RAM File Object Data
030:         */
031:        class RamFileData implements  Serializable {
032:            /**
033:             * File Name
034:             */
035:            private FileName name;
036:
037:            /**
038:             * File Type
039:             */
040:            private FileType type;
041:
042:            /**
043:             * Bytes
044:             */
045:            private byte[] buffer;
046:
047:            /**
048:             * Last modified time
049:             */
050:            private long lastModified;
051:
052:            /**
053:             * Children
054:             */
055:            private Collection children;
056:
057:            /**
058:             * Constructor
059:             */
060:            public RamFileData(FileName name) {
061:                super ();
062:                this .clear();
063:                if (name == null) {
064:                    throw new IllegalArgumentException("name can not be null");
065:                }
066:                this .name = name;
067:            }
068:
069:            /**
070:             * @return Returns the buffer.
071:             */
072:            byte[] getBuffer() {
073:                return buffer;
074:            }
075:
076:            /**
077:             * @param buffer
078:             */
079:            void setBuffer(byte[] buffer) {
080:                updateLastModified();
081:                this .buffer = buffer;
082:            }
083:
084:            /**
085:             * @return Returns the lastModified.
086:             */
087:            long getLastModified() {
088:                return lastModified;
089:            }
090:
091:            /**
092:             * @param lastModified
093:             *            The lastModified to set.
094:             */
095:            void setLastModified(long lastModified) {
096:                this .lastModified = lastModified;
097:            }
098:
099:            /**
100:             * @return Returns the type.
101:             */
102:            FileType getType() {
103:                return type;
104:            }
105:
106:            /**
107:             * @param type
108:             *            The type to set.
109:             */
110:            void setType(FileType type) {
111:                this .type = type;
112:            }
113:
114:            /**
115:             * 
116:             */
117:            void clear() {
118:                this .buffer = new byte[0];
119:                updateLastModified();
120:                this .type = FileType.IMAGINARY;
121:                this .children = Collections
122:                        .synchronizedCollection(new ArrayList());
123:                this .name = null;
124:            }
125:
126:            void updateLastModified() {
127:                this .lastModified = System.currentTimeMillis();
128:            }
129:
130:            /**
131:             * @return Returns the name.
132:             */
133:            FileName getName() {
134:                return name;
135:            }
136:
137:            /*
138:             * (non-Javadoc)
139:             * 
140:             * @see java.lang.Object#toString()
141:             */
142:            public String toString() {
143:                return this .name.toString();
144:            }
145:
146:            /**
147:             * Add a child
148:             * 
149:             * @param data
150:             */
151:            void addChild(RamFileData data) throws FileSystemException {
152:                if (!this .getType().hasChildren()) {
153:                    throw new FileSystemException(
154:                            "A child can only be added in a folder");
155:                }
156:
157:                if (data == null) {
158:                    throw new FileSystemException("No child can be null");
159:                }
160:
161:                if (this .children.contains(data)) {
162:                    throw new FileSystemException("Child already exists. "
163:                            + data);
164:                }
165:
166:                this .children.add(data);
167:                updateLastModified();
168:            }
169:
170:            /**
171:             * Remove a child
172:             * 
173:             * @param data
174:             * @throws FileSystemException
175:             */
176:            void removeChild(RamFileData data) throws FileSystemException {
177:                if (!this .getType().hasChildren()) {
178:                    throw new FileSystemException(
179:                            "A child can only be removed from a folder");
180:                }
181:                if (!this .children.contains(data)) {
182:                    throw new FileSystemException("Child not found. " + data);
183:                }
184:                this .children.remove(data);
185:                updateLastModified();
186:            }
187:
188:            /**
189:             * @return Returns the children.
190:             */
191:            Collection getChildren() {
192:                if (name == null) {
193:                    throw new IllegalStateException("Data is clear");
194:                }
195:                return children;
196:            }
197:
198:            /*
199:             * (non-Javadoc)
200:             * 
201:             * @see java.lang.Object#equals(java.lang.Object)
202:             */
203:            public boolean equals(Object o) {
204:                RamFileData data = (RamFileData) o;
205:                return this .getName().equals(data.getName());
206:            }
207:
208:            /*
209:             * (non-Javadoc)
210:             * 
211:             * @see java.lang.Object#hashCode()
212:             */
213:            public int hashCode() {
214:                return this .getName().hashCode();
215:            }
216:
217:            boolean hasChildren(RamFileData data) {
218:                return this .children.contains(data);
219:            }
220:
221:            /**
222:             * @return Returns the size of the buffer
223:             */
224:            int size() {
225:                return buffer.length;
226:            }
227:
228:            /**
229:             * Resize the buffer
230:             * 
231:             * @param newSize
232:             */
233:            void resize(int newSize) {
234:                int size = this .size();
235:                byte[] newBuf = new byte[newSize];
236:                System.arraycopy(this .buffer, 0, newBuf, 0, size);
237:                this.buffer = newBuf;
238:                updateLastModified();
239:            }
240:
241:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.