Skip to content

Commit 91edde8

Browse files
committed
Avoid using bytearray for JavaByteArray
Bytes in Java are between -128 and 127 whereas Python bytearray excepts values between 0 and 255. See #16 for references.
1 parent 0d8bba7 commit 91edde8

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

javaobj.py

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -341,15 +341,27 @@ def __init__(self, classdesc=None):
341341
self.classdesc = classdesc
342342

343343

344-
class JavaByteArray(bytearray, JavaObject):
344+
class JavaByteArray(JavaObject):
345345
"""
346346
Represents the special case of Java Array which contains bytes
347347
"""
348348
def __init__(self, data, classdesc=None):
349-
bytearray.__init__(self, data)
350349
JavaObject.__init__(self)
350+
self._data = struct.unpack("b" * len(data), data)
351351
self.classdesc = classdesc
352352

353+
def __str__(self):
354+
return "JavaByteArray({0})".format(self._data)
355+
356+
def __getitem__(self, item):
357+
return self._data[item]
358+
359+
def __iter__(self):
360+
return iter(self._data)
361+
362+
def __len__(self):
363+
return len(self._data)
364+
353365
# ------------------------------------------------------------------------------
354366

355367

@@ -1489,6 +1501,7 @@ def write_array(self, obj):
14891501
else:
14901502
log_debug("Write array of type %s" % type_char)
14911503
for v in obj:
1504+
log_debug("Writing: %s" % v)
14921505
self._write_value(type_char, v)
14931506

14941507
def _write_value(self, field_type, value):

0 commit comments

Comments
 (0)