Skip to content

Commit

Permalink
#5: better error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Yanpas committed Mar 28, 2023
1 parent 70b4b26 commit 7c0bc6f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
6 changes: 3 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<project xmlns="http://maven.apache.org/POM/4.0.0"
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>yanpas</groupId>
<artifactId>pdfmerger</artifactId>
<version>1.2.2</version>
<version>1.2.3</version>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand All @@ -19,7 +19,7 @@
<dependency>
<groupId>org.apache.pdfbox</groupId>
<artifactId>pdfbox</artifactId>
<version>[2.0.15,)</version>
<version>2.0.17</version>
</dependency>
</dependencies>

Expand Down
13 changes: 7 additions & 6 deletions src/main/java/yanpas/pdfmerger/SwingMerge.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,14 @@
import javax.swing.*;

import java.io.File;
import java.io.FilenameFilter;
import java.io.IOException;
import java.util.List;
import java.awt.Dimension;
import java.awt.FileDialog;
import java.awt.Point;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;

@SuppressWarnings("serial")
class SwingMerge extends JFrame {
private class Worker extends SwingWorker<Void, String> {
public static final String MERGING = "Merging", SAVING = "Saving";
Expand All @@ -30,18 +26,23 @@ public Worker(File[] fileList, String outFile) {

@Override
public Void doInBackground() {
String documentProcessed = null;
try (Merger m = new Merger()) {
publish(MERGING);
double i = 0;
for (File fl : fileList) {
documentProcessed = fl.getName();
m.addDocument(fl);
i++;
setProgress((int) (100 * i / (double) fileList.length));
}
publish(SAVING);
documentProcessed = outFile;
m.save(outFile);
} catch (IOException e) {
result = e.getLocalizedMessage();
} catch (Exception e) {
System.err.printf("Merging failed on %s: %s\n", documentProcessed, e);
e.printStackTrace(System.err);
result = String.format("Error during processing of %s: %s", documentProcessed, e.getLocalizedMessage());
return null;
}
successful = true;
Expand Down
File renamed without changes.

0 comments on commit 7c0bc6f

Please sign in to comment.