Skip to content

Commit 0b487ee

Browse files
committed
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.
1 parent f391b9c commit 0b487ee

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

jme3-core/src/main/java/com/jme3/app/state/ScreenshotAppState.java

+14-12
Original file line numberDiff line numberDiff line change
@@ -249,21 +249,23 @@ public void postFrame(FrameBuffer out) {
249249
}
250250
logger.log(Level.FINE, "Saving ScreenShot to: {0}", file.getAbsolutePath());
251251

252-
OutputStream outStream = null;
253252
try {
254-
outStream = new FileOutputStream(file);
255-
JmeSystem.writeImageFile(outStream, "png", outBuf, width, height);
253+
writeImageFile(file);
256254
} catch (IOException ex) {
257255
logger.log(Level.SEVERE, "Error while saving screenshot", ex);
258-
} finally {
259-
if (outStream != null){
260-
try {
261-
outStream.close();
262-
} catch (IOException ex) {
263-
logger.log(Level.SEVERE, "Error while saving screenshot", ex);
264-
}
265-
}
266-
}
256+
}
267257
}
268258
}
259+
260+
/**
261+
* Called by postFrame() once the screen has been captured to outBuf.
262+
*/
263+
protected void writeImageFile( File file ) throws IOException {
264+
OutputStream outStream = new FileOutputStream(file);
265+
try {
266+
JmeSystem.writeImageFile(outStream, "png", outBuf, width, height);
267+
} finally {
268+
outStream.close();
269+
}
270+
}
269271
}

0 commit comments

Comments
 (0)