diff --git a/briar-android/src/net/sf/briar/android/AndroidFileUtils.java b/briar-android/src/net/sf/briar/android/AndroidFileUtils.java index d2ca8a92c..8f080686c 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 1f42a60b2..e76825295 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 797700089..9c8a71767 100644 --- a/briar-desktop/.classpath +++ b/briar-desktop/.classpath @@ -6,7 +6,6 @@ - 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 5b64b7d6c..000000000 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 fc796dcf6..a86824272 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 4b3b408d2..47e425b47 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 71761e049..b800c9c4a 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 e82f04259..890522494 100644 --- a/briar-tests/.classpath +++ b/briar-tests/.classpath @@ -5,7 +5,6 @@ - diff --git a/briar-tests/src/net/sf/briar/TestFileUtils.java b/briar-tests/src/net/sf/briar/TestFileUtils.java index 3e0d12f76..ca4828f91 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 a35816527..6fcac5493 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 sendable = Arrays.asList(messageId, messageId1); - final Collection messages = - Arrays.asList(new byte[][] {raw, raw1}); + final Collection messages = Arrays.asList(raw, raw1); final Map sent = new HashMap(); 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 9419d6f7a..9f638e769 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 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();