本文整理汇总了Java中java.nio.file.LinkOption类的典型用法代码示例。如果您正苦于以下问题:Java LinkOption类的具体用法?Java LinkOption怎么用?Java LinkOption使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
LinkOption类属于java.nio.file包,在下文中一共展示了LinkOption类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: findFiles
import java.nio.file.LinkOption; //导入依赖的package包/类
/**
*
* @return
*/
public List<Path> findFiles() {
LinkOption[] options;
if (followLinks) {
options = new LinkOption[0];
} else {
options = new LinkOption[]{LinkOption.NOFOLLOW_LINKS};
}
if (includeFiles && !Files.isDirectory(path, options)) {
// if a single file was given, just check it against the pattern
if (matches(path)) {
return Collections.singletonList(path);
}
} else {
// a directory was given, let's search it
ArrayList<Path> result = new ArrayList<>();
if (includeDirectories && matches(path)) {
// check the top-level directory
result.add(path);
}
findFiles(path, result, options, 0);
return result;
}
return Collections.emptyList();
}
示例2: getConfiguration
import java.nio.file.LinkOption; //导入依赖的package包/类
public static Configuration getConfiguration(String pathConf) {
// System.setProperty("hadoop.home.dir", "/");
Configuration conf = new Configuration();
/*
* The following two instructions resolve the file system overwriting
* issues (cfr.
* http://stackoverflow.com/questions/17265002/hadoop-no-filesystem-for-
* scheme-file)
*/
conf.set("fs.hdfs.impl", org.apache.hadoop.hdfs.DistributedFileSystem.class.getName());
conf.set("fs.file.impl", org.apache.hadoop.fs.LocalFileSystem.class.getName());
java.nio.file.Path path = Paths.get(pathConf);
if( Files.exists(path, LinkOption.NOFOLLOW_LINKS) ) {
conf.addResource(pathConf);
} else {
System.err.println("The path of namenode configuration file is wrong");
System.exit(1);
}
return conf;
}
示例3: addSystemSpecificSettings
import java.nio.file.LinkOption; //导入依赖的package包/类
private static void addSystemSpecificSettings(StringBuilder builder) {
if(SystemInfoUtilities.getOperatingSystem() == OperatingSystem.OSX) {
String dockIconPath = null;
String platformIndependent = PlatformUtilities.getRapidMinerHome() + "/RapidMiner Studio.app/Contents/Resources/rapidminer_frame_icon.icns";
if(Files.exists(Paths.get(platformIndependent, new String[0]), new LinkOption[0])) {
dockIconPath = platformIndependent;
} else {
dockIconPath = PlatformUtilities.getRapidMinerHome() + "/../rapidminer_frame_icon.icns";
}
builder.append(" -Xdock:icon=");
builder.append(escapeBlanks(dockIconPath));
builder.append(" -Xdock:name=");
builder.append(escapeBlanks("RapidMiner"));
builder.append(" -Dcom.apple.mrj.application.apple.menu.about.name=");
builder.append(escapeBlanks("RapidMiner"));
builder.append(" -Dapple.laf.useScreenMenuBar=true");
builder.append(" -Dcom.apple.mrj.application.growbox.intrudes=true");
builder.append(" -Dapple.awt.antialiasing=true");
builder.append(" -Dcom.apple.mrj.application.live-resize=true");
builder.append(" -Dsun.java2d.opengl=true");
} else if(SystemInfoUtilities.getOperatingSystem() == OperatingSystem.WINDOWS) {
builder.append(" -Djava.net.preferIPv4Stack=true");
}
}
示例4: getFileName
import java.nio.file.LinkOption; //导入依赖的package包/类
public static String getFileName(final Path path)
{
String result = null;
if (path != null)
{
try
{
result = path.toRealPath(LinkOption.NOFOLLOW_LINKS).toString();
}
catch (final IOException ioe)
{
result = path.toString();
}
}
return result;
}
示例5: countFiles
import java.nio.file.LinkOption; //导入依赖的package包/类
public static long countFiles(Path file)
{
if( !Files.exists(file, LinkOption.NOFOLLOW_LINKS) )
{
return 0;
}
try
{
CountingVisitor visitor = new CountingVisitor();
Files.walkFileTree(file, EnumSet.noneOf(FileVisitOption.class), Integer.MAX_VALUE, visitor);
return visitor.getCount();
}
catch( Exception e )
{
throw new RuntimeException("Error counting files for " + file.toString(), e);
}
}
示例6: fileSize
import java.nio.file.LinkOption; //导入依赖的package包/类
public static long fileSize(Path file) throws FileNotFoundException
{
if( Files.exists(file, LinkOption.NOFOLLOW_LINKS) )
{
try
{
return Files.size(file);
}
catch( IOException io )
{
LOGGER.error("Error getting file size for " + file.toString(), io);
throw new RuntimeException(io);
}
}
throw new FileNotFoundException(file.toString());
}
示例7: tbl_listeMouseClicked
import java.nio.file.LinkOption; //导入依赖的package包/类
private void tbl_listeMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tbl_listeMouseClicked
// TODO add your handling code here:
try {
if (tbl_liste.getSelectedRow() < 0) {
return;
}
Path gelen = (Path) dtm.getValueAt(tbl_liste.getSelectedRow(), 0);
if (Files.isDirectory(Paths.get(txt_path.getText() + gelen.getFileName()), LinkOption.NOFOLLOW_LINKS)) {
txt_path.setText(txt_path.getText() + gelen.getFileName() + "\\");
}
} catch (Exception e) {
}
listele();
}
示例8: stat
import java.nio.file.LinkOption; //导入依赖的package包/类
@Override
public UnixFileStat stat(Path path)
throws IOException {
Map<String, Object> map = Files.readAttributes(path, "unix:*", LinkOption.NOFOLLOW_LINKS);
setDev((long) map.get("dev"));
setIno((long) map.get("ino"));
setLinks((int) map.get("nlink"));
setMode((int) map.get("mode"));
setUid((int) map.get("uid"));
setGid((int) map.get("gid"));
setRdev((long) map.get("rdev"));
long size = (long) map.get("size");
setSize(size);
setBlkSize(BLK_SIZE);
setBlocks(size / 512 + 1); // Fake it till you make it
setAccessTime(getInstant(map, "lastAccessTime"));
setModificationTime(getInstant(map, "lastModifiedTime"));
setInodeTime(getInstant(map, "ctime"));
return this;
}
示例9: isNameCompatible
import java.nio.file.LinkOption; //导入依赖的package包/类
@Override
public boolean isNameCompatible(String simpleName, Kind kind) {
simpleName.getClass();
// null check
if (kind == Kind.OTHER && getKind() != kind) {
return false;
}
String sn = simpleName + kind.extension;
String pn = path.getFileName().toString();
if (pn.equals(sn)) {
return true;
}
if (pn.equalsIgnoreCase(sn)) {
try {
// allow for Windows
return path.toRealPath(LinkOption.NOFOLLOW_LINKS).getFileName().toString().equals(sn);
} catch (IOException e) {
}
}
return false;
}
示例10: execute
import java.nio.file.LinkOption; //导入依赖的package包/类
/**
* execute.
* @param cmd - cmd
* @throws IOException - IOException
*/
@Override
public void execute(Command cmd) throws IOException {
Path filePath = workPath.resolve(cmd.getParam()).normalize();
if (Files.exists(filePath, LinkOption.NOFOLLOW_LINKS)
&& !Files.isDirectory(filePath) && Files.isReadable(filePath)) {
dataOutputStream.writeUTF(SUCCESS);
dataOutputStream.flush();
WritableByteChannel wbc = Channels.newChannel(dataOutputStream);
FileInputStream fis = new FileInputStream(filePath.toString());
fis.getChannel().transferTo(0, Long.MAX_VALUE, wbc);
wbc.close();
} else {
dataOutputStream.writeUTF(ERROR);
dataOutputStream.flush();
}
}
示例11: execute
import java.nio.file.LinkOption; //导入依赖的package包/类
/**
* execute.
* @param cmd - cmd
* @throws IOException - IOException
*/
@Override
public void execute(Command cmd) throws IOException {
Path filePath = Paths.get(cmd.getParam());
if (Files.exists(filePath, LinkOption.NOFOLLOW_LINKS)
&& !Files.isDirectory(filePath) && Files.isReadable(filePath)) {
System.out.println("Uploading...");
ObjectOutputStream oos = new ObjectOutputStream(outputStream);
oos.writeObject(cmd);
oos.flush();
WritableByteChannel rbc = Channels.newChannel(new DataOutputStream(outputStream));
FileInputStream fis = new FileInputStream(cmd.getParam());
fis.getChannel().transferTo(0, Long.MAX_VALUE, rbc);
rbc.close();
System.out.println("Done.");
} else {
System.out.println("Error. Please try again.");
}
}
示例12: getFileListEntry
import java.nio.file.LinkOption; //导入依赖的package包/类
private static String getFileListEntry(File fileInDir) {
StringBuilder sb = new StringBuilder();
try {
PosixFileAttributes fa = Files.readAttributes(fileInDir.toPath(), PosixFileAttributes.class, LinkOption.NOFOLLOW_LINKS);
sb.append(fa.isDirectory() ? "d" : fa.isSymbolicLink() ? "l" : fa.isRegularFile() ? "f" : "-");
sb.append(fileInDir.canRead() ? "r" : "-");
sb.append(fileInDir.canWrite() ? "w" : "-");
sb.append(fileInDir.canExecute() ? "x" : "-");
sb.append("\t");
sb.append(fa.owner());
sb.append(fa.owner().getName().length() < 4 ? "\t\t" : "\t");
sb.append(fa.group());
sb.append(fa.group().getName().length() < 4 ? "\t\t" : "\t");
sb.append(fa.size());
sb.append(String.valueOf(fa.size()).length() < 4 ? "\t\t" : "\t");
sb.append(fa.lastModifiedTime().toString());
sb.append("\t");
sb.append(fa.isDirectory() ? fileInDir.getName() + "/" : fileInDir.getName());
} catch (IOException e) {
logger.log(Level.WARNING, "Failed to get file attributes", e);
}
logger.info(sb.toString());
return sb.toString();
}
示例13: followLinks
import java.nio.file.LinkOption; //导入依赖的package包/类
static boolean followLinks(LinkOption... options) {
if (options != null) {
for (LinkOption lo : options) {
Objects.requireNonNull(lo);
if (lo == LinkOption.NOFOLLOW_LINKS) {
return false;
} else {
throw new AssertionError("should not reach here");
}
}
}
return true;
}
示例14: PollingWatchKey
import java.nio.file.LinkOption; //导入依赖的package包/类
PollingWatchKey(Path dir, PollingWatchService watcher, Object fileKey)
throws IOException
{
super(dir, watcher);
this.fileKey = fileKey;
this.valid = true;
this.tickCount = 0;
this.entries = new HashMap<Path,CacheEntry>();
// get the initial entries in the directory
try (DirectoryStream<Path> stream = Files.newDirectoryStream(dir)) {
for (Path entry: stream) {
// don't follow links
long lastModified =
Files.getLastModifiedTime(entry, LinkOption.NOFOLLOW_LINKS).toMillis();
entries.put(entry.getFileName(), new CacheEntry(lastModified, tickCount));
}
} catch (DirectoryIteratorException e) {
throw e.getCause();
}
}
示例15: checkWritePath
import java.nio.file.LinkOption; //导入依赖的package包/类
/**
* Check if the provided path is a directory and is readable/writable/executable
*
* If the path doesn't exist, attempt to create a directory
*
* @param path the path to check
* @throws IOException if the directory cannot be created or is not accessible
*/
public static void checkWritePath(String path) throws IOException {
java.nio.file.Path npath = new File(path).toPath();
// Attempt to create the directory if it doesn't exist
if (Files.notExists(npath, LinkOption.NOFOLLOW_LINKS)) {
Files.createDirectories(npath);
return;
}
if (!Files.isDirectory(npath)) {
throw new IOException(format("path %s is not a directory.", npath));
}
if (!Files.isReadable(npath)) {
throw new IOException(format("path %s is not readable.", npath));
}
if (!Files.isWritable(npath)) {
throw new IOException(format("path %s is not writable.", npath));
}
if (!Files.isExecutable(npath)) {
throw new IOException(format("path %s is not executable.", npath));
}
}