Source Code Cross Referenced for IoAdapter.java in  » Database-DBMS » db4o-6.4 » com » db4o » 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 » Database DBMS » db4o 6.4 » com.db4o.io 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* Copyright (C) 2004 - 2007  db4objects Inc.  http://www.db4o.com
002:
003:        This file is part of the db4o open source object database.
004:
005:        db4o is free software; you can redistribute it and/or modify it under
006:        the terms of version 2 of the GNU General Public License as published
007:        by the Free Software Foundation and as clarified by db4objects' GPL 
008:        interpretation policy, available at
009:        http://www.db4o.com/about/company/legalpolicies/gplinterpretation/
010:        Alternatively you can write to db4objects, Inc., 1900 S Norfolk Street,
011:        Suite 350, San Mateo, CA 94403, USA.
012:
013:        db4o is distributed in the hope that it will be useful, but WITHOUT ANY
014:        WARRANTY; without even the implied warranty of MERCHANTABILITY or
015:        FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
016:        for more details.
017:
018:        You should have received a copy of the GNU General Public License along
019:        with this program; if not, write to the Free Software Foundation, Inc.,
020:        59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. */
021:        package com.db4o.io;
022:
023:        import com.db4o.*;
024:
025:        /**
026:         * Base class for database file adapters, both for file and memory databases.
027:         */
028:        public abstract class IoAdapter {
029:
030:            private static final int COPY_SIZE = 4096;
031:
032:            private int _blockSize;
033:
034:            /**
035:             * converts address and address offset to an absolute address
036:             */
037:            protected final long regularAddress(int blockAddress,
038:                    int blockAddressOffset) {
039:                if (0 == _blockSize) {
040:                    throw new IllegalStateException();
041:                }
042:                return (long) blockAddress * _blockSize + blockAddressOffset;
043:            }
044:
045:            /**
046:             * copies a block within a file in block mode
047:             */
048:            public void blockCopy(int oldAddress, int oldAddressOffset,
049:                    int newAddress, int newAddressOffset, int length)
050:                    throws Db4oIOException {
051:                copy(regularAddress(oldAddress, oldAddressOffset),
052:                        regularAddress(newAddress, newAddressOffset), length);
053:            }
054:
055:            /**
056:             * sets the read/write pointer in the file using block mode
057:             */
058:            public void blockSeek(int address) throws Db4oIOException {
059:                blockSeek(address, 0);
060:            }
061:
062:            /**
063:             * sets the read/write pointer in the file using block mode
064:             */
065:            public void blockSeek(int address, int offset)
066:                    throws Db4oIOException {
067:                seek(regularAddress(address, offset));
068:            }
069:
070:            /**
071:             * outside call to set the block size of this adapter
072:             */
073:            public void blockSize(int blockSize) {
074:                if (blockSize < 1) {
075:                    throw new IllegalArgumentException();
076:                }
077:                _blockSize = blockSize;
078:            }
079:
080:            /**
081:             * implement to close the adapter
082:             */
083:            public abstract void close() throws Db4oIOException;
084:
085:            /**
086:             * copies a block within a file in absolute mode
087:             */
088:            public void copy(long oldAddress, long newAddress, int length)
089:                    throws Db4oIOException {
090:
091:                if (DTrace.enabled) {
092:                    DTrace.IO_COPY.logLength(newAddress, length);
093:                }
094:
095:                if (length > COPY_SIZE) {
096:                    byte[] buffer = new byte[COPY_SIZE];
097:                    int pos = 0;
098:                    while (pos + COPY_SIZE < length) {
099:                        copy(buffer, oldAddress + pos, newAddress + pos);
100:                        pos += COPY_SIZE;
101:                    }
102:                    oldAddress += pos;
103:                    newAddress += pos;
104:                    length -= pos;
105:                }
106:
107:                copy(new byte[length], oldAddress, newAddress);
108:            }
109:
110:            private void copy(byte[] buffer, long oldAddress, long newAddress)
111:                    throws Db4oIOException {
112:                seek(oldAddress);
113:                read(buffer);
114:                seek(newAddress);
115:                write(buffer);
116:            }
117:
118:            /**
119:             * deletes the given path from whatever 'file system' is addressed
120:             */
121:            public abstract void delete(String path);
122:
123:            /**
124:             * checks whether a file exists
125:             */
126:            public abstract boolean exists(String path);
127:
128:            /**
129:             * implement to return the absolute length of the file
130:             */
131:            public abstract long getLength() throws Db4oIOException;
132:
133:            /**
134:             * implement to open the file
135:             */
136:            public abstract IoAdapter open(String path, boolean lockFile,
137:                    long initialLength, boolean readOnly)
138:                    throws Db4oIOException;
139:
140:            /**
141:             * reads a buffer at the seeked address
142:             * 
143:             * @return the number of bytes read and returned
144:             */
145:            public int read(byte[] buffer) throws Db4oIOException {
146:                return read(buffer, buffer.length);
147:            }
148:
149:            /**
150:             * implement to read a buffer at the seeked address
151:             */
152:            public abstract int read(byte[] bytes, int length)
153:                    throws Db4oIOException;
154:
155:            /**
156:             * implement to set the read/write pointer in the file, absolute mode
157:             */
158:            public abstract void seek(long pos) throws Db4oIOException;
159:
160:            /**
161:             * implement to flush the file contents to storage
162:             */
163:            public abstract void sync() throws Db4oIOException;
164:
165:            /**
166:             * writes a buffer to the seeked address
167:             */
168:            public void write(byte[] bytes) throws Db4oIOException {
169:                write(bytes, bytes.length);
170:            }
171:
172:            /**
173:             * implement to write a buffer at the seeked address
174:             */
175:            public abstract void write(byte[] buffer, int length)
176:                    throws Db4oIOException;
177:
178:            /**
179:             * returns the block size currently used
180:             */
181:            public int blockSize() {
182:                return _blockSize;
183:            }
184:
185:            /**
186:             * Delegated IO Adapter
187:             * @return reference to itself
188:             */
189:            public IoAdapter delegatedIoAdapter() {
190:                return this;
191:            }
192:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.