当前位置: 首页>>代码示例>>Java>>正文


Java AccessMode类代码示例

本文整理汇总了Java中java.nio.file.AccessMode的典型用法代码示例。如果您正苦于以下问题:Java AccessMode类的具体用法?Java AccessMode怎么用?Java AccessMode使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


AccessMode类属于java.nio.file包,在下文中一共展示了AccessMode类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: ensureDirectoryExists

import java.nio.file.AccessMode; //导入依赖的package包/类
/**
 * Ensures configured directory {@code path} exists.
 * @throws IOException if {@code path} exists, but is not a directory, not accessible, or broken symbolic link.
 */
static void ensureDirectoryExists(Path path) throws IOException {
    // this isn't atomic, but neither is createDirectories.
    if (Files.isDirectory(path)) {
        // verify access, following links (throws exception if something is wrong)
        // we only check READ as a sanity test
        path.getFileSystem().provider().checkAccess(path.toRealPath(), AccessMode.READ);
    } else {
        // doesn't exist, or not a directory
        try {
            Files.createDirectories(path);
        } catch (FileAlreadyExistsException e) {
            // convert optional specific exception so the context is clear
            IOException e2 = new NotDirectoryException(path.toString());
            e2.addSuppressed(e);
            throw e2;
        }
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:23,代码来源:Security.java

示例2: start

import java.nio.file.AccessMode; //导入依赖的package包/类
/**
 * Starts this Muxer, if not already started.
 *
 * This is thread safe to be called at any time, multiple times. Returns immediately.
 *
 * @throws IOException
 */
public void start()
		throws IOException {
	if (state.compareAndSet(NOT_STARTED, RUNNING)) {
		try {
			access(mkv, AccessMode.READ);
			access(srt, AccessMode.READ);
			access(tempDir, AccessMode.WRITE);
			output.toFile().deleteOnExit();
			ProcessBuilder builder = factory.from("mkvmerge", "-o", output.toString(), mkv.toString(), srt.toString());
			builder.directory(tempDir.toFile()).inheritIO(); // TODO: Better solution than inheritIO
			process = builder.start();
		} catch (Exception e) {
			state.set(FAILED);
			deleteWarn(output);
			throw e;
		}
	}
}
 
开发者ID:tfiskgul,项目名称:mux2fs,代码行数:26,代码来源:Muxer.java

示例3: checkAccess

import java.nio.file.AccessMode; //导入依赖的package包/类
@Override
public void checkAccess(Path path, AccessMode... modes) throws IOException {
	CloudPath cloudPath = getCloudPath(path);
	CloudFileSystemImplementation sourceCloudFileSystemImplementation = getCloudFileSystemImplementation(cloudPath);

	// Work out permissions to check
	Set<AclEntryPermission> checkPermissions = EnumSet.noneOf(AclEntryPermission.class);
	Arrays.stream(modes).forEach(m ->
			{
				if (AccessMode.EXECUTE.equals(m)) {
					checkPermissions.add(AclEntryPermission.EXECUTE);
				} else if (AccessMode.READ.equals(m)) {
					checkPermissions.add(AclEntryPermission.READ_DATA);
				} else if (AccessMode.WRITE.equals(m)) {
					checkPermissions.add(AclEntryPermission.WRITE_DATA);
				}
			});

	sourceCloudFileSystemImplementation.checkAccess(getBlobStoreContext(cloudPath), cloudPath, checkPermissions);
}
 
开发者ID:brdara,项目名称:java-cloud-filesystem-provider,代码行数:21,代码来源:CloudFileSystemProviderDelegate.java

示例4: AbstractLocalFileSystem

import java.nio.file.AccessMode; //导入依赖的package包/类
public AbstractLocalFileSystem( URI uri, FileSystemProvider provider, Path cachePath, Map<String, Object> env,
                                BiFunction<Path, Map<String, ?>, FileSystemIO> fileSystemIO )
        throws IOException
{
    super( uri, provider, env, cachePath, fileSystemIO );

    this.cachePath = getFileSystemIO().getBaseDirectory();

    if( Files.notExists( cachePath ) ) {
        Files.createDirectories( cachePath );
    }

    // sm and existence check
    cachePath.getFileSystem().provider().checkAccess( cachePath, AccessMode.READ );
    if( !Files.isWritable( cachePath ) ) {
        setReadOnly( true );
    }
}
 
开发者ID:peter-mount,项目名称:filesystem,代码行数:19,代码来源:AbstractLocalFileSystem.java

示例5: checkAccess

import java.nio.file.AccessMode; //导入依赖的package包/类
@Override
public void checkAccess(Path path, AccessMode... modes) throws IOException
{
  JPath jPath = (JPath) path;
  Status status;

  try {
    status = jPath.getBfsFile().getStatus();
  }
  catch (Exception e) {
    throw createIOException(e);
  }

  if (status.getType() == Status.FileType.FILE) {
    // do nothing
  }
  else if (status.getType() == Status.FileType.DIRECTORY) {
    // do nothing
  }
  else {
    throw new NoSuchFileException(path.toUri().toString());
  }
}
 
开发者ID:baratine,项目名称:baratine,代码行数:24,代码来源:JFileSystemProvider.java

示例6: move

import java.nio.file.AccessMode; //导入依赖的package包/类
/** {@inheritDoc} */
@Override
public void move(Path source, Path target, CopyOption... options) throws IOException {

    source = ((TestPath) source).unwrap();
    target = ((TestPath) target).unwrap();

    checkIfRemoved(source);

    Path sourceParent = source.getParent();
    if (sourceParent != null) {
        checkIfRemoved(sourceParent);
        checkPermissions(sourceParent, true, AccessMode.WRITE);
    }

    Path targetParent = target.getParent();
    if (targetParent != null) {
        checkIfRemoved(targetParent);
        checkPermissions(targetParent, true, AccessMode.WRITE);
    }

    provider.move(source, target, options);
}
 
开发者ID:gredler,项目名称:test-fs,代码行数:24,代码来源:TestFileSystemProvider.java

示例7: AbstractTarFileSystem

import java.nio.file.AccessMode; //导入依赖的package包/类
protected AbstractTarFileSystem(AbstractTarFileSystemProvider provider,
		Path tfpath, Map<String, ?> env) throws IOException {
	// configurable env setup
	createNew = "true".equals(env.get("create"));
	defaultDir = env.containsKey("default.dir") ? (String) env
			.get("default.dir") : "/";
	entriesToData = new HashMap<>();
	if (defaultDir.charAt(0) != '/') {
		throw new IllegalArgumentException("default dir should be absolute");
	}
	this.provider = provider;
	this.tfpath = tfpath;
	if (Files.notExists(tfpath)) {
		if (!createNew) {
			throw new FileSystemNotFoundException(tfpath.toString());
		}
	}
	// sm and existence check
	tfpath.getFileSystem().provider().checkAccess(tfpath, AccessMode.READ);
	if (!Files.isWritable(tfpath)) {
		readOnly = true;
	}
	defaultdir = new TarPath(this, defaultDir.getBytes());
	outputStreams = new ArrayList<>();
	mapEntries();
}
 
开发者ID:PeterLaker,项目名称:archive-fs,代码行数:27,代码来源:AbstractTarFileSystem.java

示例8: accessModeMaskToSet

import java.nio.file.AccessMode; //导入依赖的package包/类
public Set<AccessMode> accessModeMaskToSet(int mask) {
	Set<AccessMode> accessModes = EnumSet.noneOf(AccessMode.class);
	// @formatter:off
	if ((mask & AccessConstants.R_OK) == AccessConstants.R_OK) accessModes.add(AccessMode.READ);
	if ((mask & AccessConstants.W_OK) == AccessConstants.W_OK) accessModes.add(AccessMode.WRITE);
	if ((mask & AccessConstants.X_OK) == AccessConstants.X_OK) accessModes.add(AccessMode.EXECUTE);
	// @formatter:on
	return accessModes;
}
 
开发者ID:cryptomator,项目名称:fuse-nio-adapter,代码行数:10,代码来源:FileAttributesUtil.java

示例9: access

import java.nio.file.AccessMode; //导入依赖的package包/类
@Override
public int access(String path, int mask) {
	try {
		Path node = resolvePath(path);
		Set<AccessMode> accessModes = attrUtil.accessModeMaskToSet(mask);
		return checkAccess(node, accessModes);
	} catch (RuntimeException e) {
		LOG.error("checkAccess failed.", e);
		return -ErrorCodes.EIO();
	}
}
 
开发者ID:cryptomator,项目名称:fuse-nio-adapter,代码行数:12,代码来源:ReadOnlyAdapter.java

示例10: testAccessModeMaskToSet

import java.nio.file.AccessMode; //导入依赖的package包/类
@ParameterizedTest
@MethodSource("accessModeProvider")
public void testAccessModeMaskToSet(Set<AccessMode> expectedModes, int mask) {
	FileAttributesUtil util = new FileAttributesUtil();
	Set<AccessMode> accessModes = util.accessModeMaskToSet(mask);
	Assertions.assertEquals(expectedModes, accessModes);
}
 
开发者ID:cryptomator,项目名称:fuse-nio-adapter,代码行数:8,代码来源:FileAttributesUtilTest.java

示例11: accessModeProvider

import java.nio.file.AccessMode; //导入依赖的package包/类
static Stream<Arguments> accessModeProvider() {
	return Stream.of( //
			Arguments.of(EnumSet.noneOf(AccessMode.class), 0), //
			Arguments.of(EnumSet.of(AccessMode.READ), AccessConstants.R_OK), //
			Arguments.of(EnumSet.of(AccessMode.WRITE), AccessConstants.W_OK), //
			Arguments.of(EnumSet.of(AccessMode.EXECUTE), AccessConstants.X_OK), //
			Arguments.of(EnumSet.of(AccessMode.READ, AccessMode.WRITE), AccessConstants.R_OK | AccessConstants.W_OK), //
			Arguments.of(EnumSet.allOf(AccessMode.class), AccessConstants.R_OK | AccessConstants.W_OK | AccessConstants.X_OK | AccessConstants.F_OK) //
	);
}
 
开发者ID:cryptomator,项目名称:fuse-nio-adapter,代码行数:11,代码来源:FileAttributesUtilTest.java

示例12: addPathIfExists

import java.nio.file.AccessMode; //导入依赖的package包/类
/**
 * Add access to a directory iff it exists already
 * @param policy current policy to add permissions to
 * @param configurationName the configuration name associated with the path (for error messages only)
 * @param path the path itself
 * @param permissions set of file permissions to grant to the path
 */
static void addPathIfExists(Permissions policy, String configurationName, Path path, String permissions) {
    if (Files.isDirectory(path)) {
        // add each path twice: once for itself, again for files underneath it
        policy.add(new FilePermission(path.toString(), permissions));
        policy.add(new FilePermission(path.toString() + path.getFileSystem().getSeparator() + "-", permissions));
        try {
            path.getFileSystem().provider().checkAccess(path.toRealPath(), AccessMode.READ);
        } catch (IOException e) {
            throw new IllegalStateException("Unable to access '" + configurationName + "' (" + path + ")", e);
        }
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:20,代码来源:Security.java

示例13: begin

import java.nio.file.AccessMode; //导入依赖的package包/类
private FileNode begin() throws IOException {
    final FileNode buffer;
    final Path entryFile = node.getPath();
    Boolean exists = null;
    if (options.get(EXCLUSIVE) && (exists = exists(entryFile)))
        throw new FileAlreadyExistsException(node.toString());
    if (options.get(CACHE)) {
        // This is obviously NOT properly isolated.
        if (TRUE.equals(exists)
                || null == exists && (exists = exists(entryFile))) {
            //if (!isWritable(entryFile)) throw new IOException(...)
            entryFile   .getFileSystem()
                        .provider()
                        .checkAccess(entryFile, AccessMode.WRITE);
        } else {
            createFile(entryFile);
        }
        buffer = node.createIoBuffer();
    } else {
        buffer = node;
    }
    if (options.get(CREATE_PARENTS) && !TRUE.equals(exists)) {
        final Path parentFile = entryFile.getParent();
        if (null != parentFile) {
            try {
                createDirectories(parentFile);
            } catch (IOException ex) {
                // Workaround for bug in Oracle JDK 1.7.0_51:
                // A call to Files.createDirectories("C:\\") will fail on
                // Windows although it shouldn't.
                // Likewise, a call to Files.createDirectories("/") will
                // fail on Mac OS X although it shouldn't.
                // On Linux, it supposedly works however.
                if (!isDirectory(parentFile)) throw ex;
            }
        }
    }
    return buffer;
}
 
开发者ID:christian-schlichtherle,项目名称:truevfs,代码行数:40,代码来源:FileOutputSocket.java

示例14: testMkvMustBeReadable

import java.nio.file.AccessMode; //导入依赖的package包/类
@Test
public void testMkvMustBeReadable()
		throws Exception {
	doThrow(new NoSuchFileException(null)).when(provider).checkAccess(mkv, AccessMode.READ);
	exception.expect(NoSuchFileException.class);
	muxer.start();
}
 
开发者ID:tfiskgul,项目名称:mux2fs,代码行数:8,代码来源:MuxerTest.java

示例15: testSrtMustBeReadable

import java.nio.file.AccessMode; //导入依赖的package包/类
@Test
public void testSrtMustBeReadable()
		throws Exception {
	doThrow(new NoSuchFileException(null)).when(provider).checkAccess(srt, AccessMode.READ);
	exception.expect(NoSuchFileException.class);
	muxer.start();
}
 
开发者ID:tfiskgul,项目名称:mux2fs,代码行数:8,代码来源:MuxerTest.java


注:本文中的java.nio.file.AccessMode类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。