Skip to content

A Java interface-front-ended library implemented in Scala for streaming objects between producers and consumers.

License

Notifications You must be signed in to change notification settings

gtri-iead/org.gtri.util.iteratee

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

97 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

org.gtri.util.iteratee

A Java interface-front-ended library implemented in Scala for streaming objects between producers(enumerators) and consumers(iteratees).

Usage Example (Java)

The following example enumerates an array of integers to an iteratee that simply prints them. ```Java IterateeFactory factory = new IterateeFactory(); Array ints = { 1,2,3 } Enumerator intProducer = new TestEnumerator(ints); Iteratee intToString = new TestIntToStringTranslator(); Iteratee printer = new TestPrintConsumer(); factory.createPlan(integerProducer, intToString, stringConsumer).run(); assertTrue(result.statusCode().isSuccess()); ```

Iteratee Implementation Example (Scala)

An iteratee implementation that prints all input chunks it receives. ```Scala import org.gtri.util.iteratee.api._ import org.gtri.util.iteratee.impl.Iteratees._ import org.gtri.util.iteratee.impl.Iteratees import org.gtri.util.iteratee.impl.ImmutableBuffers.Conversions._

class TestPrintConsumer[A] extends Iteratee[A, Unit] { case class ContA extends Iteratees.Cont[A, Unit] { def apply(items: ImmutableBuffer[A]) = { println("received=" + items) for (item <- items) { println(item) } Result(this) }

def endOfInput() = Result(Success())

}

def initialState = Cont() }

<h3>Enumeratee Implementation Example (Scala)</h3>
An enumerator implementation for any java.util.Iterator that groups output into chunks
```Scala
import scala.collection.immutable.Traversable
import org.gtri.util.iteratee.api
import api._
import scala.collection.JavaConversions._
import org.gtri.util.iteratee.impl.SeqEnumerator

class TestEnumerator[A](iterable : java.lang.Iterable[A], chunkSize : java.lang.Integer) extends Enumerator[A] {

  def initialState = new SeqEnumerator(iterable.iterator.toStream,chunkSize).initialState
}

Translating Iteratee Implementation Example (Scala)

An iteratee implementation that translates an integer to a string. ```Scala import org.gtri.util.iteratee.api._ import org.gtri.util.iteratee.impl.Iteratees._ import org.gtri.util.iteratee.impl.Iteratees import org.gtri.util.iteratee.impl.ImmutableBuffers.Conversions._

class TestIntToStringTranslator extends Iteratee[java.lang.Integer, String] { class Cont extends Iteratees.Cont[java.lang.Integer,String] {

def apply(items: ImmutableBuffer[java.lang.Integer]) = {
  println("translating=" + items)
  val nextOutput = items.foldLeft(List[String]()) {
    (list,item) => {
      item.toString :: list
    }
  }
  Result(this, nextOutput)
}

def endOfInput() = Result(Success())

}

def initialState = new Cont() }

About

A Java interface-front-ended library implemented in Scala for streaming objects between producers and consumers.

Resources

License

Stars

Watchers

Forks

Packages

No packages published