本文整理了Java中java.nio.file.AccessDeniedException
类的一些代码示例,展示了AccessDeniedException
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。AccessDeniedException
类的具体详情如下:
包路径:java.nio.file.AccessDeniedException
类名称:AccessDeniedException
暂无
代码示例来源:origin: Graylog2/graylog2-server
"MD5");
if (!java.nio.file.Files.exists(journalDirectory)) {
try {
java.nio.file.Files.createDirectories(journalDirectory);
} catch (IOException e) {
LOG.error("Cannot create journal directory at {}, please check the permissions", journalDirectory.toAbsolutePath());
throw new UncheckedIOException(e);
committedReadOffsetFile = new File(journalDirectory.toFile(), "graylog2-committed-read-offset");
try {
if (!committedReadOffsetFile.createNewFile()) {
final AccessDeniedException accessDeniedException = new AccessDeniedException(committedReadOffsetFile.getAbsolutePath(), null, e.getMessage());
throw new RuntimeException(accessDeniedException);
kafkaScheduler.startup();
logManager = new LogManager(
new File[]{journalDirectory.toFile()},
Map$.MODULE$.<String, LogConfig>empty(),
defaultConfig,
代码示例来源:origin: neo4j/neo4j
@Test
@DisabledOnOs( OS.WINDOWS )
void shouldGiveAClearErrorMessageIfTheDestinationsParentDirectoryIsNotWritable()
throws IOException
{
Path archive = testDirectory.file( "the-archive.dump" ).toPath();
Path destination = testDirectory.directory( "subdir/the-destination" ).toPath();
Files.createDirectories( destination.getParent() );
try ( Closeable ignored = withPermissions( destination.getParent(), emptySet() ) )
{
AccessDeniedException exception = assertThrows( AccessDeniedException.class, () -> new Loader().load( archive, destination, destination ) );
assertEquals( destination.getParent().toString(), exception.getMessage() );
}
}
代码示例来源:origin: de.schlichtherle.truezip/truezip-driver-file
@Override
public void setReadOnly(FsEntryName name) throws IOException {
Path file = target.resolve(name.getPath());
// Confirmed: There is no equivalent NIO.2 method, e.g. something like
// setAttribute(file, "readOnly", Boolean.TRUE, null);
// is not available!
if (!file.toFile().setReadOnly())
if (exists(file))
throw new AccessDeniedException(file.toString()); // just guessing here
else
throw new FileNotFoundException(file.toString());
}
代码示例来源:origin: io.digdag/digdag-cli
Path path = Files.createTempFile("digdag-", ".bat");
try {
try (InputStream in = res.readEntity(InputStream.class)) {
try (OutputStream out = Files.newOutputStream(path)) {
ByteStreams.copy(in, out);
path.toFile().setExecutable(true, false);
path.toFile().setReadable(true, false);
Path near = dest.getParent().resolve(".digdag.selfupdate.bat");
try {
Files.move(path, near, REPLACE_EXISTING);
path = near;
throw systemExit(String.format(ENGLISH,
"%s: permission denied\nhint: don't you need \"sudo\"?",
ex.getMessage()));
代码示例来源:origin: org.eclipse.jetty/jetty-client
public PathContentProvider(String contentType, Path filePath, int bufferSize) throws IOException
{
super(contentType);
if (!Files.isRegularFile(filePath))
throw new NoSuchFileException(filePath.toString());
if (!Files.isReadable(filePath))
throw new AccessDeniedException(filePath.toString());
this.filePath = filePath;
this.fileSize = Files.size(filePath);
this.bufferSize = bufferSize;
}
代码示例来源:origin: com.github.marschall/memoryfilesystem
@Override
public void checkAccess(AccessMode mode) throws AccessDeniedException {
switch (mode) {
case READ:
// always fine
break;
case WRITE:
if (this.readOnly) {
throw new AccessDeniedException(this.path.toString());
}
break;
case EXECUTE:
// always fine
break;
default:
throw new UnsupportedOperationException("access mode " + mode + " is not supported");
}
}
代码示例来源:origin: neo4j/neo4j
public static void checkWritableDirectory( Path directory ) throws FileSystemException
{
if ( !exists( directory ) )
{
throw new NoSuchFileException( directory.toString() );
}
if ( isRegularFile( directory ) )
{
throw new FileSystemException( directory.toString() + ": Not a directory" );
}
if ( !isWritable( directory ) )
{
throw new AccessDeniedException( directory.toString() );
}
}
代码示例来源:origin: apache/incubator-edgent
allLines.add(preFn.apply(tempFile1.toAbsolutePath().toString()));
allLines.addAll(Arrays.asList(lines));
allLines.add(postFn.apply(tempFile1.toAbsolutePath().toString(), null));
allLines.add(postFn.apply(tmpDirPath,
isWindows
? new AccessDeniedException(tmpDirPath)
: new IOException("Is a directory")));
代码示例来源:origin: org.xbib/sshd-common
if (status && Files.isDirectory(path, linkOptions)) {
String localName = name.replace('/', File.separatorChar); // in case we are running on Windows
file = path.resolve(localName);
} else if (status && Files.isRegularFile(path, linkOptions)) {
file = path;
} else if (!status) {
Path parent = path.getParent();
throw new AccessDeniedException("Receive file parent (" + parent + ") existence status cannot be determined for " + path);
if (parentStatus && Files.isDirectory(parent, linkOptions)) {
file = path;
throw new AccessDeniedException("Receive file existence status cannot be determined: " + file);
代码示例来源:origin: org.xbib/sshd-common
public void receiveDir(String header, Path local, ScpTimestamp time, boolean preserve, int bufferSize) throws IOException {
Path path = Objects.requireNonNull(local, "No local path").normalize().toAbsolutePath();
if (!header.startsWith("D")) {
throw new IOException("Expected a 'D; message but got '" + header + "'");
Boolean status = IoUtils.checkFileExists(path, options);
if (status == null) {
throw new AccessDeniedException("Receive directory existence status cannot be determined: " + path);
if (status && Files.isDirectory(path, options)) {
String localName = name.replace('/', File.separatorChar);
file = path.resolve(localName);
} else if (!status) {
Path parent = path.getParent();
throw new AccessDeniedException("Receive directory parent (" + parent + ") existence status cannot be determined for " + path);
if (status && Files.isDirectory(parent, options)) {
file = path;
throw new AccessDeniedException("Receive directory file existence status cannot be determined: " + file);
if (!(status && Files.isDirectory(file, options))) {
Files.createDirectory(file);
代码示例来源:origin: org.apache.sshd/sshd-sftp
@Override
protected String doOpenDir(int id, String path, Path p, LinkOption... options) throws IOException {
Boolean status = IoUtils.checkFileExists(p, options);
if (status == null) {
throw signalOpenFailure(id, path, p, true,
new AccessDeniedException(p.toString(), p.toString(), "Cannot determine open-dir existence"));
}
if (!status) {
throw signalOpenFailure(id, path, p, true,
new NoSuchFileException(path, path, "Referenced target directory N/A"));
} else if (!Files.isDirectory(p, options)) {
throw signalOpenFailure(id, path, p, true, new NotDirectoryException(path));
} else if (!Files.isReadable(p)) {
throw signalOpenFailure(id, path, p, true,
new AccessDeniedException(p.toString(), p.toString(), "Not readable"));
} else {
String handle;
try {
synchronized (handles) {
handle = generateFileHandle(p);
DirectoryHandle dirHandle = new DirectoryHandle(this, p, handle);
handles.put(handle, dirHandle);
}
} catch (IOException e) {
throw signalOpenFailure(id, path, p, true, e);
}
return handle;
}
}
代码示例来源:origin: com.almis.awe/awe-tools
ArrayNode resultList = JsonNodeFactory.instance.arrayNode();
try (DirectoryStream<Path> directoryStream = Files.newDirectoryStream(Paths.get(repositoryBasePath, path))) {
SimpleDateFormat dt = new SimpleDateFormat(dateFormat);
for (Path pathObj : directoryStream) {
BasicFileAttributes attrs = Files.readAttributes(pathObj, BasicFileAttributes.class);
element.put("name", pathObj.getFileName().toString());
element.put("rights", getPermissions(pathObj));
element.put("date", dt.format(new Date(attrs.lastModifiedTime().toMillis())));
} catch (AccessDeniedException ex) {
logger.error("[List files] - Access denied to read file", ex);
return error("Access denied to read file " + ex.getMessage());
} catch (IOException ex) {
logger.error("[List files] - Error list files of " + path, ex);
代码示例来源:origin: org.graalvm.compiler/compiler
Path result = Paths.get(dumpDir.toString(), fileName);
try {
if (createDirectory) {
return Files.createDirectory(result);
} else {
try {
return Files.createFile(result);
} catch (AccessDeniedException e) {
throw Files.isDirectory(result, NOFOLLOW_LINKS) ? new FileAlreadyExistsException(e.getFile()) : e;
代码示例来源:origin: org.apache.sshd/sshd-scp
Boolean status = IoUtils.checkFileExists(localPath, options);
if (status == null) {
throw new AccessDeniedException("Receive directory existence status cannot be determined: " + localPath);
if (status && Files.isDirectory(localPath, options)) {
String localName = name.replace('/', File.separatorChar);
file = localPath.resolve(localName);
} else if (!status) {
Path parent = localPath.getParent();
throw new AccessDeniedException("Receive directory parent (" + parent + ") existence status cannot be determined for " + localPath);
if (status && Files.isDirectory(parent, options)) {
file = localPath;
throw new AccessDeniedException("Receive directory file existence status cannot be determined: " + file);
if (!(status && Files.isDirectory(file, options))) {
Files.createDirectory(file);
代码示例来源:origin: org.apache.sshd/sshd-sftp
throw new AccessDeniedException(path.toString(), path.toString(), "File not opened for read");
if (Files.isDirectory(path, IoUtils.getLinkOptions(true))) {
throw new NotDirectoryException(path.toString());
long totalSize = Files.size(path);
if ((startOffset == 0L) && (length == 0L)) {
effectiveLength = totalSize;
代码示例来源:origin: org.apache.sshd/sshd-sftp
protected void doMakeDirectory(int id, String path, Map<String, ?> attrs, LinkOption... options) throws IOException {
Path p = resolveFile(path);
ServerSession session = getServerSession();
if (log.isDebugEnabled()) {
log.debug("doMakeDirectory({})[id={}] SSH_FXP_MKDIR (path={}[{}], attrs={})",
session, id, path, p, attrs);
}
Boolean status = IoUtils.checkFileExists(p, options);
if (status == null) {
throw new AccessDeniedException(p.toString(), p.toString(), "Cannot validate make-directory existence");
}
if (status) {
if (Files.isDirectory(p, options)) {
throw new FileAlreadyExistsException(p.toString(), p.toString(), "Target directory already exists");
} else {
throw new FileAlreadyExistsException(p.toString(), p.toString(), "Already exists as a file");
}
} else {
SftpEventListener listener = getSftpEventListenerProxy();
listener.creating(session, p, attrs);
try {
Files.createDirectory(p);
doSetAttributes(p, attrs);
} catch (IOException | RuntimeException e) {
listener.created(session, p, attrs, e);
throw e;
}
listener.created(session, p, attrs, null);
}
}
代码示例来源:origin: net.jthink/jaudiotagger
final ChunkHeader chunkHeader = seekToStartOfMetadata(fc, existingTag, file.toString());
logger.info(file + "Current Space allocated:" + existingTag.getSizeOfID3TagOnly() + ":NewTagRequires:" + bb.limit());
deleteTagChunk(fc, existingTag, chunkHeader, file.toString());
fc.position(fc.size());
writeExtraByteIfChunkOddSize(fc, fc.size());
deleteRemainderOfFile(fc, existingTag, file.toString());
fc.position(fc.size());
writeExtraByteIfChunkOddSize(fc, fc.size());
throw new NoWritePermissionsException(file + ":" + ade.getMessage());
代码示例来源:origin: org.apache.sshd/sshd-sftp
throw new AccessDeniedException(path.toString(), path.toString(), "File not opened for read");
for (int index = 0; Files.isSymbolicLink(path) && (index < Byte.MAX_VALUE /* TODO make this configurable */); index++) {
path = Files.readSymbolicLink(path);
if (Files.isSymbolicLink(path)) {
throw new FileSystemLoopException(target);
if (Files.isDirectory(path, IoUtils.getLinkOptions(false))) {
throw new NotDirectoryException(path.toString());
代码示例来源:origin: org.apache.sshd/sshd-sftp
protected void doRemove(int id, String path, LinkOption... options) throws IOException {
Path p = resolveFile(path);
if (log.isDebugEnabled()) {
log.debug("doRemove({})[id={}] SSH_FXP_REMOVE (path={}[{}])",
getServerSession(), id, path, p);
}
Boolean status = IoUtils.checkFileExists(p, options);
if (status == null) {
throw signalRemovalPreConditionFailure(id, path, p,
new AccessDeniedException(p.toString(), p.toString(), "Cannot determine existence of remove candidate"));
} else if (!status) {
throw signalRemovalPreConditionFailure(id, path, p,
new NoSuchFileException(p.toString(), p.toString(), "Removal candidate not found"));
} else if (Files.isDirectory(p, options)) {
throw signalRemovalPreConditionFailure(id, path, p,
new SftpException(SftpConstants.SSH_FX_FILE_IS_A_DIRECTORY, p.toString() + " is a folder"));
} else {
doRemove(id, p);
}
}
代码示例来源:origin: org.apache.sshd/sshd-sftp
int srcAccess = srcHandle.getAccessMask();
if ((srcAccess & SftpConstants.ACE4_READ_DATA) != SftpConstants.ACE4_READ_DATA) {
throw new AccessDeniedException(srcPath.toString(), srcPath.toString(), "Source file not opened for read");
ValidateUtils.checkTrue(readOffset >= 0L, "Invalid read offset: %d", readOffset);
long totalSize = Files.size(srcHandle.getFile());
long effectiveLength = readLength;
if (effectiveLength == 0L) {
int dstAccess = dstHandle.getAccessMask();
if ((dstAccess & SftpConstants.ACE4_WRITE_DATA) != SftpConstants.ACE4_WRITE_DATA) {
throw new AccessDeniedException(srcHandle.toString(), srcHandle.toString(), "Source handle not opened for write");
内容来源于网络,如有侵权,请联系作者删除!