开发者

Strange program flow

开发者 https://www.devze.com 2023-03-02 07:21 出处:网络
I\'m really puzzled by the following piece of code: // Get the content text String contentText = null; Header contentEncodingHeader = m_httpEntity.getContentEncoding();

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).


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

if (contentEncodingValue.equals("")) {
...
}
else if (contentEncodingValue.equals("gzip")) {
...
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号