Source Code Cross Referenced for ByteField.java in  » Collaboration » poi-3.0.2-beta2 » org » apache » poi » util » 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 » Collaboration » poi 3.0.2 beta2 » org.apache.poi.util 
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 org.apache.poi.util;
019:
020:        import org.apache.poi.util.LittleEndian.BufferUnderrunException;
021:
022:        import java.io.*;
023:
024:        /**
025:         * representation of a byte (8-bit) field at a fixed location within a
026:         * byte array
027:         *
028:         * @author Marc Johnson (mjohnson at apache dot org
029:         */
030:
031:        public class ByteField implements  FixedField {
032:            private static final byte _default_value = 0;
033:            private byte _value;
034:            private final int _offset;
035:
036:            /**
037:             * construct the ByteField with its offset into its containing
038:             * byte array and a default value of 0
039:             *
040:             * @param offset of the field within its byte array
041:             *
042:             * @exception ArrayIndexOutOfBoundsException if offset is negative
043:             */
044:
045:            public ByteField(final int offset)
046:                    throws ArrayIndexOutOfBoundsException {
047:                this (offset, _default_value);
048:            }
049:
050:            /**
051:             * construct the ByteField with its offset into its containing
052:             * byte array and initialize its value
053:             *
054:             * @param offset of the field within its byte array
055:             * @param value the initial value
056:             *
057:             * @exception ArrayIndexOutOfBoundsException if offset is negative
058:             */
059:
060:            public ByteField(final int offset, final byte value)
061:                    throws ArrayIndexOutOfBoundsException {
062:                if (offset < 0) {
063:                    throw new ArrayIndexOutOfBoundsException(
064:                            "offset cannot be negative");
065:                }
066:                _offset = offset;
067:                set(value);
068:            }
069:
070:            /**
071:             * Construct the ByteField with its offset into its containing
072:             * byte array and initialize its value from its byte array
073:             *
074:             * @param offset of the field within its byte array
075:             * @param data the byte array to read the value from
076:             *
077:             * @exception ArrayIndexOutOfBoundsException if the offset is not
078:             *            within the range of 0..(data.length - 1)
079:             */
080:
081:            public ByteField(final int offset, final byte[] data)
082:                    throws ArrayIndexOutOfBoundsException {
083:                this (offset);
084:                readFromBytes(data);
085:            }
086:
087:            /**
088:             * construct the ByteField with its offset into its containing
089:             * byte array, initialize its value, and write its value to its
090:             * byte array
091:             *
092:             * @param offset of the field within its byte array
093:             * @param value the initial value
094:             * @param data the byte array to write the value to
095:             *
096:             * @exception ArrayIndexOutOfBoundsException if the offset is not
097:             *            within the range of 0..(data.length - 1)
098:             */
099:
100:            public ByteField(final int offset, final byte value,
101:                    final byte[] data) throws ArrayIndexOutOfBoundsException {
102:                this (offset, value);
103:                writeToBytes(data);
104:            }
105:
106:            /**
107:             * get the ByteField's current value
108:             *
109:             * @return current value
110:             */
111:
112:            public byte get() {
113:                return _value;
114:            }
115:
116:            /**
117:             * set the ByteField's current value
118:             *
119:             * @param value to be set
120:             */
121:
122:            public void set(final byte value) {
123:                _value = value;
124:            }
125:
126:            /**
127:             * set the ByteField's current value and write it to a byte array
128:             *
129:             * @param value to be set
130:             * @param data the byte array to write the value to
131:             *
132:             * @exception ArrayIndexOutOfBoundsException if the offset is out
133:             *            of the byte array's range
134:             */
135:
136:            public void set(final byte value, final byte[] data)
137:                    throws ArrayIndexOutOfBoundsException {
138:                set(value);
139:                writeToBytes(data);
140:            }
141:
142:            /* ********** START implementation of FixedField ********** */
143:
144:            /**
145:             * set the value from its offset into an array of bytes
146:             *
147:             * @param data the byte array from which the value is to be read
148:             *
149:             * @exception ArrayIndexOutOfBoundsException if the offset is out
150:             *            of range of the bte array
151:             */
152:
153:            public void readFromBytes(final byte[] data)
154:                    throws ArrayIndexOutOfBoundsException {
155:                _value = data[_offset];
156:            }
157:
158:            /**
159:             * set the value from an InputStream
160:             *
161:             * @param stream the InputStream from which the value is to be
162:             *               read
163:             *
164:             * @exception BufferUnderrunException if there is not enough data
165:             *            available from the InputStream
166:             * @exception IOException if an IOException is thrown from reading
167:             *            the InputStream
168:             */
169:
170:            public void readFromStream(final InputStream stream)
171:                    throws IOException, BufferUnderrunException {
172:                _value = (LittleEndian.readFromStream(stream,
173:                        LittleEndianConsts.BYTE_SIZE))[0];
174:            }
175:
176:            /**
177:             * write the value out to an array of bytes at the appropriate
178:             * offset
179:             *
180:             * @param data the array of bytes to which the value is to be
181:             *             written
182:             *
183:             * @exception ArrayIndexOutOfBoundsException if the offset is out
184:             *            of the byte array's range
185:             */
186:
187:            public void writeToBytes(final byte[] data)
188:                    throws ArrayIndexOutOfBoundsException {
189:                data[_offset] = _value;
190:            }
191:
192:            /**
193:             * return the value as a String
194:             *
195:             * @return the value as a String
196:             */
197:
198:            public String toString() {
199:                return String.valueOf(_value);
200:            }
201:
202:            /* **********  END  implementation of FixedField ********** */
203:        } // end public class ByteField
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.