Java Examples for java.nio.file.Paths.get
The following java examples will help you to understand the usage of java.nio.file.Paths.get. These source code samples are taken from different open source projects.
Example 1
| Project: uberfire-master File: TestPaths.java View source code |
@Test
public void test() {
{
final String FILENAME = "file name.txt";
final org.uberfire.java.nio.file.Path path = org.uberfire.java.nio.file.Paths.get("file://reponame/path/to/").resolve(FILENAME);
assertEquals(FILENAME, path.getFileName().toString());
assertEquals(FILENAME, Paths.convert(path).getFileName());
assertEquals(FILENAME, Paths.convert(Paths.convert(path)).getFileName().toString());
System.out.println(path.toUri().toString());
System.out.println(Paths.convert(path).toURI());
System.out.println(Paths.convert(Paths.convert(path)).toUri().toString());
}
{
final String FILENAME = "file_name.txt";
final org.uberfire.java.nio.file.Path path = org.uberfire.java.nio.file.Paths.get("file://reponame/path/to/").resolve(FILENAME);
assertEquals(FILENAME, path.getFileName().toString());
assertEquals(FILENAME, Paths.convert(path).getFileName());
assertEquals(FILENAME, Paths.convert(Paths.convert(path)).getFileName().toString());
System.out.println(path.toUri().toString());
System.out.println(Paths.convert(path).toURI());
System.out.println(Paths.convert(Paths.convert(path)).toUri().toString());
}
{
final String FILENAME = "file+name.txt";
final org.uberfire.java.nio.file.Path path = org.uberfire.java.nio.file.Paths.get("file://reponame/path/to/").resolve(FILENAME);
assertEquals(FILENAME, path.getFileName().toString());
assertEquals(FILENAME, Paths.convert(path).getFileName());
assertEquals(FILENAME, Paths.convert(Paths.convert(path)).getFileName().toString());
System.out.println(path.toUri().toString());
System.out.println(Paths.convert(path).toURI());
System.out.println(Paths.convert(Paths.convert(path)).toUri().toString());
}
}Example 2
| Project: swagger-codegen-tooling-master File: YamlToJsonTest.java View source code |
@Test
public void transform() throws JsonProcessingException, IOException {
String data = getResourceContent("/kio-api.yaml");
ObjectMapper yamlMapper = Yaml.mapper();
JsonNode rootNode = yamlMapper.readTree(data);
// must have swagger node set
JsonNode swaggerNode = rootNode.get("swagger");
String rootNodeString = rootNode.toString();
System.out.println(rootNodeString);
}Example 3
| Project: Spoon-master File: TryCatchResourceClass.java View source code |
public void writeToFileZipFileContents(String zipFileName, String outputFileName) throws IOException {
java.nio.charset.Charset charset = java.nio.charset.Charset.forName("US-ASCII");
java.nio.file.Path outputFilePath = java.nio.file.Paths.get(outputFileName);
try (java.util.zip.ZipFile zf = new java.util.zip.ZipFile(zipFileName);
java.io.BufferedWriter writer = java.nio.file.Files.newBufferedWriter(outputFilePath, charset)) {
for (java.util.Enumeration<?> entries = zf.entries(); entries.hasMoreElements(); ) {
// Get the entry name and write it to the output file
String newLine = System.getProperty("line.separator");
String zipEntryName = ((java.util.zip.ZipEntry) entries.nextElement()).getName() + newLine;
writer.write(zipEntryName, 0, zipEntryName.length());
}
}
}Example 4
| Project: Aspose_Pdf_Java-master File: DisableFilesCompressionWhenAddingAsEmbeddedResources.java View source code |
public static void main(String[] args) throws Exception {
// get reference of source/input file
java.nio.file.Path path = java.nio.file.Paths.get("input.pdf");
// read all the contents from source file into ByteArray
byte[] data = java.nio.file.Files.readAllBytes(path);
// create an instance of Stream object from ByteArray contents
InputStream is = new ByteArrayInputStream(data);
// Instantiate Document object from stream instance
Document pdfDocument = new Document(is);
// setup new file to be added as attachment
FileSpecification fileSpecification = new FileSpecification("test.txt", "Sample text file");
// Specify Encoding property setting it to FileEncoding.None
fileSpecification.setEncoding(FileEncoding.None);
// add attachment to document's attachment collection
pdfDocument.getEmbeddedFiles().add(fileSpecification);
// save new output
pdfDocument.save("output.pdf");
}Example 5
| Project: bazel-master File: CompressedTarFunctionTest.java View source code |
/** Validate the content of the output directory */
private void assertOutputFiles(Path outputDir) throws Exception {
assertThat(outputDir.exists()).isTrue();
assertThat(outputDir.getRelative(REGULAR_FILE_NAME).exists()).isTrue();
assertThat(outputDir.getRelative(REGULAR_FILE_NAME).getFileSize()).isNotEqualTo(0);
assertThat(outputDir.getRelative(REGULAR_FILE_NAME).isSymbolicLink()).isFalse();
assertThat(outputDir.getRelative(HARD_LINK_FILE_NAME).exists()).isTrue();
assertThat(outputDir.getRelative(HARD_LINK_FILE_NAME).getFileSize()).isNotEqualTo(0);
assertThat(outputDir.getRelative(HARD_LINK_FILE_NAME).isSymbolicLink()).isFalse();
assertThat(outputDir.getRelative(RELATIVE_SYMBOLIC_LINK_FILE_NAME).exists()).isTrue();
assertThat(outputDir.getRelative(RELATIVE_SYMBOLIC_LINK_FILE_NAME).getFileSize()).isNotEqualTo(0);
assertThat(outputDir.getRelative(RELATIVE_SYMBOLIC_LINK_FILE_NAME).isSymbolicLink()).isTrue();
assertThat(outputDir.getRelative(ABSOLUTE_SYMBOLIC_LINK_FILE_NAME).exists()).isTrue();
assertThat(outputDir.getRelative(ABSOLUTE_SYMBOLIC_LINK_FILE_NAME).getFileSize()).isNotEqualTo(0);
assertThat(outputDir.getRelative(ABSOLUTE_SYMBOLIC_LINK_FILE_NAME).isSymbolicLink()).isTrue();
assertThat(Files.isSameFile(java.nio.file.Paths.get(outputDir.getRelative(REGULAR_FILE_NAME).toString()), java.nio.file.Paths.get(outputDir.getRelative(HARD_LINK_FILE_NAME).toString()))).isTrue();
assertThat(Files.isSameFile(java.nio.file.Paths.get(outputDir.getRelative(REGULAR_FILE_NAME).toString()), java.nio.file.Paths.get(outputDir.getRelative(RELATIVE_SYMBOLIC_LINK_FILE_NAME).toString()))).isTrue();
assertThat(Files.isSameFile(java.nio.file.Paths.get(outputDir.getRelative(REGULAR_FILE_NAME).toString()), java.nio.file.Paths.get(outputDir.getRelative(ABSOLUTE_SYMBOLIC_LINK_FILE_NAME).toString()))).isTrue();
}Example 6
| Project: neembuunow-master File: AuthorityLimitExpansionTest.java View source code |
@Test
public final void testAuthoityExpansion() throws Exception {
AtomicBoolean t1_success = new AtomicBoolean();
Thread t1 = testAtOffsetInNewThread(0, t1_success);
AtomicBoolean t2_success = new AtomicBoolean();
Thread t2 = testAtOffsetInNewThread(1024 * 1024 * 10, t2_success);
t1.join();
t2.join();
Assert.assertTrue(t1_success.get());
Assert.assertTrue(t2_success.get());
}Example 7
| Project: jumi-master File: ClasspathTest.java View source code |
@Test
public void workaround_for_Eclipse_JUnit_integration_producing_invalid_classpath_elements_on_Windows() {
// The JUnit interaction of Eclipse Kepler Service Release 1 on Windows adds to classpath
// elements which start with "/C:" and java.nio.file.Paths.get() can't handle it.
String troublesomePath = "/C:/eclipse/configuration/org.eclipse.osgi/bundles/200/1/.cp/";
Path fixedPath = Classpath.getClasspathElements(troublesomePath, ";").get(0);
assertThat(fixedPath.toString(), containsString("C:"));
assertThat(fixedPath.getFileName().toString(), is(".cp"));
}Example 8
| Project: javaee7-samples-master File: SchemaGenScriptsTest.java View source code |
@Test
@RunAsClient
public void testSchemaGenIndex() throws Exception {
Path create = get("target", "create-script.sql");
Path drop = get("target", "drop-script.sql");
assertTrue(exists(create));
assertTrue(exists(drop));
assertTrue(new String(readAllBytes(create), UTF_8).toLowerCase().contains("create table employee_schema_gen_scripts_generate"));
assertTrue(new String(readAllBytes(drop), UTF_8).toLowerCase().contains("drop table employee_schema_gen_scripts_generate"));
}Example 9
| Project: fullstop-master File: PieroneImageTest.java View source code |
@Test
public void testTryParse() throws Exception {
final Optional<PieroneImage> result = PieroneImage.tryParse(get(REPOSITORY, TEAM, ARTIFACT).toString() + ":" + TAG);
assertThat(result).isPresent();
assertThat(result.get().getRepository()).isEqualTo(REPOSITORY);
assertThat(result.get().getTeam()).isEqualTo(TEAM);
assertThat(result.get().getArtifact()).isEqualTo(ARTIFACT);
assertThat(result.get().getTag()).isEqualTo(TAG);
assertThat(pieroneImage.toString()).isEqualTo(result.get().toString());
}Example 10
| Project: reactive-ms-example-master File: RestServiceHelper.java View source code |
public static <T> Mono<T> getMonoFromJsonPath(final String jsonPath, final Class<T> type) {
try {
final URL url = RestServiceHelper.class.getResource(jsonPath);
final Path resPath = java.nio.file.Paths.get(url.toURI());
final String json = new String(java.nio.file.Files.readAllBytes(resPath), "UTF8");
return getMonoFromJson(json, type);
} catch (IOExceptionURISyntaxException | e) {
throw new RuntimeException(e);
}
}Example 11
| Project: p2-installer-master File: ShutdownHandler.java View source code |
/**
* Adds a directory to be removed after the installer has
* shutdown.
*
* @param path Path to directory
* @param onlyIfEmpty <code>true</code> to only remove directory
* if it is empty.
*/
public void addDirectoryToRemove(String path, boolean onlyIfEmpty) {
if (onlyIfEmpty) {
emptyDirectoriesToRemove.add(path);
} else {
// Set all files write-able so they can be removed.
try {
FileUtils.setWritable(java.nio.file.Paths.get(path));
} catch (IOException e) {
Installer.log(e);
}
directoriesToRemove.add(path);
}
}