You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@mina.apache.org by "Niklas Therning (JIRA)" <ji...@apache.org> on 2006/09/13 21:53:23 UTC
[jira] Resolved: (DIRMINA-199) CumulativeProtocolDecoder javadoc
example
[ http://issues.apache.org/jira/browse/DIRMINA-199?page=all ]
Niklas Therning resolved DIRMINA-199.
-------------------------------------
Resolution: Fixed
I've updated the example in the javadoc to be more advanced as requested. Please let me know if you think it's a good example or if you find any bugs in it. Zohar, if it looks ok please close this issue.
Here's a copy of the example code:
public class CRLFTerminatedCommandLineDecoder
extends CumulativeProtocolDecoder {
private Command parseCommand(ByteBuffer in) {
// Convert the bytes in the specified buffer to a
// Command object.
...
}
protected boolean doDecode(IoSession session, ByteBuffer in,
ProtocolDecoderOutput out)
throws Exception {
// Remember the initial position.
int start = in.position();
// Now find the first CRLF in the buffer.
byte previous = 0;
while (in.hasRemaining()) {
byte current = in.get();
if (previous == '\r' && current == '\n') {
// Remember the current position and limit.
int position = in.position();
int limit = in.limit();
try {
in.position(start);
in.limit(position);
// The bytes between in.position() and in.limit()
// now contain a full CRLF terminated line.
out.write(parseCommand(in.slice()));
} finally {
// Set the position to point right after the
// detected line and set the limit to the old
// one.
in.position(position);
in.limit(limit);
}
// Decoded one line; CumulativeProtocolDecoder will
// call me again until I return false. So just
// return true until there are no more lines in the
// buffer.
return true;
}
previous = current;
}
// Could not find CRLF in the buffer. Reset the initial
// position to the one we recorded above.
in.position(start);
return false;
}
}
> CumulativeProtocolDecoder javadoc example
> -----------------------------------------
>
> Key: DIRMINA-199
> URL: http://issues.apache.org/jira/browse/DIRMINA-199
> Project: Directory MINA
> Issue Type: Bug
> Affects Versions: 0.9.2
> Reporter: Zohar Amir
> Assigned To: Niklas Therning
> Priority: Minor
> Fix For: 1.0
>
>
> I think that the example given in the CumulativeProtocolDecoder's javadoc is a bit too simplistic. I think the example should include some reading from the buffer, so that it can demonstrate the need to rewind it before returning 'false'.
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira