use of java.nio.file.Path in project crate by crate.
the class CrateMetaDataUpgradeServiceTest method testSnapshotRestore.
@Test
public void testSnapshotRestore() throws Exception {
Path repoDir = startUpNodeWithRepoDir();
execute("create repository test_repo TYPE fs WITH (location='" + repoDir.toAbsolutePath() + "')");
execute("restore snapshot test_repo.test_upgrade_required TABLE test_upgrade_required " + "WITH (wait_for_completion=true)");
execute("restore snapshot test_repo.test_upgrade_required_parted TABLE test_upgrade_required_parted " + "WITH (wait_for_completion=true)");
ensureYellow();
execute("select routing_hash_function, version " + "from information_schema.tables " + "where table_name in ('test_upgrade_required', 'test_upgrade_required_parted') order by table_name");
assertThat(response.rowCount(), is(2L));
assertThat(response.rows()[0][0], is("Djb"));
assertThat(response.rows()[1][0], is(DocIndexMetaData.DEFAULT_ROUTING_HASH_FUNCTION_PRETTY_NAME));
TestingHelpers.assertCrateVersion(response.rows()[0][1], null, Version.CURRENT);
TestingHelpers.assertCrateVersion(response.rows()[1][1], null, Version.CURRENT);
execute("select routing_hash_function, version " + "from information_schema.table_partitions " + "where table_name = 'test_upgrade_required_parted'");
assertThat(response.rowCount(), is(5L));
for (Object[] row : response.rows()) {
assertThat(row[0], is("Djb"));
TestingHelpers.assertCrateVersion(row[1], null, Version.CURRENT);
}
}
use of java.nio.file.Path in project cucumber-jvm by cucumber.
the class URLOutputStreamTest method write_to_file_without_existing_parent_directory.
@Test
public void write_to_file_without_existing_parent_directory() throws IOException, URISyntaxException {
Path filesWithoutParent = Files.createTempDirectory("filesWithoutParent");
String baseURL = filesWithoutParent.toUri().toURL().toString();
URL urlWithoutParentDirectory = new URL(baseURL + "/non/existing/directory");
Writer w = new UTF8OutputStreamWriter(new URLOutputStream(urlWithoutParentDirectory));
w.write("Hellesøy");
w.close();
File testFile = new File(urlWithoutParentDirectory.toURI());
assertEquals("Hellesøy", FixJava.readReader(openUTF8FileReader(testFile)));
}
use of java.nio.file.Path in project cryptomator by cryptomator.
the class MainController method didClickCreateNewVault.
@FXML
private void didClickCreateNewVault(ActionEvent event) {
final FileChooser fileChooser = new FileChooser();
final File file = fileChooser.showSaveDialog(mainWindow);
if (file == null) {
return;
}
try {
final Path vaultDir = file.toPath();
if (!Files.exists(vaultDir)) {
Files.createDirectory(vaultDir);
}
addVault(vaultDir, true);
} catch (IOException e) {
LOG.error("Unable to create vault", e);
}
}
use of java.nio.file.Path in project cryptomator by cryptomator.
the class SettingsProvider method save.
private void save(Settings settings) {
assert settings != null : "method should only be invoked by #scheduleSave, which checks for null";
final Path settingsPath = getSettingsPath();
try {
Files.createDirectories(settingsPath.getParent());
try (//
OutputStream out = Files.newOutputStream(settingsPath, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING);
Writer writer = new OutputStreamWriter(out, StandardCharsets.UTF_8)) {
gson.toJson(settings, writer);
LOG.info("Settings saved to " + settingsPath);
}
} catch (IOException e) {
LOG.error("Failed to save settings.", e);
}
}
use of java.nio.file.Path in project cryptomator by cryptomator.
the class ConfigurableFileAppender method createAppender.
@PluginFactory
public static AbstractAppender createAppender(@PluginAttribute("name") final String name, @PluginAttribute("pathPropertyName") final String pathPropertyName, @PluginAttribute("append") final String append, @PluginElement("Layout") Layout<? extends Serializable> layout) {
if (name == null) {
LOGGER.error("No name provided for ConfigurableFileAppender");
return null;
}
if (pathPropertyName == null) {
LOGGER.error("No pathPropertyName provided for ConfigurableFileAppender with name " + name);
return null;
}
final String fileName = System.getProperty(pathPropertyName);
if (Strings.isEmpty(fileName)) {
LOGGER.warn("No log file location provided in system property \"" + pathPropertyName + "\"");
return null;
}
final Path filePath = parsePath(fileName);
if (filePath == null) {
LOGGER.warn("Invalid path \"" + fileName + "\"");
return null;
}
if (!Files.exists(filePath.getParent())) {
try {
Files.createDirectories(filePath.getParent());
} catch (IOException e) {
LOGGER.error("Could not create parent directories for log file located at " + filePath.toString(), e);
return null;
}
}
final boolean shouldAppend = Booleans.parseBoolean(append, true);
if (layout == null) {
layout = PatternLayout.createDefaultLayout();
}
final FileManager manager = FileManager.getFileManager(filePath.toString(), shouldAppend, false, true, null, layout, DEFAULT_BUFFER_SIZE);
return new ConfigurableFileAppender(name, layout, null, manager);
}
Aggregations