List of usage examples for java.nio.file Path toAbsolutePath
Path toAbsolutePath();
From source file:org.jboss.pnc.termdbuilddriver.transfer.TermdFileTranser.java
public void uploadScript(String script, Path remoteFilePath) throws TransferException { logger.debug("Uploading build script to remote path {}, build script {}", remoteFilePath, script); String scriptPath = UPLOAD_PATH + remoteFilePath.toAbsolutePath().toString(); logger.debug("Resolving script path {} to base uri {}", scriptPath, baseServerUri); URI uploadUri = baseServerUri.resolve(scriptPath); try {//from www . j a v a2s .c om HttpURLConnection connection = (HttpURLConnection) uploadUri.toURL().openConnection(); connection.setRequestMethod("PUT"); connection.setDoOutput(true); connection.setDoInput(true); byte[] fileContent = script.getBytes(); connection.setRequestProperty("Content-Length", "" + Integer.toString(fileContent.length)); try (OutputStream outputStream = connection.getOutputStream()) { outputStream.write(fileContent); } if (200 != connection.getResponseCode()) { throw new TransferException("Could not upload script to Build Agent at url " + connection.getURL() + " - Returned status code " + connection.getResponseCode()); } logger.debug("Uploaded successfully"); } catch (IOException e) { throw new TransferException("Could not upload build script: " + uploadUri.toString(), e); } }
From source file:org.sakuli.starter.SahiConnectorTest.java
@Test public void testGetIncludFolderJsPath() throws Exception { Path pathMock = mock(Path.class); when(sakuliProperties.getJsLibFolder()).thenReturn(pathMock); when(pathMock.toAbsolutePath()).thenReturn(pathMock); if (File.separator.equals("/")) { when(pathMock.toString()).thenReturn("/sakuli/src/main/include"); String result = testling.getIncludeFolderJsPath(); Assert.assertEquals("/sakuli/src/main/include/sakuli.js", result); } else {/* w w w . j a v a 2 s. co m*/ when(pathMock.toString()).thenReturn("D:\\sakuli\\src\\main\\_include"); String result = testling.getIncludeFolderJsPath(); Assert.assertEquals("D:\\\\sakuli\\\\src\\\\main\\\\_include\\\\sakuli.js", result); } }
From source file:org.tinymediamanager.core.movie.MovieRenamer.java
/** * copies file./* w w w .ja v a2 s . co m*/ * * @param oldFilename * the old filename * @param newFilename * the new filename * @return true, when we copied file OR DEST IS EXISTING */ private static boolean copyFile(Path oldFilename, Path newFilename) { if (!oldFilename.toAbsolutePath().toString().equals(newFilename.toAbsolutePath().toString())) { LOGGER.info("copy file " + oldFilename + " to " + newFilename); if (oldFilename.equals(newFilename)) { // windows: name differs, but File() is the same!!! // use move in this case, which handles this return moveFile(oldFilename, newFilename); } try { // create parent if needed if (!Files.exists(newFilename.getParent())) { Files.createDirectory(newFilename.getParent()); } Utils.copyFileSafe(oldFilename, newFilename, true); return true; } catch (Exception e) { return false; } } else { // file is the same, return true to keep file return true; } }
From source file:com.streamsets.pipeline.lib.io.LiveFile.java
/** * Creates a <code>LiveFile</code> given a {@link Path}. * * @param path the Path of the LiveFile. The file referred by the Path must exist. * @throws IOException thrown if the LiveFile does not exist. *///w w w .jav a 2s .co m public LiveFile(Path path) throws IOException { Utils.checkNotNull(path, "path"); this.path = path.toAbsolutePath(); if (!Files.isRegularFile(this.path)) { throw new NoSuchFileException(Utils.format("Path '{}' is not a file", this.path)); } BasicFileAttributes attrs = Files.readAttributes(path, BasicFileAttributes.class); headLen = (int) Math.min(HEAD_LEN, attrs.size()); headHash = computeHash(path, headLen); iNode = attrs.fileKey().toString(); }
From source file:org.fao.geonet.api.site.SiteInformation.java
/** * Compute information about Lucene index. *//*from w w w. ja v a2 s. c o m*/ private void loadIndexInfo(ServiceContext context) throws IOException { final GeonetworkDataDirectory dataDirectory = context.getBean(GeonetworkDataDirectory.class); Path luceneDir = dataDirectory.getLuceneDir(); indexProperties.put("index.path", luceneDir.toAbsolutePath().normalize().toString()); if (Files.exists(luceneDir)) { long size = ApiUtils.sizeOfDirectory(luceneDir); indexProperties.put("index.size", "" + size); // lucene + Shapefile // if exist } indexProperties.put("index.lucene.config", context.getBean(LuceneConfig.class).toString()); }
From source file:co.runrightfast.vertx.orientdb.config.OHazelcastPluginConfig.java
public OHazelcastPluginConfig(final String nodeName, @NonNull final Path distributedDBConfigFilePath) { checkArgument(isNotBlank(nodeName), MUST_NOT_BE_BLANK, "nodeName"); checkArgument(Files.exists(distributedDBConfigFilePath), PATH_DOES_NOT_EXIST, "distributedDBConfigFilePath", distributedDBConfigFilePath.toAbsolutePath()); this.enabled = true; this.nodeName = nodeName; this.distributedDBConfigFilePath = distributedDBConfigFilePath; }
From source file:com.netflix.spinnaker.clouddriver.artifacts.gitlab.GitlabArtifactCredentialsTest.java
@Test void downloadWithTokenFromFile(@TempDirectory.TempDir Path tempDir, @WiremockResolver.Wiremock WireMockServer server) throws IOException { Path authFile = tempDir.resolve("auth-file"); Files.write(authFile, "zzz".getBytes()); GitlabArtifactAccount account = new GitlabArtifactAccount(); account.setName("my-gitlab-account"); account.setTokenFile(authFile.toAbsolutePath().toString()); runTestCase(server, account, m -> m.withHeader("Private-Token", equalTo("zzz"))); }
From source file:com.basistech.yca.FlatteningConfigFileManager.java
private String toConfigKey(Path p) { return p.toAbsolutePath().toUri().toString(); }
From source file:net.daboross.bukkitdev.skywars.score.JSONScoreStorage.java
private JSONObject loadFile(Path file) throws IOException { if (!Files.isRegularFile(file)) { throw new IOException("File '" + file.toAbsolutePath() + "' is not a file (perhaps a directory?)."); }/*from w ww .j av a 2 s . c o m*/ try (FileInputStream fis = new FileInputStream(file.toFile())) { return new JSONObject(new JSONTokener(fis)); } catch (JSONException ex) { try (FileInputStream fis = new FileInputStream(file.toFile())) { byte[] buffer = new byte[10]; int read = fis.read(buffer); String str = new String(buffer, 0, read, Charset.forName("UTF-8")); if (StringUtils.isBlank(str)) { skywars.getLogger().log(Level.WARNING, "File {} is empty, perhaps it was corrupted? Ignoring it and starting new score database. If you haven't recorded any baseJson, this won't matter.", file.toAbsolutePath()); return new JSONObject(); } } throw new IOException("JSONException loading " + file.toAbsolutePath(), ex); } }
From source file:org.sonarlint.cli.report.HtmlReport.java
HtmlReport(Path basePath, Path reportFile, Charset charset) { this.basePath = basePath; this.charset = charset; this.reportDir = reportFile.getParent().toAbsolutePath(); this.reportFile = reportFile.toAbsolutePath(); }