Reverted some changes that were made for Java 1.5 compatibility.

Removed Commons IO, which we were only using as a replacement for
File.getFreeSpace() on desktop plaftorms.

Note: The Huawei U8210 (Android 2.1) doesn't have all the Java 1.6
standard library methods, and crashes if they're called. Specifically,
String.isEmpty() and NetworkInterface.supportsMulticast() are missing,
so the changes removing those methods were not reverted.
This commit is contained in:
akwizgran
2013-11-22 12:49:20 +00:00
parent 3b5769cf8a
commit 26eebee8d9
11 changed files with 30 additions and 35 deletions

View File

@@ -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();
}
}

View File

@@ -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) {

View File

@@ -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"/>

View File

@@ -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();
}
}

View File

@@ -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);

View File

@@ -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);
}
}
}

View File

@@ -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"/>

View File

@@ -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();
}
}

View File

@@ -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);

View File

@@ -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();