Path: blob/master/src/java.base/share/classes/java/nio/package-info.java
41152 views
/*1* Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425/**26* Defines buffers, which are containers for data, and provides an27* overview of the other NIO packages.28*29*30* <p> The central abstractions of the NIO APIs are: </p>31*32* <ul>33*34* <li><p> <a href="#buffers"><i>Buffers</i></a>, which are containers for data;35* </p></li>36*37* <li><p> <a38* href="charset/package-summary.html"><i>Charsets</i></a> and their39* associated <i>decoders</i> and <i>encoders</i>, <br> which40* translate between bytes and Unicode characters; </p></li>41*42* <li><p> <a43* href="channels/package-summary.html"><i>Channels</i></a> of44* various types, which represent connections <br> to entities45* capable of performing I/O operations; and </p></li>46*47* <li><p> <i>Selectors</i> and <i>selection keys</i>, which48* together with <br> <i>selectable channels</i> define a <a49* href="channels/package-summary.html#multiplex">multiplexed,50* non-blocking <br> I/O</a> facility. </p></li>51*52* </ul>53*54* <p> The {@code java.nio} package defines the buffer classes, which55* are used throughout the NIO APIs. The charset API is defined in56* the {@link java.nio.charset} package, and the channel and selector57* APIs are defined in the {@link java.nio.channels} package. Each of58* these subpackages has its own service-provider (SPI) subpackage,59* the contents of which can be used to extend the platform's default60* implementations or to construct alternative implementations.61*62* <a id="buffers"> </a>63*64* <table class="striped" style="margin-left:2em; text-align:left">65* <caption style="display:none">Description of the various buffers</caption>66* <thead>67* <tr><th scope="col">Buffers</th>68* <th scope="col">Description</th></tr>69* </thead>70* <tbody>71* <tr><th scope="row">{@link java.nio.Buffer}</th>72* <td>Position, limit, and capacity;73* clear, flip, rewind, and mark/reset</td></tr>74* <tr><th scope="row">75* <span style="padding-left:1em">{@link java.nio.ByteBuffer}</span></th>76* <td>Get/put, compact, views; allocate, wrap</td></tr>77* <tr><th scope="row">78* <span style="padding-left:2em">{@link java.nio.MappedByteBuffer}</span></th>79* <td>A byte buffer mapped to a file</td></tr>80* <tr><th scope="row">81* <span style="padding-left:1em">{@link java.nio.CharBuffer}</span></th>82* <td>Get/put, compact; allocate, wrap</td></tr>83* <tr><th scope="row">84* <span style="padding-left:1em">{@link java.nio.DoubleBuffer}</span></th>85* <td>Get/put, compact; allocate, wrap</td></tr>86* <tr><th scope="row">87* <span style="padding-left:1em">{@link java.nio.FloatBuffer}</span></th>88* <td>Get/put, compact; allocate, wrap</td></tr>89* <tr><th scope="row">90* <span style="padding-left:1em">{@link java.nio.IntBuffer}</span></th>91* <td>Get/put, compact; allocate, wrap</td></tr>92* <tr><th scope="row">93* <span style="padding-left:1em">{@link java.nio.LongBuffer}</span></th>94* <td>Get/put, compact; allocate, wrap</td></tr>95* <tr><th scope="row">96* <span style="padding-left:1em">{@link java.nio.ShortBuffer}</span></th>97* <td>Get/put, compact; allocate, wrap</td></tr>98* <tr><th scope="row">{@link java.nio.ByteOrder}</th>99* <td>Typesafe enumeration for byte orders</td></tr>100* </tbody>101* </table>102*103* <p> A <i>buffer</i> is a container for a fixed amount of data of a104* specific primitive type. In addition to its content a buffer has a105* <i>position</i>, which is the index of the next element to be read106* or written, and a <i>limit</i>, which is the index of the first107* element that should not be read or written. The base {@link108* java.nio.Buffer} class defines these properties as well as methods109* for <i>clearing</i>, <i>flipping</i>, and <i>rewinding</i>, for110* <i>marking</i> the current position, and for <i>resetting</i> the111* position to the previous mark.112*113* <p> There is a buffer class for each non-boolean primitive type.114* Each class defines a family of <i>get</i> and <i>put</i> methods115* for moving data out of and in to a buffer, methods for116* <i>compacting</i>, <i>duplicating</i>, and <i>slicing</i> a buffer,117* and static methods for <i>allocating</i> a new buffer as well as118* for <i>wrapping</i> an existing array into a buffer.119*120* <p> Byte buffers are distinguished in that they can be used as the121* sources and targets of I/O operations. They also support several122* features not found in the other buffer classes:123*124* <ul>125*126* <li><p> A byte buffer can be allocated as a <a127* href="ByteBuffer.html#direct"> <i>direct</i></a> buffer, in which128* case the Java virtual machine will make a best effort to perform129* native I/O operations directly upon it. </p></li>130*131* <li><p> A byte buffer can be created by {@link132* java.nio.channels.FileChannel#map <i>mapping</i>} a region of a133* file directly into memory, in which case a few additional134* file-related operations defined in the {@link135* java.nio.MappedByteBuffer} class are available. </p></li>136*137* <li><p> A byte buffer provides access to its content as either a138* heterogeneous or homogeneous sequence of <a139* href="ByteBuffer.html#bin"><i>binary data</i></a> of any140* non-boolean primitive type, in either big-endian or little-endian141* <a href="ByteOrder.html">byte order</a>. </p></li>142*143* </ul>144*145* <p> Unless otherwise noted, passing a {@code null} argument to a146* constructor or method in any class or interface in this package147* will cause a {@link java.lang.NullPointerException148* NullPointerException} to be thrown.149*150* @since 1.4151* @author Mark Reinhold152* @author JSR-51 Expert Group153*/154package java.nio;155156157