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:org.panbox.desktop.common.vfs.backend.generic.GenericVirtualFileImpl.java
@Override public long getLastWriteTime() { // return file.lastModified(); try {/* w w w . j a v a 2 s .c om*/ BasicFileAttributes attr = Files.readAttributes(file.toPath(), BasicFileAttributes.class, LinkOption.NOFOLLOW_LINKS); return attr.lastModifiedTime().toMillis(); } catch (IOException e) { logger.error("Error in getLastWriteTime()", e); return 0; } }
From source file:edu.ehu.galan.lite.model.Document.java
/** * Save results in a plain text file following the pattern.... topic + \tab + * Source_knowledge_id+ \tab + Source_knowledge_title * * @param pFolder - where you want to save the results * @param pDoc/*w ww. ja v a2s . co m*/ */ public static void saveResults(String pFolder, Document pDoc) { if (Files.isDirectory(Paths.get(pFolder), LinkOption.NOFOLLOW_LINKS)) { PrintWriter printWriter = null; try { printWriter = new PrintWriter(new File(pFolder + "/" + pDoc.name), "UTF-8"); for (Topic topic : pDoc.topicList) { printWriter.println(topic.getTopic() + "\t" + topic.getId() + "\t" + topic.getSourceTitle()); } printWriter.close(); } catch (FileNotFoundException | UnsupportedEncodingException ex) { logger.error("error printing the file: " + pFolder, 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"); try { FileUtils.forceMkdir(new File(pFolder)); PrintWriter printWriter = null; printWriter = new PrintWriter(new File(pFolder + "/" + pDoc.name), "UTF-8"); for (Topic topic : pDoc.topicList) { printWriter.println(topic.getTopic() + "\t" + topic.getId() + "\t" + topic.getSourceTitle()); } printWriter.close(); logger.info(pDoc.path + " Saved... "); } catch (FileNotFoundException | UnsupportedEncodingException ex) { logger.error("error printing the file: " + pFolder, ex); } catch (IOException ex) { logger.error("Error while creating directories in or printing the file: " + pFolder, ex); } } }
From source file:com.facebook.buck.util.unarchive.Untar.java
/** Create a director on the filesystem */ private void mkdirs(DirectoryCreator creator, Path target) throws IOException { ProjectFilesystem filesystem = creator.getFilesystem(); if (filesystem.isDirectory(target, LinkOption.NOFOLLOW_LINKS)) { creator.recordPath(target);/*from w w w. ja v a2s . c om*/ } else { creator.forcefullyCreateDirs(target); } }
From source file:uk.trainwatch.io.ftp.FTPClient.java
default boolean retrieveIfNeeded(FTPFile remote, Path target, CopyOption... options) throws IOException { if (remote != null && target != null && isPathRetrievable(target, remote)) { try (InputStream is = retrieveFileStream(remote)) { if (is == null) { throw new FileNotFoundException(target.toString()); }// www. jav a2s . co m Files.copy(is, target, options); } finally { completePendingCommand(); } } return Files.exists(target, LinkOption.NOFOLLOW_LINKS) && Files.isRegularFile(target, LinkOption.NOFOLLOW_LINKS); }
From source file:com.facebook.buck.util.unarchive.Unzip.java
private void extractFile(ImmutableSet.Builder<Path> filesWritten, ZipFile zip, DirectoryCreator creator, Path target, ZipArchiveEntry entry) throws IOException { ProjectFilesystem filesystem = creator.getFilesystem(); if (filesystem.isFile(target, LinkOption.NOFOLLOW_LINKS)) { // NOPMD for clarity // pass/*from w ww . j a v a 2 s . c o m*/ } else if (filesystem.exists(target, LinkOption.NOFOLLOW_LINKS)) { filesystem.deleteRecursivelyIfExists(target); } else if (target.getParent() != null) { creator.forcefullyCreateDirs(target.getParent()); } filesWritten.add(target); writeZipContents(zip, entry, filesystem, target); }
From source file:algorithm.MetsSubmissionInformationPackage.java
@SuppressWarnings("unchecked") @Override//from ww w . ja v a 2 s . co m public File encapsulate(File carrier, List<File> userPayloadList) throws IOException { List<File> payloadList = new ArrayList<File>(); payloadList.addAll(userPayloadList); Mets metsDocument = new Mets(); metsDocument.setID(carrier.getName() + "_SIP"); metsDocument.setLABEL("PeriCAT information package"); metsDocument.setTYPE("digital object and metadata files"); // HEADER: Agent periPack = new Agent(); periPack.setID("peripack agent"); periPack.setROLE(Role.PRESERVATION); periPack.setOTHERTYPE("SOFTWARE"); Name name = new Name(); PCData nameString = new PCData(); nameString.add("peripack"); name.getContent().add(nameString); periPack.getContent().add(name); Note note = new Note(); PCData noteString = new PCData(); noteString.add(TOOL_DESCRIPTION); note.getContent().add(noteString); periPack.getContent().add(note); MetsHdr header = new MetsHdr(); header.setID("mets header"); header.setCREATEDATE(new Date()); header.setLASTMODDATE(new Date()); header.setRECORDSTATUS("complete"); header.getContent().add(periPack); if (truePersonButton.isSelected()) { Agent person = new Agent(); person.setID("peripack user"); person.setROLE(Role.CREATOR); person.setTYPE(Type.INDIVIDUAL); Name personName = new Name(); PCData personNameString = new PCData(); personNameString.add(personField.getText()); personName.getContent().add(personNameString); person.getContent().add(personName); header.getContent().add(person); } metsDocument.getContent().add(header); // FILE SECTION: FileSec fileSection = new FileSec(); FileGrp carrierGroup = new FileGrp(); carrierGroup.setID("carrier files"); carrierGroup.setUSE("digital object"); // carrier div for structural map: Div carrierDiv = new Div(); carrierDiv.setID("carrier list"); carrierDiv.setTYPE("carrier files"); // back to file section: edu.harvard.hul.ois.mets.File metsCarrier = new edu.harvard.hul.ois.mets.File(); metsCarrier.setID(carrier.getAbsolutePath()); metsCarrier.setGROUPID("carrier"); metsCarrier.setCHECKSUM("" + FileUtils.checksumCRC32(carrier)); metsCarrier.setMIMETYPE(Files.probeContentType(carrier.toPath())); metsCarrier.setOWNERID(Files.getOwner(carrier.toPath(), LinkOption.NOFOLLOW_LINKS).toString()); metsCarrier.setSIZE(Files.size(carrier.toPath())); metsCarrier.setUSE(Files.getPosixFilePermissions(carrier.toPath(), LinkOption.NOFOLLOW_LINKS).toString()); FLocat fileLocation = new FLocat(); fileLocation.setXlinkHref(carrier.getAbsolutePath()); fileLocation.setLOCTYPE(Loctype.OTHER); fileLocation.setOTHERLOCTYPE("system file path"); fileLocation.setXlinkTitle("original file path of the carrier"); metsCarrier.getContent().add(fileLocation); carrierGroup.getContent().add(metsCarrier); // add structural map information: Fptr carrierFilePointer = new Fptr(); carrierFilePointer.setFILEID(carrier.getAbsolutePath()); carrierDiv.getContent().add(carrierFilePointer); fileSection.getContent().add(carrierGroup); FileGrp payloadGroup = new FileGrp(); payloadGroup.setID("payload files"); payloadGroup.setUSE("metadata"); // payload div for structural map: Div payloadDiv = new Div(); payloadDiv.setID("payload list"); payloadDiv.setTYPE("payload files"); // back to file section: for (File payload : payloadList) { edu.harvard.hul.ois.mets.File metsPayload = new edu.harvard.hul.ois.mets.File(); metsPayload.setID(payload.getAbsolutePath()); metsPayload.setGROUPID("payload"); metsPayload.setCHECKSUM(DigestUtils.md5Hex(new FileInputStream(payload))); metsPayload.setCHECKSUMTYPE(Checksumtype.MD5); metsPayload.setMIMETYPE(Files.probeContentType(payload.toPath())); metsPayload.setOWNERID(Files.getOwner(payload.toPath(), LinkOption.NOFOLLOW_LINKS).toString()); metsPayload.setSIZE(Files.size(payload.toPath())); metsPayload .setUSE(Files.getPosixFilePermissions(payload.toPath(), LinkOption.NOFOLLOW_LINKS).toString()); FLocat fileLocation2 = new FLocat(); fileLocation2.setXlinkHref(payload.getAbsolutePath()); fileLocation2.setLOCTYPE(Loctype.OTHER); fileLocation2.setOTHERLOCTYPE("system file path"); fileLocation2.setXlinkTitle("original file path of the payload"); metsPayload.getContent().add(fileLocation2); payloadGroup.getContent().add(metsPayload); // add structural map information: Fptr payloadFilePointer = new Fptr(); payloadFilePointer.setFILEID(payload.getAbsolutePath()); payloadDiv.getContent().add(payloadFilePointer); } fileSection.getContent().add(payloadGroup); metsDocument.getContent().add(fileSection); // STRUCTURAL MAP: StructMap structuralMap = new StructMap(); structuralMap.setID("structural map"); Div encapsulatedFiles = new Div(); encapsulatedFiles.setID("peripack files"); encapsulatedFiles.setTYPE("encapsulated files"); structuralMap.getContent().add(encapsulatedFiles); encapsulatedFiles.getContent().add(carrierDiv); encapsulatedFiles.getContent().add(payloadDiv); metsDocument.getContent().add(structuralMap); File metsFile = new File(OUTPUT_DIRECTORY + "mets.xml"); FileOutputStream outputStream = new FileOutputStream(metsFile); try { metsDocument.write(new MetsWriter(outputStream)); } catch (MetsException e) { } outputStream.close(); payloadList.add(metsFile); File outputFile = null; if (zipButton.isSelected()) { outputFile = new ZipPackaging().encapsulate(carrier, payloadList); } else if (tarButton.isSelected()) { outputFile = new TarPackaging().encapsulate(carrier, payloadList); } metsFile.delete(); return outputFile; }
From source file:com.facebook.buck.util.unarchive.Untar.java
/** Prepares to write out a file. This deletes existing files/directories */ private void prepareForFile(DirectoryCreator creator, Path target) throws IOException { ProjectFilesystem filesystem = creator.getFilesystem(); if (filesystem.isFile(target, LinkOption.NOFOLLOW_LINKS)) { return;/* ww w . j av a 2 s.c o m*/ } else if (filesystem.exists(target, LinkOption.NOFOLLOW_LINKS)) { filesystem.deleteRecursivelyIfExists(target); } else if (target.getParent() != null) { creator.forcefullyCreateDirs(target.getParent()); } }
From source file:au.edu.uq.cmm.paul.queue.AbstractQueueFileManager.java
@Override public FileStatus getFileStatus(File file) { Path path = file.toPath();// w w w .ja v a 2s . com File parent = path.getParent().toFile(); if (Files.exists(path)) { if (parent.equals(captureDirectory)) { if (Files.isSymbolicLink(path)) { return FileStatus.CAPTURED_SYMLINK; } else { return FileStatus.CAPTURED_FILE; } } else if (parent.equals(archiveDirectory)) { if (Files.isSymbolicLink(path)) { return FileStatus.ARCHIVED_SYMLINK; } else { return FileStatus.ARCHIVED_FILE; } } else { return FileStatus.NOT_OURS; } } else { if (Files.exists(path, LinkOption.NOFOLLOW_LINKS)) { if (parent.equals(captureDirectory)) { return FileStatus.BROKEN_CAPTURED_SYMLINK; } else if (parent.equals(archiveDirectory)) { return FileStatus.BROKEN_ARCHIVED_SYMLINK; } else { return FileStatus.NOT_OURS; } } else { return FileStatus.NON_EXISTENT; } } }
From source file:uk.ac.ebi.metabolights.webservice.utils.FileUtil.java
/** * Create a private FTP folder for uploading big study files * * @param folder//www . j a v a2 s . c om * @return a String containing created folder * @author jrmacias * @date 20151102 */ @PostConstruct public static Path createFtpFolder(String folder) throws IOException { String privateFTPRoot = PropertiesUtil.getProperty("privateFTPRoot"); // ~/ftp_private/ // create the folder File ftpFolder = new File(privateFTPRoot + File.separator + folder); Path folderPath = ftpFolder.toPath(); if (!ftpFolder.mkdir()) throw new IOException(); // set folder owner, group and access permissions // 'chmod 770' UserPrincipalLookupService lookupService = FileSystems.getDefault().getUserPrincipalLookupService(); Set<PosixFilePermission> perms = new HashSet<PosixFilePermission>(); // owner permissions perms.add(PosixFilePermission.OWNER_READ); perms.add(PosixFilePermission.OWNER_WRITE); perms.add(PosixFilePermission.OWNER_EXECUTE); // group permissions perms.add(PosixFilePermission.GROUP_READ); perms.add(PosixFilePermission.GROUP_WRITE); perms.add(PosixFilePermission.GROUP_EXECUTE); // apply changes Files.getFileAttributeView(folderPath, PosixFileAttributeView.class, LinkOption.NOFOLLOW_LINKS) .setPermissions(perms); return folderPath; }
From source file:io.hops.hopsworks.common.security.CertificateMaterializer.java
@PostConstruct public void init() { File tmpDir = new File(settings.getHopsworksTmpCertDir()); if (!tmpDir.exists()) { throw new IllegalStateException( "Transient certificates directory <" + tmpDir.getAbsolutePath() + "> does NOT exist!"); }/*from www . j a va 2 s .c o m*/ try { PosixFileAttributeView fileView = Files.getFileAttributeView(tmpDir.toPath(), PosixFileAttributeView.class, LinkOption.NOFOLLOW_LINKS); Set<PosixFilePermission> permissions = fileView.readAttributes().permissions(); boolean ownerRead = permissions.contains(PosixFilePermission.OWNER_READ); boolean ownerWrite = permissions.contains(PosixFilePermission.OWNER_WRITE); boolean ownerExecute = permissions.contains(PosixFilePermission.OWNER_EXECUTE); boolean groupRead = permissions.contains(PosixFilePermission.GROUP_READ); boolean groupWrite = permissions.contains(PosixFilePermission.GROUP_WRITE); boolean groupExecute = permissions.contains(PosixFilePermission.GROUP_EXECUTE); boolean othersRead = permissions.contains(PosixFilePermission.OTHERS_READ); boolean othersWrite = permissions.contains(PosixFilePermission.OTHERS_WRITE); boolean othersExecute = permissions.contains(PosixFilePermission.OTHERS_EXECUTE); // Permissions should be 750 if ((ownerRead && ownerWrite && ownerExecute) && (groupRead && !groupWrite && groupExecute) && (!othersRead && !othersWrite & !othersExecute)) { String owner = fileView.readAttributes().owner().getName(); String group = fileView.readAttributes().group().getName(); String permStr = PosixFilePermissions.toString(permissions); LOG.log(Level.INFO, "Passed permissions check for " + tmpDir.getAbsolutePath() + ". Owner: " + owner + " Group: " + group + " permissions: " + permStr); } else { throw new IllegalStateException( "Wrong permissions for " + tmpDir.getAbsolutePath() + ", it should be 0750"); } } catch (UnsupportedOperationException ex) { LOG.log(Level.WARNING, "Associated filesystem is not POSIX compliant. " + "Continue without checking the permissions of " + tmpDir.getAbsolutePath() + " This might be a security problem."); } catch (IOException ex) { throw new IllegalStateException( "Error while getting filesystem " + "permissions of " + tmpDir.getAbsolutePath(), ex); } try { FileUtils.cleanDirectory(tmpDir); } catch (IOException ex) { LOG.log(Level.WARNING, "Could not clean directory " + tmpDir.getAbsolutePath() + " during startup, there might be stale " + "certificates", ex); } transientDir = tmpDir.getAbsolutePath(); String delayRaw = settings.getCertificateMaterializerDelay(); DELAY_VALUE = settings.getConfTimeValue(delayRaw); DELAY_TIMEUNIT = settings.getConfTimeTimeUnit(delayRaw); try { String hostAddress = InetAddress.getLocalHost().getHostAddress(); long threadId = Thread.currentThread().getId(); String lock_identifier = hostAddress + "_" + threadId; lock_id = lock_identifier.length() <= 30 ? lock_identifier : lock_identifier.substring(0, 30); } catch (UnknownHostException ex) { throw new IllegalStateException(ex); } }