From: <chr...@us...> - 2006-12-10 23:18:18
|
Revision: 1050 http://svn.sourceforge.net/gridarta/?rev=1050&view=rev Author: christianhujer Date: 2006-12-10 15:18:18 -0800 (Sun, 10 Dec 2006) Log Message: ----------- Improved I/O handling. Modified Paths: -------------- trunk/daimonin/src/daieditor/gameobject/face/FaceObjects.java Modified: trunk/daimonin/src/daieditor/gameobject/face/FaceObjects.java =================================================================== --- trunk/daimonin/src/daieditor/gameobject/face/FaceObjects.java 2006-12-10 23:04:40 UTC (rev 1049) +++ trunk/daimonin/src/daieditor/gameobject/face/FaceObjects.java 2006-12-10 23:18:18 UTC (rev 1050) @@ -38,6 +38,7 @@ import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStreamWriter; +import java.io.InputStream; import net.sf.gridarta.gameobject.face.AbstractFaceObjects; import net.sf.japi.swing.ActionFactory; import net.sf.japi.swing.Progress; @@ -222,24 +223,21 @@ int numBytes = 0; final String path = dir + "/dev/editor/bug.101.png"; - FileInputStream fin = null; // XXX: This code limits image support to an image size of 1024 * 50 bytes = 50k final byte[] imgBuffer = new byte[IMAGE_BUFFER_SIZE]; try { - fin = new FileInputStream(path); - numBytes = fin.read(imgBuffer, 0, IMAGE_BUFFER_SIZE); + final InputStream fin = new FileInputStream(path); + try { + numBytes = fin.read(imgBuffer, 0, IMAGE_BUFFER_SIZE); + } finally { + fin.close(); + } } catch (final FileNotFoundException e) { ACTION_FACTORY.showMessageDialog(progress.getParentComponent(), "archCollectErrorFileNotFound", path); return; } catch (final IOException e) { ACTION_FACTORY.showMessageDialog(progress.getParentComponent(), "archCollectErrorIOException", path, e); return; - } finally { - try { - fin.close(); - } catch (final Exception e) { /* ignore */ } finally { - fin = null; - } } if (numBytes == -1) { @@ -264,13 +262,12 @@ try { // try to open the png image file - fin = new FileInputStream(path2); + final InputStream fin = new FileInputStream(path2); // 50000 isn't a nice constant. But there won't be pngs larger than this. try { numBytes = fin.read(imgBuffer, 0, IMAGE_BUFFER_SIZE); } finally { fin.close(); - fin = null; } } catch (final FileNotFoundException e) { ACTION_FACTORY.showMessageDialog(progress.getParentComponent(), "archCollectErrorFileNotFound", path2); @@ -304,19 +301,13 @@ } finally { try { binFile.close(); - } catch (final Exception e) { /* ignore */ } finally { - binFile = null; - } + } catch (final Exception e) { /* ignore */ } try { textFile.close(); - } catch (final Exception e) { /* ignore */ } finally { - textFile = null; - } + } catch (final Exception e) { /* ignore */ } try { treeFile.close(); - } catch (final Exception e) { /* ignore */ } finally { - treeFile = null; - } + } catch (final Exception e) { /* ignore */ } } } } // class FaceObjects This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |