jlibs.core.lang
Class ByteSequence

java.lang.Object
  extended by jlibs.core.lang.ByteSequence
All Implemented Interfaces:
Serializable

public class ByteSequence
extends Object
implements Serializable

This class represents a sequence of bytes.

Author:
Santhosh Kumar T
See Also:
Serialized Form

Constructor Summary
ByteSequence(byte[] buff)
          Allocates a new ByteSequence so that it represents the sequence of bytes currently contained in the byte array argument.
ByteSequence(byte[] buff, int offset, int length)
          Allocates a new ByteSequence that contains characters from a subarray of the byte array argument.
 
Method Summary
 ByteArrayInputStream asInputStream()
           
 byte[] buffer()
          returns the byte buffer used by this instance
 byte byteAt(int index)
           
 ByteSequence copy()
           
 int length()
           
 int offset()
          returns the index of first byte in byte buffer
 void set(byte[] buff, int offset, int length)
          replaces the internal byte buffer with the given byte array.
 ByteSequence slice(int offset)
           
 ByteSequence slice(int offset, int length)
           
 byte[] toByteArray(boolean clone)
           
 ByteBuffer toByteBuffer()
           
 String toString()
           
 String toString(Charset charset)
           
 String toString(String charset)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ByteSequence

public ByteSequence(byte[] buff)
Allocates a new ByteSequence so that it represents the sequence of bytes currently contained in the byte array argument. The contents of the byte array are not copied;

Parameters:
buff - value of the bytesequence

ByteSequence

public ByteSequence(byte[] buff,
                    int offset,
                    int length)
Allocates a new ByteSequence that contains characters from a subarray of the byte array argument. The offset argument is the index of the first byte of the subarray and the length argument specifies the length of the subarray. The contents of the subarray are not copied;

Parameters:
buff - Array that is the source of bytes
offset - The initial offset
length - The length
Throws:
IndexOutOfBoundsException - If the offset and length arguments index bytes outside the bounds of the buff array
Method Detail

set

public void set(byte[] buff,
                int offset,
                int length)
replaces the internal byte buffer with the given byte array.

Parameters:
buff - Array that is the source of bytes
offset - The initial offset
length - The length

byteAt

public byte byteAt(int index)

buffer

public byte[] buffer()
returns the byte buffer used by this instance


offset

public int offset()
returns the index of first byte in byte buffer


length

public int length()

slice

public ByteSequence slice(int offset)

slice

public ByteSequence slice(int offset,
                          int length)

toByteBuffer

public ByteBuffer toByteBuffer()

toByteArray

public byte[] toByteArray(boolean clone)

asInputStream

public ByteArrayInputStream asInputStream()

toString

public String toString(Charset charset)

toString

public String toString(String charset)
                throws UnsupportedEncodingException
Throws:
UnsupportedEncodingException

toString

public String toString()
Overrides:
toString in class Object

copy

public ByteSequence copy()


Copyright © 2018. All rights reserved.