|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||
java.lang.Objectcom.hunnysoft.jmime.ByteString
public final class ByteString
Class that represents single-byte character strings or binary strings.
The ByteString class is very similar to
java.lang.String, except that the characters it contains
are single-byte characters. Alternatively, ByteString can contain
binary data, which may contain embedded NUL bytes and which should not
be interpreted as character data. As is true for
java.lang.String, ByteString is immutable,
which means it can't be changed.
The methods in ByteString have been written to look and
feel like java.lang.String, so that developers will be able
to apply their existing knowledge of java.lang.String to
ByteString.
For the sake of efficiency, ByteString does allow
access to its internal byte array buffer. Use this feature with
caution.
Because an empty byte string is frequently needed in programs, a
static instance is provided by this class as
ByteString.EMPTY_BYTE_STRING.
ByteStringBuffer| Field Summary | |
|---|---|
static ByteString |
EMPTY_BYTE_STRING
|
| Constructor Summary | |
|---|---|
ByteString()
Default constructor. |
|
ByteString(byte[] bytes)
Constructor that takes a byte array. |
|
ByteString(byte[] bytes,
int pos,
int len)
Constructor that takes a subarray of bytes. |
|
ByteString(ByteString bstr)
Copy constructor. |
|
ByteString(ByteString bstr,
int pos,
int len)
Constructor that takes a ByteString substring. |
|
ByteString(java.lang.String str)
Constructor that takes a String argument. |
|
ByteString(java.lang.String str,
java.lang.String charset)
Constructor that takes String and encoding arguments. |
|
| Method Summary | |
|---|---|
byte |
byteAt(int pos)
Returns the byte at the specified position. |
int |
compareTo(ByteString bstr)
Compares this string to another string. |
int |
compareToIgnoreCase(ByteString bstr)
Compares this string to another string, ignoring case. |
ByteString |
concat(ByteString bstr)
Concatenates this string with another string. |
byte[] |
data()
Returns reference to the internal byte array. |
boolean |
endsWith(ByteString suffix)
Returns true if this string ends with the specified string. |
boolean |
equals(java.lang.Object obj)
Compares this string to another object. |
boolean |
equalsIgnoreCase(ByteString bstr)
Returns true if this string equals the specified string in a case sensitive comparison. |
byte[] |
getBytes()
Returns the contents of this string as a byte array. |
void |
getBytes(int srcOffset,
int length,
byte[] dstBuffer,
int dstOffset)
Copies a substring of this string to a byte array. |
int |
hashCode()
|
int |
indexOf(ByteString bstr)
Searches for a string pattern within this string. |
int |
indexOf(ByteString bstr,
int fromIndex)
Searches for a string pattern within this string, beginning at a specified position. |
int |
indexOf(int by)
Searches for the specified byte in this string. |
int |
indexOf(int by,
int fromIndex)
Searches for the specified byte in the string, beginning at a specified position. |
boolean |
isEmpty()
Returns true if this byte string is empty. |
int |
lastIndexOf(ByteString bstr)
Searches backward for a string pattern within this string. |
int |
lastIndexOf(ByteString bstr,
int fromIndex)
Searches backward for a string pattern within this string, beginning at a specified position. |
int |
lastIndexOf(int by)
Searches backward for the specified byte in this string. |
int |
lastIndexOf(int by,
int fromIndex)
Searches backward for the specified byte in the string, beginning at a specified position. |
int |
length()
Returns the length of this byte string. |
int |
offset()
Returns the offset into the internal byte array of the beginning of this byte string's content. |
boolean |
regionMatches(boolean ignoreCase,
int offset1,
ByteString bstr,
int offset2,
int length)
Compares a substring of this string to a substring of another string, with option for case-insensitive comparison. |
boolean |
regionMatches(int offset1,
ByteString bstr,
int offset2,
int length)
Compares a substring of this string to a substring of another string. |
boolean |
startsWith(ByteString prefix)
Returns true if this string starts with the specified string. |
boolean |
startsWith(ByteString prefix,
int offset)
Returns true if this string starts with the specified string. |
static int |
strcasecmp(byte[] s1,
int pos1,
int len1,
byte[] s2,
int pos2,
int len2)
|
static int |
strcmp(byte[] s1,
int pos1,
int len1,
byte[] s2,
int pos2,
int len2)
|
static int |
strncasecmp(byte[] s1,
int pos1,
int len1,
byte[] s2,
int pos2,
int len2,
int len)
|
static int |
strncmp(byte[] s1,
int pos1,
int len1,
byte[] s2,
int pos2,
int len2,
int len)
|
ByteString |
substring(int beginIndex)
Returns a substring of this string. |
ByteString |
substring(int beginIndex,
int endIndex)
Returns a substring of this string. |
ByteString |
toLowerCase()
Returns a new string equal to this string, but with all lower case characters. |
java.lang.String |
toString()
Returns a String with the same content as this string. |
ByteString |
toUpperCase()
Returns a new string equal to this string, but with all upper case characters. |
ByteString |
trim()
Returns a new string with whitespace characters removed from the beginning and the end. |
| Methods inherited from class java.lang.Object |
|---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
public static final ByteString EMPTY_BYTE_STRING
| Constructor Detail |
|---|
public ByteString()
public ByteString(byte[] bytes)
This constructor sets the content of its byte array argument as the initial content of the string. For efficiency, the byte array is used directly as the internal buffer of the string. The byte array is not copied. For this reason, the caller should not use the byte array after the call to this constructor.
bytes - byte array to be used as internal buffer of the new
stringpublic ByteString(ByteString bstr)
This constructor sets the value of the new
ByteString to be the same as the constructor's
argument.
bstr - string to copypublic ByteString(java.lang.String str)
String argument.
This constructor converts its String argument into
a ByteString. The conversion assumes that the
String argument contains only characters from the
ISO-8859-1 charset. (The ISO-8859-1 charset was chosen because its
256 code points are the same as the first 256 code points of
Unicode.)
str - String to be used as initial value
public ByteString(java.lang.String str,
java.lang.String charset)
throws java.io.UnsupportedEncodingException
String and encoding arguments.
This constructor converts its String argument into
a ByteString. The charset parameter indicates
the character encoding that the constructor should use to convert
from Unicode characters to bytes.
str - String to be used as initial valuecharset - character encoding identifier that the constructor
should use to convert from Unicode characters to bytes
java.io.UnsupportedEncodingException
public ByteString(ByteString bstr,
int pos,
int len)
ByteString substring.
This constructor extracts a substring of its
ByteString argument to use as its initial content.
bstr - byte string that contains the substring to be used as
initial valuepos - offset of the substringlen - length of the substring
java.lang.IndexOutOfBoundsException - if pos or
len are out of range
public ByteString(byte[] bytes,
int pos,
int len)
This constructor sets the content of a subarray of its byte array argument as the initial content of the string. For efficiency, the byte array is used directly as the internal buffer of the string. The bytes in the array are not copied. For this reason, the caller should not use the byte array after the call to this constructor.
bytes - byte array to be used as internal buffer of the new stringpos - offset of subarray to be used as the initial value of the
stringlen - length of subarray to be used as the initial value of the
string| Method Detail |
|---|
public byte byteAt(int pos)
pos - position in the string of the byte to return
java.lang.IndexOutOfBoundsException - if the specified position is out of
rangepublic int compareTo(ByteString bstr)
Returns -1 is this string is less than the argument. Returns 1 if this string is greater than the argument. Returns 0 if this string and the argument are equal.
bstr - string to compare to
public int compareToIgnoreCase(ByteString bstr)
Returns -1 is this string is less than the argument. Returns 1 if this string is greater than the argument. Returns 0 if this string and the argument are equal.
This method ignores case only for ASCII characters.
bstr - string to compare to
public ByteString concat(ByteString bstr)
This method returns a new ByteString that is formed by concatenating this string with the argument.
bstr - the string to concatenate
public boolean endsWith(ByteString suffix)
suffix - string to compare
public boolean equalsIgnoreCase(ByteString bstr)
bstr - the string to compare
public byte[] getBytes()
This method copies the internal buffer, so it is safe to modify the returned byte array.
data()
public void getBytes(int srcOffset,
int length,
byte[] dstBuffer,
int dstOffset)
srcOffset - offset of the substring to copylength - length of the substring to copydstBuffer - buffer to copy the byte todstOffset - offset into dstBuffer where the first byte
should be copied topublic int indexOf(int by)
If the specified byte is found in the string, this method returns the position of the first occurrence of the byte. If the search fails, this method returns -1.
by - the byte to search for
public int indexOf(int by,
int fromIndex)
If the specified byte is found in the string at a position
greater than or equal to fromIndex, this method returns
the position of the first such occurrence. If the search fails,
this method returns -1.
by - the byte to search forfromIndex - position to start searching from
public int indexOf(ByteString bstr)
If the sequence of characters specified by the argument
bstr is found within this string, the method returns
the position of the first such occurrence. If the search fails,
this method returns -1.
bstr - the string pattern to search for
public int indexOf(ByteString bstr,
int fromIndex)
If the sequence of characters specified by the argument
bstr is found within this string at a position greater
than or equal to fromIndex, the method returns the
position of the first such occurrence. If the search fails, this
method returns -1.
bstr - the string pattern to search forfromIndex - position to start searching from
public int lastIndexOf(int by)
If the specified byte is found in the string, this method returns the position of the first occurrence of the byte (in a backward direction). If the search fails, this method returns -1.
by - the byte to search for
public int lastIndexOf(int by,
int fromIndex)
If the specified byte is found in the string at a position less
than or equal to fromIndex, this method returns the
position of the first such occurrence (in a backward direction). If
the search fails, this method returns -1.
by - the byte to search forfromIndex - position to start searching from
public int lastIndexOf(ByteString bstr)
If the sequence of characters specified by the argument
bstr is found within this string, the method returns
the position of the first such occurrence (in a backward direction).
If the search fails, this method returns -1.
bstr - the string pattern to search for
public int lastIndexOf(ByteString bstr,
int fromIndex)
If the sequence of characters specified by the argument
bstr is found within this string, the method returns
the position of the first such occurrence (in a backward direction).
If the search fails, this method returns -1.
bstr - the string pattern to search forfromIndex - position to start searching from
public boolean regionMatches(int offset1,
ByteString bstr,
int offset2,
int length)
offset1 - offset of the substring of this stringbstr - string containing substring to compare tooffset2 - offset of the substring of bstrlength - length of substrings to compare
public boolean regionMatches(boolean ignoreCase,
int offset1,
ByteString bstr,
int offset2,
int length)
ignoreCase - if true, comparison is case-insensitiveoffset1 - offset of the substring of this stringbstr - string containing substring to compare tooffset2 - offset of the substring of bstrlength - length of substrings to compare
public boolean startsWith(ByteString prefix,
int offset)
offset - position in this string to start the comparisonprefix - string to compare
public boolean startsWith(ByteString prefix)
prefix - string to compare
public ByteString substring(int beginIndex,
int endIndex)
beginIndex - offset into this string of the beginning of the
substringendIndex - offset into this string of the end of the substring
public ByteString substring(int beginIndex)
This method is equivalent to
substring(beginIndex,endIndex) with
endIndex set to the length of this string.
beginIndex - offset into this string of the beginning of the
substring
public ByteString toLowerCase()
public java.lang.String toString()
String with the same content as this string.
This method converts the bytes in this string to characters in the returned string. The conversion is performed using the ISO-8859-1 character set and code points.
toString in class java.lang.ObjectString that equivalent to this stringpublic ByteString toUpperCase()
public ByteString trim()
public boolean equals(java.lang.Object obj)
equals in class java.lang.ObjectByteString and the
contents are the same as the contents of this
ByteStringpublic int hashCode()
hashCode in class java.lang.Objectpublic byte[] data()
This method provides access to the internal byte array
maintained by this ByteString. The purpose is mainly
for the package itself to use in order to perform its tasks more
efficiently by eliminating a lot of copying. However, the method is
public so that other packages may also gain access to the internal
byte array. The returned byte array should be treated as a
read-only array. All the code in this package itself treats
the returned byte array as read-only, and does not modify it in any
way.
If you use this method, you must use it together with
the methods offset() and length(), in
order to access the correct elements of the internal array.
offset(),
length()public int offset()
This method is intended to be used together with the methods
data() and length(), in order to access
the correct elements of the internal array.
data(),
length()public int length()
public boolean isEmpty()
public static int strcmp(byte[] s1,
int pos1,
int len1,
byte[] s2,
int pos2,
int len2)
public static int strncmp(byte[] s1,
int pos1,
int len1,
byte[] s2,
int pos2,
int len2,
int len)
public static int strcasecmp(byte[] s1,
int pos1,
int len1,
byte[] s2,
int pos2,
int len2)
public static int strncasecmp(byte[] s1,
int pos1,
int len1,
byte[] s2,
int pos2,
int len2,
int len)
|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||