More Input

One of the core IO classes is called Input

Basic Input

All Input resources extend the Input trait so the following operations can be used on any Input resource (ReadableByteChannel or InputStream for example).

This example does not try to cover all operations since they are covered in multiple examples like in the basic-read-write examples.

    import scalax.io._

    val input:Input = Resource.fromFileString("someFile")

    // read all bytes into an in memory arry
    input.byteArray

    // skip first 5 bytes and take the next 5
    // force the operation to take place.
    // The bytes is a ResourceView which is a LongTraversableView,
    // meaning it will evaluate lazily until the data is forced
    // or requested
    input.bytes.drop(5).take(5).force

    // read all bytes into a string
    // note: codec can be passed implicitely as well
    input.slurpString(Codec.UTF8)