use of java.nio.file.NotDirectoryException in project elasticsearch by elastic.
the class StreamInput method readException.
public <T extends Exception> T readException() throws IOException {
if (readBoolean()) {
int key = readVInt();
switch(key) {
case 0:
final int ord = readVInt();
return (T) ElasticsearchException.readException(this, ord);
case 1:
String msg1 = readOptionalString();
String resource1 = readOptionalString();
return (T) readStackTrace(new CorruptIndexException(msg1, resource1, readException()), this);
case 2:
String resource2 = readOptionalString();
int version2 = readInt();
int minVersion2 = readInt();
int maxVersion2 = readInt();
return (T) readStackTrace(new IndexFormatTooNewException(resource2, version2, minVersion2, maxVersion2), this);
case 3:
String resource3 = readOptionalString();
if (readBoolean()) {
int version3 = readInt();
int minVersion3 = readInt();
int maxVersion3 = readInt();
return (T) readStackTrace(new IndexFormatTooOldException(resource3, version3, minVersion3, maxVersion3), this);
} else {
String version3 = readOptionalString();
return (T) readStackTrace(new IndexFormatTooOldException(resource3, version3), this);
}
case 4:
return (T) readStackTrace(new NullPointerException(readOptionalString()), this);
case 5:
return (T) readStackTrace(new NumberFormatException(readOptionalString()), this);
case 6:
return (T) readStackTrace(new IllegalArgumentException(readOptionalString(), readException()), this);
case 7:
return (T) readStackTrace(new AlreadyClosedException(readOptionalString(), readException()), this);
case 8:
return (T) readStackTrace(new EOFException(readOptionalString()), this);
case 9:
return (T) readStackTrace(new SecurityException(readOptionalString(), readException()), this);
case 10:
return (T) readStackTrace(new StringIndexOutOfBoundsException(readOptionalString()), this);
case 11:
return (T) readStackTrace(new ArrayIndexOutOfBoundsException(readOptionalString()), this);
case 12:
return (T) readStackTrace(new FileNotFoundException(readOptionalString()), this);
case 13:
final int subclass = readVInt();
final String file = readOptionalString();
final String other = readOptionalString();
final String reason = readOptionalString();
// skip the msg - it's composed from file, other and reason
readOptionalString();
final Exception exception;
switch(subclass) {
case 0:
exception = new NoSuchFileException(file, other, reason);
break;
case 1:
exception = new NotDirectoryException(file);
break;
case 2:
exception = new DirectoryNotEmptyException(file);
break;
case 3:
exception = new AtomicMoveNotSupportedException(file, other, reason);
break;
case 4:
exception = new FileAlreadyExistsException(file, other, reason);
break;
case 5:
exception = new AccessDeniedException(file, other, reason);
break;
case 6:
exception = new FileSystemLoopException(file);
break;
case 7:
exception = new FileSystemException(file, other, reason);
break;
default:
throw new IllegalStateException("unknown FileSystemException with index " + subclass);
}
return (T) readStackTrace(exception, this);
case 14:
return (T) readStackTrace(new IllegalStateException(readOptionalString(), readException()), this);
case 15:
return (T) readStackTrace(new LockObtainFailedException(readOptionalString(), readException()), this);
case 16:
return (T) readStackTrace(new InterruptedException(readOptionalString()), this);
case 17:
return (T) readStackTrace(new IOException(readOptionalString(), readException()), this);
default:
assert false : "no such exception for id: " + key;
}
}
return null;
}
use of java.nio.file.NotDirectoryException in project Bytecoder by mirkosertic.
the class PollingWatchService method doPrivilegedRegister.
// registers directory returning a new key if not already registered or
// existing key if already registered
private PollingWatchKey doPrivilegedRegister(Path path, Set<? extends WatchEvent.Kind<?>> events, int sensitivityInSeconds) throws IOException {
// check file is a directory and get its file key if possible
BasicFileAttributes attrs = Files.readAttributes(path, BasicFileAttributes.class);
if (!attrs.isDirectory()) {
throw new NotDirectoryException(path.toString());
}
Object fileKey = attrs.fileKey();
if (fileKey == null)
throw new AssertionError("File keys must be supported");
// grab close lock to ensure that watch service cannot be closed
synchronized (closeLock()) {
if (!isOpen())
throw new ClosedWatchServiceException();
PollingWatchKey watchKey;
synchronized (map) {
watchKey = map.get(fileKey);
if (watchKey == null) {
// new registration
watchKey = new PollingWatchKey(path, this, fileKey);
map.put(fileKey, watchKey);
} else {
// update to existing registration
watchKey.disable();
}
}
watchKey.enable(events, sensitivityInSeconds);
return watchKey;
}
}
use of java.nio.file.NotDirectoryException in project jib by google.
the class CacheTest method testInit_notDirectory.
@Test
public void testInit_notDirectory() throws CacheMetadataCorruptedException, IOException {
Path tempFile = temporaryCacheDirectory.newFile().toPath();
try {
Cache.init(tempFile);
Assert.fail("Cache should not be able to initialize on non-directory");
} catch (NotDirectoryException ex) {
Assert.assertEquals("The cache can only write to a directory", ex.getMessage());
}
}
use of java.nio.file.NotDirectoryException in project vespa by vespa-engine.
the class MakeDirectory method converge.
public boolean converge(TaskContext context) {
boolean systemModified = false;
FileAttributesCache attributes = new FileAttributesCache(path);
if (attributes.exists()) {
if (!attributes.get().isDirectory()) {
throw new UncheckedIOException(new NotDirectoryException(path.toString()));
}
} else {
if (createParents) {
// We'll skip logginer system modification here, as we'll log about the creation
// of the directory next.
path.createParents();
}
context.recordSystemModification(logger, "Creating directory " + path);
systemModified = true;
Optional<String> permissions = attributeSync.getPermissions();
if (permissions.isPresent()) {
path.createDirectory(permissions.get());
} else {
path.createDirectory();
}
}
systemModified |= attributeSync.converge(context, attributes);
return systemModified;
}
use of java.nio.file.NotDirectoryException in project edi-debatcher by nullbucket.
the class DefaultConfig method toPath.
private Path toPath(final String path) throws NotDirectoryException {
if (path == null || path.isEmpty()) {
throw new NotDirectoryException("Path was empty or null");
}
final Path p = Paths.get(path);
final File f = p.toFile();
if (!f.exists() || !f.isDirectory()) {
throw new NotDirectoryException(path);
}
return p;
}
Aggregations