本文整理了Java中org.eclipse.jgit.util.FileUtils.toPath()
方法的一些代码示例,展示了FileUtils.toPath()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。FileUtils.toPath()
方法的具体详情如下:
包路径:org.eclipse.jgit.util.FileUtils
类名称:FileUtils
方法名:toPath
[英]Safe conversion from java.io.File to java.nio.file.Path.
[中]从java安全转换。木卫一。文件转换为java。尼奥。文件路径
代码示例来源:origin: org.eclipse.jgit/org.eclipse.jgit
/**
* @param file
* @return lastModified attribute for given file, not following symbolic
* links
* @throws IOException
*/
static long lastModified(File file) throws IOException {
return Files.getLastModifiedTime(toPath(file), LinkOption.NOFOLLOW_LINKS)
.toMillis();
}
代码示例来源:origin: org.eclipse.jgit/org.eclipse.jgit
/**
* @param file
* @return {@code true} if the given file is hidden
* @throws IOException
*/
static boolean isHidden(File file) throws IOException {
return Files.isHidden(toPath(file));
}
代码示例来源:origin: org.eclipse.jgit/org.eclipse.jgit
/**
* Set a file hidden (on Windows)
*
* @param file
* a {@link java.io.File} object.
* @param hidden
* a boolean.
* @throws java.io.IOException
* @since 4.1
*/
public static void setHidden(File file, boolean hidden) throws IOException {
Files.setAttribute(toPath(file), "dos:hidden", Boolean.valueOf(hidden), //$NON-NLS-1$
LinkOption.NOFOLLOW_LINKS);
}
代码示例来源:origin: org.eclipse.jgit/org.eclipse.jgit
/**
* Get file length
*
* @param file
* a {@link java.io.File}.
* @return length of the given file
* @throws java.io.IOException
* @since 4.1
*/
public static long getLength(File file) throws IOException {
Path nioPath = toPath(file);
if (Files.isSymbolicLink(nioPath))
return Files.readSymbolicLink(nioPath).toString()
.getBytes(UTF_8).length;
return Files.size(nioPath);
}
代码示例来源:origin: org.eclipse.jgit/org.eclipse.jgit
/**
* @param file
* @param time
* @throws IOException
*/
static void setLastModified(File file, long time) throws IOException {
Files.setLastModifiedTime(toPath(file), FileTime.fromMillis(time));
}
代码示例来源:origin: org.eclipse.jgit/org.eclipse.jgit
while (--attempts >= 0) {
try {
Files.move(toPath(src), toPath(dst), options);
return;
} catch (AtomicMoveNotSupportedException e) {
Files.move(toPath(src), toPath(dst), options);
return;
} catch (IOException e2) {
代码示例来源:origin: org.eclipse.jgit/org.eclipse.jgit
private boolean autoGcBlockedByOldLockFile() {
try {
FileTime lastModified = Files.getLastModifiedTime(FileUtils.toPath(logFile));
if (lastModified.toInstant().compareTo(getLogExpiry()) > 0) {
// There is an existing log file, which is too recent to ignore
return true;
}
} catch (NoSuchFileException e) {
// No existing log file, OK.
} catch (IOException | ParseException e) {
throw new JGitInternalException(e.getMessage(), e);
}
return false;
}
代码示例来源:origin: org.eclipse.jgit/org.eclipse.jgit
/**
* Read target path of the symlink.
*
* @param path
* a {@link java.io.File} object.
* @return target path of the symlink, or null if it is not a symbolic link
* @throws java.io.IOException
* @since 3.0
*/
public static String readSymLink(File path) throws IOException {
Path nioPath = toPath(path);
Path target = Files.readSymbolicLink(nioPath);
String targetString = target.toString();
if (SystemReader.getInstance().isWindows()) {
targetString = targetString.replace('\\', '/');
} else if (SystemReader.getInstance().isMacOS()) {
targetString = Normalizer.normalize(targetString, Form.NFC);
}
return targetString;
}
代码示例来源:origin: org.eclipse.jgit/org.eclipse.jgit
/**
* Create a symbolic link
*
* @param path
* the path of the symbolic link to create
* @param target
* the target of the symbolic link
* @return the path to the symbolic link
* @throws java.io.IOException
* @since 4.2
*/
public static Path createSymLink(File path, String target)
throws IOException {
Path nioPath = toPath(path);
if (Files.exists(nioPath, LinkOption.NOFOLLOW_LINKS)) {
BasicFileAttributes attrs = Files.readAttributes(nioPath,
BasicFileAttributes.class, LinkOption.NOFOLLOW_LINKS);
if (attrs.isRegularFile() || attrs.isSymbolicLink()) {
delete(path);
} else {
delete(path, EMPTY_DIRECTORIES_ONLY | RECURSIVE);
}
}
if (SystemReader.getInstance().isWindows()) {
target = target.replace('/', '\\');
}
Path nioTarget = toPath(new File(target));
return Files.createSymbolicLink(nioPath, nioTarget);
}
代码示例来源:origin: org.eclipse.jgit/org.eclipse.jgit
/** {@inheritDoc} */
@Override
public boolean setExecute(File f, boolean canExecute) {
if (!isFile(f))
return false;
if (!canExecute)
return f.setExecutable(false, false);
try {
Path path = FileUtils.toPath(f);
Set<PosixFilePermission> pset = Files.getPosixFilePermissions(path);
// owner (user) is always allowed to execute.
pset.add(PosixFilePermission.OWNER_EXECUTE);
int mask = umask();
apply(pset, mask, PosixFilePermission.GROUP_EXECUTE, 1 << 3);
apply(pset, mask, PosixFilePermission.OTHERS_EXECUTE, 1);
Files.setPosixFilePermissions(path, pset);
return true;
} catch (IOException e) {
// The interface doesn't allow to throw IOException
final boolean debug = Boolean.parseBoolean(SystemReader
.getInstance().getProperty("jgit.fs.debug")); //$NON-NLS-1$
if (debug)
System.err.println(e);
return false;
}
}
代码示例来源:origin: org.eclipse.jgit/org.eclipse.jgit
Files.move(FileUtils.toPath(tmp), FileUtils.toPath(dst),
StandardCopyOption.ATOMIC_MOVE);
dst.setReadOnly();
Files.move(FileUtils.toPath(tmp), FileUtils.toPath(dst),
StandardCopyOption.ATOMIC_MOVE);
dst.setReadOnly();
代码示例来源:origin: org.eclipse.jgit/org.eclipse.jgit
Path nioPath = toPath(file);
PosixFileAttributes readAttributes = nioPath
.getFileSystem()
代码示例来源:origin: org.eclipse.jgit/org.eclipse.jgit
/**
* @param fs
* @param file
* @return non null attributes object
*/
static Attributes getFileAttributesBasic(FS fs, File file) {
try {
Path nioPath = toPath(file);
BasicFileAttributes readAttributes = nioPath
.getFileSystem()
.provider()
.getFileAttributeView(nioPath,
BasicFileAttributeView.class,
LinkOption.NOFOLLOW_LINKS).readAttributes();
Attributes attributes = new Attributes(fs, file,
true,
readAttributes.isDirectory(),
fs.supportsExecute() ? file.canExecute() : false,
readAttributes.isSymbolicLink(),
readAttributes.isRegularFile(), //
readAttributes.creationTime().toMillis(), //
readAttributes.lastModifiedTime().toMillis(),
readAttributes.isSymbolicLink() ? Constants
.encode(readSymLink(file)).length
: readAttributes.size());
return attributes;
} catch (IOException e) {
return new Attributes(file, fs);
}
}
代码示例来源:origin: berlam/github-bucket
/**
* @param file
* @return lastModified attribute for given file, not following symbolic
* links
* @throws IOException
*/
static long lastModified(File file) throws IOException {
return Files.getLastModifiedTime(toPath(file), LinkOption.NOFOLLOW_LINKS)
.toMillis();
}
代码示例来源:origin: berlam/github-bucket
/**
* @param file
* @return {@code true} if the given file is hidden
* @throws IOException
*/
static boolean isHidden(File file) throws IOException {
return Files.isHidden(toPath(file));
}
代码示例来源:origin: berlam/github-bucket
/**
* Set a file hidden (on Windows)
*
* @param file
* a {@link java.io.File} object.
* @param hidden
* a boolean.
* @throws java.io.IOException
* @since 4.1
*/
public static void setHidden(File file, boolean hidden) throws IOException {
Files.setAttribute(toPath(file), "dos:hidden", Boolean.valueOf(hidden), //$NON-NLS-1$
LinkOption.NOFOLLOW_LINKS);
}
代码示例来源:origin: berlam/github-bucket
/**
* Get file length
*
* @param file
* a {@link java.io.File}.
* @return length of the given file
* @throws java.io.IOException
* @since 4.1
*/
public static long getLength(File file) throws IOException {
Path nioPath = toPath(file);
if (Files.isSymbolicLink(nioPath))
return Files.readSymbolicLink(nioPath).toString()
.getBytes(UTF_8).length;
return Files.size(nioPath);
}
代码示例来源:origin: berlam/github-bucket
/**
* @param file
* @param time
* @throws IOException
*/
static void setLastModified(File file, long time) throws IOException {
Files.setLastModifiedTime(toPath(file), FileTime.fromMillis(time));
}
代码示例来源:origin: berlam/github-bucket
private boolean autoGcBlockedByOldLockFile() {
try {
FileTime lastModified = Files.getLastModifiedTime(FileUtils.toPath(logFile));
if (lastModified.toInstant().compareTo(getLogExpiry()) > 0) {
// There is an existing log file, which is too recent to ignore
return true;
}
} catch (NoSuchFileException e) {
// No existing log file, OK.
} catch (IOException | ParseException e) {
throw new JGitInternalException(e.getMessage(), e);
}
return false;
}
代码示例来源:origin: berlam/github-bucket
/**
* Read target path of the symlink.
*
* @param path
* a {@link java.io.File} object.
* @return target path of the symlink, or null if it is not a symbolic link
* @throws java.io.IOException
* @since 3.0
*/
public static String readSymLink(File path) throws IOException {
Path nioPath = toPath(path);
Path target = Files.readSymbolicLink(nioPath);
String targetString = target.toString();
if (SystemReader.getInstance().isWindows()) {
targetString = targetString.replace('\\', '/');
} else if (SystemReader.getInstance().isMacOS()) {
targetString = Normalizer.normalize(targetString, Form.NFC);
}
return targetString;
}
内容来源于网络,如有侵权,请联系作者删除!