Source Code Cross Referenced for Buffer.java in  » Database-DBMS » db4o-6.4 » com » db4o » internal » 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.internal 
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.internal;
022:
023:        import com.db4o.*;
024:        import com.db4o.foundation.*;
025:        import com.db4o.internal.handlers.*;
026:        import com.db4o.internal.slots.*;
027:        import com.db4o.marshall.*;
028:
029:        /**
030:         * 
031:         * @exclude
032:         */
033:        public class Buffer implements  ReadBuffer, SlotBuffer, WriteBuffer {
034:
035:            // for coding convenience, we allow objects to grab into the buffer
036:            public byte[] _buffer;
037:            public int _offset;
038:
039:            Buffer() {
040:            }
041:
042:            public Buffer(int a_length) {
043:                _buffer = new byte[a_length];
044:            }
045:
046:            public void seek(int offset) {
047:                _offset = offset;
048:            }
049:
050:            public void writeBytes(byte[] bytes) {
051:                System.arraycopy(bytes, 0, _buffer, _offset, bytes.length);
052:                _offset += bytes.length;
053:            }
054:
055:            // TODO: Change all callers to call writeBytes directly.
056:            public void append(byte[] bytes) {
057:                writeBytes(bytes);
058:            }
059:
060:            public void append(Pointer4 pointer, final Buffer buffer) {
061:                writeInt(buffer.length());
062:                writeInt(pointer.id());
063:                writeInt(pointer.address());
064:                append(buffer._buffer);
065:            }
066:
067:            public final boolean containsTheSame(Buffer other) {
068:                if (other != null) {
069:                    return Arrays4.areEqual(_buffer, other._buffer);
070:                }
071:                return false;
072:            }
073:
074:            public void copyTo(Buffer to, int fromOffset, int toOffset,
075:                    int length) {
076:                System.arraycopy(_buffer, fromOffset, to._buffer, toOffset,
077:                        length);
078:            }
079:
080:            public int length() {
081:                return _buffer.length;
082:            }
083:
084:            public void incrementOffset(int a_by) {
085:                _offset += a_by;
086:            }
087:
088:            /**
089:             * non-encrypted read, used for indexes
090:             * @param a_stream
091:             * @param a_address
092:             */
093:            public void read(ObjectContainerBase stream, int address,
094:                    int addressOffset) {
095:                stream.readBytes(_buffer, address, addressOffset, length());
096:            }
097:
098:            public final void readBegin(byte identifier) {
099:                if (Deploy.debug) {
100:                    Debug.readBegin(this , identifier);
101:                }
102:            }
103:
104:            public BitMap4 readBitMap(int bitCount) {
105:                BitMap4 map = new BitMap4(_buffer, _offset, bitCount);
106:                _offset += map.marshalledLength();
107:                return map;
108:            }
109:
110:            public byte readByte() {
111:                return _buffer[_offset++];
112:            }
113:
114:            public byte[] readBytes(int a_length) {
115:                byte[] bytes = new byte[a_length];
116:                readBytes(bytes);
117:                return bytes;
118:            }
119:
120:            public void readBytes(byte[] bytes) {
121:                int length = bytes.length;
122:                System.arraycopy(_buffer, _offset, bytes, 0, length);
123:                _offset += length;
124:            }
125:
126:            public final Buffer readEmbeddedObject(Transaction trans)
127:                    throws Db4oIOException {
128:                int address = readInt();
129:                int length = readInt();
130:                if (address == 0) {
131:                    return null;
132:                }
133:                return trans.container().bufferByAddress(address, length);
134:            }
135:
136:            public void readEncrypt(ObjectContainerBase stream, int address)
137:                    throws Db4oIOException {
138:                stream.readBytes(_buffer, address, length());
139:                stream._handlers.decrypt(this );
140:            }
141:
142:            public void readEnd() {
143:                if (Deploy.debug) {
144:                    Debug.readEnd(this );
145:                }
146:            }
147:
148:            public final int readInt() {
149:                if (Deploy.debug) {
150:                    int ret = 0;
151:                    readBegin(Const4.YAPINTEGER);
152:                    if (Deploy.debugLong) {
153:                        ret = Integer.valueOf(
154:                                new LatinStringIO().read(this ,
155:                                        Const4.INTEGER_BYTES).trim())
156:                                .intValue();
157:                    } else {
158:                        for (int i = 0; i < Const4.INTEGER_BYTES; i++) {
159:                            ret = (ret << 8) + (_buffer[_offset++] & 0xff);
160:                        }
161:                    }
162:                    readEnd();
163:                    return ret;
164:                }
165:
166:                int o = (_offset += 4) - 1;
167:
168:                return (_buffer[o] & 255) | (_buffer[--o] & 255) << 8
169:                        | (_buffer[--o] & 255) << 16 | _buffer[--o] << 24;
170:
171:            }
172:
173:            public long readLong() {
174:                return LongHandler.readLong(this );
175:            }
176:
177:            public Buffer readPayloadReader(int offset, int length) {
178:                Buffer payLoad = new Buffer(length);
179:                System.arraycopy(_buffer, offset, payLoad._buffer, 0, length);
180:                return payLoad;
181:            }
182:
183:            public Slot readSlot() {
184:                return new Slot(readInt(), readInt());
185:            }
186:
187:            void replaceWith(byte[] a_bytes) {
188:                System.arraycopy(a_bytes, 0, _buffer, 0, length());
189:            }
190:
191:            public String toString() {
192:                String str = "";
193:                for (int i = 0; i < _buffer.length; i++) {
194:                    if (i > 0) {
195:                        str += " , ";
196:                    }
197:                    str += _buffer[i];
198:                }
199:                return str;
200:            }
201:
202:            public void writeBegin(byte a_identifier) {
203:                if (Deploy.debug) {
204:                    if (Deploy.brackets) {
205:                        writeByte(Const4.YAPBEGIN);
206:                    }
207:                    if (Deploy.identifiers) {
208:                        writeByte(a_identifier);
209:                    }
210:                }
211:            }
212:
213:            public final void writeBitMap(BitMap4 nullBitMap) {
214:                nullBitMap.writeTo(_buffer, _offset);
215:                _offset += nullBitMap.marshalledLength();
216:            }
217:
218:            public final void writeByte(byte a_byte) {
219:                _buffer[_offset++] = a_byte;
220:            }
221:
222:            public void writeEnd() {
223:                if (Deploy.debug && Deploy.brackets) {
224:                    writeByte(Const4.YAPEND);
225:                }
226:            }
227:
228:            public final void writeInt(int a_int) {
229:                if (Deploy.debug) {
230:                    IntHandler.writeInt(a_int, this );
231:                } else {
232:                    int o = _offset + 4;
233:                    _offset = o;
234:                    byte[] b = _buffer;
235:                    b[--o] = (byte) a_int;
236:                    b[--o] = (byte) (a_int >>= 8);
237:                    b[--o] = (byte) (a_int >>= 8);
238:                    b[--o] = (byte) (a_int >> 8);
239:                }
240:            }
241:
242:            public void writeIDOf(Transaction trans, Object obj) {
243:                if (obj == null) {
244:                    writeInt(0);
245:                    return;
246:                }
247:
248:                if (obj instanceof  PersistentBase) {
249:                    writeIDOf(trans, (PersistentBase) obj);
250:                    return;
251:                }
252:
253:                writeInt(((Integer) obj).intValue());
254:            }
255:
256:            public void writeIDOf(Transaction trans, PersistentBase persistent) {
257:                if (persistent == null) {
258:                    writeInt(0);
259:                    return;
260:                }
261:                if (canWritePersistentBase()) {
262:                    persistent.writeOwnID(trans, this );
263:                } else {
264:                    writeInt(persistent.getID());
265:                }
266:            }
267:
268:            public final void writeSlot(Slot slot) {
269:                writeInt(slot.address());
270:                writeInt(slot.length());
271:            }
272:
273:            protected boolean canWritePersistentBase() {
274:                return true;
275:            }
276:
277:            public void writeShortString(Transaction trans, String a_string) {
278:                trans.container()._handlers._stringHandler.writeShort(trans,
279:                        a_string, this );
280:            }
281:
282:            public void writeLong(long l) {
283:                LongHandler.writeLong(this , l);
284:            }
285:
286:            public void incrementIntSize() {
287:                incrementOffset(Const4.INT_LENGTH);
288:            }
289:
290:            public int offset() {
291:                return _offset;
292:            }
293:
294:            public void offset(int offset) {
295:                _offset = offset;
296:            }
297:
298:            public void copyBytes(byte[] target, int sourceOffset,
299:                    int targetOffset, int length) {
300:                System.arraycopy(_buffer, sourceOffset, target, targetOffset,
301:                        length);
302:            }
303:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.