int count = 1;
String line, fromLine = null;
ByteArrayOutputStream buf = null;
// notify listeners
StatusEvent event;
event = new StatusEvent(mstore, StatusEvent.OPERATION_START, "open");
mstore.processStatusEvent(event);
for( line = in.readLine(); line != null; line = in.readLine())
{
if( line.indexOf(FROM) == 0)
{
if( buf != null)
{
byte[] bytes = buf.toByteArray();
ByteArrayInputStream bin = new ByteArrayInputStream(bytes);
MboxMessage m = new MboxMessage(this, fromLine, bin, count++);
acc.add(m);
event = new StatusEvent(mstore, StatusEvent.OPERATION_UPDATE, "open", 1, StatusEvent.UNKNOWN,
count - 1);
mstore.processStatusEvent(event);
}
fromLine = line;
buf = new ByteArrayOutputStream();
}
else if( buf != null)
{
byte[] bytes = decodeFrom(line).getBytes();
buf.write(bytes, 0, bytes.length);
buf.write(10); // LF
}
}
if( buf != null)
{
byte[] bytes = buf.toByteArray();
ByteArrayInputStream bin = new ByteArrayInputStream(bytes);
MboxMessage m = new MboxMessage(this, fromLine, bin, count++);
acc.add(m);
event = new StatusEvent(mstore, StatusEvent.OPERATION_UPDATE, "open", 1, StatusEvent.UNKNOWN, count - 1);
mstore.processStatusEvent(event);
}
this.messages = new MboxMessage[acc.size()];
acc.toArray(this.messages);
buf = null;
acc = null;
event = new StatusEvent(mstore, StatusEvent.OPERATION_END, "open");
mstore.processStatusEvent(event);
// OK
this.open = true;
notifyConnectionListeners(ConnectionEvent.OPENED);