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:
18: package org.apache.poi.contrib.poibrowser;
19:
20: import java.io.*;
21: import org.apache.poi.poifs.filesystem.*;
22:
23: /**
24: * <p>Describes the most important (whatever that is) features of a
25: * {@link POIFSDocument}.</p>
26: *
27: * @author Rainer Klute (klute@rainer-klute.de)
28: * @version $Id: DocumentDescriptor.java 489730 2006-12-22 19:18:16Z bayard $
29: * @since 2002-02-05
30: * *
31: * @author Rainer Klute <a
32: * href="mailto:klute@rainer-klute.de"><klute@rainer-klute.de></a>
33: */
34: public class DocumentDescriptor {
35: String name;
36: POIFSDocumentPath path;
37: DocumentInputStream stream;
38:
39: int size;
40: byte[] bytes;
41:
42: /**
43: * <p>Creates a {@link DocumentDescriptor}.</p>
44: *
45: * @param name The stream's name.
46: *
47: * @param path The stream's path in the POI filesystem hierarchy.
48: *
49: * @param stream The stream.
50: *
51: * @param nrOfBytes The maximum number of bytes to display in a
52: * dump starting at the beginning of the stream.
53: */
54: public DocumentDescriptor(final String name,
55: final POIFSDocumentPath path,
56: final DocumentInputStream stream, final int nrOfBytes) {
57: this .name = name;
58: this .path = path;
59: this .stream = stream;
60: try {
61: size = stream.available();
62: if (stream.markSupported()) {
63: stream.mark(nrOfBytes);
64: final byte[] b = new byte[nrOfBytes];
65: final int read = stream.read(b, 0, Math.min(size,
66: b.length));
67: bytes = new byte[read];
68: System.arraycopy(b, 0, bytes, 0, read);
69: stream.reset();
70: }
71: } catch (IOException ex) {
72: System.out.println(ex);
73: }
74: }
75:
76: }
|