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>,SequencedCollection<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
FieldsFields inherited from class org.python.core.PyObject
gcMonitorGlobal -
Constructor Summary
ConstructorsConstructorDescriptionConstructs a zero-length Pythonbytearray.PyByteArray(byte[] storage) Constructs abytearrayby re-using an array of byte as storage initialised by the client.PyByteArray(byte[] storage, int size) Constructs abytearrayby re-using an array of byte as storage initialised by the client.PyByteArray(int size) Constructs zero-filled Pythonbytearrayof specified size.PyByteArray(int[] value) Constructs abytearrayby 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 newbytearrayobject 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-initializedbytearrayof 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/bytesor 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 Pythonbytearrayof explicitly-specified sub-type -
Method Summary
Modifier and TypeMethodDescriptionEquivalent to the standard Python __add__ method.intReturns the number of bytes actually allocated.booleanImplement to the standard Python __contains__ method, which in turn implements theinoperator.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.voidappend(byte element) Append a single byte to the end of the array.voidAppend 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.intImplementation of Pythoncount(sub).intImplementation of Pythoncount( sub [, start ] ).intImplementation of Pythoncount( sub [, start [, end ]] ).booleanImplementation of Pythonendswith(suffix).booleanImplementation of Pythonendswith( suffix [, start ] ).booleanImplementation 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.voidAppend the elements in the argument sequence to the end of the array, equivalent to:s[len(s):len(s)] = o.intImplementation of Pythonfind(sub).intImplementation of Pythonfind( sub [, start ] ).intImplementation of Pythonfind( sub [, start [, end ]] ).getBuffer(int flags) Method by which the consumer requests the buffer from the exporter.inthashCode()This type is not hashable.intImplementation of Pythonindex(sub).intImplementation of Pythonindex( sub [, start ] ).intImplementation of Pythonindex( sub [, start [, end ]] ).voidInsert 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 thenth byte element in the array.voidInsert the element (interpreted as a Python byte value) at the given index.voidSets the indexed element of thebytearrayto the given value.voidRemove 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 aPyByteArraywith all occurrences of sequenceoldBreplaced bynewB.An implementation of Pythonreplace( old, new [, count ] ), returning aPyByteArraywith all occurrences of sequenceoldBreplaced bynewB.voidreverse()Reverses the contents of the byte array in place.intImplementation of Pythonrfind(sub).intImplementation of Pythonrfind( sub [, start ] ).intImplementation of Pythonrfind( sub [, start [, end ]] ).intImplementation of Pythonrindex(sub).intImplementation of Pythonrindex( sub [, start ] ).intImplementation 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 PyExceptionSliceSizeError(String valueType, int valueSize, int sliceSize) Convenience method to build (but not throw) aValueErrorPyException with the message "attempt to assign {type} of size {valueSize} to extended slice of size {sliceSize}"booleanstartswith(PyObject prefix) Implementation of Pythonstartswith(prefix).booleanstartswith(PyObject prefix, PyObject start) Implementation of Pythonstartswith( prefix [, start ] ).booleanstartswith(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 argumentdeletecharsare 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 argumentdeletecharsare 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, upperMethods inherited from class org.python.core.PySequence
__delitem__, __delslice__, __finditem__, __finditem__, __getitem__, __getslice__, __iter__, __nonzero__, __setitem__, __setitem__, __setslice__, __tojava__, isMappingType, isNumberType, isSequenceTypeMethods 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, setTypeMethods inherited from interface java.util.Collection
parallelStream, removeIf, stream, toArrayMethods inherited from interface java.util.List
addFirst, addLast, getFirst, getLast, removeFirst, removeLast, replaceAll, reversed, sort, spliterator
-
Field Details
-
TYPE
ThePyTypeofbytearray.
-
-
Constructor Details
-
PyByteArray
Constructs a zero-length Pythonbytearrayof 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 Pythonbytearrayof specified size.- Parameters:
size- ofbytearray
-
PyByteArray
public PyByteArray(int[] value) Constructs abytearrayby 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 benullto 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 abytearrayby 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 abytearrayby 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 newbytearrayobject 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-initializedbytearrayof 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/bytesor anotherbytearray.
bytearray(string, encoding [, errors]), use the constructorPyByteArray(PyString, String, String). If thePyStringis 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-TypeErrorfor non-iterable,PyException-ValueErrorif 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
PyBufferreturned 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:
getBufferin interfaceBufferProtocol- Parameters:
flags- specifying features demanded and the navigational capabilities of the consumer- Returns:
- exported buffer
-
pyset
Sets the indexed element of thebytearrayto 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-AttributeErrorif value cannot be converted to an integerPyException-ValueErrorif value<0 or value>255
-
pyinsert
Insert the element (interpreted as a Python byte value) at the given index. Pythonint,longandstrtypes of length 1 are allowed.- Overrides:
pyinsertin classBaseBytes- Parameters:
index- to insert atelement- to insert (by value)- Throws:
PyException-IndexErrorif the index is outside the array boundsPyException-ValueErrorif element<0 or element>255PyException-TypeErrorif the subclass is immutable
-
SliceSizeError
Convenience method to build (but not throw) aValueErrorPyException 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:PyObjectEquivalent 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:PyObjectEquivalent 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:PyObjectEquivalent 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:PyObjectEquivalent 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:PyObjectEquivalent 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:PyObjectEquivalent 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:PyObjectEquivalent 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-ValueErrorif element<0 or element>255
-
__contains__
Implement to the standard Python __contains__ method, which in turn implements theinoperator.- 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 ifwidthis less thanthis.size().- Parameters:
width- desiredfillchar- one-byte String to fill with, ornullimplying space- Returns:
- new byte array containing the result
-
count
Implementation of Pythoncount(sub). Return the number of non-overlapping occurrences ofsubin 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 ofsubin 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 ofsubin the range [start, end]. Optional argumentsstartandend(which may benullorPy.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). Whensuffixis of a type that may be treated as an array of bytes, returntrueif and only if thisbytearrayends with thesuffix.suffixcan 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
bytearrayends with the suffix (or one of them)
-
endswith
Implementation of Pythonendswith( suffix [, start ] ). Whensuffixis of a type that may be treated as an array of bytes, returntrueif and only if thisbytearrayends with thesuffix.suffixcan also be a tuple of suffixes to look for. With optionalstart(which may benullorPy.None), define the effectivebytearrayto 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 thisbytearrayto match- Returns:
- true if and only if this[start:] ends with the suffix (or one of them)
-
endswith
Implementation of Pythonendswith( suffix [, start [, end ]] ). Whensuffixis of a type that may be treated as an array of bytes, returntrueif and only if thisbytearrayends with thesuffix.suffixcan also be a tuple of suffixes to look for. With optionalstartandend(which may benullorPy.None), define the effectivebytearrayto 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 thisbytearrayto matchend- of slice in thisbytearrayto 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 ofBaseBytesor 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 sequencesubis found. Return -1 ifsubis 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 sequencesubis found, such thatsubis contained in the slice[start:]. Return -1 ifsubis 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 sequencesubis found, such thatsubis contained in the slice[start:end]. Argumentsstartandend(which may benullorPy.None) are interpreted as in slice notation. Return -1 ifsubis 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:PyObjectEquivalent to the standard Python __iadd__ method. -
index
Implementation of Pythonindex(sub). Likefind(PyObject)but raisePy.ValueErrorifsubis 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.ValueErrorifsubis 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:
hashCodein interfaceCollection<PyInteger>- Specified by:
hashCodein interfaceList<PyInteger>- Overrides:
hashCodein classBaseBytes- Throws:
PyException-TypeErroras this type is not hashable.
-
index
Implementation of Pythonindex( sub [, start [, end ]] ). Likefind(PyObject,PyObject,PyObject)but raisePy.ValueErrorifsubis 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 abytearraywhich 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 ifwidthis less thanthis.size().- Parameters:
width- desiredfillchar- one-byte String to fill with, ornullimplying 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. IfnullorNone, 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 thenth 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 aPyByteArraywith all occurrences of sequenceoldBreplaced 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 aPyByteArraywith all occurrences of sequenceoldBreplaced bynewB. If the optional argumentcountis given, only the firstcountoccurrences 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 sequencesubis found. Return -1 ifsubis 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 sequencesubis found, such thatsubis contained in the slice[start:]. Return -1 ifsubis 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 sequencesubis found, such thatsubis contained in the slice[start:end]. Argumentsstartandend(which may benullorPy.None) are interpreted as in slice notation. Return -1 ifsubis 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.ValueErrorifsubis 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.ValueErrorifsubis 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 ifwidthis less thanthis.size().- Parameters:
width- desiredfillchar- one-byte String to fill with, ornullimplying space- Returns:
- new byte array containing the result
-
rindex
Implementation of Pythonrindex( sub [, start [, end ]] ). Likefind(PyObject,PyObject,PyObject)but raisePy.ValueErrorifsubis 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. IfnullorNone, 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). Whenprefixis of a type that may be treated as an array of bytes, returntrueif and only if thisbytearraystarts with theprefix.prefixcan 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
bytearraystarts with the prefix (or one of them)
-
startswith
Implementation of Pythonstartswith( prefix [, start ] ). Whenprefixis of a type that may be treated as an array of bytes, returntrueif and only if thisbytearraystarts with theprefix.prefixcan also be a tuple of prefixes to look for. With optionalstart(which may benullorPy.None), define the effectivebytearrayto 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 thisbytearrayto match- Returns:
- true if and only if this[start:] starts with the prefix (or one of them)
-
startswith
Implementation of Pythonstartswith( prefix [, start [, end ]] ). Whenprefixis of a type that may be treated as an array of bytes, returntrueif and only if thisbytearraystarts with theprefix.prefixcan also be a tuple of prefixes to look for. With optionalstartandend(which may benullorPy.None), define the effectivebytearrayto 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 thisbytearrayto matchend- of slice in thisbytearrayto 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. IfnullorNone, 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:PyObjectEquivalent to the standard Python__repr__method. Each sub-class ofPyObjectis 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 argumentdeletecharsare 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 argumentdeletecharsare 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 thestringmodule to create a translation table. For string objects, set the table argument toNonefor 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
-