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.

RawDataBlockList.java 2.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. import java.io.*;
  17. import java.util.*;
  18. import org.apache.poi.poifs.common.POIFSBigBlockSize;
  19. /**
  20. * A list of RawDataBlocks instances, and methods to manage the list
  21. *
  22. * @author Marc Johnson (mjohnson at apache dot org
  23. */
  24. public class RawDataBlockList
  25. extends BlockListImpl
  26. {
  27. /**
  28. * Constructor RawDataBlockList
  29. *
  30. * @param stream the InputStream from which the data will be read
  31. * @param bigBlockSize The big block size, either 512 bytes or 4096 bytes
  32. *
  33. * @exception IOException on I/O errors, and if an incomplete
  34. * block is read
  35. */
  36. public RawDataBlockList(final InputStream stream, POIFSBigBlockSize bigBlockSize)
  37. throws IOException
  38. {
  39. List<RawDataBlock> blocks = new ArrayList<RawDataBlock>();
  40. while (true)
  41. {
  42. RawDataBlock block = new RawDataBlock(stream, bigBlockSize.getBigBlockSize());
  43. // If there was data, add the block to the list
  44. if(block.hasData()) {
  45. blocks.add(block);
  46. }
  47. // If the stream is now at the End Of File, we're done
  48. if (block.eof()) {
  49. break;
  50. }
  51. }
  52. setBlocks( blocks.toArray(new RawDataBlock[ blocks.size() ]) );
  53. }
  54. } // end public class RawDataBlockList