📄 propertyset.java
字号:
/* * ==================================================================== * The Apache Software License, Version 1.1 * * Copyright (c) 2000 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, * if any, must include the following acknowledgment: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowledgment may appear in the software itself, * if and wherever such third-party acknowledgments normally appear. * * 4. The names "Apache" and "Apache Software Foundation" must * not be used to endorse or promote products derived from this * software without prior written permission. For written * permission, please contact apache@apache.org. * * 5. Products derived from this software may not be called "Apache", * nor may "Apache" appear in their name, without prior written * permission of the Apache Software Foundation. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * <http://www.apache.org/>. */package org.apache.poi.hpsf;import java.io.*;import java.util.*;import org.apache.poi.hpsf.wellknown.*;import org.apache.poi.poifs.filesystem.*;import org.apache.poi.util.LittleEndian;/** * <p>Represents a property set in the Horrible Property Set Format * (HPSF). These are usually metadata of a Microsoft Office * document.</p> * * <p>An application that wants to access these metadata should create * an instance of this class or one of its subclasses by calling the * factory method {@link PropertySetFactory#create} and then retrieve * the information its needs by calling appropriate methods.</p> * * <p>{@link PropertySetFactory#create} does its work by calling one * of the constructors {@link PropertySet#PropertySet(InputStream)} or * {@link PropertySet#PropertySet(byte[])}. If the constructor's * argument is not in the Horrible Property Set Format, i.e. not a * property set stream, or if any other error occurs, an appropriate * exception is thrown.</p> * * <p>A {@link PropertySet} has a list of {@link Section}s, and each * {@link Section} has a {@link Property} array. Use {@link * #getSections} to retrieve the {@link Section}s, then call {@link * Section#getProperties} for each {@link Section} to get hold of the * {@link Property} arrays.</p> Since the vast majority of {@link * PropertySet}s contains only a single {@link Section}, the * convenience method {@link #getProperties} returns the properties of * a {@link PropertySet}'s {@link Section} (throwing a {@link * NoSingleSectionException} if the {@link PropertySet} contains more * (or less) than exactly one {@link Section}).</p> * * @author Rainer Klute (klute@rainer-klute.de) * @author Drew Varner (Drew.Varner hanginIn sc.edu) * @version $Id: PropertySet.java,v 1.9 2003/02/22 14:27:16 klute Exp $ * @since 2002-02-09 */public class PropertySet{ /** * <p>The "byteOrder" field must equal this value.</p> */ final static byte[] BYTE_ORDER_ASSERTION = new byte[]{(byte) 0xFE, (byte) 0xFF}; /** * <p>Specifies this {@link PropertySet}'s byte order. See the * HPFS documentation for details!</p> */ protected int byteOrder; /** * <p>Returns the property set stream's low-level "byte order" * field. It is always <tt>0xFFFE</tt> .</p> * * @return The property set stream's low-level "byte order" field. */ public int getByteOrder() { return byteOrder; } /** * <p>The "format" field must equal this value.</p> */ final static byte[] FORMAT_ASSERTION = new byte[]{(byte) 0x00, (byte) 0x00}; /** * <p>Specifies this {@link PropertySet}'s format. See the HPFS * documentation for details!</p> */ protected int format; /** * <p>Returns the property set stream's low-level "format" * field. It is always <tt>0x0000</tt> .</p> * * @return The property set stream's low-level "format" field. */ public int getFormat() { return format; } /** * <p>Specifies the version of the operating system that created * this {@link PropertySet}. See the HPFS documentation for * details!</p> */ protected int osVersion; public final static int OS_WIN16 = 0x0000; public final static int OS_MACINTOSH = 0x0001; public final static int OS_WIN32 = 0x0002; /** * <p>Returns the property set stream's low-level "OS version" * field.</p> * * <p><strong>FIXME:</strong> Return an <code>int</code> instead * of a <code>long</code> in the next major version, i.e. when * incompatible changes are allowed.</p> * * @return The property set stream's low-level "OS version" field. */ public long getOSVersion() { return osVersion; } /** * <p>Specifies this {@link PropertySet}'s "classID" field. See * the HPFS documentation for details!</p> */ protected ClassID classID; /** * <p>Returns the property set stream's low-level "class ID" * field.</p> * * @return The property set stream's low-level "class ID" field. */ public ClassID getClassID() { return classID; } /** * <p>The number of sections in this {@link PropertySet}.</p> */ protected int sectionCount; /** * <p>Returns the number of {@link Section}s in the property * set.</p> * * <p><strong>FIXME:</strong> Return an <code>int</code> instead * of a <code>long</code> in the next major version, i.e. when * incompatible changes are allowed.</p> * * @return The number of {@link Section}s in the property set. */ public long getSectionCount() { return sectionCount; } /** * <p>The sections in this {@link PropertySet}.</p> */ protected List sections; /** * <p>Returns the {@link Section}s in the property set.</p> * * @return The {@link Section}s in the property set. */ public List getSections() { return sections; } /** * <p>Creates an empty (uninitialized) {@link PropertySet}.</p> * * <p><strong>Please note:</strong> For the time being this * constructor is protected since it is used for internal purposes * only, but expect it to become public once the property set's * writing functionality is implemented.</p> */ protected PropertySet() {} /** * <p>Creates a {@link PropertySet} instance from an {@link * InputStream} in the Horrible Property Set Format.</p> * * <p>The constructor reads the first few bytes from the stream * and determines whether it is really a property set stream. If * it is, it parses the rest of the stream. If it is not, it * resets the stream to its beginning in order to let other * components mess around with the data and throws an * exception.</p> * * @param stream Holds the data making out the property set * stream. * @throws MarkUnsupportedException if the stream does not support * the {@link InputStream#markSupported} method. * @throws IOException if the {@link InputStream} cannot not be * accessed as needed. */ public PropertySet(final InputStream stream) throws NoPropertySetStreamException, MarkUnsupportedException, IOException { if (isPropertySetStream(stream)) { final int avail = stream.available(); final byte[] buffer = new byte[avail]; stream.read(buffer, 0, buffer.length); init(buffer, 0, buffer.length); } else throw new NoPropertySetStreamException(); } /** * <p>Creates a {@link PropertySet} instance from a byte array * that represents a stream in the Horrible Property Set * Format.</p> * * @param stream The byte array holding the stream data. * @param offset The offset in <var>stream</var> where the stream * data begin. If the stream data begin with the first byte in the * array, the <var>offset</var> is 0. * @param length The length of the stream data. * @throws NoPropertySetStreamException if the byte array is not a * property set stream. */ public PropertySet(final byte[] stream, final int offset, final int length) throws NoPropertySetStreamException { if (isPropertySetStream(stream, offset, length)) init(stream, offset, length); else throw new NoPropertySetStreamException(); } /** * <p>Creates a {@link PropertySet} instance from a byte array * that represents a stream in the Horrible Property Set * Format.</p>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -