Skip to content

Commit

Permalink
Merge pull request #165 from wiktor-k/add-closeable
Browse files Browse the repository at this point in the history
Make Document and PdfWriter compatible with try-with-resources
  • Loading branch information
andreasrosdal authored Mar 26, 2019
2 parents b969bd8 + 6772897 commit a6a0caa
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 1 deletion.
3 changes: 2 additions & 1 deletion openpdf/src/main/java/com/lowagie/text/Document.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
* </BLOCKQUOTE>
*/

public class Document implements DocListener {
public class Document implements AutoCloseable, DocListener {

// membervariables
/**
Expand Down Expand Up @@ -442,6 +442,7 @@ public int getPageNumber() {
* Once all the content has been written in the body, you have to close the
* body. After that nothing can be written to the body anymore.
*/
@Override
public void close() {
if (!close) {
open = false;
Expand Down
1 change: 1 addition & 0 deletions openpdf/src/main/java/com/lowagie/text/pdf/PdfReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -3123,6 +3123,7 @@ protected static PdfObject duplicatePdfObject(PdfObject original,
/**
* Closes the reader
*/
@Override
public void close() {
if (!partial)
return;
Expand Down
3 changes: 3 additions & 0 deletions openpdf/src/main/java/com/lowagie/text/pdf/PdfWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
import java.awt.*;
import java.awt.color.ICC_Profile;
import java.io.ByteArrayOutputStream;
import java.io.Closeable;
import java.io.IOException;
import java.io.OutputStream;
import java.security.cert.Certificate;
Expand All @@ -78,6 +79,7 @@
*/

public class PdfWriter extends DocWriter implements
Closeable,
PdfViewerPreferences,
PdfEncryptionSettings,
PdfVersion,
Expand Down Expand Up @@ -1146,6 +1148,7 @@ public void open() {
* to the outputstream embedded in a Trailer.
* @see com.lowagie.text.DocWriter#close()
*/
@Override
public void close() {
if (open) {
if ((currentPageNumber - 1) != pageReferences.size())
Expand Down

0 comments on commit a6a0caa

Please sign in to comment.