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):
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 getResult(Builder) to return instances of
its own type. See the documentation of the particular methods for more information.
| Modifier and Type | Class and Description |
|---|---|
| protected static class | BaseBytes.
A |
| protected static class | BaseBytes.
Class for quickly determining whether a given byte is a member of a defined set. |
| protected static class | BaseBytes.
This class implements the Boyer-Moore-Horspool Algorithm for finding a pattern in text, applied to byte arrays. |
| protected static class | BaseBytes.
Intended as a fragment of temporary storage for use we do not know how many bytes of allocate, and we are reading in some kind of iterable stream. |
| protected static class | BaseBytes.
A container of temporary storage when we do not know how many bytes to allocate, and we are reading in some kind of iterable stream. |
| private class | BaseBytes.
Class defining the behaviour of |
| protected static class | BaseBytes.
This class is the complement of |
| Modifier and Type | Field and Description |
|---|---|
| private static final byte | |
| private static final byte | |
| private static final byte[] | |
| private static final byte | |
| protected static final byte[] | emptyStorage
Empty storage constant |
| protected final List | listDelegate
Access to the byte array as a |
| private static final byte | |
| protected int | offset
Index of first byte used in storage array. |
| private static PyString | |
| protected int | size
Number of bytes actually used in storage array. |
| private static final byte | |
| protected byte[] | storage
Storage array. |
| private static final int | |
| private static final byte |
| Access | Constructor and Description |
|---|---|
| public | |
| public | |
| public | |
| protected |
| Modifier and Type | Method and Description |
|---|---|
| public int | __len__()
Overrides org. Equivalent to the standard Python __len__ method. |
| public PyObject | Returns: PyTuple that is first stage in pickling byte arrayOverrides org. 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. |
| public boolean | add(PyInteger
element to be appended to this list o)Implements java. Appends the specified element to the end of this list (optional operation). |
| public void | add(int
index at which the specified element is to be inserted index, PyInteger element to be inserted element)Implements java. Inserts the specified element at the specified position in this list (optional operation). |
| public boolean | addAll(Collection<? extends PyInteger>
collection containing elements to be added to this list c)Implements java. Appends all of the elements in the specified collection to the end of this list, in the order that they are returned by the specified collection's iterator (optional operation). |
| public boolean | addAll(int
index at which to insert the first element from the
specified collection index, Collection<? extends PyInteger> collection containing elements to be added to this list c)Implements java. Inserts all of the elements in the specified collection into this list at the specified position (optional operation). |
| private static final void | appendHexEscape(StringBuilder
destination for characters buf, int curren (maybe unprintable) character c)Helper for __repr__() |
| public synchronized String | Returns: the byte array as a StringOverrides org. Present the bytes of a byte array, with no decoding, as a Java String. |
| protected final synchronized boolean | Returns: true iff foundbyte value to search for target)Search for the target in this byte array, returning true if found and false if not. |
| pack-priv final PyObject | Returns: Python boolean result ornull if not implemented for the other type.Python object to compare with other)Implementation of __eq__ (equality) operator, capable of comparison with another byte array. |
| pack-priv final PyObject | Returns: Python boolean result ornull if not implemented for the other type.Python object to compare with other)Implementation of __ge__ (greater than or equal to) operator, capable of comparison with another byte array. |
| pack-priv final PyObject | Returns: Python boolean result ornull if not implemented for the other type.Python object to compare with other)Implementation of __gt__ (greater than) operator, capable of comparison with another byte array. |
| pack-priv final PyObject | Returns: Python boolean result ornull if not implemented for the other type.Python object to compare with other)Implementation of __le__ (less than or equal to) operator, capable of comparison with another byte array. |
| pack-priv final PyObject | Returns: Python boolean result ornull if not implemented for the other type.Python object to compare with other)Implementation of __lt__ (less than) operator, capable of comparison with another byte array. |
| pack-priv final PyObject | Returns: Python boolean result ornull if not implemented for the other type.Python object to compare with other)Implementation of __ne__ (not equals) operator, capable of comparison with another byte array. |
| pack-priv final PyTuple | Returns: required tuple of type, arguments needed by init, and any user-added attributes.Ready-to-expose implementation of Python __reduce__() method used in pickle (persistence) of Python objects. |
| pack-priv final BaseBytes | Returns: a copy of the array with its first character capitalized and the rest lowercased.Ready-to-expose implementation of Python |
| pack-priv final BaseBytes | Returns: (possibly new) byte array containing the resultdesired width, String one-byte String to fill with, or fillchar)null implying spaceA ready-to-expose implementation of Python |
| private synchronized int | Returns: 1, 0 or -1 as this>b, this==b, or this<b respectively, or -2 if the comparison is not implementedComparison function between byte array types and any other object. |
| private synchronized int | Returns: 0 if this==b, or +1 or -1 if this!=b, or -2 if the comparison is not implementedFail-fast comparison function between byte array types and any other object, for when the test is only for equality. |
| pack-priv final int | Returns: count of occurrences of sub within this byte arraybytes to find sub, PyObject of slice to search ostart, PyObject of slice to search oend)Ready-to-expose implementation of Python |
| protected final PyObject | Returns: object containing the decoded charactersPython argument list args, String[] Assocaited keywords keywords)Ready-to-expose implementation of decode( [ encoding [, errors ]] ) |
| pack-priv final BaseBytes | Returns: copy of this byte array with tabs expandednumber of character positions between tab stops tabsize)Ready-to-expose implementation of Python |
| pack-priv final int | Returns: index of start of occurrence of sub within this byte arraybytes to find sub, PyObject of slice to search ostart, PyObject of slice to search oend)Ready-to-expose implementation of Python |
| pack-priv static void | basebytes_fromhex(BaseBytes
to receive the decoded values result, String specification of the bytes hex)Almost ready-to-expose implementation of Python class method |
| pack-priv final boolean | Returns: true if all bytes in the array are code points for alphanumerics and there is at least one byte, false otherwise.Ready-to-expose implementation of Python |
| pack-priv final boolean | Returns: true if all bytes in the array are alphabetic and there is at least one byte, false otherwiseReady-to-expose implementation of Python |
| pack-priv final boolean | Returns: true if all bytes in the array are code points for digits and there is at least one byte, false otherwise.Ready-to-expose implementation of Python |
| pack-priv final boolean | Returns: true if all cased bytes in the array are code points for lowercase characters and there is at least one cased byte, false otherwise.Ready-to-expose implementation of Python |
| pack-priv final boolean | Returns: true if all the bytes in the array are code points for whitespace characters and there is at least one byte, false otherwise.Ready-to-expose implementation of Python |
| pack-priv final boolean | Returns: true if the string is a titlecased string and there is at least one cased byte, for example uppercase characters may only follow uncased bytes and lowercase characters only cased ones. Return false otherwise.Ready-to-expose implementation of Python |
| pack-priv final boolean | Returns: true if all cased bytes in the array are code points for uppercase characters and there is at least one cased byte, false otherwise.Ready-to-expose implementation of Python |
| pack-priv final synchronized PyByteArray | Returns: the byte array that is their joiniterable of objects capable of being regarded as byte arrays iter)Almost ready-to-expose implementation of Python |
| pack-priv final BaseBytes | Returns: (possibly new) byte array containing the resultdesired width, String one-byte String to fill with, or fillchar)null implying spaceA ready-to-expose implementation of Python |
| pack-priv final BaseBytes | Returns: a copy of the array with all the cased characters converted to lowercase.Ready-to-expose implementation of Python |
| pack-priv final synchronized PyTuple | Returns: a tuple of (head, separator, tail)the separator on which to partition this byte array sep)Ready-to-expose implementation of Python |
| pack-priv final synchronized PyByteArray | Returns: result of replacement as a new PyByteArraysequence to find oldB, PyObject relacement sequence newB, int maximum occurrences are replaced or < 0 for all maxcount)An almost ready-to-expose implementation of Python |
| pack-priv final synchronized String | Returns: string representation:before + "'" + String(this) + "'" + afterString to insert before the quoted text before, String String to insert after the quoted text after)Almost ready-to-expose Python |
| pack-priv final int | Returns: index of start of occurrence of sub within this byte arraybytes to find sub, PyObject of slice to search ostart, PyObject of slice to search oend)Ready-to-expose implementation of Python |
| pack-priv final BaseBytes | Returns: (possibly new) byte array containing the resultdesired width, String one-byte String to fill with, or fillchar)null implying spaceA ready-to-expose implementation of Python |
| pack-priv final synchronized PyTuple | Returns: a tuple of (head, separator, tail)the separator on which to partition this byte array sep)Ready-to-expose implementation of Python |
| pack-priv final PyList | Returns: PyList of byte arrays that result from the splitbytes, or object viewable as bytes, defining the separatormaximum number of splits maxsplit)Ready-to-expose implementation of Python |
| pack-priv final synchronized PyList | Returns: PyList of byte arrays that result from the splitbytes, or object viewable as bytes, defining the separatormaximum number of splits maxsplit)Implementation of Python |
| pack-priv final synchronized PyList | Returns: PyList of byte arrays that result from the splitmaximum number of splits maxsplit)Implementation of Python |
| pack-priv final PyList | Returns: PyList of byte arrays that result from the splitbytes, or object viewable as bytes, defining the separatormaximum number of splits maxsplit)Ready-to-expose implementation of Python |
| pack-priv final synchronized PyList | Returns: PyList of byte arrays that result from the splitbytes, or object viewable as bytes, defining the separatormaximum number of splits maxsplit)Implementation of Python |
| pack-priv final synchronized PyList | Returns: PyList of byte arrays that result from the splitmaximum number of splits maxsplit)Implementation of Python |
| protected final synchronized PyList | Returns: List of segmentsif true, include the end of line bytes(s) keepends)Ready-to-expose implementation of Python |
| protected final synchronized boolean | Returns: true if and only if this byte array ends with (one of)target.prefix or suffix sequence to find (of a type viewable as a byte sequence) or a
tuple of those. target, PyObject of slice to search. ostart, PyObject of slice to search. oend, boolean true if we are doing endswith, false if startswith. endswith)Almost ready-to-expose implementation serving both Python
|
| pack-priv final BaseBytes | Returns: a copy of the array with uppercase characters converted to lowercase and vice versa.Ready-to-expose implementation of Python |
| pack-priv final BaseBytes | Returns: a titlecased version of the array where words start with an uppercase character and the remaining characters are lowercase.Ready-to-expose implementation of Python |
| pack-priv final BaseBytes | Returns: a copy of the array with all the cased characters converted to uppercase.Ready-to-expose implementation of Python |
| pack-priv final BaseBytes | Returns: left-filled byte arraydesired width)Ready-to-expose implementation of Python |
| private final synchronized byte | |
| protected static final byte | byteCheck(int
to convert. value)Check that an integer is suitable for storage in a (Python) byte array, and convert it to the Java byte value that can be stored there. |
| protected static final byte | |
| protected static final byte | |
| public BaseBytes | Returns: a copy of the array with its first character capitalized and the rest lowercased.Java API equivalent of Python |
| protected static final int | Returns: the length of the separatorview to test separator)Convenience routine producing a ValueError for "empty separator" if the PyBuffer is of an object with zero length, and returning the length otherwise. |
| public void | clear()
Implements java. Removes all of the elements from this list (optional operation). |
| private static int | Returns: 1, 0 or -1 as a>b, a==b, or a<b respectivelyleft-hand array in the comparison a, PyBuffer right-hand wrapped object in the comparison b)Comparison function between a byte array and a buffer of bytes exported by some other object,
such as a String, presented as a |
| pack-priv static PyException | Returns: PyException (TypeError) as detailedConvenience method to create a |
| public boolean | contains(Object
element whose presence in this list is to be tested o)Implements java. Returns true if this list contains the specified value. |
| public boolean | containsAll(Collection<?>
collection to be checked for containment in this list c)Implements java. Returns |
| public PyObject | Returns: object containing the decoded charactersDecode the byte array to a Unicode string according to the default encoding. |
| public PyObject | |
| public PyObject | |
| protected static String | Returns: encoded stringprimary argument from which value is taken arg, String name of optional encoding encoding, String name of optional errors policy errors)Helper for |
| public boolean | Returns: true if and only if this byte array is equal (in value) to otherobject to compare this byte array to other)Overrides org. Implements java. Test for the equality of (the value of) this byte array to the object |
| protected static byte | Returns: the (checked) single fill bytename function, String or fillchar)nullHelper to check the fill byte for |
| private final int | Returns: index of start of occurrence of sub within this byte arrayfor the bytes to find, sometime forwards, sometime backwards finder,of slice to search ostart, PyObject of slice to search oend)Common code for Python |
| public PyInteger | get(int
index of the element to return index)Implements java. Returns the element at the specified position in this list. |
| private static final PyString | getPickleEncoding()
Name the encoding effectively used in __reduce__() suport for pickling: this choice is hard-coded in CPython as "latin-1". |
| protected abstract BaseBytes | |
| protected abstract BaseBytes | getslice(int
the position of the first element. start, int one more than the position of the last element. stop, int the step size. step)Implements abstract org. Returns a range of elements from the sequence. |
| protected BaseBytes | Returns: a subclass instance of BaseBytes corresponding the the given range of elements.the position of the first element. start, int one more than the position of the last element. stop)Specialisation of |
| protected static PyBuffer | |
| protected static PyBuffer | Returns: byte-oriented viewobject to wrap b)Return a buffer exported by the argument or raise an exception if it does not bear the buffer API. |
| public int | hashCode()
Overrides org. Implements java. Returns the hash code value for this list. |
| private static int | |
| protected int | Returns: index in the byte array (0..size-1) or -1 if not foundbyte to search for b)The very simplest kind of find operation: return the index in the byte array of the first occurrence of the byte value |
| protected final void | indexCheck(int
to check index)Check that an index is within the range of the array, that is 0<=index<size. |
| public int | indexOf(Object
element to search for o)Implements java. Returns the index of the first occurrence of the specified element in this list, or -1 if this list does not contain the element. |
| private int[] | |
| protected void | |
| protected void | init(PyString
primary argument from which value is taken arg, PyObject name of optional encoding (must be a string type) encoding, PyObject name of optional errors policy (must be a string type) errors)Helper for |
| protected void | |
| protected void | init(int
size of zero-filled array n)Helper for |
| protected void | init(BufferProtocol
an object bearing the Buffer API and consistent with the slice assignment value)Helper for |
| protected void | |
| protected void | |
| private boolean | Returns: true iff value allows the getBufferan object possibly bearing the Buffer API value)Helper for |
| public synchronized int | Returns: the integer value at the indexof value in byte array index)Return the Python byte (in range 0 to 255 inclusive) at the given index. |
| pack-priv static final boolean | |
| public boolean | Returns: true if all bytes in the array are code points for alphanumerics and there is at least one byte, false otherwise.Java API equivalent of Python |
| pack-priv static final boolean | |
| public boolean | Returns: true if all bytes in the array are alphabetic and there is at least one byte, false otherwiseJava API equivalent of Python |
| pack-priv static final boolean | |
| public boolean | Returns: true if all bytes in the array are code points for digits and there is at least one byte, false otherwise.Java API equivalent of Python |
| public boolean | |
| pack-priv static final boolean | |
| public boolean | Returns: true if all cased bytes in the array are code points for lowercase characters and there is at least one cased byte, false otherwise.Java API equivalent of Python |
| pack-priv static final boolean | |
| public boolean | Returns: true if all the bytes in the array are code points for whitespace characters and there is at least one byte, false otherwise.Java API equivalent of Python |
| public boolean | Returns: true if the string is a titlecased string and there is at least one cased byte, for example uppercase characters may only follow uncased bytes and lowercase characters only cased ones. Return false otherwise.Java API equivalent of Python |
| pack-priv static final boolean | |
| public boolean | Returns: true if all cased bytes in the array are code points for uppercase characters and there is at least one cased byte, false otherwise.Java API equivalent of Python |
| public Iterator | iterator()
Implements java. Returns an iterator over the elements in this list in proper sequence. |
| public int | lastIndexOf(Object
element to search for o)Implements java. Returns the index of the last occurrence of the specified element in this list, or -1 if this list does not contain the element. |
| public ListIterator | listIterator()
Implements java. Returns a list iterator over the elements in this list (in proper sequence). |
| public ListIterator | listIterator(int
index of the first element to be returned from the
list iterator (by a call to index)next)Implements java. Returns a list iterator over the elements in this list (in proper sequence), starting at the specified position in the list. |
| public BaseBytes | Returns: a copy of the array with all the cased characters converted to lowercase.Java API equivalent of Python |
| protected int | Returns: index of first unstrippable byteset of byte values to skip over byteSetReturn the index [0..size-1] of the leftmost byte not matching any in |
| protected int | Returns: index of first non-whitespace byteReturn the index [0..size-1] of the leftmost non-whitespace byte, or |
| private boolean | Returns: true if and only if the slicethis[pos:pos+n] matches the given targetpattern to match target, int at which to start the comparison pos, int n, boolean endswith)Test whether the slice |
| protected void | newStorage(int
becomes the new value of this.size needed)Allocate fresh, zero-filled storage for the requested number of bytes and make that the size. |
| private BaseBytes | Returns: (possibly new) byte array containing the resultbyte to fill with pad, int padding requested left, int padding requested right)Helper function to construct the return value for |
| public PyTuple | |
| private PyTuple | Returns: ([0:p], [p:q], [q:])start of separator p, int start of tail q)Construct return value for implementation of Python
The elements of the |
| protected PyInteger | pyget(int
index of element to return. index)Implements abstract org. Returns the element of the sequence at the given index. |
| public void | |
| public boolean | remove(Object
element to be removed from this list, if present o)Implements java. Removes the first occurrence of the specified element from this list, if it is present (optional operation). |
| public PyInteger | remove(int
the index of the element to be removed index)Implements java. Removes the element at the specified position in this list (optional operation). |
| public boolean | removeAll(Collection<?>
collection containing elements to be removed from this list c)Implements java. Removes from this list all of its elements that are contained in the specified collection (optional operation). |
| protected abstract BaseBytes | repeat(int
the number of times to repeat the sequence. count)Implements abstract org. Returns a (concrete subclass of) PySequence that repeats the given sequence, as in the
implementation of |
| private PyByteArray | Returns: the result as a new PyByteArraybyte-string to find and delete from, int maximum number of deletions to make maxcount)Helper for |
| private PyByteArray | replace_interleave(PyBuffer
the replacement bytes as a byte-oriented view to, int upper limit on number of insertions maxcount)Handle the interleaving case b'hello'.replace(b'', b'..') = b'..h..e..l..l..o..' At the call site we are guaranteed: size>=1, to.getLen()>=1, maxcount>=1 |
| private PyByteArray | Returns: the result as a new PyByteArraybyte-string to find and replace from, PyBuffer replacement byte-string to, int maximum number of replacements to make maxcount)Helper for |
| private PyByteArray | Returns: the result as a new PyByteArraybyte-string to find and replace from, PyBuffer replacement byte-string to, int maximum number of replacements to make maxcount)Helper for |
| public boolean | retainAll(Collection<?>
collection containing elements to be retained in this list c)Implements java. Retains only the elements in this list that are contained in the specified collection (optional operation). |
| protected static final int | Returns: n ≥ size a recommended storage array sizeof storage actually needed size)Choose a size appropriate to store the given number of bytes, with some room for growth, when
allocating storage for mutable types or |
| public PyTuple | Returns: a tuple of (head, separator, tail)the separator on which to partition this byte array sep)Implementation of Python |
| public PyList | Returns: PyList of byte arrays that result from the splitImplementation of Python |
| public PyList | |
| public PyList | Returns: PyList of byte arrays that result from the splitbytes, or object viewable as bytes, defining the separatormaximum number of splits maxsplit)Implementation of Python |
| protected int | Returns: index of strippable tailset of byte values to strip byteSetReturn the index [0..size-1] such that all bytes from here to the right match one in
|
| protected int | Returns: index of strippable tailReturn the index [0..size-1] such that all bytes from here to the right are whitespace, that
is, the index of the whitespace tail, or |
| public PyInteger | set(int
index of the element to replace index, PyInteger element to be stored at the specified position element)Implements java. Replaces the element at the specified position in this list with the specified element (optional operation). |
| protected void | |
| protected void | |
| protected void | setStorage(byte[]
byte array allocated by client storage, int number of bytes actually used size, int index of first byte used offset)Helper for constructors and methods that manipulate the storage in mutable subclasses. |
| protected void | setStorage(byte[]
byte array allocated by client storage, int number of bytes actually used size)Helper for constructors and methods that manipulate the storage in mutable subclasses in the case where the storage should consist of the first part of the given array. |
| protected void | setStorage(byte[]
byte array allocated by client storage)Helper for constructors and methods that manipulate the storage in mutable subclasses in the case where the storage should consist of exactly the whole of the given array. |
| public int | Returns: Number of bytes in byte array.Implements java. Number of bytes in |
| public PyList | Returns: PyList of byte arrays that result from the splitImplementation of Python |
| public PyList | |
| public PyList | |
| public PyList | Returns: List of segmentsImplementation of Python |
| public PyList | Returns: PyList of segmentsif true, include the end of line bytes(s) keepends)Implementation of Python |
| public List | subList(int
low endpoint (inclusive) of the subList fromIndex, int high endpoint (exclusive) of the subList toIndex)Implements java. Returns a view of the portion of this list between the specified
|
| public BaseBytes | Returns: a copy of the array with uppercase characters converted to lowercase and vice versa.Java API equivalent of Python |
| public BaseBytes | Returns: a titlecased version of the array where words start with an uppercase character and the remaining characters are lowercase.Java API equivalent of Python |
| public Object[] | toArray()
Implements java. Returns an array containing all of the elements in this list in proper sequence (from first to last element). |
| public <T> T[] | toArray(T[]
the array into which the elements of this list are to
be stored, if it is big enough; otherwise, a new array of the
same runtime type is allocated for this purpose. a)Implements java. Returns an array containing all of the elements in this list in proper sequence (from first to last element); the runtime type of the returned array is that of the specified array. |
| public BaseBytes | Returns: a copy of the array with all the cased characters converted to uppercase.Java API equivalent of Python |