1 2 17 18 19 package org.apache.poi.util; 20 21 import org.apache.poi.util.LittleEndian.BufferUnderrunException; 22 23 import java.io.*; 24 25 31 32 public class ShortField 33 implements FixedField 34 { 35 private short _value; 36 private final int _offset; 37 38 46 47 public ShortField(final int offset) 48 throws ArrayIndexOutOfBoundsException 49 { 50 if (offset < 0) 51 { 52 throw new ArrayIndexOutOfBoundsException ("Illegal offset: " 53 + offset); 54 } 55 _offset = offset; 56 } 57 58 67 68 public ShortField(final int offset, final short value) 69 throws ArrayIndexOutOfBoundsException 70 { 71 this(offset); 72 set(value); 73 } 74 75 85 86 public ShortField(final int offset, final byte [] data) 87 throws ArrayIndexOutOfBoundsException 88 { 89 this(offset); 90 readFromBytes(data); 91 } 92 93 104 105 public ShortField(final int offset, final short value, final byte [] data) 106 throws ArrayIndexOutOfBoundsException 107 { 108 this(offset); 109 set(value, data); 110 } 111 112 117 118 public short get() 119 { 120 return _value; 121 } 122 123 128 129 public void set(final short value) 130 { 131 _value = value; 132 } 133 134 143 144 public void set(final short value, final byte [] data) 145 throws ArrayIndexOutOfBoundsException 146 { 147 _value = value; 148 writeToBytes(data); 149 } 150 151 152 153 161 162 public void readFromBytes(final byte [] data) 163 throws ArrayIndexOutOfBoundsException 164 { 165 _value = LittleEndian.getShort(data, _offset); 166 } 167 168 179 180 public void readFromStream(final InputStream stream) 181 throws IOException, BufferUnderrunException 182 { 183 _value = LittleEndian.readShort(stream); 184 } 185 186 196 197 public void writeToBytes(final byte [] data) 198 throws ArrayIndexOutOfBoundsException 199 { 200 LittleEndian.putShort(data, _offset, _value); 201 } 202 203 208 209 public String toString() 210 { 211 return String.valueOf(_value); 212 } 213 214 215 } 217 | Popular Tags |