List of usage examples for java.nio.file Paths get
public static Path get(URI uri)
From source file:org.createnet.search.raptor.search.query.impl.ObjectQueryTest.java
@Before public void setUp() throws IOException { ClassLoader classLoader = getClass().getClassLoader(); Path path = Paths.get(classLoader.getResource("object-query.json").getPath()); content = new String(Files.readAllBytes(path)); }
From source file:com.serli.open.data.poitiers.jobs.importer.ImportAllDataJobTest.java
public static void createDevNode() { LOGGER.info("Creating dev ES node ..."); Path localDevDataDirectory = Paths.get(ES_LOCAL_DATA); try {//w ww . jav a 2s .com FileUtils.deleteDirectory(localDevDataDirectory.toFile()); } catch (IOException e) { throw new RuntimeException(e); } Settings settings = ImmutableSettings.builder().put("http.port", "9200").put("network.host", "localhost") .put("path.data", ES_LOCAL_DATA).build(); Node node = NodeBuilder.nodeBuilder().local(true).data(true) .clusterName("elasticSearch" + UUID.randomUUID()).settings(settings).build(); node.start(); // loading settings run(ReloadDefaultSettings.class); ImportAllDataJob.elasticType = "test-ES"; ImportAllDataJob.filename = "conf/test-ES.properties"; run(ImportAllDataJob.class); }
From source file:eu.itesla_project.modules.offline.ExportMetricsTool.java
@Override public void run(CommandLine line) throws Exception { String metricsDbName = line.hasOption("metrics-db-name") ? line.getOptionValue("metrics-db-name") : OfflineConfig.DEFAULT_METRICS_DB_NAME; OfflineConfig config = OfflineConfig.load(); MetricsDb metricsDb = config.getMetricsDbFactoryClass().newInstance().create(metricsDbName); String workflowId = line.getOptionValue("workflow"); Path outputFile = Paths.get(line.getOptionValue("output-file")); char delimiter = ';'; if (line.hasOption("delimiter")) { String value = line.getOptionValue("delimiter"); if (value.length() != 1) { throw new RuntimeException("A character is expected"); }//from w w w . j av a2 s .com delimiter = value.charAt(0); } try (Writer writer = Files.newBufferedWriter(outputFile, StandardCharsets.UTF_8)) { metricsDb.exportCsv(workflowId, writer, delimiter); } }
From source file:com.kixeye.chassis.bootstrap.TestUtils.java
@SuppressWarnings("unchecked") public static void writePropertiesToFile(String path, Set<Path> filesCreated, SimpleEntry<String, String>... entries) { Properties properties = new Properties(); for (SimpleEntry<String, String> entry : entries) { properties.put(entry.getKey(), entry.getValue()); }// w w w . j a va 2 s . c o m Path p = Paths.get(SystemPropertyUtils.resolvePlaceholders(path)); try (OutputStream os = createFile(p.toString())) { properties.store(os, "test properties"); filesCreated.add(p); } catch (IOException e) { throw new RuntimeException(e); } }
From source file:ms.dew.devops.kernel.plugin.appkind.frontend_node.FrontendNodeBuildFlow.java
protected void preDockerBuild(FinalProjectConfig config, String flowBasePath) throws IOException { String preparePath = config.getTargetDirectory() + "dew_prepare" + File.separator; FileUtils.deleteDirectory(new File(flowBasePath + "dist")); Files.move(Paths.get(preparePath + "dist"), Paths.get(flowBasePath + "dist"), StandardCopyOption.REPLACE_EXISTING); if (config.getApp().getServerConfig() != null && !config.getApp().getServerConfig().isEmpty()) { Files.write(Paths.get(flowBasePath + "custom.conf"), config.getApp().getServerConfig().getBytes()); } else {//from w ww . j a v a 2 s . c o m Files.write(Paths.get(flowBasePath + "custom.conf"), "".getBytes()); } $.file.copyStreamToPath(DevOps.class.getResourceAsStream("/dockerfile/frontend_node/Dockerfile"), flowBasePath + "Dockerfile"); }
From source file:dk.lnj.swagger4ee.AbstractJSonTest.java
public void makeCompare(SWRoot root, String expFile) throws IOException { ObjectMapper mapper = new ObjectMapper(); mapper.enable(SerializationFeature.INDENT_OUTPUT); AnnotationIntrospector introspector = new JaxbAnnotationIntrospector(); // make deserializer use JAXB annotations (only) mapper.setAnnotationIntrospector(introspector); // make serializer use JAXB annotations (only) StringWriter sw = new StringWriter(); mapper.writeValue(sw, root);/*from ww w . j a v a 2s .co m*/ mapper.writeValue(new FileWriter(new File("lasttest.json")), root); String actual = sw.toString(); String expected = new String(Files.readAllBytes(Paths.get(expFile))); String[] exp_split = expected.split("\n"); String[] act_split = actual.split("\n"); for (int i = 0; i < exp_split.length; i++) { String exp = exp_split[i]; String act = act_split[i]; String shortFileName = expFile.substring(expFile.lastIndexOf("/")); Assert.assertEquals(shortFileName + ":" + (i + 1), superTrim(exp), superTrim(act)); } }
From source file:com.greglturnquist.mtom.service.StubImageRepository.java
@Override public byte[] readImage(String name) throws IOException { logger.info("Loading image " + name); Path file = Paths.get("D:\\jd.txt"); try (InputStream in = Files.newInputStream(file); BufferedReader reader = new BufferedReader(new InputStreamReader(in))) { String line = null;/* w w w . ja va 2 s. c o m*/ while ((line = reader.readLine()) != null) { System.out.println(line); } } catch (IOException x) { System.err.println(x); } ; return images.get(name); }
From source file:jgnash.convert.exportantur.csv.CsvExport.java
public static void exportAccount(final Account account, final LocalDate startDate, final LocalDate endDate, final File file) { Objects.requireNonNull(account); Objects.requireNonNull(startDate); Objects.requireNonNull(endDate); Objects.requireNonNull(file); // force a correct file extension final String fileName = FileUtils.stripFileExtension(file.getAbsolutePath()) + ".csv"; final CSVFormat csvFormat = CSVFormat.EXCEL.withQuoteMode(QuoteMode.ALL); try (final OutputStreamWriter outputStreamWriter = new OutputStreamWriter( Files.newOutputStream(Paths.get(fileName)), StandardCharsets.UTF_8); final CSVPrinter writer = new CSVPrinter(new BufferedWriter(outputStreamWriter), csvFormat)) { outputStreamWriter.write('\ufeff'); // write UTF-8 byte order mark to the file for easier imports writer.printRecord("Account", "Number", "Debit", "Credit", "Balance", "Date", "Timestamp", "Memo", "Payee", "Reconciled"); // write the transactions final List<Transaction> transactions = account.getTransactions(startDate, endDate); final DateTimeFormatter dateTimeFormatter = new DateTimeFormatterBuilder().appendValue(YEAR, 4) .appendValue(MONTH_OF_YEAR, 2).appendValue(DAY_OF_MONTH, 2).toFormatter(); final DateTimeFormatter timestampFormatter = new DateTimeFormatterBuilder().appendValue(YEAR, 4) .appendLiteral('-').appendValue(MONTH_OF_YEAR, 2).appendLiteral('-') .appendValue(DAY_OF_MONTH, 2).appendLiteral(' ').appendValue(HOUR_OF_DAY, 2).appendLiteral(':') .appendValue(MINUTE_OF_HOUR, 2).appendLiteral(':').appendValue(SECOND_OF_MINUTE, 2) .toFormatter();/*from www . ja va2 s .c om*/ for (final Transaction transaction : transactions) { final String date = dateTimeFormatter.format(transaction.getLocalDate()); final String timeStamp = timestampFormatter.format(transaction.getTimestamp()); final String credit = transaction.getAmount(account).compareTo(BigDecimal.ZERO) < 0 ? "" : transaction.getAmount(account).abs().toPlainString(); final String debit = transaction.getAmount(account).compareTo(BigDecimal.ZERO) > 0 ? "" : transaction.getAmount(account).abs().toPlainString(); final String balance = account.getBalanceAt(transaction).toPlainString(); final String reconciled = transaction.getReconciled(account) == ReconciledState.NOT_RECONCILED ? Boolean.FALSE.toString() : Boolean.TRUE.toString(); writer.printRecord(account.getName(), transaction.getNumber(), debit, credit, balance, date, timeStamp, transaction.getMemo(), transaction.getPayee(), reconciled); } } catch (final IOException e) { Logger.getLogger(CsvExport.class.getName()).log(Level.SEVERE, e.getLocalizedMessage(), e); } }
From source file:gumga.framework.application.template.GumgaFreemarkerTemplateEngineTest.java
@Before public void startup() throws Exception { URL resourceUrl = getClass().getResource("/templates"); Path resourcePath = Paths.get(resourceUrl.toURI()); gumgaFreemarkerTemplateEngineService = new GumgaFreemarkerTemplateEngineService(resourcePath.toString(), "UTF-8"); gumgaFreemarkerTemplateEngineService.init(); assertNotNull(gumgaFreemarkerTemplateEngineService); gumgaFreemarkerTemplateEngineService.init(); createOutputFolder(OUTPUT_FOLDER);//from w ww. ja va 2s . co m }
From source file:io.github.swagger2markup.extensions.SchemaExtensionTest.java
@Test public void testSwagger2AsciiDocSchemaExtension() throws IOException, URISyntaxException { //Given/* ww w .jav a 2s . c om*/ Path file = Paths.get(SchemaExtensionTest.class.getResource("/yaml/swagger_petstore.yaml").toURI()); Path outputDirectory = Paths.get("build/test/asciidoc/generated"); FileUtils.deleteQuietly(outputDirectory.toFile()); //When Properties properties = new Properties(); properties.load(SchemaExtensionTest.class.getResourceAsStream("/config/config.properties")); Swagger2MarkupConfig config = new Swagger2MarkupConfigBuilder(properties).build(); Swagger2MarkupExtensionRegistry registry = new Swagger2MarkupExtensionRegistryBuilder() //.withDefinitionsDocumentExtension(new SchemaExtension(Paths.get("src/test/resources/docs/asciidoc/extensions").toUri())) .build(); Swagger2MarkupConverter.from(file).withConfig(config).withExtensionRegistry(registry).build() .toFolder(outputDirectory); //Then assertThat(new String(Files.readAllBytes(outputDirectory.resolve("definitions.adoc")))).contains("=== Pet"); assertThat(new String(Files.readAllBytes(outputDirectory.resolve("definitions.adoc")))) .contains("==== XML Schema"); }