Java Code Examples for java.nio.file.LinkOption#NOFOLLOW_LINKS

The following examples show how to use java.nio.file.LinkOption#NOFOLLOW_LINKS . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SymbolicLinkTest.java    From p4ic4idea with Apache License 2.0 6 votes vote down vote up
/**
 * Check target file is a symbolic link.
 */
private void checkWorkspaceState(List<IFileSpec> files, int expectedNoOfMessages) throws P4JavaException {
	// check that both files are synced
	assertEquals(expectedNoOfMessages, files.size());

	for (IFileSpec file : files) {
		assertTrue(!file.getOpStatus().toString().equals("ERROR"));
	}

	// Read the target path of the symbolic link and verify the symbolic link has the correct target path
	GetExtendedFilesOptions extendedFilesOptions = new GetExtendedFilesOptions();
	List<IExtendedFileSpec> extendedFiles = server.getExtendedFiles(files, extendedFilesOptions);
	assertNotNull(extendedFiles);
	for (IExtendedFileSpec extendedFileSpec : extendedFiles) {
		Path path = Paths.get(extendedFileSpec.getClientPathString());
		LinkOption linkOption = LinkOption.NOFOLLOW_LINKS;
		assertTrue(Files.exists(path, linkOption));
		if (extendedFileSpec.getHeadType().toLowerCase().contains("symlink")) {
			assertTrue(SymbolicLinkHelper.isSymbolicLink(path.toString()));

		} else {
			assertTrue(!SymbolicLinkHelper.isSymbolicLink(path.toString()));
		}
	}
}
 
Example 2
Source File: SymbolicLinkTest.java    From p4ic4idea with Apache License 2.0 6 votes vote down vote up
/**
 * Check target file is a symbolic link.
 */
private void checkWorkspaceState(List<IFileSpec> files, int expectedNoOfMessages) throws P4JavaException {
	// check that both files are synced
	assertEquals(expectedNoOfMessages, files.size());

	for (IFileSpec file : files) {
		assertTrue(!file.getOpStatus().toString().equals("ERROR"));
	}

	// Read the target path of the symbolic link and verify the symbolic link has the correct target path
	GetExtendedFilesOptions extendedFilesOptions = new GetExtendedFilesOptions();
	List<IExtendedFileSpec> extendedFiles = server.getExtendedFiles(files, extendedFilesOptions);
	assertNotNull(extendedFiles);
	for (IExtendedFileSpec extendedFileSpec : extendedFiles) {
		Path path = Paths.get(extendedFileSpec.getClientPathString());
		LinkOption linkOption = LinkOption.NOFOLLOW_LINKS;
		assertTrue(Files.exists(path, linkOption));
		if (extendedFileSpec.getHeadType().toLowerCase().contains("symlink")) {
			assertTrue(SymbolicLinkHelper.isSymbolicLink(path.toString()));

		} else {
			assertTrue(!SymbolicLinkHelper.isSymbolicLink(path.toString()));
		}
	}
}
 
Example 3
Source File: SymbolicLinkReconcileTest.java    From p4ic4idea with Apache License 2.0 5 votes vote down vote up
@Test
public void testSyncSymlinksAndReconcileWorkspaceWithoutChanges() throws Exception {

	List<IFileSpec> files = null;

	client.sync(FileSpecBuilder.makeFileSpecList(depotTestPath),new SyncOptions().setForceUpdate(true));
	// Reconcile files
	for (int i = 0; i < 10; i++) {
		files = client.reconcileFiles(
				FileSpecBuilder.makeFileSpecList(depotTestPath),
				new ReconcileFilesOptions().setUpdateWorkspace(true));
		assertNotNull(files);
		assertTrue(files.get(0).getStatusMessage().contains("//depot/symlinks/... - no file(s) to reconcile."));
	}

	// Check target file id a symbolic link
	// Read the target path of the symbolic link
	// Verify the symbolic link has the correct target path
	GetExtendedFilesOptions extendedFilesOptions = new GetExtendedFilesOptions();
	List<IExtendedFileSpec> extendedFiles = server.getExtendedFiles(FileSpecBuilder.makeFileSpecList(depotTestPath), extendedFilesOptions);
	assertNotNull(extendedFiles);

	for (IExtendedFileSpec extendedFileSpec : extendedFiles) {
		Path path = Paths.get(extendedFileSpec.getClientPathString());
		LinkOption linkOption = LinkOption.NOFOLLOW_LINKS;
		assertTrue(Files.exists(path, linkOption));
		if (extendedFileSpec.getHeadType().toLowerCase().contains("symlink")) {
			assertTrue(SymbolicLinkHelper.isSymbolicLink(path.toString()));
		} else {
			assertTrue(!SymbolicLinkHelper.isSymbolicLink(path.toString()));
		}
	}
}
 
Example 4
Source File: SymbolicLinkReconcileTest.java    From p4ic4idea with Apache License 2.0 5 votes vote down vote up
@Test
public void testSyncSymlinksAndReconcileWithoutChanges() throws Exception {
	List<IFileSpec> files = null;
	ReconcileFilesOptions recOpts = new ReconcileFilesOptions();
	recOpts.setOutsideEdit(true);
	recOpts.setOutsideAdd(true);
	recOpts.setUseWildcards(true);

	// Reconcile files
	for (int i = 0; i < 10; i++) {
		files = client.reconcileFiles(
				FileSpecBuilder.makeFileSpecList(depotTestPath),
				recOpts);
		assertNotNull(files);
		assertTrue(files.get(0).getStatusMessage().contains("//depot/symlinks/... - no file(s) to reconcile."));
	}

	// Check target file is a symbolic link
	// Read the target path of the symbolic link
	// Verify the symbolic link has the correct target path
	GetExtendedFilesOptions extendedFilesOptions = new GetExtendedFilesOptions();
	List<IExtendedFileSpec> extendedFiles = server.getExtendedFiles(FileSpecBuilder.makeFileSpecList(depotTestPath), extendedFilesOptions);
	assertNotNull(extendedFiles);

	for (IExtendedFileSpec extendedFileSpec : extendedFiles) {
		Path path = Paths.get(extendedFileSpec.getClientPathString());
		LinkOption linkOption = LinkOption.NOFOLLOW_LINKS;
		assertTrue(Files.exists(path, linkOption));
		if (extendedFileSpec.getHeadType().toLowerCase().contains("symlink")) {
			assertTrue(SymbolicLinkHelper.isSymbolicLink(path.toString()));
		} else {
			assertTrue(!SymbolicLinkHelper.isSymbolicLink(path.toString()));
		}
	}

}
 
Example 5
Source File: CopyMoveVisitor.java    From copybara with Apache License 2.0 5 votes vote down vote up
CopyMoveVisitor(Path before, Path after, @Nullable PathMatcher pathMatcher, boolean overwrite, boolean isCopy) {
  this.before = before;
  this.after = after;
  this.pathMatcher = pathMatcher;
  this.isCopy = isCopy;
  if (overwrite) {
    moveMode = new CopyOption[]{LinkOption.NOFOLLOW_LINKS, StandardCopyOption.REPLACE_EXISTING};
  } else {
    moveMode = new CopyOption[]{LinkOption.NOFOLLOW_LINKS};
  }
}
 
Example 6
Source File: SymbolicLinkReconcileTest.java    From p4ic4idea with Apache License 2.0 5 votes vote down vote up
@Test
public void testSyncSymlinksAndReconcileWorkspaceWithoutChanges() throws Exception {

	List<IFileSpec> files = null;

	client.sync(FileSpecBuilder.makeFileSpecList(depotTestPath),new SyncOptions().setForceUpdate(true));
	// Reconcile files
	for (int i = 0; i < 10; i++) {
		files = client.reconcileFiles(
				FileSpecBuilder.makeFileSpecList(depotTestPath),
				new ReconcileFilesOptions().setUpdateWorkspace(true));
		assertNotNull(files);
		// p4ic4idea: IServerMessage
		assertTrue(files.get(0).getStatusMessage().hasMessageFragment("//depot/symlinks/... - no file(s) to reconcile."));
	}

	// Check target file id a symbolic link
	// Read the target path of the symbolic link
	// Verify the symbolic link has the correct target path
	GetExtendedFilesOptions extendedFilesOptions = new GetExtendedFilesOptions();
	List<IExtendedFileSpec> extendedFiles = server.getExtendedFiles(FileSpecBuilder.makeFileSpecList(depotTestPath), extendedFilesOptions);
	assertNotNull(extendedFiles);

	for (IExtendedFileSpec extendedFileSpec : extendedFiles) {
		Path path = Paths.get(extendedFileSpec.getClientPathString());
		LinkOption linkOption = LinkOption.NOFOLLOW_LINKS;
		assertTrue(Files.exists(path, linkOption));
		if (extendedFileSpec.getHeadType().toLowerCase().contains("symlink")) {
			assertTrue(SymbolicLinkHelper.isSymbolicLink(path.toString()));
		} else {
			assertTrue(!SymbolicLinkHelper.isSymbolicLink(path.toString()));
		}
	}
}
 
Example 7
Source File: UnixCopyFile.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
static Flags fromMoveOptions(CopyOption... options) {
    Flags flags = new Flags();
    for (CopyOption option: options) {
        if (option == StandardCopyOption.ATOMIC_MOVE) {
            flags.atomicMove = true;
            continue;
        }
        if (option == StandardCopyOption.REPLACE_EXISTING) {
            flags.replaceExisting = true;
            continue;
        }
        if (option == LinkOption.NOFOLLOW_LINKS) {
            // ignore
            continue;
        }
        if (option == null)
            throw new NullPointerException();
        throw new UnsupportedOperationException("Unsupported copy option");
    }

    // a move requires that all attributes be copied but only fail if
    // the basic attributes cannot be copied
    flags.copyBasicAttributes = true;
    flags.copyPosixAttributes = true;
    flags.copyNonPosixAttributes = true;
    flags.failIfUnableToCopyBasic = true;
    return flags;
}
 
Example 8
Source File: UnixCopyFile.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
static Flags fromCopyOptions(CopyOption... options) {
    Flags flags = new Flags();
    flags.followLinks = true;
    for (CopyOption option: options) {
        if (option == StandardCopyOption.REPLACE_EXISTING) {
            flags.replaceExisting = true;
            continue;
        }
        if (option == LinkOption.NOFOLLOW_LINKS) {
            flags.followLinks = false;
            continue;
        }
        if (option == StandardCopyOption.COPY_ATTRIBUTES) {
            // copy all attributes but only fail if basic attributes
            // cannot be copied
            flags.copyBasicAttributes = true;
            flags.copyPosixAttributes = true;
            flags.copyNonPosixAttributes = true;
            flags.failIfUnableToCopyBasic = true;
            continue;
        }
        if (ExtendedOptions.INTERRUPTIBLE.matches(option)) {
            flags.interruptible = true;
            continue;
        }
        if (option == null)
            throw new NullPointerException();
        throw new UnsupportedOperationException("Unsupported copy option");
    }
    return flags;
}
 
Example 9
Source File: JrtFileSystem.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
static boolean followLinks(LinkOption... options) {
    if (options != null) {
        for (LinkOption lo : options) {
            Objects.requireNonNull(lo);
            if (lo == LinkOption.NOFOLLOW_LINKS) {
                return false;
            } else {
                throw new AssertionError("should not reach here");
            }
        }
    }
    return true;
}
 
Example 10
Source File: JrtFileSystem.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
static boolean followLinks(LinkOption... options) {
    if (options != null) {
        for (LinkOption lo : options) {
            Objects.requireNonNull(lo);
            if (lo == LinkOption.NOFOLLOW_LINKS) {
                return false;
            } else {
                throw new AssertionError("should not reach here");
            }
        }
    }
    return true;
}
 
Example 11
Source File: WindowsChannelFactory.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
static Flags toFlags(Set<? extends OpenOption> options) {
    Flags flags = new Flags();
    for (OpenOption option: options) {
        if (option instanceof StandardOpenOption) {
            switch ((StandardOpenOption)option) {
                case READ : flags.read = true; break;
                case WRITE : flags.write = true; break;
                case APPEND : flags.append = true; break;
                case TRUNCATE_EXISTING : flags.truncateExisting = true; break;
                case CREATE : flags.create = true; break;
                case CREATE_NEW : flags.createNew = true; break;
                case DELETE_ON_CLOSE : flags.deleteOnClose = true; break;
                case SPARSE : flags.sparse = true; break;
                case SYNC : flags.sync = true; break;
                case DSYNC : flags.dsync = true; break;
                default: throw new UnsupportedOperationException();
            }
            continue;
        }
        if (option == LinkOption.NOFOLLOW_LINKS) {
            flags.noFollowLinks = true;
            continue;
        }
        if (option == OPEN_REPARSE_POINT) {
            flags.openReparsePoint = true;
            continue;
        }
        if (ExtendedOptions.NOSHARE_READ.matches(option)) {
            flags.shareRead = false;
            continue;
        }
        if (ExtendedOptions.NOSHARE_WRITE.matches(option)) {
            flags.shareWrite = false;
            continue;
        }
        if (ExtendedOptions.NOSHARE_DELETE.matches(option)) {
            flags.shareDelete = false;
            continue;
        }
        if (option == null)
            throw new NullPointerException();
        throw new UnsupportedOperationException();
    }
    return flags;
}
 
Example 12
Source File: CopyOptions.java    From sftp-fs with Apache License 2.0 4 votes vote down vote up
private static boolean isIgnoredCopyOption(CopyOption option) {
    return option == LinkOption.NOFOLLOW_LINKS;
}
 
Example 13
Source File: SymbolicLinkSyncTest.java    From p4ic4idea with Apache License 2.0 4 votes vote down vote up
/**
 * Test symlink support - sync command. This only works with JDK 7 or above
 * and non-Windows environment.
 */
@Test
public void testSyncSymlinks() {

    String[] repoPaths = new String[]{
            "//depot/symlinks/testdira/testdir2/...",
            "//depot/symlinks/testdira/testdirb/testfile.txt",
            "//depot/symlinks/testdira/testdir2"};

    try {

        List<IFileSpec> files = client.sync(
                FileSpecBuilder.makeFileSpecList(repoPaths),
                new SyncOptions().setForceUpdate(true));
        assertNotNull(files);

        // Check target file id a symbolic link
        // Read the target path of the symbolic link
        // Verify the symbolic link has the correct target path
        GetExtendedFilesOptions extendedFilesOptions = new GetExtendedFilesOptions();
        List<IExtendedFileSpec> extendedFiles = server.getExtendedFiles(files, extendedFilesOptions);
        assertNotNull(extendedFiles);

        for (IExtendedFileSpec extendedFileSpec: extendedFiles) {
            Path path = Paths.get(extendedFileSpec.getClientPathString());
            LinkOption linkOption = LinkOption.NOFOLLOW_LINKS;
            assertTrue(Files.exists(path, linkOption));
            if (Files.isDirectory(path, linkOption)) {
                //do nothing as currently checkpoint contains files within a symlink directory, which is not supported and causes the directory symlink check to fail.
            }
            else if (extendedFileSpec.getHeadType().toLowerCase().contains("symlink")) {
                assertTrue(SymbolicLinkHelper.isSymbolicLink(path.toString()));

            }
            else {
                assertTrue(!SymbolicLinkHelper.isSymbolicLink(path.toString()));
            }
        }
    } catch (Exception exc) {
        fail("Unexpected exception: " + exc.getLocalizedMessage());
    }
}
 
Example 14
Source File: WindowsChannelFactory.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
static Flags toFlags(Set<? extends OpenOption> options) {
    Flags flags = new Flags();
    for (OpenOption option: options) {
        if (option instanceof StandardOpenOption) {
            switch ((StandardOpenOption)option) {
                case READ : flags.read = true; break;
                case WRITE : flags.write = true; break;
                case APPEND : flags.append = true; break;
                case TRUNCATE_EXISTING : flags.truncateExisting = true; break;
                case CREATE : flags.create = true; break;
                case CREATE_NEW : flags.createNew = true; break;
                case DELETE_ON_CLOSE : flags.deleteOnClose = true; break;
                case SPARSE : flags.sparse = true; break;
                case SYNC : flags.sync = true; break;
                case DSYNC : flags.dsync = true; break;
                default: throw new UnsupportedOperationException();
            }
            continue;
        }
        if (option instanceof ExtendedOpenOption) {
            switch ((ExtendedOpenOption)option) {
                case NOSHARE_READ : flags.shareRead = false; break;
                case NOSHARE_WRITE : flags.shareWrite = false; break;
                case NOSHARE_DELETE : flags.shareDelete = false; break;
                default: throw new UnsupportedOperationException();
            }
            continue;
        }
        if (option == LinkOption.NOFOLLOW_LINKS) {
            flags.noFollowLinks = true;
            continue;
        }
        if (option == OPEN_REPARSE_POINT) {
            flags.openReparsePoint = true;
            continue;
        }
        if (option == null)
            throw new NullPointerException();
        throw new UnsupportedOperationException();
    }
    return flags;
}
 
Example 15
Source File: WindowsChannelFactory.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
static Flags toFlags(Set<? extends OpenOption> options) {
    Flags flags = new Flags();
    for (OpenOption option: options) {
        if (option instanceof StandardOpenOption) {
            switch ((StandardOpenOption)option) {
                case READ : flags.read = true; break;
                case WRITE : flags.write = true; break;
                case APPEND : flags.append = true; break;
                case TRUNCATE_EXISTING : flags.truncateExisting = true; break;
                case CREATE : flags.create = true; break;
                case CREATE_NEW : flags.createNew = true; break;
                case DELETE_ON_CLOSE : flags.deleteOnClose = true; break;
                case SPARSE : flags.sparse = true; break;
                case SYNC : flags.sync = true; break;
                case DSYNC : flags.dsync = true; break;
                default: throw new UnsupportedOperationException();
            }
            continue;
        }
        if (option instanceof ExtendedOpenOption) {
            switch ((ExtendedOpenOption)option) {
                case NOSHARE_READ : flags.shareRead = false; break;
                case NOSHARE_WRITE : flags.shareWrite = false; break;
                case NOSHARE_DELETE : flags.shareDelete = false; break;
                default: throw new UnsupportedOperationException();
            }
            continue;
        }
        if (option == LinkOption.NOFOLLOW_LINKS) {
            flags.noFollowLinks = true;
            continue;
        }
        if (option == OPEN_REPARSE_POINT) {
            flags.openReparsePoint = true;
            continue;
        }
        if (option == null)
            throw new NullPointerException();
        throw new UnsupportedOperationException();
    }
    return flags;
}
 
Example 16
Source File: WindowsChannelFactory.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
static Flags toFlags(Set<? extends OpenOption> options) {
    Flags flags = new Flags();
    for (OpenOption option: options) {
        if (option instanceof StandardOpenOption) {
            switch ((StandardOpenOption)option) {
                case READ : flags.read = true; break;
                case WRITE : flags.write = true; break;
                case APPEND : flags.append = true; break;
                case TRUNCATE_EXISTING : flags.truncateExisting = true; break;
                case CREATE : flags.create = true; break;
                case CREATE_NEW : flags.createNew = true; break;
                case DELETE_ON_CLOSE : flags.deleteOnClose = true; break;
                case SPARSE : flags.sparse = true; break;
                case SYNC : flags.sync = true; break;
                case DSYNC : flags.dsync = true; break;
                default: throw new UnsupportedOperationException();
            }
            continue;
        }
        if (option instanceof ExtendedOpenOption) {
            switch ((ExtendedOpenOption)option) {
                case NOSHARE_READ : flags.shareRead = false; break;
                case NOSHARE_WRITE : flags.shareWrite = false; break;
                case NOSHARE_DELETE : flags.shareDelete = false; break;
                default: throw new UnsupportedOperationException();
            }
            continue;
        }
        if (option == LinkOption.NOFOLLOW_LINKS) {
            flags.noFollowLinks = true;
            continue;
        }
        if (option == OPEN_REPARSE_POINT) {
            flags.openReparsePoint = true;
            continue;
        }
        if (option == null)
            throw new NullPointerException();
        throw new UnsupportedOperationException();
    }
    return flags;
}
 
Example 17
Source File: SymbolicLinkReconcileTest.java    From p4ic4idea with Apache License 2.0 4 votes vote down vote up
/**
 * @BeforeClass annotation to a method to be run before all the tests in a class.
 */
@BeforeClass
public static void setUp() throws Exception {
	setupServer(p4d.getRSHURL(), userName, password, true, null);
	assertNotNull(server);
	client = createClient(server, clientName);
	assertNotNull(client);

	String target = client.getRoot() + targetFilePath;
	String link = client.getRoot() + linkPath;

	// Create target file
	createFileOnDisk(target);

	// Create symbolic link
	String path = SymbolicLinkHelper.createSymbolicLink(link, target);

	boolean isSymlink = SymbolicLinkHelper.isSymbolicLink(path);
	assertTrue(isSymlink);

	// Create changelist
	IChangelist changelist = getNewChangelist(server,
			client,
			"add symbolic link.");
	assertNotNull(changelist);
	changelist = client.createChangelist(changelist);
	assertNotNull(changelist);

	// Add a file specified as "binary" even though it is "text"
	List<IFileSpec> files = client.addFiles(
			FileSpecBuilder.makeFileSpecList(link, target),
			new AddFilesOptions().setChangelistId(changelist.getId()));
	assertNotNull(files);

	changelist.refresh();
	files = changelist.submit(new SubmitOptions());
	assertNotNull(files);

	// Check target file id a symbolic link
	// Read the target path of the symbolic link
	// Verify the symbolic link has the correct target path
	GetExtendedFilesOptions extendedFilesOptions = new GetExtendedFilesOptions();
	List<IExtendedFileSpec> extendedFiles = server.getExtendedFiles(files, extendedFilesOptions);
	assertNotNull(extendedFiles);

	for (IExtendedFileSpec ifs : extendedFiles) {
		Path p = Paths.get(ifs.getClientPathString());
		LinkOption lo = LinkOption.NOFOLLOW_LINKS;
		assertTrue(Files.exists(p, lo));
		if (ifs.getHeadType().toLowerCase().contains("symlink")) {
			assertTrue(SymbolicLinkHelper.isSymbolicLink(ifs.getClientPathString()));
			String linkTarget = SymbolicLinkHelper.readSymbolicLink(path);
			assertNotNull(linkTarget);
			assertEquals(target, linkTarget);
		}
	}
}
 
Example 18
Source File: WindowsChannelFactory.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
static Flags toFlags(Set<? extends OpenOption> options) {
    Flags flags = new Flags();
    for (OpenOption option: options) {
        if (option instanceof StandardOpenOption) {
            switch ((StandardOpenOption)option) {
                case READ : flags.read = true; break;
                case WRITE : flags.write = true; break;
                case APPEND : flags.append = true; break;
                case TRUNCATE_EXISTING : flags.truncateExisting = true; break;
                case CREATE : flags.create = true; break;
                case CREATE_NEW : flags.createNew = true; break;
                case DELETE_ON_CLOSE : flags.deleteOnClose = true; break;
                case SPARSE : flags.sparse = true; break;
                case SYNC : flags.sync = true; break;
                case DSYNC : flags.dsync = true; break;
                default: throw new UnsupportedOperationException();
            }
            continue;
        }
        if (option instanceof ExtendedOpenOption) {
            switch ((ExtendedOpenOption)option) {
                case NOSHARE_READ : flags.shareRead = false; break;
                case NOSHARE_WRITE : flags.shareWrite = false; break;
                case NOSHARE_DELETE : flags.shareDelete = false; break;
                default: throw new UnsupportedOperationException();
            }
            continue;
        }
        if (option == LinkOption.NOFOLLOW_LINKS) {
            flags.noFollowLinks = true;
            continue;
        }
        if (option == OPEN_REPARSE_POINT) {
            flags.openReparsePoint = true;
            continue;
        }
        if (option == null)
            throw new NullPointerException();
        throw new UnsupportedOperationException();
    }
    return flags;
}
 
Example 19
Source File: WindowsChannelFactory.java    From jdk8u-jdk with GNU General Public License v2.0 3 votes vote down vote up
static Flags toFlags(Set<? extends OpenOption> options) {
    Flags flags = new Flags();
    for (OpenOption option: options) {
        if (option instanceof StandardOpenOption) {
            switch ((StandardOpenOption)option) {
                case READ : flags.read = true; break;
                case WRITE : flags.write = true; break;
                case APPEND : flags.append = true; break;
                case TRUNCATE_EXISTING : flags.truncateExisting = true; break;
                case CREATE : flags.create = true; break;
                case CREATE_NEW : flags.createNew = true; break;
                case DELETE_ON_CLOSE : flags.deleteOnClose = true; break;
                case SPARSE : flags.sparse = true; break;
                case SYNC : flags.sync = true; break;
                case DSYNC : flags.dsync = true; break;
                default: throw new UnsupportedOperationException();
            }
            continue;
        }
        if (option instanceof ExtendedOpenOption) {
            switch ((ExtendedOpenOption)option) {
                case NOSHARE_READ : flags.shareRead = false; break;
                case NOSHARE_WRITE : flags.shareWrite = false; break;
                case NOSHARE_DELETE : flags.shareDelete = false; break;
                default: throw new UnsupportedOperationException();
            }
            continue;
        }
        if (option == LinkOption.NOFOLLOW_LINKS) {
            flags.noFollowLinks = true;
            continue;
        }
        if (option == OPEN_REPARSE_POINT) {
            flags.openReparsePoint = true;
            continue;
        }
        if (option == null)
            throw new NullPointerException();
        throw new UnsupportedOperationException();
    }
    return flags;
}
 
Example 20
Source File: WindowsChannelFactory.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 3 votes vote down vote up
static Flags toFlags(Set<? extends OpenOption> options) {
    Flags flags = new Flags();
    for (OpenOption option: options) {
        if (option instanceof StandardOpenOption) {
            switch ((StandardOpenOption)option) {
                case READ : flags.read = true; break;
                case WRITE : flags.write = true; break;
                case APPEND : flags.append = true; break;
                case TRUNCATE_EXISTING : flags.truncateExisting = true; break;
                case CREATE : flags.create = true; break;
                case CREATE_NEW : flags.createNew = true; break;
                case DELETE_ON_CLOSE : flags.deleteOnClose = true; break;
                case SPARSE : flags.sparse = true; break;
                case SYNC : flags.sync = true; break;
                case DSYNC : flags.dsync = true; break;
                default: throw new UnsupportedOperationException();
            }
            continue;
        }
        if (option instanceof ExtendedOpenOption) {
            switch ((ExtendedOpenOption)option) {
                case NOSHARE_READ : flags.shareRead = false; break;
                case NOSHARE_WRITE : flags.shareWrite = false; break;
                case NOSHARE_DELETE : flags.shareDelete = false; break;
                default: throw new UnsupportedOperationException();
            }
            continue;
        }
        if (option == LinkOption.NOFOLLOW_LINKS) {
            flags.noFollowLinks = true;
            continue;
        }
        if (option == OPEN_REPARSE_POINT) {
            flags.openReparsePoint = true;
            continue;
        }
        if (option == null)
            throw new NullPointerException();
        throw new UnsupportedOperationException();
    }
    return flags;
}