/** * Sets all initial attributes for the given file, including the given attributes if possible. */ public void setInitialAttributes(File file, FileAttribute<?>... attrs) { // default values should already be sanitized by their providers for (int i = 0; i < defaultValues.size(); i++) { FileAttribute<?> attribute = defaultValues.get(i); int separatorIndex = attribute.name().indexOf(':'); String view = attribute.name().substring(0, separatorIndex); String attr = attribute.name().substring(separatorIndex + 1); file.setAttribute(view, attr, attribute.value()); } for (FileAttribute<?> attr : attrs) { setAttribute(file, attr.name(), attr.value(), true); } }
private static void checkSupportedInitialAttributes(FileAttribute<?>... attrs) { if (attrs != null) { for (FileAttribute<?> attribute : attrs) { String attributeName = attribute.name(); if (UNSUPPORTED_INITIAL_ATTRIBUTES.contains(attributeName)) { throw new UnsupportedOperationException("'" + attributeName + "' not supported as initial attribute"); } } } }
public static int parseAttrs(FileAttribute<?>... attrs) { int mode = 0; for (FileAttribute a : attrs) { for (PosixFilePermission p : (Set<PosixFilePermission>) a.value()) { Integer perm = permsToMode.get(p); if (null != perm) { mode |= perm; } } } return mode; }
void createDirectory(SFTPPath path, FileAttribute<?>... attrs) throws IOException { if (attrs.length > 0) { throw Messages.fileSystemProvider().unsupportedCreateFileAttribute(attrs[0].name()); } try (Channel channel = channelPool.get()) { channel.mkdir(path.path()); } }
public static Set<PosixFilePermission> extractPosixPermissions(final FileAttribute<?>[] fileAttributes) { // create file depending on OS config will not create all requested attributes. Set<PosixFilePermission> permissions = null; for (FileAttribute<?> attr : fileAttributes) { Object value = attr.value(); if (value instanceof Set) { Set set = (Set) value; for (Object obj : set) { if (obj instanceof PosixFilePermission) { if (permissions == null) { permissions = EnumSet.of((PosixFilePermission) obj); } else { permissions.add((PosixFilePermission) obj); } } } } } return permissions == null ? Collections.EMPTY_SET : permissions; }
void createDirectory(FTPPath path, FileAttribute<?>... attrs) throws IOException { if (attrs.length > 0) { throw Messages.fileSystemProvider().unsupportedCreateFileAttribute(attrs[0].name()); } try (FTPClientPool.Client client = clientPool.get()) { client.mkdir(path.path()); } }
SeekableByteChannel newByteChannel(FTPPath path, Set<? extends OpenOption> options, FileAttribute<?>... attrs) throws IOException { if (attrs.length > 0) { throw Messages.fileSystemProvider().unsupportedCreateFileAttribute(attrs[0].name()); } OpenOptions openOptions = OpenOptions.forNewByteChannel(options); try (FTPClientPool.Client client = clientPool.get()) { if (openOptions.read) { // use findFTPFile instead of getFTPFile, to let the opening of the stream provide the correct error message FTPFile ftpFile = findFTPFile(client, path); InputStream in = newInputStream(client, path, openOptions); long size = ftpFile == null ? 0 : ftpFile.getSize(); return FileSystemProviderSupport.createSeekableByteChannel(in, size); } // if append then we need the FTP file, to find the initial position of the channel boolean requireFTPFile = openOptions.append; FTPFileAndOutputStreamPair outPair = newOutputStream(client, path, requireFTPFile, openOptions); long initialPosition = outPair.ftpFile == null ? 0 : outPair.ftpFile.getSize(); return FileSystemProviderSupport.createSeekableByteChannel(outPair.out, initialPosition); } }
/** * Sets all initial attributes for the given file, including the given attributes if possible. */ public void setInitialAttributes(File file, FileAttribute<?>... attrs) { // default values should already be sanitized by their providers for (int i = 0; i < defaultValues.size(); i++) { FileAttribute<?> attribute = defaultValues.get(i); int separatorIndex = attribute.name().indexOf(':'); String view = attribute.name().substring(0, separatorIndex); String attr = attribute.name().substring(separatorIndex + 1); file.setAttribute(view, attr, attribute.value()); } for (FileAttribute<?> attr : attrs) { setAttribute(file, attr.name(), attr.value(), true); } }
@SuppressWarnings("resource") SeekableByteChannel newByteChannel(SFTPPath path, Set<? extends OpenOption> options, FileAttribute<?>... attrs) throws IOException { if (attrs.length > 0) { throw Messages.fileSystemProvider().unsupportedCreateFileAttribute(attrs[0].name()); } OpenOptions openOptions = OpenOptions.forNewByteChannel(options); try (Channel channel = channelPool.get()) { if (openOptions.read) { // use findAttributes instead of getAttributes, to let the opening of the stream provide the correct error message SftpATTRS attributes = findAttributes(channel, path, false); InputStream in = newInputStream(channel, path, openOptions); long size = attributes == null ? 0 : attributes.getSize(); return FileSystemProviderSupport.createSeekableByteChannel(in, size); } // if append then we need the attributes, to find the initial position of the channel boolean requireAttributes = openOptions.append; SFTPAttributesAndOutputStreamPair outPair = newOutputStream(channel, path, requireAttributes, openOptions); long initialPosition = outPair.attributes == null ? 0 : outPair.attributes.getSize(); return FileSystemProviderSupport.createSeekableByteChannel(outPair.out, initialPosition); } }
continue; if ("posix:permissions".equals(attribute.name())) { copy = new FileAttribute[length]; changed = true; System.arraycopy(attributes, 0, copy, 0, i - 1); Set<PosixFilePermission> perms = (Set<PosixFilePermission>) attribute.value(); Set<PosixFilePermission> newPerms = EnumSet.copyOf(perms); newPerms.removeAll(this.umask);
@Override @SuppressWarnings("unchecked") public void createDirectory( Path path, FileAttribute<?>... fileAttributes ) throws IOException { UnixSshPath unixPath = checkPath( path ); Set<PosixFilePermission> permissions = null; for ( FileAttribute<?> fileAttribute : fileAttributes ) { if ( fileAttribute.name().equals( "posix:permissions" ) ) { permissions = (Set<PosixFilePermission>)fileAttribute.value(); } } StringBuilder commandBuilder = new StringBuilder( unixPath.getFileSystem().getCommand( "mkdir" ) ) .append( " " ); if ( permissions != null ) { commandBuilder.append( "-m " ).append( toMode( permissions ) ); } commandBuilder.append( unixPath.toAbsolutePath().quotedString() ); executeForStdout( unixPath, commandBuilder.toString() ); }
GroupPrincipal group = null; for ( FileAttribute<?> fileAttribute : fileAttributes ) { String name = fileAttribute.name(); if ( name.equals( "posix:permissions" ) ) { permissions = (Set<PosixFilePermission>)fileAttribute.value(); owner = (UserPrincipal)fileAttribute.value(); group = (GroupPrincipal)fileAttribute.value();