Example usage for java.nio.file Path toAbsolutePath

List of usage examples for java.nio.file Path toAbsolutePath

Introduction

In this page you can find the example usage for java.nio.file Path toAbsolutePath.

Prototype

Path toAbsolutePath();

Source Link

Document

Returns a Path object representing the absolute path of this path.

Usage

From source file:org.ballerinalang.internal.file.InternalFileTest.java

@BeforeClass
public void setup() throws IOException {
    Path balPath = Paths.get("src", "test", "resources", "test-src", "file", "file-test.bal");
    fileOperationProgramFile = BCompileUtil.compile(balPath.toAbsolutePath().toString());
    workingDirPath = Files.createTempDirectory("internal-package-file-test-");
    File workingDir = new File(workingDirPath.toString());
    FileUtils.deleteQuietly(workingDir);
}

From source file:com.facebook.buck.zip.UnzipTest.java

@Test
public void testExtractSymlink() throws IOException {
    assumeThat(Platform.detect(), Matchers.is(Matchers.not(Platform.WINDOWS)));

    // Create a simple zip archive using apache's commons-compress to store executable info.
    try (ZipArchiveOutputStream zip = new ZipArchiveOutputStream(zipFile.toFile())) {
        ZipArchiveEntry entry = new ZipArchiveEntry("link.txt");
        entry.setUnixMode((int) MoreFiles.S_IFLNK);
        String target = "target.txt";
        entry.setSize(target.getBytes(Charsets.UTF_8).length);
        entry.setMethod(ZipEntry.STORED);
        zip.putArchiveEntry(entry);/*from   w w  w . ja va  2s  . c  o  m*/
        zip.write(target.getBytes(Charsets.UTF_8));
        zip.closeArchiveEntry();
    }

    // Now run `Unzip.extractZipFile` on our test zip and verify that the file is executable.
    Path extractFolder = tmpFolder.newFolder();
    Unzip.extractZipFile(zipFile.toAbsolutePath(), extractFolder.toAbsolutePath(),
            Unzip.ExistingFileMode.OVERWRITE);
    Path link = extractFolder.toAbsolutePath().resolve("link.txt");
    assertTrue(Files.isSymbolicLink(link));
    assertThat(Files.readSymbolicLink(link).toString(), Matchers.equalTo("target.txt"));
}

From source file:com.zestedesavoir.zestwriter.model.Content.java

@Override
public String getFilePath() {
    Path path = Paths.get(getBasePath());
    return path.toAbsolutePath().toString();
}

From source file:com.mesosphere.dcos.cassandra.common.config.Location.java

/**
 * Writes the Location as a Properties file.
 *
 * @param path The Path indicating where the Location will be written.
 * @throws IOException If the Location can not be written to path.
 *///w  ww  . j  a v a 2s .co  m
public void writeProperties(Path path) throws IOException {
    logger.info("Writing properties to path: " + path.toAbsolutePath());
    PrintWriter writer = new PrintWriter(path.toString(), "UTF-8");
    writer.println("dc=" + dataCenter);
    writer.println("rack=" + rack);
    writer.close();
}

From source file:org.wte4j.ui.config.StandaloneJPAConfig.java

@Bean
@Lazy// w w w .j a  v a2  s .  co m
public Server hsqlServer() {
    Path path = Paths.get(env.getProperty("java.io.tmpdir"), "hsql", "wte4j");
    String pathAsString = path.toAbsolutePath().toString();
    logger.info("dblocation: {}", pathAsString);

    HsqlProperties p = new HsqlProperties();
    p.setProperty("server.database.0", "file:" + pathAsString);
    p.setProperty("server.dbname.0", "wte4j");
    try {
        Server server = new Server();
        server.setProperties(p);
        return server;
    } catch (Exception e) {
        throw new BeanInitializationException("can not creat hsql server bean", e);
    }
}

From source file:com.github.ffremont.microservices.springboot.node.tasks.InstallPropertiesTask.java

@Override
public void run(MicroServiceTask task) throws InvalidInstallationException {
    Path msVersionFolder = helper.targetDirOf(task.getMs());

    byte[] content = msService.getContentOfProperties(task.getMs().getName());
    Path applicationProp = Paths.get(msVersionFolder.toString(), "application.properties");
    try {//from  www  .j  a va2  s.c  o m
        Files.write(applicationProp, content);
        LOG.info("Cration du fichier de proprits {}", applicationProp.toAbsolutePath());
    } catch (IOException ex) {
        throw new InvalidInstallationException("Impossible d'installer le fichier de properties", ex);
    }
}

From source file:org.xlrnet.tibaija.tools.fontgen.FontgenApplication.java

private Symbol importFile(Path path, Font font, String fontIdentifier) throws IOException, ImageReadException {
    LOGGER.info("Importing file {} ...", path.toAbsolutePath());

    BufferedImage image = Imaging.getBufferedImage(Files.newInputStream(path));
    int width = image.getWidth();
    int height = image.getHeight();
    int finalWidth = width / 2;
    int finalHeight = height / 2;

    if (width % 2 != 0 || height % 2 != 0) {
        LOGGER.warn("Width and height must be multiple of 2");
        return null;
    }/*  www.j  ava 2 s . co m*/

    Symbol symbol = new Symbol();
    PixelState[][] pixelStates = new PixelState[finalHeight][finalWidth];
    Raster imageData = image.getData();

    for (int y = 0; y < finalHeight; y++) {
        for (int x = 0; x < finalWidth; x++) {
            int sample = imageData.getSample(x * 2, y * 2, 0);
            PixelState pixelState = sample == 0 ? PixelState.ON : PixelState.OFF;
            pixelStates[y][x] = pixelState;
        }
    }

    symbol.setData(pixelStates);
    return symbol;
}

From source file:com.bytelightning.opensource.pokerface.PokerFace.java

/**
 * This is where Nashorn compiles the script, evals it into global scope to get an endpoint, and invokes the setup method of the endpoint.
 * @param rootPath   The root script directory path to assist in building a relative uri type path to discovered scripts.
 * @param f   The javascript file.//from ww  w.j  a va 2 s  . com
 * @param uriKey   A "pass-back-by-reference" construct to w
 * @return
 */
private static void MakeJavaScriptEndPointDescriptor(Path rootPath, Path f,
        HierarchicalConfiguration scriptConfig, EndpointSetupCompleteCallback cb) {
    CompiledScript compiledScript;
    try (Reader r = Files.newBufferedReader(f, Charset.forName("utf-8"))) {
        compiledScript = ((Compilable) Nashorn).compile(r);
    } catch (Throwable e) {
        cb.setupFailed(f, "Unable to load and compile script at " + f.toAbsolutePath().toString(), e);
        return;
    }
    ScriptObjectMirror obj;
    try {
        obj = (ScriptObjectMirror) compiledScript.eval(Nashorn.getBindings(ScriptContext.GLOBAL_SCOPE));
    } catch (Throwable e) {
        cb.setupFailed(f, "Unable to eval the script at " + f.toAbsolutePath().toString(), e);
        return;
    }
    assert f.startsWith(rootPath);
    String uriKey = FileToUriKey(rootPath, f);
    final JavaScriptEndPoint retVal = new JavaScriptEndPoint(uriKey, obj);

    try {
        if (obj.hasMember("setup")) {
            obj.callMember("setup", uriKey, scriptConfig, ScriptHelper.ScriptLogger,
                    new SetupCompleteCallback() {
                        @Override
                        public void setupComplete() {
                            cb.setupComplete(retVal);
                        }

                        @Override
                        public void setupFailed(String msg) {
                            cb.setupFailed(f, msg, null);
                        }
                    });
        } else {
            cb.setupComplete(retVal);
        }
    } catch (Throwable e) {
        cb.setupFailed(f, "The script at " + f.toAbsolutePath().toString()
                + " did not expose the expected 'setup' method", e);
        return;
    }
}

From source file:org.apache.nifi.processors.standard.util.SSHTestServer.java

public void startServer() throws IOException {
    sshd = SshServer.setUpDefaultServer();
    sshd.setHost("localhost");

    sshd.setKeyPairProvider(new SimpleGeneratorHostKeyProvider());

    //Accept all keys for authentication
    sshd.setPublickeyAuthenticator((s, publicKey, serverSession) -> true);

    //Allow username/password authentication using pre-defined credentials
    sshd.setPasswordAuthenticator((username, password, serverSession) -> this.username.equals(username)
            && this.password.equals(password));

    //Setup Virtual File System (VFS)
    //Ensure VFS folder exists
    Path dir = Paths.get(getVirtualFileSystemPath());
    Files.createDirectories(dir);
    sshd.setFileSystemFactory(new VirtualFileSystemFactory(dir.toAbsolutePath()));

    //Add SFTP support
    List<NamedFactory<Command>> sftpCommandFactory = new ArrayList<>();
    sftpCommandFactory.add(new SftpSubsystemFactory());
    sshd.setSubsystemFactories(sftpCommandFactory);

    sshd.start();/*w w  w  . j  av  a 2 s  .c om*/
}

From source file:org.apache.beam.sdk.io.TextIOTest.java

License:asdf

public static void assertOutputFiles(String[] elems, final String header, final String footer, int numShards,
        Path rootLocation, String outputName, String shardNameTemplate) throws Exception {
    List<File> expectedFiles = new ArrayList<>();
    if (numShards == 0) {
        String pattern = rootLocation.toAbsolutePath().resolve(outputName + "*").toString();
        List<MatchResult> matches = FileSystems.match(Collections.singletonList(pattern));
        for (Metadata expectedFile : Iterables.getOnlyElement(matches).metadata()) {
            expectedFiles.add(new File(expectedFile.resourceId().toString()));
        }//from w  w w  . j av  a2 s. c om
    } else {
        for (int i = 0; i < numShards; i++) {
            expectedFiles.add(new File(rootLocation.toString(),
                    DefaultFilenamePolicy.constructName(outputName, shardNameTemplate, "", i, numShards)));
        }
    }

    List<List<String>> actual = new ArrayList<>();

    for (File tmpFile : expectedFiles) {
        try (BufferedReader reader = new BufferedReader(new FileReader(tmpFile))) {
            List<String> currentFile = new ArrayList<>();
            for (;;) {
                String line = reader.readLine();
                if (line == null) {
                    break;
                }
                currentFile.add(line);
            }
            actual.add(currentFile);
        }
    }

    List<String> expectedElements = new ArrayList<>(elems.length);
    for (String elem : elems) {
        byte[] encodedElem = CoderUtils.encodeToByteArray(StringUtf8Coder.of(), elem);
        String line = new String(encodedElem);
        expectedElements.add(line);
    }

    List<String> actualElements = Lists.newArrayList(Iterables
            .concat(FluentIterable.from(actual).transform(removeHeaderAndFooter(header, footer)).toList()));

    assertThat(actualElements, containsInAnyOrder(expectedElements.toArray()));

    assertTrue(Iterables.all(actual, haveProperHeaderAndFooter(header, footer)));
}