}
// Now the headers
boolean isEscaping = false;
SimpleBytes holder = new SimpleBytes(1024);
outer: while (true)
{
byte b = decoder.workingBuffer[decoder.pos++];
switch (b)
{
//escaping
case ESC_CHAR:
{
if (isEscaping)
{
//this is a backslash
holder.append(b);
isEscaping = false;
}
else
{
//begin escaping
isEscaping = true;
}
break;
}
case StompDecoder.HEADER_SEPARATOR:
{
if (isEscaping)
{
//a colon
holder.append(b);
isEscaping = false;
}
else
{
if (decoder.inHeaderName)
{
try
{
decoder.headerName = holder.getString();
}
catch (UnsupportedEncodingException e)
{
throw new HornetQStompException("Encoding exception", e);
}
holder.reset();
decoder.inHeaderName = false;
decoder.headerBytesCopyStart = decoder.pos;
decoder.headerValueWhitespace = true;
}
}
decoder.whiteSpaceOnly = false;
break;
}
case StompDecoder.LN:
{
if (isEscaping)
{
holder.append(StompDecoder.NEW_LINE);
isEscaping = false;
}
else
{
holder.append(b);
}
break;
}
case StompDecoder.NEW_LINE:
{
if (decoder.whiteSpaceOnly)
{
// Headers are terminated by a blank line
decoder.readingHeaders = false;
break outer;
}
String headerValue;
try
{
headerValue = holder.getString();
}
catch (UnsupportedEncodingException e)
{
throw new HornetQStompException("Encoding exception.", e);
}
holder.reset();
decoder.headers.put(decoder.headerName, headerValue);
if (decoder.headerName.equals(StompDecoder.CONTENT_LENGTH_HEADER_NAME))
{
decoder.contentLength = Integer.parseInt(headerValue);
}
if (decoder.headerName.equals(StompDecoder.CONTENT_TYPE_HEADER_NAME))
{
decoder.contentType = headerValue;
}
decoder.whiteSpaceOnly = true;
decoder.headerBytesCopyStart = decoder.pos;
decoder.inHeaderName = true;
decoder.headerValueWhitespace = false;
break;
}
default:
{
decoder.whiteSpaceOnly = false;
decoder.headerValueWhitespace = false;
holder.append(b);
}
}
if (decoder.pos == decoder.data)
{
// Run out of data