commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mt...@apache.org
Subject svn commit: r821074 - in /commons/sandbox/runtime/trunk/src/main: java/org/apache/commons/runtime/io/ native/include/ native/os/unix/ native/os/win32/ native/shared/
Date Fri, 02 Oct 2009 16:07:52 GMT
Author: mturk
Date: Fri Oct  2 16:07:51 2009
New Revision: 821074

URL: http://svn.apache.org/viewvc?rev=821074&view=rev
Log:
Add java.io.RandomAccessFile replacement

Added:
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/RandomAccessFile.java
  (with props)
Modified:
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/FileWrapper.java
    commons/sandbox/runtime/trunk/src/main/native/include/acr_error.h
    commons/sandbox/runtime/trunk/src/main/native/os/unix/fsysio.c
    commons/sandbox/runtime/trunk/src/main/native/os/win32/fsysio.c
    commons/sandbox/runtime/trunk/src/main/native/shared/error.c

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=821074&r1=821073&r2=821074&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
Fri Oct  2 16:07:51 2009
@@ -18,6 +18,7 @@
 
 import org.apache.commons.runtime.Descriptor;
 import org.apache.commons.runtime.exception.ClosedDescriptorException;
+import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.util.EnumSet;
 
@@ -46,7 +47,7 @@
     }
 
     private static native Descriptor open0(String path, int mode)
-        throws IOException;
+        throws FileNotFoundException, IOException, SecurityException;
     /**
      * Open file Descriptor.
      * <p>
@@ -57,7 +58,8 @@
      * @throws IOException on error.
      */
     public static Descriptor open(File path, EnumSet<FileOpenMode> mode)
-        throws IOException, IllegalArgumentException
+        throws FileNotFoundException, IOException, IllegalArgumentException,
+               SecurityException
     {
         int imode = FileOpenMode.bitmapOf(mode);
         if (imode == 0)
@@ -67,7 +69,7 @@
     }
 
     private static native Descriptor open1(String path, int mode, int prot)
-        throws IOException;
+        throws FileNotFoundException, IOException, SecurityException;
     /**
      * Open file Descriptor.
      * <p>
@@ -79,7 +81,8 @@
      */
     public static Descriptor open(File path, EnumSet<FileOpenMode> mode,
                                   EnumSet<FileProtection> prot)
-        throws IOException, IllegalArgumentException
+        throws FileNotFoundException, IOException, IllegalArgumentException,
+               SecurityException
     {
         int imode = FileOpenMode.bitmapOf(mode);
         int iprot = FileProtection.bitmapOf(prot);
@@ -106,7 +109,7 @@
     {
         if (!fd.valid())
             throw new ClosedDescriptorException();
-        return = read0(fd.fd());
+        return read0(fd.fd());
     }
 
     private static native int read1(int fd, byte [] b, int off, int len);

Added: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/RandomAccessFile.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/RandomAccessFile.java?rev=821074&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/RandomAccessFile.java
(added)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/RandomAccessFile.java
Fri Oct  2 16:07:51 2009
@@ -0,0 +1,86 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+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 java.io.Closeable;
+import java.io.Flushable;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.SyncFailedException;
+import java.util.EnumSet;
+
+/**
+ * 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.
+ */
+public class RandomAccessFile implements Closeable, Flushable
+{
+    /* File's descriptor object
+     */
+    private Descriptor fd;
+
+    /**
+     * Close this file.
+     * @see java.io.Closeable#close()
+     * @throws IOException if an I/O error occurs.
+     */
+    public final void close()
+        throws IOException
+    {
+        fd.close();
+    }
+
+    /**
+     * Flushed the underlying file by writing any buffered data.
+     * <p>
+     * {@code fsync()} transfers  all  modified in-core data of the object
+     * referred to by {@code this} Descriptor 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.
+     */
+    public final void flush()
+        throws SyncFailedException, IOException
+    {
+        fd.flush();
+    }
+
+    public RandomAccessFile(File file,  EnumSet<FileOpenMode> mode)
+        throws FileNotFoundException, IllegalArgumentException, IOException,
+               SecurityException
+    {
+        fd = FileWrapper.open(file, mode);
+        if (fd == null) {
+            // File exists and EXCL mode was given
+            // TODO: Throw something
+        }
+    }
+}

Propchange: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/RandomAccessFile.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: commons/sandbox/runtime/trunk/src/main/native/include/acr_error.h
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/include/acr_error.h?rev=821074&r1=821073&r2=821074&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/include/acr_error.h (original)
+++ commons/sandbox/runtime/trunk/src/main/native/include/acr_error.h Fri Oct  2 16:07:51
2009
@@ -51,6 +51,7 @@
     ACR_EX_ULINK,           /* java/lang/UnsatisfiedLinkError */
     ACR_EX_ENOTIMPL,        /* java/lang/UnsupportedOperationException */
     ACR_EX_EIO,             /* java/io/IOException */
+    ACR_EX_ENOTFOUND,       /* java/io/FileNotFoundException */
     ACR_EX_ESYNC,           /* java/io/SyncFailedException */
     ACR_EX_ESOCK,           /* java/net/SocketException */
     ACR_EX_CLOSED_DESC,     /* exception/ClosedDescriptorException */

Modified: commons/sandbox/runtime/trunk/src/main/native/os/unix/fsysio.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/unix/fsysio.c?rev=821074&r1=821073&r2=821074&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/unix/fsysio.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/unix/fsysio.c Fri Oct  2 16:07:51 2009
@@ -279,7 +279,10 @@
     if (rc && !ACR_STATUS_IS_EEXIST(rc) && !(flags & ACR_FOPEN_EXCL))
{
         /* Don't Throw in case of EXCL and EEXIST
          */
-        ACR_THROW_IO_IF_ERR(rc);
+        if (ACR_STATUS_IS_ENOENT(rc))
+            ACR_ThrowException(_E, THROW_NMARK, ACR_EX_ENOTFOUND, 0);
+        else
+            ACR_THROW_IO_IF_ERR(rc);
     }
     return fdo;
 }
@@ -299,7 +302,10 @@
     if (rc && !ACR_STATUS_IS_EEXIST(rc) && !(flags & ACR_FOPEN_EXCL))
{
         /* Don't Throw in case of EXCL and EEXIST
          */
-        ACR_THROW_IO_IF_ERR(rc);
+        if (ACR_STATUS_IS_ENOENT(rc))
+            ACR_ThrowException(_E, THROW_NMARK, ACR_EX_ENOTFOUND, 0);
+        else
+            ACR_THROW_IO_IF_ERR(rc);
     }
     return fdo;
 }

Modified: commons/sandbox/runtime/trunk/src/main/native/os/win32/fsysio.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/os/win32/fsysio.c?rev=821074&r1=821073&r2=821074&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/os/win32/fsysio.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/os/win32/fsysio.c Fri Oct  2 16:07:51 2009
@@ -333,7 +333,10 @@
     if (rc && !ACR_STATUS_IS_EEXIST(rc) && !(flags & ACR_FOPEN_EXCL))
{
         /* Don't Throw in case of EXCL and EEXIST
          */
-        ACR_THROW_IO_IF_ERR(rc);
+        if (ACR_STATUS_IS_ENOENT(rc))
+            ACR_ThrowException(_E, THROW_NMARK, ACR_EX_ENOTFOUND, 0);
+        else
+            ACR_THROW_IO_IF_ERR(rc);
     }
     return fdo;
 }
@@ -353,7 +356,10 @@
     if (rc && !ACR_STATUS_IS_EEXIST(rc) && !(flags & ACR_FOPEN_EXCL))
{
         /* Don't Throw in case of EXCL and EEXIST
          */
-        ACR_THROW_IO_IF_ERR(rc);
+        if (ACR_STATUS_IS_ENOENT(rc))
+            ACR_ThrowException(_E, THROW_NMARK, ACR_EX_ENOTFOUND, 0);
+        else
+            ACR_THROW_IO_IF_ERR(rc);
     }
     return fdo;
 }

Modified: commons/sandbox/runtime/trunk/src/main/native/shared/error.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/error.c?rev=821074&r1=821073&r2=821074&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/error.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/error.c Fri Oct  2 16:07:51 2009
@@ -38,6 +38,7 @@
     "java/lang/UnsatisfiedLinkError",
     "java/lang/UnsupportedOperationException",
     "java/io/IOException",
+    "java/io/FileNotFoundException",
     "java/io/SyncFailedException",
     "java/net/SocketException",
     ACR_EXCEPTION_CLASS_PATH "ClosedDescriptorException",



Mime
View raw message