Source Code Cross Referenced for LongToByteBufferAdapter.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:        /* Licensed to the Apache Software Foundation (ASF) under one or more
002:         * contributor license agreements.  See the NOTICE file distributed with
003:         * this work for additional information regarding copyright ownership.
004:         * The ASF licenses this file to You under the Apache License, Version 2.0
005:         * (the "License"); you may not use this file except in compliance with
006:         * the License.  You may obtain a copy of the License at
007:         * 
008:         *     http://www.apache.org/licenses/LICENSE-2.0
009:         * 
010:         * Unless required by applicable law or agreed to in writing, software
011:         * distributed under the License is distributed on an "AS IS" BASIS,
012:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013:         * See the License for the specific language governing permissions and
014:         * limitations under the License.
015:         */
016:
017:        package java.nio;
018:
019:        import org.apache.harmony.nio.internal.DirectBuffer;
020:        import org.apache.harmony.luni.platform.PlatformAddress;
021:
022:        /**
023:         * This class wraps a byte buffer to be a long buffer.
024:         * <p>
025:         * Implementation notice:
026:         * <ul>
027:         * <li>After a byte buffer instance is wrapped, it becomes privately owned by
028:         * the adapter. It must NOT be accessed outside the adapter any more.</li>
029:         * <li>The byte buffer's position and limit are NOT linked with the adapter.
030:         * The adapter extends Buffer, thus has its own position and limit.</li>
031:         * </ul>
032:         * </p>
033:         * 
034:         */
035:        final class LongToByteBufferAdapter extends LongBuffer implements 
036:                DirectBuffer {
037:
038:            static LongBuffer wrap(ByteBuffer byteBuffer) {
039:                return new LongToByteBufferAdapter(byteBuffer.slice());
040:            }
041:
042:            private final ByteBuffer byteBuffer;
043:
044:            LongToByteBufferAdapter(ByteBuffer byteBuffer) {
045:                super ((byteBuffer.capacity() >> 3));
046:                this .byteBuffer = byteBuffer;
047:                this .byteBuffer.clear();
048:            }
049:
050:            public int getByteCapacity() {
051:                if (byteBuffer instanceof  DirectBuffer) {
052:                    return ((DirectBuffer) byteBuffer).getByteCapacity();
053:                }
054:                assert false : byteBuffer;
055:                return -1;
056:            }
057:
058:            public PlatformAddress getEffectiveAddress() {
059:                if (byteBuffer instanceof  DirectBuffer) {
060:                    return ((DirectBuffer) byteBuffer).getEffectiveAddress();
061:                }
062:                assert false : byteBuffer;
063:                return null;
064:            }
065:
066:            public PlatformAddress getBaseAddress() {
067:                if (byteBuffer instanceof  DirectBuffer) {
068:                    return ((DirectBuffer) byteBuffer).getBaseAddress();
069:                }
070:                assert false : byteBuffer;
071:                return null;
072:            }
073:
074:            public boolean isAddressValid() {
075:                if (byteBuffer instanceof  DirectBuffer) {
076:                    return ((DirectBuffer) byteBuffer).isAddressValid();
077:                }
078:                assert false : byteBuffer;
079:                return false;
080:            }
081:
082:            public void addressValidityCheck() {
083:                if (byteBuffer instanceof  DirectBuffer) {
084:                    ((DirectBuffer) byteBuffer).addressValidityCheck();
085:                } else {
086:                    assert false : byteBuffer;
087:                }
088:            }
089:
090:            public void free() {
091:                if (byteBuffer instanceof  DirectBuffer) {
092:                    ((DirectBuffer) byteBuffer).free();
093:                } else {
094:                    assert false : byteBuffer;
095:                }
096:            }
097:
098:            @Override
099:            public LongBuffer asReadOnlyBuffer() {
100:                LongToByteBufferAdapter buf = new LongToByteBufferAdapter(
101:                        byteBuffer.asReadOnlyBuffer());
102:                buf.limit = limit;
103:                buf.position = position;
104:                buf.mark = mark;
105:                return buf;
106:            }
107:
108:            @Override
109:            public LongBuffer compact() {
110:                if (byteBuffer.isReadOnly()) {
111:                    throw new ReadOnlyBufferException();
112:                }
113:                byteBuffer.limit(limit << 3);
114:                byteBuffer.position(position << 3);
115:                byteBuffer.compact();
116:                byteBuffer.clear();
117:                position = limit - position;
118:                limit = capacity;
119:                mark = UNSET_MARK;
120:                return this ;
121:            }
122:
123:            @Override
124:            public LongBuffer duplicate() {
125:                LongToByteBufferAdapter buf = new LongToByteBufferAdapter(
126:                        byteBuffer.duplicate());
127:                buf.limit = limit;
128:                buf.position = position;
129:                buf.mark = mark;
130:                return buf;
131:            }
132:
133:            @Override
134:            public long get() {
135:                if (position == limit) {
136:                    throw new BufferUnderflowException();
137:                }
138:                return byteBuffer.getLong(position++ << 3);
139:            }
140:
141:            @Override
142:            public long get(int index) {
143:                if (index < 0 || index >= limit) {
144:                    throw new IndexOutOfBoundsException();
145:                }
146:                return byteBuffer.getLong(index << 3);
147:            }
148:
149:            @Override
150:            public boolean isDirect() {
151:                return byteBuffer.isDirect();
152:            }
153:
154:            @Override
155:            public boolean isReadOnly() {
156:                return byteBuffer.isReadOnly();
157:            }
158:
159:            @Override
160:            public ByteOrder order() {
161:                return byteBuffer.order();
162:            }
163:
164:            @Override
165:            protected long[] protectedArray() {
166:                throw new UnsupportedOperationException();
167:            }
168:
169:            @Override
170:            protected int protectedArrayOffset() {
171:                throw new UnsupportedOperationException();
172:            }
173:
174:            @Override
175:            protected boolean protectedHasArray() {
176:                return false;
177:            }
178:
179:            @Override
180:            public LongBuffer put(long c) {
181:                if (position == limit) {
182:                    throw new BufferOverflowException();
183:                }
184:                byteBuffer.putLong(position++ << 3, c);
185:                return this ;
186:            }
187:
188:            @Override
189:            public LongBuffer put(int index, long c) {
190:                if (index < 0 || index >= limit) {
191:                    throw new IndexOutOfBoundsException();
192:                }
193:                byteBuffer.putLong(index << 3, c);
194:                return this ;
195:            }
196:
197:            @Override
198:            public LongBuffer slice() {
199:                byteBuffer.limit(limit << 3);
200:                byteBuffer.position(position << 3);
201:                LongBuffer result = new LongToByteBufferAdapter(byteBuffer
202:                        .slice());
203:                byteBuffer.clear();
204:                return result;
205:            }
206:
207:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.