You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by ge...@apache.org on 2005/12/01 07:04:00 UTC
svn commit: r350181 [129/198] - in
/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core: ./ depends/
depends/files/ depends/jars/ depends/libs/ depends/libs/linux.IA32/
depends/libs/win.IA32/ depends/oss/ depends/oss/linux.IA32/
depends/oss/win....
Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/java/nio/channels/AsynchronousCloseException.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/java/nio/channels/AsynchronousCloseException.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/java/nio/channels/AsynchronousCloseException.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/java/nio/channels/AsynchronousCloseException.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,34 @@
+/* Copyright 2004 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed 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 java.nio.channels;
+
+
+/**
+ * Thrown when the underlying channel for an IO operation is closed by another thread.
+ *
+ */
+public class AsynchronousCloseException extends ClosedChannelException {
+
+ static final long serialVersionUID = 6891178312432313966L;
+
+ /**
+ * Default constructor
+ */
+ public AsynchronousCloseException() {
+ super();
+ }
+
+}
Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/java/nio/channels/ByteChannel.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/java/nio/channels/ByteChannel.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/java/nio/channels/ByteChannel.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/java/nio/channels/ByteChannel.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,29 @@
+/* Copyright 2004 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed 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 java.nio.channels;
+
+
+/**
+ * A ByteChannel is both readable and writable.
+ * <p>
+ * The methods for the byte channel are precisely those defined by readable and
+ * writable byte channels.
+ * </p>
+ *
+ */
+public interface ByteChannel extends ReadableByteChannel, WritableByteChannel {
+ // No methods defined.
+}
Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/java/nio/channels/CancelledKeyException.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/java/nio/channels/CancelledKeyException.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/java/nio/channels/CancelledKeyException.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/java/nio/channels/CancelledKeyException.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,37 @@
+/* Copyright 2005 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed 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 java.nio.channels;
+
+
+/**
+ * Thrown when an invalid selection key is used.
+ *
+ */
+public class CancelledKeyException extends IllegalStateException {
+
+ /**
+ * Version ID for serialization.
+ */
+ private static final long serialVersionUID = -8438032138028814268L;
+
+ /**
+ * Default constructor.
+ *
+ */
+ public CancelledKeyException() {
+ super();
+ }
+}
Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/java/nio/channels/Channel.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/java/nio/channels/Channel.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/java/nio/channels/Channel.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/java/nio/channels/Channel.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,65 @@
+/* Copyright 2004 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed 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 java.nio.channels;
+
+
+import java.io.IOException;
+
+/**
+ * A channel is a conduit to IO services covering such items as files, sockets,
+ * hardware devices, IO ports, or some software component.
+ * <p>
+ * Channels are open upon creation, and can be explicitly closed. Once a channel
+ * is closed it cannot be re-opened, and attempts to perform IO operations on
+ * the closed channel result in a <code>ClosedChannelException
+ * </code>.
+ * </p>
+ * <p>
+ * Particular implementations or sub-interfaces of Channel dictate whther they
+ * are thread-safe or not.
+ * </p>
+ *
+ */
+public interface Channel {
+
+ /**
+ * Answers whether this channel is open or not.
+ *
+ * @return true if the channel is open, otherwise answers false.
+ */
+ public boolean isOpen();
+
+ /**
+ * Closes an open channel.
+ *
+ * If the channel is already closed this method has no effect. If there is a
+ * problem with closing the channel then the method throws an IOException
+ * and the exception contains reasons for the failure.
+ * <p>
+ * If an attempt is made to perform an operation on a closed channel then a
+ * <code>ClosedChannelException</code> will be thrown on that attempt.
+ * </p>
+ * <p>
+ * If multiple threads attempts to simultaneously close a channel, then only
+ * one thread will runthe closure code, and others will be blocked until the
+ * first returns.
+ * </p>
+ *
+ * @throws IOException
+ * if a problem occurs closing the channel.
+ */
+ public void close() throws IOException;
+}
Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/java/nio/channels/Channels.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/java/nio/channels/Channels.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/java/nio/channels/Channels.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/java/nio/channels/Channels.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,105 @@
+/* Copyright 2004 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed 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 java.nio.channels;
+
+
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.Reader;
+import java.io.Writer;
+import java.nio.charset.Charset;
+import java.nio.charset.CharsetDecoder;
+import java.nio.charset.CharsetEncoder;
+
+import com.ibm.misc.util.NotYetImplementedException;
+
+/**
+ * Provides convenience methods to java.io package streams.
+ *
+ */
+public final class Channels {
+
+ /*
+ * Not intended to be instantiated.
+ */
+ private Channels() {
+ super();
+ }
+
+ /**
+ * Answers an input stream on the given channel.
+ *
+ * @param channel the channel to be wrapped in an InputStream.
+ * @return an InputStream that takes bytes from the given byte channel.
+ */
+ public static InputStream newInputStream(ReadableByteChannel channel) {
+ // TODO
+ throw new NotYetImplementedException();
+ }
+
+ /**
+ * Answers an output stream on the given channel.
+ *
+ * @param channel the channel to be wrapped in an OutputStream.
+ * @return an OutputStream that puts bytes onto the given byte channel.
+ */
+ public static OutputStream newOutputStream(WritableByteChannel channel) {
+ // TODO
+ throw new NotYetImplementedException();
+ }
+
+ /**
+ * Answers a channel on the given input stream.
+ * @param inputStream the stream to be wrapped in a byte channel.
+ * @return a byte channel that reads bytes from the input stream.
+ */
+ public static ReadableByteChannel newChannel(InputStream inputStream) {
+ //TODO
+ throw new NotYetImplementedException();
+ }
+
+ /**
+ * Answers a channel on the given output stream.
+ * @param outputStream the stream to be wrapped in a byte channel.
+ * @return a byte channel that writes bytes to the output stream.
+ */
+ public static WritableByteChannel newChannel(OutputStream outputStream) {
+ //TODO
+ throw new NotYetImplementedException();
+ }
+
+ public static Reader newReader(ReadableByteChannel channel,
+ CharsetDecoder decoder, int minBufferCapacity) {
+ //TODO
+ throw new NotYetImplementedException();
+ }
+
+ public static Reader newReader(ReadableByteChannel channel,
+ String charsetName) {
+ return newReader(channel, Charset.forName(charsetName).newDecoder(), -1);
+ }
+
+ public static Writer newWriter(WritableByteChannel channel,
+ CharsetEncoder encoder, int minBufferCapacity) {
+ // TODO
+ throw new NotYetImplementedException();
+ }
+
+ public static Writer newWriter(WritableByteChannel channel,
+ String charsetName) {
+ return newWriter(channel, Charset.forName(charsetName).newEncoder(), -1);
+ }
+}
Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/java/nio/channels/ClosedByInterruptException.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/java/nio/channels/ClosedByInterruptException.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/java/nio/channels/ClosedByInterruptException.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/java/nio/channels/ClosedByInterruptException.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,38 @@
+/* Copyright 2004 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed 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 java.nio.channels;
+
+
+/**
+ * Thrown when a thread is interrupted in a blocking IO operation.
+ * <p>
+ * When the thread is interrupted by a call to <code>interrupt()</code>
+ * it will close the channel, set the interrupt status of the thread to true,
+ * and throw a <code>ClosedByInterruptException</code>.
+ *
+ */
+public class ClosedByInterruptException extends AsynchronousCloseException {
+
+ static final long serialVersionUID = -4488191543534286750L;
+
+ /**
+ * Default constructor.
+ *
+ */
+ public ClosedByInterruptException() {
+ super();
+ }
+}
Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/java/nio/channels/ClosedChannelException.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/java/nio/channels/ClosedChannelException.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/java/nio/channels/ClosedChannelException.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/java/nio/channels/ClosedChannelException.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,37 @@
+/* Copyright 2004 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed 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 java.nio.channels;
+
+
+import java.io.IOException;
+
+/**
+ * This exception is thrown when a channel is closed for the type of operation
+ * attempted.
+ *
+ */
+public class ClosedChannelException extends IOException {
+
+ static final long serialVersionUID = 882777185433553857L;
+
+ /**
+ * Default constructor.
+ */
+ public ClosedChannelException() {
+ super();
+ }
+
+}
Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/java/nio/channels/ClosedSelectorException.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/java/nio/channels/ClosedSelectorException.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/java/nio/channels/ClosedSelectorException.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/java/nio/channels/ClosedSelectorException.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,36 @@
+/* Copyright 2005 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed 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 java.nio.channels;
+
+
+/**
+ * Thrown when an a selector is closed and an IO operation is attempted.
+ *
+ */
+public class ClosedSelectorException extends IllegalStateException {
+
+ static final long serialVersionUID = 6466297122317847835L;
+
+ /**
+ * Default constructor.
+ *
+ */
+ public ClosedSelectorException() {
+ super();
+ }
+}
+
+
Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/java/nio/channels/ConnectionPendingException.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/java/nio/channels/ConnectionPendingException.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/java/nio/channels/ConnectionPendingException.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/java/nio/channels/ConnectionPendingException.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,36 @@
+/* Copyright 2005 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed 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 java.nio.channels;
+
+
+/**
+ * Thrown when an attempt is made to connect a SocketChannel that has a
+ * non-blocking connection already underway.
+ *
+ */
+public class ConnectionPendingException extends IllegalStateException {
+
+ static final long serialVersionUID = 2008393366501760879L;
+
+ /**
+ * Default constructor.
+ *
+ */
+ public ConnectionPendingException() {
+ super();
+ }
+
+}
Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/java/nio/channels/FileChannel.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/java/nio/channels/FileChannel.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/java/nio/channels/FileChannel.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/java/nio/channels/FileChannel.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,587 @@
+/* Copyright 2004 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed 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 java.nio.channels;
+
+
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.nio.MappedByteBuffer;
+import java.nio.channels.spi.AbstractInterruptibleChannel;
+
+/**
+ * An abstract channel type for interaction with a platform file.
+ * <p>
+ * A FileChannel defines the methods for reading, writing, memory mapping, and
+ * manipulating the logical state of a platform file. This type does not have a
+ * method for opening files, since this behaviour has been delegated to the
+ * <code>FileInputStream</code>, <code>FileOutputStream</code>, and
+ * <code>RandomAccessFile</code> types.
+ * </p>
+ * <p>
+ * FileChannels created from a FileInputStream, or a RandomAccessFile created in
+ * mode "r", are read-only. FileChannels created from a FileOutputStream are
+ * write-only. FileChannels created from a RandomAccessFile created in mode "rw"
+ * are read/write. FileChannels created from a RandomAccessFile that was opened
+ * in append-mode will also be in append-mode -- meaning that each write will be
+ * preceeded by a seek to the end of file. Some platforms will seek and write
+ * atomically, others will not.
+ * </p>
+ * <p>
+ * FileChannels has a virtual pointer into the file which is refered to as a
+ * file <em>position</em>. The position can be manipulated by repositioning
+ * it within the file, and its current position can be queried.
+ * </p>
+ * <p>
+ * FileChannels also have an associated <em>size</em>. The size of the file
+ * is the number of bytes that it currently contains. The size can be
+ * manipulated by adding more bytes to the end of the file (which increases the
+ * size) or truncating the file (which decreases the size). The current size can
+ * also be queried.
+ * </p>
+ * <p>
+ * FileChannels have operations beyond the simple read, write, and close. They
+ * can also:
+ * <ul>
+ * <li>request that cached data be forced onto the disk</li>
+ * <li>lock ranges of bytes associated with the file</li>
+ * <li>transfer data directly to another channel in a manner that has the
+ * potential to be optimized by the platform</li>
+ * <li>memory-mapping files into NIO buffers to provide efficient manipulation
+ * of file data</li>
+ * <li>read and write to the file at absolute byte offsets in a fashion that
+ * does not modify the current position</li>
+ * </ul>
+ * </p>
+ * <p>
+ * FileChannels are thread-safe. Only one operation involving manipulation of
+ * the file position may be in-flight at once. Subsequent calls to such
+ * operations will block, and one of those blocked will be freed to continue
+ * when the first operation has completed. There is no ordered queue or fairness
+ * applied to the blocked threads.
+ * </p>
+ * <p>
+ * It is undefined whether operations that do not manipulate the file position
+ * will also block when there are any other operations in-flight.
+ * </p>
+ * <p>
+ * The logical view of the underlying file is consistent across all FileChannels
+ * and IO streams opened on the same file by the same JVM process. Therefore
+ * modifications performed via a channel will be visible to the stream, and vice
+ * versa; including modifications to the file position, content, size, etc.
+ * </p>
+ *
+ */
+public abstract class FileChannel extends AbstractInterruptibleChannel
+ implements GatheringByteChannel, ScatteringByteChannel, ByteChannel {
+
+ /**
+ * A type of file mapping modes.
+ *
+ */
+ public static class MapMode {
+ /**
+ * Private mapping mode (equivalent to copy on write).
+ */
+ public static final MapMode PRIVATE = new MapMode("PRIVATE"); //$NON-NLS-1$
+
+ /**
+ * Read-only mapping mode.
+ */
+ public static final MapMode READ_ONLY = new MapMode("READ_ONLY"); //$NON-NLS-1$
+
+ /**
+ * Read-write mapping mode.
+ */
+ public static final MapMode READ_WRITE = new MapMode("READ_WRITE"); //$NON-NLS-1$
+
+ // The string used to display the mapping mode.
+ private final String displayName;
+
+ /*
+ * Private constructor prevents others creating new modes.
+ */
+ private MapMode(String displayName) {
+ super();
+ this.displayName = displayName;
+ }
+
+ /**
+ * Answers a string version of the mapping mode useful for debugging
+ * etc.
+ *
+ * @return the mode string.
+ */
+ public String toString() {
+ return displayName;
+ }
+ }
+
+ /**
+ * Protected default constructor.
+ */
+ protected FileChannel() {
+ super();
+ }
+
+ /**
+ * Request that all updates to the channel are committed to the storage
+ * device.
+ * <p>
+ * When this method returns all modifications made to the platform file
+ * underlying this channel will be committed to a local storage device. If
+ * the file is not hosted locally, such as a networked file system, then
+ * applications cannot be certain that the modifications have been
+ * committed.
+ * </p>
+ * <p>
+ * There are no assurances given that changes made to the file using methods
+ * defined elsewhere will be committed. For example, changes made via a
+ * mapped byte buffer may not be committed.
+ * </p>
+ * <p>
+ * The <code>metadata</code> parameter indicated whether the update should
+ * include the file's metadata such as last modification time, last access
+ * time, etc. Note that passing <code>true</code> may invoke an underlying
+ * write to the operating system (if the platform is maintaining metadata
+ * such as last access time), even if the channel is opened read-only.
+ *
+ * @param metadata
+ * true if the file metadata should be flushed in addition to the
+ * file content, and false otherwise.
+ * @throws ClosedChannelException
+ * if the channel is already closed.
+ * @throws IOException
+ * some other problem occured.
+ */
+ public abstract void force(boolean metadata) throws IOException;
+
+ /**
+ * Obtain an exclusive lock on this file.
+ * <p>
+ * This is a convenience method for acquiring a maximum length lock on a
+ * file. It is equivalent to:
+ *
+ * <pre>
+ * fileChannel.lock(0L, Long.MAX_VALUE, false)
+ * </pre>
+ *
+ * @return the lock object representing the locked file area.
+ * @throws ClosedChannelException
+ * the file channel is closed.
+ * @throws NonWritableChannelException
+ * this channel was not opened for writing.
+ * @throws OverlappingFileLockException
+ * Either a lock is already held that overlaps this lock
+ * request, or another thread is waiting to acquire a lock that
+ * will overlap with this request.
+ * @throws FileLockInterruptionException
+ * The calling thread was interrupted while waiting to acquire
+ * the lock.
+ * @throws AsynchronousCloseException
+ * The channel was closed while the calling thread was waiting
+ * to acquire the lock.
+ * @throws IOException
+ * some other problem occured obtaining the requested lock.
+ */
+ public final FileLock lock() throws IOException {
+ return lock(0L, Long.MAX_VALUE, false);
+ }
+
+ /**
+ * Obtain a lock on a specified region of the file.
+ * <p>
+ * This is the blocking version of lock acquisition, see also the
+ * <code>tryLock()</code> methods.
+ * </p>
+ * <p>
+ * Attempts to acquire an overlapping lock region will fail. The attempt
+ * will fail if the overlapping lock has already been obtained, or if
+ * another thread is currently waiting to acquire the overlapping lock.
+ * </p>
+ * <p>
+ * If the request is not for an overlapping lock, the thread calling this
+ * method will block until the lock is obtained (likely by no contention or
+ * another process releasing a lock), or this thread being interrupted or
+ * the channel closed.
+ * </p>
+ * <p>
+ * If the lock is obtained successfully then the FileLock object returned
+ * represents the lock for subsequent operations on the locked region.
+ * </p>
+ * <p>
+ * If the thread is interrupted while waiting for the lock, the thread is
+ * set to the interrupted state, and throws a
+ * <code>FileLockInterruptionException</code>. If the channel is closed
+ * while the thread is waiting to obtain the lock then the thread throws a
+ * <code>AsynchronousCloseException</code>.
+ * </p>
+ * <p>
+ * There is no requirement for the position and size to be within the
+ * current start and length of the file.
+ * </p>
+ * <p>
+ * Some platforms do not support shared locks, and if a request is made for
+ * a shared lock on such a platform this method will attempt to acquire an
+ * exclusive lock instead. It is undefined whether the lock obtained is
+ * advisory or mandatory.
+ * </p>
+ *
+ * @param position
+ * the starting position for the lock region
+ * @param size
+ * the length of the lock, in bytes
+ * @param shared
+ * a flag indicating whether an attempt should be made to acquire
+ * a shared lock.
+ * @return the file lock object
+ * @throws IllegalArgumentException
+ * if the parameters are invalid.
+ * @throws ClosedChannelException
+ * if the channel is already closed.
+ * @throws OverlappingFileLockException
+ * if the requested region overlaps an existing lock or pending
+ * lock request.
+ * @throws NonReadableChannelException
+ * if the channel is not open in read-mode and shared is true.
+ * @throws NonWritableChannelException
+ * if the channel is not open in write mode and shared is false.
+ * @throws AsynchronousCloseException
+ * if the channel is closed by another thread while this method
+ * is in operation.
+ * @throws FileLockInterruptionException
+ * if the thread is interrupted while in the state of waiting
+ * on the desired file lock.
+ * @throws IOException
+ * if some other IO problem occurs.
+ */
+ public abstract FileLock lock(long position, long size, boolean shared)
+ throws IOException;
+
+ /**
+ * TODO:
+ *
+ * @param mode
+ * @param position
+ * @param size
+ * @return the mapped byte buffer.
+ * @throws IOException
+ */
+ public abstract MappedByteBuffer map(FileChannel.MapMode mode,
+ long position, long size) throws IOException;
+
+ /**
+ * Answers the current value of the file position pointer.
+ *
+ * @return the current position as a positive integer number of bytes from
+ * the start of the file.
+ * @throws ClosedChannelException
+ * if the channel is already closed.
+ * @throws IOException
+ * if some other IO problem occurs.
+ */
+ public abstract long position() throws IOException;
+
+ /**
+ * Sets the file position pointer to a new value.
+ * <p>
+ * The argument is the number of bytes counted from the start of the file.
+ * The position cannot be set to a value that is negative. The new position
+ * can be set beyond the current file size. If set beyond the current file
+ * size, attempts to read will return end of file, and writes will succeed,
+ * but fill-in the bytes between the current end of file and the position
+ * with the required number of (unspecified) byte values.
+ *
+ * @param offset
+ * the new file position, in bytes.
+ * @return the receiver.
+ * @throws IllegalArgumentException
+ * if the new position is negative.
+ * @throws ClosedChannelException
+ * if the channel is already closed.
+ * @throws IOException
+ * if some other IO problem occurs.
+ */
+ public abstract FileChannel position(long offset) throws IOException;
+
+ /**
+ * Reads bytes from the channel into the given byte buffer.
+ * <p>
+ * The bytes are read starting at the current file position, and after some
+ * number of bytes are read (up to the remaining number of bytes in the
+ * buffer) the file position is increased by the number of bytes actually
+ * read.
+ *
+ * @see java.nio.channels.ReadableByteChannel#read(java.nio.ByteBuffer)
+ */
+ public abstract int read(ByteBuffer buffer) throws IOException;
+
+ /**
+ * Reads bytes from the file channel into the given buffer starting from the
+ * given file position.
+ * <p>
+ * The bytes are read starting at the given file position (up to the
+ * remaining number of bytes in the buffer). The number of bytes actually
+ * read is returned.
+ * </p>
+ * <p>
+ * If the position is beyond the current end of file, then no bytes are
+ * read.
+ * </p>
+ * <p>
+ * Note that file position is unmodified by this method.
+ * </p>
+ *
+ * @param buffer
+ * the buffer to receive the bytes
+ * @param position
+ * the (non-negative) position at which to read the bytes.
+ * @return the number of bytes actually read.
+ * @throws IllegalArgumentException
+ * if <code>position</code> is less than <code>-1</code>.
+ * @throws ClosedChannelException
+ * if the channel is already closed.
+ * @throws NonReadableChannelException
+ * if the channel was not opened in read-mode.
+ * @throws AsynchronousCloseException
+ * if the channel is closed by another thread while this method
+ * is in operation.
+ * @throws ClosedByInterruptException
+ * if another thread interrupts the calling thread while the
+ * operation is in progress. The calling thread will have the
+ * interrupt state set, and the channel will be closed.
+ * @throws IOException
+ * some other IO error occured.
+ */
+ public abstract int read(ByteBuffer buffer, long position)
+ throws IOException;
+
+ /**
+ * Reads bytes from the channel into all the given byte buffers.
+ * <p>
+ * The bytes are read starting at the current file position, and after some
+ * number of bytes are read (up to the remaining number of bytes in all the
+ * buffers) the file position is increased by the number of bytes actually
+ * read.
+ * </p>
+ * <p>
+ * This method behaves exactly like:
+ *
+ * <pre>
+ * read(buffers, 0, buffers.length);
+ * </pre>
+ *
+ * </p>
+ *
+ * @see java.nio.channels.ScatteringByteChannel#read(java.nio.ByteBuffer[])
+ */
+ public final long read(ByteBuffer[] buffers) throws IOException {
+ return read(buffers, 0, buffers.length);
+ }
+
+ /**
+ * Reads bytes from the file channel into a subset of the given byte
+ * buffers.
+ *
+ * @see java.nio.channels.ScatteringByteChannel#read(java.nio.ByteBuffer[],
+ * int, int)
+ */
+ public abstract long read(ByteBuffer[] buffers, int start, int number)
+ throws IOException;
+
+ /**
+ * Answers the size of the file underlying this channel, in bytes.
+ *
+ * @return the size of the file in bytes.
+ * @throws ClosedChannelException
+ * if the channel is closed.
+ * @throws IOException
+ * if a problem occurs getting the size of the file.
+ */
+ public abstract long size() throws IOException;
+
+ /**
+ * TODO:
+ *
+ * @param src
+ * @param position
+ * @param count
+ * @return the number of bytes that were transferred.
+ * @throws IOException
+ */
+ public abstract long transferFrom(ReadableByteChannel src, long position,
+ long count) throws IOException;
+
+ /**
+ * TODO
+ *
+ * @param position
+ * @param count
+ * @param target
+ * @return the number of bytes transferred.
+ * @throws IOException
+ */
+ public abstract long transferTo(long position, long count,
+ WritableByteChannel target) throws IOException;
+
+ /**
+ * Truncates the file underlying this channel to a given size.
+ * <p>
+ * Any bytes beyond the given size are removed from the file. If there are
+ * no bytes beyond the given size then the file contents are unmodified.
+ * </p>
+ * <p>
+ * If the file position is curently greater than the given size, then it is
+ * set to be the given size.
+ * </p>
+ *
+ * @param size
+ * the maximum size of the underlying file
+ * @throws IllegalArgumentException
+ * the requested size is negative.
+ * @throws ClosedChannelException
+ * the channel is closed.
+ * @throws NonWritableChannelException
+ * the channel cannot be written.
+ * @throws IOException
+ * some other IO problem occured.
+ * @return this channel
+ */
+ public abstract FileChannel truncate(long size) throws IOException;
+
+ /**
+ * Attempts to acquire an exclusive lock on this file without blocking.
+ * <p>
+ * This is a convenience method for attempting to acquire a maximum length
+ * lock on the file. It is equivalent to:
+ *
+ * <pre>
+ * fileChannel.tryLock(0L, Long.MAX_VALUE, false)
+ * </pre>
+ *
+ * </p>
+ * <p>
+ * The method returns
+ * <code>null</code< if the acquisition would result in an overlapped lock with another
+ * OS process.</p>
+ *
+ * @return the file lock object, or <code>null</code> if the lock would overlap an existing exclusive lock
+ * in another OS process.
+ * @throws ClosedChannelException the file channel is closed.
+ * @throws NonWritableChannelException this channel was not opened for writing.
+ * @throws OverlappingFileLockException Either a lock is already held that overlaps this lock request, or another thread is waiting to acquire a lock that will overlap with this request.
+ * @throws IOException
+ */
+ public final FileLock tryLock() throws IOException {
+ return tryLock(0L, Long.MAX_VALUE, false);
+ }
+
+ /**
+ * TODO
+ *
+ * @param position
+ * @param size
+ * @param shared
+ * @return the file lock.
+ * @throws IOException
+ */
+ public abstract FileLock tryLock(long position, long size, boolean shared)
+ throws IOException;
+
+ /**
+ * Writes bytes from the given byte buffer into the file channel.
+ * <p>
+ * The bytes are written starting at the current file position, and after
+ * some number of bytes are written (up to the remaining number of bytes in
+ * the buffer) the file position is increased by the number of bytes
+ * actually written.
+ *
+ * @see java.nio.channels.WritableByteChannel#write(java.nio.ByteBuffer)
+ */
+ public abstract int write(ByteBuffer src) throws IOException;
+
+ /**
+ * Writes bytes from the given buffer to the file channel starting at the
+ * given file position.
+ * <p>
+ * The bytes are written starting at the given file position (up to the
+ * remaining number of bytes in the buffer). The number of bytes actually
+ * written is returned.
+ * </p>
+ * <p>
+ * If the position is beyond the current end of file, then the file is first
+ * extended up to the given position by the required number of unspecified
+ * byte values.
+ * </p>
+ * <p>
+ * Note that file position is unmodified by this method.
+ * </p>
+ *
+ * @param buffer
+ * the buffer containing the bytes to be written.
+ * @param position
+ * the (non-negative) position at which to write the bytes.
+ * @return the number of bytes actually written.
+ * @throws IllegalArgumentException
+ * if <code>position</code> is less than <code>-1</code>.
+ * @throws ClosedChannelException
+ * if the channel is aleady closed.
+ * @throws NonWritableChannelException
+ * if the channel was not opened in write-mode.
+ * @throws AsynchronousCloseException
+ * if the channel is closed by another thread while this method
+ * is in operation.
+ * @throws ClosedByInterruptException
+ * if another thread interrupts the calling thread while the
+ * operation is in progress. The calling thread will have the
+ * interrupt state set, and the channel will be closed.
+ * @throws IOException
+ * some other IO error occured.
+ */
+ public abstract int write(ByteBuffer buffer, long position)
+ throws IOException;
+
+ /**
+ * Writes bytes from all the given byte buffers into the file channel.
+ * <p>
+ * The bytes are written starting at the current file position, and after
+ * some number of bytes are written (up to the remaining number of bytes in
+ * all the buffers) the file position is increased by the number of bytes
+ * actually written.
+ * <p>
+ * This method behaves exactly like:
+ *
+ * <pre>
+ * write(buffers, 0, buffers.length);
+ * </pre>
+ *
+ * </p>
+ *
+ * @see java.nio.channels.GatheringByteChannel#write(java.nio.ByteBuffer[])
+ */
+ public final long write(ByteBuffer[] buffers) throws IOException {
+ return write(buffers, 0, buffers.length);
+ }
+
+ /**
+ *
+ *
+ * @see java.nio.channels.GatheringByteChannel#write(java.nio.ByteBuffer[],
+ * int, int)
+ */
+ public abstract long write(ByteBuffer[] buffers, int offset, int length)
+ throws IOException;
+
+}
Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/java/nio/channels/FileLock.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/java/nio/channels/FileLock.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/java/nio/channels/FileLock.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/java/nio/channels/FileLock.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,200 @@
+/* Copyright 2004 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed 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 java.nio.channels;
+
+
+import java.io.IOException;
+
+/**
+ * A <code>FileLock</code> represents a locked region of a file.
+ * <p>
+ * Locks have certain properties that enable collaborating processes to avoid
+ * the lost update problem, or reading inconsistent data.
+ * </p>
+ * <p>
+ * logically, a file lock can be 'exclusive' or 'shared'. Multiple processes can
+ * hold shared locks on the same region of a file, but only a single process can
+ * hold an exclusive lock on a given region of a file and no other process can
+ * simultaneously hold a shared lock overlapping the exclusive lock. An
+ * application can determine whether a FileLock is shared or exclusive via the
+ * <code>isShared()</code> API.
+ * </p>
+ * <p>
+ * Locks held by a particular process cannot overlap one another. Applications
+ * can determine whether a proposed lock will overlap by using the
+ * <code>overlaps(long, long)</code) API. Locks held in
+ * other processes may overlap locks held in this process.</p>
+ * <p>
+ * Locks are shared amongst all threads in the acquiring process, and are therefore unsuitable for
+ * intra-process synchronization.</p>
+ * <p>
+ * Once a lock is acquired it is immutable in all its state except <code>isValid()</code>. The lock
+ * will initially be valid, but may be rendered invalid by explicit removal of the lock, using <code>
+ * release()</code>, or implictly by closing the channel or exiting the process (terminating the JVM).</p>
+ * <p>
+ * <em>Platform dependencies</em></p>
+ * <p>
+ * Locks are intended to be true platform operating system file locks, and therefore locks held by the
+ * JVM process will be visible to other OS processes.</p>
+ * <p>
+ * The characteristics of the underlying OS locks will show through in the Java implementation. For
+ * example, some platforms' locks are 'mandatory' -- meaning the operating system enforces the locks
+ * on processes that attempt to access locked regions of file; whereas other platforms' locks are
+ * only 'advisory' -- meaning that processes are required to collaborate on ensuring locks are acquired
+ * and there is a potential for processes not to play well. The only safe answer is to assume that
+ * the platform is adopting advisory locks an always acquire shared locks when reading a region of file.</p>
+ * <p>
+ * On some platforms the presence of a lock will prevent the file being memory mapped. On some platforms
+ * closing a channel on a given file handle will release all the locks held on that file -- even if there
+ * are other channels open on the same file (their locks will be released). The safe option here is to
+ * ensure that you only acquire locks on a single channel for a particular file, and that becomes the
+ * synchronization point.</p>
+ * <p>
+ * Further care should be exercised when locking files maintained on network file systems since they often
+ * have further limitations.</p>
+ *
+ */
+public abstract class FileLock {
+
+ // The underlying file channel.
+ private final FileChannel channel;
+
+ // The lock starting position.
+ private final long position;
+
+ // The lock length in bytes
+ private final long size;
+
+ // If true then shared, if false then exclusive
+ private final boolean shared;
+
+ /**
+ * Constructor for a new file lock instance for a given channel. The
+ * constructor enforces the starting position, stretch, and shared status of
+ * the lock.
+ *
+ * @param channel
+ * underlying file channel that holds the lock.
+ * @param position
+ * starting point for the lock.
+ * @param size
+ * length of lock in number of bytes.
+ * @param shared
+ * shared status of lock (true is shared, false is exclusive).
+ */
+ protected FileLock(FileChannel channel, long position, long size,
+ boolean shared) {
+ super();
+
+ this.channel = channel;
+ this.position = position;
+ this.size = size;
+ this.shared = shared;
+ }
+
+ /**
+ * Answers the lock's FileChannel.
+ *
+ * @return the channel.
+ */
+ public final FileChannel channel() {
+ return channel;
+ }
+
+ /**
+ * Answers the lock's starting position in the file.
+ *
+ * @return the lock position.
+ */
+ public final long position() {
+ return position;
+ }
+
+ /**
+ * Answers the length of the file lock in bytes.
+ *
+ * @return the size of file lock in bytes.
+ */
+ public final long size() {
+ return size;
+ }
+
+ /**
+ * Answers true if the file lock is shared with other proceses and false if
+ * it is not.
+ *
+ * @return true if the lock is a shared lock, and false if it is exclusive.
+ */
+ public final boolean isShared() {
+ return shared;
+ }
+
+ /**
+ * Answers true if the receiver's lock region overlapps the region described
+ * in the parameter list,and answers false otherwise.
+ *
+ * @param start
+ * the starting position for the comparative lock.
+ * @param length
+ * the length of the comparative lock.
+ * @return true if there is an overlap, and false otherwise.
+ */
+ public final boolean overlaps(long start, long length) {
+ long myEnd = position + size;
+ long otherEnd = start + length;
+ return ((start >= position) && (start <= myEnd))
+ || ((otherEnd >= position) && (otherEnd <= myEnd));
+ }
+
+ /**
+ * Answers whether the receiver is a valid file lock or not. The lock is
+ * valid unless the underlying channel has been closed or it has been
+ * explicitly released.
+ *
+ * @return true if the lock is valid, and false otherwise.
+ */
+ public abstract boolean isValid();
+
+ /**
+ * Releases this particular lock on the file. If the lock is invalid then
+ * this method has no effect. Once released the lock becomes invalid.
+ *
+ * @throws ClosedChannelException
+ * if the channel is already closed when an attempt to release
+ * the lock is made.
+ * @throws IOException
+ * some other IO exception occurred.
+ */
+ public abstract void release() throws IOException;
+
+ /**
+ * Answers a string that shows the details of the lock suitable for display
+ * to an end user.
+ *
+ * @return the display string.
+ */
+ public final String toString() {
+ StringBuffer buffer = new StringBuffer(64); // Guess length of string
+ buffer.append("FileLock: [position="); //$NON-NLS-1$
+ buffer.append(position);
+ buffer.append(", size="); //$NON-NLS-1$
+ buffer.append(size);
+ buffer.append(", shared="); //$NON-NLS-1$
+ buffer.append(Boolean.toString(shared));
+ buffer.append("]"); //$NON-NLS-1$
+ return buffer.toString();
+ }
+}
Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/java/nio/channels/FileLockInterruptionException.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/java/nio/channels/FileLockInterruptionException.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/java/nio/channels/FileLockInterruptionException.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/java/nio/channels/FileLockInterruptionException.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,38 @@
+/* Copyright 2004 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed 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 java.nio.channels;
+
+
+import java.io.IOException;
+
+/**
+ * Thrown when thread was interrupted while waiting to acquire a file lock.
+ * <p>
+ * Note that the thread will also be in the 'interrupted' state.
+ * </p>
+ *
+ */
+public class FileLockInterruptionException extends IOException {
+
+ static final long serialVersionUID = 7104080643653532383L;
+
+ /**
+ * Default constructor.
+ */
+ public FileLockInterruptionException() {
+ super();
+ }
+}
Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/java/nio/channels/GatheringByteChannel.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/java/nio/channels/GatheringByteChannel.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/java/nio/channels/GatheringByteChannel.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/java/nio/channels/GatheringByteChannel.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,103 @@
+/* Copyright 2004 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed 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 java.nio.channels;
+
+
+import java.io.IOException;
+import java.nio.ByteBuffer;
+
+/**
+ * The interface to channels that can write a set of buffers in a single
+ * operation.
+ * <p>
+ * The corresponding interface for reads is called
+ * <code>ScatteringByteChannel</code>.
+ *
+ */
+public interface GatheringByteChannel extends WritableByteChannel {
+
+ /**
+ * Writes bytes from all the given buffers to the channel.
+ * <p>
+ * This method is equivalent to:
+ *
+ * <pre>
+ * write(buffers, 0, buffers.length);
+ * </pre>
+ *
+ * </p>
+ *
+ * @param buffers
+ * the buffers containing bytes to be written.
+ * @return the number of bytes actually written.
+ * @throws ClosedChannelException
+ * if the channel is closed.
+ * @throws NonWritableChannelException
+ * if the channel is open, but not in a mode that permits
+ * writing.
+ * @throws ClosedByInterruptException
+ * if the thread is interrupted in its IO operation by another
+ * thread closing the channel.
+ * @throws AsynchronousCloseException
+ * if the write is interrupted by another thread sending an
+ * explicit interrupt.
+ * @throws IOException
+ * if some other type of exception occurs. Details are in the
+ * message.
+ */
+ public long write(ByteBuffer[] buffers) throws IOException;
+
+ /**
+ * Writes a subset of the given bytes from the buffers to the channel.
+ * <p>
+ * This method attempts to write all of the <code>remaining()</code> bytes
+ * from <code>length</code> byte buffers, in order, starting at
+ * <code>buffers[offset]</code>. The number of bytes actually written is
+ * returned.
+ * </p>
+ * <p>
+ * If a write operation is in progress, subsequent threads will block until
+ * the write is completed, and will then contend for the ability to write.
+ * </p>
+ *
+ * @param buffers
+ * the array of byte buffers containing the source of remaining
+ * bytes that will be attempted to be written.
+ * @param offset
+ * the index of the first buffer to write.
+ * @param length
+ * the number of buffers to write.
+ * @return the number of bytes actually written.
+ * @throws IndexOutOfBoundsException
+ * if offset < 0 or > buffers.length; or length < 0 or >
+ * buffers.length - offset.
+ * @throws NonWritableChannelException
+ * if the channel was not opened for writing.
+ * @throws ClosedChannelException
+ * the channel is currently closed.
+ * @throws AsynchronousCloseException
+ * the channel was closed by another thread while the write was
+ * underway.
+ * @throws ClosedByInterruptException
+ * the thread was interrupted by another thread while the write
+ * was underway.
+ * @throws IOException
+ * if some other type of exception occurs. Details are in the
+ * message.
+ */
+ public long write(ByteBuffer[] buffers, int offset, int length)
+ throws IOException;
+}
Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/java/nio/channels/IllegalBlockingModeException.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/java/nio/channels/IllegalBlockingModeException.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/java/nio/channels/IllegalBlockingModeException.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/java/nio/channels/IllegalBlockingModeException.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,34 @@
+/* Copyright 2005 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed 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 java.nio.channels;
+
+
+/**
+ * Thrown when when operation that requires a specific blocking mode is invoked
+ * on a channel that is in a different blocking mode.
+ *
+ */
+public class IllegalBlockingModeException extends IllegalStateException {
+
+ static final long serialVersionUID = -3335774961855590474L;
+
+ /**
+ * Default constructor.
+ */
+ public IllegalBlockingModeException() {
+ super();
+ }
+}
Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/java/nio/channels/IllegalSelectorException.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/java/nio/channels/IllegalSelectorException.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/java/nio/channels/IllegalSelectorException.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/java/nio/channels/IllegalSelectorException.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,36 @@
+/* Copyright 2005 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed 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 java.nio.channels;
+
+
+/**
+ * Thrown when a call is made to register a channel on a selector that has been
+ * created by a different provider.
+ *
+ */
+public class IllegalSelectorException extends IllegalArgumentException {
+
+ static final long serialVersionUID = -8406323347253320987L;
+
+ /**
+ * Default constructor.
+ *
+ */
+ public IllegalSelectorException() {
+ super();
+ }
+
+}
Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/java/nio/channels/InterruptibleChannel.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/java/nio/channels/InterruptibleChannel.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/java/nio/channels/InterruptibleChannel.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/java/nio/channels/InterruptibleChannel.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,57 @@
+/* Copyright 2004 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed 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 java.nio.channels;
+
+
+import java.io.IOException;
+
+/**
+ * Channels that implement this interface are both asynchronously closeable and
+ * interruptable.
+ * <p>
+ * A channel that is asynchronously closeable permits a thread blocked on an IO
+ * operation (the IO thread) to be released by another thread calling the
+ * channel's <code>close()</code> method. The IO thread will throw an
+ * <code>AsynchronousCloseException</code> and the channel will be closed.
+ * </p>
+ * <p>
+ * A channel that is interruptable permits a thread blocked on an IO operation
+ * (the IO thread) to be interrupted by another thread (by invoking
+ * <code>interrupt()</code> on the IO thread). When the IO thread is
+ * interrupted it will throw a <code>ClosedByInterruptException</code>
+ * exception, it will have its interrupted status set, and the channel will be
+ * closed. If the IO thread attempts to make an IO call with the interrupt
+ * status set the call will immediately fail with a
+ * <code>ClosedByInterruptException</code>.
+ *
+ */
+public interface InterruptibleChannel extends Channel {
+
+ /**
+ * Closes an InterruptibleChannel. This method is precisely the same as the
+ * super-interface <code>close()</code>.
+ * <p>
+ * Any threads that are blocked on IO operations on this channel will be
+ * interrupted with an <code>AsynchronousCloseException
+ * </code>.
+ * </p>
+ *
+ * @throws IOException
+ * if an IO problem occurs closing the channel.
+ */
+ public void close() throws IOException;
+
+}
Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/java/nio/channels/NoConnectionPendingException.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/java/nio/channels/NoConnectionPendingException.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/java/nio/channels/NoConnectionPendingException.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/java/nio/channels/NoConnectionPendingException.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,35 @@
+/* Copyright 2005 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed 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 java.nio.channels;
+
+
+/**
+ * Thrown if SocketChannel's finishConnect method is called before the
+ * SocketChannel's connect method completed without error.
+ *
+ */
+public class NoConnectionPendingException extends IllegalStateException {
+
+ static final long serialVersionUID = -8296561183633134743L;
+
+ /**
+ * Default constructor.
+ *
+ */
+ public NoConnectionPendingException() {
+ super();
+ }
+}
Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/java/nio/channels/NonReadableChannelException.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/java/nio/channels/NonReadableChannelException.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/java/nio/channels/NonReadableChannelException.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/java/nio/channels/NonReadableChannelException.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,33 @@
+/* Copyright 2004 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed 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 java.nio.channels;
+
+
+/**
+ * Thrown when attempting to read from a channel that is not open for reading.
+ *
+ */
+public class NonReadableChannelException extends IllegalStateException {
+
+ static final long serialVersionUID = -3200915679294993514L;
+
+ /**
+ * Default constructor.
+ */
+ public NonReadableChannelException() {
+ super();
+ }
+}
Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/java/nio/channels/NonWritableChannelException.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/java/nio/channels/NonWritableChannelException.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/java/nio/channels/NonWritableChannelException.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/java/nio/channels/NonWritableChannelException.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,33 @@
+/* Copyright 2004 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed 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 java.nio.channels;
+
+
+/**
+ * Thrown when attempting to write to a channel that is not open for writing.
+ *
+ */
+public class NonWritableChannelException extends IllegalStateException {
+
+ static final long serialVersionUID = -7071230488279011621L;
+
+ /**
+ * Default constructor.
+ */
+ public NonWritableChannelException() {
+ super();
+ }
+}
Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/java/nio/channels/NotYetBoundException.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/java/nio/channels/NotYetBoundException.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/java/nio/channels/NotYetBoundException.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/java/nio/channels/NotYetBoundException.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,35 @@
+/* Copyright 2005 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed 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 java.nio.channels;
+
+
+/**
+ * Thrown if the server socket channel is not bound before an IO operation is
+ * made.
+ *
+ */
+public class NotYetBoundException extends IllegalStateException {
+
+ static final long serialVersionUID = 4640999303950202242L;
+
+ /**
+ * Default constructor.
+ *
+ */
+ public NotYetBoundException() {
+ super();
+ }
+}
Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/java/nio/channels/NotYetConnectedException.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/java/nio/channels/NotYetConnectedException.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/java/nio/channels/NotYetConnectedException.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/java/nio/channels/NotYetConnectedException.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,36 @@
+/* Copyright 2005 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed 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 java.nio.channels;
+
+
+/**
+ * Thrown if the socket channel is not connected before an IO operation is
+ * invoked.
+ *
+ */
+public class NotYetConnectedException extends IllegalStateException {
+
+ static final long serialVersionUID = 4697316551909513464L;
+
+ /**
+ * Default constructor.
+ *
+ */
+ public NotYetConnectedException() {
+ super();
+ }
+
+}
Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/java/nio/channels/OverlappingFileLockException.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/java/nio/channels/OverlappingFileLockException.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/java/nio/channels/OverlappingFileLockException.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/java/nio/channels/OverlappingFileLockException.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,34 @@
+/* Copyright 2004 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed 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 java.nio.channels;
+
+
+/**
+ * Thrown when attempting to acquire a lock that overlaps an existing or pending
+ * lock held by this process.
+ *
+ */
+public class OverlappingFileLockException extends IllegalStateException {
+
+ static final long serialVersionUID = 2047812138163068433L;
+
+ /**
+ * Default constructor.
+ */
+ public OverlappingFileLockException() {
+ super();
+ }
+}
Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/java/nio/channels/Pipe.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/java/nio/channels/Pipe.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/java/nio/channels/Pipe.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/java/nio/channels/Pipe.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,67 @@
+/* Copyright 2005 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed 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 java.nio.channels;
+
+
+import java.io.IOException;
+import java.nio.channels.spi.AbstractSelectableChannel;
+import java.nio.channels.spi.SelectorProvider;
+
+/**
+ * TODO Type description
+ *
+ */
+public abstract class Pipe {
+
+ public static abstract class SinkChannel extends AbstractSelectableChannel
+ implements WritableByteChannel, GatheringByteChannel {
+ protected SinkChannel(SelectorProvider provider) {
+ super(provider);
+ }
+
+ public final int validOps() {
+ return SelectionKey.OP_WRITE;
+ }
+
+ }
+
+ public static abstract class SourceChannel extends
+ AbstractSelectableChannel implements ReadableByteChannel,
+ ScatteringByteChannel {
+
+ protected SourceChannel(SelectorProvider provider) {
+ super(provider);
+ }
+
+ public final int validOps() {
+ return SelectionKey.OP_READ;
+ }
+
+ }
+
+ public static Pipe open() throws IOException {
+ return SelectorProvider.provider().openPipe();
+ }
+
+ protected Pipe() {
+ super();
+ }
+
+ public abstract SinkChannel sink();
+
+ public abstract SourceChannel source();
+
+}
Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/java/nio/channels/ReadableByteChannel.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/java/nio/channels/ReadableByteChannel.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/java/nio/channels/ReadableByteChannel.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/java/nio/channels/ReadableByteChannel.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,66 @@
+/* Copyright 2004 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed 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 java.nio.channels;
+
+
+import java.io.IOException;
+import java.nio.ByteBuffer;
+
+/**
+ * A ReadableByteChannel is a type of Channel that can read bytes.
+ * <p>
+ * Reads are synchronous on a ReadableByteChannel, that is, if a read is already
+ * in progress on the channel then subsequent reads will block until the first
+ * read completes. It is undefined whether non-read operations will block.
+ *
+ */
+public interface ReadableByteChannel extends Channel {
+
+ /**
+ * Reads bytes from the channel into the given buffer.
+ * <p>
+ * The maximum number of bytes that will be read is the
+ * <code>remaining()</code> number of bytes in the buffer when the method
+ * invoked. The bytes will be read into the buffer starting at the buffer's
+ * <code>position</code>.
+ * </p>
+ * <p>
+ * The call may block if other threads are also attempting to read on the
+ * same channel.
+ * </p>
+ * <p>
+ * Upon completion, the buffer's <code>position()</code> is updated to the
+ * end of the bytes that were read. The buffer's <code>limit()</code> is
+ * unmodified.
+ * </p>
+ *
+ * @param buffer
+ * the byte buffer to receive the bytes.
+ * @return the number of bytes actually read.
+ * @throws NonReadableChannelException
+ * if the channel was not opened for reading.
+ * @throws ClosedChannelException
+ * if the channel was already closed.
+ * @throws AsynchronousCloseException
+ * if another thread closes the channel during the read.
+ * @throws ClosedByInterruptException
+ * if another thread interrupt the calling thread during the
+ * read.
+ * @throws IOException
+ * another IO exception occurs, details are in the message.
+ */
+ public int read(ByteBuffer buffer) throws IOException;
+}
Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/java/nio/channels/ScatteringByteChannel.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/java/nio/channels/ScatteringByteChannel.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/java/nio/channels/ScatteringByteChannel.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/java/nio/channels/ScatteringByteChannel.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,103 @@
+/* Copyright 2004 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed 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 java.nio.channels;
+
+
+import java.io.IOException;
+import java.nio.ByteBuffer;
+
+/**
+ * The interface to channels that can read a set of buffers in a single
+ * operation.
+ * <p>
+ * The corresponding interface for writes is called
+ * <code>GatheringByteChannel</code>.
+ *
+ */
+public interface ScatteringByteChannel extends ReadableByteChannel {
+
+ /**
+ * Reads bytes from the channel into all the given buffers.
+ * <p>
+ * This method is equivalent to:
+ *
+ * <pre>
+ * read(buffers, 0, buffers.length);
+ * </pre>
+ *
+ * </p>
+ *
+ * @param buffers
+ * the array of byte buffers to receive the bytes being read.
+ * @return the number of bytes actually read.
+ * @throws ClosedChannelException
+ * if the channel is closed.
+ * @throws NonReadableChannelException
+ * if the channel is open, but not in a mode that permits
+ * reading.
+ * @throws ClosedByInterruptException
+ * if the thread is interrupted in its IO operation by another
+ * thread closing the channel.
+ * @throws AsynchronousCloseException
+ * if the read is interrupted by another thread sending an
+ * explicit interrupt.
+ * @throws IOException
+ * if some other type of exception occurs. Details are in the
+ * message.
+ */
+ public long read(ByteBuffer[] buffers) throws IOException;
+
+ /**
+ * Reads bytes from the channel into a subset of the given buffers.
+ * <p>
+ * This method attempts to read all of the <code>remaining()</code> bytes
+ * from <code>length</code> byte buffers, in order, starting at
+ * <code>buffers[offset]</code>. The number of bytes actually read is
+ * returned.
+ * </p>
+ * <p>
+ * If a read operation is in progress, subsequent threads will block until
+ * the read is completed, and will then contend for the ability to read.
+ * </p>
+ *
+ * @param buffers
+ * the array of byte buffers into which the bytes will be read.
+ * @param offset
+ * the index of the first buffer to read.
+ * @param length
+ * the maximum number of buffers to read.
+ * @return the number of bytes actually read.
+ * @throws IndexOutOfBoundsException
+ * if offset < 0 or > buffers.length; or length < 0 or >
+ * buffers.length - offset.
+ * @throws NonReadableChannelException
+ * if the channel was not opened for reading.
+ * @throws ClosedChannelException
+ * the channel is currently closed.
+ * @throws AsynchronousCloseException
+ * the channel was closed by another thread while the write was
+ * underway.
+ * @throws ClosedByInterruptException
+ * the thread was interrupted by another thread while the write
+ * was underway.
+ * @throws IOException
+ * if some other type of exception occurs. Details are in the
+ * message.
+ */
+ public long read(ByteBuffer[] buffers, int offset, int length)
+ throws IOException;
+
+}
Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/java/nio/channels/SelectableChannel.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/java/nio/channels/SelectableChannel.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/java/nio/channels/SelectableChannel.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/java/nio/channels/SelectableChannel.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,57 @@
+/* Copyright 2005 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed 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 java.nio.channels;
+
+
+import java.io.IOException;
+import java.nio.channels.spi.AbstractInterruptibleChannel;
+import java.nio.channels.spi.SelectorProvider;
+
+/**
+ * TODO Type description
+ *
+ */
+public abstract class SelectableChannel extends AbstractInterruptibleChannel
+ implements Channel {
+
+ protected SelectableChannel() {
+ super();
+ }
+
+ public abstract Object blockingLock();
+
+ public abstract SelectableChannel configureBlocking(boolean block)
+ throws IOException;
+
+ public abstract boolean isBlocking();
+
+ public abstract boolean isRegistered();
+
+ public abstract SelectionKey keyFor(Selector sel);
+
+ public abstract SelectorProvider provider();
+
+ public final SelectionKey register(Selector selector, int operations)
+ throws ClosedChannelException {
+ return register(selector, operations, null);
+ }
+
+ public abstract SelectionKey register(Selector sel, int ops, Object att)
+ throws ClosedChannelException;
+
+ public abstract int validOps();
+
+}
Added: incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/java/nio/channels/SelectionKey.java
URL: http://svn.apache.org/viewcvs/incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/java/nio/channels/SelectionKey.java?rev=350181&view=auto
==============================================================================
--- incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/java/nio/channels/SelectionKey.java (added)
+++ incubator/harmony/enhanced/trunk/sandbox/contribs/ibm_core/java-src/nio/src/java/nio/channels/SelectionKey.java Wed Nov 30 21:29:27 2005
@@ -0,0 +1,80 @@
+/* Copyright 2005 The Apache Software Foundation or its licensors, as applicable
+ *
+ * Licensed 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 java.nio.channels;
+
+
+import java.nio.channels.Selector;
+
+/**
+ * TODO Type description
+ *
+ */
+public abstract class SelectionKey {
+
+ public static final int OP_ACCEPT = 16;
+
+ public static final int OP_CONNECT = 8;
+
+ public static final int OP_READ = 1;
+
+ public static final int OP_WRITE = 4;
+
+ private volatile Object attachment = null;
+
+ protected SelectionKey() {
+ super();
+ }
+
+ public final Object attach(Object anObject) {
+ Object oldAttachment = attachment;
+ attachment = anObject;
+ return oldAttachment;
+ }
+
+ public final Object attachment() {
+ return attachment;
+ }
+
+ public abstract void cancel();
+
+ public abstract SelectableChannel channel();
+
+ public abstract int interestOps();
+
+ public abstract SelectionKey interestOps(int operations);
+
+ public final boolean isAcceptable() {
+ return (readyOps() & OP_ACCEPT) == OP_ACCEPT;
+ }
+
+ public final boolean isConnectable() {
+ return (readyOps() & OP_CONNECT) == OP_CONNECT;
+ }
+
+ public final boolean isReadable() {
+ return (readyOps() & OP_READ) == OP_READ;
+ }
+
+ public abstract boolean isValid();
+
+ public final boolean isWritable() {
+ return (readyOps() & OP_WRITE) == OP_WRITE;
+ }
+
+ public abstract int readyOps();
+
+ public abstract Selector selector();
+}