You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pdfbox.apache.org by ti...@apache.org on 2015/05/31 13:10:10 UTC
svn commit: r1682717 - in
/pdfbox/trunk/tools/src/main/java/org/apache/pdfbox/tools:
pdfdebugger/ui/Tree.java util/FileOpenSaveDialog.java
Author: tilman
Date: Sun May 31 11:10:10 2015
New Revision: 1682717
URL: http://svn.apache.org/r1682717
Log:
PDFBOX-2530, PDFBOX-2576: avoid throwing RuntimeException; use List instead of ArrayList when possible; make field private that isn't used outside; close OutputStream on checked exception
Modified:
pdfbox/trunk/tools/src/main/java/org/apache/pdfbox/tools/pdfdebugger/ui/Tree.java
pdfbox/trunk/tools/src/main/java/org/apache/pdfbox/tools/util/FileOpenSaveDialog.java
Modified: pdfbox/trunk/tools/src/main/java/org/apache/pdfbox/tools/pdfdebugger/ui/Tree.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/tools/src/main/java/org/apache/pdfbox/tools/pdfdebugger/ui/Tree.java?rev=1682717&r1=1682716&r2=1682717&view=diff
==============================================================================
--- pdfbox/trunk/tools/src/main/java/org/apache/pdfbox/tools/pdfdebugger/ui/Tree.java (original)
+++ pdfbox/trunk/tools/src/main/java/org/apache/pdfbox/tools/pdfdebugger/ui/Tree.java Sun May 31 11:10:10 2015
@@ -89,10 +89,10 @@ public class Tree extends JTree
* @param nodePath is instance of TreePath of the specified Node.
* @return the JMenuItem list for the node
*/
- private ArrayList<JMenuItem> getPopupMenuItems(TreePath nodePath)
+ private List<JMenuItem> getPopupMenuItems(TreePath nodePath)
{
Object obj = nodePath.getLastPathComponent();
- ArrayList<JMenuItem> menuItems = new ArrayList<JMenuItem>();
+ List<JMenuItem> menuItems = new ArrayList<JMenuItem>();
if (obj instanceof MapEntry)
{
@@ -253,19 +253,13 @@ public class Tree extends JTree
}
/**
- * save the stream
- * @param bytes byte array of the stream
+ * Save the stream.
+ * @param bytes byte array of the stream.
+ * @throws IOException if there is an error in creation of the file.
*/
- private void saveStream(byte[] bytes)
+ private void saveStream(byte[] bytes) throws IOException
{
FileOpenSaveDialog saveDialog = new FileOpenSaveDialog(parent, null);
- try
- {
- saveDialog.saveFile(bytes);
- }
- catch (IOException e)
- {
- throw new RuntimeException(e);
- }
+ saveDialog.saveFile(bytes);
}
}
Modified: pdfbox/trunk/tools/src/main/java/org/apache/pdfbox/tools/util/FileOpenSaveDialog.java
URL: http://svn.apache.org/viewvc/pdfbox/trunk/tools/src/main/java/org/apache/pdfbox/tools/util/FileOpenSaveDialog.java?rev=1682717&r1=1682716&r2=1682717&view=diff
==============================================================================
--- pdfbox/trunk/tools/src/main/java/org/apache/pdfbox/tools/util/FileOpenSaveDialog.java (original)
+++ pdfbox/trunk/tools/src/main/java/org/apache/pdfbox/tools/util/FileOpenSaveDialog.java Sun May 31 11:10:10 2015
@@ -32,7 +32,7 @@ import org.apache.pdfbox.tools.PDFDebugg
*/
public class FileOpenSaveDialog
{
- PDFDebugger mainUI;
+ private PDFDebugger mainUI;
private static final JFileChooser fileChooser = new JFileChooser()
{
@@ -68,10 +68,11 @@ public class FileOpenSaveDialog
}
/**
- * saves a file while user is prompted to chose the destination.
- * @param bytes byte array of the saving file.
- * @return true if file is saved successfully or false if failed.
- * @throws IOException if there is error in creation of file.
+ * Saves data into a file after the user is prompted to choose the destination.
+ *
+ * @param bytes byte array to be saved in a file.
+ * @return true if the file is saved successfully or false if failed.
+ * @throws IOException if there is an error in creation of the file.
*/
public boolean saveFile(byte[] bytes) throws IOException
{
@@ -79,9 +80,19 @@ public class FileOpenSaveDialog
if (result == JFileChooser.APPROVE_OPTION)
{
File selectedFile = fileChooser.getSelectedFile();
- FileOutputStream outputStream = new FileOutputStream(selectedFile);
- outputStream.write(bytes);
- outputStream.close();
+ FileOutputStream outputStream = null;
+ try
+ {
+ outputStream = new FileOutputStream(selectedFile);
+ outputStream.write(bytes);
+ }
+ finally
+ {
+ if (outputStream != null)
+ {
+ outputStream.close();
+ }
+ }
return true;
}
return false;