use of java.nio.file.NoSuchFileException in project sis by apache.
the class FolderStoreProvider method open.
/**
* Shared implementation of public {@code open(…)} methods.
* Note that this method may modify the given {@code options} set for its own purpose.
*
* @param connector information about the storage (URL, path, <i>etc</i>).
* @param format format name for directory content, or {@code null} if unspecified.
* @param options whether to create a new directory, overwrite existing content, <i>etc</i>.
*/
private DataStore open(final StorageConnector connector, final String format, final EnumSet<StandardOpenOption> options) throws DataStoreException {
/*
* Determine now the provider to use for directory content. We do that for determining if the component
* has write capability. If not, then the WRITE, CREATE and related options will be ignored. If we can
* not determine whether the component store has write capabilities (i.e. if canWrite(…) returns null),
* assume that the answer is "yes".
*/
final DataStoreProvider componentProvider;
if (format != null) {
componentProvider = StoreUtilities.providerByFormatName(format.trim());
if (Boolean.FALSE.equals(StoreUtilities.canWrite(componentProvider.getClass()))) {
// No write capability.
options.clear();
}
} else {
componentProvider = null;
// Can not write if we don't know the components format.
options.clear();
}
final Path path = connector.getStorageAs(Path.class);
final Store store;
try {
/*
* If the user asked to create a new directory, we need to perform this task before
* to create the Store (otherwise constructor will fail with NoSuchFileException).
* In the particular case of CREATE_NEW, we unconditionally attempt to create the
* directory in order to rely on the atomic check performed by Files.createDirectory(…).
*/
boolean isNew = false;
if (options.contains(StandardOpenOption.CREATE)) {
if (options.contains(StandardOpenOption.CREATE_NEW) || Files.notExists(path)) {
// IOException if the directory already exists.
Files.createDirectory(path);
isNew = true;
}
}
if (isNew || (options.contains(StandardOpenOption.WRITE) && Files.isWritable(path))) {
// May throw NoSuchFileException.
store = new WritableStore(this, connector, path, componentProvider);
} else {
// May throw NoSuchFileException.
store = new Store(this, connector, path, componentProvider);
}
/*
* If there is a destructive operation to perform (TRUNCATE_EXISTING), do it last only
* after we have successfully created the data store. The check for directory existence
* is also done after creation to be sure to check the path used by the store.
*/
if (!Files.isDirectory(path)) {
throw new DataStoreException(Resources.format(Resources.Keys.FileIsNotAResourceDirectory_1, path));
}
if (options.contains(StandardOpenOption.TRUNCATE_EXISTING)) {
WritableStore.deleteRecursively(path, false);
}
} catch (IOException e) {
/*
* In case of error, Java FileSystem implementation tries to throw a specific exception
* (NoSuchFileException or FileAlreadyExistsException), but this is not guaranteed.
*/
int isDirectory = 0;
final short errorKey;
if (e instanceof FileAlreadyExistsException) {
if (path != null && Files.isDirectory(path)) {
isDirectory = 1;
}
errorKey = Resources.Keys.FileAlreadyExists_2;
} else if (e instanceof NoSuchFileException) {
errorKey = Resources.Keys.NoSuchResourceDirectory_1;
} else {
errorKey = Resources.Keys.CanNotCreateFolderStore_1;
}
throw new DataStoreException(Resources.format(errorKey, (path != null) ? path : connector.getStorageName(), isDirectory), e);
}
return store;
}
use of java.nio.file.NoSuchFileException in project Wurst-MC-1.12 by Wurst-Imperium.
the class ClickGui method init.
public void init() {
LinkedHashMap<Category, Window> windowMap = new LinkedHashMap<>();
for (Category category : Category.values()) windowMap.put(category, new Window(category.getName()));
ArrayList<Feature> features = new ArrayList<>();
features.addAll(WurstClient.INSTANCE.mods.getAllMods());
features.addAll(WurstClient.INSTANCE.commands.getAllCommands());
features.addAll(WurstClient.INSTANCE.special.getAllFeatures());
for (Feature f : features) if (f.getCategory() != null)
windowMap.get(f.getCategory()).add(new FeatureButton(f));
windows.addAll(windowMap.values());
int x = 5;
int y = 5;
ScaledResolution sr = new ScaledResolution(Minecraft.getMinecraft());
for (Window window : windows) {
window.pack();
window.setMinimized(true);
if (x + window.getWidth() + 5 > sr.getScaledWidth()) {
x = 5;
y += 18;
}
window.setX(x);
window.setY(y);
x += window.getWidth() + 5;
}
JsonObject json;
try (BufferedReader reader = Files.newBufferedReader(windowsFile)) {
json = JsonUtils.jsonParser.parse(reader).getAsJsonObject();
} catch (NoSuchFileException e) {
saveWindows();
return;
} catch (Exception e) {
System.out.println("Failed to load " + windowsFile.getFileName());
e.printStackTrace();
saveWindows();
return;
}
for (Window window : windows) {
JsonElement jsonWindow = json.get(window.getTitle());
if (jsonWindow == null || !jsonWindow.isJsonObject())
continue;
JsonElement jsonX = jsonWindow.getAsJsonObject().get("x");
if (jsonX.isJsonPrimitive() && jsonX.getAsJsonPrimitive().isNumber())
window.setX(jsonX.getAsInt());
JsonElement jsonY = jsonWindow.getAsJsonObject().get("y");
if (jsonY.isJsonPrimitive() && jsonY.getAsJsonPrimitive().isNumber())
window.setY(jsonY.getAsInt());
JsonElement jsonMinimized = jsonWindow.getAsJsonObject().get("minimized");
if (jsonMinimized.isJsonPrimitive() && jsonMinimized.getAsJsonPrimitive().isBoolean())
window.setMinimized(jsonMinimized.getAsBoolean());
JsonElement jsonPinned = jsonWindow.getAsJsonObject().get("pinned");
if (jsonPinned.isJsonPrimitive() && jsonPinned.getAsJsonPrimitive().isBoolean())
window.setPinned(jsonPinned.getAsBoolean());
}
saveWindows();
}
use of java.nio.file.NoSuchFileException in project Wurst-MC-1.12 by Wurst-Imperium.
the class KeybindList method init.
public void init() {
JsonObject json;
try (BufferedReader reader = Files.newBufferedReader(path)) {
json = JsonUtils.jsonParser.parse(reader).getAsJsonObject();
} catch (NoSuchFileException e) {
loadDefaults();
return;
} catch (Exception e) {
System.out.println("Failed to load " + path.getFileName());
e.printStackTrace();
loadDefaults();
return;
}
keybinds.clear();
TreeMap<String, String> keybinds2 = new TreeMap<>();
for (Entry<String, JsonElement> entry : json.entrySet()) {
String key = entry.getKey().toUpperCase();
if (Keyboard.getKeyIndex(key) == Keyboard.KEY_NONE)
continue;
JsonElement value = entry.getValue();
String commands;
if (value.isJsonPrimitive() && value.getAsJsonPrimitive().isString())
commands = value.getAsString();
else if (value.isJsonArray()) {
ArrayList<String> commands2 = new ArrayList<>();
for (JsonElement e : value.getAsJsonArray()) if (e.isJsonPrimitive() && e.getAsJsonPrimitive().isString())
commands2.add(e.getAsString());
commands = String.join(";", commands2);
} else
continue;
keybinds2.put(key, commands);
}
for (Entry<String, String> entry : keybinds2.entrySet()) keybinds.add(new Keybind(entry.getKey(), entry.getValue()));
save();
}
use of java.nio.file.NoSuchFileException in project OpenOLAT by OpenOLAT.
the class QTIImportProcessor method processSidecarMetadata.
private boolean processSidecarMetadata(QuestionItemImpl item, DocInfos docInfos) {
InputStream metadataIn = null;
try {
Path path = docInfos.root;
if (path != null && path.getFileName() != null) {
Path metadata = path.resolve(path.getFileName().toString() + "_metadata.xml");
metadataIn = Files.newInputStream(metadata);
SAXReader reader = new SAXReader();
Document document = reader.read(metadataIn);
Element rootElement = document.getRootElement();
QTIMetadataConverter enricher = new QTIMetadataConverter(rootElement, qItemTypeDao, qEduContextDao, qpoolService);
enricher.toQuestion(item);
}
return true;
} catch (NoSuchFileException e) {
// nothing to do
return true;
} catch (Exception e) {
log.error("", e);
return false;
} finally {
IOUtils.closeQuietly(metadataIn);
}
}
use of java.nio.file.NoSuchFileException in project microservice_framework by CJSCommonPlatform.
the class SubscriptionDescriptorParser method read.
public SubscriptionDescriptor read(final Path absolutePath) {
try {
subscriptionDescriptorFileValidator.validate(absolutePath);
final ObjectMapper mapper = new ObjectMapper(new YAMLFactory()).registerModule(new Jdk8Module()).registerModule(new ParameterNamesModule(PROPERTIES));
mapper.setPropertyNamingStrategy(PropertyNamingStrategy.CAMEL_CASE_TO_LOWER_CASE_WITH_UNDERSCORES);
return mapper.readValue(absolutePath.toFile(), SubscriptionDescriptorDef.class).getSubscriptionDescriptor();
} catch (final NoSuchFileException e) {
throw new SubscriptionDescriptorException(format("No such subscriptions YAML file %s ", absolutePath), e);
} catch (final ValidationException e) {
throw new SubscriptionDescriptorException(format("Failed to validate subscriptions yaml file %s ", absolutePath), e);
} catch (final IOException e) {
throw new SubscriptionDescriptorException(format("Failed to read subscriptions yaml file %s ", absolutePath), e);
}
}
Aggregations