Class 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 Python bytearray with a Java API that includes equivalents to most of the Python API. These Python equivalents accept a PyObject as argument, where you might have expected a byte[] or PyByteArray, 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 bytearray 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
    • Field Detail

      • TYPE

        public static final PyType TYPE
        The PyType of bytearray.
    • Constructor Detail

      • PyByteArray

        public PyByteArray​(PyType type)
        Constructs a zero-length Python bytearray of explicitly-specified sub-type
        Parameters:
        type - explicit Jython type
      • PyByteArray

        public PyByteArray()
        Constructs a zero-length Python bytearray.
      • PyByteArray

        public PyByteArray​(int size)
        Constructs zero-filled Python bytearray of specified size.
        Parameters:
        size - of bytearray
      • PyByteArray

        public PyByteArray​(int[] value)
        Constructs a bytearray 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 a bytearray (or bytes).
        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 taken
        encoding - 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 taken
        encoding - name of optional encoding (may be null 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 a bytearray 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 a bytearray 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
        size - 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 new bytearray object from an arbitrary Python object according to the same rules as apply in Python to the bytearray() constructor:
        • bytearray() Construct a zero-length bytearray.
        • bytearray(int) Construct a zero-initialized bytearray of the given length.
        • bytearray(iterable_of_ints) Construct from iterable yielding integers in [0..255]
        • bytearray(buffer) Construct by reading from any object implementing BufferProtocol, including str/bytes or another bytearray.
        When it is necessary to specify an encoding, as in the Python signature bytearray(string, encoding [, errors]), use the constructor PyByteArray(PyString, String, String). If the PyString is actually a PyUnicode, 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 be null)
        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 to PyBuffer.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 interface BufferProtocol
        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 the bytearray to the given value. This is an extension point called by PySequence in its implementation of PySequence.__setitem__(int, org.python.core.PyObject) It is guaranteed by PySequence that the index is within the bounds of the array. Any other clients calling pyset(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 integer
        PyException - (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. Python int, long and str types of length 1 are allowed.
        Overrides:
        pyinsert in class BaseBytes
        Parameters:
        index - to insert at
        element - to insert (by value)
        Throws:
        PyException - (IndexError) if the index is outside the array bounds
        PyException - (ValueError) if element<0 or element>255
        PyException - (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) a ValueError 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 slice
        sliceSize - 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 class PySequence
        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 class PySequence
        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 class PySequence
        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 class PySequence
        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 class PySequence
        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 class PySequence
        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.
        Overrides:
        __add__ in class PyObject
        Parameters:
        o - the object to perform this binary operation with (the right-hand operand).
        Returns:
        the result of the add, or null if this operation is not defined.
      • __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.
        Overrides:
        __imul__ in class PyObject
        Parameters:
        n - the object to perform this binary operation with (the right-hand operand).
        Returns:
        the result of the imul, or null if this operation is not defined.
      • __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.
        Overrides:
        __mul__ in class PyObject
        Parameters:
        n - the object to perform this binary operation with (the right-hand operand).
        Returns:
        the result of the mul, or null if this operation is not defined
      • __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.
        Overrides:
        __rmul__ in class PyObject
        Parameters:
        n - the object to perform this binary operation with (the left-hand operand).
        Returns:
        the result of the mul, or null if this operation is not defined.
      • 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 the in operator.
        Overrides:
        __contains__ in class PyObject
        Parameters:
        o - the element to search for in this bytearray.
        Returns:
        the result of the search.
      • center

        public PyByteArray center​(int width)
        Java API equivalent of Python center(width): return the bytes centered in an array of length width, padded by spaces. A copy of the original byte array is returned if width is less than this.size().
        Parameters:
        width - desired
        Returns:
        new byte array containing result
      • center

        public PyByteArray center​(int width,
                                  java.lang.String fillchar)
        Java API equivalent of Python center(width [, fillchar]): return the bytes centered in an array of length width. Padding is done using the specified fillchar (default is a space). A copy of the original byte array is returned if width is less than this.size().
        Parameters:
        width - desired
        fillchar - one-byte String to fill with, or null implying space
        Returns:
        new byte array containing the result
      • count

        public int count​(PyObject sub)
        Implementation of Python count(sub). Return the number of non-overlapping occurrences of sub 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 Python count( sub [, start ] ). Return the number of non-overlapping occurrences of sub 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 Python count( sub [, start [, end ]] ). Return the number of non-overlapping occurrences of sub in the range [start, end]. Optional arguments start and end (which may be null or Py.None ) are interpreted as in slice notation.
        Parameters:
        sub - sequence to find (of a type viewable as a byte sequence)
        start - of slice to search
        end - of slice to search
        Returns:
        count of occurrences of sub within this byte array
      • endswith

        public boolean endswith​(PyObject suffix)
        Implementation of Python endswith(suffix). When suffix is of a type that may be treated as an array of bytes, return true if and only if this bytearray ends with the suffix. 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 Python endswith( suffix [, start ] ). When suffix is of a type that may be treated as an array of bytes, return true if and only if this bytearray ends with the suffix. suffix can also be a tuple of suffixes to look for. With optional start (which may be null or Py.None), define the effective bytearray to be the slice [start:] of this bytearray.
        Parameters:
        suffix - byte array to match, or object viewable as such, or a tuple of them
        start - of slice in this bytearray 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 Python endswith( suffix [, start [, end ]] ). When suffix is of a type that may be treated as an array of bytes, return true if and only if this bytearray ends with the suffix. suffix can also be a tuple of suffixes to look for. With optional start and end (which may be null or Py.None), define the effective bytearray to be the slice [start:end] of this bytearray.
        Parameters:
        suffix - byte array to match, or object viewable as such, or a tuple of them
        start - of slice in this bytearray to match
        end - of slice in this bytearray 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 Python expandtabs(): return a copy of the byte array where all tab characters are replaced by one or more spaces, as expandtabs(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 Python expandtabs(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 of BaseBytes 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 Python find(sub). Return the lowest index in the byte array where byte sequence sub is found. Return -1 if sub 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 Python find( sub [, start ] ). Return the lowest index in the byte array where byte sequence sub is found, such that sub is contained in the slice [start:]. Return -1 if sub 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 Python find( sub [, start [, end ]] ). Return the lowest index in the byte array where byte sequence sub is found, such that sub is contained in the slice [start:end]. Arguments start and end (which may be null or Py.None ) are interpreted as in slice notation. Return -1 if sub is not found.
        Parameters:
        sub - sequence to find (of a type viewable as a byte sequence)
        start - of slice to search
        end - 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.
        Overrides:
        __iadd__ in class PyObject
        Parameters:
        o - the object to perform this binary operation with (the right-hand operand).
        Returns:
        the result of the iadd, or null if this operation is not defined
      • index

        public int index​(PyObject sub)
        Implementation of Python index(sub). Like find(PyObject) but raise Py.ValueError if sub 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 Python index( sub [, start ] ). Like find(PyObject,PyObject) but raise Py.ValueError if sub 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 interface java.util.Collection<PyInteger>
        Specified by:
        hashCode in interface java.util.List<PyInteger>
        Overrides:
        hashCode in class BaseBytes
        Throws:
        PyException - (TypeError) as this type is not hashable.
      • index

        public int index​(PyObject sub,
                         PyObject start,
                         PyObject end)
                  throws PyException
        Implementation of Python index( sub [, start [, end ]] ). Like find(PyObject,PyObject,PyObject) but raise Py.ValueError if sub is not found.
        Parameters:
        sub - sequence to find (of a type viewable as a byte sequence)
        start - of slice to search
        end - 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 as s[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 Python join(iterable). Return a bytearray which is the concatenation of the byte arrays in the iterable iterable. 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 Python ljust(width): return the bytes left justified in an array of length width, padded by spaces. A copy of the original byte array is returned if width is less than this.size().
        Parameters:
        width - desired
        Returns:
        new byte array containing result
      • ljust

        public PyByteArray ljust​(int width,
                                 java.lang.String fillchar)
        Java API equivalent of Python ljust(width [, fillchar]): return the bytes left-justified in an array of length width. Padding is done using the specified fillchar (default is a space). A copy of the original byte array is returned if width is less than this.size().
        Parameters:
        width - desired
        fillchar - one-byte String to fill with, or null implying space
        Returns:
        new byte array containing the result
      • lstrip

        public PyByteArray lstrip()
        Implementation of Python lstrip(). 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 Python lstrip(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. If null or None, 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 the nth 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 in bytearray
      • replace

        public PyByteArray replace​(PyObject oldB,
                                   PyObject newB)
        An implementation of Python replace( old, new ), returning a PyByteArray with all occurrences of sequence oldB replaced by newB.
        Parameters:
        oldB - sequence to find
        newB - relacement sequence
        Returns:
        result of replacement as a new PyByteArray
      • replace

        public PyByteArray replace​(PyObject oldB,
                                   PyObject newB,
                                   int maxcount)
        An implementation of Python replace( old, new [, count ] ), returning a PyByteArray with all occurrences of sequence oldB replaced by newB. If the optional argument count is given, only the first count occurrences are replaced.
        Parameters:
        oldB - sequence to find
        newB - relacement sequence
        maxcount - maximum occurrences are replaced or all if maxcount < 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 Python rfind(sub). Return the highest index in the byte array where byte sequence sub is found. Return -1 if sub 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 Python rfind( sub [, start ] ). Return the highest index in the byte array where byte sequence sub is found, such that sub is contained in the slice [start:]. Return -1 if sub 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 Python rfind( sub [, start [, end ]] ). Return the highest index in the byte array where byte sequence sub is found, such that sub is contained in the slice [start:end]. Arguments start and end (which may be null or Py.None ) are interpreted as in slice notation. Return -1 if sub is not found.
        Parameters:
        sub - sequence to find (of a type viewable as a byte sequence)
        start - of slice to search
        end - 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 Python rindex(sub). Like find(PyObject) but raise Py.ValueError if sub 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 Python rindex( sub [, start ] ). Like find(PyObject,PyObject) but raise Py.ValueError if sub 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 Python rjust(width): return the bytes right justified in an array of length width, padded by spaces. A copy of the original byte array is returned if width is less than this.size().
        Parameters:
        width - desired
        Returns:
        new byte array containing result
      • rjust

        public PyByteArray rjust​(int width,
                                 java.lang.String fillchar)
        Java API equivalent of Python rjust(width [, fillchar]): return the bytes right-justified in an array of length width. Padding is done using the specified fillchar (default is a space). A copy of the original byte array is returned if width is less than this.size().
        Parameters:
        width - desired
        fillchar - one-byte String to fill with, or null implying space
        Returns:
        new byte array containing the result
      • rindex

        public int rindex​(PyObject sub,
                          PyObject start,
                          PyObject end)
        Implementation of Python rindex( sub [, start [, end ]] ). Like find(PyObject,PyObject,PyObject) but raise Py.ValueError if sub is not found.
        Parameters:
        sub - sequence to find (of a type viewable as a byte sequence)
        start - of slice to search
        end - of slice to search
        Returns:
        index of start of occurrence of sub within this byte array
      • rstrip

        public PyByteArray rstrip()
        Implementation of Python rstrip(). 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 Python rstrip(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. If null or None, 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 Python startswith(prefix). When prefix is of a type that may be treated as an array of bytes, return true if and only if this bytearray starts with the prefix. 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 Python startswith( prefix [, start ] ). When prefix is of a type that may be treated as an array of bytes, return true if and only if this bytearray starts with the prefix. prefix can also be a tuple of prefixes to look for. With optional start (which may be null or Py.None), define the effective bytearray to be the slice [start:] of this bytearray.
        Parameters:
        prefix - byte array to match, or object viewable as such, or a tuple of them
        start - of slice in this bytearray 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 Python startswith( prefix [, start [, end ]] ). When prefix is of a type that may be treated as an array of bytes, return true if and only if this bytearray starts with the prefix. prefix can also be a tuple of prefixes to look for. With optional start and end (which may be null or Py.None), define the effective bytearray to be the slice [start:end] of this bytearray.
        Parameters:
        prefix - byte array to match, or object viewable as such, or a tuple of them
        start - of slice in this bytearray to match
        end - of slice in this bytearray 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 Python strip(). 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 Python strip(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. If null or None, 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 Java toString() method, returning a printable expression of this byte array in the form bytearray(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 function repr() is expected to call this method, and wraps the result in a Python str.
        Overrides:
        toString in class PyObject
      • __str__

        public PyString __str__()
        An overriding of the PyObject.__str__() method, returning PyString, where in the characters are simply those with a point-codes given in this byte array. The built-in function str() is expected to call this method.
        Overrides:
        __str__ in class PyObject
      • translate

        public PyByteArray translate​(PyObject table)
        Implementation of Python translate(table). Return a copy of the byte array where all bytes occurring in the optional argument deletechars 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 Python translate(table[, deletechars]). Return a copy of the byte array where all bytes occurring in the optional argument deletechars are removed, and the remaining bytes have been mapped through the given translation table, which must be of length 256. You can use the Python maketrans() helper function in the string module to create a translation table. For string objects, set the table argument to None 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 Python zfill(width): return the numeric string left filled with zeros in a byte array of length width. 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