📄 property.java
字号:
/* ==================================================================== * The Apache Software License, Version 1.1 * * Copyright (c) 2003 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" and * "Apache POI" 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", * "Apache POI", 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.poifs.property;import java.io.*;import java.util.*;import org.apache.poi.hpsf.ClassID;import org.apache.poi.poifs.common.POIFSConstants;import org.apache.poi.poifs.dev.POIFSViewable;import org.apache.poi.util.ByteField;import org.apache.poi.util.IntegerField;import org.apache.poi.util.LittleEndianConsts;import org.apache.poi.util.ShortField;/** * This abstract base class is the ancestor of all classes * implementing POIFS Property behavior. * * @author Marc Johnson (mjohnson at apache dot org) */public abstract class Property implements Child, POIFSViewable{ static final private byte _default_fill = ( byte ) 0x00; static final private int _name_size_offset = 0x40; static final private int _max_name_length = (_name_size_offset / LittleEndianConsts.SHORT_SIZE) - 1; static final protected int _NO_INDEX = -1; // useful offsets static final private int _node_color_offset = 0x43; static final private int _previous_property_offset = 0x44; static final private int _next_property_offset = 0x48; static final private int _child_property_offset = 0x4C; static final private int _storage_clsid_offset = 0x50; static final private int _user_flags_offset = 0x60; static final private int _seconds_1_offset = 0x64; static final private int _days_1_offset = 0x68; static final private int _seconds_2_offset = 0x6C; static final private int _days_2_offset = 0x70; static final private int _start_block_offset = 0x74; static final private int _size_offset = 0x78; // node colors static final protected byte _NODE_BLACK = 1; static final protected byte _NODE_RED = 0; // documents must be at least this size to be stored in big blocks static final private int _big_block_minimum_bytes = 4096; private String _name; private ShortField _name_size; private ByteField _property_type; private ByteField _node_color; private IntegerField _previous_property; private IntegerField _next_property; private IntegerField _child_property; private ClassID _storage_clsid; private IntegerField _user_flags; private IntegerField _seconds_1; private IntegerField _days_1; private IntegerField _seconds_2; private IntegerField _days_2; private IntegerField _start_block; private IntegerField _size; private byte[] _raw_data; private int _index; private Child _next_child; private Child _previous_child; /** * Default constructor */ protected Property() { _raw_data = new byte[ POIFSConstants.PROPERTY_SIZE ]; Arrays.fill(_raw_data, _default_fill); _name_size = new ShortField(_name_size_offset); _property_type = new ByteField(PropertyConstants.PROPERTY_TYPE_OFFSET); _node_color = new ByteField(_node_color_offset); _previous_property = new IntegerField(_previous_property_offset, _NO_INDEX, _raw_data); _next_property = new IntegerField(_next_property_offset, _NO_INDEX, _raw_data); _child_property = new IntegerField(_child_property_offset, _NO_INDEX, _raw_data); _storage_clsid = new ClassID(_raw_data,_storage_clsid_offset); _user_flags = new IntegerField(_user_flags_offset, 0, _raw_data); _seconds_1 = new IntegerField(_seconds_1_offset, 0, _raw_data); _days_1 = new IntegerField(_days_1_offset, 0, _raw_data); _seconds_2 = new IntegerField(_seconds_2_offset, 0, _raw_data); _days_2 = new IntegerField(_days_2_offset, 0, _raw_data); _start_block = new IntegerField(_start_block_offset); _size = new IntegerField(_size_offset, 0, _raw_data); _index = _NO_INDEX; setName(""); setNextChild(null); setPreviousChild(null); } /** * Constructor from byte data * * @param index index number * @param array byte data * @param offset offset into byte data */ protected Property(final int index, final byte [] array, final int offset) { _raw_data = new byte[ POIFSConstants.PROPERTY_SIZE ]; System.arraycopy(array, offset, _raw_data, 0, POIFSConstants.PROPERTY_SIZE); _name_size = new ShortField(_name_size_offset, _raw_data); _property_type = new ByteField(PropertyConstants.PROPERTY_TYPE_OFFSET, _raw_data); _node_color = new ByteField(_node_color_offset, _raw_data); _previous_property = new IntegerField(_previous_property_offset, _raw_data); _next_property = new IntegerField(_next_property_offset, _raw_data); _child_property = new IntegerField(_child_property_offset, _raw_data); _storage_clsid = new ClassID(_raw_data,_storage_clsid_offset); _user_flags = new IntegerField(_user_flags_offset, 0, _raw_data); _seconds_1 = new IntegerField(_seconds_1_offset, _raw_data); _days_1 = new IntegerField(_days_1_offset, _raw_data); _seconds_2 = new IntegerField(_seconds_2_offset, _raw_data); _days_2 = new IntegerField(_days_2_offset, _raw_data); _start_block = new IntegerField(_start_block_offset, _raw_data); _size = new IntegerField(_size_offset, _raw_data); _index = index; int name_length = (_name_size.get() / LittleEndianConsts.SHORT_SIZE) - 1; if (name_length < 1) { _name = ""; } else { char[] char_array = new char[ name_length ]; int name_offset = 0; for (int j = 0; j < name_length; j++) { char_array[ j ] = ( char ) new ShortField(name_offset, _raw_data).get(); name_offset += LittleEndianConsts.SHORT_SIZE; } _name = new String(char_array, 0, name_length); } _next_child = null; _previous_child = null; } /** * Write the raw data to an OutputStream. * * @param stream the OutputStream to which the data should be * written. * * @exception IOException on problems writing to the specified * stream. */ public void writeData(final OutputStream stream) throws IOException { stream.write(_raw_data); } /** * Set the start block for the document referred to by this * Property. * * @param startBlock the start block index */ public void setStartBlock(final int startBlock) { _start_block.set(startBlock, _raw_data); } /** * @return the start block */ public int getStartBlock() { return _start_block.get(); } /** * find out the document size * * @return size in bytes */ public int getSize() { return _size.get(); } /** * Based on the currently defined size, should this property use * small blocks? * * @return true if the size is less than _big_block_minimum_bytes */ public boolean shouldUseSmallBlocks() { return Property.isSmall(_size.get()); } /** * does the length indicate a small document? * * @param length length in bytes * * @return true if the length is less than * _big_block_minimum_bytes */ public static boolean isSmall(final int length) { return length < _big_block_minimum_bytes; } /** * Get the name of this property * * @return property name as String */ public String getName() { return _name; } /** * @return true if a directory type Property */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -