Documentation of 'edu.rit.util.ByteSequence' Java class
ByteSequence
edu.rit.util

Class ByteSequence



  • public class ByteSequence
    extends java.lang.Object
    Class ByteSequence provides an abstraction for a sequence of bytes. The contents of the byte sequence are specified at construction time; the contents may come from a byte array, an input stream, or another byte sequence. You can obtain the byte sequence's contents as a byte array or write the byte sequence's contents to an output stream.
    • Constructor Summary

      Constructors 
      Constructor and Description
      ByteSequence(byte[] buf)
      Construct a new byte sequence whose contents are a copy of the given byte array.
      ByteSequence(byte[] buf, int off, int len)
      Construct a new byte sequence whose contents are a copy of a portion of the given byte array.
      ByteSequence(ByteSequence theByteSequence)
      Construct a new byte sequence whose contents are a copy of the given byte sequence.
      ByteSequence(java.io.InputStream theInputStream)
      Construct a new byte sequence whose contents come from the given input stream.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method and Description
      int copy(byte[] buf)
      Copy this byte sequence's contents into the given byte array.
      int copy(byte[] buf, int off, int len)
      Copy this byte sequence's contents into a portion of the given byte array.
      int length()
      Obtain the length of this byte sequence.
      byte[] toByteArray()
      Obtain a byte array with a copy of this byte sequence's contents.
      void write(java.io.DataOutput theOutputStream)
      Write this byte sequence's contents to the given data output stream.
      void write(java.io.OutputStream theOutputStream)
      Write this byte sequence's contents to the given output stream.
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • ByteSequence

        public ByteSequence(byte[] buf)
        Construct a new byte sequence whose contents are a copy of the given byte array.
        Parameters:
        buf - Byte array to copy.
        Throws:
        java.lang.NullPointerException - Thrown if buf is null.
      • ByteSequence

        public ByteSequence(byte[] buf,
                            int off,
                            int len)
        Construct a new byte sequence whose contents are a copy of a portion of the given byte array.
        Parameters:
        buf - Byte array to copy.
        off - Index of first byte to copy.
        len - Number of bytes to copy.
        Throws:
        java.lang.NullPointerException - Thrown if buf is null.
        java.lang.IndexOutOfBoundsException - Thrown if off < 0, len < 0, or off+len > buf.length.
      • ByteSequence

        public ByteSequence(java.io.InputStream theInputStream)
                     throws java.io.IOException
        Construct a new byte sequence whose contents come from the given input stream. Bytes are read from theInputStream into the byte sequence until the end-of-stream is encountered, then theInputStream is closed. If theInputStream is null, the byte sequence's length is 0.
        Parameters:
        theInputStream - Input stream, or null.
        Throws:
        java.io.IOException - Thrown if an I/O error occurred.
      • ByteSequence

        public ByteSequence(ByteSequence theByteSequence)
        Construct a new byte sequence whose contents are a copy of the given byte sequence.
        Parameters:
        theByteSequence - Byte sequence to copy.
        Throws:
        java.lang.NullPointerException - Thrown if theByteSequence is null.
    • Method Detail

      • length

        public int length()
        Obtain the length of this byte sequence.
        Returns:
        Number of bytes.
      • toByteArray

        public byte[] toByteArray()
        Obtain a byte array with a copy of this byte sequence's contents. A new byte array of the proper size is created and returned.
        Returns:
        Contents.
      • copy

        public int copy(byte[] buf)
        Copy this byte sequence's contents into the given byte array. Bytes are copied into buf starting at index 0. The number of bytes copied is buf.length or this byte sequence's length, whichever is smaller.
        Parameters:
        buf - Buffer to hold the copy.
        Returns:
        Actual number of bytes copied.
        Throws:
        java.lang.NullPointerException - (unchecked exception) Thrown if buf is null.
      • copy

        public int copy(byte[] buf,
                        int off,
                        int len)
        Copy this byte sequence's contents into a portion of the given byte array. Bytes are copied into buf starting at index off. The number of bytes copied is len or this byte sequence's length, whichever is smaller.
        Parameters:
        buf - Buffer to hold the copy.
        off - Index in buf at which to start copying.
        len - Maximum number of bytes to copy.
        Returns:
        Actual number of bytes copied.
        Throws:
        java.lang.NullPointerException - (unchecked exception) Thrown if buf is null.
        java.lang.IndexOutOfBoundsException - Thrown if off < 0, len < 0, or off+len > buf.length.
      • write

        public void write(java.io.OutputStream theOutputStream)
                   throws java.io.IOException
        Write this byte sequence's contents to the given output stream.
        Parameters:
        theOutputStream - Output stream.
        Throws:
        java.io.IOException - Thrown if an I/O error occurred.
      • write

        public void write(java.io.DataOutput theOutputStream)
                   throws java.io.IOException
        Write this byte sequence's contents to the given data output stream.
        Parameters:
        theOutputStream - Data output stream.
        Throws:
        java.io.IOException - Thrown if an I/O error occurred.

DMelt 3.0 © DataMelt by jWork.ORG

You see the box below because you did not login.