1 /* 2 * Copyright (c) 2000, 2004, 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 overview of the 28 * 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 href="charset/package-summary.html"><i>Charsets</i></a> and their 39 * associated <i>decoders</i> and <i>encoders</i>, <br> which translate between 40 * bytes and Unicode characters; </p></li> 41 * 42 * <li><p> <a href="channels/package-summary.html"><i>Channels</i></a> of 43 * various types, which represent connections <br> to entities capable of 44 * performing I/O operations; and </p></li> 45 * 46 * <li><p> <i>Selectors</i> and <i>selection keys</i>, which together with <br> 47 * <i>selectable channels</i> define a <a 48 * href="channels/package-summary.html#multiplex">multiplexed, non-blocking <br> 49 * I/O</a> facility. </p></li> 50 * 51 * </ul> 52 * 53 * <p> The <tt>java.nio</tt> package defines the buffer classes, which are used 54 * throughout the NIO APIs. The charset API is defined in the {@link 55 * java.nio.charset} package, and the channel and selector APIs are defined in the 56 * {@link java.nio.channels} package. Each of these subpackages has its own 57 * service-provider (SPI) subpackage, the contents of which can be used to extend 58 * the platform's default implementations or to construct alternative 59 * implementations. 60 * 61 * 62 * <a name="buffers"> 63 * 64 * <blockquote><table cellspacing=1 cellpadding=0 summary="Description of the various buffers"> 65 * <tr><th><p align="left">Buffers</p></th><th><p align="left">Description</p></th></tr> 66 * <tr><td valign=top><tt>{@link java.nio.Buffer}</tt></td> 67 * <td>Position, limit, and capacity; 68 * <br>clear, flip, rewind, and mark/reset</td></tr> 69 * <tr><td valign=top><tt> {@link java.nio.ByteBuffer}</tt></td> 70 * <td>Get/put, compact, views; allocate, wrap</td></tr> 71 * <tr><td valign=top><tt> {@link java.nio.MappedByteBuffer} </tt></td> 72 * <td>A byte buffer mapped to a file</td></tr> 73 * <tr><td valign=top><tt> {@link java.nio.CharBuffer}</tt></td> 74 * <td>Get/put, compact; allocate, wrap</td></tr> 75 * <tr><td valign=top><tt> {@link java.nio.DoubleBuffer}</tt></td> 76 * <td> ' '</td></tr> 77 * <tr><td valign=top><tt> {@link java.nio.FloatBuffer}</tt></td> 78 * <td> ' '</td></tr> 79 * <tr><td valign=top><tt> {@link java.nio.IntBuffer}</tt></td> 80 * <td> ' '</td></tr> 81 * <tr><td valign=top><tt> {@link java.nio.LongBuffer}</tt></td> 82 * <td> ' '</td></tr> 83 * <tr><td valign=top><tt> {@link java.nio.ShortBuffer}</tt></td> 84 * <td> ' '</td></tr> 85 * <tr><td valign=top><tt>{@link java.nio.ByteOrder}</tt></td> 86 * <td>Typesafe enumeration for byte orders</td></tr> 87 * </table></blockquote> 88 * 89 * <p> A <i>buffer</i> is a container for a fixed amount of data of a specific 90 * primitive type. In addition to its content a buffer has a <i>position</i>, 91 * which is the index of the next element to be read or written, and a 92 * <i>limit</i>, which is the index of the first element that should not be read 93 * or written. The base {@link java.nio.Buffer} class defines these properties as 94 * well as methods for <i>clearing</i>, <i>flipping</i>, and <i>rewinding</i>, for 95 * <i>marking</i> the current position, and for <i>resetting</i> the position to 96 * the previous mark. 97 * 98 * <p> There is a buffer class for each non-boolean primitive type. Each class 99 * defines a family of <i>get</i> and <i>put</i> methods for moving data out of 100 * and in to a buffer, methods for <i>compacting</i>, <i>duplicating</i>, and 101 * <i>slicing</i> a buffer, and static methods for <i>allocating</i> a new buffer 102 * as well as for <i>wrapping</i> an existing array into a buffer. 103 * 104 * <p> Byte buffers are distinguished in that they can be used as the sources and 105 * targets of I/O operations. They also support several features not found in the 106 * other buffer classes: 107 * 108 * <ul> 109 * 110 * <li><p> A byte buffer can be allocated as a <a href="ByteBuffer.html#direct"> 111 * <i>direct</i></a> buffer, in which case the Java virtual machine will make a 112 * best effort to perform native I/O operations directly upon it. </p></li> 113 * 114 * <li><p> A byte buffer can be created by {@link 115 * java.nio.channels.FileChannel#map </code><i>mapping</i><code>} a region of a 116 * file directly into memory, in which case a few additional file-related 117 * operations defined in the {@link java.nio.MappedByteBuffer} class are 118 * available. </p></li> 119 * 120 * <li><p> A byte buffer provides access to its content as either a heterogeneous 121 * or homogeneous sequence of <a href="ByteBuffer.html#bin">binary data</i></a> 122 * of any non-boolean primitive type, in either big-endian or little-endian <a 123 * href="ByteOrder.html">byte order</a>. </p></li> 124 * 125 * </ul> 126 * 127 * <p> Unless otherwise noted, passing a <tt>null</tt> argument to a constructor 128 * or method in any class or interface in this package will cause a {@link 129 * java.lang.NullPointerException NullPointerException} to be thrown. 130 * 131 * @since 1.4 132 * @author Mark Reinhold 133 * @author JSR-51 Expert Group 134 */ 135 136 package java.nio; 137