You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-dev@db.apache.org by "Knut Anders Hatlen (JIRA)" <ji...@apache.org> on 2007/07/13 14:26:04 UTC

[jira] Created: (DERBY-2936) Use java.nio.ByteBuffer for buffering in DDMWriter

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
            Priority: Minor


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.


[jira] Resolved: (DERBY-2936) Use java.nio.ByteBuffer for buffering in DDMWriter

Posted by "Knut Anders Hatlen (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/DERBY-2936?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Knut Anders Hatlen resolved DERBY-2936.
---------------------------------------

    Resolution: Fixed
    Derby Info:   (was: [Patch Available])

Committed derby-2936-4.diff with revision 569661.

> 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
>             Fix For: 10.4.0.0
>
>         Attachments: d2936-1.diff, derby-2936-2.diff, derby-2936-2.stat, derby-2936-3.diff, derby-2936-3.stat, derby-2936-4.diff
>
>
> 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.


[jira] Updated: (DERBY-2936) Use java.nio.ByteBuffer for buffering in DDMWriter

Posted by "Knut Anders Hatlen (JIRA)" <ji...@apache.org>.
     [ 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-3.stat
                derby-2936-3.diff

Attaching a partial patch (derby-2936-3) which removes some uses of the bytes field.

Description of the patch:
  * replaces all occurrences of bytes[xxx] with absolute buffer.get/put methods
  * replaces calls to Arrays.fill() + buffer.position() with calls to the existing padBytes() method
  * makes CcsidManager.convertFromUCS2() take a ByteBuffer instead of byte array + offset
  * removes the original writeBigDecimal() method and renames bigDecimalToPackedDecimalBytes() to writeBigDecimal()

Derbyall and suites.All ran cleanly (except a known, intermittent failure in ProcedureInTriggerTest).

> 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
>             Fix For: 10.4.0.0
>
>         Attachments: d2936-1.diff, derby-2936-2.diff, derby-2936-2.stat, derby-2936-3.diff, derby-2936-3.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.


[jira] Updated: (DERBY-2936) Use java.nio.ByteBuffer for buffering in DDMWriter

Posted by "Knut Anders Hatlen (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/DERBY-2936?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

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

    Derby Info:   (was: [Patch Available])

Committed revision 556583.

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


[jira] Assigned: (DERBY-2936) Use java.nio.ByteBuffer for buffering in DDMWriter

Posted by "Knut Anders Hatlen (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/DERBY-2936?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Knut Anders Hatlen reassigned DERBY-2936:
-----------------------------------------

    Assignee: Knut Anders Hatlen

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


[jira] Closed: (DERBY-2936) Use java.nio.ByteBuffer for buffering in DDMWriter

Posted by "Knut Anders Hatlen (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/DERBY-2936?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Knut Anders Hatlen closed DERBY-2936.
-------------------------------------


> 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
>             Fix For: 10.4.0.0
>
>         Attachments: d2936-1.diff, derby-2936-2.diff, derby-2936-2.stat, derby-2936-3.diff, derby-2936-3.stat, derby-2936-4.diff
>
>
> 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.


[jira] Commented: (DERBY-2936) Use java.nio.ByteBuffer for buffering in DDMWriter

Posted by "Knut Anders Hatlen (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/DERBY-2936?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12513001 ] 

Knut Anders Hatlen commented on DERBY-2936:
-------------------------------------------

Thanks for looking at the patch, Bryan!

Yes, the ByteBuffer methods do the masking and shifting automatically for us.

In the first diff, "(byte) (value & 0xff)" is actually identical to "(byte) value" since & 0xff masks away all but the eight least significant bits and the cast to byte only looks at the eight least significant bits, which were not affected by the mask, so the masking was not required in the first place.

In the second diff, the original code manually encoded an int as a two-byte big-endian byte sequence (and I think the same argument about masking goes for this code). ByteBuffer can read/write both big-endian byte order and little-endian byte order; the default is big-endian. So if you pass in an int consisting of the following bits: xxxxxxxxyyyyyyyyzzzzzzzzwwwwwwww, the old code would do

  1. right shift (without preserving sign bit) so that the int becomes 00000000xxxxxxxxyyyyyyyyzzzzzzzz
  2. mask away three most significant bytes from (1), which gives this int: 000000000000000000000000zzzzzzzz
  3. store the eight least significant bits (zzzzzzzz) in bytes[offset]
  4. mask away the 3 most significant bytes from the original int: 0000000000000000000000000wwwwwwww
  5. store the least significant byte of (4) in bytes[offset+1]: wwwwwwww

The new code does this:

  1. cast original int to short, discarding the two most significant bytes. Bit pattern for the short: zzzzzzzzwwwwwwww
  2. store the short in two bytes, big-endian byte order, that is
        - first byte: zzzzzzzz
        - second byte: wwwwwwww

Note that it's the bit patterns of the ints/shorts/bytes that are interesting, not the actual values of the bytes. So it's perfectly fine to encode a positive int as two negative byte values.

If we decode the values with a ByteBuffer (that would be in DDMReader) we might have to do some masking, depending on whether we see them as signed or unsigned shorts. Since a Java short is signed, the code for reading an unsigned short from a byte buffer would look like this:

  int ushort = 0xffff & buffer.getShort();

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


[jira] Commented: (DERBY-2936) Use java.nio.ByteBuffer for buffering in DDMWriter

Posted by "Bryan Pendleton (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/DERBY-2936?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12512954 ] 

Bryan Pendleton commented on DERBY-2936:
----------------------------------------

I noticed the patch has changes such as this:

 		ensureLength (1);
-		bytes[offset++] = (byte) (value & 0xff);
+		buffer.put((byte) value);
 	}
 
 
@@ -485,9 +496,7 @@
 	protected void writeNetworkShort (int value)
 	{
 		ensureLength (2);
-		bytes[offset] = (byte) ((value >>> 8) & 0xff);
-		bytes[offset + 1] = (byte) (value & 0xff);
-		offset += 2;
+		buffer.putShort((short) value);

The new code is certainly simpler and clearer, which is great!

But why is it that we no longer need to do the masking and shifting?

Is this something that the ByteBuffer methods do for us automatically?


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


[jira] Updated: (DERBY-2936) Use java.nio.ByteBuffer for buffering in DDMWriter

Posted by "Knut Anders Hatlen (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/DERBY-2936?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

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

    Derby Info: [Patch Available]

> 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
>             Fix For: 10.4.0.0
>
>         Attachments: d2936-1.diff, derby-2936-2.diff, derby-2936-2.stat, derby-2936-3.diff, derby-2936-3.stat, derby-2936-4.diff
>
>
> 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.


[jira] Updated: (DERBY-2936) Use java.nio.ByteBuffer for buffering in DDMWriter

Posted by "Knut Anders Hatlen (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/DERBY-2936?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

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

    Derby Info: [Patch Available]

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


[jira] Updated: (DERBY-2936) Use java.nio.ByteBuffer for buffering in DDMWriter

Posted by "Knut Anders Hatlen (JIRA)" <ji...@apache.org>.
     [ 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.


[jira] Updated: (DERBY-2936) Use java.nio.ByteBuffer for buffering in DDMWriter

Posted by "Knut Anders Hatlen (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/DERBY-2936?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

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

    Attachment: d2936-1.diff

Attaching a patch which adds a ByteBuffer field which wraps the byte array (the byte array is still a field). Also removed the offset variable, since the byte buffer maintains a position variable. DDMWriter now uses ByteBuffer's utility methods for encoding primitive types, but it still uses String.getBytes() to encode strings. I plan to change the string encoding methods later.

The patch also fixes a bug where writeBigDecimal() called ensureLength() with offset+length as argument, instead of length as it should. Derbyall and suites.All ran cleanly with the patch.

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


[jira] Updated: (DERBY-2936) Use java.nio.ByteBuffer for buffering in DDMWriter

Posted by "Knut Anders Hatlen (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/DERBY-2936?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

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

    Derby Info: [Patch Available]

> 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
>             Fix For: 10.4.0.0
>
>         Attachments: d2936-1.diff, derby-2936-2.diff, derby-2936-2.stat, derby-2936-3.diff, derby-2936-3.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.


[jira] Updated: (DERBY-2936) Use java.nio.ByteBuffer for buffering in DDMWriter

Posted by "Knut Anders Hatlen (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/DERBY-2936?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

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

    Derby Info:   (was: [Patch Available])

Committed revision 568039.

> 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
>             Fix For: 10.4.0.0
>
>         Attachments: d2936-1.diff, derby-2936-2.diff, derby-2936-2.stat, derby-2936-3.diff, derby-2936-3.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.


[jira] Reopened: (DERBY-2936) Use java.nio.ByteBuffer for buffering in DDMWriter

Posted by "Knut Anders Hatlen (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/DERBY-2936?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Knut Anders Hatlen reopened DERBY-2936:
---------------------------------------


I agree, the bytes field should be removed. Reopening the issue to fix it.

> 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
>             Fix For: 10.4.0.0
>
>         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.


[jira] Commented: (DERBY-2936) Use java.nio.ByteBuffer for buffering in DDMWriter

Posted by "Daniel John Debrunner (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/DERBY-2936?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12515029 ] 

Daniel John Debrunner commented on DERBY-2936:
----------------------------------------------

In DDMWriter is there a good reason to keep the byte[] bytes field?

It's basically a bug waiting to happen, for bytes and buffer to get out of sync. I had to waste time going through the code to ensure that they currently are kept in sync.

Why not just use buffer.array() anytime direct access to the array is required. Then it's clearly visible in the method that they will be in sync.


> 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
>             Fix For: 10.4.0.0
>
>         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.


[jira] Updated: (DERBY-2936) Use java.nio.ByteBuffer for buffering in DDMWriter

Posted by "Knut Anders Hatlen (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/DERBY-2936?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

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

    Derby Info: [Patch Available]

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


[jira] Updated: (DERBY-2936) Use java.nio.ByteBuffer for buffering in DDMWriter

Posted by "Knut Anders Hatlen (JIRA)" <ji...@apache.org>.
     [ 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-4.diff

Attaching a patch (derby-2936-4) which removes the DDMWriter.bytes field entirely. This patch
  - removes the field "bytes"
  - updates comments which contain references to the old field
  - makes endDdm() use ByteBuffer.put(byte[],int,int) instead of System.arraycopy()
  - makes writeScalarStream() use buffer.array() instead of the old field
  - removes unused variables and narrows the scope of others in writeScalarStream()

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
>             Fix For: 10.4.0.0
>
>         Attachments: d2936-1.diff, derby-2936-2.diff, derby-2936-2.stat, derby-2936-3.diff, derby-2936-3.stat, derby-2936-4.diff
>
>
> 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.


[jira] Resolved: (DERBY-2936) Use java.nio.ByteBuffer for buffering in DDMWriter

Posted by "Knut Anders Hatlen (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/DERBY-2936?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Knut Anders Hatlen resolved DERBY-2936.
---------------------------------------

       Resolution: Fixed
    Fix Version/s: 10.4.0.0
       Derby Info:   (was: [Patch Available])

Committed revision 557506.

> 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
>             Fix For: 10.4.0.0
>
>         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.