ref_send API 2.17
defensive programming in Java

org.joe_e.file
Class Filesystem

java.lang.Object
  extended by org.joe_e.file.Filesystem

public final class Filesystem
extends java.lang.Object

File construction. This provides a capability-safe API for access to files. A File object grants read and write access to a file or directory. Due to limitations in Java, all file references are to textual file names, not file descriptors. Multiple operations on a File may thus apply to different incarnations of the file.


Method Summary
static void checkName(java.lang.String name)
          Vets a filename.
static java.io.File file(java.io.File folder, java.lang.String child)
          Produce a File capability for a file contained in a folder.
static long length(java.io.File file)
          Gets the length of a file
static ConstArray<java.io.File> list(java.io.File dir)
          List the contents of a directory.
static java.io.InputStream read(java.io.File file)
          Opens an existing file for reading.
static java.io.OutputStream writeNew(java.io.File file)
          Creates a file for writing.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

file

public static java.io.File file(java.io.File folder,
                                java.lang.String child)
                         throws InvalidFilenameException
Produce a File capability for a file contained in a folder. The returned object is just a handle; the underlying file may not yet exist.

Parameters:
folder - containing folder
child - a single filename component, not a relative path
Returns:
a capability for the requested file
Throws:
java.lang.IllegalArgumentException - if folder is null or the empty path
InvalidFilenameException

checkName

public static void checkName(java.lang.String name)
                      throws InvalidFilenameException
Vets a filename. Checks that the argument would be interpreted as a file name rather than as a path or relative directory specifier

Parameters:
name - a single filename component, not a relative path
Throws:
InvalidFilenameException - name is rejected\

list

public static ConstArray<java.io.File> list(java.io.File dir)
                                     throws java.io.IOException
List the contents of a directory.

Parameters:
dir - directory to list
Returns:
directory entries, sorted alphabetically
Throws:
java.io.IOException - dir is not a directory, or an I/O error

length

public static long length(java.io.File file)
                   throws java.io.FileNotFoundException
Gets the length of a file

Parameters:
file - file to stat
Returns:
the length of the file in bytes
Throws:
java.io.FileNotFoundException - file not found

read

public static java.io.InputStream read(java.io.File file)
                                throws java.io.FileNotFoundException
Opens an existing file for reading.

Parameters:
file - file to open
Returns:
opened input stream
Throws:
java.io.FileNotFoundException - file not found

writeNew

public static java.io.OutputStream writeNew(java.io.File file)
                                     throws java.io.IOException
Creates a file for writing.

Parameters:
file - file to create
Returns:
opened output stream
Throws:
java.io.IOException - file could not be created

ref_send API 2.17
defensive programming in Java

Submit a bug or feature, or get help

Copyright 1998-2009 Waterken Inc. under the terms of the MIT X license.