Issue2169

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

Created on 2014-06-18.23:44:39 by zyasoft, last changed 2016-01-11.04:15:06 by zyasoft.

Messages
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 http://docs.oracle.com/javase/7/docs/api/java/nio/ByteBuffer.html#wrap(byte[],%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
History
Date User Action Args
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