From eb278af8186496a6517bb1d27b7210bd173841fd Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Wed, 7 May 2014 11:37:52 +0200 Subject: Shutdown hook for safely closing files --- src/main/TweetShell.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/main/TweetShell.java b/src/main/TweetShell.java index 4ba50f3..231007f 100644 --- a/src/main/TweetShell.java +++ b/src/main/TweetShell.java @@ -49,6 +49,14 @@ public class TweetShell implements TwitterApi.PinSupplier { // and something that prints tweets to console. resultListeners.register(new StreamHandler()); // see getPossibleTargets() for more listener types. + + // register shutdown listener to prevent corruption on SIGINT + Runtime.getRuntime().addShutdownHook(new Thread(new Runnable() { + @Override + public void run() { + safeClose(); + } + })); } private TwitterApi getApi() throws IOException { -- cgit v1.2.1