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:
java.io.Serializable,java.lang.Iterable<PyInteger>,java.util.Collection<PyInteger>,java.util.List<PyInteger>,BufferProtocol
- Direct Known Subclasses:
PyByteArrayDerived
public class PyByteArray extends BaseBytes implements BufferProtocol
Implementation of Pythonbytearraywith a Java API that includes equivalents to most of the Python API. These Python equivalents accept aPyObjectas argument, where you might have expected abyte[]orPyByteArray, in order to accommodate the full range of types accepted by the Python equivalent: usually, anyPyObjectthat implementsBufferProtocol, 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 ofbytearraywhen 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:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.python.core.PyObject
PyObject.ConversionException
-
-
Field Summary
Fields Modifier and Type Field Description static PyTypeTYPEThePyTypeofbytearray.-
Fields inherited from class org.python.core.PyObject
gcMonitorGlobal
-
-
Constructor Summary
Constructors Constructor Description PyByteArray()Constructs 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(java.lang.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, java.lang.String encoding, java.lang.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
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description PyObject__add__(PyObject o)Equivalent to the standard Python __add__ method.int__alloc__()Returns the number of bytes actually allocated.boolean__contains__(PyObject o)Implement to the standard Python __contains__ method, which in turn implements theinoperator.PyObject__eq__(PyObject other)Equivalent to the standard Python __eq__ method.PyObject__ge__(PyObject other)Equivalent to the standard Python __ge__ method.PyObject__gt__(PyObject other)Equivalent to the standard Python __gt__ method.PyObject__iadd__(PyObject o)Equivalent to the standard Python __iadd__ method.PyObject__imul__(PyObject n)Equivalent to the standard Python__imul__method, that for a byte array returns a new byte array containing the same thing n times.PyObject__le__(PyObject other)Equivalent to the standard Python __le__ method.PyObject__lt__(PyObject other)Equivalent to the standard Python __lt__ method.PyObject__mul__(PyObject n)Equivalent to the standard Python__mul__method, that for a byte array returns a new byte array containing the same thing n times.PyObject__ne__(PyObject other)Equivalent to the standard Python __ne__ method.PyObject__rmul__(PyObject n)Equivalent to the standard Python__rmul__method, that for a byte array returns a new byte array containing the same thing n times.PyString__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(PyObject element)Append a single element to the end of the array, equivalent to:s[len(s):len(s)] = o.PyByteArraycenter(int width)Java API equivalent of Pythoncenter(width): return the bytes centered in an array of lengthwidth, padded by spaces.PyByteArraycenter(int width, java.lang.String fillchar)Java API equivalent of Pythoncenter(width [, fillchar]): return the bytes centered in an array of lengthwidth.intcount(PyObject sub)Implementation of Pythoncount(sub).intcount(PyObject sub, PyObject start)Implementation of Pythoncount( sub [, start ] ).intcount(PyObject sub, PyObject start, PyObject end)Implementation of Pythoncount( sub [, start [, end ]] ).booleanendswith(PyObject suffix)Implementation of Pythonendswith(suffix).booleanendswith(PyObject suffix, PyObject start)Implementation of Pythonendswith( suffix [, start ] ).booleanendswith(PyObject suffix, PyObject start, PyObject end)Implementation of Pythonendswith( suffix [, start [, end ]] ).PyByteArrayexpandtabs()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.PyByteArrayexpandtabs(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.voidextend(PyObject o)Append the elements in the argument sequence to the end of the array, equivalent to:s[len(s):len(s)] = o.intfind(PyObject sub)Implementation of Pythonfind(sub).intfind(PyObject sub, PyObject start)Implementation of Pythonfind( sub [, start ] ).intfind(PyObject sub, PyObject start, PyObject end)Implementation of Pythonfind( sub [, start [, end ]] ).PyBuffergetBuffer(int flags)Method by which the consumer requests the buffer from the exporter.inthashCode()This type is not hashable.intindex(PyObject sub)Implementation of Pythonindex(sub).intindex(PyObject sub, PyObject start)Implementation of Pythonindex( sub [, start ] ).intindex(PyObject sub, PyObject start, PyObject end)Implementation of Pythonindex( sub [, start [, end ]] ).voidinsert(PyObject index, PyObject value)Insert the argument element into the byte array at the specified index.PyByteArrayjoin(PyObject iterable)Implementation of Pythonjoin(iterable).PyByteArrayljust(int width)Java API equivalent of Pythonljust(width): return the bytes left justified in an array of lengthwidth, padded by spaces.PyByteArrayljust(int width, java.lang.String fillchar)Java API equivalent of Pythonljust(width [, fillchar]): return the bytes left-justified in an array of lengthwidth.PyByteArraylstrip()Implementation of Pythonlstrip().PyByteArraylstrip(PyObject bytes)Implementation of Pythonlstrip(bytes)Return a copy of the byte array with the leading characters removed.PyIntegerpop()Remove and return the last element in the byte array.PyIntegerpop(int i)Remove and return thenth byte element in the array.voidpyinsert(int index, PyObject element)Insert the element (interpreted as a Python byte value) at the given index.voidpyset(int index, PyObject value)Sets the indexed element of thebytearrayto the given value.voidremove(PyObject o)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.PyByteArrayreplace(PyObject oldB, PyObject newB)An implementation of Pythonreplace( old, new ), returning aPyByteArraywith all occurrences of sequenceoldBreplaced bynewB.PyByteArrayreplace(PyObject oldB, PyObject newB, int maxcount)An implementation of Pythonreplace( old, new [, count ] ), returning aPyByteArraywith all occurrences of sequenceoldBreplaced bynewB.voidreverse()Reverses the contents of the byte array in place.intrfind(PyObject sub)Implementation of Pythonrfind(sub).intrfind(PyObject sub, PyObject start)Implementation of Pythonrfind( sub [, start ] ).intrfind(PyObject sub, PyObject start, PyObject end)Implementation of Pythonrfind( sub [, start [, end ]] ).intrindex(PyObject sub)Implementation of Pythonrindex(sub).intrindex(PyObject sub, PyObject start)Implementation of Pythonrindex( sub [, start ] ).intrindex(PyObject sub, PyObject start, PyObject end)Implementation of Pythonrindex( sub [, start [, end ]] ).PyByteArrayrjust(int width)Java API equivalent of Pythonrjust(width): return the bytes right justified in an array of lengthwidth, padded by spaces.PyByteArrayrjust(int width, java.lang.String fillchar)Java API equivalent of Pythonrjust(width [, fillchar]): return the bytes right-justified in an array of lengthwidth.PyByteArrayrstrip()Implementation of Pythonrstrip().PyByteArrayrstrip(PyObject bytes)Implementation of Pythonrstrip(bytes)Return a copy of the byte array with the trailing characters removed.static PyExceptionSliceSizeError(java.lang.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 ]] ).PyByteArraystrip()Implementation of Pythonstrip().PyByteArraystrip(PyObject bytes)Implementation of Pythonstrip(bytes)Return a copy of the byte array with the leading and trailing characters removed.java.lang.StringtoString()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.PyByteArraytranslate(PyObject table)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.PyByteArraytranslate(PyObject table, PyObject deletechars)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.PyByteArrayzfill(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__, __repr__, __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
-
-
-
-
Constructor Detail
-
PyByteArray
public PyByteArray(PyType type)
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
public PyByteArray(BaseBytes value)
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
public 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.- Parameters:
value- source of the bytes (and size)
-
PyByteArray
public PyByteArray(java.lang.Iterable<? extends PyObject> value)
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
public PyByteArray(PyString arg, PyObject encoding, PyObject errors)
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
public PyByteArray(PyString arg, java.lang.String encoding, java.lang.String errors)
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
public PyByteArray(PyString arg)
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:
java.lang.IllegalArgumentException- if the range [0:size] is not within the array bounds of the storage.
-
PyByteArray
public PyByteArray(PyObject arg) throws PyException
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- (TypeError) for non-iterable,PyException- (ValueError) if iterables do not yield byte [0..255] values.
-
-
Method Detail
-
getBuffer
public PyBuffer getBuffer(int flags)
Method by which the consumer requests the buffer from the exporter. The consumer provides information on its intended method of navigation and the features the buffer object is asked (or assumed) to provide. 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, 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
public void pyset(int index, PyObject value) throws PyExceptionSets 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- (AttributeError) if value cannot be converted to an integerPyException- (ValueError) if value<0 or value>255
-
pyinsert
public void pyinsert(int index, PyObject element)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- (IndexError) if the index is outside the array boundsPyException- (ValueError) if element<0 or element>255PyException- (TypeError) if the subclass is immutable
-
SliceSizeError
public static PyException SliceSizeError(java.lang.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}"- Parameters:
valueType-valueSize- size of sequence being assigned to slicesliceSize- size of slice expected to receive- Returns:
- PyException (ValueError) as detailed
-
__eq__
public PyObject __eq__(PyObject other)
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__
public PyObject __ne__(PyObject other)
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__
public PyObject __lt__(PyObject other)
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__
public PyObject __le__(PyObject other)
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__
public PyObject __ge__(PyObject other)
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__
public PyObject __gt__(PyObject other)
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__
public PyObject __add__(PyObject o)
Description copied from class:PyObjectEquivalent to the standard Python __add__ method.
-
__alloc__
public int __alloc__()
Returns the number of bytes actually allocated.
-
__imul__
public PyObject __imul__(PyObject n)
Equivalent to the standard Python__imul__method, that for a byte array returns a new byte array containing the same thing n times.
-
__mul__
public PyObject __mul__(PyObject n)
Equivalent to the standard Python__mul__method, that for a byte array returns a new byte array containing the same thing n times.
-
__rmul__
public PyObject __rmul__(PyObject n)
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
public void append(PyObject element)
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__
public boolean __contains__(PyObject o)
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
public PyByteArray center(int width)
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
public PyByteArray center(int width, java.lang.String fillchar)
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
public int count(PyObject sub)
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
public int count(PyObject sub, PyObject start)
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
public int count(PyObject sub, PyObject start, PyObject end)
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
public boolean endswith(PyObject suffix)
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
public boolean endswith(PyObject suffix, PyObject start)
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
public boolean endswith(PyObject suffix, PyObject start, PyObject end)
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
public PyByteArray 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
public PyByteArray 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. 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
public void extend(PyObject o)
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
public int find(PyObject sub)
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
public int find(PyObject sub, PyObject start)
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
public int find(PyObject sub, PyObject start, PyObject end)
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__
public PyObject __iadd__(PyObject o)
Description copied from class:PyObjectEquivalent to the standard Python __iadd__ method.
-
index
public int index(PyObject sub)
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
public int index(PyObject sub, PyObject start)
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
public int hashCode() throws PyExceptionThis type is not hashable.- Specified by:
hashCodein interfacejava.util.Collection<PyInteger>- Specified by:
hashCodein interfacejava.util.List<PyInteger>- Overrides:
hashCodein classBaseBytes- Throws:
PyException- (TypeError) as this type is not hashable.
-
index
public int index(PyObject sub, PyObject start, PyObject end) throws PyException
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
public void insert(PyObject index, PyObject value)
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
public PyByteArray join(PyObject iterable)
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
public PyByteArray ljust(int width)
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
public PyByteArray ljust(int width, java.lang.String fillchar)
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
public PyByteArray 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
public PyByteArray lstrip(PyObject bytes)
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
public PyInteger pop()
Remove and return the last element in the byte array.- Returns:
- PyInteger representing the value
-
pop
public PyInteger pop(int i)
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
public void remove(PyObject o) throws PyException
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
public PyByteArray replace(PyObject oldB, PyObject newB)
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
public PyByteArray replace(PyObject oldB, PyObject newB, int maxcount)
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
public int rfind(PyObject sub)
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
public int rfind(PyObject sub, PyObject start)
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
public int rfind(PyObject sub, PyObject start, PyObject end)
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
public int rindex(PyObject sub)
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
public int rindex(PyObject sub, PyObject start)
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
public PyByteArray rjust(int width)
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
public PyByteArray rjust(int width, java.lang.String fillchar)
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
public int rindex(PyObject sub, PyObject start, PyObject end)
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
public PyByteArray 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
public PyByteArray rstrip(PyObject bytes)
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
public boolean startswith(PyObject prefix)
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
public boolean startswith(PyObject prefix, PyObject start)
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
public boolean startswith(PyObject prefix, PyObject start, PyObject end)
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
public PyByteArray 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
public PyByteArray strip(PyObject bytes)
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
public java.lang.String 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.
-
__str__
public PyString __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
public PyByteArray translate(PyObject table)
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
public PyByteArray translate(PyObject table, PyObject deletechars)
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
public PyByteArray zfill(int width)
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
-
-