You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by mt...@apache.org on 2009/10/15 10:09:26 UTC

svn commit: r825430 - in /commons/sandbox/runtime/trunk/src: main/java/org/apache/commons/runtime/io/ test/org/apache/commons/runtime/

Author: mturk
Date: Thu Oct 15 08:09:25 2009
New Revision: 825430

URL: http://svn.apache.org/viewvc?rev=825430&view=rev
Log:
Use FileInstance only for creating files

Modified:
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/File.java
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/FileInstance.java
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/FileStream.java
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/Stream.java
    commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestFileSys.java

Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/File.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/File.java?rev=825430&r1=825429&r2=825430&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/File.java (original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/File.java Thu Oct 15 08:09:25 2009
@@ -217,6 +217,24 @@
         return FileType.valueOf(fileType);
     }
 
+    /**
+     * Get file type.
+     *
+     * @return This file {@code FileType}.
+     *
+     * @throws ClosedDescriptorException
+     *          If this file is closed.
+     * @throws IOException
+     *          If some other I/O error occurs.
+     * @see FileType
+     */
+    public static FileType getFileType(final Descriptor fd)
+        throws IOException
+    {
+        return FileWrapper.ftype(fd);
+    }
+
+
     public EnumSet<FileProtection> getFileProtection()
         throws IOException, SecurityException
     {
@@ -547,42 +565,43 @@
     }
 
     /**
-     * Create new temporary {@code FileInstance} inide {@code path}.
+     * Create new temporary {@code FileStream} inide {@code path}.
      *
      * @param prefix temporary file prefix.
      * @param suffix temporary file sufix.
      * @param directory The directory in which the file is to be created.
      * @param preserve if {@code true} do not delete file on {@code close}.
      *
-     * @return new temporary {@code FileInstance}.
+     * @return new temporary {@code FileStream}.
      */
-    public static FileInstance createTempFile(String prefix, String suffix,
-                                              File directory, boolean preserve)
+    public static FileStream createTempFileStream(String prefix, String suffix,
+                                                  File directory,
+                                                  boolean preserve)
         throws IOException, IllegalArgumentException, SecurityException
     {
         if (prefix == null) {
             throw new IllegalArgumentException();
         }
         Descriptor fd = FileWrapper.mktemp(directory, prefix, suffix, preserve);
-        return new FileInstance(fd);
+        return new FileStream(fd);
     }
 
     /**
-     * Create new temporary {@code FileInstance} inside current directory.
+     * Create new temporary {@code FileStream} inside current directory.
      *
      * @param prefix file prefix.
      *
-     * @return new temporary {@code FileInstance}.
+     * @return new temporary {@code FileStream}.
      */
-    public static FileInstance createTempFile(String prefix, String suffix,
-                                              boolean preserve)
+    public static FileStream createTempFileStream(String prefix, String suffix,
+                                                  boolean preserve)
         throws IOException, IllegalArgumentException, SecurityException
     {
         if (prefix == null) {
             throw new IllegalArgumentException();
         }
         Descriptor fd = FileWrapper.mktemp(prefix, suffix, preserve);
-        return new FileInstance(fd);
+        return new FileStream(fd);
     }
 
     /**
@@ -659,5 +678,50 @@
             link = true;
         return stat0(getPath(), link, true);
     }
+
+    /**
+     * Return new {@link FileInfo} object for the file {@code Descriptor}.
+     *
+     * @param fd
+     *          file {@code Descriptor} for which to get the info.
+     * @throws ClosedDescriptorException
+     *          If this file is closed.
+     * @throws AsyncClosedDescriptorException
+     *          If another thread closes this file while the lock
+     *          operation is in progress.
+     * @throws IOException
+     *          If some other I/O error occurs.
+     */
+    public static FileInfo stat(Descriptor fd)
+        throws IOException, SecurityException
+    {
+        return FileWrapper.stat(fd);
+    }
+
+    /**
+     * Return file system path.
+     * <p>
+     * Returned path is in Operating system cannonical form with all relative
+     * path elements removed. Depending on the Operating system this method
+     * either returns the real operating system file name, or transformed file
+     * name by combining the currect working directory path and file path at the
+     * the time of file creation.
+     * </p>
+     *
+     * @param fd
+     *          file {@code Descriptor} for which to get the path.
+     * @return Cannonical file path.
+     *
+     * @throws ClosedDescriptorException
+     *          If this file is closed.
+     * @throws IOException
+     *          If some other I/O error occurs.
+     */
+    public static String getFileSystemPath(Descriptor fd)
+        throws IOException
+    {
+        return FileWrapper.name(fd);
+    }
+
 }
 

Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/FileInstance.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/FileInstance.java?rev=825430&r1=825429&r2=825430&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/FileInstance.java (original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/FileInstance.java Thu Oct 15 08:09:25 2009
@@ -17,172 +17,78 @@
 package org.apache.commons.runtime.io;
 
 import org.apache.commons.runtime.Descriptor;
-import org.apache.commons.runtime.Pointer;
 import org.apache.commons.runtime.exception.ClosedDescriptorException;
 import org.apache.commons.runtime.exception.AsyncClosedDescriptorException;
 import org.apache.commons.runtime.exception.InvalidDescriptorException;
 import org.apache.commons.runtime.exception.OverlappingFileLockException;
 import org.apache.commons.runtime.exception.TimeoutException;
 import org.apache.commons.runtime.util.StringManager;
-import java.io.Closeable;
-import java.io.Flushable;
 import java.io.FileNotFoundException;
 import java.io.IOException;
-import java.io.SyncFailedException;
-import java.nio.ByteBuffer;
 import java.util.Enumeration;
 import java.util.EnumSet;
 import java.util.Vector;
 
 /**
- * Allows reading from and writing to a file in a random-access manner.
- * This is different from the uni-directional sequential access that a
- * {@code FileInputStream} or {@code FileOutputStream} provides. If the file is
- * opened in read/write mode, write operations are available as well. The
- * position of the next read or write operation can be moved forwards and
- * backwards after every operation.
+ * Allows creation of file instances.
  */
-public class FileInstance extends Stream
+public final class FileInstance
 {
-    /* File's descriptor object
-     */
-    private Descriptor fd;
-    /* File's object lock
-     */
-    private Object sync = new Object();
-    /*
-     * List of all lock regions to this file.
-     */
-    private Vector<FileLockImpl> locks = new Vector<FileLockImpl>(2);
-
-    /**
-     * Return the {@link Descriptor} accosicated with this file.
-     *
-     * @return file's Descriptor object
-     */
-    public Descriptor fd()
-    {
-        return fd;
-    }
-
-    @Override
-    public boolean valid()
+    private FileInstance()
     {
-        if (fd != null)
-            return fd.valid();
-        else
-            return false;
+        // No instance
     }
 
-    /**
-     * Close this file.
-     * @see java.io.Closeable#close()
-     * @throws IOException if an I/O error occurs.
-     */
-    @Override
-    public final void close()
-        throws IOException
-    {
-        fd.close();
-    }
-
-    /**
-     * Flush the underlying file metadata.
-     * <p>
-     * {@code flush} transfers  all modified metadata of the file object
-     * referred to by {@code this} file to the disk device
-     * (or other permanent storage device)  where  that  object resides.
-     * The call blocks until the device reports that the transfer has
-     * completed.  It also flushes  metadata information associated with
-     * {@code this} Descriptor.
-     * </p>
-     *
-     * @throws SyncFailedException when the object cannot be flushed.
-     * @throws IOException if an I/O error occurs.
-     */
-    @Override
-    public final void flush()
-        throws SyncFailedException, IOException
-    {
-        fd.flush();
-    }
-
-    /**
-     * Sync the underlying file by writing any buffered data.
-     * <p>
-     * {@code sync} transfers  all  modified in-core data of the file object
-     * referred to by {@code this} file to the disk device
-     * (or other permanent storage device)  where  that  object resides.
-     * The call blocks until the device reports that the transfer has
-     * completed.  It also flushes  metadata information associated with
-     * {@code this} Descriptor.
-     * </p>
-     *
-     * @throws SyncFailedException when the object cannot be flushed.
-     * @throws IOException if an I/O error occurs.
-     */
-    @Override
-    public final void sync()
-        throws SyncFailedException, IOException
-    {
-        fd.sync();
-    }
-
-    public FileInstance(File file, EnumSet<FileOpenMode> mode)
+    public static Descriptor create(File file, EnumSet<FileOpenMode> mode)
         throws FileNotFoundException, IOException, IllegalArgumentException,
                SecurityException
     {
-        fd = FileWrapper.open(file, mode);
+        Descriptor fd = FileWrapper.open(file, mode);
         if (fd == null) {
             // File exists and EXCL mode was given
             throw new FileNotFoundException(Local.sm.get("file.EEXIST"));
         }
+        return fd;
     }
 
-    public FileInstance(File file, EnumSet<FileOpenMode> mode,
-                                   EnumSet<FileProtection> prot)
+    public static Descriptor create(File file, EnumSet<FileOpenMode> mode,
+                                    EnumSet<FileProtection> prot)
         throws FileNotFoundException, IOException, IllegalArgumentException,
                SecurityException
     {
-        fd = FileWrapper.open(file, mode, prot);
+        Descriptor fd = FileWrapper.open(file, mode, prot);
         if (fd == null) {
             // File exists and EXCL mode was given
             throw new FileNotFoundException(Local.sm.get("file.EEXIST"));
         }
-    }
-
-    /** Create new FileInstance object from the {@code fd}.
-     */
-    public FileInstance(Descriptor fd)
-    {
-        this.fd = fd;
+        return fd;
     }
 
     /**
-     * The "standard" input stream {@code FileInstance}.
+     * The "standard" input stream {@code FileStream}.
      */
-    public static final FileInstance STDIN;
+    public static final FileStream STDIN;
     /**
-     * The "standard" output stream {@code FileInstance}.
+     * The "standard" output stream {@code FileStream}.
      */
-    public static final FileInstance STDOUT;
+    public static final FileStream STDOUT;
     /**
-     * The "standard" error stream {@code FileInstance}.
+     * The "standard" error stream {@code FileStream}.
      */
-    public static final FileInstance STDERR;
+    public static final FileStream STDERR;
 
     static {
-        /* Initialize the "standard" FileInstances.
+        /* Initialize the "standard" FileStream.
          * Note that those descriptors can be NULL in
-         * case the FileWrapper.open call fails.
+         * case the FileStream.open call fails.
          */
-        STDIN  = new FileInstance(FileWrapper.open(0, null));
-        STDOUT = new FileInstance(FileWrapper.open(1, null));
-        STDERR = new FileInstance(FileWrapper.open(2, null));
+        STDIN  = new FileStream(FileWrapper.open(0, null));
+        STDOUT = new FileStream(FileWrapper.open(1, null));
+        STDERR = new FileStream(FileWrapper.open(2, null));
     }
 
     /**
-     * Create new {@code FileInstance} that is bound to the spacified standard
+     * Create new {@code FileStream} that is bound to the spacified standard
      * I/O device (standard input, standard output, or standard error).
      * <p>
      * FileInstance returned can be used by applications that need to
@@ -209,15 +115,15 @@
      * @return new {@code FileInstance} connected to standard stream.
      *
      */
-    public static FileInstance openStdStream(int which,
-                                             EnumSet<FileOpenMode> mode)
+    public static FileStream createStdStream(int which,
+                                          EnumSet<FileOpenMode> mode)
         throws IllegalArgumentException
     {
         if (which < 0 || which > 2) {
             throw new IllegalArgumentException();
         }
         Descriptor fd = FileWrapper.open(which, mode);
-        return new FileInstance(fd);
+        return new FileStream(fd);
     }
 
     /**
@@ -227,15 +133,14 @@
      *
      * @return new temporary {@code FileInstance}.
      */
-    public static FileInstance createTemp(String prefix, String suffix,
-                                          File directory, boolean preserve)
+    public static Descriptor createTemp(String prefix, String suffix,
+                                        File directory, boolean preserve)
         throws IOException, IllegalArgumentException, SecurityException
     {
         if (prefix == null) {
             throw new IllegalArgumentException();
         }
-        Descriptor fd = FileWrapper.mktemp(directory, prefix, suffix, preserve);
-        return new FileInstance(fd);
+        return FileWrapper.mktemp(directory, prefix, suffix, preserve);
     }
 
     /**
@@ -245,1173 +150,14 @@
      *
      * @return new temporary {@code FileInstance}.
      */
-    public static FileInstance createTemp(String prefix, String suffix,
-                                          boolean preserve)
+    public static Descriptor createTemp(String prefix, String suffix,
+                                        boolean preserve)
         throws IOException, IllegalArgumentException, SecurityException
     {
         if (prefix == null) {
             throw new IllegalArgumentException();
         }
-        Descriptor fd = FileWrapper.mktemp(prefix, suffix, preserve);
-        return new FileInstance(fd);
-    }
-
-    /**
-     * Clear the file errors.
-     * <p>
-     * Method clears all pending file errors and resets the
-     * end-of-file mark.
-     * </p>
-     *
-     * @throws ClosedDescriptorException
-     *          If this file is closed.
-     * @throws IOException
-     *          If some other I/O error occurs.
-     */
-    public void clearerr()
-        throws IOException
-    {
-        FileWrapper.clearerr(fd);
-        fd.clearerr();
-    }
-
-    /**
-     * Test the end-of-file indicator.
-     *
-     * @return {@code true} if end-of-file was reached.
-     *
-     * @throws ClosedDescriptorException
-     *          If this file is closed.
-     * @throws IOException
-     *          If some other I/O error occurs.
-     */
-    public boolean eof()
-        throws IOException
-    {
-        return FileWrapper.eof(fd);
-    }
-
-    /**
-     * Test the file blocking mode.
-     *
-     * @return {@code true} if file operations are blocking.
-     *
-     * @throws ClosedDescriptorException
-     *          If this file is closed.
-     * @throws IOException
-     *          If some other I/O error occurs.
-     */
-    @Override
-    public boolean isBlocking()
-        throws IOException
-    {
-        return FileWrapper.blocking(fd);
-    }
-
-    /**
-     * Set file timeout.
-     *
-     * @param timeout
-     *          File timeout value in miliseconds.
-     * @return {@code true} if timeout was set. {@code false}
-     *         if file was opened in blocking mode.
-     *
-     * @throws ClosedDescriptorException
-     *          If this file is closed.
-     * @throws IOException
-     *          If some other I/O error occurs.
-     */
-    public boolean setTimeout(int timeout)
-        throws IOException
-    {
-        return FileWrapper.tmset(fd, timeout);
-    }
-
-    /**
-     * Get file timeout.
-     *
-     * @return Current file timeout value in miliseconds.
-     *
-     * @throws ClosedDescriptorException
-     *          If this file is closed.
-     * @throws IOException
-     *          If some other I/O error occurs.
-     */
-    public int getTimeout()
-        throws IOException
-    {
-        return FileWrapper.tmget(fd);
-    }
-
-    /**
-     * Get file type.
-     *
-     * @return This file {@code FileType}.
-     *
-     * @throws ClosedDescriptorException
-     *          If this file is closed.
-     * @throws IOException
-     *          If some other I/O error occurs.
-     * @see FileType
-     */
-    public FileType getFileType()
-        throws IOException
-    {
-        return FileWrapper.ftype(fd);
-    }
-
-    /**
-     * Return cannonical file path.
-     * <p>
-     * Returned path is in Operating system cannonical form with all relative
-     * path elements removed. Depending on the Operating system this method
-     * either returns the real operating system file name, or tranformed file
-     * name by combining the currect working directory path and file path at the
-     * the time of file creation.
-     * </p>
-     *
-     * @return Cannonical file path.
-     *
-     * @throws ClosedDescriptorException
-     *          If this file is closed.
-     * @throws IOException
-     *          If some other I/O error occurs.
-     */
-    public String getPath()
-        throws IOException
-    {
-        return FileWrapper.name(fd);
-    }
-
-    private boolean regionOverlaps(long offset, long length)
-    {
-        for (Enumeration<FileLockImpl> e = locks.elements(); e.hasMoreElements();) {
-            try {
-                FileLockImpl lck = e.nextElement();
-                /* Check if we already have the valid lock
-                 * for the requested region.
-                 */
-                if (lck.isValid()) {
-                    if (lck.overlaps(offset, length)) {
-                        return true;
-                    }
-                }
-                else {
-                    locks.remove(lck);
-                }
-            } catch (Throwable te) {
-            }
-        }
-        return false;
-    }
-
-    /**
-     * Return new {@link FileInfo} object.
-     *
-     * @throws ClosedDescriptorException
-     *          If this file is closed.
-     * @throws AsyncClosedDescriptorException
-     *          If another thread closes this file while the lock
-     *          operation is in progress.
-     * @throws IOException
-     *          If some other I/O error occurs.
-     */
-    public FileInfo stat()
-        throws IOException, SecurityException
-    {
-        return FileWrapper.stat(fd);
-    }
-
-    /**
-     * Lock the entire file.
-     * <p>
-     * To simulate the {@link java.nio.channels.FileChannel#tryLock} use
-     * the {@link FileLockType#NONBLOCK} type.
-     * </p>
-     *
-     * @param type
-     *          {@code FileLockType} to acquire.
-     *
-     * @throws ClosedDescriptorException
-     *          If this file is closed.
-     * @throws AsyncClosedDescriptorException
-     *          If another thread closes this file while the lock
-     *          operation is in progress.
-     * @throws TimeoutException
-     *          If lock operation times out.
-     * @throws IOException
-     *          If some other I/O error occurs.
-     * @see FileLock#release
-     */
-    public FileLock lock(EnumSet<FileLockType> type)
-        throws OverlappingFileLockException, IOException
-    {
-        if (regionOverlaps(0L, -1L)) {
-            /* We already have at least one lock, so we cannot
-             * lock the entire file.
-             */
-            throw new OverlappingFileLockException();
-        }
-
-        FileWrapper.lock(fd, type);
-        FileLockImpl lock = new FileLockImpl(fd, type);
-        /* Add the FileLock to the list of locks
-         */
-        locks.add(lock);
-        return lock;
-    }
-
-    /**
-     * Lock the file region.
-     * <p>
-     * Locking a region of file gives a locking process exclusive access to
-     * the specified file region. Locking can go beyond the end of the current
-     * file. This is useful to coordinate adding records to the end of file.
-     * </p>
-     * <p>
-     * <b>Warning:</b>
-     * <br/>
-     * Locks may not overlap and existing region of the file.
-     * </p>
-     *
-     * @param type
-     *          {@code FileLockType} to acquire.
-     * @param offset
-     *          The offset in bytes where the lock should begin.
-     * @param length
-     *          The length of the byte region to be locked.
-     *
-     * @throws IllegalArgumentException
-     *          If {@code offset < 0} or {@code length < 0}.
-     * @throws ClosedDescriptorException
-     *          If this file is closed.
-     * @throws AsyncClosedDescriptorException
-     *          If another thread closes this file while the lock
-     *          operation is in progress.
-     * @throws TimeoutException
-     *          If read operation times out.
-     * @throws IOException
-     *          If some other I/O error occurs.
-     * @see FileLock#release
-     */
-    public FileLock lock(EnumSet<FileLockType> type, long offset, long length)
-        throws OverlappingFileLockException, IllegalArgumentException,
-               IOException
-    {
-        if (offset < 0 || length < 0 || offset < length) {
-            // unlock position is negative
-            throw new IllegalArgumentException();
-        }
-        if (regionOverlaps(offset, length)) {
-            /* We already have locked overlapping region.
-             */
-            throw new OverlappingFileLockException();
-        }
-        FileLockImpl lock = new FileLockImpl(fd, type, offset, length);
-        /* Add the FileLock to the list of locks
-         */
-        locks.add(lock);
-        return lock;
-    }
-
-    /**
-     * Moves this file's file pointer to a new position, from where following
-     * {@code read}, {@code write} or {@code skip} operations are done. The
-     * position may be greater than the current length of the file, but the
-     * file's length will only change if the moving of the pointer is followed
-     * by a {@code write} operation.
-     *
-     * @param pos
-     *          The new file pointer position.
-     * @throws IllegalArgumentException
-     *          If {@code pos < 0}.
-     * @throws ClosedDescriptorException
-     *          If this file is closed.
-     * @throws AsyncClosedDescriptorException
-     *          If another thread closes this file while the set
-     *          operation is in progress.
-     * @throws IOException
-     *          If some other I/O error occurs.
-     */
-    public void setFilePointer(long pos)
-        throws IllegalArgumentException, IOException
-    {
-        if (pos < 0) {
-            // seek position is negative
-            throw new IllegalArgumentException();
-        }
-        synchronized (sync) {
-            FileWrapper.seek(fd, FileSeekMethod.SET.valueOf(), pos);
-        }
-    }
-
-    /**
-     * Moves this file's file pointer to a new position, from where following
-     * {@code read}, {@code write} or {@code skip} operations are done.
-     *
-     * @param moveMethod
-     *          Starting point for the file pointer move.
-     * @param off
-     *          Move offset in bytes.
-     *
-     * @throws IllegalArgumentException
-     *          If {@code moveMethod == FileSeekMethod.SET} and
-     *          {@code off < 0}.
-     * @throws ClosedDescriptorException
-     *          If this file is closed.
-     * @throws AsyncClosedDescriptorException
-     *          If another thread closes this file while this
-     *          operation is in progress.
-     * @throws IOException
-     *          If some other I/O error occurs.
-     * @see FileSeekMethod
-     */
-    public void moveFilePointer(FileSeekMethod moveMethod, long off)
-        throws IOException
-    {
-        if (moveMethod == FileSeekMethod.SET && off < 0L) {
-            // seek position is negative
-            throw new IllegalArgumentException();
-        }
-        synchronized (sync) {
-            FileWrapper.seek(fd, moveMethod.valueOf(), off);
-        }
-    }
-
-    /**
-     * Skips over {@code count} bytes in this file. Less than {@code count}
-     * bytes are skipped if the end of the file is reached or an exception is
-     * thrown during the operation. Nothing is done if {@code count} is
-     * negative.
-     *
-     * @param count
-     *          The number of bytes to skip.
-     *
-     * @return The number of bytes actually skipped.
-     *
-     * @throws ClosedDescriptorException
-     *          If this file is closed.
-     * @throws AsyncClosedDescriptorException
-     *          If another thread closes this file while this
-     *          operation is in progress.
-     * @throws IOException
-     *          If some other I/O error occurs.
-     */
-    public int skipBytes(int count)
-        throws IOException
-    {
-        if (count > 0) {
-            synchronized (sync) {
-                long cur = FileWrapper.seek(fd, FileSeekMethod.CUR.valueOf(), 0L);
-                long eof = FileWrapper.seek(fd, FileSeekMethod.END.valueOf(), 0L);
-
-                int cnt = (int)((cur + count > eof) ? eof - cur : count);
-                FileWrapper.seek(fd, FileSeekMethod.SET.valueOf(), cnt);
-                return cnt;
-            }
-        }
-        return 0;
-    }
-
-    /**
-     * Gets the current position within this file. All reads and
-     * writes take place at the current file pointer position.
-     *
-     * @return the current offset in bytes from the beginning of the file.
-     *
-     * @throws ClosedDescriptorException
-     *          If this file is closed.
-     * @throws AsyncClosedDescriptorException
-     *          If another thread closes this file while the get
-     *          operation is in progress.
-     * @throws IOException
-     *          If some other I/O error occurs.
-     */
-    public long getFilePointer()
-        throws IOException
-    {
-        return FileWrapper.seek(fd, FileSeekMethod.CUR.valueOf(), 0L);
-    }
-
-    /**
-     * Returns the length of this file in bytes.
-     *
-     * @return the file's length in bytes.
-     *
-     * @throws ClosedDescriptorException
-     *          If this file is closed.
-     * @throws AsyncClosedDescriptorException
-     *          If another thread closes this file while this
-     *          operation is in progress.
-     * @throws IOException
-     *          If some other I/O error occurs.
-     */
-    public long length()
-        throws IOException
-    {
-        synchronized (sync) {
-            long cur = FileWrapper.seek(fd, FileSeekMethod.CUR.valueOf(), 0L);
-            long end = FileWrapper.seek(fd, FileSeekMethod.END.valueOf(), 0L);
-
-            FileWrapper.seek(fd, FileSeekMethod.SET.valueOf(), cur);
-            return end;
-        }
-    }
-
-    /**
-     * Sets the length of this file to {@code newLength}. If the current file is
-     * smaller, it is expanded but the contents from the previous end of the
-     * file to the new end are undefined. The file is truncated if its current
-     * size is bigger than {@code newLength}. If the current file pointer
-     * position is in the truncated part, it is set to the end of the file.
-     *
-     * @param newLength
-     *            the new file length in bytes.
-     * @throws IllegalArgumentException
-     *          If {@code newLength < 0}.
-     * @throws ClosedDescriptorException
-     *          If this file is closed.
-     * @throws AsyncClosedDescriptorException
-     *          If another thread closes this file while the set
-     *          operation is in progress.
-     * @throws IOException
-     *          If some other I/O error occurs.
-     */
-    public void setLength(long newLength)
-        throws IllegalArgumentException, IOException
-    {
-        if (newLength < 0) {
-            throw new IllegalArgumentException();
-        }
-        synchronized (sync) {
-            FileWrapper.trunc(fd, newLength);
-        }
-    }
-
-    /**
-     * Reads a single byte from the current position in this file and returns
-     * it as an integer in the range from 0 to 255. Returns {@code -1} if the
-     * end of the file has been reached. Blocks until one byte has been read,
-     * the end of the file is detected or an exception is thrown.
-     *
-     * @return The byte read or {@code -1} if the end of the file has been reached.
-     * @throws ClosedDescriptorException
-     *          If this file is closed.
-     * @throws AsyncClosedDescriptorException
-     *          If another thread closes this file while the read
-     *          operation is in progress.
-     * @throws TimeoutException
-     *          If read operation times out.
-     * @throws IOException
-     *          If some other I/O error occurs.
-     */
-    public int read()
-        throws IOException
-    {
-        return FileWrapper.read(fd);
-    }
-
-    /**
-     * Reads bytes from the current position in this file and stores them in the
-     * byte array {@code buffer}. The maximum number of bytes read corresponds
-     * to the size of {@code buffer}. Blocks until at least one byte has been
-     * read if the file is in blocking mode.
-     *
-     * @param buffer
-     *            The byte array in which to store the bytes read.
-     * @return The number of bytes actually read or {@code -1} if the end of
-     *         the file has been reached.
-     *
-     * @throws ClosedDescriptorException
-     *          If this file is closed.
-     * @throws AsyncClosedDescriptorException
-     *          If another thread closes this file while the read
-     *             operation is in progress.
-     * @throws TimeoutException
-     *          If read operation times out.
-     * @throws IOException
-     *             if this file is closed or another I/O error occurs.
-     */
-    public int read(byte[] buffer)
-        throws IOException
-    {
-        if (buffer.length == 0) {
-            return 0;
-        }
-        return FileWrapper.read(fd, buffer, 0, buffer.length);
-    }
-
-    /**
-     * Reads at most {@code count} bytes from the current position in this file
-     * and stores them in the byte array {@code buffer} starting at
-     * {@code offset}. Blocks until {@code count} bytes have been read,
-     * the end of the file is reached or an exception is thrown.
-     *
-     * @param buffer
-     *          The array in which to store the bytes read from this file.
-     * @param offset
-     *          The initial position in {@code buffer} to store the bytes read
-     *          from this file.
-     * @param count
-     *          The maximum number of bytes to store in {@code buffer}.
-     * @return The number of bytes actually read or {@code -1} if the end of
-     *         the stream has been reached.
-     *
-     * @throws IndexOutOfBoundsException
-     *          If {@code offset < 0} or {@code count < 0}, or if
-     *          {@code offset + count} is greater than the size of
-     *          {@code buffer}.
-     * @throws ClosedDescriptorException
-     *          If this file is closed.
-     * @throws AsyncClosedDescriptorException
-     *          If another thread closes this file while the read
-     *             operation is in progress.
-     * @throws TimeoutException
-     *          If read operation times out.
-     * @throws IOException
-     *          If some other I/O error occurs.
-     */
-    public int read(byte[] buffer, int offset, int count)
-        throws IndexOutOfBoundsException, IOException
-    {
-        if (count > (buffer.length - offset) || count < 0 || offset < 0)
-            throw new IndexOutOfBoundsException();
-        if (count == 0) {
-            /* Returning zero usually represents a timeout.
-             */
-            return 0;
-        }
-        return FileWrapper.read(fd, buffer, offset, count);
-    }
-
-    /**
-     * Reads bytes from the current position in this file and stores them in the
-     * {@code pointer}. The maximum number of bytes read corresponds
-     * to the size of {@code pointer}. Blocks until at least one byte has been
-     * read if the file is in blocking mode.
-     *
-     * @param pointer
-     *            The {@code Pointer} in which to store the bytes read.
-     * @return The number of bytes actually read or {@code -1} if the end of
-     *         the file has been reached.
-     *
-     * @throws NullPointerException
-     *          If {@code pointer} is {@code null}.
-     * @throws ClosedDescriptorException
-     *          If this file is closed.
-     * @throws AsyncClosedDescriptorException
-     *          If another thread closes this file while the read
-     *             operation is in progress.
-     * @throws TimeoutException
-     *          If read operation times out.
-     * @throws IOException
-     *             if this file is closed or another I/O error occurs.
-     */
-    public long read(Pointer pointer)
-        throws NullPointerException, IOException
-    {
-        if (pointer.isNull())
-            throw new NullPointerException();
-        return FileWrapper.read(fd, pointer, 0L, pointer.sizeof());
-    }
-
-    /**
-     * Reads at most {@code count} bytes from the current position in this file
-     * and stores them in the Pointer {@code pointer} starting at
-     * {@code offset}. Blocks until {@code count} bytes have been read,
-     * the end of the file is reached or an exception is thrown.
-     *
-     * @param pointer
-     *          The {code Pointer} in which to store the bytes read from
-     *          this file.
-     * @param offset
-     *          The initial position in {@code pointer} to store the bytes read
-     *          from this file.
-     * @param count
-     *          The maximum number of bytes to store in {@code pointer}.
-     *
-     * @return The number of bytes actually read or {@code -1} if the end of
-     *         the stream has been reached.
-     *
-     * @throws NullPointerException
-     *          If {@code pointer} is {@code null}.
-     * @throws IndexOutOfBoundsException
-     *          If {@code offset < 0} or {@code count < 0}, or if
-     *          {@code offset + count} is greater than the size of
-     *          {@code buffer}.
-     * @throws ClosedDescriptorException
-     *          If this file is closed.
-     * @throws AsyncClosedDescriptorException
-     *          If another thread closes this file while the read
-     *             operation is in progress.
-     * @throws TimeoutException
-     *          If read operation times out.
-     * @throws IOException
-     *          If some other I/O error occurs.
-     */
-    public long read(Pointer pointer, long offset, long count)
-        throws NullPointerException, IndexOutOfBoundsException, IOException
-    {
-        if (pointer.isNull())
-            throw new NullPointerException();
-        if (count < 0 || offset < 0) {
-            throw new IndexOutOfBoundsException();
-        }
-        if (count == 0L) {
-            /* Returning zero usually represents a timeout.
-             */
-            return 0L;
-        }
-        return FileWrapper.read(fd, pointer, offset, count);
-    }
-
-    /**
-     * Reads bytes from the current position in this file and stores them in the
-     * {@code buffer}. The maximum number of bytes read corresponds
-     * to the size of {@code buffer}. Blocks until at least one byte has been
-     * read if the file is in blocking mode.
-     *
-     * @param buffer
-     *            The {@code ByteBuffer} in which to store the bytes read.
-     * @return The number of bytes actually read or {@code -1} if the end of
-     *         the file has been reached.
-     *
-     * @throws ClosedDescriptorException
-     *          If this file is closed.
-     * @throws AsyncClosedDescriptorException
-     *          If another thread closes this file while the read
-     *             operation is in progress.
-     * @throws TimeoutException
-     *          If read operation times out.
-     * @throws IOException
-     *             if this file is closed or another I/O error occurs.
-     */
-    public int read(ByteBuffer buffer)
-        throws IOException
-    {
-        return FileWrapper.read(fd, buffer, 0, buffer.capacity());
-    }
-
-    /**
-     * Reads at most {@code count} bytes from the current position in this file
-     * and stores them in the ByteBuffer {@code buffer} starting at
-     * {@code offset}. Blocks until {@code count} bytes have been read,
-     * the end of the file is reached or an exception is thrown.
-     *
-     * @param buffer
-     *          The {code ByteBuffer} in which to store the bytes read from
-     *          this file.
-     * @param offset
-     *          The initial position in {@code buffer} to store the bytes read
-     *          from this file.
-     * @param count
-     *          The maximum number of bytes to store in {@code buffer}.
-     *
-     * @return The number of bytes actually read or {@code -1} if the end of
-     *         the stream has been reached.
-     *
-     * @throws IndexOutOfBoundsException
-     *          If {@code offset < 0} or {@code count < 0}, or if
-     *          {@code offset + count} is greater than the size of
-     *          {@code buffer}.
-     * @throws ClosedDescriptorException
-     *          If this file is closed.
-     * @throws AsyncClosedDescriptorException
-     *          If another thread closes this file while the read
-     *             operation is in progress.
-     * @throws TimeoutException
-     *          If read operation times out.
-     * @throws IOException
-     *          If some other I/O error occurs.
-     */
-    public int read(ByteBuffer buffer, int offset, int count)
-        throws IndexOutOfBoundsException, IOException
-    {
-        if (count > (buffer.capacity() - offset) || count < 0 || offset < 0)
-            throw new IndexOutOfBoundsException();
-        if (count == 0) {
-            /* Returning zero usually represents a timeout.
-             */
-            return 0;
-        }
-        return FileWrapper.read(fd, buffer, offset, count);
-    }
-
-    /**
-     * Writes a byte to this file, starting at the current file pointer. Only
-     * the least significant byte of the integer {@code b} is written.
-     *
-     * @param b
-     *            the byte to write to this file.
-     *
-     * @return The number of bytes actually written.
-     *
-     * @throws ClosedDescriptorException
-     *          If this file is closed.
-     * @throws AsyncClosedDescriptorException
-     *          If another thread closes this file while the read
-     *             operation is in progress.
-     * @throws TimeoutException
-     *          If write operation times out.
-     * @throws IOException
-     *          If some other I/O error occurs.
-     */
-    public int write(int b)
-        throws IOException
-    {
-        return FileWrapper.write(fd, b);
-    }
-
-    /**
-     * Writes the entire contents of the byte array {@code buffer} to this file,
-     * starting at the current file pointer.
-     *
-     * @param buffer
-     *            the buffer to write.
-     * @return The number of bytes actually written.
-     *
-     * @throws ClosedDescriptorException
-     *          If this file is closed.
-     * @throws AsyncClosedDescriptorException
-     *          If another thread closes this file while the write
-     *             operation is in progress.
-     * @throws TimeoutException
-     *          If write operation times out.
-     * @throws IOException
-     *          If some other I/O error occurs.
-     */
-    public int write(byte[] buffer)
-        throws IOException
-    {
-        if (buffer.length == 0) {
-            return 0;
-        }
-        return FileWrapper.write(fd, buffer, 0, buffer.length);
-    }
-
-    /**
-     * Writes {@code count} bytes from the byte array {@code buffer} to this
-     * file, starting at the current file pointer and using {@code offset} as
-     * the first position within {@code buffer} to get bytes.
-     *
-     * @param buffer
-     *            The buffer to write to this file.
-     * @param offset
-     *            The index of the first byte in {@code buffer} to write.
-     * @param count
-     *            The number of bytes from {@code buffer} to write.
-     * @return The number of bytes actually written.
-     *
-     * @throws IndexOutOfBoundsException
-     *          If {@code offset < 0} or {@code count < 0}, or if
-     *          {@code offset + count} is greater than the size of
-     *          {@code buffer}.
-     * @throws ClosedDescriptorException
-     *          If this file is closed.
-     * @throws AsyncClosedDescriptorException
-     *          If another thread closes this file while the write
-     *             operation is in progress.
-     * @throws TimeoutException
-     *          If write operation times out.
-     * @throws IOException
-     *          If some other I/O error occurs.
-     */
-    public int write(byte[] buffer, int offset, int count)
-        throws IndexOutOfBoundsException, IOException
-    {
-        if (count > (buffer.length - offset) || count < 0 || offset < 0) {
-            throw new IndexOutOfBoundsException();
-        }
-        if (count == 0) {
-            return 0;
-        }
-        return FileWrapper.write(fd, buffer, offset, count);
-    }
-
-    /**
-     * Writes the entire contents of the Pointer {@code pointer} to this file,
-     * starting at the current file pointer.
-     *
-     * @param pointer
-     *            the {@code Pointer} to write.
-     * @return The number of bytes actually written.
-     *
-     * @throws NullPointerException
-     *          If {@code pointer} is {@code null}.
-     * @throws ClosedDescriptorException
-     *          If this file is closed.
-     * @throws AsyncClosedDescriptorException
-     *          If another thread closes this file while the write
-     *             operation is in progress.
-     * @throws TimeoutException
-     *          If write operation times out.
-     * @throws IOException
-     *          If some other I/O error occurs.
-     */
-    public long write(Pointer pointer)
-        throws NullPointerException, IOException
-    {
-        if (pointer.isNull())
-            throw new NullPointerException();
-        return FileWrapper.write(fd, pointer, 0L, pointer.sizeof());
-    }
-
-    /**
-     * Writes {@code count} bytes from the Pointer {@code pointer} to this
-     * file, starting at the current file pointer and using {@code offset} as
-     * the first position within {@code pointer} to get bytes.
-     *
-     * @param pointer
-     *            The {@code Pointer} to write to this file.
-     * @param offset
-     *            The index of the first byte in {@code pointer} to write.
-     * @param count
-     *            The number of bytes from {@code pointer} to write.
-     * @return The number of bytes actually written.
-     *
-     * @throws NullPointerException
-     *          If {@code pointer} is {@code null}.
-     * @throws IndexOutOfBoundsException
-     *          If {@code offset < 0} or {@code count < 0}, or if
-     *          {@code offset + count} is greater than the size of
-     *          {@code pointer}.
-     * @throws ClosedDescriptorException
-     *          If this file is closed.
-     * @throws AsyncClosedDescriptorException
-     *          If another thread closes this file while the write
-     *             operation is in progress.
-     * @throws TimeoutException
-     *          If write operation times out.
-     * @throws IOException
-     *          If some other I/O error occurs.
-     */
-    public long write(Pointer pointer, int offset, int count)
-        throws IndexOutOfBoundsException, IOException
-    {
-        if (pointer.isNull())
-            throw new NullPointerException();
-        if (count < 0L || offset < 0L) {
-            throw new IndexOutOfBoundsException();
-        }
-        if (count == 0) {
-            return 0;
-        }
-        return FileWrapper.write(fd, pointer, offset, count);
-    }
-
-    /**
-     * Writes the entire contents of the ByteBuffer {@code buffer} to this file,
-     * starting at the current file pointer.
-     *
-     * @param buffer
-     *            The {@code ByteBuffer} to write.
-     * @return The number of bytes actually written.
-     *
-     * @throws ClosedDescriptorException
-     *          If this file is closed.
-     * @throws AsyncClosedDescriptorException
-     *          If another thread closes this file while the write
-     *             operation is in progress.
-     * @throws TimeoutException
-     *          If write operation times out.
-     * @throws IOException
-     *          If some other I/O error occurs.
-     */
-    public int write(ByteBuffer buffer)
-        throws IOException
-    {
-        return FileWrapper.write(fd, buffer, 0, buffer.capacity());
-    }
-
-    /**
-     * Writes {@code count} bytes from the ByteBuffer {@code buffer} to this
-     * file, starting at the current file pointer and using {@code offset} as
-     * the first position within {@code buffer} to get bytes.
-     *
-     * @param buffer
-     *            The {@code ByteBuffer} to write to this file.
-     * @param offset
-     *            The index of the first byte in {@code buffer} to write.
-     * @param count
-     *            The number of bytes from {@code buffer} to write.
-     * @return The number of bytes actually written.
-     *
-     * @throws IndexOutOfBoundsException
-     *          If {@code offset < 0} or {@code count < 0}, or if
-     *          {@code offset + count} is greater than the size of
-     *          {@code buffer}.
-     * @throws ClosedDescriptorException
-     *          If this file is closed.
-     * @throws AsyncClosedDescriptorException
-     *          If another thread closes this file while the write
-     *             operation is in progress.
-     * @throws TimeoutException
-     *          If write operation times out.
-     * @throws IOException
-     *          If some other I/O error occurs.
-     */
-    public int write(ByteBuffer buffer, int offset, int count)
-        throws IndexOutOfBoundsException, IOException
-    {
-        if (count > (buffer.capacity() - offset) || count < 0 || offset < 0) {
-            throw new IndexOutOfBoundsException();
-        }
-        if (count == 0) {
-            return 0;
-        }
-        return FileWrapper.write(fd, buffer, offset, count);
-    }
-
-    /**
-     * Writes {@code count} arrays from the array of byte arrays {@code array}
-     * to this file, starting at the current file pointer and using
-     * {@code offset} as the first position within {@code array} to get bytes.
-     *
-     * @param array
-     *            The array of buffer arrays to write to this file.
-     * @param offset
-     *            The index of the first array in {@code array} to write.
-     * @param count
-     *            The number of arrays from {@code array} to write.
-     *
-     * @throws IndexOutOfBoundsException
-     *             if {@code count < 0}, {@code offset < 0} or
-     *             {@code count + offset} is greater than the size of
-     *             {@code array}.
-     * @throws ClosedDescriptorException
-     *          If this file is closed.
-     * @throws AsyncClosedDescriptorException
-     *          If another thread closes this file while the write
-     *             operation is in progress.
-     * @throws TimeoutException
-     *          If write operation times out.
-     * @throws IOException
-     *          If some other I/O error occurs.
-     */
-    public long write(byte[][] array, int offset, int count)
-        throws IndexOutOfBoundsException, IOException
-    {
-        if (count > (array.length - offset) || count < 0 || offset < 0) {
-            throw new IndexOutOfBoundsException();
-        }
-        if (count == 0) {
-            return 0;
-        }
-        return FileWrapper.write(fd, array, offset, count);
-    }
-
-
-    /**
-     * Writes {@code count} arrays from the ByteBufferr {@code array}
-     * to this file, starting at the current file pointer and using
-     * {@code offset} as the first position within {@code array} to get bytes.
-     *
-     * @param array
-     *            The {@code ByteBuffer} array to write to this file.
-     * @param offset
-     *            The index of the first array in {@code array} to write.
-     * @param count
-     *            The number of arrays from {@code array} to write.
-     * @throws IndexOutOfBoundsException
-     *             if {@code count < 0}, {@code offset < 0} or
-     *             {@code count + offset} is greater than the size of
-     *             {@code array}.
-     * @throws ClosedDescriptorException
-     *          If this file is closed.
-     * @throws AsyncClosedDescriptorException
-     *          If another thread closes this file while the write
-     *             operation is in progress.
-     * @throws TimeoutException
-     *          If write operation times out.
-     * @throws IOException
-     *          If some other I/O error occurs.
-     */
-    public long write(ByteBuffer[] array, int offset, int count)
-        throws IndexOutOfBoundsException, IOException
-    {
-        if (count > (array.length - offset) || count < 0 || offset < 0) {
-            throw new IndexOutOfBoundsException();
-        }
-        if (count == 0) {
-            return 0;
-        }
-        return FileWrapper.write(fd, array, offset, count);
-    }
-
-
-    /**
-     * Writes {@code count} bytes from the byte array {@code buffer} to this
-     * file, starting at the current file pointer and using {@code offset} as
-     * the first position within {@code buffer} to get bytes.
-     * <p>
-     * Method tries to fully write provided data blocking if necessary
-     * regardless of file blocking mode.
-     * </p>
-     *
-     * @param buffer
-     *            The buffer to write to this file.
-     * @param offset
-     *            The index of the first byte in {@code buffer} to write.
-     * @param count
-     *            The number of bytes from {@code buffer} to write.
-     * @return The number of bytes actually written.
-     *
-     * @throws IndexOutOfBoundsException
-     *             if {@code count < 0}, {@code offset < 0} or
-     *             {@code count + offset} is greater than the size of
-     *             {@code array}.
-     * @throws ClosedDescriptorException
-     *          If this file is closed.
-     * @throws AsyncClosedDescriptorException
-     *          If another thread closes this file while the write
-     *             operation is in progress.
-     * @throws IOException
-     *          If some other I/O error occurs.
-     */
-    public int writeFully(byte[] buffer, int offset, int count)
-        throws IndexOutOfBoundsException, IOException
-    {
-        if (count > (buffer.length - offset) || count < 0 || offset < 0) {
-            throw new IndexOutOfBoundsException();
-        }
-        if (count == 0) {
-            return 0;
-        }
-        return FileWrapper.writeFully(fd, buffer, offset, count);
-    }
-
-    /**
-     * Writes the entire contents of the ByteBuffer {@code buffer} to this file,
-     * starting at the current file pointer.
-     *
-     * @param buffer
-     *            the {@code ByteBuffer} to write.
-     * @return The number of bytes actually written.
-     *
-     * @throws ClosedDescriptorException
-     *          If this file is closed.
-     * @throws AsyncClosedDescriptorException
-     *          If another thread closes this file while the write
-     *             operation is in progress.
-     * @throws IOException
-     *          If some other I/O error occurs.
-     */
-    public int writeFully(ByteBuffer buffer)
-        throws IOException
-    {
-        return FileWrapper.write(fd, buffer, 0, buffer.capacity());
-    }
-
-    /**
-     * Writes {@code count} bytes from the ByteBuffer {@code buffer} to this
-     * file, starting at the current file pointer and using {@code offset} as
-     * the first position within {@code buffer} to get bytes.
-     * <p>
-     * Method tries to fully write provided data blocking if necessary
-     * regardless of file blocking mode.
-     * </p>
-     *
-     * @param buffer
-     *            The buffer to write to this file.
-     * @param offset
-     *            The index of the first byte in {@code buffer} to write.
-     * @param count
-     *            The number of bytes from {@code buffer} to write.
-     * @return The number of bytes actually written.
-     *
-     * @throws IndexOutOfBoundsException
-     *          If {@code offset < 0} or {@code count < 0}, or if
-     *          {@code offset + count} is greater than the size of
-     *          {@code buffer}.
-     * @throws ClosedDescriptorException
-     *          If this file is closed.
-     * @throws AsyncClosedDescriptorException
-     *          If another thread closes this file while the write
-     *             operation is in progress.
-     * @throws IOException
-     *          If some other I/O error occurs.
-     */
-    public int writeFully(ByteBuffer buffer, int offset, int count)
-        throws IndexOutOfBoundsException, IOException
-    {
-        if (count > (buffer.capacity() - offset) || count < 0 || offset < 0) {
-            throw new IndexOutOfBoundsException();
-        }
-        if (count == 0) {
-            return 0;
-        }
-        return FileWrapper.writeFully(fd, buffer, offset, count);
-    }
-
-
-    /**
-     * Writes the entire contents of the Pointer {@code pointer} to this file,
-     * starting at the current file pointer.
-     *
-     * @param pointer
-     *            the {@code Pointer} to write.
-     * @return The number of bytes actually written.
-     *
-     * @throws NullPointerException
-     *          If {@code pointer} is {@code null}.
-     * @throws ClosedDescriptorException
-     *          If this file is closed.
-     * @throws AsyncClosedDescriptorException
-     *          If another thread closes this file while the write
-     *             operation is in progress.
-     * @throws TimeoutException
-     *          If write operation times out.
-     * @throws IOException
-     *          If some other I/O error occurs.
-     */
-    public long writeFully(Pointer pointer)
-        throws NullPointerException, IOException
-    {
-        if (pointer.isNull())
-            throw new NullPointerException();
-        return FileWrapper.write(fd, pointer, 0L, pointer.sizeof());
-    }
-
-    /**
-     * Writes {@code count} bytes from the Pointer {@code pointer} to this
-     * file, starting at the current file pointer and using {@code offset} as
-     * the first position within {@code buffer} to get bytes.
-     * <p>
-     * Method tries to fully write provided data blocking if necessary
-     * regardless of file blocking mode.
-     * </p>
-     *
-     * @param pointer
-     *            The {@code Pointer} to write to this file.
-     * @param offset
-     *            The index of the first byte in {@code pointer} to write.
-     * @param count
-     *            The number of bytes from {@code pointer} to write.
-     * @return The number of bytes actually written.
-     *
-     * @throws NullPointerException
-     *          If {@code pointer} is {@code null}.
-     * @throws IndexOutOfBoundsException
-     *          If {@code offset < 0} or {@code count < 0}, or if
-     *          {@code offset + count} is greater than the size of
-     *          {@code pointer}.
-     * @throws ClosedDescriptorException
-     *          If this file is closed.
-     * @throws AsyncClosedDescriptorException
-     *          If another thread closes this file while the write
-     *             operation is in progress.
-     * @throws IOException
-     *          If some other I/O error occurs.
-     */
-    public long writeFully(Pointer pointer, long offset, long count)
-        throws NullPointerException, IndexOutOfBoundsException, IOException
-    {
-        if (pointer.isNull())
-            throw new NullPointerException();
-        if (count == 0) {
-            return 0;
-        }
-        return FileWrapper.writeFully(fd, pointer, offset, count);
+        return FileWrapper.mktemp(prefix, suffix, preserve);
     }
 
 }

Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/FileStream.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/FileStream.java?rev=825430&r1=825429&r2=825430&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/FileStream.java (original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/FileStream.java Thu Oct 15 08:09:25 2009
@@ -126,29 +126,6 @@
         fd.sync();
     }
 
-    public FileStream(File file, EnumSet<FileOpenMode> mode)
-        throws FileNotFoundException, IOException, IllegalArgumentException,
-               SecurityException
-    {
-        fd = FileWrapper.open(file, mode);
-        if (fd == null) {
-            // File exists and EXCL mode was given
-            throw new FileNotFoundException(Local.sm.get("file.EEXIST"));
-        }
-    }
-
-    public FileStream(File file, EnumSet<FileOpenMode> mode,
-                                 EnumSet<FileProtection> prot)
-        throws FileNotFoundException, IOException, IllegalArgumentException,
-               SecurityException
-    {
-        fd = FileWrapper.open(file, mode, prot);
-        if (fd == null) {
-            // File exists and EXCL mode was given
-            throw new FileNotFoundException(Local.sm.get("file.EEXIST"));
-        }
-    }
-
     /** Create new FileStream object from the {@code fd}.
      */
     public FileStream(Descriptor fd)
@@ -306,23 +283,6 @@
     }
 
     /**
-     * Return new {@link FileInfo} object.
-     *
-     * @throws ClosedDescriptorException
-     *          If this file is closed.
-     * @throws AsyncClosedDescriptorException
-     *          If another thread closes this file while the lock
-     *          operation is in progress.
-     * @throws IOException
-     *          If some other I/O error occurs.
-     */
-    public FileInfo stat()
-        throws IOException, SecurityException
-    {
-        return FileWrapper.stat(fd);
-    }
-
-    /**
      * Lock the entire file.
      * <p>
      * To simulate the {@link java.nio.channels.FileChannel#tryLock} use
@@ -589,6 +549,26 @@
     }
 
     /**
+     * Return new {@link FileInfo} object for this file stream.
+     *
+     * @throws ClosedDescriptorException
+     *          If this file is closed.
+     * @throws AsyncClosedDescriptorException
+     *          If another thread closes this file while the lock
+     *          operation is in progress.
+     * @throws IOException
+     *          If some other I/O error occurs.
+     */
+    public FileInfo stat()
+        throws IOException, SecurityException
+    {
+        synchronized (sync) {
+            return FileWrapper.stat(fd);
+        }
+    }
+
+
+    /**
      * Reads a single byte from the current position in this file and returns
      * it as an integer in the range from 0 to 255. Returns {@code -1} if the
      * end of the file has been reached. Blocks until one byte has been read,

Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/Stream.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/Stream.java?rev=825430&r1=825429&r2=825430&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/Stream.java (original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/Stream.java Thu Oct 15 08:09:25 2009
@@ -120,48 +120,4 @@
         return false;
     }
 
-    /**
-     * Reads a single byte from the current position in this stream and returns
-     * it as an integer in the range from 0 to 255. Returns {@code -1} if the
-     * end of the stream has been reached. If the stream is in blocking mode,
-     * it blocks until one byte has been read, the end of the stream is
-     * detected or an exception is thrown.
-     *
-     * @return The byte read or {@code -1} if the end of the stream has
-     *         been reached.
-     * @throws ClosedDescriptorException
-     *          If this stream is closed.
-     * @throws AsyncClosedDescriptorException
-     *          If another thread closes this stream while the read
-     *          operation is in progress.
-     * @throws TimeoutException
-     *          If read operation times out.
-     * @throws IOException
-     *          If some other I/O error occurs.
-     */
-    public abstract int read()
-        throws IOException;
-
-    /**
-     * Writes a byte to this stream, starting at the current file pointer. Only
-     * the least significant byte of the integer {@code b} is written.
-     *
-     * @param b
-     *            the byte to write to this stream.
-     *
-     * @return The number of bytes actually written.
-     *
-     * @throws ClosedDescriptorException
-     *          If this stream is closed.
-     * @throws AsyncClosedDescriptorException
-     *          If another thread closes this stream while the read
-     *             operation is in progress.
-     * @throws TimeoutException
-     *          If write operation times out.
-     * @throws IOException
-     *          If some other I/O error occurs.
-     */
-    public abstract int write(int b)
-        throws IOException;
-
 }

Modified: commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestFileSys.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestFileSys.java?rev=825430&r1=825429&r2=825430&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestFileSys.java (original)
+++ commons/sandbox/runtime/trunk/src/test/org/apache/commons/runtime/TestFileSys.java Thu Oct 15 08:09:25 2009
@@ -47,7 +47,7 @@
         throws Exception
     {
         File file = new File("ftest1.txt");
-        FileInstance f = new FileInstance(file, EnumSet.of(FileOpenMode.RDWR, FileOpenMode.CREATE));
+        Descriptor f = FileInstance.create(file, EnumSet.of(FileOpenMode.RDWR, FileOpenMode.CREATE));
 
         assertFalse("FileInstance", f == null);
         System.out.println();
@@ -59,8 +59,8 @@
     {
         File file = new File("ftest1.txt");
         try {
-            FileInstance f = new FileInstance(file, EnumSet.of(FileOpenMode.RDWR, FileOpenMode.CREATE, FileOpenMode.EXCL));
-            assertFalse("FileInstance", f != null);
+            Descriptor f = FileInstance.create(file, EnumSet.of(FileOpenMode.RDWR, FileOpenMode.CREATE, FileOpenMode.EXCL));
+            assertFalse("Descriptor", f != null);
             f.close();
         }
         catch (FileNotFoundException fe) {
@@ -76,7 +76,7 @@
     {
         File file = new File("ftest1.txt");
         file.delete();
-        FileInstance f = new FileInstance(file, EnumSet.of(FileOpenMode.RDWR, FileOpenMode.CREATE, FileOpenMode.EXCL));
+        Descriptor f = FileInstance.create(file, EnumSet.of(FileOpenMode.RDWR, FileOpenMode.CREATE, FileOpenMode.EXCL));
         assertFalse("FileInstance", f == null);
         f.close();
         file.delete();
@@ -110,10 +110,10 @@
         File file = new File("ftest1.rnd");
         makeRandomFile(file.getPath(), 1024 * 128);
 
-        FileInstance f = new FileInstance(file, EnumSet.of(FileOpenMode.READ, FileOpenMode.NONBLOCK));
-        assertFalse("FileInstance", f == null);
+        Descriptor d = FileInstance.create(file, EnumSet.of(FileOpenMode.READ, FileOpenMode.NONBLOCK));
+        assertFalse("Descriptor", d == null);
         byte [] buf = new byte[1024 * 128];
-
+        FileStream f = new FileStream(d);
         int rd = f.read(buf, 0, buf.length);
         System.out.println();
         System.out.println("Readed " + rd + " bytes from " + file.getPath());
@@ -134,21 +134,21 @@
     public void testFileSysMktemp()
         throws Exception
     {
-        FileInstance f = FileInstance.createTemp("tmp.", null, false);
-        assertFalse("FileInstance", f == null);
+        Descriptor f = FileInstance.createTemp("tmp.", null, false);
+        assertFalse("Descriptor", f == null);
         System.out.println();
-        System.out.println("Temporary file " + f.getPath());
+        System.out.println("Temporary file " + File.getFileSystemPath(f));
         f.close();
     }
 
     public void testFileInfo()
         throws Exception
     {
-        FileInstance f = FileInstance.createTemp("tmp.", null, false);
-        assertFalse("FileInstance", f == null);
+        Descriptor f = FileInstance.createTemp("tmp.", null, false);
+        assertFalse("Descriptor", f == null);
         System.out.println();
-        System.out.println("Temporary file " + f.getPath());
-        FileInfo info = f.stat();
+        System.out.println("Temporary file " + File.getFileSystemPath(f));
+        FileInfo info = File.stat(f);
         System.out.println("Info Name   : " + info.Name);
         System.out.println("     Size   : " + info.Size);
         System.out.println("     Inode  : " + info.InodeId);