diff --git a/briar-android/src/net/sf/briar/android/AndroidFileUtils.java b/briar-android/src/net/sf/briar/android/AndroidFileUtils.java index d2ca8a92ca8cb74751bd5284f7ead11d9effb47f..8f080686ccfc28531abc6a363f8b73a4225faef9 100644 --- a/briar-android/src/net/sf/briar/android/AndroidFileUtils.java +++ b/briar-android/src/net/sf/briar/android/AndroidFileUtils.java @@ -10,9 +10,9 @@ import android.os.StatFs; class AndroidFileUtils implements FileUtils { public long getFreeSpace(File f) throws IOException { + if(Build.VERSION.SDK_INT >= 9) return f.getUsableSpace(); StatFs s = new StatFs(f.getAbsolutePath()); - if(Build.VERSION.SDK_INT >= 18) - return s.getAvailableBlocksLong() * s.getBlockSizeLong(); + // These deprecated methods are the best thing available for SDK < 9 return (long) s.getAvailableBlocks() * s.getBlockSize(); } } diff --git a/briar-android/src/net/sf/briar/plugins/tor/TorPlugin.java b/briar-android/src/net/sf/briar/plugins/tor/TorPlugin.java index 1f42a60b2b5e9a502a7f9ea03faf6f8c90d61f6b..e768252956712924b1d6a8f97b8ad00c9fa77b7e 100644 --- a/briar-android/src/net/sf/briar/plugins/tor/TorPlugin.java +++ b/briar-android/src/net/sf/briar/plugins/tor/TorPlugin.java @@ -275,19 +275,23 @@ class TorPlugin implements DuplexPlugin, EventHandler { } private boolean setExecutable(File f) { - String[] command = { "chmod", "700", f.getAbsolutePath() }; - try { - return Runtime.getRuntime().exec(command).waitFor() == 0; - } catch(IOException e) { - if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e); - } catch(InterruptedException e) { - if(LOG.isLoggable(WARNING)) - LOG.warning("Interrupted while executing chmod"); - Thread.currentThread().interrupt(); - } catch(SecurityException e) { - if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e); + if(Build.VERSION.SDK_INT >= 9) { + return f.setExecutable(true, true); + } else { + String[] command = { "chmod", "700", f.getAbsolutePath() }; + try { + return Runtime.getRuntime().exec(command).waitFor() == 0; + } catch(IOException e) { + if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e); + } catch(InterruptedException e) { + if(LOG.isLoggable(WARNING)) + LOG.warning("Interrupted while executing chmod"); + Thread.currentThread().interrupt(); + } catch(SecurityException e) { + if(LOG.isLoggable(WARNING)) LOG.log(WARNING, e.toString(), e); + } + return false; } - return false; } private void tryToClose(InputStream in) { diff --git a/briar-desktop/.classpath b/briar-desktop/.classpath index 7977000899e1aeadcb3d4c7f94e5f4dd11ca0d04..9c8a7176703e39beadce86d8bdbb454de50afd59 100644 --- a/briar-desktop/.classpath +++ b/briar-desktop/.classpath @@ -6,7 +6,6 @@ <classpathentry kind="lib" path="/briar-api/libs/guice-3.0-no_aop.jar"/> <classpathentry kind="lib" path="libs/bluecove-2.1.1-SNAPSHOT-briar.jar"/> <classpathentry kind="lib" path="libs/bluecove-gpl-2.1.1-SNAPSHOT.jar"/> - <classpathentry kind="lib" path="libs/commons-io-2.0.1.jar"/> <classpathentry kind="lib" path="libs/jna-3.5.2-SNAPSHOT.jar"/> <classpathentry kind="lib" path="libs/jnotify-0.93.jar"/> <classpathentry kind="lib" path="libs/jssc-0.9-briar.jar" sourcepath="libs/source/jssc-0.9-briar-source.jar"/> diff --git a/briar-desktop/libs/commons-io-2.0.1.jar b/briar-desktop/libs/commons-io-2.0.1.jar deleted file mode 100644 index 5b64b7d6ceaf400483318272d9d52e4a390409c9..0000000000000000000000000000000000000000 Binary files a/briar-desktop/libs/commons-io-2.0.1.jar and /dev/null differ diff --git a/briar-desktop/src/net/sf/briar/os/FileUtilsImpl.java b/briar-desktop/src/net/sf/briar/os/FileUtilsImpl.java index fc796dcf6480214cfa48a509e68ff6a0418d171c..a86824272f2145d5451293dbffbe4b576415b248 100644 --- a/briar-desktop/src/net/sf/briar/os/FileUtilsImpl.java +++ b/briar-desktop/src/net/sf/briar/os/FileUtilsImpl.java @@ -5,11 +5,9 @@ import java.io.IOException; import net.sf.briar.api.os.FileUtils; -import org.apache.commons.io.FileSystemUtils; - class FileUtilsImpl implements FileUtils { public long getFreeSpace(File f) throws IOException { - return FileSystemUtils.freeSpaceKb(f.getAbsolutePath()) * 1024; + return f.getFreeSpace(); } } diff --git a/briar-desktop/src/net/sf/briar/plugins/file/WindowsRemovableDriveFinder.java b/briar-desktop/src/net/sf/briar/plugins/file/WindowsRemovableDriveFinder.java index 4b3b408d2f255c719c9a8d21ee1f49be82d3a43e..47e425b47cdf050dce40840e70150de8de93ea8a 100644 --- a/briar-desktop/src/net/sf/briar/plugins/file/WindowsRemovableDriveFinder.java +++ b/briar-desktop/src/net/sf/briar/plugins/file/WindowsRemovableDriveFinder.java @@ -23,7 +23,7 @@ class WindowsRemovableDriveFinder implements RemovableDriveFinder { int type = Kernel32.INSTANCE.GetDriveType(root.getPath()); if(type == DRIVE_REMOVABLE) drives.add(root); } catch(RuntimeException e) { - throw new IOException(e.toString()); + throw new IOException(e); } } return Collections.unmodifiableList(drives); diff --git a/briar-desktop/src/net/sf/briar/plugins/modem/SerialPortImpl.java b/briar-desktop/src/net/sf/briar/plugins/modem/SerialPortImpl.java index 71761e04933a92124c7c1412783800a93fe9b1c8..b800c9c4ac8cd7f72cd1eda9d56d0e553ba3ba0c 100644 --- a/briar-desktop/src/net/sf/briar/plugins/modem/SerialPortImpl.java +++ b/briar-desktop/src/net/sf/briar/plugins/modem/SerialPortImpl.java @@ -17,7 +17,7 @@ class SerialPortImpl implements SerialPort { try { if(!port.openPort()) throw new IOException("Failed to open port"); } catch(SerialPortException e) { - throw new IOException(e.toString()); + throw new IOException(e); } } @@ -25,7 +25,7 @@ class SerialPortImpl implements SerialPort { try { if(!port.closePort()) throw new IOException("Failed to close port"); } catch(SerialPortException e) { - throw new IOException(e.toString()); + throw new IOException(e); } } @@ -34,7 +34,7 @@ class SerialPortImpl implements SerialPort { try { return port.setParams(baudRate, dataBits, stopBits, parityBits); } catch(SerialPortException e) { - throw new IOException(e.toString()); + throw new IOException(e); } } @@ -43,7 +43,7 @@ class SerialPortImpl implements SerialPort { if(!port.purgePort(flags)) throw new IOException("Failed to purge port"); } catch(SerialPortException e) { - throw new IOException(e.toString()); + throw new IOException(e); } } @@ -51,7 +51,7 @@ class SerialPortImpl implements SerialPort { try { port.addEventListener(l); } catch(SerialPortException e) { - throw new IOException(e.toString()); + throw new IOException(e); } } @@ -59,7 +59,7 @@ class SerialPortImpl implements SerialPort { try { return port.readBytes(); } catch(SerialPortException e) { - throw new IOException(e.toString()); + throw new IOException(e); } } @@ -67,7 +67,7 @@ class SerialPortImpl implements SerialPort { try { if(!port.writeBytes(b)) throw new IOException("Failed to write"); } catch(SerialPortException e) { - throw new IOException(e.toString()); + throw new IOException(e); } } } diff --git a/briar-tests/.classpath b/briar-tests/.classpath index e82f042591dc56c1962903c525c715e910cd00ca..8905224944fdbb1e3d566e87a215fc23148793ec 100644 --- a/briar-tests/.classpath +++ b/briar-tests/.classpath @@ -5,7 +5,6 @@ <classpathentry combineaccessrules="false" kind="src" path="/briar-core"/> <classpathentry combineaccessrules="false" kind="src" path="/briar-desktop"/> <classpathentry kind="lib" path="/briar-api/libs/guice-3.0-no_aop.jar"/> - <classpathentry kind="lib" path="/briar-desktop/libs/commons-io-2.0.1.jar"/> <classpathentry kind="lib" path="/briar-desktop/libs/jnotify-0.93.jar"/> <classpathentry kind="lib" path="/briar-desktop/libs/jssc-0.9-briar.jar" sourcepath="/briar-desktop/libs/source/jssc-0.9-briar-source.jar"/> <classpathentry kind="lib" path="libs/hamcrest-core-1.1.jar"/> diff --git a/briar-tests/src/net/sf/briar/TestFileUtils.java b/briar-tests/src/net/sf/briar/TestFileUtils.java index 3e0d12f7696c8c99fa7ed454426e72bb25a29318..ca4828f91482c2fe732a211b62f4f799d0977486 100644 --- a/briar-tests/src/net/sf/briar/TestFileUtils.java +++ b/briar-tests/src/net/sf/briar/TestFileUtils.java @@ -5,11 +5,9 @@ import java.io.IOException; import net.sf.briar.api.os.FileUtils; -import org.apache.commons.io.FileSystemUtils; - public class TestFileUtils implements FileUtils { public long getFreeSpace(File f) throws IOException { - return FileSystemUtils.freeSpaceKb(f.getAbsolutePath()) * 1024; + return f.getFreeSpace(); } } diff --git a/briar-tests/src/net/sf/briar/db/DatabaseComponentTest.java b/briar-tests/src/net/sf/briar/db/DatabaseComponentTest.java index a35816527eff1cfe379c9f40d6d28f1d7fdd754f..6fcac549350c78daff2a1e4b2e1cc5185540a3e9 100644 --- a/briar-tests/src/net/sf/briar/db/DatabaseComponentTest.java +++ b/briar-tests/src/net/sf/briar/db/DatabaseComponentTest.java @@ -674,8 +674,7 @@ public abstract class DatabaseComponentTest extends BriarTestCase { final byte[] raw1 = new byte[size]; final Collection<MessageId> sendable = Arrays.asList(messageId, messageId1); - final Collection<byte[]> messages = - Arrays.asList(new byte[][] {raw, raw1}); + final Collection<byte[]> messages = Arrays.asList(raw, raw1); final Map<MessageId, Integer> sent = new HashMap<MessageId, Integer>(); sent.put(messageId, 1); sent.put(messageId1, 2); diff --git a/briar-tests/src/net/sf/briar/db/H2DatabaseTest.java b/briar-tests/src/net/sf/briar/db/H2DatabaseTest.java index 9419d6f7a5d895fd1115b351c406720ef98d1ebf..9f638e7696e178ee02ecd13093d694981dfbdd2b 100644 --- a/briar-tests/src/net/sf/briar/db/H2DatabaseTest.java +++ b/briar-tests/src/net/sf/briar/db/H2DatabaseTest.java @@ -42,7 +42,6 @@ import net.sf.briar.api.messaging.MessageId; import net.sf.briar.api.transport.Endpoint; import net.sf.briar.api.transport.TemporarySecret; -import org.apache.commons.io.FileSystemUtils; import org.junit.After; import org.junit.Before; import org.junit.Test; @@ -545,8 +544,7 @@ public class H2DatabaseTest extends BriarTestCase { Database<Connection> db = open(false); // Sanity check: there should be enough space on disk for this test - String path = testDir.getAbsolutePath(); - assertTrue(FileSystemUtils.freeSpaceKb(path) * 1024 > MAX_SIZE); + assertTrue(testDir.getFreeSpace() > MAX_SIZE); // The free space should not be more than the allowed maximum size long free = db.getFreeSpace();