* Then, alter+add some streams, write and read
*/
@Test
public void readWriteRead() throws Exception {
SummaryInformation sinf = null;
DocumentSummaryInformation dinf = null;
DirectoryEntry root = null, testDir = null;
for(NPOIFSFileSystem fs : get512and4kFileAndInput()) {
// Check we can find the entries we expect
root = fs.getRoot();
assertEquals(5, root.getEntryCount());
assertThat(root.getEntryNames(), hasItem("Thumbnail"));
assertThat(root.getEntryNames(), hasItem("Image"));
assertThat(root.getEntryNames(), hasItem("Tags"));
assertThat(root.getEntryNames(), hasItem("\u0005DocumentSummaryInformation"));
assertThat(root.getEntryNames(), hasItem("\u0005SummaryInformation"));
// Write out, re-load
fs = writeOutAndReadBack(fs);
// Check they're still there
root = fs.getRoot();
assertEquals(5, root.getEntryCount());
assertThat(root.getEntryNames(), hasItem("Thumbnail"));
assertThat(root.getEntryNames(), hasItem("Image"));
assertThat(root.getEntryNames(), hasItem("Tags"));
assertThat(root.getEntryNames(), hasItem("\u0005DocumentSummaryInformation"));
assertThat(root.getEntryNames(), hasItem("\u0005SummaryInformation"));
// Check the contents of them - parse the summary block and check
sinf = (SummaryInformation)PropertySetFactory.create(new NDocumentInputStream(
(DocumentEntry)root.getEntry(SummaryInformation.DEFAULT_STREAM_NAME)));
assertEquals(131333, sinf.getOSVersion());
dinf = (DocumentSummaryInformation)PropertySetFactory.create(new NDocumentInputStream(
(DocumentEntry)root.getEntry(DocumentSummaryInformation.DEFAULT_STREAM_NAME)));
assertEquals(131333, dinf.getOSVersion());
// Add a test mini stream
testDir = root.createDirectory("Testing 123");
testDir.createDirectory("Testing 456");
testDir.createDirectory("Testing 789");
byte[] mini = new byte[] { 42, 0, 1, 2, 3, 4, 42 };
testDir.createDocument("Mini", new ByteArrayInputStream(mini));
// Write out, re-load
fs = writeOutAndReadBack(fs);
root = fs.getRoot();
testDir = (DirectoryEntry)root.getEntry("Testing 123");
assertEquals(6, root.getEntryCount());
assertThat(root.getEntryNames(), hasItem("Thumbnail"));
assertThat(root.getEntryNames(), hasItem("Image"));
assertThat(root.getEntryNames(), hasItem("Tags"));
assertThat(root.getEntryNames(), hasItem("Testing 123"));
assertThat(root.getEntryNames(), hasItem("\u0005DocumentSummaryInformation"));
assertThat(root.getEntryNames(), hasItem("\u0005SummaryInformation"));
// Check old and new are there
sinf = (SummaryInformation)PropertySetFactory.create(new NDocumentInputStream(
(DocumentEntry)root.getEntry(SummaryInformation.DEFAULT_STREAM_NAME)));
assertEquals(131333, sinf.getOSVersion());
dinf = (DocumentSummaryInformation)PropertySetFactory.create(new NDocumentInputStream(
(DocumentEntry)root.getEntry(DocumentSummaryInformation.DEFAULT_STREAM_NAME)));
assertEquals(131333, dinf.getOSVersion());
assertContentsMatches(mini, (DocumentEntry)testDir.getEntry("Mini"));
// Write out and read once more, just to be sure
fs = writeOutAndReadBack(fs);
root = fs.getRoot();
testDir = (DirectoryEntry)root.getEntry("Testing 123");
assertEquals(6, root.getEntryCount());
assertThat(root.getEntryNames(), hasItem("Thumbnail"));
assertThat(root.getEntryNames(), hasItem("Image"));
assertThat(root.getEntryNames(), hasItem("Tags"));
assertThat(root.getEntryNames(), hasItem("Testing 123"));
assertThat(root.getEntryNames(), hasItem("\u0005DocumentSummaryInformation"));
assertThat(root.getEntryNames(), hasItem("\u0005SummaryInformation"));
sinf = (SummaryInformation)PropertySetFactory.create(new NDocumentInputStream(
(DocumentEntry)root.getEntry(SummaryInformation.DEFAULT_STREAM_NAME)));
assertEquals(131333, sinf.getOSVersion());
dinf = (DocumentSummaryInformation)PropertySetFactory.create(new NDocumentInputStream(
(DocumentEntry)root.getEntry(DocumentSummaryInformation.DEFAULT_STREAM_NAME)));
assertEquals(131333, dinf.getOSVersion());
assertContentsMatches(mini, (DocumentEntry)testDir.getEntry("Mini"));
// Add a full stream, delete a full stream
byte[] main4096 = new byte[4096];
main4096[0] = -10;
main4096[4095] = -11;
testDir.createDocument("Normal4096", new ByteArrayInputStream(main4096));
root.getEntry("Tags").delete();
// Write out, re-load
fs = writeOutAndReadBack(fs);
// Check it's all there
root = fs.getRoot();
testDir = (DirectoryEntry)root.getEntry("Testing 123");
assertEquals(5, root.getEntryCount());
assertThat(root.getEntryNames(), hasItem("Thumbnail"));
assertThat(root.getEntryNames(), hasItem("Image"));
assertThat(root.getEntryNames(), hasItem("Testing 123"));
assertThat(root.getEntryNames(), hasItem("\u0005DocumentSummaryInformation"));
assertThat(root.getEntryNames(), hasItem("\u0005SummaryInformation"));
// Check old and new are there
sinf = (SummaryInformation)PropertySetFactory.create(new NDocumentInputStream(
(DocumentEntry)root.getEntry(SummaryInformation.DEFAULT_STREAM_NAME)));
assertEquals(131333, sinf.getOSVersion());
dinf = (DocumentSummaryInformation)PropertySetFactory.create(new NDocumentInputStream(
(DocumentEntry)root.getEntry(DocumentSummaryInformation.DEFAULT_STREAM_NAME)));
assertEquals(131333, dinf.getOSVersion());
assertContentsMatches(mini, (DocumentEntry)testDir.getEntry("Mini"));
assertContentsMatches(main4096, (DocumentEntry)testDir.getEntry("Normal4096"));