← Back to team overview

gnome-split-team team mailing list archive

[Branch ~respawneral/gnome-split/mainline] Rev 240: Kill signals handler.

 

------------------------------------------------------------
revno: 240
committer: Guillaume Mazoyer <respawneral@xxxxxxxxx>
branch nick: gnome-split
timestamp: Sun 2010-11-07 21:02:45 +0100
message:
  Kill signals handler.
  
  Add a kill signal handler that can close all
  IO streams to terminate the application in a
  proper way.
added:
  src/org/gnome/split/core/io/
  src/org/gnome/split/core/io/GFileInputStream.java
  src/org/gnome/split/core/io/GFileWriter.java
  src/org/gnome/split/core/io/GRandomAccessFile.java
  src/org/gnome/split/core/utils/ShutdownHandler.java
modified:
  src/org/gnome/split/GnomeSplit.java
  src/org/gnome/split/config/Configuration.java
  src/org/gnome/split/core/merger/DefaultMergeEngine.java
  src/org/gnome/split/core/merger/Generic.java
  src/org/gnome/split/core/merger/GnomeSplit.java
  src/org/gnome/split/core/merger/KFK.java
  src/org/gnome/split/core/merger/Xtremsplit.java
  src/org/gnome/split/core/merger/YoyoCut.java
  src/org/gnome/split/core/splitter/DefaultSplitEngine.java
  src/org/gnome/split/core/splitter/Generic.java
  src/org/gnome/split/core/splitter/GnomeSplit.java
  src/org/gnome/split/core/splitter/KFK.java
  src/org/gnome/split/core/splitter/Xtremsplit.java
  src/org/gnome/split/core/splitter/YoyoCut.java


--
lp:gnome-split
https://code.launchpad.net/~respawneral/gnome-split/mainline

Your team GNOME Split developers is subscribed to branch lp:gnome-split.
To unsubscribe from this branch go to https://code.launchpad.net/~respawneral/gnome-split/mainline/+edit-subscription
=== modified file 'src/org/gnome/split/GnomeSplit.java'
--- src/org/gnome/split/GnomeSplit.java	2010-09-15 19:54:43 +0000
+++ src/org/gnome/split/GnomeSplit.java	2010-11-07 20:02:45 +0000
@@ -32,6 +32,7 @@
 import org.gnome.split.config.Constants;
 import org.gnome.split.core.EngineListener;
 import org.gnome.split.core.utils.Algorithm;
+import org.gnome.split.core.utils.ShutdownHandler;
 import org.gnome.split.core.utils.UncaughtExceptionLogger;
 import org.gnome.split.getopt.GetOptions;
 import org.gnome.split.getopt.LongOption;
@@ -82,6 +83,9 @@
         // Initialize uncaught exception handler
         new UncaughtExceptionLogger();
 
+        // Start kill signals handler
+        Runtime.getRuntime().addShutdownHook(new ShutdownHandler());
+
         // Load program name
         Glib.setProgramName(Constants.PROGRAM_NAME);
 

=== modified file 'src/org/gnome/split/config/Configuration.java'
--- src/org/gnome/split/config/Configuration.java	2010-07-22 15:42:22 +0000
+++ src/org/gnome/split/config/Configuration.java	2010-11-07 20:02:45 +0000
@@ -21,12 +21,13 @@
 package org.gnome.split.config;
 
 import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileWriter;
 import java.io.IOException;
 import java.io.InputStream;
 import java.util.Properties;
 
+import org.gnome.split.core.io.GFileInputStream;
+import org.gnome.split.core.io.GFileWriter;
+
 /**
  * Load the configuration file and interact with it.
  * 
@@ -171,10 +172,10 @@
      * This method is used to reset the preferences.
      */
     private void createPreferences() {
-        FileWriter writer = null;
+        GFileWriter writer = null;
         try {
             // Open the file writer
-            writer = new FileWriter(configuration);
+            writer = new GFileWriter(configuration);
 
             // Write general config
             writer.write("StartAssistant    = true\n");
@@ -226,7 +227,7 @@
     private void load() {
         try {
             Properties preferences = new Properties();
-            InputStream stream = new FileInputStream(configuration);
+            InputStream stream = new GFileInputStream(configuration);
 
             // Load the properties
             preferences.load(stream);
@@ -274,10 +275,10 @@
      * This method is used to save the preferences by overwriting the file.
      */
     public void savePreferences() {
-        FileWriter writer = null;
+        GFileWriter writer = null;
         try {
             // Open the file writer
-            writer = new FileWriter(configuration);
+            writer = new GFileWriter(configuration);
 
             // Write general config
             writer.write("StartAssistant    = " + ASSISTANT_ON_START + "\n");

=== added directory 'src/org/gnome/split/core/io'
=== added file 'src/org/gnome/split/core/io/GFileInputStream.java'
--- src/org/gnome/split/core/io/GFileInputStream.java	1970-01-01 00:00:00 +0000
+++ src/org/gnome/split/core/io/GFileInputStream.java	2010-11-07 20:02:45 +0000
@@ -0,0 +1,75 @@
+/*
+ * GFileInputStream.java
+ * 
+ * Copyright (c) 2009-2010 Guillaume Mazoyer
+ * 
+ * This file is part of GNOME Split.
+ * 
+ * GNOME Split is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * 
+ * GNOME Split is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with GNOME Split.  If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.gnome.split.core.io;
+
+import java.io.File;
+import java.io.FileDescriptor;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Subclass of {@link FileInputStream} to be able to close all opened streams
+ * when needed.
+ * 
+ * @author Guillaume Mazoyer
+ */
+public final class GFileInputStream extends FileInputStream
+{
+    /**
+     * Instances of {@link GFileInputStream} that have been opened.
+     */
+    private static final List<GFileInputStream> instances;
+
+    static {
+        instances = new ArrayList<GFileInputStream>();
+    }
+
+    public GFileInputStream(String name) throws FileNotFoundException {
+        super(name);
+        instances.add(this);
+    }
+
+    public GFileInputStream(File file) throws FileNotFoundException {
+        super(file);
+        instances.add(this);
+    }
+
+    public GFileInputStream(FileDescriptor descriptor) {
+        super(descriptor);
+        instances.add(this);
+    }
+
+    /**
+     * Return all instances of {@link GFileInputStream} that have been opened.
+     */
+    public static List<GFileInputStream> getInstances() {
+        return instances;
+    }
+
+    @Override
+    public void close() throws IOException {
+        super.close();
+        instances.remove(this);
+    }
+}

=== added file 'src/org/gnome/split/core/io/GFileWriter.java'
--- src/org/gnome/split/core/io/GFileWriter.java	1970-01-01 00:00:00 +0000
+++ src/org/gnome/split/core/io/GFileWriter.java	2010-11-07 20:02:45 +0000
@@ -0,0 +1,84 @@
+/*
+ * GFileWriter.java
+ * 
+ * Copyright (c) 2009-2010 Guillaume Mazoyer
+ * 
+ * This file is part of GNOME Split.
+ * 
+ * GNOME Split is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * 
+ * GNOME Split is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with GNOME Split.  If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.gnome.split.core.io;
+
+import java.io.File;
+import java.io.FileDescriptor;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Subclass of {@link FileWriter} to be able to close all opened streams when
+ * needed.
+ * 
+ * @author Guillaume Mazoyer
+ */
+public final class GFileWriter extends FileWriter
+{
+    /**
+     * Instances of {@link GFileWriter} that have been opened.
+     */
+    private static final List<GFileWriter> instances;
+
+    static {
+        instances = new ArrayList<GFileWriter>();
+    }
+
+    public GFileWriter(String filename) throws IOException {
+        super(filename);
+        instances.add(this);
+    }
+
+    public GFileWriter(File file) throws IOException {
+        super(file);
+        instances.add(this);
+    }
+
+    public GFileWriter(FileDescriptor descriptor) {
+        super(descriptor);
+        instances.add(this);
+    }
+
+    public GFileWriter(String filename, boolean append) throws IOException {
+        super(filename, append);
+        instances.add(this);
+    }
+
+    public GFileWriter(File file, boolean append) throws IOException {
+        super(file, append);
+        instances.add(this);
+    }
+
+    /**
+     * Return all instances of {@link GFileWriter} that have been opened.
+     */
+    public static List<GFileWriter> getInstances() {
+        return instances;
+    }
+
+    @Override
+    public void close() throws IOException {
+        super.close();
+        instances.remove(this);
+    }
+}

=== added file 'src/org/gnome/split/core/io/GRandomAccessFile.java'
--- src/org/gnome/split/core/io/GRandomAccessFile.java	1970-01-01 00:00:00 +0000
+++ src/org/gnome/split/core/io/GRandomAccessFile.java	2010-11-07 20:02:45 +0000
@@ -0,0 +1,70 @@
+/*
+ * GRandomAccessFile.java
+ * 
+ * Copyright (c) 2009-2010 Guillaume Mazoyer
+ * 
+ * This file is part of GNOME Split.
+ * 
+ * GNOME Split is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * 
+ * GNOME Split is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with GNOME Split.  If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.gnome.split.core.io;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.RandomAccessFile;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Subclass of {@link RandomAccessFile} to be able to close all opened streams
+ * when needed.
+ * 
+ * @author Guillaume Mazoyer
+ */
+public final class GRandomAccessFile extends RandomAccessFile
+{
+    /**
+     * Instances of {@link GRandomAccessFile} that have been opened.
+     */
+    private static final List<GRandomAccessFile> instances;
+
+    static {
+        instances = new ArrayList<GRandomAccessFile>();
+    }
+
+    public GRandomAccessFile(String name, String mode) throws FileNotFoundException {
+        super(name, mode);
+        instances.add(this);
+    }
+
+    public GRandomAccessFile(File file, String mode) throws FileNotFoundException {
+        super(file, mode);
+        instances.add(this);
+    }
+
+    /**
+     * Return all instances of {@link GRandomAccessFile} that have been
+     * opened.
+     */
+    public static List<GRandomAccessFile> getInstances() {
+        return instances;
+    }
+
+    @Override
+    public void close() throws IOException {
+        super.close();
+        instances.remove(this);
+    }
+}

=== modified file 'src/org/gnome/split/core/merger/DefaultMergeEngine.java'
--- src/org/gnome/split/core/merger/DefaultMergeEngine.java	2010-10-13 17:50:44 +0000
+++ src/org/gnome/split/core/merger/DefaultMergeEngine.java	2010-11-07 20:02:45 +0000
@@ -22,7 +22,6 @@
 
 import java.io.File;
 import java.io.IOException;
-import java.io.RandomAccessFile;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Timer;
@@ -31,6 +30,7 @@
 import org.gnome.split.core.DefaultEngine;
 import org.gnome.split.core.Engine;
 import org.gnome.split.core.exception.EngineException;
+import org.gnome.split.core.io.GRandomAccessFile;
 import org.gnome.split.core.utils.Algorithm;
 
 import static org.freedesktop.bindings.Internationalization._;
@@ -284,7 +284,7 @@
      * maximum number of bytes that can be read. It returns <code>true</code>
      * if the reading was fully performed, else it returns <code>false</code>.
      */
-    protected boolean mergeChunk(RandomAccessFile merge, RandomAccessFile chunk, long read, long length)
+    protected boolean mergeChunk(GRandomAccessFile merge, GRandomAccessFile chunk, long read, long length)
             throws IOException {
         // Setup the buffer
         byte[] buffer = null;

=== modified file 'src/org/gnome/split/core/merger/Generic.java'
--- src/org/gnome/split/core/merger/Generic.java	2010-10-13 17:50:44 +0000
+++ src/org/gnome/split/core/merger/Generic.java	2010-11-07 20:02:45 +0000
@@ -22,11 +22,11 @@
 
 import java.io.File;
 import java.io.IOException;
-import java.io.RandomAccessFile;
 
 import org.gnome.split.GnomeSplit;
 import org.gnome.split.core.exception.EngineException;
 import org.gnome.split.core.exception.MissingChunkException;
+import org.gnome.split.core.io.GRandomAccessFile;
 
 /**
  * Algorithm to merge files with an algorithm which does not use any headers
@@ -93,13 +93,13 @@
     @Override
     public void merge() throws IOException, EngineException {
         String part = file.getAbsolutePath().substring(0, file.getAbsolutePath().length() - 3);
-        RandomAccessFile out = null;
+        GRandomAccessFile out = null;
         File chunk = null;
         boolean run = true;
 
         try {
             // Open the final file
-            out = new RandomAccessFile(filename, "rw");
+            out = new GRandomAccessFile(filename, "rw");
 
             // We assume that there is at least one part (which is kinda
             // ridiculous, but still...). We'll do some tricks to find out
@@ -115,7 +115,7 @@
                 }
 
                 // Open the chunk to read it
-                RandomAccessFile access = new RandomAccessFile(chunk, "r");
+                GRandomAccessFile access = new GRandomAccessFile(chunk, "r");
 
                 // Notify the view from a new part read
                 this.fireEnginePartRead(chunk.getName());

=== modified file 'src/org/gnome/split/core/merger/GnomeSplit.java'
--- src/org/gnome/split/core/merger/GnomeSplit.java	2010-10-13 17:50:44 +0000
+++ src/org/gnome/split/core/merger/GnomeSplit.java	2010-11-07 20:02:45 +0000
@@ -22,11 +22,11 @@
 
 import java.io.File;
 import java.io.IOException;
-import java.io.RandomAccessFile;
 
 import org.gnome.split.core.exception.EngineException;
 import org.gnome.split.core.exception.MD5Exception;
 import org.gnome.split.core.exception.MissingChunkException;
+import org.gnome.split.core.io.GRandomAccessFile;
 import org.gnome.split.core.utils.MD5Hasher;
 
 /**
@@ -42,10 +42,10 @@
 
     @Override
     protected void loadHeaders() throws IOException {
-        RandomAccessFile access = null;
+        GRandomAccessFile access = null;
         try {
             // Open the first part to merge
-            access = new RandomAccessFile(file, "r");
+            access = new GRandomAccessFile(file, "r");
 
             // Skip useless header
             access.skipBytes(5);
@@ -98,14 +98,14 @@
     @Override
     public void merge() throws IOException, EngineException {
         String part = file.getAbsolutePath().substring(0, file.getAbsolutePath().length() - 7);
-        RandomAccessFile out = null;
+        GRandomAccessFile out = null;
         File chunk = null;
         boolean run = true;
         boolean success = true;
 
         try {
             // Open the final file
-            out = new RandomAccessFile(filename, "rw");
+            out = new GRandomAccessFile(filename, "rw");
 
             // Define the buffer size
             byte[] buffer;
@@ -119,7 +119,7 @@
                 }
 
                 // Open the chunk to read it
-                RandomAccessFile access = new RandomAccessFile(chunk, "r");
+                GRandomAccessFile access = new GRandomAccessFile(chunk, "r");
 
                 // Notify the view from a new part read
                 this.fireEnginePartRead(chunk.getName());

=== modified file 'src/org/gnome/split/core/merger/KFK.java'
--- src/org/gnome/split/core/merger/KFK.java	2010-10-13 17:50:44 +0000
+++ src/org/gnome/split/core/merger/KFK.java	2010-11-07 20:02:45 +0000
@@ -22,11 +22,11 @@
 
 import java.io.File;
 import java.io.IOException;
-import java.io.RandomAccessFile;
 
 import org.gnome.split.GnomeSplit;
 import org.gnome.split.core.exception.EngineException;
 import org.gnome.split.core.exception.MissingChunkException;
+import org.gnome.split.core.io.GRandomAccessFile;
 
 /**
  * Algorithm to merge files with the KFK algorithm.
@@ -76,13 +76,13 @@
     @Override
     public void merge() throws IOException, EngineException {
         String part = file.getAbsolutePath().substring(0, file.getAbsolutePath().length() - 4);
-        RandomAccessFile out = null;
+        GRandomAccessFile out = null;
         File chunk = null;
         boolean run = true;
 
         try {
             // Open the final file
-            out = new RandomAccessFile(filename, "rw");
+            out = new GRandomAccessFile(filename, "rw");
 
             for (int i = 0; i < parts; i++) {
                 // Next chunk
@@ -93,7 +93,7 @@
                 }
 
                 // Open the chunk to read it
-                RandomAccessFile access = new RandomAccessFile(chunk, "r");
+                GRandomAccessFile access = new GRandomAccessFile(chunk, "r");
 
                 // Notify the view from a new part read
                 this.fireEnginePartRead(chunk.getName());

=== modified file 'src/org/gnome/split/core/merger/Xtremsplit.java'
--- src/org/gnome/split/core/merger/Xtremsplit.java	2010-10-13 17:50:44 +0000
+++ src/org/gnome/split/core/merger/Xtremsplit.java	2010-11-07 20:02:45 +0000
@@ -22,12 +22,12 @@
 
 import java.io.File;
 import java.io.IOException;
-import java.io.RandomAccessFile;
 
 import org.gnome.split.GnomeSplit;
 import org.gnome.split.core.exception.EngineException;
 import org.gnome.split.core.exception.MD5Exception;
 import org.gnome.split.core.exception.MissingChunkException;
+import org.gnome.split.core.io.GRandomAccessFile;
 import org.gnome.split.core.utils.ByteUtils;
 import org.gnome.split.core.utils.MD5Hasher;
 
@@ -52,7 +52,7 @@
     private void loadMD5sums(String lastFilename) throws IOException {
         // Find the last file to read
         File lastFile = new File(lastFilename);
-        RandomAccessFile access = new RandomAccessFile(lastFile, "r");
+        GRandomAccessFile access = new GRandomAccessFile(lastFile, "r");
 
         // Find the position of the MD5 sums
         long position = access.length() - (parts * 32);
@@ -73,10 +73,10 @@
 
     @Override
     protected void loadHeaders() throws IOException {
-        RandomAccessFile access = null;
+        GRandomAccessFile access = null;
         try {
             // Open the first part to merge
-            access = new RandomAccessFile(file, "r");
+            access = new GRandomAccessFile(file, "r");
 
             if (file.getName().endsWith(".001.exe")) {
                 // Skip useless header and .exe header
@@ -140,14 +140,14 @@
     @Override
     public void merge() throws IOException, EngineException {
         String part = file.getAbsolutePath().substring(0, file.getAbsolutePath().length() - 7);
-        RandomAccessFile out = null;
+        GRandomAccessFile out = null;
         File chunk = null;
         boolean run = true;
         boolean success = true;
 
         try {
             // Open the final file
-            out = new RandomAccessFile(filename, "rw");
+            out = new GRandomAccessFile(filename, "rw");
 
             // Load all the MD5 sums
             md5sums = new String[parts];
@@ -170,7 +170,7 @@
                 }
 
                 // Open the chunk to read it
-                RandomAccessFile access = new RandomAccessFile(chunk, "r");
+                GRandomAccessFile access = new GRandomAccessFile(chunk, "r");
 
                 // Notify the view from a new part read
                 this.fireEnginePartRead(chunk.getName());

=== modified file 'src/org/gnome/split/core/merger/YoyoCut.java'
--- src/org/gnome/split/core/merger/YoyoCut.java	2010-10-13 17:50:44 +0000
+++ src/org/gnome/split/core/merger/YoyoCut.java	2010-11-07 20:02:45 +0000
@@ -22,13 +22,13 @@
 
 import java.io.File;
 import java.io.IOException;
-import java.io.RandomAccessFile;
 import java.util.ArrayList;
 
 import org.gnome.split.GnomeSplit;
 import org.gnome.split.core.exception.EngineException;
 import org.gnome.split.core.exception.MD5Exception;
 import org.gnome.split.core.exception.MissingChunkException;
+import org.gnome.split.core.io.GRandomAccessFile;
 import org.gnome.split.core.utils.MD5Hasher;
 
 /**
@@ -49,10 +49,10 @@
 
     @Override
     protected void loadHeaders() throws IOException {
-        RandomAccessFile access = null;
+        GRandomAccessFile access = null;
         try {
             // Open the first part to merge
-            access = new RandomAccessFile(file, "r");
+            access = new GRandomAccessFile(file, "r");
 
             // Set the length of the header to 0
             header = 0;
@@ -147,14 +147,14 @@
     @Override
     public void merge() throws IOException, EngineException {
         String part = file.getAbsolutePath().substring(0, file.getAbsolutePath().length() - 7);
-        RandomAccessFile out = null;
+        GRandomAccessFile out = null;
         File chunk = null;
         boolean run = true;
         boolean success = true;
 
         try {
             // Open the final file
-            out = new RandomAccessFile(filename, "rw");
+            out = new GRandomAccessFile(filename, "rw");
 
             for (int i = 1; i <= parts; i++) {
                 // Next chunk
@@ -165,7 +165,7 @@
                 }
 
                 // Open the chunk to read it
-                RandomAccessFile access = new RandomAccessFile(chunk, "r");
+                GRandomAccessFile access = new GRandomAccessFile(chunk, "r");
 
                 // Notify the view from a new part read
                 this.fireEnginePartRead(chunk.getName());

=== modified file 'src/org/gnome/split/core/splitter/DefaultSplitEngine.java'
--- src/org/gnome/split/core/splitter/DefaultSplitEngine.java	2010-10-13 17:50:44 +0000
+++ src/org/gnome/split/core/splitter/DefaultSplitEngine.java	2010-11-07 20:02:45 +0000
@@ -22,7 +22,6 @@
 
 import java.io.File;
 import java.io.IOException;
-import java.io.RandomAccessFile;
 import java.util.Timer;
 import java.util.TimerTask;
 
@@ -31,6 +30,7 @@
 import org.gnome.split.core.Engine;
 import org.gnome.split.core.exception.EngineException;
 import org.gnome.split.core.exception.InvalidSizeException;
+import org.gnome.split.core.io.GRandomAccessFile;
 
 import static org.freedesktop.bindings.Internationalization._;
 
@@ -222,7 +222,7 @@
      * returns <code>true</code> if the writing was fully performed, else it
      * returns <code>false</code>.
      */
-    protected boolean writeChunk(RandomAccessFile split, RandomAccessFile chunk) throws IOException {
+    protected boolean writeChunk(GRandomAccessFile split, GRandomAccessFile chunk) throws IOException {
         // Needed variables to know when the chunk writing must be stopped
         int read = 0;
         byte[] buffer = null;

=== modified file 'src/org/gnome/split/core/splitter/Generic.java'
--- src/org/gnome/split/core/splitter/Generic.java	2010-10-13 17:50:44 +0000
+++ src/org/gnome/split/core/splitter/Generic.java	2010-11-07 20:02:45 +0000
@@ -23,7 +23,8 @@
 import java.io.File;
 import java.io.FileNotFoundException;
 import java.io.IOException;
-import java.io.RandomAccessFile;
+
+import org.gnome.split.core.io.GRandomAccessFile;
 
 /**
  * Algorithm to split files with an algorithm which does not use any headers
@@ -58,19 +59,19 @@
 
     @Override
     public void split() throws IOException, FileNotFoundException {
-        RandomAccessFile toSplit = null;
+        GRandomAccessFile toSplit = null;
         boolean run = true;
         try {
             // Open a new file
-            toSplit = new RandomAccessFile(file, "r");
+            toSplit = new GRandomAccessFile(file, "r");
 
             for (int i = 1; i <= parts; i++) {
-                RandomAccessFile access = null;
+                GRandomAccessFile access = null;
                 File chunk = null;
                 try {
                     // Open the part
                     chunk = new File(this.getChunkName(destination, i));
-                    access = new RandomAccessFile(chunk, "rw");
+                    access = new GRandomAccessFile(chunk, "rw");
 
                     // Notify the view from a new part
                     chunks.add(chunk.getAbsolutePath());

=== modified file 'src/org/gnome/split/core/splitter/GnomeSplit.java'
--- src/org/gnome/split/core/splitter/GnomeSplit.java	2010-10-13 17:50:44 +0000
+++ src/org/gnome/split/core/splitter/GnomeSplit.java	2010-11-07 20:02:45 +0000
@@ -23,9 +23,9 @@
 import java.io.File;
 import java.io.FileNotFoundException;
 import java.io.IOException;
-import java.io.RandomAccessFile;
 
 import org.gnome.split.config.Constants;
+import org.gnome.split.core.io.GRandomAccessFile;
 import org.gnome.split.core.utils.MD5Hasher;
 
 /**
@@ -45,7 +45,7 @@
     /**
      * Write the GNOME Split header at the beginning of a file.
      */
-    private void writeHeaders(RandomAccessFile access) throws IOException {
+    private void writeHeaders(GRandomAccessFile access) throws IOException {
         byte[] toWrite;
 
         // Write program version
@@ -97,19 +97,19 @@
 
     @Override
     public void split() throws IOException, FileNotFoundException {
-        RandomAccessFile toSplit = null;
+        GRandomAccessFile toSplit = null;
         boolean run = true;
         try {
             // Open a new file
-            toSplit = new RandomAccessFile(file, "r");
+            toSplit = new GRandomAccessFile(file, "r");
 
             for (int i = 1; i <= parts; i++) {
-                RandomAccessFile access = null;
+                GRandomAccessFile access = null;
                 File chunk = null;
                 try {
                     // Open the part
                     chunk = new File(this.getChunkName(destination, i));
-                    access = new RandomAccessFile(chunk, "rw");
+                    access = new GRandomAccessFile(chunk, "rw");
 
                     // Notify the view from a new part
                     chunks.add(chunk.getAbsolutePath());

=== modified file 'src/org/gnome/split/core/splitter/KFK.java'
--- src/org/gnome/split/core/splitter/KFK.java	2010-10-13 17:50:44 +0000
+++ src/org/gnome/split/core/splitter/KFK.java	2010-11-07 20:02:45 +0000
@@ -23,7 +23,8 @@
 import java.io.File;
 import java.io.FileNotFoundException;
 import java.io.IOException;
-import java.io.RandomAccessFile;
+
+import org.gnome.split.core.io.GRandomAccessFile;
 
 /**
  * Algorithm to split a file with the KFK algorithm.
@@ -46,19 +47,19 @@
 
     @Override
     public void split() throws IOException, FileNotFoundException {
-        RandomAccessFile toSplit = null;
+        GRandomAccessFile toSplit = null;
         boolean run = true;
         try {
             // Open a new file
-            toSplit = new RandomAccessFile(file, "r");
+            toSplit = new GRandomAccessFile(file, "r");
 
             for (int i = 0; i < parts; i++) {
-                RandomAccessFile access = null;
+                GRandomAccessFile access = null;
                 File chunk = null;
                 try {
                     // Open the part
                     chunk = new File(this.getChunkName(destination, i));
-                    access = new RandomAccessFile(chunk, "rw");
+                    access = new GRandomAccessFile(chunk, "rw");
 
                     // Notify the view from a new part
                     chunks.add(chunk.getAbsolutePath());

=== modified file 'src/org/gnome/split/core/splitter/Xtremsplit.java'
--- src/org/gnome/split/core/splitter/Xtremsplit.java	2010-10-13 17:50:44 +0000
+++ src/org/gnome/split/core/splitter/Xtremsplit.java	2010-11-07 20:02:45 +0000
@@ -23,10 +23,10 @@
 import java.io.File;
 import java.io.FileNotFoundException;
 import java.io.IOException;
-import java.io.RandomAccessFile;
 
 import org.gnome.split.GnomeSplit;
 import org.gnome.split.config.Constants;
+import org.gnome.split.core.io.GRandomAccessFile;
 import org.gnome.split.core.utils.ByteUtils;
 import org.gnome.split.core.utils.MD5Hasher;
 import org.gnome.split.core.utils.Utils;
@@ -48,7 +48,7 @@
     /**
      * Write the xtm header at the beginning of a file.
      */
-    private void writeHeaders(RandomAccessFile access) throws IOException {
+    private void writeHeaders(GRandomAccessFile access) throws IOException {
         byte[] toWrite;
 
         // Write program name
@@ -112,11 +112,11 @@
 
     @Override
     public void split() throws IOException, FileNotFoundException {
-        RandomAccessFile toSplit = null;
+        GRandomAccessFile toSplit = null;
         boolean run = true;
         try {
             // Open a new file
-            toSplit = new RandomAccessFile(file, "r");
+            toSplit = new GRandomAccessFile(file, "r");
 
             // Used for the MD5 calculation
             StringBuilder md5sum = null;
@@ -129,12 +129,12 @@
             }
 
             for (int i = 1; i <= parts; i++) {
-                RandomAccessFile access = null;
+                GRandomAccessFile access = null;
                 File chunk = null;
                 try {
                     // Open the part
                     chunk = new File(this.getChunkName(destination, i));
-                    access = new RandomAccessFile(chunk, "rw");
+                    access = new GRandomAccessFile(chunk, "rw");
 
                     // Notify the view from a new part
                     chunks.add(chunk.getAbsolutePath());

=== modified file 'src/org/gnome/split/core/splitter/YoyoCut.java'
--- src/org/gnome/split/core/splitter/YoyoCut.java	2010-10-13 17:50:44 +0000
+++ src/org/gnome/split/core/splitter/YoyoCut.java	2010-11-07 20:02:45 +0000
@@ -22,9 +22,9 @@
 
 import java.io.File;
 import java.io.IOException;
-import java.io.RandomAccessFile;
 
 import org.gnome.split.GnomeSplit;
+import org.gnome.split.core.io.GRandomAccessFile;
 import org.gnome.split.core.utils.MD5Hasher;
 
 /**
@@ -44,7 +44,7 @@
     /**
      * Write the GNOME Split header at the beginning of a file.
      */
-    private void writeHeaders(RandomAccessFile access) throws IOException {
+    private void writeHeaders(GRandomAccessFile access) throws IOException {
         // Write the extension
         String extension = file.getName().substring(file.getName().lastIndexOf('.') + 1) + " ";
         access.write(extension.getBytes());
@@ -101,19 +101,19 @@
 
     @Override
     public void split() throws IOException {
-        RandomAccessFile toSplit = null;
+        GRandomAccessFile toSplit = null;
         boolean run = true;
         try {
             // Open a new file
-            toSplit = new RandomAccessFile(file, "r");
+            toSplit = new GRandomAccessFile(file, "r");
 
             for (int i = 1; i <= parts; i++) {
-                RandomAccessFile access = null;
+                GRandomAccessFile access = null;
                 File chunk = null;
                 try {
                     // Open the part
                     chunk = new File(this.getChunkName(destination, i));
-                    access = new RandomAccessFile(chunk, "rw");
+                    access = new GRandomAccessFile(chunk, "rw");
 
                     // Notify the view from a new part
                     chunks.add(chunk.getAbsolutePath());

=== added file 'src/org/gnome/split/core/utils/ShutdownHandler.java'
--- src/org/gnome/split/core/utils/ShutdownHandler.java	1970-01-01 00:00:00 +0000
+++ src/org/gnome/split/core/utils/ShutdownHandler.java	2010-11-07 20:02:45 +0000
@@ -0,0 +1,58 @@
+/*
+ * ShutdownHandler.java
+ * 
+ * Copyright (c) 2009-2010 Guillaume Mazoyer
+ * 
+ * This file is part of GNOME Split.
+ * 
+ * GNOME Split is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * 
+ * GNOME Split is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with GNOME Split.  If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.gnome.split.core.utils;
+
+import java.io.Closeable;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.gnome.split.core.io.GFileInputStream;
+import org.gnome.split.core.io.GFileWriter;
+import org.gnome.split.core.io.GRandomAccessFile;
+
+/**
+ * A class to handle cases where kill signals are emitted to terminate the
+ * application.
+ * 
+ * @author Guillaume Mazoyer
+ */
+public final class ShutdownHandler extends Thread
+{
+    @Override
+    public void run() {
+        List<Closeable> io = new ArrayList<Closeable>();
+
+        // Get all opened IO
+        io.addAll(GFileInputStream.getInstances());
+        io.addAll(GFileWriter.getInstances());
+        io.addAll(GRandomAccessFile.getInstances());
+
+        for (Closeable closeable : io) {
+            try {
+                // Close each opened IO
+                closeable.close();
+            } catch (IOException e) {
+                e.printStackTrace();
+            }
+        }
+    }
+}