This is the mail archive of the java-patches@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] java.nio -- important, please test on your platform


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi list,


I wrote this little patch to build the whole java.nio currently in 
CVS. This patch makes java.nio's API nearly 100% ready (2 methods in 
java.nio.charset are still missing).

It activates some native code so I would like that this gets tested on 
several platforms before committing and get the feedback back 
(especially the Windows and newlib [arm] people).

Please review and comment.


Michael
- -- 
Homepage: http://www.worldforge.org/
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (GNU/Linux)

iD4DBQE+TOTOWSOgCCdjSDsRAuSoAJ4se0+tl+LClnOqo7jHAu9s9FY5tQCWNbJy
sxtALtMwHUp+yHVCMEtXHQ==
=UZl4
-----END PGP SIGNATURE-----
Index: ChangeLog
===================================================================
RCS file: /cvs/gcc/gcc/libjava/ChangeLog,v
retrieving revision 1.1703
diff -u -r1.1703 ChangeLog
--- ChangeLog	14 Feb 2003 12:07:31 -0000	1.1703
+++ ChangeLog	14 Feb 2003 12:39:20 -0000
@@ -1,5 +1,40 @@
 2003-02-14  Michael Koch  <konqueror@gmx.de>
 
+	* java/nio/channels/FileChannel.java
+	(toString): New implementation, added documentation.
+	(map): Added exception documentation.
+	(size): Added exception documentation.
+	(write): New methods, documentation work.
+	(read): New methods, documentation work.
+	(implCloseChannel): Rewrote exception documentation.
+	(force): Throws IOException, added documentation.
+	(lock): New methods.
+	(tryLock): New methods.
+	(position): New methods.
+	(transferTo): New method.
+	(transferFrom): New method.
+	(truncate): New method.
+	* java/nio/channels/spi/SelectorProvider.java
+	(provider): Implemented.
+	* Makefile.am
+	(ordinary_java_source_files): Added the following files:
+	gnu/java/nio/DatagramChannelImpl.java
+	gnu/java/nio/FileChannelImpl.java
+	gnu/java/nio/PipeImpl.java
+	gnu/java/nio/SelectionKeyImpl.java
+	gnu/java/nio/SelectorImpl.java
+	gnu/java/nio/SelectorProviderImpl.java
+	gnu/java/nio/ServerSocketChannelImpl.java
+	gnu/java/nio/SocketChannelImpl.java
+	java/nio/channels/FileLock.java
+	(nat_java_source_files): Added the following files:
+	gnu/java/nio/natFileChannelImpl.cc
+	gnu/java/nio/natSelectorImpl.cc
+	gnu/java/nio/natSocketChannelImpl.cc
+	* Makefile.in: Regenerated.
+
+2003-02-14  Michael Koch  <konqueror@gmx.de>
+
 	* gnu/java/nio/natServerSocketChannelImpl.cc: Removed.
 	* gnu/java/nio/ServerSocketChannelImpl.java
 	(SocketAccept): Removed.
Index: Makefile.am
===================================================================
RCS file: /cvs/gcc/gcc/libjava/Makefile.am,v
retrieving revision 1.277
diff -u -r1.277 Makefile.am
--- Makefile.am	13 Feb 2003 07:45:57 -0000	1.277
+++ Makefile.am	14 Feb 2003 12:39:21 -0000
@@ -2048,11 +2048,19 @@
 gnu/java/math/MPN.java \
 gnu/java/nio/ByteBufferImpl.java \
 gnu/java/nio/CharBufferImpl.java \
+gnu/java/nio/DatagramChannelImpl.java \
 gnu/java/nio/DoubleBufferImpl.java \
+gnu/java/nio/FileChannelImpl.java \
 gnu/java/nio/FloatBufferImpl.java \
 gnu/java/nio/IntBufferImpl.java \
 gnu/java/nio/LongBufferImpl.java \
+gnu/java/nio/PipeImpl.java \
+gnu/java/nio/SelectionKeyImpl.java \
+gnu/java/nio/SelectorImpl.java \
+gnu/java/nio/SelectorProviderImpl.java \
+gnu/java/nio/ServerSocketChannelImpl.java \
 gnu/java/nio/ShortBufferImpl.java \
+gnu/java/nio/SocketChannelImpl.java \
 gnu/java/nio/charset/ISO_8859_1.java \
 gnu/java/nio/charset/Provider.java \
 gnu/java/nio/charset/US_ASCII.java \
@@ -2180,6 +2188,7 @@
 java/nio/channels/ConnectionPendingException.java \
 java/nio/channels/DatagramChannel.java \
 java/nio/channels/FileChannel.java \
+java/nio/channels/FileLock.java \
 java/nio/channels/FileLockInterruptionException.java \
 java/nio/channels/GatheringByteChannel.java \
 java/nio/channels/IllegalBlockingModeException.java \
@@ -2461,10 +2470,13 @@
 gnu/java/nio/natByteBufferImpl.cc \
 gnu/java/nio/natCharBufferImpl.cc \
 gnu/java/nio/natDoubleBufferImpl.cc \
+gnu/java/nio/natFileChannelImpl.cc \
 gnu/java/nio/natFloatBufferImpl.cc \
 gnu/java/nio/natIntBufferImpl.cc \
 gnu/java/nio/natLongBufferImpl.cc \
+gnu/java/nio/natSelectorImpl.cc \
 gnu/java/nio/natShortBufferImpl.cc \
+gnu/java/nio/natSocketChannelImpl.cc \
 java/io/natFile.cc \
 java/io/natFileDescriptor.cc \
 java/io/natObjectInputStream.cc \
Index: Makefile.in
===================================================================
RCS file: /cvs/gcc/gcc/libjava/Makefile.in,v
retrieving revision 1.298
diff -u -r1.298 Makefile.in
--- Makefile.in	13 Feb 2003 07:45:57 -0000	1.298
+++ Makefile.in	14 Feb 2003 12:39:24 -0000
@@ -1808,11 +1808,19 @@
 gnu/java/math/MPN.java \
 gnu/java/nio/ByteBufferImpl.java \
 gnu/java/nio/CharBufferImpl.java \
+gnu/java/nio/DatagramChannelImpl.java \
 gnu/java/nio/DoubleBufferImpl.java \
+gnu/java/nio/FileChannelImpl.java \
 gnu/java/nio/FloatBufferImpl.java \
 gnu/java/nio/IntBufferImpl.java \
 gnu/java/nio/LongBufferImpl.java \
+gnu/java/nio/PipeImpl.java \
+gnu/java/nio/SelectionKeyImpl.java \
+gnu/java/nio/SelectorImpl.java \
+gnu/java/nio/SelectorProviderImpl.java \
+gnu/java/nio/ServerSocketChannelImpl.java \
 gnu/java/nio/ShortBufferImpl.java \
+gnu/java/nio/SocketChannelImpl.java \
 gnu/java/nio/charset/ISO_8859_1.java \
 gnu/java/nio/charset/Provider.java \
 gnu/java/nio/charset/US_ASCII.java \
@@ -1940,6 +1948,7 @@
 java/nio/channels/ConnectionPendingException.java \
 java/nio/channels/DatagramChannel.java \
 java/nio/channels/FileChannel.java \
+java/nio/channels/FileLock.java \
 java/nio/channels/FileLockInterruptionException.java \
 java/nio/channels/GatheringByteChannel.java \
 java/nio/channels/IllegalBlockingModeException.java \
@@ -2220,10 +2229,13 @@
 gnu/java/nio/natByteBufferImpl.cc \
 gnu/java/nio/natCharBufferImpl.cc \
 gnu/java/nio/natDoubleBufferImpl.cc \
+gnu/java/nio/natFileChannelImpl.cc \
 gnu/java/nio/natFloatBufferImpl.cc \
 gnu/java/nio/natIntBufferImpl.cc \
 gnu/java/nio/natLongBufferImpl.cc \
+gnu/java/nio/natSelectorImpl.cc \
 gnu/java/nio/natShortBufferImpl.cc \
+gnu/java/nio/natSocketChannelImpl.cc \
 java/io/natFile.cc \
 java/io/natFileDescriptor.cc \
 java/io/natObjectInputStream.cc \
@@ -2397,9 +2409,11 @@
 gnu/gcj/runtime/natStackTrace.lo gnu/gcj/runtime/natStringBuffer.lo \
 gnu/gcj/runtime/natVMClassLoader.lo gnu/java/nio/natByteBufferImpl.lo \
 gnu/java/nio/natCharBufferImpl.lo gnu/java/nio/natDoubleBufferImpl.lo \
+gnu/java/nio/natFileChannelImpl.lo \
 gnu/java/nio/natFloatBufferImpl.lo gnu/java/nio/natIntBufferImpl.lo \
 gnu/java/nio/natLongBufferImpl.lo \
-gnu/java/nio/natShortBufferImpl.lo \
+gnu/java/nio/natSelectorImpl.lo \
+gnu/java/nio/natShortBufferImpl.lo gnu/java/nio/natSocketChannelImpl.lo \
 java/io/natFile.lo java/io/natFileDescriptor.lo \
 java/io/natObjectInputStream.lo \
 java/io/natObjectOutputStream.lo java/io/natVMObjectStreamClass.lo \
@@ -2861,10 +2875,16 @@
 .deps/gnu/java/locale/LocaleInformation_zh_TW.P \
 .deps/gnu/java/math/MPN.P .deps/gnu/java/nio/ByteBufferImpl.P \
 .deps/gnu/java/nio/CharBufferImpl.P \
+.deps/gnu/java/nio/DatagramChannelImpl.P \
 .deps/gnu/java/nio/DoubleBufferImpl.P \
+.deps/gnu/java/nio/FileChannelImpl.P \
 .deps/gnu/java/nio/FloatBufferImpl.P .deps/gnu/java/nio/IntBufferImpl.P \
-.deps/gnu/java/nio/LongBufferImpl.P \
+.deps/gnu/java/nio/LongBufferImpl.P .deps/gnu/java/nio/PipeImpl.P \
+.deps/gnu/java/nio/SelectionKeyImpl.P .deps/gnu/java/nio/SelectorImpl.P \
+.deps/gnu/java/nio/SelectorProviderImpl.P \
+.deps/gnu/java/nio/ServerSocketChannelImpl.P \
 .deps/gnu/java/nio/ShortBufferImpl.P \
+.deps/gnu/java/nio/SocketChannelImpl.P \
 .deps/gnu/java/nio/charset/ISO_8859_1.P \
 .deps/gnu/java/nio/charset/Provider.P \
 .deps/gnu/java/nio/charset/US_ASCII.P \
@@ -2877,10 +2897,13 @@
 .deps/gnu/java/nio/natByteBufferImpl.P \
 .deps/gnu/java/nio/natCharBufferImpl.P \
 .deps/gnu/java/nio/natDoubleBufferImpl.P \
+.deps/gnu/java/nio/natFileChannelImpl.P \
 .deps/gnu/java/nio/natFloatBufferImpl.P \
 .deps/gnu/java/nio/natIntBufferImpl.P \
 .deps/gnu/java/nio/natLongBufferImpl.P \
+.deps/gnu/java/nio/natSelectorImpl.P \
 .deps/gnu/java/nio/natShortBufferImpl.P \
+.deps/gnu/java/nio/natSocketChannelImpl.P \
 .deps/gnu/java/rmi/RMIMarshalledObjectInputStream.P \
 .deps/gnu/java/rmi/RMIMarshalledObjectOutputStream.P \
 .deps/gnu/java/rmi/dgc/DGCImpl.P .deps/gnu/java/rmi/dgc/DGCImpl_Skel.P \
@@ -3370,6 +3393,7 @@
 .deps/java/nio/channels/ConnectionPendingException.P \
 .deps/java/nio/channels/DatagramChannel.P \
 .deps/java/nio/channels/FileChannel.P \
+.deps/java/nio/channels/FileLock.P \
 .deps/java/nio/channels/FileLockInterruptionException.P \
 .deps/java/nio/channels/GatheringByteChannel.P \
 .deps/java/nio/channels/IllegalBlockingModeException.P \
Index: java/nio/channels/FileChannel.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/nio/channels/FileChannel.java,v
retrieving revision 1.1
diff -u -r1.1 FileChannel.java
--- java/nio/channels/FileChannel.java	18 Nov 2002 13:56:59 -0000	1.1
+++ java/nio/channels/FileChannel.java	14 Feb 2003 12:39:24 -0000
@@ -65,9 +65,17 @@
       m = a;
     }
 
+    /**
+     * Returns a string representation of the <code>MapMode</code> object.
+     */
     public String toString() 
     {
-      return "" + m;
+      if (this == READ_ONLY)
+        return "READ_ONLY";
+      else if (this == READ_WRITE)
+        return "READ_WRITE";
+
+      return "PRIVATE";
     }
   }
 
@@ -81,20 +89,28 @@
   /**
    * Maps the file into the memory.
    *
-   * @exception IOException If an error occurs.
+   * @exception IllegalArgumentException If the preconditions on the parameters
+   * do not hold.
+   * @exception IOException If an I/O error occurs.
+   * @exception NonReadableChannelException If mode is READ_ONLY but this channel was
+   * not opened for reading.
+   * @exception NonWritableChannelException If mode is READ_WRITE or PRIVATE but this
+   * channel was not opened for writing.
    */
   public abstract MappedByteBuffer map(MapMode mode, long position, long size)
     throws IOException;
 
   /**
    * Return the size of the file thus far
+   * 
+   * @exception ClosedChannelException If this channel is closed.
    */
   public abstract long size() throws IOException;
   
   /**
    * Writes data to the channel.
    *
-   * @exception IOException If an error occurs.
+   * @exception IOException If an I/O error occurs.
    */
   public long write (ByteBuffer[] srcs) throws IOException
   {
@@ -110,26 +126,243 @@
   
   /**
    * Writes data to the channel.
+   *
+   * @exception IOException If an I/O error occurs.
+   */
+  public abstract int write (ByteBuffer src) throws IOException;
+
+  /**
+   * Writes data to the channel.
+   *
+   * @exception AsynchronousCloseException If another thread closes this channel
+   * while the transfer is in progress.
+   * @exception ClosedByInterruptException If another thread interrupts the
+   * current thread while the transfer is in progress, thereby closing both
+   * channels and setting the current thread's interrupt status.
+   * @exception ClosedChannelException If this channel is closed.
+   * @exception IllegalArgumentException If position is negative.
+   * @exception IOException If an I/O error occurs.
+   * @exception NonWritableChannelException If this channel was not opened for
+   * writing.
+   */
+  public abstract int write (ByteBuffer srcs, long position) throws IOException;
+
+  /**
+   * Writes data to the channel.
+   *
+   * @exception IOException If an I/O error occurs.
    */
   public abstract long write(ByteBuffer[] srcs, int offset, int length)
     throws IOException;
   
   /**
    * Reads data from the channel.
+   *
+   * @exception IOException If an I/O error occurs.
+   */
+  public abstract long read (ByteBuffer[] dsts, int offset, int length)
+    throws IOException;
+
+  /**
+   * Reads data from the channel.
+   *
+   * @exception IOException If an I/O error occurs.
+   */
+  public final long read (ByteBuffer[] dsts) throws IOException
+  {
+    long result = 0;
+    
+    for (int i = 0; i < dsts.length; i++)
+      {
+        read (dsts [i]);
+      }
+
+    return result;
+  }
+
+  /**
+   * Reads data from the channel.
+   *
+   * @exception IOException If an I/O error occurs.
    */
   public abstract int read(ByteBuffer dst) throws IOException;
   
   /**
+   * Reads data from the channel.
+   *
+   * @exception AsynchronousCloseException If another thread closes this channel
+   * while the transfer is in progress.
+   * @exception ClosedByInterruptException If another thread interrupts the
+   * current thread while the transfer is in progress, thereby closing both
+   * channels and setting the current thread's interrupt status.
+   * @exception ClosedChannelException If this channel is closed.
+   * @exception IllegalArgumentException If position is negative.
+   * @exception IOException If an I/O error occurs.
+   * @exception NonReadableChannelException If this channel was not opened for
+   * reading.
+   */
+  public abstract int read(ByteBuffer dst, long position) throws IOException;
+  
+  /**
    * Closes the channel.
    *
    * This is called from @see close.
    *
-   * @exception IOException If an error occurs.
+   * @exception IOException If an I/O error occurs.
    */
   protected abstract void implCloseChannel() throws IOException;
 
   /**
    * msync with the disk
+   *
+   * @exception ClosedChannelException If this channel is closed.
+   * @exception IOException If an I/O error occurs.
+   */
+  public abstract void force(boolean metaData) throws IOException;
+
+  /**
+   * Creates a file lock for the whole assoziated file.
+   *
+   * @exception AsynchronousCloseException If another thread closes this channel
+   * while the transfer is in progress.
+   * @exception ClosedChannelException If this channel is closed.
+   * @exception FileLockInterruptionException If the invoking thread is
+   * interrupted while blocked in this method.
+   * @exception IOException If an I/O error occurs.
+   * @exception NonReadableChannelException If shared is true and this channel
+   * was not opened for reading.
+   * @exception NonWritableChannelException If shared is false and this channel
+   * was not opened for writing.
+   * @exception OverlappingFileLockException If a lock that overlaps the
+   * requested region is already held by this Java virtual machine, or if
+   * another thread is already blocked in this method and is attempting to lock
+   * an overlapping region.
+   */
+  public final FileLock lock () throws IOException
+  {
+    return lock (0, Long.MAX_VALUE, false);
+  }
+
+  /**
+   * Creates a file lock for a region of the assoziated file.
+   *
+   * @exception AsynchronousCloseException If another thread closes this channel
+   * while the transfer is in progress.
+   * @exception ClosedChannelException If this channel is closed.
+   * @exception FileLockInterruptionException If the invoking thread is
+   * interrupted while blocked in this method.
+   * @exception IllegalArgumentException If the preconditions on the parameters
+   * do not hold.
+   * @exception IOException If an I/O error occurs.
+   * @exception OverlappingFileLockException If a lock that overlaps the
+   * requested region is already held by this Java virtual machine, or if
+   * another thread is already blocked in this method and is attempting to lock
+   * an overlapping region.
+   * @exception NonReadableChannelException If shared is true and this channel
+   * was not opened for reading.
+   * @exception NonWritableChannelException If shared is false and this channel
+   * was not opened for writing.
+   */
+  public abstract FileLock lock (long position, long size, boolean shared)
+    throws IOException;
+
+  /**
+   * Tries to aqquire alock on the whole assoziated file.
+   *
+   * @exception ClosedChannelException If this channel is closed.
+   * @exception IOException If an I/O error occurs.
+   * @exception OverlappingFileLockException If a lock that overlaps the
+   * requested region is already held by this Java virtual machine, or if
+   * another thread is already blocked in this method and is attempting to lock
+   * an overlapping region.
+   */
+  public final FileLock tryLock () throws IOException
+  {
+    return tryLock (0, Long.MAX_VALUE, false);
+  }
+
+  /**
+   * Tries to aqquire a lock on a region of the assoziated file.
+   *
+   * @exception ClosedChannelException If this channel is closed.
+   * @exception IllegalArgumentException If the preconditions on the parameters
+   * do not hold.
+   * @exception IOException If an I/O error occurs.
+   * @exception OverlappingFileLockException If a lock that overlaps the
+   * requested region is already held by this Java virtual machine, or if
+   * another thread is already blocked in this method and is attempting to lock
+   * an overlapping region.
+   */
+  public abstract FileLock tryLock (long position, long size, boolean shared)
+    throws IOException;
+
+  /**
+   * Returns the current position on the file.
+   *
+   * @exception ClosedChannelException If this channel is closed.
+   * @exception IOException If an I/O error occurs.
+   */
+  public abstract long position () throws IOException;
+
+  /**
+   * Sets the position of the channel on the assoziated file.
+   *
+   * @exception ClosedChannelException If this channel is closed.
+   * @exception IllegalArgumentException If newPosition is negative.
+   * @exception IOException If an I/O error occurs.
+   */
+  public abstract FileChannel position (long newPosition) throws IOException;
+
+  /**
+   * Transfers bytes from this channel's file to the given writable byte
+   * channel.
+   *
+   * @exception AsynchronousCloseException If another thread closes this channel
+   * while the transfer is in progress.
+   * @exception ClosedByInterruptException If another thread interrupts the
+   * current thread while the transfer is in progress, thereby closing both
+   * channels and setting the current thread's interrupt status.
+   * @exception ClosedChannelException If this channel is closed.
+   * @exception IllegalArgumentException If the preconditions on the parameters
+   * do not hold.
+   * @exception IOException If an I/O error occurs.
+   * @exception NonReadableChannelException If this channel was not opened for
+   * reading.
+   * @exception NonWritableChannelException If the target channel was not
+   * opened for writing.
+   */
+  public abstract long transferTo (long position, long count,
+                                   WritableByteChannel target)
+    throws IOException;
+
+  /**
+   * Transfers bytes from the given readable channel into this channel.
+   *
+   * @exception AsynchronousCloseException If another thread closes this channel
+   * while the transfer is in progress.
+   * @exception ClosedByInterruptException If another thread interrupts the
+   * current thread while the transfer is in progress, thereby closing both
+   * channels and setting the current thread's interrupt status.
+   * @exception ClosedChannelException If this channel is closed.
+   * @exception IllegalArgumentException If the preconditions on the parameters
+   * do not hold.
+   * @exception IOException If an I/O error occurs.
+   * @exception NonReadableChannelException If the source channel was not
+   * opened for reading.
+   * @exception NonWritableChannelException If this channel was not opened for
+   * writing.
+   */
+  public abstract long transferFrom (ReadableByteChannel src, long position,
+                                     long count) throws IOException;
+
+  /**
+   * Truncates the channel's file at <code>size</code>.
+   *
+   * @exception ClosedChannelException If this channel is closed.
+   * @exception IllegalArgumentException If size is negative.
+   * @exception IOException If an I/O error occurs.
+   * @exception NonWritableChannelException If this channel was not opened for
+   * writing.
    */
-  public abstract void force(boolean metaData);    
+  public abstract FileChannel truncate (long size) throws IOException;
 }
Index: java/nio/channels/spi/SelectorProvider.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/nio/channels/spi/SelectorProvider.java,v
retrieving revision 1.3
diff -u -r1.3 SelectorProvider.java
--- java/nio/channels/spi/SelectorProvider.java	11 Feb 2003 06:48:53 -0000	1.3
+++ java/nio/channels/spi/SelectorProvider.java	14 Feb 2003 12:39:24 -0000
@@ -37,7 +37,7 @@
 
 package java.nio.channels.spi;
 
-/* import gnu.java.nio.channels.SelectorProviderImpl; */
+import gnu.java.nio.SelectorProviderImpl;
 import java.io.IOException;
 import java.nio.channels.DatagramChannel;
 import java.nio.channels.Pipe;
@@ -97,8 +97,10 @@
    */
   public static SelectorProvider provider ()
   {
-/*    if (pr == null) */
-/*      pr = new SelectorProviderImpl (); */
+    if (pr == null)
+      {
+        pr = new SelectorProviderImpl ();
+      }
     
     return pr;
   }

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]