src/java.base/unix/classes/java/io/FileDescriptor.java

Print this page




  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 package java.io;
  27 
  28 import java.util.ArrayList;
  29 import java.util.List;


  30 
  31 /**
  32  * Instances of the file descriptor class serve as an opaque handle
  33  * to the underlying machine-specific structure representing an open
  34  * file, an open socket, or another source or sink of bytes. The
  35  * main practical use for a file descriptor is to create a
  36  * <code>FileInputStream</code> or <code>FileOutputStream</code> to
  37  * contain it.
  38  * <p>
  39  * Applications should not create their own file descriptors.
  40  *
  41  * @author  Pavani Diwanji
  42  * @see     java.io.FileInputStream
  43  * @see     java.io.FileOutputStream
  44  * @since   1.0
  45  */
  46 public final class FileDescriptor {
  47 
  48     private int fd;
  49 


 128      * be flushed into the FileDescriptor (for example, by invoking
 129      * OutputStream.flush) before that data will be affected by sync.
 130      *
 131      * @exception SyncFailedException
 132      *        Thrown when the buffers cannot be flushed,
 133      *        or because the system cannot guarantee that all the
 134      *        buffers have been synchronized with physical media.
 135      * @since     1.1
 136      */
 137     public native void sync() throws SyncFailedException;
 138 
 139     /* This routine initializes JNI field offsets for the class */
 140     private static native void initIDs();
 141 
 142     static {
 143         initIDs();
 144     }
 145 
 146     // Set up JavaIOFileDescriptorAccess in SharedSecrets
 147     static {
 148         sun.misc.SharedSecrets.setJavaIOFileDescriptorAccess(
 149             new sun.misc.JavaIOFileDescriptorAccess() {
 150                 public void set(FileDescriptor obj, int fd) {
 151                     obj.fd = fd;
 152                 }
 153 
 154                 public int get(FileDescriptor obj) {
 155                     return obj.fd;
 156                 }
 157 
 158                 public void setAppend(FileDescriptor obj, boolean append) {
 159                     obj.append = append;
 160                 }
 161 
 162                 public boolean getAppend(FileDescriptor obj) {
 163                     return obj.append;
 164                 }
 165 
 166                 public void setHandle(FileDescriptor obj, long handle) {
 167                     throw new UnsupportedOperationException();
 168                 }
 169 




  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 package java.io;
  27 
  28 import java.util.ArrayList;
  29 import java.util.List;
  30 import jdk.internal.misc.JavaIOFileDescriptorAccess;
  31 import jdk.internal.misc.SharedSecrets;
  32 
  33 /**
  34  * Instances of the file descriptor class serve as an opaque handle
  35  * to the underlying machine-specific structure representing an open
  36  * file, an open socket, or another source or sink of bytes. The
  37  * main practical use for a file descriptor is to create a
  38  * <code>FileInputStream</code> or <code>FileOutputStream</code> to
  39  * contain it.
  40  * <p>
  41  * Applications should not create their own file descriptors.
  42  *
  43  * @author  Pavani Diwanji
  44  * @see     java.io.FileInputStream
  45  * @see     java.io.FileOutputStream
  46  * @since   1.0
  47  */
  48 public final class FileDescriptor {
  49 
  50     private int fd;
  51 


 130      * be flushed into the FileDescriptor (for example, by invoking
 131      * OutputStream.flush) before that data will be affected by sync.
 132      *
 133      * @exception SyncFailedException
 134      *        Thrown when the buffers cannot be flushed,
 135      *        or because the system cannot guarantee that all the
 136      *        buffers have been synchronized with physical media.
 137      * @since     1.1
 138      */
 139     public native void sync() throws SyncFailedException;
 140 
 141     /* This routine initializes JNI field offsets for the class */
 142     private static native void initIDs();
 143 
 144     static {
 145         initIDs();
 146     }
 147 
 148     // Set up JavaIOFileDescriptorAccess in SharedSecrets
 149     static {
 150         SharedSecrets.setJavaIOFileDescriptorAccess(
 151             new JavaIOFileDescriptorAccess() {
 152                 public void set(FileDescriptor obj, int fd) {
 153                     obj.fd = fd;
 154                 }
 155 
 156                 public int get(FileDescriptor obj) {
 157                     return obj.fd;
 158                 }
 159 
 160                 public void setAppend(FileDescriptor obj, boolean append) {
 161                     obj.append = append;
 162                 }
 163 
 164                 public boolean getAppend(FileDescriptor obj) {
 165                     return obj.append;
 166                 }
 167 
 168                 public void setHandle(FileDescriptor obj, long handle) {
 169                     throw new UnsupportedOperationException();
 170                 }
 171