Package org.python.core
Class PyByteArray
java.lang.Object
org.python.core.PyObject
org.python.core.PySequence
org.python.core.BaseBytes
org.python.core.PyByteArray
- All Implemented Interfaces:
Serializable
,Iterable<PyInteger>
,Collection<PyInteger>
,List<PyInteger>
,BufferProtocol
- Direct Known Subclasses:
PyByteArrayDerived
Implementation of Python
bytearray
with a Java API that includes equivalents to most
of the Python API. These Python equivalents accept a PyObject
as argument, where you
might have expected a byte[]
or PyByteArray
, in order to accommodate
the full range of types accepted by the Python equivalent: usually, any PyObject
that implements BufferProtocol
, providing a one-dimensional array of bytes, is an
acceptable argument. In the documentation, the reader will often see the terms "byte array" or
"object viewable as bytes" instead of bytearray
when this broader scope is intended.
This may relate to parameters, or to the target object itself (in text that applies equally to
base or sibling classes).- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class org.python.core.PyObject
PyObject.ConversionException
-
Field Summary
Fields inherited from class org.python.core.PyObject
gcMonitorGlobal
-
Constructor Summary
ConstructorDescriptionConstructs a zero-length Pythonbytearray
.PyByteArray
(byte[] storage) Constructs abytearray
by re-using an array of byte as storage initialised by the client.PyByteArray
(byte[] storage, int size) Constructs abytearray
by re-using an array of byte as storage initialised by the client.PyByteArray
(int size) Constructs zero-filled Pythonbytearray
of specified size.PyByteArray
(int[] value) Constructs abytearray
by copying values from int[].PyByteArray
(Iterable<? extends PyObject> value) Constructs a new array filled from an iterable of PyObject.PyByteArray
(BaseBytes value) Constructs a new array filled exactly by a copy of the contents of the source, which is abytearray
(orbytes
).PyByteArray
(BufferProtocol value) Constructs a new array filled exactly by a copy of the contents of the source, which is an object supporting the Jython version of the PEP 3118 buffer API.PyByteArray
(PyObject arg) Constructs a newbytearray
object from an arbitrary Python object according to the same rules as apply in Python to thebytearray()
constructor:bytearray()
Construct a zero-lengthbytearray
.bytearray(int)
Construct a zero-initializedbytearray
of the given length.bytearray(iterable_of_ints)
Construct from iterable yielding integers in [0..255]bytearray(buffer)
Construct by reading from any object implementingBufferProtocol
, includingstr/bytes
or anotherbytearray
. When it is necessary to specify an encoding, as in the Python signaturebytearray(string, encoding [, errors])
, use the constructorPyByteArray(PyString, String, String)
.PyByteArray
(PyString arg) Constructs a new array by encoding a PyString argument to bytes.PyByteArray
(PyString arg, String encoding, String errors) Constructs a new array by encoding a PyString argument to bytes.PyByteArray
(PyString arg, PyObject encoding, PyObject errors) Constructs a new array by encoding a PyString argument to bytes.PyByteArray
(PyType type) Constructs a zero-length Pythonbytearray
of explicitly-specified sub-type -
Method Summary
Modifier and TypeMethodDescriptionEquivalent to the standard Python __add__ method.int
Returns the number of bytes actually allocated.boolean
Implement to the standard Python __contains__ method, which in turn implements thein
operator.Equivalent to the standard Python __eq__ method.Equivalent to the standard Python __ge__ method.Equivalent to the standard Python __gt__ method.Equivalent to the standard Python __iadd__ method.Equivalent to the standard Python__imul__
method, that for a byte array returns a new byte array containing the same thing n times.Equivalent to the standard Python __le__ method.Equivalent to the standard Python __lt__ method.Equivalent to the standard Python__mul__
method, that for a byte array returns a new byte array containing the same thing n times.Equivalent to the standard Python __ne__ method.__repr__()
Equivalent to the standard Python__repr__
method.Equivalent to the standard Python__rmul__
method, that for a byte array returns a new byte array containing the same thing n times.__str__()
An overriding of thePyObject.__str__()
method, returningPyString
, where in the characters are simply those with a point-codes given in this byte array.void
append
(byte element) Append a single byte to the end of the array.void
Append a single element to the end of the array, equivalent to:s[len(s):len(s)] = o
.center
(int width) Java API equivalent of Pythoncenter(width)
: return the bytes centered in an array of lengthwidth
, padded by spaces.Java API equivalent of Pythoncenter(width [, fillchar])
: return the bytes centered in an array of lengthwidth
.int
Implementation of Pythoncount(sub)
.int
Implementation of Pythoncount( sub [, start ] )
.int
Implementation of Pythoncount( sub [, start [, end ]] )
.boolean
Implementation of Pythonendswith(suffix)
.boolean
Implementation of Pythonendswith( suffix [, start ] )
.boolean
Implementation of Pythonendswith( suffix [, start [, end ]] )
.Implementation of Pythonexpandtabs()
: return a copy of the byte array where all tab characters are replaced by one or more spaces, asexpandtabs(int)
with a tab size of 8 characters.expandtabs
(int tabsize) Implementation of Pythonexpandtabs(tabsize)
: return a copy of the byte array where all tab characters are replaced by one or more spaces, depending on the current column and the given tab size.void
Append the elements in the argument sequence to the end of the array, equivalent to:s[len(s):len(s)] = o
.int
Implementation of Pythonfind(sub)
.int
Implementation of Pythonfind( sub [, start ] )
.int
Implementation of Pythonfind( sub [, start [, end ]] )
.getBuffer
(int flags) Method by which the consumer requests the buffer from the exporter.int
hashCode()
This type is not hashable.int
Implementation of Pythonindex(sub)
.int
Implementation of Pythonindex( sub [, start ] )
.int
Implementation of Pythonindex( sub [, start [, end ]] )
.void
Insert the argument element into the byte array at the specified index.Implementation of Pythonjoin(iterable)
.ljust
(int width) Java API equivalent of Pythonljust(width)
: return the bytes left justified in an array of lengthwidth
, padded by spaces.Java API equivalent of Pythonljust(width [, fillchar])
: return the bytes left-justified in an array of lengthwidth
.lstrip()
Implementation of Pythonlstrip()
.Implementation of Pythonlstrip(bytes)
Return a copy of the byte array with the leading characters removed.pop()
Remove and return the last element in the byte array.pop
(int i) Remove and return then
th byte element in the array.void
Insert the element (interpreted as a Python byte value) at the given index.void
Sets the indexed element of thebytearray
to the given value.void
Remove the first occurrence of an element from the array, equivalent to:del s[s.index(x)]
, although x must be convertable to a single byte value.An implementation of Pythonreplace( old, new )
, returning aPyByteArray
with all occurrences of sequenceoldB
replaced bynewB
.An implementation of Pythonreplace( old, new [, count ] )
, returning aPyByteArray
with all occurrences of sequenceoldB
replaced bynewB
.void
reverse()
Reverses the contents of the byte array in place.int
Implementation of Pythonrfind(sub)
.int
Implementation of Pythonrfind( sub [, start ] )
.int
Implementation of Pythonrfind( sub [, start [, end ]] )
.int
Implementation of Pythonrindex(sub)
.int
Implementation of Pythonrindex( sub [, start ] )
.int
Implementation of Pythonrindex( sub [, start [, end ]] )
.rjust
(int width) Java API equivalent of Pythonrjust(width)
: return the bytes right justified in an array of lengthwidth
, padded by spaces.Java API equivalent of Pythonrjust(width [, fillchar])
: return the bytes right-justified in an array of lengthwidth
.rstrip()
Implementation of Pythonrstrip()
.Implementation of Pythonrstrip(bytes)
Return a copy of the byte array with the trailing characters removed.static PyException
SliceSizeError
(String valueType, int valueSize, int sliceSize) Convenience method to build (but not throw) aValueError
PyException with the message "attempt to assign {type} of size {valueSize} to extended slice of size {sliceSize}"boolean
startswith
(PyObject prefix) Implementation of Pythonstartswith(prefix)
.boolean
startswith
(PyObject prefix, PyObject start) Implementation of Pythonstartswith( prefix [, start ] )
.boolean
startswith
(PyObject prefix, PyObject start, PyObject end) Implementation of Pythonstartswith( prefix [, start [, end ]] )
.strip()
Implementation of Pythonstrip()
.Implementation of Pythonstrip(bytes)
Return a copy of the byte array with the leading and trailing characters removed.toString()
An overriding of the standard JavatoString()
method, returning a printable expression of this byte array in the formbytearray(b'hello')
, where in the "inner string", any special characters are escaped to their well-known backslash equivalents or a hexadecimal escape.Implementation of Pythontranslate(table).
Return a copy of the byte array where all bytes occurring in the optional argumentdeletechars
are removed, and the remaining bytes have been mapped through the given translation table, which must be of length 256.Implementation of Pythontranslate(table[, deletechars]).
Return a copy of the byte array where all bytes occurring in the optional argumentdeletechars
are removed, and the remaining bytes have been mapped through the given translation table, which must be of length 256.zfill
(int width) Implementation of Pythonzfill(width):
return the numeric string left filled with zeros in a byte array of lengthwidth
.Methods inherited from class org.python.core.BaseBytes
__len__, __reduce__, add, add, addAll, addAll, asString, capitalize, clear, contains, containsAll, decode, decode, decode, equals, get, indexOf, intAt, isalnum, isalpha, isdigit, isEmpty, islower, isspace, istitle, isupper, iterator, lastIndexOf, listIterator, listIterator, lower, partition, remove, remove, removeAll, retainAll, rpartition, rsplit, rsplit, rsplit, set, size, split, split, split, splitlines, splitlines, subList, swapcase, title, toArray, toArray, upper
Methods inherited from class org.python.core.PySequence
__delitem__, __delslice__, __finditem__, __finditem__, __getitem__, __getslice__, __iter__, __nonzero__, __setitem__, __setitem__, __setslice__, __tojava__, isMappingType, isNumberType, isSequenceType
Methods inherited from class org.python.core.PyObject
__abs__, __and__, __call__, __call__, __call__, __call__, __call__, __call__, __call__, __call__, __call__, __call__, __call__, __call__, __call__, __call__, __call__, __call__, __cmp__, __coerce__, __coerce_ex__, __complex__, __delattr__, __delattr__, __delete__, __delitem__, __delslice__, __dir__, __div__, __divmod__, __ensure_finalizer__, __findattr__, __findattr__, __findattr_ex__, __finditem__, __float__, __floordiv__, __format__, __get__, __getattr__, __getattr__, __getitem__, __getnewargs__, __getslice__, __hash__, __hex__, __iand__, __idiv__, __idivmod__, __ifloordiv__, __ilshift__, __imod__, __index__, __int__, __invert__, __ior__, __ipow__, __irshift__, __isub__, __iternext__, __itruediv__, __ixor__, __long__, __lshift__, __mod__, __neg__, __not__, __oct__, __or__, __pos__, __pow__, __pow__, __radd__, __rand__, __rdiv__, __rdivmod__, __reduce_ex__, __reduce_ex__, __rfloordiv__, __rlshift__, __rmod__, __ror__, __rpow__, __rrshift__, __rshift__, __rsub__, __rtruediv__, __rxor__, __set__, __setattr__, __setattr__, __setitem__, __setslice__, __sub__, __truediv__, __trunc__, __unicode__, __xor__, _add, _and, _callextra, _cmp, _div, _divmod, _doget, _doget, _doset, _eq, _floordiv, _ge, _gt, _iadd, _iand, _idiv, _idivmod, _ifloordiv, _ilshift, _imod, _imul, _in, _ior, _ipow, _irshift, _is, _isnot, _isub, _itruediv, _ixor, _jcall, _jcallexc, _jthrow, _le, _lshift, _lt, _mod, _mul, _ne, _notin, _or, _pow, _rshift, _sub, _truediv, _xor, asDouble, asIndex, asIndex, asInt, asInt, asIterable, asLong, asLong, asName, asName, asString, asStringOrNull, asStringOrNull, bit_length, conjugate, delDict, delType, dispatch__init__, fastGetClass, fastGetDict, getDict, getType, implementsDescrDelete, implementsDescrGet, implementsDescrSet, invoke, invoke, invoke, invoke, invoke, invoke, isCallable, isDataDescr, isIndex, isInteger, noAttributeError, object___subclasshook__, readonlyAttributeError, setDict, setType
Methods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArray
Methods inherited from interface java.util.List
replaceAll, sort, spliterator
-
Field Details
-
TYPE
ThePyType
ofbytearray
.
-
-
Constructor Details
-
PyByteArray
Constructs a zero-length Pythonbytearray
of explicitly-specified sub-type- Parameters:
type
- explicit Jython type
-
PyByteArray
public PyByteArray()Constructs a zero-length Pythonbytearray
. -
PyByteArray
public PyByteArray(int size) Constructs zero-filled Pythonbytearray
of specified size.- Parameters:
size
- ofbytearray
-
PyByteArray
public PyByteArray(int[] value) Constructs abytearray
by copying values from int[].- Parameters:
value
- source of the bytes (and size)
-
PyByteArray
Constructs a new array filled exactly by a copy of the contents of the source, which is abytearray
(orbytes
).- Parameters:
value
- source of the bytes (and size)
-
PyByteArray
Constructs a new array filled exactly by a copy of the contents of the source, which is an object supporting the Jython version of the PEP 3118 buffer API.- Parameters:
value
- source of the bytes (and size)
-
PyByteArray
Constructs a new array filled from an iterable of PyObject. The iterable must yield objects convertible to Python bytes (non-negative integers less than 256 or strings of length 1).- Parameters:
value
- source of the bytes (and size)
-
PyByteArray
Constructs a new array by encoding a PyString argument to bytes. If the PyString is actually a PyUnicode, the encoding must be explicitly specified.- Parameters:
arg
- primary argument from which value is takenencoding
- name of optional encoding (must be a string type)errors
- name of optional errors policy (must be a string type)
-
PyByteArray
Constructs a new array by encoding a PyString argument to bytes. If the PyString is actually a PyUnicode, the encoding must be explicitly specified.- Parameters:
arg
- primary argument from which value is takenencoding
- name of optional encoding (may benull
to select the default for this installation)errors
- name of optional errors policy
-
PyByteArray
Constructs a new array by encoding a PyString argument to bytes. If the PyString is actually a PyUnicode, an exception is thrown saying that the encoding must be explicitly specified.- Parameters:
arg
- primary argument from which value is taken
-
PyByteArray
public PyByteArray(byte[] storage) Constructs abytearray
by re-using an array of byte as storage initialised by the client.- Parameters:
storage
- pre-initialised with desired value: the caller should not keep a reference
-
PyByteArray
public PyByteArray(byte[] storage, int size) Constructs abytearray
by re-using an array of byte as storage initialised by the client.- Parameters:
storage
- pre-initialised with desired value: the caller should not keep a referencesize
- number of bytes actually used- Throws:
IllegalArgumentException
- if the range [0:size] is not within the array bounds of the storage.
-
PyByteArray
Constructs a newbytearray
object from an arbitrary Python object according to the same rules as apply in Python to thebytearray()
constructor:bytearray()
Construct a zero-lengthbytearray
.bytearray(int)
Construct a zero-initializedbytearray
of the given length.bytearray(iterable_of_ints)
Construct from iterable yielding integers in [0..255]bytearray(buffer)
Construct by reading from any object implementingBufferProtocol
, includingstr/bytes
or anotherbytearray
.
bytearray(string, encoding [, errors])
, use the constructorPyByteArray(PyString, String, String)
. If thePyString
is actually aPyUnicode
, an encoding must be specified, and using this constructor will throw an exception about that.- Parameters:
arg
- primary argument from which value is taken (may benull
)- Throws:
PyException
-TypeError
for non-iterable,PyException
-ValueError
if iterables do not yield byte [0..255] values.
-
-
Method Details
-
getBuffer
Method by which the consumer requests the buffer from the exporter. The consumer provides information on its ability to understand buffer navigation. Each consumer requesting a buffer in this way, when it has finished using it, should make a corresponding call toPyBuffer.release()
on the buffer it obtained, orPyBuffer.close()
using try-with-resources, since some objects alter their behaviour while buffers are exported.The
PyBuffer
returned from this method is a one-dimensional array of single byte items that allows modification of the object state. The existence of this export prohibits resizing the byte array. This prohibition is not only on the consumer of the view but extends to any other operations, such as any kind or insertion or deletion.- Specified by:
getBuffer
in interfaceBufferProtocol
- Parameters:
flags
- specifying features demanded and the navigational capabilities of the consumer- Returns:
- exported buffer
-
pyset
Sets the indexed element of thebytearray
to the given value. This is an extension point called by PySequence in its implementation ofPySequence.__setitem__(int, org.python.core.PyObject)
It is guaranteed by PySequence that the index is within the bounds of the array. Any other clients callingpyset(int)
must make the same guarantee.- Parameters:
index
- index of the element to set.value
- the value to set this element to.- Throws:
PyException
-AttributeError
if value cannot be converted to an integerPyException
-ValueError
if value<0 or value>255
-
pyinsert
Insert the element (interpreted as a Python byte value) at the given index. Pythonint
,long
andstr
types of length 1 are allowed.- Overrides:
pyinsert
in classBaseBytes
- Parameters:
index
- to insert atelement
- to insert (by value)- Throws:
PyException
-IndexError
if the index is outside the array boundsPyException
-ValueError
if element<0 or element>255PyException
-TypeError
if the subclass is immutable
-
SliceSizeError
Convenience method to build (but not throw) aValueError
PyException with the message "attempt to assign {type} of size {valueSize} to extended slice of size {sliceSize}"- Parameters:
valueType
-valueSize
- size of sequence being assigned to slicesliceSize
- size of slice expected to receive- Returns:
- PyException (ValueError) as detailed
-
__eq__
Description copied from class:PyObject
Equivalent to the standard Python __eq__ method.- Overrides:
__eq__
in classPySequence
- Parameters:
other
- the object to compare this with.- Returns:
- the result of the comparison.
-
__ne__
Description copied from class:PyObject
Equivalent to the standard Python __ne__ method.- Overrides:
__ne__
in classPySequence
- Parameters:
other
- the object to compare this with.- Returns:
- the result of the comparison.
-
__lt__
Description copied from class:PyObject
Equivalent to the standard Python __lt__ method.- Overrides:
__lt__
in classPySequence
- Parameters:
other
- the object to compare this with.- Returns:
- the result of the comparison.
-
__le__
Description copied from class:PyObject
Equivalent to the standard Python __le__ method.- Overrides:
__le__
in classPySequence
- Parameters:
other
- the object to compare this with.- Returns:
- the result of the comparison.
-
__ge__
Description copied from class:PyObject
Equivalent to the standard Python __ge__ method.- Overrides:
__ge__
in classPySequence
- Parameters:
other
- the object to compare this with.- Returns:
- the result of the comparison.
-
__gt__
Description copied from class:PyObject
Equivalent to the standard Python __gt__ method.- Overrides:
__gt__
in classPySequence
- Parameters:
other
- the object to compare this with.- Returns:
- the result of the comparison.
-
__add__
Description copied from class:PyObject
Equivalent to the standard Python __add__ method. -
__alloc__
public int __alloc__()Returns the number of bytes actually allocated. -
__imul__
Equivalent to the standard Python__imul__
method, that for a byte array returns a new byte array containing the same thing n times. -
__mul__
Equivalent to the standard Python__mul__
method, that for a byte array returns a new byte array containing the same thing n times. -
__rmul__
Equivalent to the standard Python__rmul__
method, that for a byte array returns a new byte array containing the same thing n times. -
append
public void append(byte element) Append a single byte to the end of the array.- Parameters:
element
- the byte to append.
-
append
Append a single element to the end of the array, equivalent to:s[len(s):len(s)] = o
. The argument must be a PyInteger, PyLong or string of length 1.- Parameters:
element
- the item to append.- Throws:
PyException
-ValueError
if element<0 or element>255
-
__contains__
Implement to the standard Python __contains__ method, which in turn implements thein
operator.- Overrides:
__contains__
in classPyObject
- Parameters:
o
- the element to search for in thisbytearray
.- Returns:
- the result of the search.
-
center
Java API equivalent of Pythoncenter(width)
: return the bytes centered in an array of lengthwidth
, padded by spaces. A copy of the original byte array is returned if width is less thanthis.size()
.- Parameters:
width
- desired- Returns:
- new byte array containing result
-
center
Java API equivalent of Pythoncenter(width [, fillchar])
: return the bytes centered in an array of lengthwidth
. Padding is done using the specified fillchar (default is a space). A copy of the original byte array is returned ifwidth
is less thanthis.size()
.- Parameters:
width
- desiredfillchar
- one-byte String to fill with, ornull
implying space- Returns:
- new byte array containing the result
-
count
Implementation of Pythoncount(sub)
. Return the number of non-overlapping occurrences ofsub
in this byte array.- Parameters:
sub
- sequence to find (of a type viewable as a byte sequence)- Returns:
- count of occurrences of sub within this byte array
-
count
Implementation of Pythoncount( sub [, start ] )
. Return the number of non-overlapping occurrences ofsub
in the range [start:].- Parameters:
sub
- sequence to find (of a type viewable as a byte sequence)start
- of slice to search- Returns:
- count of occurrences of sub within this byte array
-
count
Implementation of Pythoncount( sub [, start [, end ]] )
. Return the number of non-overlapping occurrences ofsub
in the range [start, end]. Optional argumentsstart
andend
(which may benull
orPy.None
) are interpreted as in slice notation.- Parameters:
sub
- sequence to find (of a type viewable as a byte sequence)start
- of slice to searchend
- of slice to search- Returns:
- count of occurrences of sub within this byte array
-
endswith
Implementation of Pythonendswith(suffix)
. Whensuffix
is of a type that may be treated as an array of bytes, returntrue
if and only if thisbytearray
ends with thesuffix
.suffix
can also be a tuple of suffixes to look for.- Parameters:
suffix
- byte array to match, or object viewable as such, or a tuple of them- Returns:
- true if and only if this
bytearray
ends with the suffix (or one of them)
-
endswith
Implementation of Pythonendswith( suffix [, start ] )
. Whensuffix
is of a type that may be treated as an array of bytes, returntrue
if and only if thisbytearray
ends with thesuffix
.suffix
can also be a tuple of suffixes to look for. With optionalstart
(which may benull
orPy.None
), define the effectivebytearray
to be the slice[start:]
of thisbytearray
.- Parameters:
suffix
- byte array to match, or object viewable as such, or a tuple of themstart
- of slice in thisbytearray
to match- Returns:
- true if and only if this[start:] ends with the suffix (or one of them)
-
endswith
Implementation of Pythonendswith( suffix [, start [, end ]] )
. Whensuffix
is of a type that may be treated as an array of bytes, returntrue
if and only if thisbytearray
ends with thesuffix
.suffix
can also be a tuple of suffixes to look for. With optionalstart
andend
(which may benull
orPy.None
), define the effectivebytearray
to be the slice[start:end]
of thisbytearray
.- Parameters:
suffix
- byte array to match, or object viewable as such, or a tuple of themstart
- of slice in thisbytearray
to matchend
- of slice in thisbytearray
to match- Returns:
- true if and only if this[start:end] ends with the suffix (or one of them)
-
expandtabs
Implementation of Pythonexpandtabs()
: return a copy of the byte array where all tab characters are replaced by one or more spaces, asexpandtabs(int)
with a tab size of 8 characters.- Returns:
- copy of this byte array with tabs expanded
-
expandtabs
Implementation of Pythonexpandtabs(tabsize)
: return a copy of the byte array where all tab characters are replaced by one or more spaces, depending on the current column and the given tab size. The column number is reset to zero after each newline occurring in the array. This treats other non-printing characters or escape sequences as regular characters.- Parameters:
tabsize
- number of character positions between tab stops- Returns:
- copy of this byte array with tabs expanded
-
extend
Append the elements in the argument sequence to the end of the array, equivalent to:s[len(s):len(s)] = o
. The argument must be a subclass ofBaseBytes
or an iterable type returning elements compatible with byte assignment.- Parameters:
o
- the sequence of items to append to the list.
-
find
Implementation of Pythonfind(sub)
. Return the lowest index in the byte array where byte sequencesub
is found. Return -1 ifsub
is not found.- Parameters:
sub
- sequence to find (of a type viewable as a byte sequence)- Returns:
- index of start of occurrence of sub within this byte array
-
find
Implementation of Pythonfind( sub [, start ] )
. Return the lowest index in the byte array where byte sequencesub
is found, such thatsub
is contained in the slice[start:]
. Return -1 ifsub
is not found.- Parameters:
sub
- sequence to find (of a type viewable as a byte sequence)start
- of slice to search- Returns:
- index of start of occurrence of sub within this byte array
-
find
Implementation of Pythonfind( sub [, start [, end ]] )
. Return the lowest index in the byte array where byte sequencesub
is found, such thatsub
is contained in the slice[start:end]
. Argumentsstart
andend
(which may benull
orPy.None
) are interpreted as in slice notation. Return -1 ifsub
is not found.- Parameters:
sub
- sequence to find (of a type viewable as a byte sequence)start
- of slice to searchend
- of slice to search- Returns:
- index of start of occurrence of sub within this byte array
-
__iadd__
Description copied from class:PyObject
Equivalent to the standard Python __iadd__ method. -
index
Implementation of Pythonindex(sub)
. Likefind(PyObject)
but raisePy.ValueError
ifsub
is not found.- Parameters:
sub
- sequence to find (of a type viewable as a byte sequence)- Returns:
- index of start of occurrence of sub within this byte array
-
index
Implementation of Pythonindex( sub [, start ] )
. Likefind(PyObject,PyObject)
but raisePy.ValueError
ifsub
is not found.- Parameters:
sub
- sequence to find (of a type viewable as a byte sequence)start
- of slice to search- Returns:
- index of start of occurrence of sub within this byte array
-
hashCode
This type is not hashable.- Specified by:
hashCode
in interfaceCollection<PyInteger>
- Specified by:
hashCode
in interfaceList<PyInteger>
- Overrides:
hashCode
in classBaseBytes
- Throws:
PyException
-TypeError
as this type is not hashable.
-
index
Implementation of Pythonindex( sub [, start [, end ]] )
. Likefind(PyObject,PyObject,PyObject)
but raisePy.ValueError
ifsub
is not found.- Parameters:
sub
- sequence to find (of a type viewable as a byte sequence)start
- of slice to searchend
- of slice to search- Returns:
- index of start of occurrence of sub within this byte array
- Throws:
PyException
- ValueError if sub not found in byte array
-
insert
Insert the argument element into the byte array at the specified index. Same ass[index:index] = [o] if index >= 0
.- Parameters:
index
- the position where the element will be inserted.value
- the element to insert.
-
join
Implementation of Pythonjoin(iterable)
. Return abytearray
which is the concatenation of the byte arrays in the iterableiterable
. The separator between elements is the byte array providing this method.- Parameters:
iterable
- of byte array objects, or objects viewable as such.- Returns:
- byte array produced by concatenation.
-
ljust
Java API equivalent of Pythonljust(width)
: return the bytes left justified in an array of lengthwidth
, padded by spaces. A copy of the original byte array is returned if width is less thanthis.size()
.- Parameters:
width
- desired- Returns:
- new byte array containing result
-
ljust
Java API equivalent of Pythonljust(width [, fillchar])
: return the bytes left-justified in an array of lengthwidth
. Padding is done using the specified fillchar (default is a space). A copy of the original byte array is returned ifwidth
is less thanthis.size()
.- Parameters:
width
- desiredfillchar
- one-byte String to fill with, ornull
implying space- Returns:
- new byte array containing the result
-
lstrip
Implementation of Pythonlstrip()
. Return a copy of the byte array with the leading whitespace characters removed.- Returns:
- a byte array containing this value stripped of those bytes
-
lstrip
Implementation of Pythonlstrip(bytes)
Return a copy of the byte array with the leading characters removed. The bytes argument is an object specifying the set of characters to be removed. Ifnull
orNone
, the bytes argument defaults to removing whitespace. The bytes argument is not a prefix; rather, all combinations of its values are stripped.- Parameters:
bytes
- treated as a set of bytes defining what values to strip- Returns:
- a byte array containing this value stripped of those bytes (at the left)
-
pop
Remove and return the last element in the byte array.- Returns:
- PyInteger representing the value
-
pop
Remove and return then
th byte element in the array.- Parameters:
i
- the index of the byte to remove and return.- Returns:
- PyInteger representing the value
-
remove
Remove the first occurrence of an element from the array, equivalent to:del s[s.index(x)]
, although x must be convertable to a single byte value. The argument must be a PyInteger, PyLong or string of length 1.- Parameters:
o
- the value to remove from the list.- Throws:
PyException
- ValueError if o not found inbytearray
-
replace
An implementation of Pythonreplace( old, new )
, returning aPyByteArray
with all occurrences of sequenceoldB
replaced bynewB
.- Parameters:
oldB
- sequence to findnewB
- relacement sequence- Returns:
- result of replacement as a new PyByteArray
-
replace
An implementation of Pythonreplace( old, new [, count ] )
, returning aPyByteArray
with all occurrences of sequenceoldB
replaced bynewB
. If the optional argumentcount
is given, only the firstcount
occurrences are replaced.- Parameters:
oldB
- sequence to findnewB
- relacement sequencemaxcount
- maximum occurrences are replaced or all ifmaxcount < 0
- Returns:
- result of replacement as a new PyByteArray
-
reverse
public void reverse()Reverses the contents of the byte array in place. The reverse() methods modify in place for economy of space when reversing a large array. It doesn't return the reversed array to remind you that it works by side effect. -
rfind
Implementation of Pythonrfind(sub)
. Return the highest index in the byte array where byte sequencesub
is found. Return -1 ifsub
is not found.- Parameters:
sub
- sequence to find (of a type viewable as a byte sequence)- Returns:
- index of start of rightmost occurrence of sub within this byte array
-
rfind
Implementation of Pythonrfind( sub [, start ] )
. Return the highest index in the byte array where byte sequencesub
is found, such thatsub
is contained in the slice[start:]
. Return -1 ifsub
is not found.- Parameters:
sub
- sequence to find (of a type viewable as a byte sequence)start
- of slice to search- Returns:
- index of start of rightmost occurrence of sub within this byte array
-
rfind
Implementation of Pythonrfind( sub [, start [, end ]] )
. Return the highest index in the byte array where byte sequencesub
is found, such thatsub
is contained in the slice[start:end]
. Argumentsstart
andend
(which may benull
orPy.None
) are interpreted as in slice notation. Return -1 ifsub
is not found.- Parameters:
sub
- sequence to find (of a type viewable as a byte sequence)start
- of slice to searchend
- of slice to search- Returns:
- index of start of rightmost occurrence of sub within this byte array
-
rindex
Implementation of Pythonrindex(sub)
. Likefind(PyObject)
but raisePy.ValueError
ifsub
is not found.- Parameters:
sub
- sequence to find (of a type viewable as a byte sequence)- Returns:
- index of start of occurrence of sub within this byte array
-
rindex
Implementation of Pythonrindex( sub [, start ] )
. Likefind(PyObject,PyObject)
but raisePy.ValueError
ifsub
is not found.- Parameters:
sub
- sequence to find (of a type viewable as a byte sequence)start
- of slice to search- Returns:
- index of start of occurrence of sub within this byte array
-
rjust
Java API equivalent of Pythonrjust(width)
: return the bytes right justified in an array of lengthwidth
, padded by spaces. A copy of the original byte array is returned if width is less thanthis.size()
.- Parameters:
width
- desired- Returns:
- new byte array containing result
-
rjust
Java API equivalent of Pythonrjust(width [, fillchar])
: return the bytes right-justified in an array of lengthwidth
. Padding is done using the specified fillchar (default is a space). A copy of the original byte array is returned ifwidth
is less thanthis.size()
.- Parameters:
width
- desiredfillchar
- one-byte String to fill with, ornull
implying space- Returns:
- new byte array containing the result
-
rindex
Implementation of Pythonrindex( sub [, start [, end ]] )
. Likefind(PyObject,PyObject,PyObject)
but raisePy.ValueError
ifsub
is not found.- Parameters:
sub
- sequence to find (of a type viewable as a byte sequence)start
- of slice to searchend
- of slice to search- Returns:
- index of start of occurrence of sub within this byte array
-
rstrip
Implementation of Pythonrstrip()
. Return a copy of the byte array with the trailing whitespace characters removed.- Returns:
- a byte array containing this value stripped of those bytes (at right)
-
rstrip
Implementation of Pythonrstrip(bytes)
Return a copy of the byte array with the trailing characters removed. The bytes argument is an object specifying the set of characters to be removed. Ifnull
orNone
, the bytes argument defaults to removing whitespace. The bytes argument is not a suffix; rather, all combinations of its values are stripped.- Parameters:
bytes
- treated as a set of bytes defining what values to strip- Returns:
- a byte array containing this value stripped of those bytes (at right)
-
startswith
Implementation of Pythonstartswith(prefix)
. Whenprefix
is of a type that may be treated as an array of bytes, returntrue
if and only if thisbytearray
starts with theprefix
.prefix
can also be a tuple of prefixes to look for.- Parameters:
prefix
- byte array to match, or object viewable as such, or a tuple of them- Returns:
- true if and only if this
bytearray
starts with the prefix (or one of them)
-
startswith
Implementation of Pythonstartswith( prefix [, start ] )
. Whenprefix
is of a type that may be treated as an array of bytes, returntrue
if and only if thisbytearray
starts with theprefix
.prefix
can also be a tuple of prefixes to look for. With optionalstart
(which may benull
orPy.None
), define the effectivebytearray
to be the slice[start:]
of thisbytearray
.- Parameters:
prefix
- byte array to match, or object viewable as such, or a tuple of themstart
- of slice in thisbytearray
to match- Returns:
- true if and only if this[start:] starts with the prefix (or one of them)
-
startswith
Implementation of Pythonstartswith( prefix [, start [, end ]] )
. Whenprefix
is of a type that may be treated as an array of bytes, returntrue
if and only if thisbytearray
starts with theprefix
.prefix
can also be a tuple of prefixes to look for. With optionalstart
andend
(which may benull
orPy.None
), define the effectivebytearray
to be the slice[start:end]
of thisbytearray
.- Parameters:
prefix
- byte array to match, or object viewable as such, or a tuple of themstart
- of slice in thisbytearray
to matchend
- of slice in thisbytearray
to match- Returns:
- true if and only if this[start:end] starts with the prefix (or one of them)
-
strip
Implementation of Pythonstrip()
. Return a copy of the byte array with the leading and trailing whitespace characters removed.- Returns:
- a byte array containing this value stripped of those bytes (left and right)
-
strip
Implementation of Pythonstrip(bytes)
Return a copy of the byte array with the leading and trailing characters removed. The bytes argument is anbyte arrayt specifying the set of characters to be removed. Ifnull
orNone
, the bytes argument defaults to removing whitespace. The bytes argument is not a prefix or suffix; rather, all combinations of its values are stripped.- Parameters:
bytes
- treated as a set of bytes defining what values to strip- Returns:
- a byte array containing this value stripped of those bytes (left and right)
-
toString
An overriding of the standard JavatoString()
method, returning a printable expression of this byte array in the formbytearray(b'hello')
, where in the "inner string", any special characters are escaped to their well-known backslash equivalents or a hexadecimal escape. The built-in functionrepr()
is expected to call this method, and wraps the result in a Pythonstr
. -
__repr__
Description copied from class:PyObject
Equivalent to the standard Python__repr__
method. Each sub-class ofPyObject
is likely to re-define this method to provide for its own reproduction. -
__str__
An overriding of thePyObject.__str__()
method, returningPyString
, where in the characters are simply those with a point-codes given in this byte array. The built-in functionstr()
is expected to call this method. -
translate
Implementation of Pythontranslate(table).
Return a copy of the byte array where all bytes occurring in the optional argumentdeletechars
are removed, and the remaining bytes have been mapped through the given translation table, which must be of length 256.- Parameters:
table
- length 256 translation table (of a type that may be regarded as a byte array)- Returns:
- translated byte array
-
translate
Implementation of Pythontranslate(table[, deletechars]).
Return a copy of the byte array where all bytes occurring in the optional argumentdeletechars
are removed, and the remaining bytes have been mapped through the given translation table, which must be of length 256. You can use the Pythonmaketrans()
helper function in thestring
module to create a translation table. For string objects, set the table argument toNone
for translations that only delete characters:- Parameters:
table
- length 256 translation table (of a type that may be regarded as a byte array)deletechars
- object that may be regarded as a byte array, defining bytes to delete- Returns:
- translated byte array
-
zfill
Implementation of Pythonzfill(width):
return the numeric string left filled with zeros in a byte array of lengthwidth
. A sign prefix is handled correctly if it is in the first byte. A copy of the original is returned if width is less than the current size of the array.- Parameters:
width
- desired- Returns:
- left-filled byte array
-