public abstract class BaseBytes extends PySequence implements List<PyInteger>
bytearray (and bytes in due course) that provides
most of the Java API, including Java List behaviour. Attempts to modify the contents
through this API will throw a TypeError if the actual type of the object is not
mutable. It is possible for a Java client to treat this class as a
List<PyInteger>, obtaining equivalent functionality to the Python interface in a
Java paradigm.
Subclasses must define (from PySequence):
PySequence.pyset(int, PyObject)PySequence.setslice(int, int, int, PyObject)PySequence.del(int)PySequence.delRange(int, int)
Many of the methods implemented here are inherited or thinly wrapped by PyByteArray,
which offers them as Java API, or exposes them as Python methods. These prototype Python methods
mostly accept a PyObject as argument, where you might have expected a byte[]
or BaseBytes, 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
BaseBytes when this broader scope is intended.
Where the methods return a BaseBytes, this is will normally be an instance of the
class of the object on which the method was actually called. For example capitalize(),
defined in BaseBytes to return a BaseBytes, actually returns a PyByteArray
when applied to a bytearray. Or it may be that the method returns a
PyList of instances of the target type, for example rpartition(PyObject).
This is achieved by the sub-class defining getslice(int, int, int) and
getBuilder(int) to return instances of its own type. See the documentation of particular
methods for more information.
PyObject.ConversionExceptiongcMonitorGlobal, TYPE| Constructor and Description |
|---|
BaseBytes(PyType type)
Constructs a zero-length
BaseBytes of explicitly-specified sub-type. |
BaseBytes(PyType type,
int size)
Constructs a zero-filled array of defined size and type.
|
BaseBytes(PyType type,
int[] value)
Constructs a byte array of defined type by copying values from int[].
|
| Modifier and Type | Method and Description |
|---|---|
int |
__len__()
Equivalent to the standard Python __len__ method.
|
PyObject |
__reduce__()
Support for pickling byte arrays: reduce a byte array to the actual type, arguments for
(re-)construction of the object, and the dictionary of any user-defined sub-class.
|
void |
add(int index,
PyInteger element) |
boolean |
add(PyInteger o) |
boolean |
addAll(Collection<? extends PyInteger> c) |
boolean |
addAll(int index,
Collection<? extends PyInteger> c) |
String |
asString()
Present the bytes of a byte array, with no decoding, as a Java String.
|
BaseBytes |
capitalize()
Java API equivalent of Python
capitalize(). |
void |
clear() |
boolean |
contains(Object o)
Returns true if this list contains the specified value.
|
boolean |
containsAll(Collection<?> c) |
PyObject |
decode()
Decode the byte array to a Unicode string according to the default encoding.
|
PyObject |
decode(String encoding)
Decode the byte array to a Unicode string according to the specified encoding and default
error policy.
|
PyObject |
decode(String encoding,
String errors)
Decode the byte array to a Unicode string according to the specified encoding and error
policy.
|
boolean |
equals(Object other)
Test for the equality of (the value of) this byte array to the object
other. |
PyInteger |
get(int index) |
int |
hashCode() |
int |
indexOf(Object o) |
int |
intAt(int index)
Return the Python byte (in range 0 to 255 inclusive) at the given index.
|
boolean |
isalnum()
Java API equivalent of Python
isalnum(). |
boolean |
isalpha()
Java API equivalent of Python
isalpha(). |
boolean |
isdigit()
Java API equivalent of Python
isdigit(). |
boolean |
isEmpty() |
boolean |
islower()
Java API equivalent of Python
islower(). |
boolean |
isspace()
Java API equivalent of Python
isspace(). |
boolean |
istitle()
Java API equivalent of Python
istitle(). |
boolean |
isupper()
Java API equivalent of Python
isupper(). |
Iterator<PyInteger> |
iterator() |
int |
lastIndexOf(Object o) |
ListIterator<PyInteger> |
listIterator() |
ListIterator<PyInteger> |
listIterator(int index) |
BaseBytes |
lower()
Java API equivalent of Python
lower(). |
PyTuple |
partition(PyObject sep)
Implementation of Python
partition(sep), returning a 3-tuple of byte arrays (of
the same type as this). |
void |
pyinsert(int index,
PyObject element)
Insert the element (interpreted as a Python byte value) at the given index.
|
PyInteger |
remove(int index) |
boolean |
remove(Object o) |
boolean |
removeAll(Collection<?> c) |
boolean |
retainAll(Collection<?> c) |
PyTuple |
rpartition(PyObject sep)
Implementation of Python
rpartition(sep), returning a 3-tuple of byte arrays (of
the same type as this). |
PyList |
rsplit()
Implementation of Python
rsplit(), that returns a list of the words in the byte
array, using whitespace as the delimiter. |
PyList |
rsplit(PyObject sep)
Implementation of Python
rsplit(sep), that returns a list of the words in the
byte array, using sep as the delimiter. |
PyList |
rsplit(PyObject sep,
int maxsplit)
Implementation of Python
rsplit(sep, maxsplit), that returns a list of the words
in the byte array, using sep as the delimiter. |
PyInteger |
set(int index,
PyInteger element) |
int |
size()
Number of bytes in
bytearray (or bytes) object. |
PyList |
split()
Implementation of Python
split(), that returns a list of the words in the byte
array, using whitespace as the delimiter. |
PyList |
split(PyObject sep)
Implementation of Python
split(sep), that returns a list of the words in the
byte array, using sep as the delimiter. |
PyList |
split(PyObject sep,
int maxsplit)
Implementation of Python
split(sep, maxsplit), that returns a list of the words
in the byte array, using sep as the delimiter. |
PyList |
splitlines()
Implementation of Python
splitlines(), returning a list of the lines in the byte
array, breaking at line boundaries. |
PyList |
splitlines(boolean keepends)
Implementation of Python
splitlines(keepends), returning a list of the lines in
the string, breaking at line boundaries. |
List<PyInteger> |
subList(int fromIndex,
int toIndex) |
BaseBytes |
swapcase()
Java API equivalent of Python
swapcase(). |
BaseBytes |
title()
Java API equivalent of Python
title(). |
Object[] |
toArray() |
<T> T[] |
toArray(T[] a) |
BaseBytes |
upper()
Java API equivalent of Python
upper(). |
__delitem__, __delslice__, __eq__, __finditem__, __finditem__, __ge__, __getitem__, __getslice__, __gt__, __iter__, __le__, __lt__, __ne__, __nonzero__, __setitem__, __setitem__, __setslice__, __tojava__, isMappingType, isNumberType, isSequenceType__abs__, __add__, __and__, __call__, __call__, __call__, __call__, __call__, __call__, __call__, __call__, __call__, __call__, __call__, __call__, __call__, __call__, __call__, __call__, __cmp__, __coerce__, __coerce_ex__, __complex__, __contains__, __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__, __iadd__, __iand__, __idiv__, __idivmod__, __ifloordiv__, __ilshift__, __imod__, __imul__, __index__, __int__, __invert__, __ior__, __ipow__, __irshift__, __isub__, __iternext__, __itruediv__, __ixor__, __long__, __lshift__, __mod__, __mul__, __neg__, __not__, __oct__, __or__, __pos__, __pow__, __pow__, __radd__, __rand__, __rdiv__, __rdivmod__, __reduce_ex__, __reduce_ex__, __repr__, __rfloordiv__, __rlshift__, __rmod__, __rmul__, __ror__, __rpow__, __rrshift__, __rshift__, __rsub__, __rtruediv__, __rxor__, __set__, __setattr__, __setattr__, __setitem__, __setslice__, __str__, __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, toStringreplaceAll, sort, spliteratorparallelStream, removeIf, streampublic BaseBytes(PyType type)
BaseBytes of explicitly-specified sub-type.type - explicit Jython typepublic BaseBytes(PyType type, int size)
size - requiredtype - explicit Jython typepublic BaseBytes(PyType type, int[] value)
type - explicit Jython typevalue - source of values (and size)public void pyinsert(int index,
PyObject element)
index - to insert atelement - to insert (by value)PyException - (IndexError) if the index is outside the array boundsPyException - (ValueError) if element<0 or element>255PyException - (TypeError) if the subclass is immutablepublic int __len__()
PyObjectpublic String asString()
public PyObject decode()
PyUnicode, since the default codec is well-behaved.public PyObject decode(String encoding)
PyUnicode, but in practice
it is whatever the decode method of the codec decides.encoding - the name of the codec (uses default codec if null)public PyObject decode(String encoding, String errors)
PyUnicode, but in practice it is
whatever the decode method of the codec decides.encoding - the name of the codec (uses default codec if null)errors - the name of the error policy (uses 'strict' if null)public PyObject __reduce__()
__reduce__ in class PyObjectpublic PyTuple partition(PyObject sep)
partition(sep), returning a 3-tuple of byte arrays (of
the same type as this).
Split the string at the first occurrence of sep, and return a 3-tuple containing
the part before the separator, the separator itself, and the part after the separator. If the
separator is not found, return a 3-tuple containing the string itself, followed by two empty
byte arrays.
The elements of the PyTuple returned by this method are instances of the same
actual type as this.
sep - the separator on which to partition this byte arraypublic PyTuple rpartition(PyObject sep)
rpartition(sep), returning a 3-tuple of byte arrays (of
the same type as this).
Split the string at the rightmost occurrence of sep, and return a 3-tuple
containing the part before the separator, the separator itself, and the part after the
separator. If the separator is not found, return a 3-tuple containing two empty byte arrays,
followed by the byte array itself.
The elements of the PyTuple returned by this method are instances of the same
actual type as this.
sep - the separator on which to partition this byte arraypublic PyList rsplit()
rsplit(), that returns a list of the words in the byte
array, using whitespace as the delimiter. See rsplit(PyObject, int).
The elements of the PyList returned by this method are instances of the same
actual type as this.
public PyList rsplit(PyObject sep)
rsplit(sep), that returns a list of the words in the
byte array, using sep as the delimiter. See rsplit(PyObject, int) for
the semantics of the separator.
The elements of the PyList returned by this method are instances of the same
actual type as this.
sep - bytes, or object viewable as bytes, defining the separatorpublic PyList rsplit(PyObject sep, int maxsplit)
rsplit(sep, maxsplit), that returns a list of the words
in the byte array, using sep as the delimiter. If maxsplit is
given, at most maxsplit splits are done (thus, the list will have at most
maxsplit+1 elements). If maxsplit is not specified, then there is
no limit on the number of splits (all possible splits are made).
The semantics of sep and maxcount are identical to those of
split(sep, maxsplit) , except that splits are generated from the right (and
pushed onto the front of the result list). The result is only different from that of
split if maxcount limits the number of splits. For example,
bytearray(b' 1 2 3 ').rsplit() returns
[bytearray(b'1'), bytearray(b'2'), bytearray(b'3')], andbytearray(b' 1 2 3 ').rsplit(None, 1) returns
[bytearray(b' 1 2'), bytearray(b'3')]
The elements of the PyList returned by this method are instances of the same
actual type as this.
sep - bytes, or object viewable as bytes, defining the separatormaxsplit - maximum number of splitspublic PyList split()
split(), that returns a list of the words in the byte
array, using whitespace as the delimiter. See split(PyObject, int).
The elements of the PyList returned by this method are instances of the same
actual type as this.
public PyList split(PyObject sep)
split(sep), that returns a list of the words in the
byte array, using sep as the delimiter. See split(PyObject, int) for
the semantics of the separator.
The elements of the PyList returned by this method are instances of the same
actual type as this.
sep - bytes, or object viewable as bytes, defining the separatorpublic PyList split(PyObject sep, int maxsplit)
split(sep, maxsplit), that returns a list of the words
in the byte array, using sep as the delimiter. If maxsplit is
given, at most maxsplit splits are done. (Thus, the list will have at most
maxsplit+1 elements). If maxsplit is not specified, then there is
no limit on the number of splits (all possible splits are made).
If sep is given, consecutive delimiters are not grouped together and are deemed
to delimit empty strings (for example, '1,,2'.split(',') returns
['1', '', '2']). The sep argument may consist of multiple
characters (for example, '1<>2<>3'.split('<>') returns ['1',
'2', '3']). Splitting an empty string with a specified separator [''].
If sep is not specified or is None, a different splitting algorithm
is applied: runs of consecutive whitespace are regarded as a single separator, and the result
will contain no empty strings at the start or end if the string has leading or trailing
whitespace. Consequently, splitting an empty string or a string consisting of just whitespace
with a None separator returns []. For example,
bytearray(b' 1 2 3 ').split() returns
[bytearray(b'1'), bytearray(b'2'), bytearray(b'3')], andbytearray(b' 1 2 3 ').split(None, 1) returns
[bytearray(b'1'), bytearray(b'2 3 ')].
The elements of the PyList returned by this method are instances of the same
actual type as this.
sep - bytes, or object viewable as bytes, defining the separatormaxsplit - maximum number of splitspublic PyList splitlines()
splitlines(), returning a list of the lines in the byte
array, breaking at line boundaries. Line breaks are not included in the resulting segments.
The elements of the PyList returned by this method are instances of the same
actual type as this.
public PyList splitlines(boolean keepends)
splitlines(keepends), returning a list of the lines in
the string, breaking at line boundaries. Line breaks are not included in the resulting list
unless keepends is true.
The elements of the PyList returned by this method are instances of the same
actual type as this.
keepends - if true, include the end of line bytes(s)public boolean isalnum()
isalnum(). This method treats the bytes as
US-ASCII code points.public boolean isalpha()
isalpha(). This method treats the bytes as
US-ASCII code points.public boolean isdigit()
isdigit(). This method treats the bytes as
US-ASCII code points.public boolean islower()
islower(). This method treats the bytes as
US-ASCII code points.public boolean isspace()
isspace(). This method treats the bytes as
US-ASCII code points.public boolean istitle()
istitle(). This method treats the bytes as
US-ASCII code points.public boolean isupper()
isupper(). This method treats the bytes as
US-ASCII code points.public BaseBytes capitalize()
capitalize(). This method treats the bytes as
US-ASCII code points. The BaseBytes returned by this method has the same actual
type as this/self.public BaseBytes lower()
lower(). This method treats the bytes as US-ASCII
code points. The BaseBytes returned by this method has the same actual type as
this/self.public BaseBytes swapcase()
swapcase(). This method treats the bytes as
US-ASCII code points. The BaseBytes returned by this method has the same actual
type as this/self.public BaseBytes title()
title(). The algorithm uses a simple
language-independent definition of a word as groups of consecutive letters. The definition
works in many contexts but it means that apostrophes in contractions and possessives form
word boundaries, which may not be the desired result. The BaseBytes returned by
this method has the same actual type as this/self.public BaseBytes upper()
upper(). Note that
x.upper().isupper() might be false if the array contains uncased
characters. The BaseBytes returned by this method has the same actual type as
this/self.public int intAt(int index)
throws PyException
index - of value in byte arrayPyException - (IndexError) if the index is outside the array boundspublic int size()
bytearray (or bytes) object.size in interface Collection<PyInteger>size in interface List<PyInteger>List.size()public boolean isEmpty()
public boolean contains(Object o)
public Object[] toArray()
public <T> T[] toArray(T[] a)
public boolean add(PyInteger o)
public boolean remove(Object o)
public boolean containsAll(Collection<?> c)
containsAll in interface Collection<PyInteger>containsAll in interface List<PyInteger>public boolean addAll(Collection<? extends PyInteger> c)
public boolean addAll(int index,
Collection<? extends PyInteger> c)
public boolean removeAll(Collection<?> c)
public boolean retainAll(Collection<?> c)
public void clear()
public boolean equals(Object other)
other. In
the case where other is a PyObject, the comparison used is the
standard Python == operation through PyObject. When
other is not a PyObject, this object acts as a
List<PyInteger>.equals in interface Collection<PyInteger>equals in interface List<PyInteger>equals in class PyObjectother - object to compare this byte array totrue if and only if this byte array is equal (in value) to
otherList.equals(java.lang.Object)public int hashCode()
public int lastIndexOf(Object o)
lastIndexOf in interface List<PyInteger>public ListIterator<PyInteger> listIterator()
listIterator in interface List<PyInteger>public ListIterator<PyInteger> listIterator(int index)
listIterator in interface List<PyInteger>