commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mt...@apache.org
Subject svn commit: r884438 - in /commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime: exception/ReadOnlyDescriptorException.java io/Pipe.java
Date Thu, 26 Nov 2009 07:50:06 GMT
Author: mturk
Date: Thu Nov 26 07:50:05 2009
New Revision: 884438

URL: http://svn.apache.org/viewvc?rev=884438&view=rev
Log:
Pipe has two descriptors, so make sure correct exceptions are thrown, since the Pipe can have
on or two Descriptors

Added:
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/exception/ReadOnlyDescriptorException.java
  (with props)
Modified:
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/Pipe.java

Added: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/exception/ReadOnlyDescriptorException.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/exception/ReadOnlyDescriptorException.java?rev=884438&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/exception/ReadOnlyDescriptorException.java
(added)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/exception/ReadOnlyDescriptorException.java
Thu Nov 26 07:50:05 2009
@@ -0,0 +1,38 @@
+/* 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.exception;
+import java.io.IOException;
+
+/**
+ * ReadOnlyDescriptorException thrown when an attempt is made to
+ * invoke an write operation on read only {@code Descriptor}.
+ *
+ * @since Runtime 1.0
+ */
+public class ReadOnlyDescriptorException extends IOException
+{
+
+    public ReadOnlyDescriptorException()
+    {
+        super();
+    }
+
+    public ReadOnlyDescriptorException(String msg)
+    {
+        super(msg);
+    }
+}

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

Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/Pipe.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/Pipe.java?rev=884438&r1=884437&r2=884438&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/Pipe.java (original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/io/Pipe.java Thu
Nov 26 07:50:05 2009
@@ -30,6 +30,7 @@
 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.ReadOnlyDescriptorException;
 import org.apache.commons.runtime.exception.TimeoutException;
 import org.apache.commons.runtime.util.StringManager;
 
@@ -140,16 +141,27 @@
     public boolean isBlocking()
         throws IOException
     {
-        if (!valid())
+        if (rd != null) {
+            if (!rd.valid())
+                throw new ClosedDescriptorException();
+            return blocking0(rd.fd());
+        }
+        else if (wr != null) {
+            if (!wr.valid())
+                throw new ClosedDescriptorException();
+            return blocking0(wr.fd());
+        }
+        else
             throw new ClosedDescriptorException();
-        return blocking0(rd.fd());
     }
 
     @Override
     public boolean valid()
     {
-        if (rd != null && wr != null)
-            return rd.valid() && wr.valid();
+        if (rd != null)
+            return rd.valid();
+        else if (wr != null)
+            return wr.valid();
         else
             return false;
     }
@@ -163,8 +175,10 @@
     public final void close()
         throws IOException
     {
-        rd.close();
-        wr.close();
+        if (rd != null)
+            rd.close();
+        if (wr != null)
+            wr.close();
     }
 
     /**
@@ -185,7 +199,12 @@
     public final void flush()
         throws SyncFailedException, IOException
     {
-        wr.flush();
+        if (wr != null)
+            wr.flush();
+        else if (rd != null)
+            throw new ReadOnlyDescriptorException();
+        else
+            throw new ClosedDescriptorException();
     }
 
     /**
@@ -206,7 +225,12 @@
     public final void sync()
         throws SyncFailedException, IOException
     {
-        wr.sync();
+        if (wr != null)
+            wr.sync();
+        else if (rd != null)
+            throw new ReadOnlyDescriptorException();
+        else
+            throw new ClosedDescriptorException();
     }
 
     private static native int tmget0(int fd)
@@ -217,9 +241,18 @@
     public int getTimeout()
         throws IOException
     {
-        if (!valid())
+        if (rd != null) {
+            if (!rd.valid())
+                throw new ClosedDescriptorException();
+            return tmget0(rd.fd());
+        }
+        else if (wr != null) {
+            if (!wr.valid())
+                throw new ClosedDescriptorException();
+            return tmget0(wr.fd());
+        }
+        else
             throw new ClosedDescriptorException();
-        return tmget0(rd.fd());
     }
 
     private static native int tmset0(int fd, int timeout)
@@ -230,11 +263,18 @@
     public boolean setTimeout(int timeout)
         throws IOException
     {
-        if (!valid())
-            throw new ClosedDescriptorException();
-        int rc = tmset0(rd.fd(), timeout);
-        int wc = tmset0(wr.fd(), timeout);
-        return rc + wc == 0 ? true : false;
+        boolean stat = false;
+        if (rd != null) {
+            if (!rd.valid())
+                throw new ClosedDescriptorException();
+            stat = tmset0(rd.fd(), timeout) == 0 ? true : false;
+        }
+        if (wr != null) {
+            if (!wr.valid())
+                throw new ClosedDescriptorException();
+            stat = tmset0(wr.fd(), timeout) == 0 ? stat : false;
+        }
+        return stat;
     }
 
 }



Mime
View raw message