1 /*
   2  * Copyright (c) 2018, 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 package jdk.internal.misc;
  27 
  28 import sun.nio.fs.ExtendedOptions;
  29 
  30 import java.nio.file.CopyOption;
  31 import java.nio.file.OpenOption;
  32 import java.nio.file.WatchEvent;
  33 
  34 /**
  35  * Internal file system options for jdk.unsupported com.sun.nio.file API use.
  36  */
  37 public final class FileSystemOption<T> {
  38     public static final FileSystemOption<Void> INTERRUPTIBLE =
  39         new FileSystemOption<>(ExtendedOptions.INTERRUPTIBLE);
  40     public static final FileSystemOption<Void> NOSHARE_READ =
  41         new FileSystemOption<>(ExtendedOptions.NOSHARE_READ);
  42     public static final FileSystemOption<Void> NOSHARE_WRITE =
  43         new FileSystemOption<>(ExtendedOptions.NOSHARE_WRITE);
  44     public static final FileSystemOption<Void> NOSHARE_DELETE =
  45         new FileSystemOption<>(ExtendedOptions.NOSHARE_DELETE);
  46     public static final FileSystemOption<Void> FILE_TREE =
  47         new FileSystemOption<>(ExtendedOptions.FILE_TREE);
  48     public static final FileSystemOption<Void> DIRECT =
  49         new FileSystemOption<>(ExtendedOptions.DIRECT);
  50     public static final FileSystemOption<Integer> SENSITIVITY_HIGH =
  51         new FileSystemOption<>(ExtendedOptions.SENSITIVITY_HIGH);
  52     public static final FileSystemOption<Integer> SENSITIVITY_MEDIUM =
  53         new FileSystemOption<>(ExtendedOptions.SENSITIVITY_MEDIUM);
  54     public static final FileSystemOption<Integer> SENSITIVITY_LOW =
  55         new FileSystemOption<>(ExtendedOptions.SENSITIVITY_LOW);
  56 
  57     private final ExtendedOptions.InternalOption<T> internalOption;
  58     private FileSystemOption(ExtendedOptions.InternalOption<T> option) {
  59         this.internalOption = option;
  60     }
  61 
  62     /**
  63      * Register this internal option as an OpenOption.
  64      */
  65     public void register(OpenOption option) {
  66         internalOption.register(option);
  67     }
  68 
  69     /**
  70      * Register this internal option as a CopyOption.
  71      */
  72     public void register(CopyOption option) {
  73         internalOption.register(option);
  74     }
  75 
  76     /**
  77      * Register this internal option as a WatchEvent.Modifier.
  78      */
  79     public void register(WatchEvent.Modifier option) {
  80         internalOption.register(option);
  81     }
  82 
  83     /**
  84      * Register this internal option as a WatchEvent.Modifier with the
  85      * given parameter.
  86      */
  87     public void register(WatchEvent.Modifier option, T param) {
  88         internalOption.register(option, param);
  89     }
  90 }