jdk/src/share/classes/java/nio/channels/WritableByteChannel.java
author alanb
Fri, 02 Nov 2012 15:50:11 +0000
changeset 14342 8435a30053c1
parent 5506 202f599c92aa
permissions -rw-r--r--
7197491: update copyright year to match last edit in jdk8 jdk repository Reviewed-by: chegar, ksrini
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     2
 * Copyright (c) 2000, 2005, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package java.nio.channels;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.nio.ByteBuffer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * A channel that can write bytes.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * <p> Only one write operation upon a writable channel may be in progress at
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * any given time.  If one thread initiates a write operation upon a channel
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * then any other thread that attempts to initiate another write operation will
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * block until the first operation is complete.  Whether or not other kinds of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * I/O operations may proceed concurrently with a write operation depends upon
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * the type of the channel. </p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * @author Mark Reinhold
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * @author JSR-51 Expert Group
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
public interface WritableByteChannel
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
    extends Channel
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
{
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
     * Writes a sequence of bytes to this channel from the given buffer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
     * <p> An attempt is made to write up to <i>r</i> bytes to the channel,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
     * where <i>r</i> is the number of bytes remaining in the buffer, that is,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
     * <tt>src.remaining()</tt>, at the moment this method is invoked.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
     * <p> Suppose that a byte sequence of length <i>n</i> is written, where
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
     * <tt>0</tt>&nbsp;<tt>&lt;=</tt>&nbsp;<i>n</i>&nbsp;<tt>&lt;=</tt>&nbsp;<i>r</i>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
     * This byte sequence will be transferred from the buffer starting at index
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
     * <i>p</i>, where <i>p</i> is the buffer's position at the moment this
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
     * method is invoked; the index of the last byte written will be
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
     * <i>p</i>&nbsp;<tt>+</tt>&nbsp;<i>n</i>&nbsp;<tt>-</tt>&nbsp;<tt>1</tt>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
     * Upon return the buffer's position will be equal to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
     * <i>p</i>&nbsp;<tt>+</tt>&nbsp;<i>n</i>; its limit will not have changed.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
     * <p> Unless otherwise specified, a write operation will return only after
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
     * writing all of the <i>r</i> requested bytes.  Some types of channels,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
     * depending upon their state, may write only some of the bytes or possibly
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
     * none at all.  A socket channel in non-blocking mode, for example, cannot
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
     * write any more bytes than are free in the socket's output buffer.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
     * <p> This method may be invoked at any time.  If another thread has
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
     * already initiated a write operation upon this channel, however, then an
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
     * invocation of this method will block until the first operation is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     * complete. </p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     * @param  src
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     *         The buffer from which bytes are to be retrieved
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     * @return The number of bytes written, possibly zero
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     * @throws  NonWritableChannelException
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     *          If this channel was not opened for writing
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     * @throws  ClosedChannelException
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     *          If this channel is closed
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     * @throws  AsynchronousCloseException
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     *          If another thread closes this channel
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     *          while the write operation is in progress
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     * @throws  ClosedByInterruptException
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     *          If another thread interrupts the current thread
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     *          while the write operation is in progress, thereby
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     *          closing the channel and setting the current thread's
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     *          interrupt status
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     * @throws  IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     *          If some other I/O error occurs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    public int write(ByteBuffer src) throws IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
}