#59 File IO

brian Tue 28 Mar 2006

I checked in support for basic file IO via two new methods:

class File
{
  InStream in()
  OutStream out(Bool append := false)
}

To handle the glue code between Fan and native IO facilities I created two internal classes SysOutStream and SysInStream which mixin the OutStream and InStream interfaces respectively. In Java these classes take the raw java.io.OutputStream or java.io.InputStream and handle the core IO methods. They will route the convenience stuff to the mixin body classes OutStream$ and InStream$.

I also created a new Charset class which is used to represent the character encoding being whenever translating between bytes and chars. Every stream has a current charset. The default for everything in Fan will be UTF-8.

Actually implementing unbuffered charset encoding with the binary stream stuff is ridiculously hard in Java. It amazes me how over-engineered the java.io and java.nio libraries are without providing fundamental basic functionality such as using OutputStreamWriter without internal buffering (that particular call is package private). I think if I jump thru enough hoops I can make CharEncoding and CharDecoding do what I want.

Login or Signup to reply.