home *** CD-ROM | disk | FTP | other *** search
/ Chip 1998 November / Chip_1998-11_cd.bin / tema / Cafe / main.bin / FileDescriptor.java < prev    next >
Text File  |  1997-05-20  |  4KB  |  113 lines

  1. /*
  2.  * @(#)FileDescriptor.java    1.10 97/01/22
  3.  * 
  4.  * Copyright (c) 1995, 1996 Sun Microsystems, Inc. All Rights Reserved.
  5.  * 
  6.  * This software is the confidential and proprietary information of Sun
  7.  * Microsystems, Inc. ("Confidential Information").  You shall not
  8.  * disclose such Confidential Information and shall use it only in
  9.  * accordance with the terms of the license agreement you entered into
  10.  * with Sun.
  11.  * 
  12.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
  13.  * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  14.  * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  15.  * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES
  16.  * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
  17.  * THIS SOFTWARE OR ITS DERIVATIVES.
  18.  * 
  19.  * CopyrightVersion 1.1_beta
  20.  * 
  21.  */
  22.  
  23. package java.io;
  24.  
  25. /**
  26.  * Instances of the file descriptor class serve as an opaque handle 
  27.  * to the underlying machine-specific structure representing an open 
  28.  * file or an open socket. 
  29.  * <p>
  30.  * Applications should not create their own file descriptors. 
  31.  *
  32.  * @author  Pavani Diwanji
  33.  * @version 1.10, 01/22/97
  34.  * @see        java.io.FileInputStream
  35.  * @see        java.io.FileOutputStream
  36.  * @see     java.net.SocketInputStream
  37.  * @see     java.net.SocketOutputStream
  38.  * @since   JDK1.0
  39.  */
  40. public final class FileDescriptor {
  41.  
  42.     private int fd; 
  43.  
  44.     /**
  45.      * A handle to the standard input stream. 
  46.      *
  47.      * @since   JDK1.0
  48.      */    
  49.     public static final FileDescriptor in 
  50.     = initSystemFD(new FileDescriptor(),0);
  51.  
  52.     /**
  53.      * A handle to the standard output stream. 
  54.      *
  55.      * @since   JDK1.0
  56.      */  
  57.     public static final FileDescriptor out 
  58.     = initSystemFD(new FileDescriptor(),1);
  59.  
  60.     /**
  61.      * A handle to the standard error stream. 
  62.      *
  63.      * @since   JDK1.0
  64.      */  
  65.     public static final FileDescriptor err 
  66.     = initSystemFD(new FileDescriptor(),2);
  67.  
  68.     /**
  69.      * Tests if this file descriptor object is valid.
  70.      *
  71.      * @return  <code>true</code> if the file descriptor object represents a
  72.      *          valid, open file or socket; <code>false</code> otherwise.
  73.      * @since   JDK1.0
  74.      */
  75.     public native boolean valid();
  76.  
  77.     /**
  78.      * Force all system buffers to synchronize with the underlying
  79.      * device.  This method returns after all modified data and
  80.      * attributes of this FileDescriptor have been written to the
  81.      * relevant device(s).  In particular, if this FileDescriptor
  82.      * refers to a physical storage medium, such as a file in a file
  83.      * system, sync will not return until all in-memory modified copies
  84.      * of buffers associated with this FileDesecriptor have been
  85.      * written to the physical medium.
  86.      *
  87.      * sync is meant to be used by code that requires physical
  88.      * storage (such as a file) to be in a known state  For
  89.      * example, a class that provided a simple transaction facility
  90.      * might use sync to ensure that all changes to a file caused
  91.      * by a given transaction were recorded on a storage medium.
  92.      *
  93.      * sync only affects buffers downstream of this FileDescriptor.  If
  94.      * any in-memory buffering is being done by the application (for
  95.      * example, by a BufferedOutputStream object), those buffers must
  96.      * be flushed into the FileDescriptor (for example, by invoking
  97.      * OutputStream.flush) before that data will be affected by sync.
  98.      *
  99.      * @exception SyncFailedException
  100.      *          Thrown when the buffers cannot be flushed,
  101.      *          or because the system cannot guarantee that all the
  102.      *          buffers have been synchronized with physical media.
  103.      * @since     JDK1.1
  104.      */
  105.     public native void sync() throws SyncFailedException;
  106.  
  107.     /**
  108.      * This routine initializes in, out and err in a sytem dependent way.
  109.      */
  110.     private static native FileDescriptor initSystemFD(FileDescriptor fdObj, 
  111.     int desc);
  112. }
  113.