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.

HWPFDocFixture.java 2.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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.hwpf;
  16. import org.apache.poi.hwpf.model.FileInformationBlock;
  17. import org.apache.poi.poifs.filesystem.DocumentEntry;
  18. import org.apache.poi.poifs.filesystem.POIFSFileSystem;
  19. import org.apache.poi.POIDataSamples;
  20. import java.io.IOException;
  21. public final class HWPFDocFixture
  22. {
  23. public static final String DEFAULT_TEST_FILE = "test.doc";
  24. public byte[] _tableStream;
  25. public byte[] _mainStream;
  26. public FileInformationBlock _fib;
  27. private String _testFile;
  28. public HWPFDocFixture(Object obj, String testFile)
  29. {
  30. _testFile = testFile;
  31. }
  32. public void setUp() throws IOException {
  33. POIFSFileSystem filesystem = new POIFSFileSystem(
  34. POIDataSamples.getDocumentInstance().openResourceAsStream(_testFile));
  35. DocumentEntry documentProps =
  36. (DocumentEntry) filesystem.getRoot().getEntry("WordDocument");
  37. _mainStream = new byte[documentProps.getSize()];
  38. filesystem.createDocumentInputStream("WordDocument").read(_mainStream);
  39. // use the fib to determine the name of the table stream.
  40. _fib = new FileInformationBlock(_mainStream);
  41. String name = "0Table";
  42. if (_fib.getFibBase().isFWhichTblStm())
  43. {
  44. name = "1Table";
  45. }
  46. // read in the table stream.
  47. DocumentEntry tableProps =
  48. (DocumentEntry) filesystem.getRoot().getEntry(name);
  49. _tableStream = new byte[tableProps.getSize()];
  50. filesystem.createDocumentInputStream(name).read(_tableStream);
  51. _fib.fillVariableFields(_mainStream, _tableStream);
  52. }
  53. public void tearDown()
  54. {
  55. }
  56. }