frysk.sys
Class FileDescriptor

java.lang.Object
  extended by frysk.sys.FileDescriptor
Direct Known Subclasses:
PseudoTerminal

public class FileDescriptor
extends Object

Unix file descriptor. This object is loosely based on the Unix file-descriptor.


Field Summary
private static int CREAT
          Create a new file.
static FileDescriptor err
          File descriptor corresponding to standard error.
private  int fd
           
static FileDescriptor in
          File descriptor corresponding to standard input.
static FileDescriptor out
          File descriptor corresponding to standard output
static int RDONLY
          Open file read-only.
static int RDWR
          Open file read-write
static int WRONLY
          Open file write-only
 
Constructor Summary
FileDescriptor(File file, int accessMode)
          Create a file descriptor for the specified FILE, open with MODE.
FileDescriptor(File file, int accessMode, int prot)
          Create a new file tied to FileDescriptor with accessMode and protection.
FileDescriptor(int fd)
          Package local file descriptor used by various classes when returning a file descriptor.
FileDescriptor(String file, int accessMode)
          Create a file descriptor for the specified FILE, open in mode specified by flags.
FileDescriptor(String file, int accessMode, int prot)
          Create a new file tied to FileDescriptor with accessMode and protection.
 
Method Summary
 void close()
          Close the file descriptor.
private static void close(int fd)
          Close the file-descriptor.
private static int creat()
           
 void dup(FileDescriptor old)
          Make this FileDescriptor a dup (point at the same system object) as OLD.
private static void dup(int fd, int old)
           
protected  void finalize()
          Always clean up the file descriptor.
 int getFd()
           
 InputStream getInputStream()
          Return an input stream that can read this file descriptor.
 OutputStream getOutputStream()
          Return an output stream that can write this file descriptor.
 Size getSize()
          Return the size of a terminal window.
private static Size getSize(int fd)
           
private static int open(String file, int accessMode, int prot)
          Open the specified FILE in FLAGS; returning a file descriptor.
private static int rdonly()
           
private static int rdwr()
           
 int read()
          Read a single byte from the file descriptor.
 int read(byte[] bytes, int start, int length)
          Read bytes from the file descriptor.
private static int read(int fd)
           
private static int read(int fd, byte[] bytes, int start, int length)
           
 boolean ready()
          Poll the file descriptor determining if there is there at least one character, the end-of-file, or hangup indication available for reading?
private static boolean ready(int fd, long millisecondTimeout)
           
 boolean ready(long millisecondTimeout)
          Wait on the file descriptor for upto millesecond timeout, checking for at least one character, an eof indication, or hangup available for reading?
private static long seekCurrent(int fd, long offset)
           
 long seekCurrent(long offset)
          Seek to OFFSET from current position.
private static long seekEnd(int fd, long offset)
           
 long seekEnd(long offset)
          Seek to OFFSET from end of file.
private static long seekSet(int fd, long offset)
           
 long seekSet(long offset)
          Seek to OFFSET from start of file.
private static void setSize(int fd, Size size)
           
 void setSize(Size size)
          Set the size of a terminal window.
 String toString()
           
 int write(byte[] bytes, int start, int length)
          Write elements of BUF to the file descriptor.
 void write(int b)
          Write a single byte to the file descriptor.
private static int write(int fd, byte[] bytes, int start, int length)
           
private static void write(int fd, int b)
           
private static int wronly()
           
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

fd

private int fd

RDONLY

public static final int RDONLY
Open file read-only.


WRONLY

public static final int WRONLY
Open file write-only


RDWR

public static final int RDWR
Open file read-write


CREAT

private static final int CREAT
Create a new file. Implied by the three-param constructor.


in

public static final FileDescriptor in
File descriptor corresponding to standard input.


out

public static final FileDescriptor out
File descriptor corresponding to standard output


err

public static final FileDescriptor err
File descriptor corresponding to standard error.

Constructor Detail

FileDescriptor

FileDescriptor(int fd)
Package local file descriptor used by various classes when returning a file descriptor.


FileDescriptor

public FileDescriptor(String file,
                      int accessMode)
Create a file descriptor for the specified FILE, open in mode specified by flags.


FileDescriptor

public FileDescriptor(File file,
                      int accessMode)
Create a file descriptor for the specified FILE, open with MODE.


FileDescriptor

public FileDescriptor(String file,
                      int accessMode,
                      int prot)
Create a new file tied to FileDescriptor with accessMode and protection.


FileDescriptor

public FileDescriptor(File file,
                      int accessMode,
                      int prot)
Create a new file tied to FileDescriptor with accessMode and protection.

Method Detail

rdonly

private static int rdonly()

wronly

private static int wronly()

rdwr

private static int rdwr()

creat

private static int creat()

getFd

public int getFd()

dup

public void dup(FileDescriptor old)
Make this FileDescriptor a dup (point at the same system object) as OLD. See dup2(2).


dup

private static void dup(int fd,
                        int old)

open

private static int open(String file,
                        int accessMode,
                        int prot)
Open the specified FILE in FLAGS; returning a file descriptor. If CREAT was specified, create file based on PROT.


close

private static void close(int fd)
Close the file-descriptor.


ready

public boolean ready()
Poll the file descriptor determining if there is there at least one character, the end-of-file, or hangup indication available for reading?


ready

public boolean ready(long millisecondTimeout)
Wait on the file descriptor for upto millesecond timeout, checking for at least one character, an eof indication, or hangup available for reading?


ready

private static boolean ready(int fd,
                             long millisecondTimeout)

read

public int read()
Read a single byte from the file descriptor. Return -1 if end-of-file.


read

private static int read(int fd)

read

public int read(byte[] bytes,
                int start,
                int length)
Read bytes from the file descriptor. Return number of bytes read, or -1 of end-of-file. XXX: Since read is capped by byte[].length, int is returned.


read

private static int read(int fd,
                        byte[] bytes,
                        int start,
                        int length)

write

public void write(int b)
Write a single byte to the file descriptor.


write

private static void write(int fd,
                          int b)

write

public int write(byte[] bytes,
                 int start,
                 int length)
Write elements of BUF to the file descriptor. XXX: Since write is capped by byte[].lenght, int is returned.


write

private static int write(int fd,
                         byte[] bytes,
                         int start,
                         int length)

close

public void close()
Close the file descriptor.


finalize

protected void finalize()
Always clean up the file descriptor.

Overrides:
finalize in class Object

getInputStream

public InputStream getInputStream()
Return an input stream that can read this file descriptor.


getOutputStream

public OutputStream getOutputStream()
Return an output stream that can write this file descriptor.


toString

public String toString()
Overrides:
toString in class Object

getSize

public Size getSize()
Return the size of a terminal window. Can throw an exception if the file descriptor is not a terminal.


getSize

private static Size getSize(int fd)

setSize

public void setSize(Size size)
Set the size of a terminal window.


setSize

private static void setSize(int fd,
                            Size size)

seekSet

public long seekSet(long offset)
Seek to OFFSET from start of file.


seekSet

private static long seekSet(int fd,
                            long offset)

seekEnd

public long seekEnd(long offset)
Seek to OFFSET from end of file.


seekEnd

private static long seekEnd(int fd,
                            long offset)

seekCurrent

public long seekCurrent(long offset)
Seek to OFFSET from current position.


seekCurrent

private static long seekCurrent(int fd,
                                long offset)