You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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.storage;
  16. /**
  17. * Abstract base class of all POIFS block storage classes. All
  18. * extensions of BigBlock should write 512 or 4096 bytes of data when
  19. * requested to write their data (as per their BigBlockSize).
  20. *
  21. * This class has package scope, as there is no reason at this time to
  22. * make the class public.
  23. *
  24. * @author Marc Johnson (mjohnson at apache dot org)
  25. */
  26. import java.io.IOException;
  27. import java.io.OutputStream;
  28. import org.apache.poi.poifs.common.POIFSBigBlockSize;
  29. import org.apache.poi.poifs.common.POIFSConstants;
  30. abstract class BigBlock
  31. implements BlockWritable
  32. {
  33. /**
  34. * Either 512 bytes ({@link POIFSConstants#SMALLER_BIG_BLOCK_SIZE})
  35. * or 4096 bytes ({@link POIFSConstants#LARGER_BIG_BLOCK_SIZE})
  36. */
  37. protected POIFSBigBlockSize bigBlockSize;
  38. protected BigBlock(POIFSBigBlockSize bigBlockSize) {
  39. this.bigBlockSize = bigBlockSize;
  40. }
  41. /**
  42. * Default implementation of write for extending classes that
  43. * contain their data in a simple array of bytes.
  44. *
  45. * @param stream the OutputStream to which the data should be
  46. * written.
  47. * @param data the byte array of to be written.
  48. *
  49. * @exception IOException on problems writing to the specified
  50. * stream.
  51. */
  52. protected void doWriteData(final OutputStream stream, final byte [] data)
  53. throws IOException
  54. {
  55. stream.write(data);
  56. }
  57. /**
  58. * Write the block's data to an OutputStream
  59. *
  60. * @param stream the OutputStream to which the stored data should
  61. * be written
  62. *
  63. * @exception IOException on problems writing to the specified
  64. * stream
  65. */
  66. abstract void writeData(final OutputStream stream)
  67. throws IOException;
  68. /* ********** START implementation of BlockWritable ********** */
  69. /**
  70. * Write the storage to an OutputStream
  71. *
  72. * @param stream the OutputStream to which the stored data should
  73. * be written
  74. *
  75. * @exception IOException on problems writing to the specified
  76. * stream
  77. */
  78. public void writeBlocks(final OutputStream stream)
  79. throws IOException
  80. {
  81. writeData(stream);
  82. }
  83. /* ********** END implementation of BlockWritable ********** */
  84. } // end abstract class BigBlock