1 2 17 18 19 package org.apache.poi.poifs.storage; 20 21 import java.io.*; 22 23 import java.util.*; 24 25 import org.apache.poi.poifs.common.POIFSConstants; 26 import org.apache.poi.util.IOUtils; 27 import org.apache.poi.util.IntegerField; 28 import org.apache.poi.util.LittleEndian; 29 import org.apache.poi.util.LittleEndianConsts; 30 import org.apache.poi.util.LongField; 31 import org.apache.poi.util.ShortField; 32 33 38 39 public class HeaderBlockReader 40 implements HeaderBlockConstants 41 { 42 43 private IntegerField _bat_count; 45 46 private IntegerField _property_start; 49 50 private IntegerField _sbat_start; 53 54 private IntegerField _xbat_start; 56 private IntegerField _xbat_count; 57 private byte[] _data; 58 59 66 67 public HeaderBlockReader(final InputStream stream) 68 throws IOException 69 { 70 _data = new byte[ POIFSConstants.BIG_BLOCK_SIZE ]; 71 int byte_count = IOUtils.readFully(stream, _data); 72 73 if (byte_count != POIFSConstants.BIG_BLOCK_SIZE) 74 { 75 String type = " byte" + ((byte_count == 1) ? ("") 76 : ("s")); 77 78 throw new IOException("Unable to read entire header; " 79 + byte_count + type + " read; expected " 80 + POIFSConstants.BIG_BLOCK_SIZE + " bytes"); 81 } 82 83 LongField signature = new LongField(_signature_offset, _data); 85 86 if (signature.get() != _signature) 87 { 88 throw new IOException("Invalid header signature; read " 89 + signature.get() + ", expected " 90 + _signature); 91 } 92 _bat_count = new IntegerField(_bat_count_offset, _data); 93 _property_start = new IntegerField(_property_start_offset, _data); 94 _sbat_start = new IntegerField(_sbat_start_offset, _data); 95 _xbat_start = new IntegerField(_xbat_start_offset, _data); 96 _xbat_count = new IntegerField(_xbat_count_offset, _data); 97 } 98 99 104 105 public int getPropertyStart() 106 { 107 return _property_start.get(); 108 } 109 110 113 114 public int getSBATStart() 115 { 116 return _sbat_start.get(); 117 } 118 119 122 123 public int getBATCount() 124 { 125 return _bat_count.get(); 126 } 127 128 131 132 public int [] getBATArray() 133 { 134 int[] result = new int[ _max_bats_in_header ]; 135 int offset = _bat_array_offset; 136 137 for (int j = 0; j < _max_bats_in_header; j++) 138 { 139 result[ j ] = LittleEndian.getInt(_data, offset); 140 offset += LittleEndianConsts.INT_SIZE; 141 } 142 return result; 143 } 144 145 148 149 public int getXBATCount() 150 { 151 return _xbat_count.get(); 152 } 153 154 157 158 public int getXBATIndex() 159 { 160 return _xbat_start.get(); 161 } 162 } 164 | Popular Tags |