Scala IO API Documentation

The Scala IO umbrella project consists of a few sub projects for different aspects and extensions of IO. The core project deals with raw input and output, primarily through streams and channels (at least the Java implementation).

Warning #1: The current API is a very early version and is likely to change. That said barring a massive outcry the core components should remain fairly consistent. Both the core and file projects will be changing but file is even more likely to change. Especially with regard to FileAttributes and the API for implementing custom filesystems.

Warning #2: I have spent no time on optimization so there are a large number of known inefficiencies. Patches and suggestions are welcome but please keep flaming to a minimum.

If you have any suggestions please open a ticket at https://github.com/jesseeichar/scala-io/issues

I welcome patches, bug reports and suggestions for this documentation or for the libraries themselves.

The forum for discussions is the scala-incubator users group (at least for now) http://groups.google.com/group/scala-incubator

If you are interested at looking at the code, you are welcome to take a look at: https://github.com/jesseeichar/scala-io

As an example of what Scala IO brings to the table the following examples compare Java IO vs Scala IO performing a simple task of reading data from two URLs and writing them to a file. (I found it amusing that I actually messed up the Java example the first try and had to debug it).

Scala

import java.net.URL
import scalax.io.Input.asInputConverter
import scalax.file.Path

object ScalaIOExample extends Application {
  val scalalang = new URL("http://www.scala-lang.org").asInput.bytes
  val scalatools = new URL("http://www.scala-tools.org").asInput.bytes

  Path("scalaout").write(scalalang ++ scalatools)
}

Java

import java.io.FileOutputStream;
import java.io.InputStream;
import java.net.URL;

public class JavaIOExample {
    public static void write(FileOutputStream out, String urlString) throws Exception {
        byte[] buffer = new byte[8192];
        URL url = new URL(urlString);
        InputStream in1 = url.openStream();
        try {
            int read = in1.read(buffer);
            while (read > -1) {
                out.write(buffer,0,read);
                read = in1.read(buffer);
            }
        } finally {
            in1.close();
        }

    }
    public static void main(String[] args) throws Exception {
        FileOutputStream out = new FileOutputStream("javaout");
        try {
            write(out,"http://www.scala-lang.org");
            write(out,"http://www.scala-tools.org");
        } finally {
            out.close();
        }
    }
}