Lines 25-30
Link Here
|
25 |
import java.util.Arrays; |
25 |
import java.util.Arrays; |
26 |
|
26 |
|
27 |
import org.apache.poi.poifs.common.POIFSConstants; |
27 |
import org.apache.poi.poifs.common.POIFSConstants; |
|
|
28 |
import org.apache.poi.poifs.filesystem.POIFSFileSystem; |
28 |
import org.apache.poi.util.IOUtils; |
29 |
import org.apache.poi.util.IOUtils; |
29 |
import org.apache.poi.util.IntegerField; |
30 |
import org.apache.poi.util.IntegerField; |
30 |
import org.apache.poi.util.LittleEndian; |
31 |
import org.apache.poi.util.LittleEndian; |
Lines 82-88
Link Here
|
82 |
|
83 |
|
83 |
private DocumentBlock() |
84 |
private DocumentBlock() |
84 |
{ |
85 |
{ |
85 |
_data = new byte[ POIFSConstants.BIG_BLOCK_SIZE ]; |
86 |
_data = new byte[ POIFSFileSystem.getBigBlockSize() ]; |
86 |
Arrays.fill(_data, _default_value); |
87 |
Arrays.fill(_data, _default_value); |
87 |
} |
88 |
} |
88 |
|
89 |
|
Lines 105-111
Link Here
|
105 |
|
106 |
|
106 |
public boolean partiallyRead() |
107 |
public boolean partiallyRead() |
107 |
{ |
108 |
{ |
108 |
return _bytes_read != POIFSConstants.BIG_BLOCK_SIZE; |
109 |
return _bytes_read != POIFSFileSystem.getBigBlockSize(); |
109 |
} |
110 |
} |
110 |
|
111 |
|
111 |
/** |
112 |
/** |
Lines 132-138
Link Here
|
132 |
final int size) |
133 |
final int size) |
133 |
{ |
134 |
{ |
134 |
DocumentBlock[] rval = |
135 |
DocumentBlock[] rval = |
135 |
new DocumentBlock[ (size + POIFSConstants.BIG_BLOCK_SIZE - 1) / POIFSConstants.BIG_BLOCK_SIZE ]; |
136 |
new DocumentBlock[ (size + POIFSFileSystem.getBigBlockSize() - 1) / |
|
|
137 |
POIFSFileSystem.getBigBlockSize() ]; |
136 |
int offset = 0; |
138 |
int offset = 0; |
137 |
|
139 |
|
138 |
for (int k = 0; k < rval.length; k++) |
140 |
for (int k = 0; k < rval.length; k++) |
Lines 140-153
Link Here
|
140 |
rval[ k ] = new DocumentBlock(); |
142 |
rval[ k ] = new DocumentBlock(); |
141 |
if (offset < array.length) |
143 |
if (offset < array.length) |
142 |
{ |
144 |
{ |
143 |
int length = Math.min(POIFSConstants.BIG_BLOCK_SIZE, |
145 |
int length = Math.min(POIFSFileSystem.getBigBlockSize(), |
144 |
array.length - offset); |
146 |
array.length - offset); |
145 |
|
147 |
|
146 |
System.arraycopy(array, offset, rval[ k ]._data, 0, length); |
148 |
System.arraycopy(array, offset, rval[ k ]._data, 0, length); |
147 |
if (length != POIFSConstants.BIG_BLOCK_SIZE) |
149 |
if (length != POIFSFileSystem.getBigBlockSize()) |
148 |
{ |
150 |
{ |
149 |
Arrays.fill(rval[ k ]._data, length, |
151 |
Arrays.fill(rval[ k ]._data, length, |
150 |
POIFSConstants.BIG_BLOCK_SIZE, |
152 |
POIFSFileSystem.getBigBlockSize(), |
151 |
_default_value); |
153 |
_default_value); |
152 |
} |
154 |
} |
153 |
} |
155 |
} |
Lines 155-161
Link Here
|
155 |
{ |
157 |
{ |
156 |
Arrays.fill(rval[ k ]._data, _default_value); |
158 |
Arrays.fill(rval[ k ]._data, _default_value); |
157 |
} |
159 |
} |
158 |
offset += POIFSConstants.BIG_BLOCK_SIZE; |
160 |
offset += POIFSFileSystem.getBigBlockSize(); |
159 |
} |
161 |
} |
160 |
return rval; |
162 |
return rval; |
161 |
} |
163 |
} |
Lines 171-180
Link Here
|
171 |
public static void read(final DocumentBlock [] blocks, |
173 |
public static void read(final DocumentBlock [] blocks, |
172 |
final byte [] buffer, final int offset) |
174 |
final byte [] buffer, final int offset) |
173 |
{ |
175 |
{ |
174 |
int firstBlockIndex = offset / POIFSConstants.BIG_BLOCK_SIZE; |
176 |
int firstBlockIndex = offset / POIFSFileSystem.getBigBlockSize(); |
175 |
int firstBlockOffset = offset % POIFSConstants.BIG_BLOCK_SIZE; |
177 |
int firstBlockOffset = offset % POIFSFileSystem.getBigBlockSize(); |
176 |
int lastBlockIndex = (offset + buffer.length - 1) |
178 |
int lastBlockIndex = (offset + buffer.length - 1) |
177 |
/ POIFSConstants.BIG_BLOCK_SIZE; |
179 |
/ POIFSFileSystem.getBigBlockSize(); |
178 |
|
180 |
|
179 |
if (firstBlockIndex == lastBlockIndex) |
181 |
if (firstBlockIndex == lastBlockIndex) |
180 |
{ |
182 |
{ |
Lines 187-200
Link Here
|
187 |
|
189 |
|
188 |
System.arraycopy(blocks[ firstBlockIndex ]._data, |
190 |
System.arraycopy(blocks[ firstBlockIndex ]._data, |
189 |
firstBlockOffset, buffer, buffer_offset, |
191 |
firstBlockOffset, buffer, buffer_offset, |
190 |
POIFSConstants.BIG_BLOCK_SIZE |
192 |
POIFSFileSystem.getBigBlockSize() |
191 |
- firstBlockOffset); |
193 |
- firstBlockOffset); |
192 |
buffer_offset += POIFSConstants.BIG_BLOCK_SIZE - firstBlockOffset; |
194 |
buffer_offset += POIFSFileSystem.getBigBlockSize() - |
|
|
195 |
firstBlockOffset; |
193 |
for (int j = firstBlockIndex + 1; j < lastBlockIndex; j++) |
196 |
for (int j = firstBlockIndex + 1; j < lastBlockIndex; j++) |
194 |
{ |
197 |
{ |
195 |
System.arraycopy(blocks[ j ]._data, 0, buffer, buffer_offset, |
198 |
System.arraycopy(blocks[ j ]._data, 0, buffer, buffer_offset, |
196 |
POIFSConstants.BIG_BLOCK_SIZE); |
199 |
POIFSFileSystem.getBigBlockSize()); |
197 |
buffer_offset += POIFSConstants.BIG_BLOCK_SIZE; |
200 |
buffer_offset += POIFSFileSystem.getBigBlockSize(); |
198 |
} |
201 |
} |
199 |
System.arraycopy(blocks[ lastBlockIndex ]._data, 0, buffer, |
202 |
System.arraycopy(blocks[ lastBlockIndex ]._data, 0, buffer, |
200 |
buffer_offset, buffer.length - buffer_offset); |
203 |
buffer_offset, buffer.length - buffer_offset); |