[ 
https://issues.apache.org/jira/browse/JENA-347?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13499478#comment-13499478
 ] 

Andy Seaborne commented on JENA-347:
------------------------------------

I'm afraid that your code makes an unwarranted assumption.

A ByterBuffer has a limit that indicates which part is in-use and which part 
isn't.  This is lost when you do buffer.array -- the backing array is all the 
space of the buffer (caution - it may also throw UnsupportedOperationException).

When you do ByteBuffer.wrap, the limit is set to the maximum -- and that 
includes bytes outside space used to encoded the URI.  maxSize is an upper 
bound and is done without inspecting the node other than it's type.

The use of str.trim is removing nulls caused by the inclusion of null bytes.

Try this:

      val bytesUsed = buffer.limit()
      val encodedInArray = buffer.array
      val bb = ByteBuffer.wrap( encodedInArray )
      bb.limit(bytesUsed)
      bb.position(0)
      val decodedFromArray = n.decode( bb, null )

                
> NodecSSE decode problem
> -----------------------
>
>                 Key: JENA-347
>                 URL: https://issues.apache.org/jira/browse/JENA-347
>             Project: Apache Jena
>          Issue Type: Bug
>          Components: TDB
>    Affects Versions: TDB 0.9.1, TDB 0.9.4
>         Environment: Confirmed in Scala 2.9.2 REPL
>            Reporter: Svatopluk Šperka
>            Priority: Minor
>         Attachments: NodecSSEProof.scala
>
>
> Decode method of NodecSSE should be the inverse function of encode but it's 
> not. In case of URI, decode create NodeURI from the string obtained from the 
> whole ByteBuffer passed to decode. This results in URL that is not equal to 
> the original URI (it's longer as it contains nonsensical suffix). I've 
> temporarily fixed that by trimming the decoded string before creating URI:
> if ( str.startsWith("<") )
>         {
>             // Do directly.
>             // (is it quicker?)
>             str = str.trim(); // !!!!!!!!!!! this line inserted
>             str = str.substring(1,str.length()-1) ;
>             str = StrUtils.unescapeString(str) ;
>             str = StrUtils.decodeHex(str, MarkerChar) ;
>             return Node.createURI(str) ;
>         }
> I'm using NodecSSE to encode Nodes in order to transfer them through network.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

Reply via email to