01: /* ====================================================================
02: Licensed to the Apache Software Foundation (ASF) under one or more
03: contributor license agreements. See the NOTICE file distributed with
04: this work for additional information regarding copyright ownership.
05: The ASF licenses this file to You under the Apache License, Version 2.0
06: (the "License"); you may not use this file except in compliance with
07: the License. You may obtain a copy of the License at
08:
09: http://www.apache.org/licenses/LICENSE-2.0
10:
11: Unless required by applicable law or agreed to in writing, software
12: distributed under the License is distributed on an "AS IS" BASIS,
13: WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: See the License for the specific language governing permissions and
15: limitations under the License.
16: ==================================================================== */
17: package org.apache.poi.hdgf.streams;
18:
19: import java.util.ArrayList;
20:
21: import org.apache.poi.hdgf.chunks.Chunk;
22: import org.apache.poi.hdgf.chunks.ChunkFactory;
23: import org.apache.poi.hdgf.pointers.Pointer;
24:
25: public class ChunkStream extends Stream {
26: private ChunkFactory chunkFactory;
27: /** All the Chunks we contain */
28: private Chunk[] chunks;
29:
30: protected ChunkStream(Pointer pointer, StreamStore store,
31: ChunkFactory chunkFactory) {
32: super (pointer, store);
33: this .chunkFactory = chunkFactory;
34:
35: // For compressed stores, we require all of the data
36: store.copyBlockHeaderToContents();
37: }
38:
39: public Chunk[] getChunks() {
40: return chunks;
41: }
42:
43: /**
44: * Process the contents of the stream out into chunks
45: */
46: public void findChunks() {
47: ArrayList chunksA = new ArrayList();
48:
49: if (getPointer().getOffset() == 0x64b3) {
50: int i = 0;
51: i++;
52: }
53:
54: int pos = 0;
55: byte[] contents = getStore().getContents();
56: while (pos < contents.length) {
57: Chunk chunk = chunkFactory.createChunk(contents, pos);
58: chunksA.add(chunk);
59:
60: pos += chunk.getOnDiskSize();
61: }
62:
63: chunks = (Chunk[]) chunksA.toArray(new Chunk[chunksA.size()]);
64: }
65: }
|