[ 
https://issues.apache.org/jira/browse/DERBY-2936?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Knut Anders Hatlen updated DERBY-2936:
--------------------------------------

    Attachment: derby-2936-2.stat
                derby-2936-2.diff

Attaching a patch which removes the use of String.getBytes(String) in 
DDMWriter. It does the following:

  1) Removes an unused constructor and an unused writeString() method so that 
they don't have to be updated with duplicated and unused code.
  2) Adds a CharsetEncoder object for the default encoding to the DDMWriters. 
(I made the encoder replace unmappable characters with the default replacement 
character. It is undefined what String.getBytes(String) does with such 
characters, so this might or might not match the old behaviour depending on the 
JVM, but the new implementation will at least have a clearly defined behaviour 
across different JVMs.)
  3) Changes writeString() and writeLDString() so that they encode the strings 
directly into the output buffer (using the CharsetEncoder object) instead of 
encoding it into a new temporary byte array before copying it to the output 
buffer.
  4) Removes constants and helper methods used for truncating the byte sequence 
on a character boundary in writeLDString() since CharsetEncoder automatically 
truncates it correctly.

Derbyall and suites.All ran cleanly.

> Use java.nio.ByteBuffer for buffering in DDMWriter
> --------------------------------------------------
>
>                 Key: DERBY-2936
>                 URL: https://issues.apache.org/jira/browse/DERBY-2936
>             Project: Derby
>          Issue Type: Improvement
>          Components: Network Server
>            Reporter: Knut Anders Hatlen
>            Assignee: Knut Anders Hatlen
>            Priority: Minor
>         Attachments: d2936-1.diff, derby-2936-2.diff, derby-2936-2.stat
>
>
> org.apache.derby.impl.drda.DDMWriter uses a byte array as a buffer. Wrapping 
> the array in a java.nio.ByteBuffer has some advantages, for instance:
>   - utility methods for encoding primitive types into the byte array could be 
> used instead of manually encoding the values
>   - it allows us to encode strings directly into the buffer (using a 
> CharsetEncoder) without doing an expensive String.getBytes(String encoding) 
> in an intermediate step
> By using a utility class, the code becomes easier to maintain. Also, 
> ByteBuffer allows us to access the backing byte array without going through 
> the ByteBuffer interface, so we still have the possibility to modify the byte 
> array directly in cases where that's more convenient.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to