use of java.nio.file.NotDirectoryException in project ballerina by ballerina-lang.
the class FileSystemService method createErrorResponse.
/**
* Creates an error response for the given IO Exception.
*
* @param ex Thrown Exception
* @return Error Message
*/
private Response createErrorResponse(Throwable ex) {
JsonObject entity = new JsonObject();
String errMsg = ex.getMessage();
if (ex instanceof AccessDeniedException) {
errMsg = "Access Denied to " + ex.getMessage();
} else if (ex instanceof NoSuchFileException) {
errMsg = "No such file: " + ex.getMessage();
} else if (ex instanceof FileAlreadyExistsException) {
errMsg = "File already exists: " + ex.getMessage();
} else if (ex instanceof NotDirectoryException) {
errMsg = "Not a directory: " + ex.getMessage();
} else if (ex instanceof ReadOnlyFileSystemException) {
errMsg = "Read only: " + ex.getMessage();
} else if (ex instanceof DirectoryNotEmptyException) {
errMsg = "Directory not empty: " + ex.getMessage();
} else if (ex instanceof FileNotFoundException) {
errMsg = "File not found: " + ex.getMessage();
}
entity.addProperty("Error", errMsg);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(entity).header(ACCESS_CONTROL_ALLOW_ORIGIN_HEADER, '*').type(MediaType.APPLICATION_JSON).build();
}
use of java.nio.file.NotDirectoryException in project mycore by MyCoRe-Org.
the class MCRFileSystemProvider method resolvePath.
static MCRFilesystemNode resolvePath(MCRPath path) throws IOException {
try {
String ifsid = nodeCache.getUnchecked(path);
MCRFilesystemNode node = MCRFilesystemNode.getNode(ifsid);
if (node != null) {
return node;
}
nodeCache.invalidate(path);
return resolvePath(path);
} catch (UncheckedExecutionException e) {
Throwable cause = e.getCause();
if (cause instanceof NoSuchFileException) {
throw (NoSuchFileException) cause;
}
if (cause instanceof NotDirectoryException) {
throw (NotDirectoryException) cause;
}
if (cause instanceof IOException) {
throw (IOException) cause;
}
throw e;
}
}
use of java.nio.file.NotDirectoryException in project mycore by MyCoRe-Org.
the class MCRFileSystemProvider method newDirectoryStream.
/* (non-Javadoc)
* @see java.nio.file.spi.FileSystemProvider#newDirectoryStream(java.nio.file.Path, java.nio.file.DirectoryStream.Filter)
*/
@Override
public DirectoryStream<Path> newDirectoryStream(Path dir, Filter<? super Path> filter) throws IOException {
MCRPath mcrPath = MCRFileSystemUtils.checkPathAbsolute(dir);
MCRFilesystemNode node = resolvePath(mcrPath);
if (node instanceof MCRDirectory) {
return new MCRDirectoryStream((MCRDirectory) node, mcrPath);
}
throw new NotDirectoryException(dir.toString());
}
use of java.nio.file.NotDirectoryException in project mycore by MyCoRe-Org.
the class MCRFileSystemProvider method createDirectory.
/* (non-Javadoc)
* @see java.nio.file.spi.FileSystemProvider#createDirectory(java.nio.file.Path, java.nio.file.attribute.FileAttribute[])
*/
@Override
public void createDirectory(Path dir, FileAttribute<?>... attrs) throws IOException {
if (attrs.length > 0) {
throw new UnsupportedOperationException("Setting 'attrs' atomically is unsupported.");
}
MCRPath mcrPath = MCRFileSystemUtils.checkPathAbsolute(dir);
MCRDirectory rootDirectory;
if (mcrPath.isAbsolute() && mcrPath.getNameCount() == 0) {
rootDirectory = MCRDirectory.getDirectory(mcrPath.getOwner());
if (rootDirectory != null) {
throw new FileAlreadyExistsException(mcrPath.toString());
}
rootDirectory = new MCRDirectory(mcrPath.getOwner());
return;
}
rootDirectory = getRootDirectory(mcrPath);
MCRPath parentPath = mcrPath.getParent();
MCRPath absolutePath = getAbsolutePathFromRootComponent(parentPath);
MCRFilesystemNode childByPath = rootDirectory.getChildByPath(absolutePath.toString());
if (childByPath == null) {
throw new NoSuchFileException(parentPath.toString(), dir.getFileName().toString(), "parent directory does not exist");
}
if (childByPath instanceof MCRFile) {
throw new NotDirectoryException(parentPath.toString());
}
MCRDirectory parentDir = (MCRDirectory) childByPath;
String dirName = mcrPath.getFileName().toString();
if (parentDir.getChild(dirName) != null) {
throw new FileAlreadyExistsException(mcrPath.toString());
}
new MCRDirectory(dirName, parentDir);
}
use of java.nio.file.NotDirectoryException in project neo4j by neo4j.
the class FileUtils method moveFileToDirectory.
/**
* Utility method that moves a file from its current location to the
* provided target directory. If rename fails (for example if the target is
* another disk) a copy/delete will be performed instead.
*
* @param toMove The File object to move.
* @param targetDirectory the destination directory
* @return the new file, null iff the move was unsuccessful
* @throws IOException if an IO error occurs.
*/
public static Path moveFileToDirectory(Path toMove, Path targetDirectory) throws IOException {
if (notExists(targetDirectory)) {
Files.createDirectories(targetDirectory);
}
if (!isDirectory(targetDirectory)) {
throw new NotDirectoryException(targetDirectory.toString());
}
Path target = targetDirectory.resolve(toMove.getFileName());
moveFile(toMove, target);
return target;
}
Aggregations