yusuke/twitter4j — pull request #62 by akira (2012-09-22 00:05:59+00:00)
Title: Fix issue - control stream not being renewed upon stream reconnect

**The issue:**
If we have a stream that is connected, and then a disconnect and reconnect occurs,
the control stream URI does not get updated correctly.

This is the error message that occurs on a reconnect:
```
15:32:30.196 [Twitter4J Async Dispatcher[0]] ERROR t.internal.async.ExecuteThread - Got an exception while running a task:
java.lang.StringIndexOutOfBoundsException: String index out of range: -15
at java.lang.String.substring(String.java:1937) ~[na:1.6.0_31]
at twitter4j.SiteStreamsImpl.parseLine(SiteStreamsImpl.java:76) ~[twitter4j-stream-3.0.0-SNAPSHOT.jar:3.0.0-SNAPSHOT]
at twitter4j.AbstractStreamImplementation$1.run(AbstractStreamImplementation.java:93) ~[twitter4j-stream-3.0.0-SNAPSHOT.jar:3.0.0-SNAPSHOT]
at twitter4j.internal.async.ExecuteThread.run(DispatcherImpl.java:116) ~[twitter4j-core-3.0.0-SNAPSHOT.jar:3.0.0-SNAPSHOT]
```

As a result, any further control stream commands result in a 404.

**To reproduce:**
Start a site stream connection and wait until it is active. Now cause a
disconnect (perhaps turn off WiFi), and wait until Twitter4J detects the disconnect
and does a retry. Now make sure connection is active (turn on WiFi) and you should
see error above when a control stream is issued by twitter.

**The cause:**
This happens because on line 59 of `SiteStreamsImpl` there is a
check `cs.getControlURI() == null`. Since the control URI has been set by previous
connection, it does not pick up the new control URI.

**The fix:**
There are a few ways to fix this.

* (THIS PR) - in `public void next(StreamListener[] listeners)` detect if
an exception has been thrown that causes a disconnect. Set the
control URI to null in this case. Note that there is probably a better way
to detect a disconnect than checking exception message, but the
variable `streamAlive` in `AbstractStreamImplementation` is private and
cannot be accessed from SiteStreamImpl.

* The other way is to remove the check `cs.getControlURI() == null &&` on line 59 of `SiteStreamsImpl`.