public abstract class BaseBytes extends PySequence implements java.util.List<PyInteger>
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
):
PyObject.ConversionException
Constructor and Description |
---|
BaseBytes(PyType type)
Simple constructor of empty zero-length array of defined type.
|
BaseBytes(PyType type,
int size)
Simple constructor of zero-filled array of defined size and type.
|
BaseBytes(PyType type,
int[] value)
Construct 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(java.util.Collection<? extends PyInteger> c) |
boolean |
addAll(int index,
java.util.Collection<? extends PyInteger> c) |
java.lang.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(java.lang.Object o)
Returns true if this list contains the specified value.
|
boolean |
containsAll(java.util.Collection<?> c) |
PyObject |
decode()
Decode the byte array to a Unicode string according to the default encoding.
|
PyObject |
decode(java.lang.String encoding)
Decode the byte array to a Unicode string according to the specified encoding and default
error policy.
|
PyObject |
decode(java.lang.String encoding,
java.lang.String errors)
Decode the byte array to a Unicode string according to the specified encoding and error
policy.
|
boolean |
equals(java.lang.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(java.lang.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() . |
java.util.Iterator<PyInteger> |
iterator() |
int |
lastIndexOf(java.lang.Object o) |
java.util.ListIterator<PyInteger> |
listIterator() |
java.util.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(java.lang.Object o) |
boolean |
removeAll(java.util.Collection<?> c) |
boolean |
retainAll(java.util.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. |
java.util.List<PyInteger> |
subList(int fromIndex,
int toIndex) |
BaseBytes |
swapcase()
Java API equivalent of Python
swapcase() . |
BaseBytes |
title()
Java API equivalent of Python
title() . |
java.lang.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__, __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, noAttributeError, object___subclasshook__, readonlyAttributeError, setDict, setType, toString
public BaseBytes(PyType 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__()
PyObject
public java.lang.String asString()
public PyObject decode()
PyUnicode
, since the default codec is well-behaved.public PyObject decode(java.lang.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(java.lang.String encoding, java.lang.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 PyObject
public 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.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.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)
.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.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')]
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)
.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.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 returns [''].
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 ')]
.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.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.keepends
- if true, include the end of line bytes(s)public boolean isalnum()
isalnum()
. This method treats the bytes as Unicode
pont codes and is consistent with Java's Character.isLetterOrDigit(char)
.public boolean isalpha()
isalpha()
. This method treats the bytes as Unicode
pont codes and is consistent with Java's Character.isLetter(char)
.public boolean isdigit()
isdigit()
. This method treats the bytes as Unicode
pont codes and is consistent with Java's Character.isDigit(char)
.public boolean islower()
islower()
. This method treats the bytes as Unicode
pont codes and is consistent with Java's Character.isLowerCase(char)
.public boolean isspace()
isspace()
. This method treats the bytes as Unicode
pont codes and is consistent with Java's Character.isWhitespace(char)
.public boolean istitle()
istitle()
. This method treats the bytes as Unicode
pont codes and is consistent with Java's Character.isUpperCase(char)
and
Character.isLowerCase(char)
.public boolean isupper()
isupper()
. This method treats the bytes as Unicode
pont codes and is consistent with Java's Character.isUpperCase(char)
.public BaseBytes capitalize()
capitalize()
. This method treats the bytes as
Unicode pont codes and is consistent with Java's Character.toUpperCase(char)
and
Character.toLowerCase(char)
.public BaseBytes lower()
lower()
. This method treats the bytes as Unicode
pont codes and is consistent with Java's Character.toLowerCase(char)
.public BaseBytes swapcase()
swapcase()
. This method treats the bytes as
Unicode pont codes and is consistent with Java's Character.toUpperCase(char)
and
Character.toLowerCase(char)
.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.public BaseBytes upper()
upper()
. Note that
x.upper().isupper()
might be false
if the array contains uncased
characters.public int intAt(int index) throws PyException
index
- of value in byte arrayPyException(IndexError)
- if the index is outside the array boundsPyException
public int size()
public boolean isEmpty()
public boolean contains(java.lang.Object o)
public java.util.Iterator<PyInteger> iterator()
public java.lang.Object[] toArray()
public <T> T[] toArray(T[] a)
public boolean add(PyInteger o)
public boolean remove(java.lang.Object o)
public boolean containsAll(java.util.Collection<?> c)
public boolean addAll(java.util.Collection<? extends PyInteger> c)
public boolean addAll(int index, java.util.Collection<? extends PyInteger> c)
addAll
in interface java.util.List<PyInteger>
public boolean removeAll(java.util.Collection<?> c)
public boolean retainAll(java.util.Collection<?> c)
public void clear()
public boolean equals(java.lang.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 java.util.Collection<PyInteger>
equals
in interface java.util.List<PyInteger>
equals
in class PyObject
other
- object to compare this byte array totrue
if and only if this byte array is equal (in value) to
other
List.equals(java.lang.Object)
public int hashCode()
public PyInteger set(int index, PyInteger element)
set
in interface java.util.List<PyInteger>
public void add(int index, PyInteger element)
add
in interface java.util.List<PyInteger>
public PyInteger remove(int index)
remove
in interface java.util.List<PyInteger>
public int indexOf(java.lang.Object o)
indexOf
in interface java.util.List<PyInteger>
public int lastIndexOf(java.lang.Object o)
lastIndexOf
in interface java.util.List<PyInteger>
public java.util.ListIterator<PyInteger> listIterator()
listIterator
in interface java.util.List<PyInteger>
public java.util.ListIterator<PyInteger> listIterator(int index)
listIterator
in interface java.util.List<PyInteger>