JadPropertiespublic class JadProperties extends com.sun.midp.io.Properties This class represents a set of properties loaded from a MIDP Java
Application Descriptor. The parsing of descriptor is more relaxed than
the MIDP 1.0 specification. First, the white space that is required
before and after the property value is optional. Second, any extra
carrage returns and end of file characters are ignored. Third, the key
of the property is only checked for whitespace. Fourth, blanklines
are allowed so the save code when parsing JAR manfests.
The set of properties, though not strictly ordered, will be stored
in the same order it was read in or created, with modifications being
appeneded to the end of the list by default.
If an alternate encoding type is not given, when saving properties
to a stream or loading them from a stream, the ISO 8859-1 character
encoding is used. |
Fields Summary |
---|
protected static final int | HTHorizontal Tab - Unicode character 0x09. | protected static final int | LFLine Feed - Unicode character 0x0A. | protected static final int | CRCarrage Return - Unicode character 0x0D. | protected static final int | EOFEnd Of File - Unicode character 0x1A. | protected static final int | SPSPace - Unicode character 0x20. | protected char[] | lineBufferBuffers one line from the stream. |
Constructors Summary |
---|
public JadProperties()Constructor - creates an empty property list.
|
Methods Summary |
---|
protected boolean | checkKeyChars(java.lang.String key)Check to see if all the chars in the key of a property are valid.
char[] temp = key.toCharArray();
int len = temp.length;
for (int i = 0; i < len; i++) {
char current = temp[i];
if (current <= 0x1F ||
current == 0x7F ||
current == '(" ||
current == ')" ||
current == '<" ||
current == '>" ||
current == '@" ||
current == '," ||
current == ';" ||
current == '\'" ||
current == '"" ||
current == '/" ||
current == '[" ||
current == ']" ||
current == '?" ||
current == '=" ||
current == '{" ||
current == '}" ||
current == SP ||
current == HT) {
return false;
}
}
return true;
| protected boolean | checkValueChars(java.lang.String value)Check to see if all the chars in the value of a property are valid.
char[] temp = value.toCharArray();
int len = temp.length;
// assume whitespace and newlines are trimmed
for (int i = 0; i < len; i++) {
char current = temp[i];
// if current is a CTL character, throw exception
if ((current <= 0x1F || current == 0x7F) &&
(current != HT)) {
return false;
}
}
return true;
| public synchronized void | load(java.io.InputStream inStream, java.lang.String enc)Reads a JAD (key and element pairs) from the input stream.
The stream uses the character encoding specified by enc
Every property occupies one line of the input stream. Each line
is terminated by a line terminator which can be a LF, or (CR LF).
Lines from the input stream are processed until
end of file is reached on the input stream.
Every line describes one property to be added to the table.
The key consists of all the characters from beginning of the line
up to, but not including the first ASCII : .
All remaining characters on the line become part of the associated
element. The element is also trimmed of leading and trailing
whitespace.
As an example, each of the following line specifies the key
"Truth" and the associated element value
"Beauty" :
Truth: Beauty
This method will try to continue after a format error and load as
many properties it can, but throw the last error encountered.
partialLoad(inStream, enc, Integer.MAX_VALUE);
| public synchronized void | load(java.io.InputStream inStream)Loads properties from the input stream using the default
character encoding. Currently the default encoding is UTF8.
load(inStream, null);
| public void | partialLoad(java.io.InputStream inStream, java.lang.String enc, int propertiesToLoad)Loads up a given number of properties from a JAD.
Used when authenticating a JAD.
Reader in;
String line;
int endOfKey;
String key = null;
int startOfValue;
String value = null;
InvalidJadException jadException = null;
if (enc == null) {
in = new InputStreamReader(inStream, "UTF-8");
} else {
in = new InputStreamReader(inStream, enc);
}
lineBuffer = new char[512];
for (int i = 0; i < propertiesToLoad; i++) {
// Get next line
line = readLine(in);
if (line == null) {
break;
}
// blank line separate groups of properties
if (line.length() == 0) {
continue;
}
endOfKey = line.indexOf(":");
if (endOfKey == -1) {
jadException =
new InvalidJadException(InvalidJadException.INVALID_KEY,
line);
continue;
}
key = line.substring(0, endOfKey);
if (key == null || key.length() == 0) {
jadException =
new InvalidJadException(InvalidJadException.INVALID_KEY,
line);
continue;
}
if (!checkKeyChars(key)) {
jadException =
new InvalidJadException(InvalidJadException.INVALID_KEY,
line);
continue;
}
startOfValue = endOfKey + 1;
value = line.substring(startOfValue, line.length());
value = value.trim();
if (value == null) {
jadException =
new InvalidJadException(InvalidJadException.INVALID_VALUE,
key);
continue;
}
if (!checkValueChars(value)) {
jadException = new
InvalidJadException(InvalidJadException.INVALID_VALUE,
key);
continue;
}
putProperty(key, value);
}
// we only need the line buffer while loading, so let it be reclaimed
lineBuffer = null;
if (jadException != null) {
throw jadException;
}
| protected void | putProperty(java.lang.String key, java.lang.String value)Store key:value pair.
setProperty(key, value);
| protected java.lang.String | readLine(java.io.Reader in)Reads one using a given reader. LF or CR LF end a line.
The end of line and end of file characters are dropped.
int room;
int offset = 0;
int c = 0;
char[] temp;
room = lineBuffer.length;
for (;;) {
c = in.read();
if (c == -1 || c == LF) {
// LF or CR LF ends a line
break;
}
/*
* throw away carrage returns and the end of file character.
*/
if (c == CR || c == EOF) {
continue;
}
if (--room < 0) {
temp = new char[offset + 128];
room = temp.length - offset - 1;
System.arraycopy(lineBuffer, 0, temp, 0, offset);
lineBuffer = temp;
}
lineBuffer[offset++] = (char) c;
}
if ((c == -1) && (offset <= 0)) {
return null;
}
return new String(lineBuffer, 0, offset);
|
|