improved null handling after suggestions from Danielius Jurna

git-svn-id: https://svn.apache.org/repos/asf/incubator/activemq/trunk@399999 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
James Strachan 2006-05-05 07:31:35 +00:00
parent b29f744014
commit ac13202007
2 changed files with 37 additions and 22 deletions

View File

@ -34,15 +34,20 @@ class CommandParser {
}
Command parse(DataInput in) throws IOException, JMSException {
String line;
String line = null;
// skip white space to next real line
try {
while ((line = in.readLine()).trim().length() == 0) {
while (true) {
line = in.readLine();
if (line == null) {
throw new IOException("connection was closed");
}
else {
line = line.trim();
if (line.length() > 0) {
break;
}
}
}
catch (NullPointerException e) {
throw new IOException("connection was closed");
}
// figure correct command and return it

View File

@ -32,28 +32,38 @@ class HeaderParser {
*/
Properties parse(BufferedReader in) throws IOException {
Properties props = new Properties();
String line;
while (((line = in.readLine()).trim().length() > 0)) {
int seperator_index = line.indexOf(Stomp.Headers.SEPERATOR);
String name = line.substring(0, seperator_index).trim();
String value = line.substring(seperator_index + 1, line.length()).trim();
props.setProperty(name, value);
while (true) {
String line = in.readLine();
if (line != null && line.trim().length() > 0) {
int seperator_index = line.indexOf(Stomp.Headers.SEPERATOR);
String name = line.substring(0, seperator_index).trim();
String value = line.substring(seperator_index + 1, line.length()).trim();
props.setProperty(name, value);
}
else {
break;
}
}
return props;
}
Properties parse(DataInput in) throws IOException {
Properties props = new Properties();
String line;
while (((line = in.readLine()).trim().length() > 0)) {
try {
int seperator_index = line.indexOf(Stomp.Headers.SEPERATOR);
String name = line.substring(0, seperator_index).trim();
String value = line.substring(seperator_index + 1, line.length()).trim();
props.setProperty(name, value);
while (true) {
String line = in.readLine();
if (line != null && line.trim().length() > 0) {
try {
int seperator_index = line.indexOf(Stomp.Headers.SEPERATOR);
String name = line.substring(0, seperator_index).trim();
String value = line.substring(seperator_index + 1, line.length()).trim();
props.setProperty(name, value);
}
catch (Exception e) {
throw new ProtocolException("Unable to parser header line [" + line + "]");
}
}
catch (Exception e) {
throw new ProtocolException("Unable to parser header line [" + line + "]");
else {
break;
}
}
return props;