home *** CD-ROM | disk | FTP | other *** search
/ Java 1.2 How-To / JavaHowTo.iso / 3rdParty / jbuilder / unsupported / JDK1.2beta3 / SOURCE / SRC.ZIP / java / io / FileDescriptor.java < prev    next >
Encoding:
Java Source  |  1998-03-20  |  3.5 KB  |  110 lines

  1. /*
  2.  * @(#)FileDescriptor.java    1.13 98/03/18
  3.  *
  4.  * Copyright 1995-1997 by Sun Microsystems, Inc.,
  5.  * 901 San Antonio Road, Palo Alto, California, 94303, U.S.A.
  6.  * All rights reserved.
  7.  *
  8.  * This software is the confidential and proprietary information
  9.  * of Sun Microsystems, Inc. ("Confidential Information").  You
  10.  * shall not disclose such Confidential Information and shall use
  11.  * it only in accordance with the terms of the license agreement
  12.  * you entered into with Sun.
  13.  */
  14.  
  15. package java.io;
  16.  
  17. /**
  18.  * Instances of the file descriptor class serve as an opaque handle 
  19.  * to the underlying machine-specific structure representing an open 
  20.  * file or an open socket. 
  21.  * <p>
  22.  * Applications should not create their own file descriptors. 
  23.  *
  24.  * @author  Pavani Diwanji
  25.  * @version 1.13, 03/18/98
  26.  * @see        java.io.FileInputStream
  27.  * @see        java.io.FileOutputStream
  28.  * @see     java.net.SocketInputStream
  29.  * @see     java.net.SocketOutputStream
  30.  * @since   JDK1.0
  31.  */
  32. public final class FileDescriptor {
  33.  
  34.     private int fd; 
  35.  
  36.     /**
  37.      * Constructs an (invalid) FileDescriptor
  38.      * object.
  39.      */
  40.     public /**/ FileDescriptor() {
  41.     fd = -1;
  42.     }
  43.  
  44.     private /* */ FileDescriptor(int fd) {
  45.     this.fd = fd;
  46.     }
  47.  
  48.     /**
  49.      * A handle to the standard input stream. 
  50.      */    
  51.     public static final FileDescriptor in = new FileDescriptor(0);
  52.  
  53.     /**
  54.      * A handle to the standard output stream. 
  55.      */  
  56.     public static final FileDescriptor out = new FileDescriptor(1);
  57.  
  58.     /**
  59.      * A handle to the standard error stream. 
  60.      */  
  61.     public static final FileDescriptor err = new FileDescriptor(2);
  62.  
  63.     /**
  64.      * Tests if this file descriptor object is valid.
  65.      *
  66.      * @return  <code>true</code> if the file descriptor object represents a
  67.      *          valid, open file or socket; <code>false</code> otherwise.
  68.      */
  69.     public boolean valid() {
  70.     return fd != -1;
  71.     }
  72.  
  73.     /**
  74.      * Force all system buffers to synchronize with the underlying
  75.      * device.  This method returns after all modified data and
  76.      * attributes of this FileDescriptor have been written to the
  77.      * relevant device(s).  In particular, if this FileDescriptor
  78.      * refers to a physical storage medium, such as a file in a file
  79.      * system, sync will not return until all in-memory modified copies
  80.      * of buffers associated with this FileDesecriptor have been
  81.      * written to the physical medium.
  82.      *
  83.      * sync is meant to be used by code that requires physical
  84.      * storage (such as a file) to be in a known state  For
  85.      * example, a class that provided a simple transaction facility
  86.      * might use sync to ensure that all changes to a file caused
  87.      * by a given transaction were recorded on a storage medium.
  88.      *
  89.      * sync only affects buffers downstream of this FileDescriptor.  If
  90.      * any in-memory buffering is being done by the application (for
  91.      * example, by a BufferedOutputStream object), those buffers must
  92.      * be flushed into the FileDescriptor (for example, by invoking
  93.      * OutputStream.flush) before that data will be affected by sync.
  94.      *
  95.      * @exception SyncFailedException
  96.      *          Thrown when the buffers cannot be flushed,
  97.      *          or because the system cannot guarantee that all the
  98.      *          buffers have been synchronized with physical media.
  99.      * @since     JDK1.1
  100.      */
  101.     public native void sync() throws SyncFailedException;
  102.  
  103.     /* This routine initializes JNI field offsets for the class */
  104.     private static native void initIDs();
  105.  
  106.     static {
  107.     initIDs();
  108.     }
  109. }
  110.