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 Pythonbytearray
with a Java API that includes equivalents to most of the Python API. These Python equivalents accept aPyObject
as argument, where you might have expected abyte[]
orPyByteArray
, in order to accommodate the full range of types accepted by the Python equivalent: usually, anyPyObject
that 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 ofbytearray
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:
- 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 PyType
TYPE
ThePyType
ofbytearray
.-
Fields inherited from class org.python.core.PyObject
gcMonitorGlobal
-
-
Constructor Summary
Constructors Constructor Description PyByteArray()
Constructs 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(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 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, 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 Pythonbytearray
of 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 thein
operator.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.void
append(byte element)
Append a single byte to the end of the array.void
append(PyObject element)
Append a single element to the end of the array, equivalent to:s[len(s):len(s)] = o
.PyByteArray
center(int width)
Java API equivalent of Pythoncenter(width)
: return the bytes centered in an array of lengthwidth
, padded by spaces.PyByteArray
center(int width, java.lang.String fillchar)
Java API equivalent of Pythoncenter(width [, fillchar])
: return the bytes centered in an array of lengthwidth
.int
count(PyObject sub)
Implementation of Pythoncount(sub)
.int
count(PyObject sub, PyObject start)
Implementation of Pythoncount( sub [, start ] )
.int
count(PyObject sub, PyObject start, PyObject end)
Implementation of Pythoncount( sub [, start [, end ]] )
.boolean
endswith(PyObject suffix)
Implementation of Pythonendswith(suffix)
.boolean
endswith(PyObject suffix, PyObject start)
Implementation of Pythonendswith( suffix [, start ] )
.boolean
endswith(PyObject suffix, PyObject start, PyObject end)
Implementation of Pythonendswith( suffix [, start [, end ]] )
.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.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.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
.int
find(PyObject sub)
Implementation of Pythonfind(sub)
.int
find(PyObject sub, PyObject start)
Implementation of Pythonfind( sub [, start ] )
.int
find(PyObject sub, PyObject start, PyObject end)
Implementation of Pythonfind( sub [, start [, end ]] )
.PyBuffer
getBuffer(int flags)
Method by which the consumer requests the buffer from the exporter.int
hashCode()
This type is not hashable.int
index(PyObject sub)
Implementation of Pythonindex(sub)
.int
index(PyObject sub, PyObject start)
Implementation of Pythonindex( sub [, start ] )
.int
index(PyObject sub, PyObject start, PyObject end)
Implementation of Pythonindex( sub [, start [, end ]] )
.void
insert(PyObject index, PyObject value)
Insert the argument element into the byte array at the specified index.PyByteArray
join(PyObject iterable)
Implementation of Pythonjoin(iterable)
.PyByteArray
ljust(int width)
Java API equivalent of Pythonljust(width)
: return the bytes left justified in an array of lengthwidth
, padded by spaces.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
.PyByteArray
lstrip()
Implementation of Pythonlstrip()
.PyByteArray
lstrip(PyObject bytes)
Implementation of Pythonlstrip(bytes)
Return a copy of the byte array with the leading characters removed.PyInteger
pop()
Remove and return the last element in the byte array.PyInteger
pop(int i)
Remove and return then
th byte element in the array.void
pyinsert(int index, PyObject element)
Insert the element (interpreted as a Python byte value) at the given index.void
pyset(int index, PyObject value)
Sets the indexed element of thebytearray
to the given value.void
remove(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.PyByteArray
replace(PyObject oldB, PyObject newB)
An implementation of Pythonreplace( old, new )
, returning aPyByteArray
with all occurrences of sequenceoldB
replaced bynewB
.PyByteArray
replace(PyObject oldB, PyObject newB, int maxcount)
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
rfind(PyObject sub)
Implementation of Pythonrfind(sub)
.int
rfind(PyObject sub, PyObject start)
Implementation of Pythonrfind( sub [, start ] )
.int
rfind(PyObject sub, PyObject start, PyObject end)
Implementation of Pythonrfind( sub [, start [, end ]] )
.int
rindex(PyObject sub)
Implementation of Pythonrindex(sub)
.int
rindex(PyObject sub, PyObject start)
Implementation of Pythonrindex( sub [, start ] )
.int
rindex(PyObject sub, PyObject start, PyObject end)
Implementation of Pythonrindex( sub [, start [, end ]] )
.PyByteArray
rjust(int width)
Java API equivalent of Pythonrjust(width)
: return the bytes right justified in an array of lengthwidth
, padded by spaces.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
.PyByteArray
rstrip()
Implementation of Pythonrstrip()
.PyByteArray
rstrip(PyObject bytes)
Implementation of Pythonrstrip(bytes)
Return a copy of the byte array with the trailing characters removed.static PyException
SliceSizeError(java.lang.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 ]] )
.PyByteArray
strip()
Implementation of Pythonstrip()
.PyByteArray
strip(PyObject bytes)
Implementation of Pythonstrip(bytes)
Return a copy of the byte array with the leading and trailing characters removed.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.PyByteArray
translate(PyObject table)
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.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 argumentdeletechars
are removed, and the remaining bytes have been mapped through the given translation table, which must be of length 256.PyByteArray
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__, __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 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
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 benull
to 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 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:
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 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 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
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
public void pyset(int index, PyObject value) throws PyException
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
public void pyinsert(int index, PyObject element)
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
public static PyException SliceSizeError(java.lang.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}"- 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: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__
public PyObject __ne__(PyObject other)
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__
public PyObject __lt__(PyObject other)
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__
public PyObject __le__(PyObject other)
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__
public PyObject __ge__(PyObject other)
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__
public PyObject __gt__(PyObject other)
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__
public PyObject __add__(PyObject o)
Description copied from class:PyObject
Equivalent 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 thein
operator.- 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 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
public int count(PyObject sub)
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
public int count(PyObject sub, PyObject start)
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
public int count(PyObject sub, PyObject start, PyObject end)
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
public boolean endswith(PyObject suffix)
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
public boolean endswith(PyObject suffix, PyObject start)
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
public boolean endswith(PyObject suffix, PyObject start, PyObject end)
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
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 ofBaseBytes
or 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 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
public int find(PyObject sub, PyObject start)
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
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 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__
public PyObject __iadd__(PyObject o)
Description copied from class:PyObject
Equivalent to the standard Python __iadd__ method.
-
index
public int index(PyObject sub)
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
public int index(PyObject sub, PyObject start)
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
public int hashCode() throws PyException
This type is not hashable.- Specified by:
hashCode
in interfacejava.util.Collection<PyInteger>
- Specified by:
hashCode
in interfacejava.util.List<PyInteger>
- Overrides:
hashCode
in 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.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
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 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
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 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
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. 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
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 then
th 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 aPyByteArray
with all occurrences of sequenceoldB
replaced 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 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
public int rfind(PyObject sub)
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
public int rfind(PyObject sub, PyObject start)
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
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 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
public int rindex(PyObject sub)
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
public int rindex(PyObject sub, PyObject start)
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
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 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
public int rindex(PyObject sub, PyObject start, PyObject end)
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
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. 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
public boolean startswith(PyObject prefix)
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
public boolean startswith(PyObject prefix, PyObject start)
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
public boolean startswith(PyObject prefix, PyObject start, PyObject end)
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
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. 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
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 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
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 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
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
-
-