use of java.nio.file.FileSystemLoopException in project elasticsearch by elastic.
the class StreamOutput method writeException.
public void writeException(Throwable throwable) throws IOException {
if (throwable == null) {
writeBoolean(false);
} else {
writeBoolean(true);
boolean writeCause = true;
boolean writeMessage = true;
if (throwable instanceof CorruptIndexException) {
writeVInt(1);
writeOptionalString(((CorruptIndexException) throwable).getOriginalMessage());
writeOptionalString(((CorruptIndexException) throwable).getResourceDescription());
writeMessage = false;
} else if (throwable instanceof IndexFormatTooNewException) {
writeVInt(2);
writeOptionalString(((IndexFormatTooNewException) throwable).getResourceDescription());
writeInt(((IndexFormatTooNewException) throwable).getVersion());
writeInt(((IndexFormatTooNewException) throwable).getMinVersion());
writeInt(((IndexFormatTooNewException) throwable).getMaxVersion());
writeMessage = false;
writeCause = false;
} else if (throwable instanceof IndexFormatTooOldException) {
writeVInt(3);
IndexFormatTooOldException t = (IndexFormatTooOldException) throwable;
writeOptionalString(t.getResourceDescription());
if (t.getVersion() == null) {
writeBoolean(false);
writeOptionalString(t.getReason());
} else {
writeBoolean(true);
writeInt(t.getVersion());
writeInt(t.getMinVersion());
writeInt(t.getMaxVersion());
}
writeMessage = false;
writeCause = false;
} else if (throwable instanceof NullPointerException) {
writeVInt(4);
writeCause = false;
} else if (throwable instanceof NumberFormatException) {
writeVInt(5);
writeCause = false;
} else if (throwable instanceof IllegalArgumentException) {
writeVInt(6);
} else if (throwable instanceof AlreadyClosedException) {
writeVInt(7);
} else if (throwable instanceof EOFException) {
writeVInt(8);
writeCause = false;
} else if (throwable instanceof SecurityException) {
writeVInt(9);
} else if (throwable instanceof StringIndexOutOfBoundsException) {
writeVInt(10);
writeCause = false;
} else if (throwable instanceof ArrayIndexOutOfBoundsException) {
writeVInt(11);
writeCause = false;
} else if (throwable instanceof FileNotFoundException) {
writeVInt(12);
writeCause = false;
} else if (throwable instanceof FileSystemException) {
writeVInt(13);
if (throwable instanceof NoSuchFileException) {
writeVInt(0);
} else if (throwable instanceof NotDirectoryException) {
writeVInt(1);
} else if (throwable instanceof DirectoryNotEmptyException) {
writeVInt(2);
} else if (throwable instanceof AtomicMoveNotSupportedException) {
writeVInt(3);
} else if (throwable instanceof FileAlreadyExistsException) {
writeVInt(4);
} else if (throwable instanceof AccessDeniedException) {
writeVInt(5);
} else if (throwable instanceof FileSystemLoopException) {
writeVInt(6);
} else {
writeVInt(7);
}
writeOptionalString(((FileSystemException) throwable).getFile());
writeOptionalString(((FileSystemException) throwable).getOtherFile());
writeOptionalString(((FileSystemException) throwable).getReason());
writeCause = false;
} else if (throwable instanceof IllegalStateException) {
writeVInt(14);
} else if (throwable instanceof LockObtainFailedException) {
writeVInt(15);
} else if (throwable instanceof InterruptedException) {
writeVInt(16);
writeCause = false;
} else if (throwable instanceof IOException) {
writeVInt(17);
} else {
ElasticsearchException ex;
if (throwable instanceof ElasticsearchException && ElasticsearchException.isRegistered(throwable.getClass(), version)) {
ex = (ElasticsearchException) throwable;
} else {
ex = new NotSerializableExceptionWrapper(throwable);
}
writeVInt(0);
writeVInt(ElasticsearchException.getId(ex.getClass()));
ex.writeTo(this);
return;
}
if (writeMessage) {
writeOptionalString(throwable.getMessage());
}
if (writeCause) {
writeException(throwable.getCause());
}
ElasticsearchException.writeStackTraces(throwable, this);
}
}
use of java.nio.file.FileSystemLoopException in project elasticsearch by elastic.
the class ExceptionSerializationTests method testFileSystemExceptions.
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());
}
}
}
use of java.nio.file.FileSystemLoopException in project j2objc by google.
the class Files2Test method test_walkFileTree$Path$FileVisitor_FileSystemLoopException.
@Test
public void test_walkFileTree$Path$FileVisitor_FileSystemLoopException() throws IOException {
// Directory structure.
// .
// ├── DATA_FILE
// └── root
// └── dir1
// └── file1
//
// file1 is symlink to dir1
// Directory Setup.
Path rootDir = filesSetup.getPathInTestDir("root");
Path dir1 = filesSetup.getPathInTestDir("root/dir1");
Path file1 = filesSetup.getPathInTestDir("root/dir1/file1");
Files.createDirectories(dir1);
Files.createSymbolicLink(file1, dir1.toAbsolutePath());
assertEquals(dir1.getFileName(), Files.readSymbolicLink(file1).getFileName());
Map<Object, VisitOption> dirMap = new HashMap<>();
Set<FileVisitOption> option = new HashSet<>();
option.add(FileVisitOption.FOLLOW_LINKS);
try {
Files.walkFileTree(rootDir, option, Integer.MAX_VALUE, new Files2Test.TestFileVisitor(dirMap));
fail();
} catch (FileSystemLoopException expected) {
}
}
use of java.nio.file.FileSystemLoopException in project crate by crate.
the class LocalFsFileInput method expandUri.
@Override
public List<URI> expandUri() throws IOException {
if (preGlobUri == null) {
return List.of(uri);
}
Path preGlobPath = Paths.get(preGlobUri);
if (!Files.isDirectory(preGlobPath)) {
preGlobPath = preGlobPath.getParent();
if (preGlobPath == null) {
return List.of();
}
}
if (Files.notExists(preGlobPath)) {
return List.of();
}
final int fileURIDepth = countOccurrences(uri.toString(), '/');
final int maxDepth = fileURIDepth - countOccurrences(preGlobUri.toString(), '/') + 1;
final List<URI> uris = new ArrayList<>();
var fileVisitor = new SimpleFileVisitor<Path>() {
@Override
public FileVisitResult visitFileFailed(Path file, IOException exc) throws IOException {
if (exc instanceof AccessDeniedException) {
return FileVisitResult.CONTINUE;
}
if (exc instanceof FileSystemLoopException) {
final int maxDepth = fileURIDepth - countOccurrences(file.toUri().toString(), '/') + 1;
if (maxDepth >= 0) {
Files.walkFileTree(file, EnumSet.of(FOLLOW_LINKS), maxDepth, this);
}
return FileVisitResult.CONTINUE;
}
throw exc;
}
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) {
URI uri = file.toUri();
if (uriPredicate.test(uri)) {
uris.add(uri);
}
return FileVisitResult.CONTINUE;
}
};
Files.walkFileTree(preGlobPath, EnumSet.of(FOLLOW_LINKS), maxDepth, fileVisitor);
return uris;
}
Aggregations