commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mt...@apache.org
Subject svn commit: r823244 - in /commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io: FileInstance.java FileWrapper.java
Date Thu, 08 Oct 2009 17:51:33 GMT
Author: mturk
Date: Thu Oct  8 17:51:33 2009
New Revision: 823244

URL: http://svn.apache.org/viewvc?rev=823244&view=rev
Log:
Add few more File methods

Modified:
    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/FileWrapper.java

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=823244&r1=823243&r2=823244&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  8 17:51:33 2009
@@ -160,9 +160,6 @@
      *
      * @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.
      */
@@ -174,6 +171,90 @@
     }
 
     /**
+     * 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.
+     */
+    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
@@ -187,9 +268,6 @@
      *
      * @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.
      */

Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/FileWrapper.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/FileWrapper.java?rev=823244&r1=823243&r2=823244&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/FileWrapper.java
(original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/FileWrapper.java
Thu Oct  8 17:51:33 2009
@@ -42,7 +42,8 @@
         // Nothing.
     }
 
-    private static native boolean eof0(int fd);
+    private static native boolean eof0(int fd)
+        throws IOException;
     /**
      * Returns {@code true} if file reached end-of-file.
      */
@@ -65,11 +66,55 @@
             throw new ClosedDescriptorException();
         int rc = eof1(fd.fd());
         if (rc != 0) {
+            /* This can only happen if file gets closed
+             * between the fd.valid() and eof1(...) call
+             */
             throw new IOException(Status.describe(rc));
         }
     }
 
-    private static native String name0(int fd);
+    private static native boolean blocking0(int fd)
+        throws IOException;
+    /**
+     * Returns {@code true} if file is blocking.
+     */
+    public static boolean blocking(Descriptor fd)
+        throws IOException
+    {
+        if (!fd.valid())
+            throw new ClosedDescriptorException();
+        return blocking0(fd.fd());
+    }
+
+    private static native int tmget0(int fd)
+        throws IOException;
+    /**
+     * Returns file timeout.
+     */
+    public static int tmget(Descriptor fd)
+        throws IOException
+    {
+        if (!fd.valid())
+            throw new ClosedDescriptorException();
+        return tmget0(fd.fd());
+    }
+
+    private static native int tmset0(int fd, int timeout)
+        throws IOException;
+    /**
+     * Returns file timeout.
+     */
+    public static boolean tmset(Descriptor fd, int timeout)
+        throws IOException
+    {
+        if (!fd.valid())
+            throw new ClosedDescriptorException();
+        int rc = tmget0(fd.fd());
+        return rc == 0 ? true : false;
+    }
+
+    private static native String name0(int fd)
+        throws IOException;
     /**
      * Returns real file name.
      */
@@ -81,6 +126,19 @@
         return name0(fd.fd());
     }
 
+    private static native int ftype0(int fd)
+        throws IOException;
+    /**
+     * Returns {@code FileType} name.
+     */
+    public static FileType ftype(Descriptor fd)
+        throws IOException
+    {
+        if (!fd.valid())
+            throw new ClosedDescriptorException();
+        return FileType.valueOf(ftype0(fd.fd()));
+    }
+
     private static native Descriptor open0(String path, int mode)
         throws FileNotFoundException, IOException, SecurityException;
     /**



Mime
View raw message