use of org.apache.poi.poifs.filesystem.NPOIFSFileSystem in project poi by apache.
the class TestWriteWellKnown method write2ndFile.
/*
* Open <em>doc2</em> for reading and check summary information and
* document summary information. All properties written before must be
* found in the property streams of <em>doc2</em> and have the correct
* values.
*/
private static CustomProperties write2ndFile(File fileIn, File fileOut) throws Exception {
NPOIFSFileSystem poifs = new NPOIFSFileSystem(fileIn, false);
SummaryInformation si = getSummaryInformation(poifs);
DocumentSummaryInformation dsi = getDocumentSummaryInformation(poifs);
assertEquals(P_APPLICATION_NAME, si.getApplicationName());
assertEquals(P_AUTHOR, si.getAuthor());
assertEquals(P_CHAR_COUNT, si.getCharCount());
assertEquals(P_COMMENTS, si.getComments());
assertEquals(P_CREATE_DATE_TIME, si.getCreateDateTime());
assertEquals(P_EDIT_TIME, si.getEditTime());
assertEquals(P_KEYWORDS, si.getKeywords());
assertEquals(P_LAST_AUTHOR, si.getLastAuthor());
assertEquals(P_LAST_PRINTED, si.getLastPrinted());
assertEquals(P_LAST_SAVE_DATE_TIME, si.getLastSaveDateTime());
assertEquals(P_PAGE_COUNT, si.getPageCount());
assertEquals(P_REV_NUMBER, si.getRevNumber());
assertEquals(P_SECURITY, si.getSecurity());
assertEquals(P_SUBJECT, si.getSubject());
assertEquals(P_TEMPLATE, si.getTemplate());
// FIXME (byte array properties not yet implemented): assertEquals(P_THUMBNAIL, si.getThumbnail());
assertEquals(P_TITLE, si.getTitle());
assertEquals(P_WORD_COUNT, si.getWordCount());
assertEquals(P_BYTE_COUNT, dsi.getByteCount());
assertEquals(P_CATEGORY, dsi.getCategory());
assertEquals(P_COMPANY, dsi.getCompany());
// FIXME (byte array properties not yet implemented): assertEquals(P_, dsi.getDocparts());
// FIXME (byte array properties not yet implemented): assertEquals(P_, dsi.getHeadingPair());
assertEquals(P_HIDDEN_COUNT, dsi.getHiddenCount());
assertEquals(P_LINE_COUNT, dsi.getLineCount());
assertEquals(P_LINKS_DIRTY, dsi.getLinksDirty());
assertEquals(P_MANAGER, dsi.getManager());
assertEquals(P_MM_CLIP_COUNT, dsi.getMMClipCount());
assertEquals(P_NOTE_COUNT, dsi.getNoteCount());
assertEquals(P_PAR_COUNT, dsi.getParCount());
assertEquals(P_PRESENTATION_FORMAT, dsi.getPresentationFormat());
assertEquals(P_SCALE, dsi.getScale());
assertEquals(P_SLIDE_COUNT, dsi.getSlideCount());
final CustomProperties cps = dsi.getCustomProperties();
assertNotNull(cps);
assertNull(cps.get("No value available"));
assertEquals("Wert ä", cps.get("Schlüssel ä"));
assertEquals("Wert äö", cps.get("Schlüssel äö"));
assertEquals("Wert äöü", cps.get("Schlüssel äöü"));
assertEquals("Wert äöüÖ", cps.get("Schlüssel äöüÖ"));
assertEquals(POSITIVE_INTEGER, cps.get("positive_Integer"));
assertEquals(POSITIVE_LONG, cps.get("positive_Long"));
assertEquals(POSITIVE_DOUBLE, cps.get("positive_Double"));
assertEquals(NEGATIVE_INTEGER, cps.get("negative_Integer"));
assertEquals(NEGATIVE_LONG, cps.get("negative_Long"));
assertEquals(NEGATIVE_DOUBLE, cps.get("negative_Double"));
assertEquals(Boolean.TRUE, cps.get("Boolean"));
assertEquals(now, cps.get("Date"));
assertEquals(MAX_INTEGER, cps.get("max_Integer"));
assertEquals(MIN_INTEGER, cps.get("min_Integer"));
assertEquals(MAX_LONG, cps.get("max_Long"));
assertEquals(MIN_LONG, cps.get("min_Long"));
assertEquals(MAX_DOUBLE, cps.get("max_Double"));
assertEquals(MIN_DOUBLE, cps.get("min_Double"));
/* Remove all properties supported by HPSF from the summary
* information (e.g. author, edit date, application name) and from the
* document summary information (e.g. company, manager). */
si.removeApplicationName();
si.removeAuthor();
si.removeCharCount();
si.removeComments();
si.removeCreateDateTime();
si.removeEditTime();
si.removeKeywords();
si.removeLastAuthor();
si.removeLastPrinted();
si.removeLastSaveDateTime();
si.removePageCount();
si.removeRevNumber();
si.removeSecurity();
si.removeSubject();
si.removeTemplate();
si.removeThumbnail();
si.removeTitle();
si.removeWordCount();
dsi.removeByteCount();
dsi.removeCategory();
dsi.removeCompany();
dsi.removeCustomProperties();
dsi.removeDocparts();
dsi.removeHeadingPair();
dsi.removeHiddenCount();
dsi.removeLineCount();
dsi.removeLinksDirty();
dsi.removeManager();
dsi.removeMMClipCount();
dsi.removeNoteCount();
dsi.removeParCount();
dsi.removePresentationFormat();
dsi.removeScale();
dsi.removeSlideCount();
// Write the summary information stream and the document summary
// information stream to the POI filesystem.
si.write(poifs.getRoot(), SummaryInformation.DEFAULT_STREAM_NAME);
dsi.write(poifs.getRoot(), DocumentSummaryInformation.DEFAULT_STREAM_NAME);
// Write the POI filesystem to a (temporary) file doc3 and close the latter.
FileOutputStream out = new FileOutputStream(fileOut);
poifs.writeFilesystem(out);
out.close();
poifs.close();
return cps;
}
use of org.apache.poi.poifs.filesystem.NPOIFSFileSystem in project poi by apache.
the class TestBiffViewer method runOneFile.
@Override
void runOneFile(File fileIn) throws IOException {
NPOIFSFileSystem fs = new NPOIFSFileSystem(fileIn, true);
try {
InputStream is = BiffViewer.getPOIFSInputStream(fs);
try {
// use a NullOutputStream to not write the bytes anywhere for best runtime
PrintWriter dummy = new PrintWriter(new OutputStreamWriter(NULL_OUTPUT_STREAM, LocaleUtil.CHARSET_1252));
BiffViewer.runBiffViewer(dummy, is, true, true, true, false);
} finally {
is.close();
}
} finally {
fs.close();
}
}
use of org.apache.poi.poifs.filesystem.NPOIFSFileSystem in project poi by apache.
the class TestHSSFWorkbook method inPlaceWrite.
@Test
public void inPlaceWrite() throws Exception {
// Setup as a copy of a known-good file
final File file = TempFile.createTempFile("TestHSSFWorkbook", ".xls");
InputStream inputStream = POIDataSamples.getSpreadSheetInstance().openResourceAsStream("SampleSS.xls");
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
HSSFWorkbook wb = new HSSFWorkbook(new NPOIFSFileSystem(file, false));
assertEquals(3, wb.getNumberOfSheets());
// Change
wb.removeSheetAt(2);
wb.removeSheetAt(1);
wb.getSheetAt(0).getRow(0).getCell(0).setCellValue("Changed!");
// Save in-place, close, re-open and check
wb.write();
wb.close();
wb = new HSSFWorkbook(new NPOIFSFileSystem(file));
assertEquals(1, wb.getNumberOfSheets());
assertEquals("Changed!", wb.getSheetAt(0).getRow(0).getCell(0).toString());
wb.close();
}
use of org.apache.poi.poifs.filesystem.NPOIFSFileSystem in project poi by apache.
the class TestHSSFWorkbook method invalidInPlaceWrite.
@Test
public void invalidInPlaceWrite() throws Exception {
HSSFWorkbook wb;
// Can't work for new files
wb = new HSSFWorkbook();
try {
wb.write();
fail("Shouldn't work for new files");
} catch (IllegalStateException e) {
// expected here
}
wb.close();
// Can't work for InputStream opened files
wb = new HSSFWorkbook(POIDataSamples.getSpreadSheetInstance().openResourceAsStream("SampleSS.xls"));
try {
wb.write();
fail("Shouldn't work for InputStream");
} catch (IllegalStateException e) {
// expected here
}
wb.close();
// Can't work for OPOIFS
OPOIFSFileSystem ofs = new OPOIFSFileSystem(POIDataSamples.getSpreadSheetInstance().openResourceAsStream("SampleSS.xls"));
wb = new HSSFWorkbook(ofs.getRoot(), true);
try {
wb.write();
fail("Shouldn't work for OPOIFSFileSystem");
} catch (IllegalStateException e) {
// expected here
}
wb.close();
// Can't work for Read-Only files
NPOIFSFileSystem fs = new NPOIFSFileSystem(POIDataSamples.getSpreadSheetInstance().getFile("SampleSS.xls"), true);
wb = new HSSFWorkbook(fs);
try {
wb.write();
fail("Shouldn't work for Read Only");
} catch (IllegalStateException e) {
// expected here
}
wb.close();
}
use of org.apache.poi.poifs.filesystem.NPOIFSFileSystem in project poi by apache.
the class TestVBAMacroReader method fromNPOIFS.
protected void fromNPOIFS(POIDataSamples dataSamples, String filename) throws IOException {
File f = dataSamples.getFile(filename);
NPOIFSFileSystem fs = new NPOIFSFileSystem(f);
try {
VBAMacroReader r = new VBAMacroReader(fs);
try {
assertMacroContents(dataSamples, r);
} finally {
r.close();
}
} finally {
fs.close();
}
}
Aggregations