Skip to content

Commit

Permalink
Merge pull request #3 from mkarg/path
Browse files Browse the repository at this point in the history
Support for java.nio.file.Path
  • Loading branch information
jze authored Dec 1, 2024
2 parents 3a29bdd + 1f1f6fe commit cbf6e16
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/main/java/de/zedlitz/opendocument/Document.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Path;
import java.util.Optional;
import java.util.function.Consumer;
import java.util.zip.ZipEntry;
Expand Down Expand Up @@ -41,6 +42,10 @@ public Document(final File file) throws XMLStreamException, IOException {
this(new ZipFile(file));
}

public Document(final Path path) throws XMLStreamException, IOException {
this(new ZipFile(path.toFile()));
}

public Document(final ZipFile file) throws XMLStreamException, IOException {
final XMLInputFactory factory = XMLInputFactory.newInstance();
final ZipEntry content = file.getEntry("content.xml");
Expand Down
10 changes: 10 additions & 0 deletions src/test/java/de/zedlitz/opendocument/DocumentTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import java.io.File;
import java.io.IOException;
import java.io.PrintStream;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Objects;
import java.util.Optional;
import java.util.zip.ZipFile;
Expand Down Expand Up @@ -165,6 +167,14 @@ public void constructor_file() throws XMLStreamException, IOException {
assertNotNull(table1, "1st table exits");
}

@Test
public void constructor_path() throws XMLStreamException, IOException {
Path path = Paths.get(Objects.requireNonNull(getClass().getResource("/test01.ods")).getFile());
final Document doc = new Document(path);
final Table table1 = doc.nextTable();
assertNotNull(table1, "1st table exits");
}

@Test
public void brokenXmlContent() throws Exception {
PrintStream originalErr = System.err;
Expand Down

0 comments on commit cbf6e16

Please sign in to comment.