aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNick Burch <nick@apache.org>2014-04-24 17:32:47 +0000
committerNick Burch <nick@apache.org>2014-04-24 17:32:47 +0000
commitea3d7cd99b42a1442bee235edf4ee14aef1c6c27 (patch)
tree540fa22aada2939578b59207a03ab2e03c6db7ee
parentd99d2e559e2596ec1dcecbbf915870434d1f3a04 (diff)
downloadpoi-ea3d7cd99b42a1442bee235edf4ee14aef1c6c27.tar.gz
poi-ea3d7cd99b42a1442bee235edf4ee14aef1c6c27.zip
Update a test to use the existing EntryUtils to copy with, rather than duplciating the logic, and tweak naming/javadocs to clarify what the test does
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1589802 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--src/testcases/org/apache/poi/poifs/filesystem/TestNPOIFSFileSystem.java36
1 files changed, 6 insertions, 30 deletions
diff --git a/src/testcases/org/apache/poi/poifs/filesystem/TestNPOIFSFileSystem.java b/src/testcases/org/apache/poi/poifs/filesystem/TestNPOIFSFileSystem.java
index 75ef5f18fd..36ba94d88b 100644
--- a/src/testcases/org/apache/poi/poifs/filesystem/TestNPOIFSFileSystem.java
+++ b/src/testcases/org/apache/poi/poifs/filesystem/TestNPOIFSFileSystem.java
@@ -646,14 +646,18 @@ if(1==2) {
// TODO The rest of the test
}
+ /**
+ * Test that we can read a file with NPOIFS, create a new NPOIFS instance,
+ * write it out, read it with POIFS, and see the original data
+ */
@Test
- public void writPOIFSWriterListener() throws Exception {
+ public void NPOIFSReadCopyWritePOIFSRead() throws Exception {
File testFile = POIDataSamples.getSpreadSheetInstance().getFile("Simple.xls");
NPOIFSFileSystem src = new NPOIFSFileSystem(testFile);
byte wbDataExp[] = IOUtils.toByteArray(src.createDocumentInputStream("Workbook"));
NPOIFSFileSystem nfs = new NPOIFSFileSystem();
- copy(src.getRoot(), nfs.getRoot());
+ EntryUtils.copyNodes(src.getRoot(), nfs.getRoot());
src.close();
ByteArrayOutputStream bos = new ByteArrayOutputStream();
@@ -665,34 +669,6 @@ if(1==2) {
assertThat(wbDataExp, equalTo(wbDataAct));
}
-
- private static void copy(final DirectoryNode src, final DirectoryNode dest) throws IOException {
- Iterator<Entry> srcIter = src.getEntries();
- while(srcIter.hasNext()) {
- Entry entry = srcIter.next();
- if (entry.isDirectoryEntry()) {
- DirectoryNode srcDir = (DirectoryNode)entry;
- DirectoryNode destDir = (DirectoryNode)dest.createDirectory(srcDir.getName());
- destDir.setStorageClsid(src.getStorageClsid());
- copy(srcDir, destDir);
- } else {
- final DocumentNode srcDoc = (DocumentNode)entry;
- // dest.createDocument(srcDoc.getName(), src.createDocumentInputStream(srcDoc));
- dest.createDocument(srcDoc.getName(), srcDoc.getSize(), new POIFSWriterListener() {
- public void processPOIFSWriterEvent(POIFSWriterEvent event) {
- try {
- DocumentInputStream dis = src.createDocumentInputStream(srcDoc);
- IOUtils.copy(dis, event.getStream());
- } catch (IOException e) {
- throw new RuntimeException(e);
- }
- }
- });
- }
- }
-
- }
-
// TODO Directory/Document write tests
}