2003-05-14 Michael Koch <konqueror@gmx.de>
authorMichael Koch <konqueror@gmx.de>
Wed, 14 May 2003 06:37:59 +0000 (06:37 +0000)
committerMichael Koch <mkoch@gcc.gnu.org>
Wed, 14 May 2003 06:37:59 +0000 (06:37 +0000)
* gnu/java/nio/FileLockImpl.java
(released): New member variable.
(FileLockImpl): Initialize released.
(releaseImpl): New native method.
(release): Implemented.
* gnu/java/nio/SelectorImpl.java: Reformatted.
* gnu/java/nio/SelectionKeyImpl.java: Reformatted.
* gnu/java/nio/ServerSocketChannelImpl.java: Reformatted.
(accept): Throws IOException.
* gnu/java/nio/SocketChannelImpl.java: Reformatted.
(implConfigureBlocking): Throws IOException.
(connect): Likewise.
(read): Likewise.
(write): Likewise.
* gnu/java/nio/natFileLockImpl.cc: New file.
* java/nio/channels/FileLock.java: Reformatted.
* Makefile.am:
(ordinary_java_source_files): Added gnu/java/nio/FileLockImpl.java.
(nat_source_files): Added gnu/java/nio/natFileLockImpl.cc.
* Makefile.in: Regenerated.

From-SVN: r66799

libjava/ChangeLog
libjava/Makefile.am
libjava/Makefile.in
libjava/gnu/java/nio/FileLockImpl.java
libjava/gnu/java/nio/SelectionKeyImpl.java
libjava/gnu/java/nio/SelectorImpl.java
libjava/gnu/java/nio/ServerSocketChannelImpl.java
libjava/gnu/java/nio/SocketChannelImpl.java
libjava/gnu/java/nio/natFileLockImpl.cc [new file with mode: 0644]
libjava/java/nio/channels/FileLock.java

index 1135ea7995b8936c304e94b8d22e615a609f4883..30479ae3e51cb205ead1275779dd8096206572d1 100644 (file)
@@ -1,3 +1,26 @@
+2003-05-14  Michael Koch  <konqueror@gmx.de>
+
+       * gnu/java/nio/FileLockImpl.java
+       (released): New member variable.
+       (FileLockImpl): Initialize released.
+       (releaseImpl): New native method.
+       (release): Implemented.
+       * gnu/java/nio/SelectorImpl.java: Reformatted.
+       * gnu/java/nio/SelectionKeyImpl.java: Reformatted.
+       * gnu/java/nio/ServerSocketChannelImpl.java: Reformatted.
+       (accept): Throws IOException.
+       * gnu/java/nio/SocketChannelImpl.java: Reformatted.
+       (implConfigureBlocking): Throws IOException.
+       (connect): Likewise.
+       (read): Likewise.
+       (write): Likewise.
+       * gnu/java/nio/natFileLockImpl.cc: New file.
+       * java/nio/channels/FileLock.java: Reformatted.
+       * Makefile.am:
+       (ordinary_java_source_files): Added gnu/java/nio/FileLockImpl.java.
+       (nat_source_files): Added gnu/java/nio/natFileLockImpl.cc.
+       * Makefile.in: Regenerated.
+
 2003-05-13  Michael Koch  <konqueror@gmx.de>
 
        * gnu/java/nio/CharViewBufferImpl.java
index 2f394ddd42e4c46e5f32107128d4b4ec24f6278c..ff60cba7ec4c4d92e89970cc44c6073dd5a269c7 100644 (file)
@@ -2104,6 +2104,7 @@ gnu/java/nio/DirectByteBufferImpl.java \
 gnu/java/nio/DoubleBufferImpl.java \
 gnu/java/nio/DoubleViewBufferImpl.java \
 gnu/java/nio/FileChannelImpl.java \
+gnu/java/nio/FileLockImpl.java \
 gnu/java/nio/FloatBufferImpl.java \
 gnu/java/nio/FloatViewBufferImpl.java \
 gnu/java/nio/IntBufferImpl.java \
@@ -2564,6 +2565,7 @@ gnu/gcj/runtime/natStringBuffer.cc \
 gnu/gcj/runtime/natVMClassLoader.cc \
 gnu/java/nio/natDirectByteBufferImpl.cc \
 gnu/java/nio/natFileChannelImpl.cc \
+gnu/java/nio/natFileLockImpl.cc \
 gnu/java/nio/natMappedByteFileBuffer.cc \
 gnu/java/nio/natSelectorImpl.cc \
 gnu/java/nio/natSocketChannelImpl.cc \
index 78eec34c1bb9e871e0134172405a8eabb507375d..9fb912d79233b7ba681b12d62eb189ed51531805 100644 (file)
@@ -1866,6 +1866,7 @@ gnu/java/nio/DirectByteBufferImpl.java \
 gnu/java/nio/DoubleBufferImpl.java \
 gnu/java/nio/DoubleViewBufferImpl.java \
 gnu/java/nio/FileChannelImpl.java \
+gnu/java/nio/FileLockImpl.java \
 gnu/java/nio/FloatBufferImpl.java \
 gnu/java/nio/FloatViewBufferImpl.java \
 gnu/java/nio/IntBufferImpl.java \
@@ -2325,6 +2326,7 @@ gnu/gcj/runtime/natStringBuffer.cc \
 gnu/gcj/runtime/natVMClassLoader.cc \
 gnu/java/nio/natDirectByteBufferImpl.cc \
 gnu/java/nio/natFileChannelImpl.cc \
+gnu/java/nio/natFileLockImpl.cc \
 gnu/java/nio/natMappedByteFileBuffer.cc \
 gnu/java/nio/natSelectorImpl.cc \
 gnu/java/nio/natSocketChannelImpl.cc \
@@ -2500,7 +2502,7 @@ gnu/gcj/runtime/natNameFinder.lo gnu/gcj/runtime/natSharedLibLoader.lo \
 gnu/gcj/runtime/natStackTrace.lo gnu/gcj/runtime/natStringBuffer.lo \
 gnu/gcj/runtime/natVMClassLoader.lo \
 gnu/java/nio/natDirectByteBufferImpl.lo \
-gnu/java/nio/natFileChannelImpl.lo \
+gnu/java/nio/natFileChannelImpl.lo gnu/java/nio/natFileLockImpl.lo \
 gnu/java/nio/natMappedByteFileBuffer.lo gnu/java/nio/natSelectorImpl.lo \
 gnu/java/nio/natSocketChannelImpl.lo java/io/natFile.lo \
 java/io/natFileDescriptor.lo java/io/natObjectInputStream.lo \
@@ -2970,7 +2972,7 @@ DEP_FILES =  .deps/$(srcdir)/$(CONVERT_DIR)/gen-from-JIS.P \
 .deps/gnu/java/nio/DirectByteBufferImpl.P \
 .deps/gnu/java/nio/DoubleBufferImpl.P \
 .deps/gnu/java/nio/DoubleViewBufferImpl.P \
-.deps/gnu/java/nio/FileChannelImpl.P \
+.deps/gnu/java/nio/FileChannelImpl.P .deps/gnu/java/nio/FileLockImpl.P \
 .deps/gnu/java/nio/FloatBufferImpl.P \
 .deps/gnu/java/nio/FloatViewBufferImpl.P \
 .deps/gnu/java/nio/IntBufferImpl.P \
@@ -2995,6 +2997,7 @@ DEP_FILES =  .deps/$(srcdir)/$(CONVERT_DIR)/gen-from-JIS.P \
 .deps/gnu/java/nio/charset/UTF_8.P \
 .deps/gnu/java/nio/natDirectByteBufferImpl.P \
 .deps/gnu/java/nio/natFileChannelImpl.P \
+.deps/gnu/java/nio/natFileLockImpl.P \
 .deps/gnu/java/nio/natMappedByteFileBuffer.P \
 .deps/gnu/java/nio/natSelectorImpl.P \
 .deps/gnu/java/nio/natSocketChannelImpl.P \
index 2e55f6bb657947e4e6f7c776a1eeba9191e1b432..088e552bea26992bbc6cc64d7694c4f3e68cc38f 100644 (file)
@@ -35,29 +35,41 @@ this exception to your version of the library, but you are not
 obligated to do so.  If you do not wish to do so, delete this
 exception statement from your version. */
 
+
 package gnu.java.nio;
 
+import java.io.FileDescriptor;
+import java.io.IOException;
 import java.nio.channels.FileChannel;
 import java.nio.channels.FileLock;
 
 /**
  * @author Michael Koch
+ * @since 1.4
  */
 public class FileLockImpl extends FileLock
 {
-  public FileLockImpl (FileChannel channel, long position, long size,
-                       boolean shared)
+  private FileDescriptor fd;
+  private boolean released;
+  
+  public FileLockImpl (FileDescriptor fd, FileChannel channel, long position,
+                       long size, boolean shared)
   {
     super (channel, position, size, shared);
+    this.fd = fd;
+    this.released = false;
   }
   
   public boolean isValid ()
   {
-    throw new Error ("Not implemented");
+    return (released || !channel.isOpen ());
   }
 
-  public void release ()
+  private native void releaseImpl () throws IOException;
+
+  public synchronized void release () throws IOException
   {
-    throw new Error ("Not implemented");
+    releaseImpl ();
+    released = true;
   }
 }
index 5763d6880d3a6c5951e9e9382b25854a1e0a2856..72dc20b15b8292d1ee2558844af6d4dc77243806 100644 (file)
@@ -50,7 +50,7 @@ public class SelectionKeyImpl extends AbstractSelectionKey
   SelectorImpl impl;
   SelectableChannel ch;
 
-  public SelectionKeyImpl(SelectableChannel ch, SelectorImpl impl, int fd)
+  public SelectionKeyImpl (SelectableChannel ch, SelectorImpl impl, int fd)
   {
     this.ch  = ch;
     this.impl = impl;
index 0b513f9da5216ba276bc409975269030282d9d4f..e3eed255501afd1d2d105a8dd2439d9e48207226 100644 (file)
@@ -261,16 +261,16 @@ public class SelectorImpl extends AbstractSelector
 //         return impl;
 //       }
 //     else
-       
+
     if (ch instanceof SocketChannelImpl)
-           {
+      {
         SocketChannelImpl sc = (SocketChannelImpl) ch;
         SelectionKeyImpl impl = new SelectionKeyImpl (ch, this, sc.fd);
         add (impl);
         impl.interestOps (ops);
         impl.attach (att);
         return impl;
-           }
+      }
     else if (ch instanceof DatagramChannelImpl)
       {
         DatagramChannelImpl dc = (DatagramChannelImpl) ch;
@@ -290,9 +290,9 @@ public class SelectorImpl extends AbstractSelector
         return impl;
       }
     else
-           {
+      {
         System.err.println ("INTERNAL ERROR, no known channel type");
-           }
+      }
 
     return null;
   }
index 039b50308d60b5d74491ee0c074b055588fb17c4..0b3fc66e9812da37c79457d5e55f08798ea5b9ae 100644 (file)
@@ -73,15 +73,15 @@ class ServerSocketChannelImpl extends ServerSocketChannel
   public void finalizer()
   {
     if (connected)
-           {
+      {
         try
           {
-            close();
+            close ();
           }
         catch (Exception e)
           {
           }
-           }
+      }
   }
 
   protected void implCloseSelectableChannel () throws IOException
@@ -91,12 +91,12 @@ class ServerSocketChannelImpl extends ServerSocketChannel
     fd = SocketChannelImpl.SocketCreate ();
   }
 
-  protected void implConfigureBlocking (boolean block) throws IOException
+  protected void implConfigureBlocking (boolean blocking) throws IOException
   {
-    blocking = block;
+    this.blocking = blocking;
   }
 
-  public SocketChannel accept ()
+  public SocketChannel accept () throws IOException
   {
     SocketChannelImpl result = new SocketChannelImpl (provider ());
     result.sa = new InetSocketAddress (0);
index 9f2de278d811a26314ca0b9662786c880e06859c..65ca62341aeaffecb85bad262c33e3a5b3933cc2 100644 (file)
@@ -80,37 +80,36 @@ public class SocketChannelImpl extends SocketChannel
   public void finalizer()
   {
     if (connected)
-           {
+      {
         try
           {
-            close();
+            close ();
           }
         catch (Exception e)
           {
           }
-           }
+      }
   }
 
-  protected void implCloseSelectableChannel()
+  protected void implCloseSelectableChannel () throws IOException
   {
     connected = false;
     SocketClose(fd);
     fd = SocketCreate();
   }
 
-  protected void implConfigureBlocking(boolean  block)
+  protected void implConfigureBlocking (boolean blocking) throws IOException
   {
-    if (blocking == block)
-           return;
+    if (this.blocking == blocking)
+      return;
   }   
 
-  public boolean connect(SocketAddress remote)
-    throws IOException
+  public boolean connect (SocketAddress remote) throws IOException
   {
     if (connected)
-           {
-        throw new AlreadyConnectedException();
-           }
+      {
+        throw new AlreadyConnectedException ();
+      }
 
     // ok, lets connect !
        
@@ -130,17 +129,17 @@ public class SocketChannelImpl extends SocketChannel
     return blocking;
   }
     
-  public boolean finishConnect()
+  public boolean finishConnect ()
   {
     return false;
   }
 
-  public boolean isConnected()
+  public boolean isConnected ()
   {
     return connected;
   }
     
-  public boolean isConnectionPending()
+  public boolean isConnectionPending ()
   {
     if (blocking)
            return true;
@@ -148,7 +147,7 @@ public class SocketChannelImpl extends SocketChannel
     return false;
   }
     
-  public Socket socket()
+  public Socket socket ()
   {
     if (sock_object != null)
            {
@@ -158,7 +157,7 @@ public class SocketChannelImpl extends SocketChannel
     return sock_object;
   }
 
-  public int read(ByteBuffer dst)
+  public int read (ByteBuffer dst) throws IOException
   {
     int bytes = 0;
     int len = 1024;
@@ -168,27 +167,29 @@ public class SocketChannelImpl extends SocketChannel
     dst.put(b, 0, bytes);
 
     if (bytes == 0)
-           {
+      {
         // we've hit eof ?
         return -1;
-           }
+      }
 
     return bytes;
   }
     
-  public long read(ByteBuffer[] dsts, int offset, int length)
+  public long read (ByteBuffer[] dsts, int offset, int length)
+    throws IOException
   {
     long bytes = 0;
 
-    for (int i=offset; i<length; i++)
-           {
-        bytes += read(dsts[i]);
-           }
+    for (int i = offset; i < length; i++)
+      {
+        bytes += read (dsts [i]);
+      }
 
     return bytes;
   }
      
-  public int write(ByteBuffer src)
+  public int write (ByteBuffer src)
+    throws IOException
   {
     int bytes = 0;
     int len = src.position();
@@ -210,13 +211,14 @@ public class SocketChannelImpl extends SocketChannel
   }
 
   public long write (ByteBuffer[] srcs, int offset, int length)
+    throws IOException
   {
     long bytes = 0;
 
-    for (int i=offset; i<length; i++)
-           {
-        bytes += write(srcs[i]);
-           }
+    for (int i = offset; i < length; i++)
+      {
+        bytes += write (srcs [i]);
+      }
 
     return bytes;
   }
diff --git a/libjava/gnu/java/nio/natFileLockImpl.cc b/libjava/gnu/java/nio/natFileLockImpl.cc
new file mode 100644 (file)
index 0000000..19a3b83
--- /dev/null
@@ -0,0 +1,25 @@
+// natFileLockImpl.cc
+
+/* Copyright (C) 2003  Free Software Foundation
+
+   This file is part of libgcj.
+
+This software is copyrighted work licensed under the terms of the
+Libgcj License.  Please consult the file "LIBGCJ_LICENSE" for
+details.  */
+
+#include <config.h>
+
+#include <jvm.h>
+#include <errno.h>
+
+#include <gnu/java/nio/FileLockImpl.h>
+#include <java/io/FileDescriptor.h>
+#include <java/io/IOException.h>
+
+void
+gnu::java::nio::FileLockImpl::releaseImpl ()
+{
+  throw new ::java::io::IOException
+    (JvNewStringUTF ("releaseImpl not implemented"));
+}
index 1b4595e5c43f57498ae1cfa3d9c38e5a3deca12d..866ed3997d188de8bf10cdb7e68a1e1324742d0e 100644 (file)
@@ -101,7 +101,7 @@ public abstract class FileLock
    */
   public final boolean overlaps (long position, long size)
   {
-    if (position > this.position +this.size)
+    if (position > this.position + this.size)
       return false;
 
     if (position + size < this.position)