Java Code Examples for java.nio.file.OpenOption

Following code examples demonstrate how to use java.nio.file.OpenOptionfrom java. These examples are extracted from various highly rated open source projects. You can directly use these code snippets or view their entire linked source code. These snippets are extracted to provide contextual information about how to use this class in the real world. These samples also let you understand some good practices on how to use java.nio.file.OpenOptionand various code implementation of this class.

    @Test
    public default void verifyGenericType()
    throws Exception {
        final Class<SUT> sut = createNewSUT();
        assertTrue("This j8unit test interface is used with a generic type that is illegaly not assignable to OpenOption.class!",
                   OpenOption.class.isAssignableFrom(sut));
    } 


    public OpenResourceEvent(Object source, boolean output, OpenOption... options) {
        super(source);
        this.output = output;
        this.options = options;
    } 

    public static void main(String[] args) {
        Path debugFile = Paths.get("C:\\temp\\debug.txt");
        try (OutputStream outputStream = Files.newOutputStream(
                debugFile, StandardOpenOption.CREATE, 
                StandardOpenOption.APPEND);
            PrintStream printStream = new PrintStream(outputStream, 
                    true)) {

            System.setOut(printStream);
            System.out.println("To file");

        } catch (IOException e) {
            e.printStackTrace();
        }
    } 

    public static boolean isCreateParents(OpenOption... options) {
        for (OpenOption option : options)
            if (option == CreateOption.CREATE_PARENTS)
                return true;
        return false;
    } 

    public static boolean isAppend(OpenOption... options) {
        for (OpenOption option : options)
            if (option == StandardOpenOption.APPEND)
                return true;
        return false;
    } 

    public static boolean isCreateNew(OpenOption... options) {
        for (OpenOption option : options)
            if (option == StandardOpenOption.CREATE_NEW)
                return true;
        return false;
    }