KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > poi > contrib > poibrowser > DocumentDescriptor


1
2 /* ====================================================================
3    Copyright 2002-2004 Apache Software Foundation
4
5    Licensed under the Apache License, Version 2.0 (the "License");
6    you may not use this file except in compliance with the License.
7    You may obtain a copy of the License at
8
9        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
19 package org.apache.poi.contrib.poibrowser;
20
21 import java.io.*;
22 import org.apache.poi.poifs.filesystem.*;
23
24 /**
25  * <p>Describes the most important (whatever that is) features of a
26  * {@link POIFSDocument}.</p>
27  *
28  * @author Rainer Klute (klute@rainer-klute.de)
29  * @version $Id: DocumentDescriptor.java,v 1.3 2004/04/09 13:05:08 glens Exp $
30  * @since 2002-02-05
31  * *
32  * @author Rainer Klute <a
33  * HREF="mailto:klute@rainer-klute.de">&lt;klute@rainer-klute.de&gt;</a>
34  */

35 public class DocumentDescriptor
36 {
37     String JavaDoc name;
38     POIFSDocumentPath path;
39     DocumentInputStream stream;
40
41     int size;
42     byte[] bytes;
43
44
45     /**
46      * <p>Creates a {@link DocumentDescriptor}.</p>
47      *
48      * @param name The stream's name.
49      *
50      * @param path The stream's path in the POI filesystem hierarchy.
51      *
52      * @param stream The stream.
53      *
54      * @param nrOfBytes The maximum number of bytes to display in a
55      * dump starting at the beginning of the stream.
56      */

57     public DocumentDescriptor(final String JavaDoc name,
58                               final POIFSDocumentPath path,
59                               final DocumentInputStream stream,
60                               final int nrOfBytes)
61     {
62         this.name = name;
63         this.path = path;
64         this.stream = stream;
65         try
66         {
67             size = stream.available();
68             if (stream.markSupported())
69             {
70                 stream.mark(nrOfBytes);
71                 final byte[] b = new byte[nrOfBytes];
72                 final int read = stream.read(b, 0, Math.min(size, b.length));
73                 bytes = new byte[read];
74                 System.arraycopy(b, 0, bytes, 0, read);
75                 stream.reset();
76             }
77         }
78         catch (IOException ex)
79         {
80             System.out.println(ex);
81         }
82     }
83
84 }
85
Popular Tags