Skip to content
Snippets Groups Projects
Verified Commit 1ee7feca authored by bontric's avatar bontric Committed by Julian Dehm
Browse files

Remove deprecated sync session readers/writers

parent d1c66b5b
No related branches found
No related tags found
No related merge requests found
package org.briarproject.bramble.mailbox;
import org.briarproject.bramble.api.plugin.TransportConnectionReader;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
class MailboxSyncConnectionReader implements TransportConnectionReader {
private final ByteArrayInputStream bIS;
public MailboxSyncConnectionReader(byte[] encryptedSyncStream) {
bIS = new ByteArrayInputStream(encryptedSyncStream);
}
@Override
public InputStream getInputStream() {
return bIS;
}
@Override
public void dispose(boolean exception, boolean recognised)
throws IOException {
bIS.close();
}
}
package org.briarproject.bramble.mailbox;
import org.briarproject.bramble.api.contact.ContactId;
import org.briarproject.bramble.api.mailbox.MailboxConstants;
import org.briarproject.bramble.api.plugin.TransportConnectionWriter;
import org.briarproject.bramble.mailbox.protocol.MailboxProtocol;
import org.briarproject.bramble.mailbox.protocol.MailboxRequestStore;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
public class MailboxSyncConnectionWriter implements TransportConnectionWriter {
private ByteArrayOutputStream bufferOS = new ByteArrayOutputStream();
private MailboxProtocol mailboxProtocol;
private ContactId contactId;
public MailboxSyncConnectionWriter(MailboxProtocol mailboxProtocol,
ContactId contactId) {
this.mailboxProtocol = mailboxProtocol;
this.contactId = contactId;
}
@Override
public int getMaxLatency() {
return MailboxConstants.MAX_MAILBOX_LATENCY;
}
@Override
public int getMaxIdleTime() {
return MailboxConstants.MAX_IDLE_TIME;
}
@Override
public OutputStream getOutputStream() {
return bufferOS;
}
@Override
public void dispose(boolean exception) throws IOException {
if (exception == true) return;
MailboxRequestStore message =
new MailboxRequestStore(contactId, bufferOS.toByteArray());
try {
mailboxProtocol.writeRequest(message);
message.awaitResponse();
} catch (InterruptedException e) {
throw new IOException("MailboxMessage delivery failed");
}
if (!message.wasSuccessfull()) {
throw new IOException(message.getResponseError());
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment