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 IntegerField 33 implements FixedField 34 { 35 private int _value; 36 private final int _offset; 37 38 47 48 public IntegerField(final int offset) 49 throws ArrayIndexOutOfBoundsException 50 { 51 if (offset < 0) 52 { 53 throw new ArrayIndexOutOfBoundsException ("negative offset"); 54 } 55 _offset = offset; 56 } 57 58 68 69 public IntegerField(final int offset, final int value) 70 throws ArrayIndexOutOfBoundsException 71 { 72 this(offset); 73 set(value); 74 } 75 76 86 87 public IntegerField(final int offset, final byte [] data) 88 throws ArrayIndexOutOfBoundsException 89 { 90 this(offset); 91 readFromBytes(data); 92 } 93 94 106 107 public IntegerField(final int offset, final int value, final byte [] data) 108 throws ArrayIndexOutOfBoundsException 109 { 110 this(offset); 111 set(value, data); 112 } 113 114 119 120 public int get() 121 { 122 return _value; 123 } 124 125 130 131 public void set(final int value) 132 { 133 _value = value; 134 } 135 136 146 147 public void set(final int value, final byte [] data) 148 throws ArrayIndexOutOfBoundsException 149 { 150 _value = value; 151 writeToBytes(data); 152 } 153 154 155 156 164 165 public void readFromBytes(final byte [] data) 166 throws ArrayIndexOutOfBoundsException 167 { 168 _value = LittleEndian.getInt(data, _offset); 169 } 170 171 182 183 public void readFromStream(final InputStream stream) 184 throws IOException, BufferUnderrunException 185 { 186 _value = LittleEndian.readInt(stream); 187 } 188 189 199 200 public void writeToBytes(final byte [] data) 201 throws ArrayIndexOutOfBoundsException 202 { 203 LittleEndian.putInt(data, _offset, _value); 204 } 205 206 211 212 public String toString() 213 { 214 return String.valueOf(_value); 215 } 216 217 218 } 220 | Popular Tags |