Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

PropertyTable.java 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /* ====================================================================
  2. Licensed to the Apache Software Foundation (ASF) under one or more
  3. contributor license agreements. See the NOTICE file distributed with
  4. this work for additional information regarding copyright ownership.
  5. The ASF licenses this file to You under the Apache License, Version 2.0
  6. (the "License"); you may not use this file except in compliance with
  7. the License. You may obtain a copy of the License at
  8. http://www.apache.org/licenses/LICENSE-2.0
  9. Unless required by applicable law or agreed to in writing, software
  10. distributed under the License is distributed on an "AS IS" BASIS,
  11. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. See the License for the specific language governing permissions and
  13. limitations under the License.
  14. ==================================================================== */
  15. package org.apache.poi.poifs.property;
  16. import java.io.IOException;
  17. import java.io.OutputStream;
  18. import org.apache.poi.poifs.common.POIFSBigBlockSize;
  19. import org.apache.poi.poifs.filesystem.POIFSFileSystem;
  20. import org.apache.poi.poifs.storage.BlockWritable;
  21. import org.apache.poi.poifs.storage.HeaderBlock;
  22. import org.apache.poi.poifs.storage.PropertyBlock;
  23. import org.apache.poi.poifs.storage.RawDataBlockList;
  24. /**
  25. * This class embodies the Property Table for the {@link POIFSFileSystem};
  26. * this is basically the directory for all of the documents in the
  27. * filesystem.
  28. *
  29. * @author Marc Johnson (mjohnson at apache dot org)
  30. */
  31. public final class PropertyTable extends PropertyTableBase implements BlockWritable {
  32. private POIFSBigBlockSize _bigBigBlockSize;
  33. private BlockWritable[] _blocks;
  34. public PropertyTable(HeaderBlock headerBlock)
  35. {
  36. super(headerBlock);
  37. _bigBigBlockSize = headerBlock.getBigBlockSize();
  38. _blocks = null;
  39. }
  40. /**
  41. * reading constructor (used when we've read in a file and we want
  42. * to extract the property table from it). Populates the
  43. * properties thoroughly
  44. *
  45. * @param headerBlock the header block of the file
  46. * @param blockList the list of blocks
  47. *
  48. * @exception IOException if anything goes wrong (which should be
  49. * a result of the input being NFG)
  50. */
  51. public PropertyTable(final HeaderBlock headerBlock,
  52. final RawDataBlockList blockList)
  53. throws IOException
  54. {
  55. super(
  56. headerBlock,
  57. PropertyFactory.convertToProperties(
  58. blockList.fetchBlocks(headerBlock.getPropertyStart(), -1)
  59. )
  60. );
  61. _bigBigBlockSize = headerBlock.getBigBlockSize();
  62. _blocks = null;
  63. }
  64. /**
  65. * Prepare to be written
  66. */
  67. public void preWrite()
  68. {
  69. Property[] properties = _properties.toArray(new Property[_properties.size()]);
  70. // give each property its index
  71. for (int k = 0; k < properties.length; k++)
  72. {
  73. properties[ k ].setIndex(k);
  74. }
  75. // allocate the blocks for the property table
  76. _blocks = PropertyBlock.createPropertyBlockArray(_bigBigBlockSize, _properties);
  77. // prepare each property for writing
  78. for (int k = 0; k < properties.length; k++)
  79. {
  80. properties[ k ].preWrite();
  81. }
  82. }
  83. /**
  84. * Return the number of BigBlock's this instance uses
  85. *
  86. * @return count of BigBlock instances
  87. */
  88. public int countBlocks()
  89. {
  90. return (_blocks == null) ? 0
  91. : _blocks.length;
  92. }
  93. /**
  94. * Write the storage to an OutputStream
  95. *
  96. * @param stream the OutputStream to which the stored data should
  97. * be written
  98. *
  99. * @exception IOException on problems writing to the specified
  100. * stream
  101. */
  102. public void writeBlocks(final OutputStream stream)
  103. throws IOException
  104. {
  105. if (_blocks != null)
  106. {
  107. for (int j = 0; j < _blocks.length; j++)
  108. {
  109. _blocks[ j ].writeBlocks(stream);
  110. }
  111. }
  112. }
  113. }