All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class hplb.misc.ByteArray

java.lang.Object
   |
   +----hplb.misc.ByteArray

public class ByteArray
extends Object
This class is a container for algorithms working on byte arrays - some of the algorithms are analogous to those in java.lang.String.

Author:
Anders Kristensen

Constructor Index

 o ByteArray()

Method Index

 o cpybytes(InputStream, OutputStream)
Copies data from the specified input stream to the output stream until end of file is met.
 o cpybytes(InputStream, OutputStream, int)
Copies data from the specified input stream to the output stream until n bytes has been copied or end of file is met.
 o findBytes(byte[], int, int, byte[])
Find byte pattern ptrn in buffer buf.
 o getBytes(String)
Returns copy of characters in s as a new byte array.
 o getContent(URL)
Return contents of a WWW resource identified by a URL.
 o indexOf(byte[], int)
Returns the index within this String of the first occurrence of the specified character or -1 if the character is not found.
 o indexOf(byte[], int, int, int)
Returns the index within this String of the first occurrence of the specified character, starting the search at fromIndex.
 o indexOf(byte[], String)
Returns the index of the first occurrence of s in the specified buffer or -1 if this is not found.
 o indexOf(byte[], String, int)
Returns the index of the first occurrence of s in the specified buffer.
 o isSpace(int)
 o loadFromFile(File)
Returns contents of file file as byte array.
 o loadFromFile(String)
Returns contents of file as byte array.
 o readAll(InputStream)
Read all input from an InputStream and return as a byte array.
 o readn(InputStream, int)
Reads n bytes from the specified input stream.
 o skipSpaces(byte[], int, int)

Constructors

 o ByteArray
 public ByteArray()

Methods

 o getBytes
 public static final byte[] getBytes(String s)
Returns copy of characters in s as a new byte array.

 o loadFromFile
 public static byte[] loadFromFile(String filename) throws IOException
Returns contents of file as byte array.

 o loadFromFile
 public static byte[] loadFromFile(File file) throws IOException
Returns contents of file file as byte array.

 o readn
 public static byte[] readn(InputStream in,
                            int n) throws IOException
Reads n bytes from the specified input stream. It will return fewer bytes if fewer bytes are available on the stream. Hence the application should check the resulting arrays length.

 o getContent
 public static byte[] getContent(URL url) throws IOException
Return contents of a WWW resource identified by a URL.

Parameters:
url - the resource to retrieve
Returns:
the resource contents as a byte array
 o readAll
 public static byte[] readAll(InputStream in) throws IOException
Read all input from an InputStream and return as a byte array. This method will not return before the end of the stream is reached.

Returns:
contents of the stream
 o cpybytes
 public static int cpybytes(InputStream in,
                            OutputStream out) throws IOException
Copies data from the specified input stream to the output stream until end of file is met.

Returns:
the total number of bytes written to the output stream
 o cpybytes
 public static int cpybytes(InputStream in,
                            OutputStream out,
                            int n) throws IOException
Copies data from the specified input stream to the output stream until n bytes has been copied or end of file is met.

Returns:
the total number of bytes written to the output stream
 o indexOf
 public static final int indexOf(byte buf[],
                                 int ch)
Returns the index within this String of the first occurrence of the specified character or -1 if the character is not found.

Parameters:
s - buf the buffer to search
s - ch the character to search for
 o indexOf
 public static final int indexOf(byte buf[],
                                 int ch,
                                 int fromIndex,
                                 int toIndex)
Returns the index within this String of the first occurrence of the specified character, starting the search at fromIndex. This method returns -1 if the character is not found.

Parameters:
s - buf the buffer to search
s - ch the character to search for
s - fromIndex the index to start the search from
s - toIndex the highest possible index returned plus 1
 o indexOf
 public static final int indexOf(byte buf[],
                                 String s)
Returns the index of the first occurrence of s in the specified buffer or -1 if this is not found.

 o indexOf
 public static final int indexOf(byte buf[],
                                 String s,
                                 int fromIndex)
Returns the index of the first occurrence of s in the specified buffer. The search starts from fromIndex. This method returns -1 if the index is not found.

 o isSpace
 public static final boolean isSpace(int ch)
 o skipSpaces
 public static final int skipSpaces(byte buf[],
                                    int fromIndex,
                                    int toIndex)
 o findBytes
 public static final int findBytes(byte buf[],
                                   int off,
                                   int len,
                                   byte ptrn[])
Find byte pattern ptrn in buffer buf.

Returns:
index of first occurrence of ptrn in buf, -1 if no occurence

All Packages  Class Hierarchy  This Package  Previous  Next  Index