本文整理匯總了Java中java.nio.file.FileSystemException類的典型用法代碼示例。如果您正苦於以下問題:Java FileSystemException類的具體用法?Java FileSystemException怎麽用?Java FileSystemException使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
FileSystemException類屬於java.nio.file包,在下文中一共展示了FileSystemException類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: test
import java.nio.file.FileSystemException; //導入依賴的package包/類
void test(Path base, String name) throws IOException {
Path file = base.resolve(name);
Path javaFile = base.resolve("HelloWorld.java");
tb.writeFile(file,
"public class HelloWorld {\n"
+ " public static void main(String... args) {\n"
+ " System.err.println(\"Hello World!\");\n"
+ " }\n"
+ "}");
try {
Files.createSymbolicLink(javaFile, file.getFileName());
} catch (FileSystemException fse) {
System.err.println("warning: test passes vacuously, sym-link could not be created");
System.err.println(fse.getMessage());
return;
}
Path classes = Files.createDirectories(base.resolve("classes"));
new JavacTask(tb)
.outdir(classes)
.files(javaFile)
.run()
.writeAll();
}
示例2: testSystemProperties1
import java.nio.file.FileSystemException; //導入依賴的package包/類
@Test
public void testSystemProperties1() throws Exception {
final String tempFileName = System.getProperty("java.io.tmpdir") + "/hadoop.log";
final Path tempFilePath = new File(tempFileName).toPath();
Files.deleteIfExists(tempFilePath);
try {
final Configuration configuration = getConfiguration("config-1.2/log4j-system-properties-1.properties");
final RollingFileAppender appender = configuration.getAppender("RFA");
appender.stop(10, TimeUnit.SECONDS);
System.out.println("expected: " + tempFileName + " Actual: " + appender.getFileName());
assertEquals(tempFileName, appender.getFileName());
} finally {
try {
Files.deleteIfExists(tempFilePath);
} catch (FileSystemException e) {
e.printStackTrace();
}
}
}
示例3: watchDir
import java.nio.file.FileSystemException; //導入依賴的package包/類
protected void watchDir(Path dir) throws IOException {
LOG.debug("Registering watch for {}", dir);
if (Thread.currentThread().isInterrupted()) {
LOG.debug("Skipping adding watch since current thread is interrupted.");
}
// check if directory is already watched
// on Windows, check if any parent is already watched
for (Path path = dir; path != null; path = FILE_TREE_WATCHING_SUPPORTED ? path.getParent() : null) {
WatchKey previousWatchKey = watchKeys.get(path);
if (previousWatchKey != null && previousWatchKey.isValid()) {
LOG.debug("Directory {} is already watched and the watch is valid, not adding another one.", path);
return;
}
}
int retryCount = 0;
IOException lastException = null;
while (retryCount++ < 2) {
try {
WatchKey watchKey = dir.register(watchService, WATCH_KINDS, WATCH_MODIFIERS);
watchKeys.put(dir, watchKey);
return;
} catch (IOException e) {
LOG.debug("Exception in registering for watching of " + dir, e);
lastException = e;
if (e instanceof NoSuchFileException) {
LOG.debug("Return silently since directory doesn't exist.");
return;
}
if (e instanceof FileSystemException && e.getMessage() != null && e.getMessage().contains("Bad file descriptor")) {
// retry after getting "Bad file descriptor" exception
LOG.debug("Retrying after 'Bad file descriptor'");
continue;
}
// Windows at least will sometimes throw odd exceptions like java.nio.file.AccessDeniedException
// if the file gets deleted while the watch is being set up.
// So, we just ignore the exception if the dir doesn't exist anymore
if (!Files.exists(dir)) {
// return silently when directory doesn't exist
LOG.debug("Return silently since directory doesn't exist.");
return;
} else {
// no retry
throw e;
}
}
}
LOG.debug("Retry count exceeded, throwing last exception");
throw lastException;
}
示例4: testFileSystemExceptions
import java.nio.file.FileSystemException; //導入依賴的package包/類
public void testFileSystemExceptions() throws IOException {
for (FileSystemException ex : Arrays.asList(new FileSystemException("a", "b", "c"),
new NoSuchFileException("a", "b", "c"),
new NotDirectoryException("a"),
new DirectoryNotEmptyException("a"),
new AtomicMoveNotSupportedException("a", "b", "c"),
new FileAlreadyExistsException("a", "b", "c"),
new AccessDeniedException("a", "b", "c"),
new FileSystemLoopException("a"))) {
FileSystemException serialize = serialize(ex);
assertEquals(serialize.getClass(), ex.getClass());
assertEquals("a", serialize.getFile());
if (serialize.getClass() == NotDirectoryException.class ||
serialize.getClass() == FileSystemLoopException.class ||
serialize.getClass() == DirectoryNotEmptyException.class) {
assertNull(serialize.getOtherFile());
assertNull(serialize.getReason());
} else {
assertEquals(serialize.getClass().toString(), "b", serialize.getOtherFile());
assertEquals(serialize.getClass().toString(), "c", serialize.getReason());
}
}
}
示例5: rm
import java.nio.file.FileSystemException; //導入依賴的package包/類
/**
* Deletes the given file or directory.
* If the file is a directory, it must be empty.
*
* @param file the file or directory.
* Note that although this just needs to be a plain {@code File}
* object, archive files and entries are only supported for
* instances of {@code TFile}.
* @throws IOException if any I/O error occurs.
* @see <a href="#bulkIOMethods">Bulk I/O Methods</a>
*/
@FsAssertion(atomic=YES, consistent=YES, isolated=YES)
@SuppressWarnings("AccessingNonPublicFieldOfAnotherObject")
public static void rm(File file) throws IOException {
if (file instanceof TFile) {
TFile tfile = (TFile) file;
if (null != tfile.innerArchive) {
tfile.innerArchive.getController().unlink(
getAccessPreferences(), tfile.getNodeName());
return;
}
file = tfile.file;
}
if (!file.delete())
throw new FileSystemException(file.getPath(), null, "Cannot delete!");
}
示例6: removeRoot
import java.nio.file.FileSystemException; //導入依賴的package包/類
@Override
public void removeRoot(String owner) throws FileSystemException {
MCRPath rootPath = getPath(owner, "", this);
MCRDirectory rootDirectory = MCRDirectory.getRootDirectory(owner);
if (rootDirectory == null) {
throw new NoSuchFileException(rootPath.toString());
}
if (rootDirectory.isDeleted()) {
return;
}
if (rootDirectory.hasChildren()) {
throw new DirectoryNotEmptyException(rootPath.toString());
}
try {
rootDirectory.delete();
} catch (RuntimeException e) {
LogManager.getLogger(getClass()).warn("Catched run time exception while removing root directory.", e);
throw new FileSystemException(rootPath.toString(), null, e.getMessage());
}
LogManager.getLogger(getClass()).info("Removed root directory: {}", rootPath);
}
示例7: copyIfLocked
import java.nio.file.FileSystemException; //導入依賴的package包/類
@Override
public void copyIfLocked(final Path source, final Path target, final Mover mover) throws IOException {
checkNotNull(source);
checkNotNull(target);
try {
mover.accept(source, target);
}
catch (AtomicMoveNotSupportedException atomicMoveNotSupported) {
throw atomicMoveNotSupported;
}
catch (FileSystemException e) { // NOSONAR
// Windows can throw a FileSystemException on move or moveAtomic
// if the file is in use; in this case, copy and attempt to delete
// source
log.warn("Using copy to move {} to {}", source, target);
copy(source, target);
try {
delete(source);
}
catch (IOException deleteException) { // NOSONAR
log.error("Unable to delete {} after move: {}", source, deleteException.getMessage());
}
}
}
示例8: FilePersister
import java.nio.file.FileSystemException; //導入依賴的package包/類
/**
* Folder to which we save all the data
*
* @param folder target folder
*/
public FilePersister(File folder) throws FileSystemException {
if (!folder.exists() && !folder.mkdir()) {
throw new FileSystemException("Can't create target directory");
}
if (!folder.isDirectory()) {
throw new FileSystemException("Target is not a folder");
}
//Creating subdirectories
playlists = new File(getChildPath(folder.toString(), "playlists"));
segments = new File(getChildPath(folder.toString(), "segments"));
if ((!playlists.exists() && !playlists.mkdir()) || (!segments.exists() && !segments.mkdir())) {
throw new FileSystemException("Can't create subdirectories");
}
if (!playlists.isDirectory() || !segments.isDirectory()) {
throw new FileSystemException("Sanity check #1 failed");
}
}
示例9: testClearAllStubConfigAndUpload
import java.nio.file.FileSystemException; //導入依賴的package包/類
/**
* Clears all the existing stub configurations of Wilma.
*
* @throws Exception in case of an error.
*/
@Test
public void testClearAllStubConfigAndUpload() throws Exception {
//clear all stubconfig
RequestParameters requestParameters = createRequestParameters();
ResponseHolder responseVersion = callWilmaWithPostMethod(requestParameters); //Get the actual DialogDescriptors
String answer = responseVersion.getResponseMessage();
for (String groupName : getGroupNamesFromJson(answer)) {
MultiStubRequestParameters multiStubRequestParameters = createMultiStubRequestParameters(groupName);
callWilmaWithPostMethod(multiStubRequestParameters); //Delete the uploaded stub configuration
logComment(groupName + "'s config has been dropped.");
}
//upload preserved stubconfig
uploadStubConfigToWilmaAndAllowEmptyStuvConfig(STUB_CONFIG);
//if we are here, then the stub config is restored, so we can delete it
Path path = FileSystems.getDefault().getPath(STUB_CONFIG);
try {
Files.deleteIfExists(path);
} catch (FileSystemException e) {
logComment("Ups, cannot delete the file, reason: " + e.getLocalizedMessage());
}
}
示例10: deleteDirectory
import java.nio.file.FileSystemException; //導入依賴的package包/類
@Override
public void deleteDirectory(Path path) throws IOException {
EphemeralFsPath efsPath = cast(path);
synchronized(efsPath.fs.fsLock) {
EphemeralFsPath actualPath = translate(efsPath);
if(actualPath == null) {
throw new NoSuchFileException(path.toString());
}
ResolvedPath resolved = ResolvedPath.resolve(actualPath, true);
if(resolved.resolvedToSymbolicLink()) {
throw new FileSystemException("symlink: Not a directory");
}
if(!resolved.getTarget().isDir()) {
throw new FileSystemException(path + ": Not a directory");
}
actualPath.fs.delete(actualPath);
return;
}
}
示例11: createDirectory
import java.nio.file.FileSystemException; //導入依賴的package包/類
void createDirectory(EphemeralFsPath dir, FileAttribute<?>... attrs)
throws IOException {
dir = dir.toAbsolutePath();
synchronized(fsLock) {
//this is root
if(dir.getParent() == null) {
throw new FileAlreadyExistsException(dir.toString());
}
ResolvedPath resolvedPath = ResolvedPath.resolve(dir.getParent(), false);
if(!resolvedPath.hasTarget()) {
throw new NoSuchFileException(dir.getParent().toString());
}
if(!resolvedPath.getTarget().isDir()) {
throw new FileSystemException(dir.getParent() + " : is Not a directory");
}
resolvedPath.getTarget().addDir(dir.getFileName(), new FilePermissions(true, attrs));
}
}
示例12: createLink
import java.nio.file.FileSystemException; //導入依賴的package包/類
void createLink(EphemeralFsPath link, EphemeralFsPath existing) throws IOException {
synchronized(fsLock) {
EphemeralFsPath dir = link.getParent();
ResolvedPath resolvedPath = ResolvedPath.resolve(dir, false);
if(!resolvedPath.hasTarget()) {
throw new NoSuchFileException(dir.toString());
}
if(!resolvedPath.getTarget().isDir()) {
throw new FileSystemException(dir + " : is Not a directory");
}
ResolvedPath existingResolved = ResolvedPath.resolve(existing);
if(!existingResolved.hasTarget()) {
throw new NoSuchFileException(link.toString());
}
if(existingResolved.getTarget().isDir()) {
throw new FileSystemException(link + " -> " + existing + ": Operation not permitted");
}
resolvedPath.getTarget().add(link.getFileName(), existingResolved.getTarget());
}
}
示例13: assertCanAddChild
import java.nio.file.FileSystemException; //導入依賴的package包/類
private void assertCanAddChild(EphemeralFsPath name) throws IOException {
if(isFile()) {
throw new NotDirectoryException("can't add children to file");
}
if(name.toString().equals(".") || name.toString().equals("..")) {
throw new IllegalStateException("invalid path:" + name);
}
if(fs.getSettings().getMaxPathLength() != Long.MAX_VALUE &&
getPathToRoot().resolve(name).toString().length() > fs.getSettings().getMaxPathLength()) {
throw new FileSystemException("Path too long");
}
assertOnlyFileName(name);
if(children.containsKey(name.toFileName())) {
throw new FileAlreadyExistsException("a child with name:" + name + " already exists");
}
}
示例14: notifyChange
import java.nio.file.FileSystemException; //導入依賴的package包/類
public void notifyChange(EphemeralFsPath path) throws NoSuchFileException {
ResolvedPath resolvedPath;
try {
resolvedPath = ResolvedPath.resolve(path.getParent(), false);
} catch (FileSystemException e) {
//we can't resolve the path
//ignore and skip notifying
return;
}
if(!resolvedPath.hasTarget()) {
return;
}
if(resolvedPath.getTarget().isDir() &&
resolvedPath.getTarget().getName(this) != null) {
EphemeralFsWatchEvent event = new EphemeralFsWatchEvent(
path,
StandardWatchEventKinds.ENTRY_MODIFY);
fs.getWatchRegistry().hearChange(resolvedPath.getTarget(), event);
}
}
示例15: testCopyFileFailsIfTargetParentIsFileExist
import java.nio.file.FileSystemException; //導入依賴的package包/類
@Test
public void testCopyFileFailsIfTargetParentIsFileExist() throws Exception {
byte[] contents = new byte[20];
random.nextBytes(contents);
Path source = root.resolve("source");
Path dest = root.resolve("dest").resolve("child");
Files.write(source, contents);
Files.createFile(dest.getParent());
try {
Files.copy(source, dest);
fail();
} catch(FileSystemException e) {
//pass
}
}