1 /*
   2  * Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 /**
  27  * Defines buffers, which are containers for data, and provides an
  28  * overview of the other NIO packages.
  29  *
  30  *
  31  * <p> The central abstractions of the NIO APIs are: </p>
  32  *
  33  * <ul>
  34  *
  35  *   <li><p> <a href="#buffers"><i>Buffers</i></a>, which are containers for data;
  36  *   </p></li>
  37  *
  38  *   <li><p> <a
  39  *   href="charset/package-summary.html"><i>Charsets</i></a> and their
  40  *   associated <i>decoders</i> and <i>encoders</i>, <br> which
  41  *   translate between bytes and Unicode characters; </p></li>
  42  *
  43  *   <li><p> <a
  44  *   href="channels/package-summary.html"><i>Channels</i></a> of
  45  *   various types, which represent connections <br> to entities
  46  *   capable of performing I/O operations; and </p></li>
  47  *
  48  *   <li><p> <i>Selectors</i> and <i>selection keys</i>, which
  49  *   together with <br> <i>selectable channels</i> define a <a
  50  *   href="channels/package-summary.html#multiplex">multiplexed,
  51  *   non-blocking <br> I/O</a>&nbsp;facility.  </p></li>
  52  *
  53  *  </ul>
  54  *
  55  * <p> The {@code java.nio} package defines the buffer classes, which
  56  * are used throughout the NIO APIs.  The charset API is defined in
  57  * the {@link java.nio.charset} package, and the channel and selector
  58  * APIs are defined in the {@link java.nio.channels} package.  Each of
  59  * these subpackages has its own service-provider (SPI) subpackage,
  60  * the contents of which can be used to extend the platform's default
  61  * implementations or to construct alternative implementations.
  62  *
  63  * <a id="buffers"> </a>
  64  *
  65  * <blockquote><table cellspacing=1 cellpadding=0 summary="Description of the various buffers">
  66  *   <tr><th align="left">Buffers</th><th align="left">Description</th></tr>
  67  *   <tr><td valign=top>{@link java.nio.Buffer}</td>
  68  *       <td>Position, limit, and capacity;
  69  *           <br>clear, flip, rewind, and mark/reset</td></tr>
  70  *   <tr><td valign=top>&nbsp;&nbsp;{@link java.nio.ByteBuffer}</td>
  71  *       <td>Get/put, compact, views; allocate,&nbsp;wrap</td></tr>
  72  *   <tr><td valign=top>&nbsp;&nbsp;&nbsp;&nbsp;{@link java.nio.MappedByteBuffer}&nbsp;&nbsp;</td>
  73  *       <td>A byte buffer mapped to a file</td></tr>
  74  *   <tr><td valign=top>&nbsp;&nbsp;{@link java.nio.CharBuffer}</td>
  75  *       <td>Get/put, compact; allocate,&nbsp;wrap</td></tr>
  76  *   <tr><td valign=top>&nbsp;&nbsp;{@link java.nio.DoubleBuffer}</td>
  77  *       <td>&nbsp;&nbsp;&nbsp;&nbsp;'&nbsp;'</td></tr>
  78  *   <tr><td valign=top>&nbsp;&nbsp;{@link java.nio.FloatBuffer}</td>
  79  *       <td>&nbsp;&nbsp;&nbsp;&nbsp;'&nbsp;'</td></tr>
  80  *   <tr><td valign=top>&nbsp;&nbsp;{@link java.nio.IntBuffer}</td>
  81  *       <td>&nbsp;&nbsp;&nbsp;&nbsp;'&nbsp;'</td></tr>
  82  *   <tr><td valign=top>&nbsp;&nbsp;{@link java.nio.LongBuffer}</td>
  83  *       <td>&nbsp;&nbsp;&nbsp;&nbsp;'&nbsp;'</td></tr>
  84  *   <tr><td valign=top>&nbsp;&nbsp;{@link java.nio.ShortBuffer}</td>
  85  *       <td>&nbsp;&nbsp;&nbsp;&nbsp;'&nbsp;'</td></tr>
  86  *   <tr><td valign=top>{@link java.nio.ByteOrder}</td>
  87  *       <td>Typesafe enumeration for&nbsp;byte&nbsp;orders</td></tr>
  88  * </table></blockquote>
  89  *
  90  * <p> A <i>buffer</i> is a container for a fixed amount of data of a
  91  * specific primitive type.  In addition to its content a buffer has a
  92  * <i>position</i>, which is the index of the next element to be read
  93  * or written, and a <i>limit</i>, which is the index of the first
  94  * element that should not be read or written.  The base {@link
  95  * java.nio.Buffer} class defines these properties as well as methods
  96  * for <i>clearing</i>, <i>flipping</i>, and <i>rewinding</i>, for
  97  * <i>marking</i> the current position, and for <i>resetting</i> the
  98  * position to the previous mark.
  99  *
 100  * <p> There is a buffer class for each non-boolean primitive type.
 101  * Each class defines a family of <i>get</i> and <i>put</i> methods
 102  * for moving data out of and in to a buffer, methods for
 103  * <i>compacting</i>, <i>duplicating</i>, and <i>slicing</i> a buffer,
 104  * and static methods for <i>allocating</i> a new buffer as well as
 105  * for <i>wrapping</i> an existing array into a buffer.
 106  *
 107  * <p> Byte buffers are distinguished in that they can be used as the
 108  * sources and targets of I/O operations.  They also support several
 109  * features not found in the other buffer classes:
 110  *
 111  * <ul>
 112  *
 113  *   <li><p> A byte buffer can be allocated as a <a
 114  *   href="ByteBuffer.html#direct"> <i>direct</i></a> buffer, in which
 115  *   case the Java virtual machine will make a best effort to perform
 116  *   native I/O operations directly upon it.  </p></li>
 117  *
 118  *   <li><p> A byte buffer can be created by {@link
 119  *   java.nio.channels.FileChannel#map <i>mapping</i>} a region of a
 120  *   file directly into memory, in which case a few additional
 121  *   file-related operations defined in the {@link
 122  *   java.nio.MappedByteBuffer} class are available.  </p></li>
 123  *
 124  *   <li><p> A byte buffer provides access to its content as either a
 125  *   heterogeneous or homogeneous sequence of <a
 126  *   href="ByteBuffer.html#bin"><i>binary data</i></a> of any
 127  *   non-boolean primitive type, in either big-endian or little-endian
 128  *   <a href="ByteOrder.html">byte order</a>.  </p></li>
 129  *
 130  * </ul>
 131  *
 132  * <p> Unless otherwise noted, passing a {@code null} argument to a
 133  * constructor or method in any class or interface in this package
 134  * will cause a {@link java.lang.NullPointerException
 135  * NullPointerException} to be thrown.
 136  *
 137  * @since 1.4
 138  * @author Mark Reinhold
 139  * @author JSR-51 Expert Group
 140  */
 141 package java.nio;