diff --git a/.classpath b/.classpath index 2ed9bb6ee03d54c507ff19daa62b1c761d8cb246..88eeadcf43f812a49b0ae25475b3f8da61e329ff 100644 --- a/.classpath +++ b/.classpath @@ -15,5 +15,6 @@ <classpathentry kind="lib" path="lib/test/hamcrest-core-1.1.jar"/> <classpathentry kind="lib" path="lib/test/hamcrest-library-1.1.jar"/> <classpathentry kind="lib" path="lib/test/jmock-2.5.1.jar"/> + <classpathentry kind="lib" path="lib/commons-io-2.0.1.jar"/> <classpathentry kind="output" path="bin"/> </classpath> diff --git a/components/net/sf/briar/db/H2Database.java b/components/net/sf/briar/db/H2Database.java index 34e6647a2088b5ece6c7058455abae7f40759895..82df78d049b245ec38531c9345cf282f0232cbe5 100644 --- a/components/net/sf/briar/db/H2Database.java +++ b/components/net/sf/briar/db/H2Database.java @@ -1,6 +1,7 @@ package net.sf.briar.db; import java.io.File; +import java.io.IOException; import java.sql.Connection; import java.sql.DriverManager; import java.sql.SQLException; @@ -13,6 +14,8 @@ import net.sf.briar.api.crypto.Password; import net.sf.briar.api.db.DatabasePassword; import net.sf.briar.api.db.DbException; +import org.apache.commons.io.FileSystemUtils; + import com.google.inject.Inject; /** Contains all the H2-specific code for the database. */ @@ -50,13 +53,17 @@ class H2Database extends JdbcDatabase { } public long getFreeSpace() throws DbException { - File dir = home.getParentFile(); - long free = dir.getFreeSpace(); - long used = getDiskSpace(dir); - long quota = maxSize - used; - long min = Math.min(free, quota); - if(LOG.isLoggable(Level.FINE)) LOG.fine("Free space: " + min); - return min; + try { + File dir = home.getParentFile(); + long free = FileSystemUtils.freeSpaceKb(dir.getAbsolutePath()); + long used = getDiskSpace(dir); + long quota = maxSize - used; + long min = Math.min(free, quota); + if(LOG.isLoggable(Level.FINE)) LOG.fine("Free space: " + min); + return min; + } catch(IOException e) { + throw new DbException(e); + } } @Override diff --git a/components/net/sf/briar/db/JdbcDatabase.java b/components/net/sf/briar/db/JdbcDatabase.java index 4e648b351874d3c1355a1f7230b8ce72d7cdbc05..44ba21db345d0e6cd2b54fa7312cb3be5853a5fc 100644 --- a/components/net/sf/briar/db/JdbcDatabase.java +++ b/components/net/sf/briar/db/JdbcDatabase.java @@ -442,7 +442,8 @@ abstract class JdbcDatabase implements Database<Connection> { ps.setBytes(4, m.getAuthor().getBytes()); ps.setLong(5, m.getTimestamp()); ps.setInt(6, m.getSize()); - ps.setBlob(7, new ByteArrayInputStream(m.getBytes())); + byte[] raw = m.getBytes(); + ps.setBinaryStream(7, new ByteArrayInputStream(raw), raw.length); ps.setInt(8, 0); int rowsAffected = ps.executeUpdate(); assert rowsAffected == 1; diff --git a/components/net/sf/briar/invitation/InvitationWorker.java b/components/net/sf/briar/invitation/InvitationWorker.java index cfa03930aa9893d7fd91aefe0252d233a6a722f6..9b05d6329e053b062cccbc4f6aa8b24c896d2c3d 100644 --- a/components/net/sf/briar/invitation/InvitationWorker.java +++ b/components/net/sf/briar/invitation/InvitationWorker.java @@ -75,7 +75,7 @@ class InvitationWorker implements Runnable { try { transports = databaseComponent.getTransports(); } catch(DbException e) { - throw new IOException(e); + throw new IOException(e.getMessage()); } FileOutputStream out = new FileOutputStream(invitationDat); Writer w = writerFactory.createWriter(out); diff --git a/components/net/sf/briar/protocol/SigningDigestingInputStream.java b/components/net/sf/briar/protocol/SigningDigestingInputStream.java index d95768eff1125b1218f7b780e28925bbd978387c..a4871725f547f710f8f3862694a9fae489cb54b4 100644 --- a/components/net/sf/briar/protocol/SigningDigestingInputStream.java +++ b/components/net/sf/briar/protocol/SigningDigestingInputStream.java @@ -41,7 +41,7 @@ class SigningDigestingInputStream extends FilterInputStream { try { signature.update(b); } catch(SignatureException e) { - throw new IOException(e); + throw new IOException(e.getMessage()); } } if(digesting) messageDigest.update(b); @@ -52,7 +52,7 @@ class SigningDigestingInputStream extends FilterInputStream { try { signature.update(b, off, len); } catch(SignatureException e) { - throw new IOException(e); + throw new IOException(e.getMessage()); } } if(digesting) messageDigest.update(b, off, len); diff --git a/components/net/sf/briar/protocol/SigningDigestingOutputStream.java b/components/net/sf/briar/protocol/SigningDigestingOutputStream.java index 5b411c63b9469453e53c3d90d5d7ff2765ddfc6a..6d72dc905b8a49f95f0c7cdc0da6830c8a85491b 100644 --- a/components/net/sf/briar/protocol/SigningDigestingOutputStream.java +++ b/components/net/sf/briar/protocol/SigningDigestingOutputStream.java @@ -44,7 +44,7 @@ class SigningDigestingOutputStream extends FilterOutputStream { try { signature.update(b, off, len); } catch(SignatureException e) { - throw new IOException(e); + throw new IOException(e.getMessage()); } } if(digesting) messageDigest.update(b, off, len); @@ -57,7 +57,7 @@ class SigningDigestingOutputStream extends FilterOutputStream { try { signature.update((byte) b); } catch(SignatureException e) { - throw new IOException(e); + throw new IOException(e.getMessage()); } } if(digesting) messageDigest.update((byte) b);