Source Code Cross Referenced for IntegerField.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 an integer (32-bit) field at a fixed location
026:         * within a byte array
027:         *
028:         * @author Marc Johnson (mjohnson at apache dot org
029:         */
030:
031:        public class IntegerField implements  FixedField {
032:            private int _value;
033:            private final int _offset;
034:
035:            /**
036:             * construct the IntegerField with its offset into its containing
037:             * byte array
038:             *
039:             * @param offset of the field within its byte array
040:             *
041:             * @exception ArrayIndexOutOfBoundsException if the offset is
042:             *            negative
043:             */
044:
045:            public IntegerField(final int offset)
046:                    throws ArrayIndexOutOfBoundsException {
047:                if (offset < 0) {
048:                    throw new ArrayIndexOutOfBoundsException("negative offset");
049:                }
050:                _offset = offset;
051:            }
052:
053:            /**
054:             * construct the IntegerField with its offset into its containing
055:             * byte array and initialize its value
056:             *
057:             * @param offset of the field within its byte array
058:             * @param value the initial value
059:             *
060:             * @exception ArrayIndexOutOfBoundsException if the offset is
061:             *            negative
062:             */
063:
064:            public IntegerField(final int offset, final int value)
065:                    throws ArrayIndexOutOfBoundsException {
066:                this (offset);
067:                set(value);
068:            }
069:
070:            /**
071:             * Construct the IntegerField 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 IntegerField(final int offset, final byte[] data)
082:                    throws ArrayIndexOutOfBoundsException {
083:                this (offset);
084:                readFromBytes(data);
085:            }
086:
087:            /**
088:             * construct the IntegerField with its offset into its containing
089:             * byte array, initialize its value, and write the value to a byte
090:             * 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
097:             *            negative or too large
098:             */
099:
100:            public IntegerField(final int offset, final int value,
101:                    final byte[] data) throws ArrayIndexOutOfBoundsException {
102:                this (offset);
103:                set(value, data);
104:            }
105:
106:            /**
107:             * get the IntegerField's current value
108:             *
109:             * @return current value
110:             */
111:
112:            public int get() {
113:                return _value;
114:            }
115:
116:            /**
117:             * set the IntegerField's current value
118:             *
119:             * @param value to be set
120:             */
121:
122:            public void set(final int value) {
123:                _value = value;
124:            }
125:
126:            /**
127:             * set the IntegerField's current value and write it to a byte
128:             * array
129:             *
130:             * @param value to be set
131:             * @param data the byte array to write the value to
132:             *
133:             * @exception ArrayIndexOutOfBoundsException if the offset is too
134:             *            large
135:             */
136:
137:            public void set(final int value, final byte[] data)
138:                    throws ArrayIndexOutOfBoundsException {
139:                _value = value;
140:                writeToBytes(data);
141:            }
142:
143:            /* ********** START implementation of FixedField ********** */
144:
145:            /**
146:             * set the value from its offset into an array of bytes
147:             *
148:             * @param data the byte array from which the value is to be read
149:             *
150:             * @exception ArrayIndexOutOfBoundsException if the offset is too
151:             *            large
152:             */
153:
154:            public void readFromBytes(final byte[] data)
155:                    throws ArrayIndexOutOfBoundsException {
156:                _value = LittleEndian.getInt(data, _offset);
157:            }
158:
159:            /**
160:             * set the value from an InputStream
161:             *
162:             * @param stream the InputStream from which the value is to be
163:             *               read
164:             *
165:             * @exception BufferUnderrunException if there is not enough data
166:             *            available from the InputStream
167:             * @exception IOException if an IOException is thrown from reading
168:             *            the InputStream
169:             */
170:
171:            public void readFromStream(final InputStream stream)
172:                    throws IOException, BufferUnderrunException {
173:                _value = LittleEndian.readInt(stream);
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 too
184:             *            large
185:             */
186:
187:            public void writeToBytes(final byte[] data)
188:                    throws ArrayIndexOutOfBoundsException {
189:                LittleEndian.putInt(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 IntegerField
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.