Java Code Examples for org.apache.poi.poifs.common.POIFSConstants#PROPERTY_SIZE

The following examples show how to use org.apache.poi.poifs.common.POIFSConstants#PROPERTY_SIZE . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: NPropertyTable.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Return the number of BigBlock's this instance uses
 *
 * @return count of BigBlock instances
 */
public int countBlocks()
{
   long rawSize = _properties.size() * (long)POIFSConstants.PROPERTY_SIZE;
   int blkSize = _bigBigBlockSize.getBigBlockSize();
   int numBlocks = (int)(rawSize / blkSize);
   if ((rawSize % blkSize) != 0) {
       numBlocks++;
   }
   return numBlocks;
}
 
Example 2
Source File: Property.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
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);
}
 
Example 3
Source File: PropertyFactory.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
static void convertToProperties(byte[] data, List<Property> properties)
    throws IOException
{
   int property_count = data.length / POIFSConstants.PROPERTY_SIZE;
   int offset         = 0;

   for (int k = 0; k < property_count; k++) {
      switch (data[ offset + PropertyConstants.PROPERTY_TYPE_OFFSET ]) {
      case PropertyConstants.DIRECTORY_TYPE :
         properties.add(
               new DirectoryProperty(properties.size(), data, offset)
         );
         break;

      case PropertyConstants.DOCUMENT_TYPE :
         properties.add(
               new DocumentProperty(properties.size(), data, offset)
         );
         break;

      case PropertyConstants.ROOT_TYPE :
         properties.add(
               new RootProperty(properties.size(), data, offset)
         );
         break;

      default :
         properties.add(null);
         break;
      }
      
      offset += POIFSConstants.PROPERTY_SIZE;
   }
}
 
Example 4
Source File: PropertyTable.java    From dremio-oss with Apache License 2.0 5 votes vote down vote up
private void processSector(int sectorOffset) {
  final int property_count = sectorSize / POIFSConstants.PROPERTY_SIZE;

  byte[] bytes = new byte[POIFSConstants.PROPERTY_SIZE];

  int index = properties.size();
  is.seek(sectorOffset);
  for (int k = 0; k < property_count; k++, index++) {
    try {
      is.read(bytes, 0, bytes.length);
    } catch (IOException e) {
      // shouldn't be possible in a well formatted xls stream
      throw new IllegalStateException("Couldn't read from stream");
    }

    switch (bytes[PropertyConstants.PROPERTY_TYPE_OFFSET ]) {
      case PropertyConstants.DIRECTORY_TYPE :
      case PropertyConstants.ROOT_TYPE :
        properties.add(new DirectoryProperty(index, bytes));
        break;
      case PropertyConstants.DOCUMENT_TYPE :
        properties.add(new DocumentProperty(index, bytes));
        break;
      default :
        // add a null as we'll need to access properties by index later (or do we ?)
        properties.add(null);
        break;
    }
  }
}
 
Example 5
Source File: Property.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Constructor from byte data
 *
 * @param index index number
 * @param array byte data
 * @param offset offset into byte data
 */
protected Property(int index, byte [] array, 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;
}