use of org.apache.poi.hwpf.HWPFDocument in project poi by apache.
the class TestSprms method reload.
private static HWPFDocument reload(HWPFDocument hwpfDocument) throws IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
hwpfDocument.write(baos);
return new HWPFDocument(new ByteArrayInputStream(baos.toByteArray()));
}
use of org.apache.poi.hwpf.HWPFDocument in project poi by apache.
the class TestSprms method testSprmPJc.
/**
* Test correct processing of "sprmPJc" by uncompressor
*/
public void testSprmPJc() throws IOException {
InputStream resourceAsStream = POIDataSamples.getDocumentInstance().openResourceAsStream("Bug49820.doc");
HWPFDocument hwpfDocument = new HWPFDocument(resourceAsStream);
resourceAsStream.close();
assertEquals(1, hwpfDocument.getStyleSheet().getParagraphStyle(8).getJustification());
hwpfDocument = reload(hwpfDocument);
assertEquals(1, hwpfDocument.getStyleSheet().getParagraphStyle(8).getJustification());
}
use of org.apache.poi.hwpf.HWPFDocument in project poi by apache.
the class TestBug50075 method test.
public void test() {
HWPFDocument doc = HWPFTestDataSamples.openSampleFile("Bug50075.doc");
Range range = doc.getRange();
assertEquals(1, range.numParagraphs());
ListEntry entry = (ListEntry) range.getParagraph(0);
LFO override = doc.getListTables().getLfo(entry.getIlfo());
ListLevel level = doc.getListTables().getLevel(override.getLsid(), entry.getIlvl());
// the bug reproduces, if this call fails with NullPointerException
level.getNumberText();
}
use of org.apache.poi.hwpf.HWPFDocument in project poi by apache.
the class TestHWPFWrite method testInvalidInPlaceWriteInputStream.
@Test(expected = IllegalStateException.class)
public void testInvalidInPlaceWriteInputStream() throws IOException {
// Can't work for InputStream opened files
InputStream is = SAMPLES.openResourceAsStream("SampleDoc.doc");
HWPFDocument doc = new HWPFDocument(is);
is.close();
try {
doc.write();
} finally {
doc.close();
}
}
use of org.apache.poi.hwpf.HWPFDocument in project poi by apache.
the class TestHWPFWrite method testInPlaceWrite.
/**
* Writing to the file we opened from - note, uses a temp file to avoid
* changing our test files!
*/
@Test
public void testInPlaceWrite() throws Exception {
// Setup as a copy of a known-good file
final File file = TempFile.createTempFile("TestDocument", ".doc");
InputStream inputStream = SAMPLES.openResourceAsStream("SampleDoc.doc");
try {
FileOutputStream outputStream = new FileOutputStream(file);
try {
IOUtils.copy(inputStream, outputStream);
} finally {
outputStream.close();
}
} finally {
inputStream.close();
}
// Open from the temp file in read-write mode
NPOIFSFileSystem poifs = new NPOIFSFileSystem(file, false);
HWPFDocument doc = new HWPFDocument(poifs.getRoot());
Range r = doc.getRange();
assertEquals("I am a test document\r", r.getParagraph(0).text());
// Change
r.replaceText("X XX a test document\r", false);
// Save in-place, close, re-open and check
doc.write();
doc.close();
poifs.close();
poifs = new NPOIFSFileSystem(file);
doc = new HWPFDocument(poifs.getRoot());
r = doc.getRange();
assertEquals("X XX a test document\r", r.getParagraph(0).text());
doc.close();
poifs.close();
}
Aggregations