jdk/src/share/classes/java/nio/file/StandardOpenOption.java
changeset 2057 3acf8e5e2ca0
child 5506 202f599c92aa
equal deleted inserted replaced
2056:115e09b7a004 2057:3acf8e5e2ca0
       
     1 /*
       
     2  * Copyright 2007-2009 Sun Microsystems, Inc.  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.  Sun designates this
       
     8  * particular file as subject to the "Classpath" exception as provided
       
     9  * by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
       
    22  * CA 95054 USA or visit www.sun.com if you need additional information or
       
    23  * have any questions.
       
    24  */
       
    25 
       
    26 package java.nio.file;
       
    27 
       
    28 /**
       
    29  * Defines the standard open options.
       
    30  *
       
    31  * @since 1.7
       
    32  */
       
    33 
       
    34 public enum StandardOpenOption implements OpenOption {
       
    35     /**
       
    36      * Open for read access.
       
    37      */
       
    38     READ,
       
    39 
       
    40     /**
       
    41      * Open for write access.
       
    42      */
       
    43     WRITE,
       
    44 
       
    45     /**
       
    46      * If the file is opened for {@link #WRITE} access then bytes will be written
       
    47      * to the end of the file rather than the beginning.
       
    48      *
       
    49      * <p> If the file is opened for write access by other programs, then it
       
    50      * is file system specific if writing to the end of the file is atomic.
       
    51      */
       
    52     APPEND,
       
    53 
       
    54     /**
       
    55      * If the file already exists and it is opened for {@link #WRITE}
       
    56      * access, then its length is truncated to 0. This option is ignored
       
    57      * if the file is opened only for {@link #READ} access.
       
    58      */
       
    59     TRUNCATE_EXISTING,
       
    60 
       
    61     /**
       
    62      * Create a new file if it does not exist.
       
    63      * This option is ignored if the {@link #CREATE_NEW} option is also set.
       
    64      * The check for the existence of the file and the creation of the file
       
    65      * if it does not exist is atomic with respect to other file system
       
    66      * operations.
       
    67      */
       
    68     CREATE,
       
    69 
       
    70     /**
       
    71      * Create a new file, failing if the file already exists.
       
    72      * The check for the existence of the file and the creation of the file
       
    73      * if it does not exist is atomic with respect to other file system
       
    74      * operations.
       
    75      */
       
    76     CREATE_NEW,
       
    77 
       
    78     /**
       
    79      * Delete on close. When this option is present then the implementation
       
    80      * makes a <em>best effort</em> attempt to delete the file when closed
       
    81      * by the appropriate {@code close} method. If the {@code close} method is
       
    82      * not invoked then a <em>best effort</em> attempt is made to delete the
       
    83      * file when the Java virtual machine terminates (either normally, as
       
    84      * defined by the Java Language Specification, or where possible, abnormally).
       
    85      * This option is primarily intended for use with <em>work files</em> that
       
    86      * are used solely by a single instance of the Java virtual machine. This
       
    87      * option is not recommended for use when opening files that are open
       
    88      * concurrently by other entities. Many of the details as to when and how
       
    89      * the file is deleted are implementation specific and therefore not
       
    90      * specified. In particular, an implementation may be unable to guarantee
       
    91      * that it deletes the expected file when replaced by an attacker while the
       
    92      * file is open. Consequently, security sensitive applications should take
       
    93      * care when using this option.
       
    94      *
       
    95      * <p> For security reasons, this option may imply the {@link
       
    96      * LinkOption#NOFOLLOW_LINKS} option. In other words, if the option is present
       
    97      * when opening an existing file that is a symbolic link then it may fail
       
    98      * (by throwing {@link java.io.IOException}).
       
    99      */
       
   100     DELETE_ON_CLOSE,
       
   101 
       
   102     /**
       
   103      * Sparse file. When used with the {@link #CREATE_NEW} option then this
       
   104      * option provides a <em>hint</em> that the new file will be sparse. The
       
   105      * option is ignored when the file system does not support the creation of
       
   106      * sparse files.
       
   107      */
       
   108     SPARSE,
       
   109 
       
   110     /**
       
   111      * Requires that every update to the file's content or metadata be written
       
   112      * synchronously to the underlying storage device.
       
   113      *
       
   114      * @see <a href="package-summary.html#integrity">Synchronized I/O file integrity</a>
       
   115      */
       
   116     SYNC,
       
   117 
       
   118     /**
       
   119      * Requires that every update to the file's content be written
       
   120      * synchronously to the underlying storage device.
       
   121      *
       
   122      * @see <a href="package-summary.html#integrity">Synchronized I/O file integrity</a>
       
   123      */
       
   124     DSYNC;
       
   125 }