Right this uses NextIterator, which is elsewhere in the repo. It just makes
it cleaner to implement a custom iterator. But i guess you got the high
level point, so its okay.

TD


On Thu, Jul 10, 2014 at 7:21 PM, kytay <kaiyang....@gmail.com> wrote:

> Hi TD
>
> Thanks.
>
> I have problem understanding the codes in github,  Object
> SocketReceiver.byteToLines(...)
> <
> https://github.com/apache/spark/blob/095b5182536a43e2ae738be93294ee5215d86581/streaming/src/main/scala/org/apache/spark/streaming/dstream/SocketInputDStream.scala
> >
>
> private[streaming]
> object SocketReceiver  {
>
>   /**
>    * This methods translates the data from an inputstream (say, from a
> socket)
>    * to '\n' delimited strings and returns an iterator to access the
> strings.
>    */
>   def bytesToLines(inputStream: InputStream): Iterator[String] = {
>     val dataInputStream = new BufferedReader(new
> InputStreamReader(inputStream, "UTF-8"))
>     new NextIterator[String] {
>       protected override def getNext() = {
>         val nextValue = dataInputStream.readLine()
>         if (nextValue == null) {
>           finished = true
>         }
>         nextValue
>       }
>
>       protected override def close() {
>         dataInputStream.close()
>       }
>     }
>   }
>
> Sorry will need some time to digest this. I do not know scala at the
> moment.
> But I understand what you mean about the implementation. Thanks.
>
>
>
> --
> View this message in context:
> http://apache-spark-user-list.1001560.n3.nabble.com/Getting-Persistent-Connection-using-socketStream-tp9285p9380.html
> Sent from the Apache Spark User List mailing list archive at Nabble.com.
>

Reply via email to