Source Code Cross Referenced for ReadWriteDirectByteBuffer.java in  » Apache-Harmony-Java-SE » java-package » java » nio » 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 » Apache Harmony Java SE » java package » java.nio 
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:
018:        package java.nio;
019:
020:        import org.apache.harmony.luni.platform.PlatformAddress;
021:
022:        /**
023:         * DirectByteBuffer, ReadWriteDirectByteBuffer and ReadOnlyDirectByteBuffer
024:         * compose the implementation of platform memory based byte buffers.
025:         * <p>
026:         * ReadWriteDirectByteBuffer extends DirectByteBuffer with all the write
027:         * methods.
028:         * </p>
029:         * <p>
030:         * This class is marked final for runtime performance.
031:         * </p>
032:         * 
033:         */
034:        final class ReadWriteDirectByteBuffer extends DirectByteBuffer {
035:
036:            static ReadWriteDirectByteBuffer copy(DirectByteBuffer other,
037:                    int markOfOther) {
038:                ReadWriteDirectByteBuffer buf = new ReadWriteDirectByteBuffer(
039:                        other.safeAddress, other.capacity(), other.offset);
040:                buf.limit = other.limit();
041:                buf.position = other.position();
042:                buf.mark = markOfOther;
043:                buf.order(other.order());
044:                return buf;
045:            }
046:
047:            ReadWriteDirectByteBuffer(int capacity) {
048:                super (capacity);
049:            }
050:
051:            ReadWriteDirectByteBuffer(SafeAddress address, int capacity,
052:                    int offset) {
053:                super (address, capacity, offset);
054:            }
055:
056:            ReadWriteDirectByteBuffer(PlatformAddress address, int aCapacity,
057:                    int anOffset) {
058:                super (new SafeAddress(address), aCapacity, anOffset);
059:            }
060:
061:            @Override
062:            public ByteBuffer asReadOnlyBuffer() {
063:                return ReadOnlyDirectByteBuffer.copy(this , mark);
064:            }
065:
066:            @Override
067:            public ByteBuffer compact() {
068:                PlatformAddress effectiveAddress = getEffectiveAddress();
069:                effectiveAddress.offsetBytes(position).moveTo(effectiveAddress,
070:                        remaining());
071:                position = limit - position;
072:                limit = capacity;
073:                mark = UNSET_MARK;
074:                return this ;
075:            }
076:
077:            @Override
078:            public ByteBuffer duplicate() {
079:                return copy(this , mark);
080:            }
081:
082:            @Override
083:            public boolean isReadOnly() {
084:                return false;
085:            }
086:
087:            @Override
088:            public ByteBuffer put(byte value) {
089:                if (position == limit) {
090:                    throw new BufferOverflowException();
091:                }
092:                getBaseAddress().setByte(offset + position++, value);
093:                return this ;
094:            }
095:
096:            @Override
097:            public ByteBuffer put(int index, byte value) {
098:                if (index < 0 || index >= limit) {
099:                    throw new IndexOutOfBoundsException();
100:                }
101:                getBaseAddress().setByte(offset + index, value);
102:                return this ;
103:            }
104:
105:            /*
106:             * Override ByteBuffer.put(byte[], int, int) to improve performance.
107:             * 
108:             * (non-Javadoc)
109:             * 
110:             * @see java.nio.ByteBuffer#put(byte[], int, int)
111:             */
112:            @Override
113:            public ByteBuffer put(byte[] src, int off, int len) {
114:                int length = src.length;
115:                if (off < 0 || len < 0 || (long) off + (long) len > length) {
116:                    throw new IndexOutOfBoundsException();
117:                }
118:                if (len > remaining()) {
119:                    throw new BufferOverflowException();
120:                }
121:                if (isReadOnly()) {
122:                    throw new ReadOnlyBufferException();
123:                }
124:                getBaseAddress().setByteArray(offset + position, src, off, len);
125:                position += len;
126:                return this ;
127:            }
128:
129:            @Override
130:            public ByteBuffer putDouble(double value) {
131:                int newPosition = position + 8;
132:                if (newPosition > limit) {
133:                    throw new BufferOverflowException();
134:                }
135:                getBaseAddress().setDouble(offset + position, value, order);
136:                position = newPosition;
137:                return this ;
138:            }
139:
140:            @Override
141:            public ByteBuffer putDouble(int index, double value) {
142:                if (index < 0 || (long) index + 8 > limit) {
143:                    throw new IndexOutOfBoundsException();
144:                }
145:                getBaseAddress().setDouble(offset + index, value, order);
146:                return this ;
147:            }
148:
149:            @Override
150:            public ByteBuffer putFloat(float value) {
151:                int newPosition = position + 4;
152:                if (newPosition > limit) {
153:                    throw new BufferOverflowException();
154:                }
155:                getBaseAddress().setFloat(offset + position, value, order);
156:                position = newPosition;
157:                return this ;
158:            }
159:
160:            @Override
161:            public ByteBuffer putFloat(int index, float value) {
162:                if (index < 0 || (long) index + 4 > limit) {
163:                    throw new IndexOutOfBoundsException();
164:                }
165:                getBaseAddress().setFloat(offset + index, value, order);
166:                return this ;
167:            }
168:
169:            @Override
170:            public ByteBuffer putInt(int value) {
171:                int newPosition = position + 4;
172:                if (newPosition > limit) {
173:                    throw new BufferOverflowException();
174:                }
175:                getBaseAddress().setInt(offset + position, value, order);
176:                position = newPosition;
177:                return this ;
178:            }
179:
180:            @Override
181:            public ByteBuffer putInt(int index, int value) {
182:                if (index < 0 || (long) index + 4 > limit) {
183:                    throw new IndexOutOfBoundsException();
184:                }
185:                getBaseAddress().setInt(offset + index, value, order);
186:                return this ;
187:            }
188:
189:            @Override
190:            public ByteBuffer putLong(long value) {
191:                int newPosition = position + 8;
192:                if (newPosition > limit) {
193:                    throw new BufferOverflowException();
194:                }
195:                getBaseAddress().setLong(offset + position, value, order);
196:                position = newPosition;
197:                return this ;
198:            }
199:
200:            @Override
201:            public ByteBuffer putLong(int index, long value) {
202:                if (index < 0 || (long) index + 8 > limit) {
203:                    throw new IndexOutOfBoundsException();
204:                }
205:                getBaseAddress().setLong(offset + index, value, order);
206:                return this ;
207:            }
208:
209:            @Override
210:            public ByteBuffer putShort(short value) {
211:                int newPosition = position + 2;
212:                if (newPosition > limit) {
213:                    throw new BufferOverflowException();
214:                }
215:                getBaseAddress().setShort(offset + position, value, order);
216:                position = newPosition;
217:                return this ;
218:            }
219:
220:            @Override
221:            public ByteBuffer putShort(int index, short value) {
222:                if (index < 0 || (long) index + 2 > limit) {
223:                    throw new IndexOutOfBoundsException();
224:                }
225:                getBaseAddress().setShort(offset + index, value, order);
226:                return this ;
227:            }
228:
229:            @Override
230:            public ByteBuffer slice() {
231:                ReadWriteDirectByteBuffer buf = new ReadWriteDirectByteBuffer(
232:                        safeAddress, remaining(), offset + position);
233:                buf.order = order;
234:                return buf;
235:            }
236:
237:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.