0

I'm really puzzled by the following piece of code:

// Get the content text
String contentText = null;
Header contentEncodingHeader = m_httpEntity.getContentEncoding();
final String contentEncodingValue = contentEncodingHeader != null ? contentEncodingHeader.getValue() : ""; // In my example, this is set to "gzip"

if (contentEncodingValue == "")
{
    contentText = this.GetResponseContentText(inputStream, charset);
}
else if (contentEncodingValue == "gzip")
{
    contentText = this.GetResponseContentText_GZip(inputStream, charset);           
}

return contentText;

When I step over the lines of code, it executes in the following order:

1) if (contentEncodingValue == "")
{
3)  contentText = this.GetResponseContentText(inputStream, charset);
}
2) else if (contentEncodingValue == "gzip")
{
    contentText = this.GetResponseContentText_GZip(inputStream, charset);           
}

4) return contentText;

And even stranger still, is it doesn't even enter the GetResponseContentText function. I really am confused. Can anyone shed any light on this?

Also, if I comment out the if statement, it works fine (goes into the GetResponseContentText_GZip function).

Mark Ingram
  • 71,849
  • 51
  • 176
  • 230

1 Answers1

2

From string comparison, you would want to use equals instead of ==

if (contentEncodingValue.equals("")) {
...
}
else if (contentEncodingValue.equals("gzip")) {
...
}
ccheneson
  • 49,072
  • 8
  • 63
  • 68