Search in sources :

Example 41 with Path

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);
    }
}
Also used : Path(java.nio.file.Path) Test(org.junit.Test)

Example 42 with Path

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)));
}
Also used : Path(java.nio.file.Path) File(java.io.File) URL(java.net.URL) Writer(java.io.Writer) Test(org.junit.Test)

Example 43 with Path

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);
    }
}
Also used : Path(java.nio.file.Path) FileChooser(javafx.stage.FileChooser) IOException(java.io.IOException) File(java.io.File) FXML(javafx.fxml.FXML)

Example 44 with Path

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);
    }
}
Also used : Path(java.nio.file.Path) OutputStream(java.io.OutputStream) OutputStreamWriter(java.io.OutputStreamWriter) IOException(java.io.IOException) OutputStreamWriter(java.io.OutputStreamWriter) Writer(java.io.Writer)

Example 45 with Path

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);
}
Also used : Path(java.nio.file.Path) IOException(java.io.IOException) FileManager(org.apache.logging.log4j.core.appender.FileManager) PluginFactory(org.apache.logging.log4j.core.config.plugins.PluginFactory)

Aggregations

Path (java.nio.file.Path)4893 Test (org.junit.Test)1960 IOException (java.io.IOException)829 File (java.io.File)445 SourcePath (com.facebook.buck.rules.SourcePath)389 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)334 BuildTarget (com.facebook.buck.model.BuildTarget)320 ArrayList (java.util.ArrayList)313 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)250 ProjectWorkspace (com.facebook.buck.testutil.integration.ProjectWorkspace)231 PathSourcePath (com.facebook.buck.rules.PathSourcePath)226 InputStream (java.io.InputStream)210 ImmutableList (com.google.common.collect.ImmutableList)175 FakeSourcePath (com.facebook.buck.rules.FakeSourcePath)166 HashMap (java.util.HashMap)159 ImmutableMap (com.google.common.collect.ImmutableMap)157 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)154 Matchers.containsString (org.hamcrest.Matchers.containsString)148 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)147 Map (java.util.Map)146