Separated MessageHeader interface from Message interface.

This commit is contained in:
akwizgran
2011-10-21 18:42:27 +01:00
parent f2d80825bc
commit ef61eaa804
9 changed files with 69 additions and 44 deletions

View File

@@ -236,7 +236,7 @@ DatabaseCleaner.Callback {
if(sendability > 0) updateAncestorSendability(txn, id, true);
// Count the bytes stored
synchronized(spaceLock) {
bytesStoredSinceLastCheck += m.getSize();
bytesStoredSinceLastCheck += m.getLength();
}
}
return stored;
@@ -344,7 +344,7 @@ DatabaseCleaner.Callback {
else db.setStatus(txn, c, id, Status.NEW);
// Count the bytes stored
synchronized(spaceLock) {
bytesStoredSinceLastCheck += m.getSize();
bytesStoredSinceLastCheck += m.getLength();
}
return true;
}

View File

@@ -1,6 +1,5 @@
package net.sf.briar.db;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
import java.sql.Connection;
@@ -549,9 +548,9 @@ abstract class JdbcDatabase implements Database<Connection> {
if(m.getAuthor() == null) ps.setNull(4, Types.BINARY);
else ps.setBytes(4, m.getAuthor().getBytes());
ps.setLong(5, m.getTimestamp());
ps.setInt(6, m.getSize());
byte[] raw = m.getBytes();
ps.setBinaryStream(7, new ByteArrayInputStream(raw), raw.length);
int length = m.getLength();
ps.setInt(6, length);
ps.setBinaryStream(7, m.getSerialisedStream(), length);
int affected = ps.executeUpdate();
if(affected != 1) throw new DbStateException();
ps.close();
@@ -635,9 +634,9 @@ abstract class JdbcDatabase implements Database<Connection> {
if(m.getParent() == null) ps.setNull(2, Types.BINARY);
else ps.setBytes(2, m.getParent().getBytes());
ps.setLong(3, m.getTimestamp());
ps.setInt(4, m.getSize());
byte[] raw = m.getBytes();
ps.setBinaryStream(5, new ByteArrayInputStream(raw), raw.length);
int length = m.getLength();
ps.setInt(4, length);
ps.setBinaryStream(5, m.getSerialisedStream(), length);
ps.setInt(6, c.getInt());
int affected = ps.executeUpdate();
if(affected != 1) throw new DbStateException();

View File

@@ -1,5 +1,8 @@
package net.sf.briar.protocol;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import net.sf.briar.api.protocol.AuthorId;
import net.sf.briar.api.protocol.GroupId;
import net.sf.briar.api.protocol.Message;
@@ -50,14 +53,18 @@ class MessageImpl implements Message {
return timestamp;
}
public int getSize() {
public int getLength() {
return raw.length;
}
public byte[] getBytes() {
public byte[] getSerialisedBytes() {
return raw;
}
public InputStream getSerialisedStream() {
return new ByteArrayInputStream(raw);
}
@Override
public boolean equals(Object o) {
return o instanceof Message && id.equals(((Message) o).getId());