List of usage examples for java.io File toPath
public Path toPath()
From source file:com.hortonworks.registries.util.HdfsFileStorageTest.java
@Test public void testUploadJarWithDir() throws Exception { Map<String, String> config = new HashMap<>(); config.put(HdfsFileStorage.CONFIG_FSURL, "file:///"); config.put(HdfsFileStorage.CONFIG_DIRECTORY, HDFS_DIR); fileStorage.init(config);/* w w w . ja v a 2 s .c o m*/ File file = File.createTempFile("test", ".tmp"); file.deleteOnExit(); List<String> lines = Arrays.asList("test-line-1", "test-line-2"); Files.write(file.toPath(), lines, Charset.forName("UTF-8")); String jarFileName = "test.jar"; fileStorage.deleteFile(jarFileName); fileStorage.uploadFile(new FileInputStream(file), jarFileName); InputStream inputStream = fileStorage.downloadFile(jarFileName); List<String> actual = IOUtils.readLines(inputStream); Assert.assertEquals(lines, actual); }
From source file:io.mangoo.maven.MangooMojo.java
@Override public void execute() throws MojoExecutionException { if (skip) {//from w w w.j a v a 2 s . co m getLog().info("Skip flag is on. Will not execute."); return; } initMojo(); checkClasses(buildOutputDirectory); MinificationUtils.setBasePath(project.getBasedir().getAbsolutePath()); List<String> classpathItems = new ArrayList<>(); classpathItems.add(buildOutputDirectory); for (Artifact artifact : project.getArtifacts()) { classpathItems.add(artifact.getFile().toString()); } Set<String> includesSet = new LinkedHashSet<>(includes); Set<String> excludesSet = new LinkedHashSet<>(excludes); Set<Path> watchDirectories = new LinkedHashSet<>(); FileSystem fileSystem = FileSystems.getDefault(); watchDirectories.add(fileSystem.getPath(buildOutputDirectory).toAbsolutePath()); if (this.watchDirs != null) { for (File watchDir : this.watchDirs) { watchDirectories.add(watchDir.toPath().toAbsolutePath()); } } getArtifacts(includesSet, excludesSet, watchDirectories); startRunner(classpathItems, includesSet, excludesSet, watchDirectories); IOUtils.closeQuietly(fileSystem); }
From source file:com.comcast.cdn.traffic_control.traffic_router.neustar.data.NeustarDatabaseUpdater.java
private File createTmpDir(File directory) { try {/*from w ww . j a v a 2 s .co m*/ return Files.createTempDirectory(directory.toPath(), "neustar-").toFile(); } catch (IOException e) { System.out.println("Failed to create temporary directory in " + directory.getAbsolutePath() + ": " + e.getMessage()); } return null; }
From source file:de.yaio.services.metaextract.server.extractor.TesseractExtractor.java
@Override public String extractText(final InputStream input, final String fileName, final String lang) throws IOException, ExtractorException { File tmpFile; tmpFile = File.createTempFile("metaextractor", "." + FilenameUtils.getExtension(fileName)); tmpFile.deleteOnExit();/*from w w w . j a v a 2s . c o m*/ Files.copy(input, tmpFile.toPath(), java.nio.file.StandardCopyOption.REPLACE_EXISTING); return this.extractText(tmpFile, lang); }
From source file:ch.sportchef.business.event.control.EventImageService.java
public byte[] getImage(@NotNull final Long eventId) throws IOException { final File file = new File(IMAGE_UPLOAD_PATH, String.format("%d%s", eventId, FILE_EXTENSION)); //NON-NLS if (file.exists()) { return Files.readAllBytes(file.toPath()); }/*from w w w . j a v a 2 s . c om*/ throw new NotFoundException(String.format("event with id '%d' has no image", eventId)); //NON-NLS }
From source file:com.eriwen.gradle.Digest.java
private String digest(final File file, final DigestAlgorithm algorithm) throws IOException { final byte[] contentBytes = Files.readAllBytes(file.toPath()); final String checksum; switch (algorithm) { case MD5:/*ww w . j a v a 2 s . c o m*/ checksum = DigestUtils.md5Hex(contentBytes); break; case SHA1: checksum = DigestUtils.sha1Hex(contentBytes); break; case SHA256: checksum = DigestUtils.sha256Hex(contentBytes); break; case SHA512: checksum = DigestUtils.sha512Hex(contentBytes); break; default: throw new IllegalArgumentException("Cannot use unknown digest algorithm " + algorithm.toString()); } return checksum; }
From source file:io.cloudslang.lang.enforcer.SpringCleansingRule.java
private void applyForJavaSourcesInRoot(final String path, final Log log) throws EnforcerRuleException { Iterator<File> fileIterator = iterateFiles(new File(path), new String[] { JAVA }, true); while (fileIterator.hasNext()) { File source = fileIterator.next(); if (isRegularFile(source.toPath(), NOFOLLOW_LINKS)) { if (log.isDebugEnabled()) { log.debug(format(STARTED_SCANNING_ORG_SPRINGFRAMEWORK, source.getAbsolutePath())); }//from w w w . j a v a2 s .c om try { String contents = readFileToString(source, UTF_8.displayName()); if (isSpringConfigurationAnnotatedClass(contents)) { log.info(format("Skipping verification for Spring configuration class in file '%s'", source.getAbsolutePath())); continue; } // At this point it is clear this is a regular Java class that is not a Spring Configuration class // and just validate we don't have org.springframework in it findMatchesUsingPattern(source, log, contents, patternImport, FOUND_USAGE_OF_ORG_SPRINGFRAMEWORK_IN_IMPORT_AT_LINE); findMatchesUsingPattern(source, log, contents, patternCodeLine, FOUND_USAGE_OF_ORG_SPRINGFRAMEWORK_IN_CODE_FRAGMENT_AT_LINE); } catch (IOException ignore) { log.error(format("Could not process file '%s'", source)); } if (log.isDebugEnabled()) { log.debug(format(FINISHED_SCANNING_ORG_SPRINGFRAMEWORK, source.getAbsolutePath())); } } } }
From source file:net.portalblockz.portalbot.serverdata.JSONConfigManager.java
public JSONConfigManager(File file) { instance = this; try {/*from w w w . j a va 2s . c o m*/ if (!file.exists()) { Path path = file.toPath(); Files.copy(getClass().getClassLoader().getResourceAsStream("config.json"), path); } } catch (Exception e) { e.printStackTrace(); } String s; try { BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(file))); StringBuilder jsonObjectBuilder = new StringBuilder(); while ((s = reader.readLine()) != null) { jsonObjectBuilder.append(s); } configObject = new JSONObject(jsonObjectBuilder.toString()); reader.close(); } catch (Exception e) { } for (int i = 0; i < getJSONServers().length(); i++) { JSONObject server = getJSONServers().getJSONObject(i); serverList.add(new Server(server.getString("host"), server.getString("username"), server.getString("password"), server.getInt("port"), getList(server, "channels"), getList(server, "staff"), server.getString("prefix").charAt(0))); System.out.println(String.format("%s %s %s %s %s", server.getString("host"), server.getString("username"), server.getString("password"), server.getInt("port"), server.getString("prefix").charAt(0))); } serializeRepos(); serializeBlacklist(); }
From source file:ai.susi.server.api.cms.AppsService.java
@Override public JSONObject serviceImpl(Query query, HttpServletResponse response, Authorization auth, final JsonObjectWithDefault permissions) throws APIException { String categorySelection = query.get("category", ""); // generate json File apps = new File(DAO.html_dir, "apps"); JSONObject json = new JSONObject(true); JSONArray app_array = new JSONArray(); json.put("apps", app_array); JSONObject categories = new JSONObject(true); for (String appname : apps.list()) try {//from w ww .j ava 2s . c om // read app and verify the structure of the app File apppath = new File(apps, appname); if (!apppath.isDirectory()) continue; Set<String> files = new HashSet<>(); for (String f : apppath.list()) files.add(f); if (!files.contains("index.html")) continue; if (!files.contains("app.json")) continue; File json_ld_file = new File(apppath, "app.json"); String jsonString = new String(Files.readAllBytes(json_ld_file.toPath()), StandardCharsets.UTF_8); JSONObject json_ld = new JSONObject(jsonString); // translate permissions if (json_ld.has("permissions")) { String p = json_ld.getString("permissions"); String[] ps = p.split(","); JSONArray a = new JSONArray(); for (String s : ps) a.put(s); json_ld.put("permissions", a); } // check category if (json_ld.has("applicationCategory") && json_ld.has("name")) { String cname = json_ld.getString("applicationCategory"); if (categorySelection.length() == 0 || categorySelection.equals(cname)) app_array.put(json_ld); String aname = json_ld.getString("name"); if (!categories.has(cname)) categories.put(cname, new JSONArray()); JSONArray appnames = categories.getJSONArray(cname); appnames.put(aname); } } catch (Throwable e) { Log.getLog().warn(e); } // write categories json.put("categories", categories.keySet().toArray(new String[categories.length()])); json.put("category", categories); return json; }
From source file:com.movilizer.mds.webservice.services.MafManagementService.java
protected MafSource readSource(File sourceFile) { try {//from w ww . j ava 2 s.com MafCliMetaFile meta = readMetaFile(sourceFile); String scriptSrc = new String(Files.readAllBytes(sourceFile.toPath())); meta.getSource().setScriptSrc(scriptSrc); return meta.getSource(); } catch (IOException e) { throw new MovilizerMAFManagementException(e); } }