类java.nio.file.attribute.FileAttribute源码实例Demo

下面列出了怎么用java.nio.file.attribute.FileAttribute的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: presto   文件: Standard.java
public static void enablePrestoJavaDebugger(DockerContainer container, int debugPort)
{
    try {
        FileAttribute<Set<PosixFilePermission>> rwx = PosixFilePermissions.asFileAttribute(PosixFilePermissions.fromString("rwxrwxrwx"));
        Path script = Files.createTempFile("enable-java-debugger", ".sh", rwx);
        Files.writeString(
                script,
                format(
                        "#!/bin/bash\n" +
                                "printf '%%s\\n' '%s' >> '%s'\n",
                        "-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=0.0.0.0:" + debugPort,
                        CONTAINER_PRESTO_JVM_CONFIG),
                UTF_8);
        container.withCopyFileToContainer(MountableFile.forHostPath(script), "/docker/presto-init.d/enable-java-debugger.sh");

        // expose debug port unconditionally when debug is enabled
        exposePort(container, debugPort);
    }
    catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}
 
源代码2 项目: aion   文件: Aion.java
private static void writeKeyToFile(final String path, final String fileName, final String key)
        throws IOException {
    Set<PosixFilePermission> perms = PosixFilePermissions.fromString("rwxr-----");
    FileAttribute<Set<PosixFilePermission>> attr = PosixFilePermissions.asFileAttribute(perms);

    Path p = Paths.get(path).resolve(fileName);
    Path keyFile;
    if (!java.nio.file.Files.exists(p)) {
        keyFile = java.nio.file.Files.createFile(p, attr);
    } else {
        keyFile = p;
    }

    FileOutputStream fos = new FileOutputStream(keyFile.toString());
    fos.write(key.getBytes());
    fos.close();
}
 
private File flushPropertiesToTempFile(Map<String, Object> configProps) throws IOException {
  FileAttribute<Set<PosixFilePermission>> attributes
      = PosixFilePermissions.asFileAttribute(new HashSet<>(
          Arrays.asList(PosixFilePermission.OWNER_WRITE,
                        PosixFilePermission.OWNER_READ)));
  File configFile = Files.createTempFile("ksqlclient", "properties", attributes).toFile();
  configFile.deleteOnExit();

  try (FileOutputStream outputStream = new FileOutputStream(configFile)) {
    Properties clientProps = new Properties();
    for (Map.Entry<String, Object> property
        : configProps.entrySet()) {
      clientProps.put(property.getKey(), property.getValue());
    }
    clientProps.store(outputStream, "Configuration properties of KSQL AdminClient");
  }
  return configFile;
}
 
源代码4 项目: openjdk-jdk8u   文件: FaultyFileSystem.java
@Override
public void createSymbolicLink(Path link, Path target, FileAttribute<?>... attrs)
    throws IOException
{
    triggerEx(target, "createSymbolicLink");
    Files.createSymbolicLink(unwrap(link), unwrap(target), attrs);
}
 
源代码5 项目: incubator-tuweni   文件: Files.java
/**
 * Create a file, if it does not already exist.
 *
 * @param path The path to the file to create.
 * @param attrs An optional list of file attributes to set atomically when creating the file.
 * @return {@code true} if the file was created.
 * @throws IOException If an I/O error occurs or the parent directory does not exist.
 */
public static boolean createFileIfMissing(Path path, FileAttribute<?>... attrs) throws IOException {
  requireNonNull(path);
  try {
    java.nio.file.Files.createFile(path, attrs);
  } catch (FileAlreadyExistsException e) {
    return false;
  }
  return true;
}
 
源代码6 项目: metastore   文件: LocalFileStorage.java
private void init(RegistryInfo registryInfo, Map<String, String> config) {
  this.registryName = registryInfo.getName();
  this.path = config.get("path");
  if (path == null) {
    throw new RuntimeException("path variable not set");
  }
  if (!new File(path).isDirectory()) {
    try {
      Files.createDirectories(new File(path).toPath(), new FileAttribute[] {});
    } catch (IOException e) {
      throw new RuntimeException(e);
    }
  }
}
 
源代码7 项目: jdk1.8-source-analysis   文件: TempFileHelper.java
/**
 * 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);
}
 
源代码8 项目: paintera   文件: TmpDirectoryCreator.java
public TmpDirectoryCreator(final Supplier<Path> dir, final String prefix, final FileAttribute<?>... attrs)
{
	super();
	LOG.debug("Creating {} with dir={} prefix={} attrs={}", this.getClass().getSimpleName(), dir, prefix, attrs);
	this.dir = dir;
	this.prefix = prefix;
	this.attrs = attrs;
}
 
源代码9 项目: openjdk-jdk8u   文件: TempFileHelper.java
/**
 * 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);
}
 
源代码10 项目: jdk1.8-source-analysis   文件: Files.java
/**
 * 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;
    }
}
 
源代码11 项目: dragonwell8_jdk   文件: TempFileHelper.java
/**
 * 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 项目: dragonwell8_jdk   文件: TempFileHelper.java
/**
 * 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 项目: dragonwell8_jdk   文件: Files.java
/**
 * 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 项目: dragonwell8_jdk   文件: FaultyFileSystem.java
@Override
public void createSymbolicLink(Path link, Path target, FileAttribute<?>... attrs)
    throws IOException
{
    triggerEx(target, "createSymbolicLink");
    Files.createSymbolicLink(unwrap(link), unwrap(target), attrs);
}
 
源代码15 项目: dragonwell8_jdk   文件: FaultyFileSystem.java
@Override
public void createDirectory(Path dir, FileAttribute<?>... attrs)
    throws IOException
{
    triggerEx(dir, "createDirectory");
    Files.createDirectory(unwrap(dir), attrs);
}
 
源代码16 项目: dragonwell8_jdk   文件: FaultyFileSystem.java
@Override
public SeekableByteChannel newByteChannel(Path file,
                                          Set<? extends OpenOption> options,
                                          FileAttribute<?>... attrs)
    throws IOException
{
    triggerEx(file, "newByteChannel");
    return Files.newByteChannel(unwrap(file), options, attrs);
}
 
源代码17 项目: dragonwell8_jdk   文件: CustomOptions.java
@Override
public SeekableByteChannel newByteChannel(Path path,
                                          Set<? extends OpenOption> options,
                                          FileAttribute<?>... attrs)
    throws IOException
{
    if (options.contains(CustomOption.IGNORE)) {
        ignoreCount++;
        options.remove(CustomOption.IGNORE);
    }
    return super.newByteChannel(path, options, attrs);
}
 
源代码18 项目: TencentKona-8   文件: TempFileHelper.java
/**
 * 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);
}
 
源代码19 项目: TencentKona-8   文件: FaultyFileSystem.java
@Override
public void createSymbolicLink(Path link, Path target, FileAttribute<?>... attrs)
    throws IOException
{
    triggerEx(target, "createSymbolicLink");
    Files.createSymbolicLink(unwrap(link), unwrap(target), attrs);
}
 
源代码20 项目: TencentKona-8   文件: FaultyFileSystem.java
@Override
public void createDirectory(Path dir, FileAttribute<?>... attrs)
    throws IOException
{
    triggerEx(dir, "createDirectory");
    Files.createDirectory(unwrap(dir), attrs);
}
 
源代码21 项目: TencentKona-8   文件: FaultyFileSystem.java
@Override
public SeekableByteChannel newByteChannel(Path file,
                                          Set<? extends OpenOption> options,
                                          FileAttribute<?>... attrs)
    throws IOException
{
    triggerEx(file, "newByteChannel");
    return Files.newByteChannel(unwrap(file), options, attrs);
}
 
源代码22 项目: TencentKona-8   文件: CustomOptions.java
@Override
public SeekableByteChannel newByteChannel(Path path,
                                          Set<? extends OpenOption> options,
                                          FileAttribute<?>... attrs)
    throws IOException
{
    if (options.contains(CustomOption.IGNORE)) {
        ignoreCount++;
        options.remove(CustomOption.IGNORE);
    }
    return super.newByteChannel(path, options, attrs);
}
 
源代码23 项目: jdk8u60   文件: TempFileHelper.java
/**
 * 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);
}
 
源代码24 项目: jdk8u60   文件: TempFileHelper.java
/**
 * 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);
}
 
源代码25 项目: jdk8u60   文件: Files.java
/**
 * 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;
    }
}
 
源代码26 项目: openjdk-jdk8u   文件: CustomOptions.java
@Override
public SeekableByteChannel newByteChannel(Path path,
                                          Set<? extends OpenOption> options,
                                          FileAttribute<?>... attrs)
    throws IOException
{
    if (options.contains(CustomOption.IGNORE)) {
        ignoreCount++;
        options.remove(CustomOption.IGNORE);
    }
    return super.newByteChannel(path, options, attrs);
}
 
源代码27 项目: jdk8u60   文件: FaultyFileSystem.java
@Override
public SeekableByteChannel newByteChannel(Path file,
                                          Set<? extends OpenOption> options,
                                          FileAttribute<?>... attrs)
    throws IOException
{
    triggerEx(file, "newByteChannel");
    return Files.newByteChannel(unwrap(file), options, attrs);
}
 
源代码28 项目: embedded-cassandra   文件: FileUtils.java
/**
 * Creates a new and empty file, if the file does not exist.
 *
 * @param file the path to the file to create
 * @param attributes an optional list of file attributes to set atomically when creating the file
 * @return the file
 * @throws IOException if an I/O error occurs or the parent directory does not exist
 * @see Files#createFile(Path, FileAttribute[])
 */
public static Path createIfNotExists(Path file, FileAttribute<?>... attributes) throws IOException {
	Objects.requireNonNull(file, "'file' must not be null");
	Objects.requireNonNull(attributes, "'attributes' must not be null");
	try {
		return Files.createFile(file, attributes);
	}
	catch (FileAlreadyExistsException ex) {
		return file;
	}
}
 
源代码29 项目: cava   文件: Files.java
/**
 * Create a file, if it does not already exist.
 *
 * @param path The path to the file to create.
 * @param attrs An optional list of file attributes to set atomically when creating the file.
 * @return {@code true} if the file was created.
 * @throws IOException If an I/O error occurs or the parent directory does not exist.
 */
public static boolean createFileIfMissing(Path path, FileAttribute<?>... attrs) throws IOException {
  requireNonNull(path);
  try {
    java.nio.file.Files.createFile(path, attrs);
  } catch (FileAlreadyExistsException e) {
    return false;
  }
  return true;
}
 
源代码30 项目: JDKSourceCode1.8   文件: TempFileHelper.java
/**
 * 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);
}
 
 类所在包
 类方法
 同包方法