mina-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Pavel Zdenek (JIRA)" <j...@apache.org>
Subject [jira] Commented: (DIRMINA-242) ByteBuffer.getString(ByteBuffer buf, int fieldSize, CharsetDecoder decoder, boolean stopOnZero )
Date Wed, 06 Sep 2006 06:57:23 GMT
    [ http://issues.apache.org/jira/browse/DIRMINA-242?page=comments#action_12432768 ] 
            
Pavel Zdenek commented on DIRMINA-242:
--------------------------------------

Let's stop talking about "string". I would name it "fixed buffer space allocated for the string".
The existing getString(...) pushes the buffer position only to the end of  "string".
I would like it to be pushed to the end of whole "fixed space", and on the way, reading the
valid string in it. But not stopping once the string is finished, if it is shorter than the
fixed space!

Maybe the extra parameter should not be stopOnZero, behaving like existing getString when
true.
For clarity, it probably should be named something like continueAfterZero, default false.


> ByteBuffer.getString(ByteBuffer buf, int fieldSize, CharsetDecoder decoder, boolean stopOnZero
)
> ------------------------------------------------------------------------------------------------
>
>                 Key: DIRMINA-242
>                 URL: http://issues.apache.org/jira/browse/DIRMINA-242
>             Project: Directory MINA
>          Issue Type: New Feature
>    Affects Versions: 0.8.2
>            Reporter: Pavel Zdenek
>            Priority: Trivial
>
> The method would read an ASCIIZ string off the buffer as the existing method without
added parameter.
> If stopOnZero is false, it would continue blindly reading the stream up to the required
fieldSize.
> So far MINA has no support for reading fixed (small) size strings. This is common for
protocols constructed at devices with limited resources (i.e. network attached microcontrollers)
and above the mandatory ending zero may be whatever garbage left from previous memory usage.
> My temporary implementation follows, to get the idea.
> It also solves the problem with getString behavior when reading ASCIIZ at the end of
buffer (apparently fixed in dev 0.9) 
>     public static String getString(ByteBuffer buf, int fieldSize, CharsetDecoder decoder,
boolean stopOnZero )
>     throws CharacterCodingException
>     {
>     	if( fieldSize == 0) fieldSize = buf.remaining(); // convenience "0 ~ till the end"
>     	int origLimit = buf.limit();
>     	int posStrEnd = 0;
>     	buf.mark(); // beginning of string
>     	boolean foundZero = false;
>         while(buf.hasRemaining() && (fieldSize-- > 0) )
>         {
>             if( (buf.get() == 0) && !foundZero ) 
>             {
>             	foundZero = true;
>             	posStrEnd = buf.position()-1;
>             	if( stopOnZero ) break;
>             }
>         }
>     	int reachedPos = buf.position(); // later must return here
>     	buf.reset(); // position to string begin
>         if(foundZero) buf.limit( posStrEnd ); 
>     	String str = buf.getString(decoder);
>     	if(foundZero) buf.limit(origLimit);
>     	buf.position(reachedPos);
>     	return str;
> }

-- 
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

        

Mime
View raw message