List of usage examples for java.nio.file LinkOption NOFOLLOW_LINKS
LinkOption NOFOLLOW_LINKS
To view the source code for java.nio.file LinkOption NOFOLLOW_LINKS.
Click Source Link
From source file:de.huberlin.wbi.cuneiform.core.cre.LocalThread.java
public static void deleteIfExists(Path f) throws IOException { if (!Files.exists(f, LinkOption.NOFOLLOW_LINKS)) return;/*from w w w . java2s. c o m*/ if (Files.isDirectory(f)) try (DirectoryStream<Path> stream = Files.newDirectoryStream(f)) { for (Path p : stream) deleteIfExists(p); } Files.delete(f); }
From source file:edu.ehu.galan.lite.model.Document.java
/** * Save the results of the document in a Json text file, if you want to use current directory * use "./" or the absolute path, the method will check whether the Dir exists or not and will * try to create according to that/*from w w w .ja va 2 s. c o m*/ * * @param pFolder - where you want to save the results * @param pDoc */ public static void saveJsonToDir(String pFolder, Document pDoc) { Doc msg = new Doc(); msg.setName(pDoc.name); msg.setKnowledgeSource(pDoc.getSource().toString()); List<MsgTop> list = new ArrayList<>(); for (Topic string : pDoc.topicList) { MsgTop top = new MsgTop(); top.setSourceTitle(string.getSourceTitle()); top.setDefinition(string.getSourceDef()); top.setId(string.getId()); top.setTopic(string.getTopic()); top.setLabels(string.getLabelList()); top.setDomainRelatedness(string.getDomainRelatedness()); List<Translation> transList = new ArrayList<>(); HashMap<String, String> map = string.getTranslations(); Iterator<Map.Entry<String, String>> it = map.entrySet().iterator(); while (it.hasNext()) { Map.Entry<String, String> pairs = it.next(); Translation trans = new Translation(); trans.setLang(pairs.getKey()); trans.setText(pairs.getValue()); transList.add(trans); } List<Link> linksIn = new ArrayList<>(); HashMap<Integer, Double> map3 = string.getLinksIn(); Iterator<Map.Entry<Integer, Double>> it2 = map3.entrySet().iterator(); while (it2.hasNext()) { Map.Entry<Integer, Double> pairs = it2.next(); Link link = new Link(); link.setId(pairs.getKey()); link.setRelatedness(pairs.getValue()); linksIn.add(link); } List<Link> linksOut = new ArrayList<>(); HashMap<Integer, Double> map4 = string.getLinksOut(); Iterator<Map.Entry<Integer, Double>> it3 = map4.entrySet().iterator(); while (it3.hasNext()) { Map.Entry<Integer, Double> pairs = it3.next(); Link link = new Link(); link.setId(pairs.getKey()); link.setRelatedness(pairs.getValue()); linksOut.add(link); } top.setLinksIn(linksIn); top.setLinksOut(linksOut); top.setTranslations(transList); List<Parent> parentList = new ArrayList<>(); HashMap<Integer, String> map2 = string.getParentCategories(); Iterator<Map.Entry<Integer, String>> itr = map2.entrySet().iterator(); while (itr.hasNext()) { Map.Entry<Integer, String> pairs = itr.next(); Parent trans = new Parent(); trans.setId(pairs.getKey()); trans.setSourceTitle(pairs.getValue()); parentList.add(trans); } top.setParentCategories(parentList); list.add(top); } msg.setTopics(list); List<DomainRel> listRel = new ArrayList<>(); for (Map.Entry<Integer, String> pair : pDoc.domainTopics.entrySet()) { DomainRel rel = new DomainRel(); rel.setId(pair.getKey()); rel.setTitle(pair.getValue()); listRel.add(rel); } msg.setDomainTopics(listRel); if (pFolder.equals("")) { pFolder = System.getProperty("user.dir"); } if (Files.isDirectory(Paths.get(pFolder), LinkOption.NOFOLLOW_LINKS)) { FileWriter outFile = null; try { FileUtils.deleteQuietly(new File(pFolder + "/" + pDoc.getName() + ".json")); outFile = new FileWriter(pFolder + "/" + pDoc.getName() + ".json"); boolean first = true; try (PrintWriter out = new PrintWriter(outFile)) { Gson son = new GsonBuilder().setPrettyPrinting().create(); out.print(son.toJson(msg)); } } catch (IOException ex) { logger.warn("couldn't save the document results in json format", ex); } finally { try { if (outFile != null) { outFile.close(); } } catch (IOException ex) { logger.warn("Error while closing the file", ex); } } logger.info(pDoc.path + " Saved... "); } else if (Files.exists(Paths.get(pFolder), LinkOption.NOFOLLOW_LINKS)) { logger.error("The folder exists but it isn't a directory...maybe a file?"); } else { logger.warn("The directory doesn't exist... will be created"); FileWriter outFile = null; try { FileUtils.forceMkdir(new File(pFolder)); FileUtils.deleteQuietly(new File(pFolder + "/" + pDoc.getName() + ".json")); outFile = new FileWriter(pFolder + "/" + pDoc.getName() + ".json"); boolean first = true; try (PrintWriter out = new PrintWriter(outFile)) { Gson son = new GsonBuilder().setPrettyPrinting().create(); out.print(son.toJson(pDoc)); } } catch (IOException ex) { logger.warn("couldn't save the document results in json format", ex); } finally { try { if (outFile != null) { outFile.close(); } } catch (IOException ex) { logger.warn("Error while closing the file", ex); } } logger.info(pDoc.path + " Saved... "); } }
From source file:com.htmlhifive.visualeditor.persister.LocalFileContentsPersister.java
/** * ?????????????./*from w w w .j a v a 2s .c om*/ * * @param key ? * @return ???? */ @Override public UrlTreeMetaData<InputStream> generateMetaDataFromReal(String key, UrlTreeContext ctx) throws BadContentException { if (!this.canLoad(key, ctx)) { throw new IllegalArgumentException( "Cannot Load it. check before can it load with canLoad(key): " + key); } Path p = this.generateFileObj(key); File f = p.toFile(); long lastModified = f.lastModified(); logger.trace("[?]????lastModified: " + p.toString() + ":" + lastModified); UrlTreeMetaData<InputStream> md = new UrlTreeMetaData<>(); md.setDirectory(Files.isDirectory(p, LinkOption.NOFOLLOW_LINKS)); md.setFilename(key); md.setOwnerId(ctx.getUserName()); md.setGroupId(ctx.getPrimaryGroup()); md.setCreatedTime(lastModified); md.setUpdatedTime(lastModified); md.setPermission(ctx.getDefaultPermission()); String contentType = new MimetypesFileTypeMap().getContentType(p.getFileName().toString()); md.setContentType(contentType); return md; }
From source file:it.reexon.lib.files.FileUtils.java
/** * Moves a file to a destination. //from w w w . j a v a2 s .c om * * @param file the path to the file to move * @param destination the destination path * @throws IOException if an I/O error occurs * @throws IllegalArgumentException if file is null or not exists, destination is null */ public static void moveFile(Path file, Path destination) throws IOException, IllegalArgumentException { if ((file == null) || !Files.exists(file, LinkOption.NOFOLLOW_LINKS) || (destination == null)) { throw new IllegalArgumentException("The filepath is null or points to an invalid location! " + file); } Files.move(file, destination, StandardCopyOption.REPLACE_EXISTING); }
From source file:at.tfr.securefs.ui.CopyFilesServiceBean.java
private Path validateFromPath(String fromPathName) throws IOException { Path from = Paths.get(fromPathName); if (!Files.isDirectory(from, LinkOption.NOFOLLOW_LINKS)) { throw new IOException("Path " + from + " is no directory"); }/* w ww. j a va2 s . co m*/ if (!Files.isReadable(from)) { throw new IOException("Path " + from + " is not readable"); } if (!Files.isExecutable(from)) { throw new IOException("Path " + from + " is not executable"); } return from; }
From source file:org.codice.ddf.configuration.migration.AbstractMigrationSupport.java
/** * Creates a test softlink with the given name in the specified directory resolved under * ${ddf.home}.//from w ww . ja va 2s .c om * * @param dir the directory where to create the test softlink * @param name the name of the test softlink to create in the specified directory * @param dest the destination path for the softlink * @return a path corresponding to the test softlink created (relativized from ${ddf.home}) * @throws IOException if an I/O error occurs while creating the test softlink * @throws UnsupportedOperationException if the implementation does not support symbolic links */ public Path createSoftLink(Path dir, String name, Path dest) throws IOException { final Path path = ddfHome.resolve(dir).resolve(name); dir.toFile().mkdirs(); try { Files.createSymbolicLink(path, dest); } catch (FileSystemException exception) { // symlinks cannot be reliably created on Windows throw new AssumptionViolatedException("The system cannot create symlinks.", exception); } final Path apath = path.toRealPath(LinkOption.NOFOLLOW_LINKS); return apath.startsWith(ddfHome) ? ddfHome.relativize(apath) : apath; }
From source file:org.codice.ddf.configuration.migration.AbstractMigrationTest.java
@Before public void baseSetup() throws Exception { root = testFolder.getRoot().toPath().toRealPath(LinkOption.NOFOLLOW_LINKS); ddfHome = testFolder.newFolder("ddf").toPath().toRealPath(LinkOption.NOFOLLOW_LINKS); System.setProperty("ddf.home", ddfHome.toString()); }
From source file:at.tfr.securefs.ui.CopyFilesServiceBean.java
private Path validateToPath(String toPathName, ProcessFilesData pfd) throws IOException { Path to = Paths.get(toPathName); if (Files.exists(to, LinkOption.NOFOLLOW_LINKS)) { if (Files.isSameFile(to, Paths.get(pfd.getFromRootPath()))) { throw new IOException("Path " + to + " may not be same as FromPath: " + pfd.getFromRootPath()); }/* ww w .ja v a 2 s . c o m*/ if (!Files.isDirectory(to, LinkOption.NOFOLLOW_LINKS)) { throw new IOException("Path " + to + " is no directory"); } if (!Files.isWritable(to)) { throw new IOException("Path " + to + " is not writable"); } if (!Files.isExecutable(to)) { throw new IOException("Path " + to + " is not executable"); } if (!pfd.isAllowOverwriteExisting()) { if (Files.newDirectoryStream(to).iterator().hasNext()) { throw new IOException("Path " + to + " is not empty, delete content copy."); } } } return to; }
From source file:ftpclientgui.MainWindow.java
private void btnUploasdActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnUploasdActionPerformed if (!txtUploadFile.getText().equals("") && java.nio.file.Files .exists(java.nio.file.Paths.get(txtUploadFile.getText()), LinkOption.NOFOLLOW_LINKS)) { try {//w w w . j a va2 s . co m String message; if (!mngr.UploadFile(new java.io.File(txtUploadFile.getText()).getName(), new java.io.BufferedInputStream(new java.io.FileInputStream(txtUploadFile.getText())))) { message = "File could not be uploaded!"; } else { message = "File uploaded sucesfully."; txtUploadFile.setText(""); } JOptionPane.showMessageDialog(this, message); } catch (FileNotFoundException ex) { Logger.getLogger(MainWindow.class.getName()).log(Level.SEVERE, null, ex); } } }
From source file:org.codice.ddf.configuration.migration.AbstractMigrationSupport.java
@Before public void baseSetup() throws Exception { root = testFolder.getRoot().toPath().toRealPath(LinkOption.NOFOLLOW_LINKS); ddfHome = testFolder.newFolder("ddf").toPath().toRealPath(LinkOption.NOFOLLOW_LINKS); ddfBin = testFolder.newFolder("ddf", "bin").toPath().toRealPath(LinkOption.NOFOLLOW_LINKS); System.setProperty("ddf.home", ddfHome.toString()); }