From 0b487ee9f3fe96b6c4725945344b1c679c9eae31 Mon Sep 17 00:00:00 2001 From: Paul Speed Date: Sun, 13 Mar 2016 04:44:54 -0400 Subject: [PATCH] Moved the file writing in screen shot app state to its own method... 1) because it's a little cleaner, 2) because it means subclasses can hook it if desired. --- .../jme3/app/state/ScreenshotAppState.java | 26 ++++++++++--------- 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/jme3-core/src/main/java/com/jme3/app/state/ScreenshotAppState.java b/jme3-core/src/main/java/com/jme3/app/state/ScreenshotAppState.java index f386af5db..c6ba5b124 100644 --- a/jme3-core/src/main/java/com/jme3/app/state/ScreenshotAppState.java +++ b/jme3-core/src/main/java/com/jme3/app/state/ScreenshotAppState.java @@ -249,21 +249,23 @@ public class ScreenshotAppState extends AbstractAppState implements ActionListen } logger.log(Level.FINE, "Saving ScreenShot to: {0}", file.getAbsolutePath()); - OutputStream outStream = null; try { - outStream = new FileOutputStream(file); - JmeSystem.writeImageFile(outStream, "png", outBuf, width, height); + writeImageFile(file); } catch (IOException ex) { logger.log(Level.SEVERE, "Error while saving screenshot", ex); - } finally { - if (outStream != null){ - try { - outStream.close(); - } catch (IOException ex) { - logger.log(Level.SEVERE, "Error while saving screenshot", ex); - } - } - } + } } } + + /** + * Called by postFrame() once the screen has been captured to outBuf. + */ + protected void writeImageFile( File file ) throws IOException { + OutputStream outStream = new FileOutputStream(file); + try { + JmeSystem.writeImageFile(outStream, "png", outBuf, width, height); + } finally { + outStream.close(); + } + } }