Message10545

Author zyasoft
Recipients lsenta, zyasoft
Date 2015-12-17.16:16:16
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1450368977.83.0.662683267901.issue2444@psf.upfronthosting.co.za>
In-reply-to
Content
Most likely the problem with Bytes.toString(byte[]) is caused by #1002, since Bytes.toInt(byte[]), Bytes.toHex(byte[]), etc, works:

>>> import array
>>> qualifier = array.array('b', [98, 121, 116, 101, 45, 115, 105, 122, 101])
>>> qualifier
array('b', [98, 121, 116, 101, 45, 115, 105, 122, 101])
>>> Bytes.toHex(qualifier)
u'627974652d73697a65'

which we can verify

>>> [hex(b) for b in qualifier]
['0x62', '0x79', '0x74', '0x65', '0x2d', '0x73', '0x69', '0x7a', '0x65']

Workaround for now:

>>> qualifier.tostring() # note case!
'byte-size'

re choice of the overloading for Bytes.toBytes(java.lang.String) vs Bytes.toBytes(char), I don't think this works if both overloads are available. Perhaps we should make that possible, but that seems like a possible breaking change. So the docs on the wiki should be updated.

However, you can control the specific overloaded method that is selected like so:

>>> from java.lang import Short
>>> Bytes.toBytes(Short(ord("v")))
array('b', [0, 118])

You could also do this, but in this specific library there is no overloading for Character. Nor is there an implicit conversion to short in Jython, although that would be problematic given that char is unsigned and short is signed.

>>> from java.lang import Character
>>> Bytes.toBytes(Character("v"))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: toBytes(): 1st arg can't be coerced to boolean, long, int, double, short, java.nio.ByteBuffer, float, java.math.BigDecimal, String
History
Date User Action Args
2015-12-17 16:16:17zyasoftsetmessageid: <1450368977.83.0.662683267901.issue2444@psf.upfronthosting.co.za>
2015-12-17 16:16:17zyasoftsetrecipients: + zyasoft, lsenta
2015-12-17 16:16:17zyasoftlinkissue2444 messages
2015-12-17 16:16:16zyasoftcreate