Title: buffer/memoryview objects should be valid arguments for Java methods taking byte[] parameters
Type: Severity: normal
Components: Versions: Jython 2.7
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: jeff.allen, pdina, zyasoft
Priority: low Keywords:

Created on 2014-06-18.23:44:39 by zyasoft, last changed 2018-03-23.20:04:41 by jeff.allen.

msg8685 (view) Author: Jim Baker (zyasoft) Date: 2014-06-18.23:44:38
>>> from java.nio import ByteBuffer
>>> x = memoryview("foobar")
>>> ByteBuffer.wrap(x)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: wrap(): 1st arg can't be coerced to byte[]

This is also true of buffer.

The underlying problem appears to be a lack of a __tojava__ method in PyMemoryView/Py2KBuffer that will return the desired byte[] object. For contiguous/complete arrays, this should not require a copy.

It would be interesting if we could somehow support a method like[],%20int,%20int), which is a very common pattern in Java, but this seems difficult :)
msg9077 (view) Author: Jim Baker (zyasoft) Date: 2014-10-05.16:56:10
Deferring to 2.7.1 or later
msg10619 (view) Author: Jim Baker (zyasoft) Date: 2016-01-11.04:14:43
Easy fix for 2.7.2
msg10620 (view) Author: Jim Baker (zyasoft) Date: 2016-01-11.04:15:06
Also this is a good starter bug for someone interested in looking at core work
msg11849 (view) Author: Jeff Allen (jeff.allen) Date: 2018-03-23.20:04:41
Not that easy. What should this do?

m = memoryview(bytearray("foobar"))
Date User Action Args
2018-03-23 20:04:41jeff.allensetnosy: + jeff.allen
messages: + msg11849
milestone: Jython 2.7.2 ->
2016-01-11 04:15:06zyasoftsetmessages: + msg10620
2016-01-11 04:14:43zyasoftsetmessages: + msg10619
milestone: Jython 2.7.2
2014-10-05 16:56:10zyasoftsetpriority: low
messages: + msg9077
2014-09-01 15:54:06pdinasetnosy: + pdina
2014-06-18 23:44:39zyasoftcreate