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