Skip to content
Snippets Groups Projects
Commit dafb4a45 authored by bontric's avatar bontric
Browse files

Add readTag function to AbstractMailboxSession

parent 98ad421a
No related branches found
No related tags found
No related merge requests found
...@@ -247,4 +247,35 @@ public abstract class AbstractMailboxSession implements Runnable { ...@@ -247,4 +247,35 @@ public abstract class AbstractMailboxSession implements Runnable {
return os.toByteArray(); return os.toByteArray();
} }
/**
* Reads a Tag from the given InputStream and returns the matching StreamContext
* if available
*
* @param in InputStream to read the tag from
* @return StreamContext matching the tag read from the InputStream
* @throws IOException
* @throws DbException
*/
@Nullable
protected StreamContext readTag(InputStream in)
throws IOException, DbException {
byte[] tag = new byte[TAG_LENGTH];
// read tag from input stream
int offset = 0;
while (offset < tag.length) {
int read = in.read(tag, offset, tag.length - offset);
if (read == -1) throw new EOFException();
offset += read;
}
StreamContext ctx =
keyManager.getStreamContext(MailboxConstants.ID, tag);
if (ctx == null)
throw new IOException(
"Received stream with unrecognisable tag");
return ctx;
}
} }
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