本文整理汇总了Java中java.nio.file.attribute.FileAttribute类的典型用法代码示例。如果您正苦于以下问题:Java FileAttribute类的具体用法?Java FileAttribute怎么用?Java FileAttribute使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
FileAttribute类属于java.nio.file.attribute包,在下文中一共展示了FileAttribute类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createLocalConfigFile
import java.nio.file.attribute.FileAttribute; //导入依赖的package包/类
/**
* Create localconf folder and properties file necessary to run build task in order to check merge integrity.
* @param branchName
*/
public void createLocalConfigFile(String branchName) throws Exception {
String branchPath = SvnUtils.TEMP_FOLDER + "/" + branchName;
//create localconf directory
String newDirectoryPath = branchPath + "/localconf";
if ( !Files.exists( Paths.get(newDirectoryPath))) {
Set<PosixFilePermission> permissions = PosixFilePermissions.fromString("rwxrwxrwx");
FileAttribute<Set<PosixFilePermission>> fileAttributes = PosixFilePermissions
.asFileAttribute(permissions);
Files.createDirectory(Paths.get(newDirectoryPath), fileAttributes);
}
//copy properties template
Files.copy(
Paths.get(branchPath + "/common/conf/worldnettps.properties.template"),
Paths.get(newDirectoryPath + "/worldnettps.properties"),
StandardCopyOption.REPLACE_EXISTING);
//setting glassfish directory in properties file
String appServerDir = PropertiesUtil.getString("appserver.dir");
String sedCommand = String.format(
"sed -i '/glassfish.dir/c\\glassfish.dir=%s' localconf/worldnettps.properties", appServerDir);
CommandExecutor.run( sedCommand, branchPath);
logger.info("worldnettps.properties file has been created in localconf folder.");
}
示例2: create
import java.nio.file.attribute.FileAttribute; //导入依赖的package包/类
@Override
public int create(String path, @mode_t long mode, FuseFileInfo fi) {
try {
Set<OpenFlags> flags = bitMaskUtil.bitMaskToSet(OpenFlags.class, fi.flags.longValue());
LOG.info("createAndOpen {} with openOptions {}", path, flags);
Path node = resolvePath(path);
if (fileStore.supportsFileAttributeView(PosixFileAttributeView.class)) {
FileAttribute<?> attrs = PosixFilePermissions.asFileAttribute(attrUtil.octalModeToPosixPermissions(mode));
return fileHandler.createAndOpen(node, fi, attrs);
} else {
return fileHandler.createAndOpen(node, fi);
}
} catch (RuntimeException e) {
LOG.error("create failed.", e);
return -ErrorCodes.EIO();
}
}
示例3: newByteChannel
import java.nio.file.attribute.FileAttribute; //导入依赖的package包/类
/**
* File access is checked using {@link #checkAccess(BlobStoreContext, CloudPath, Set)}
* always with {@link AclEntryPermission#WRITE_DATA} and {@link AclEntryPermission#ADD_FILE},
* and optionally with {@link AclEntryPermission#APPEND_DATA} if <em>options</em> contains
* {@link StandardOpenOption#APPEND}.
* @see CloudFileChannel
*/
@Override
public CloudFileChannel newByteChannel(BlobStoreContext context, CloudPath path,
Set<? extends OpenOption> options, FileAttribute<?>... attrs) throws IOException {
EnumSet<AclEntryPermission> channelPerms = EnumSet.noneOf(AclEntryPermission.class);
options.forEach(o -> {
AclEntryPermission aclPerm = openOptionToAclEntryPermission(o);
if (aclPerm != null) {
channelPerms.add(aclPerm);
}
});
// Check the parent path for file add
if (channelPerms.remove(AclEntryPermission.ADD_FILE)) {
checkAccess(context, path.getParent(), CREATE_NEW_FILE_PERMS);
}
// Check file access if the file exists
if (path.exists()) {
checkAccess(context, path, channelPerms);
}
// Create the channel
return new CloudFileChannel(context, path, getCloudFileChannelTransport(), options, attrs);
}
开发者ID:brdara,项目名称:java-cloud-filesystem-provider,代码行数:32,代码来源:DefaultCloudFileSystemImplementation.java
示例4: newByteChannel
import java.nio.file.attribute.FileAttribute; //导入依赖的package包/类
public SeekableByteChannel newByteChannel( Path path, Set<? extends OpenOption> options, FileAttribute<?>... attrs )
throws IOException
{
boolean append = true;
if( options.contains( StandardOpenOption.APPEND ) ) {
append = true;
}
else if( options.contains( StandardOpenOption.TRUNCATE_EXISTING ) ) {
append = false;
}
if( options.contains( StandardOpenOption.READ ) ) {
return new MemChannel.Read( buffer );
}
if( options.contains( StandardOpenOption.WRITE ) ) {
if( !append ) {
truncate();
}
return new MemChannel.Appender( buffer );
}
throw new IOException( "Must read or write" );
}
示例5: newByteChannel
import java.nio.file.attribute.FileAttribute; //导入依赖的package包/类
/**
* Creates and returns a new {@link SeekableSMBByteChannel} instance.
*
* @param path The {@link SMBPath} for which a byte channel should be opened.
* @param options A set of {@link StandardOpenOption}s.
* @param attrs An optional list of file attributes to set when creating the file.
* @return An instance of {@link SeekableSMBByteChannel}.
*
* @throws IllegalArgumentException If provided path is not an {@link SMBPath} instance.
* @throws IOException If an I/O error occurs
* @throws UnsupportedOperationException If an unsupported open option is specified (DSYNC, SYNC or SPARSE)
*/
@Override
public SeekableByteChannel newByteChannel(Path path, Set<? extends OpenOption> options, FileAttribute<?>... attrs) throws IOException {
/* Convert path and instantiate SmbFile. */
final SMBPath smbPath = SMBPath.fromPath(path);
final SmbFile file = smbPath.getSmbFile();
/* Determines how the SeekableByteChannel should be setup. */
boolean write = false;
boolean create = false;
boolean create_new = false;
boolean append = false;
boolean truncate = false;
for (OpenOption option : options) {
if (option.equals(StandardOpenOption.WRITE)) {
write = true;
} else if (option.equals(StandardOpenOption.CREATE)) {
create = true;
} else if (option.equals(StandardOpenOption.CREATE_NEW)) {
create_new = true;
} else if (option.equals(StandardOpenOption.APPEND)) {
append = true;
} else if (option.equals(StandardOpenOption.TRUNCATE_EXISTING)) {
truncate = true;
} else if (option.equals(StandardOpenOption.DSYNC) || option.equals(StandardOpenOption.SYNC) || option.equals(StandardOpenOption.SPARSE) || option.equals(StandardOpenOption.DELETE_ON_CLOSE)) {
throw new UnsupportedOperationException("SMBFileSystemProvider does not support the option options SYNC, DSYNC, SPARSE or DELETE_ON_CLOSE");
}
}
/* Returns a new SeekableSMBByteChannel object. */
return new SeekableSMBByteChannel(file, write, create, create_new, truncate, append);
}
示例6: newByteChannel
import java.nio.file.attribute.FileAttribute; //导入依赖的package包/类
@Override
public SeekableByteChannel newByteChannel(
Path path,
Set<? extends OpenOption> options,
FileAttribute<?>... attrs)
throws IOException {
return promote(path).newByteChannel(options, attrs);
}
示例7: createFiles
import java.nio.file.attribute.FileAttribute; //导入依赖的package包/类
public List<Path> createFiles(Path directory, int number) throws IOException {
if (directory == null) {
throw new NullPointerException("Path passed to createFiles cannot be null");
}
FileAttribute<?>[] attrs = {};
System.out.println("Creating " + number + " files in " + directory);
Files.createDirectories(directory, attrs);
assertTrue("Directory was not created", Files.exists(directory));
List<Path> files = new LinkedList<Path>();
for (int counter = 0; counter < number; counter++) {
Path newFile;
synchronized (file_counter_lock) {
newFile = directory.resolve("file" + file_counter++ + ".txt");
}
Files.createFile(newFile, attrs);
assertTrue("File was not created", Files.exists(newFile));
files.add(newFile);
}
return files;
}
示例8: staticCreateFiles
import java.nio.file.attribute.FileAttribute; //导入依赖的package包/类
public static List<Path> staticCreateFiles(Path directory, int number) throws IOException {
if (directory == null) {
throw new NullPointerException("Path passed to createFiles cannot be null");
}
FileAttribute<?>[] attrs = {};
Files.createDirectories(directory, attrs);
assertTrue("Directory was not created", Files.exists(directory));
List<Path> files = new LinkedList<Path>();
for (int counter = 0 ; counter < number ; counter++) {
Path newFile = directory.resolve("file" + counter + ".txt");
Files.createFile(newFile, attrs);
assertTrue("File was not created", Files.exists(newFile));
files.add(newFile);
}
assertEquals("The number of files generated was not equal to the requested number", number, files.size());
// Check via another means
final List<Path> visitorFiles = new LinkedList<Path>();
Files.walkFileTree(directory, new SimpleFileVisitor<Path>() {
@Override
public FileVisitResult visitFile(Path path, BasicFileAttributes attributes) {
if (path.toString().endsWith(".txt")) {
visitorFiles.add(path);
}
return FileVisitResult.CONTINUE;
}
});
assertEquals("WalkFileTreeTest.staticCreateFiles() - The number of files created was not equal to the number seen using the FileVisitor. " +
"FileVisitor found " + Arrays.toString(visitorFiles.toArray()) + " & we created " + Arrays.toString(files.toArray()) ,
number, visitorFiles.size());
return files;
}
示例9: createParentDirectories
import java.nio.file.attribute.FileAttribute; //导入依赖的package包/类
/**
* Creates any necessary but nonexistent parent directories of the specified path. Note that if
* this operation fails, it may have succeeded in creating some (but not all) of the necessary
* parent directories. The parent directory is created with the given {@code attrs}.
*
* @throws IOException if an I/O error occurs, or if any necessary but nonexistent parent
* directories of the specified file could not be created.
*/
public static void createParentDirectories(
Path path, FileAttribute<?>... attrs) throws IOException {
// Interestingly, unlike File.getCanonicalFile(), Path/Files provides no way of getting the
// canonical (absolute, normalized, symlinks resolved, etc.) form of a path to a nonexistent
// file. getCanonicalFile() can at least get the canonical form of the part of the path which
// actually exists and then append the normalized remainder of the path to that.
Path normalizedAbsolutePath = path.toAbsolutePath().normalize();
Path parent = normalizedAbsolutePath.getParent();
if (parent == null) {
// The given directory is a filesystem root. All zero of its ancestors exist. This doesn't
// mean that the root itself exists -- consider x:\ on a Windows machine without such a
// drive -- or even that the caller can create it, but this method makes no such guarantees
// even for non-root files.
return;
}
// Check if the parent is a directory first because createDirectories will fail if the parent
// exists and is a symlink to a directory... we'd like for this to succeed in that case.
// (I'm kind of surprised that createDirectories would fail in that case; doesn't seem like
// what you'd want to happen.)
if (!Files.isDirectory(parent)) {
Files.createDirectories(parent, attrs);
if (!Files.isDirectory(parent)) {
throw new IOException("Unable to create parent directories of " + path);
}
}
}
示例10: exposeNativeLibrary
import java.nio.file.attribute.FileAttribute; //导入依赖的package包/类
/**
* Java cannot load native libraries from jars so we need to expose the library
* first by copying it to an external folder and then refreshing the Java library path.
*
* @param resourceName the name of the library resource to expose
* @return whether the library was successfully exposed
*/
private boolean exposeNativeLibrary(String resourceName) {
try {
Path tempDir = Files.createTempDirectory("native-", new FileAttribute[0]);
log.debug("Resource name: {}", resourceName);
copyLibraryResources(tempDir, resourceName);
refreshLibraryPath(tempDir);
} catch (Throwable t) {
log.warn("Unable to expose library {}", resourceName, t);
return false;
}
return true;
}
示例11: createTempFile
import java.nio.file.attribute.FileAttribute; //导入依赖的package包/类
/**
* Creates a temporary file in the given directory, or in in the
* temporary directory if dir is {@code null}.
*/
static Path createTempFile(Path dir,
String prefix,
String suffix,
FileAttribute<?>[] attrs)
throws IOException
{
return create(dir, prefix, suffix, false, attrs);
}
示例12: createTempDirectory
import java.nio.file.attribute.FileAttribute; //导入依赖的package包/类
/**
* Creates a temporary directory in the given directory, or in in the
* temporary directory if dir is {@code null}.
*/
static Path createTempDirectory(Path dir,
String prefix,
FileAttribute<?>[] attrs)
throws IOException
{
return create(dir, prefix, null, true, attrs);
}
示例13: createAndCheckIsDirectory
import java.nio.file.attribute.FileAttribute; //导入依赖的package包/类
/**
* Used by createDirectories to attempt to create a directory. A no-op
* if the directory already exists.
*/
private static void createAndCheckIsDirectory(Path dir,
FileAttribute<?>... attrs)
throws IOException
{
try {
createDirectory(dir, attrs);
} catch (FileAlreadyExistsException x) {
if (!isDirectory(dir, LinkOption.NOFOLLOW_LINKS))
throw x;
}
}
示例14: createSymbolicLink
import java.nio.file.attribute.FileAttribute; //导入依赖的package包/类
@Override
public void createSymbolicLink(Path link, Path target, FileAttribute<?>... attrs)
throws IOException
{
triggerEx(target, "createSymbolicLink");
Files.createSymbolicLink(unwrap(link), unwrap(target), attrs);
}
示例15: createDirectory
import java.nio.file.attribute.FileAttribute; //导入依赖的package包/类
@Override
public void createDirectory(Path dir, FileAttribute<?>... attrs)
throws IOException
{
triggerEx(dir, "createDirectory");
Files.createDirectory(unwrap(dir), attrs);
}