本文整理汇总了Java中org.apache.commons.vfs2.FileObject.getType方法的典型用法代码示例。如果您正苦于以下问题:Java FileObject.getType方法的具体用法?Java FileObject.getType怎么用?Java FileObject.getType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.vfs2.FileObject
的用法示例。
在下文中一共展示了FileObject.getType方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: refreshFtpCache
import org.apache.commons.vfs2.FileObject; //导入方法依赖的package包/类
/**
* Refresh ftp cache.
*
* @param fileObject the file object
* @throws FileSystemException
*/
public void refreshFtpCache(FileObject fileObject) throws FileSystemException {
if (fileObject == null) {
return;
}
if (!(fileObject.getFileSystem() instanceof FtpFileSystem)) {
return;
}
if (fileObject.exists()) {
return;
}
FileObject fileObjectParent = fileObject.getParent();
if (fileObjectParent == null) {
return;
}
fileObjectParent.getType(); // force to attach : needed for force refresh
fileObjectParent.refresh();
}
示例2: copyToDir
import org.apache.commons.vfs2.FileObject; //导入方法依赖的package包/类
@SneakyThrows
private static File copyToDir(FileObject jarredFile, File destination, boolean retryIfImaginary) {
switch (jarredFile.getType()) {
case FILE:
return copyFileToDir(jarredFile, destination);
case FOLDER:
return copyDirToDir(jarredFile, destination);
case IMAGINARY:
if (retryIfImaginary) {
log.debug("Imaginary file found, retrying extraction");
VFS.getManager().getFilesCache().removeFile(jarredFile.getFileSystem(), jarredFile.getName());
FileObject newJarredFile = VFS.getManager().resolveFile(jarredFile.getName().getURI());
return copyToDir(newJarredFile, destination, false);
} else {
log.debug("Imaginary file found after retry, abandoning retry");
}
default:
throw new IllegalStateException("File Type not supported: " + jarredFile.getType());
}
}
示例3: moveFile
import org.apache.commons.vfs2.FileObject; //导入方法依赖的package包/类
/**
* Move the files
*
* @param source Location of the file
* @param destination Destination of the file
* @return return a resultStatus
*/
private boolean moveFile(String source, String destination, MessageContext messageContext,
boolean includeParentDirectory, String filePattern) {
boolean resultStatus = false;
StandardFileSystemManager manager = null;
try {
manager = FileConnectorUtils.getManager();
// Create remote object
FileObject remoteFile = manager.resolveFile(source, FileConnectorUtils.init(messageContext));
if (remoteFile.exists()) {
if (remoteFile.getType() == FileType.FILE) {
fileMove(destination, remoteFile, messageContext, manager);
} else {
folderMove(source, destination, filePattern, includeParentDirectory, messageContext, manager);
}
resultStatus = true;
if (log.isDebugEnabled()) {
log.debug("File move completed from " + source + " to " + destination);
}
} else {
log.error("The file/folder location does not exist.");
resultStatus = false;
}
} catch (IOException e) {
handleException("Unable to move a file/folder.", e, messageContext);
} finally {
if (manager != null) {
manager.close();
}
}
return resultStatus;
}
示例4: folderMove
import org.apache.commons.vfs2.FileObject; //导入方法依赖的package包/类
/**
* Move the folder
*
* @param destination New location of the folder
* @param source Location of the folder
* @param messageContext The message context that is processed by a handler in the handle method
* @param includeParentDirectory Boolean type
* @param manager Standard file system manager
*/
private void folderMove(String source, String destination, String filePattern, boolean includeParentDirectory,
MessageContext messageContext, StandardFileSystemManager manager) throws IOException {
FileObject remoteFile = manager.resolveFile(source, FileConnectorUtils.init(messageContext));
FileObject file = manager.resolveFile(destination, FileConnectorUtils.init(messageContext));
if (StringUtils.isNotEmpty(filePattern)) {
FileObject[] children = remoteFile.getChildren();
for (FileObject child : children) {
if (child.getType() == FileType.FILE) {
moveFileWithPattern(child, destination, filePattern, manager, messageContext);
} else if (child.getType() == FileType.FOLDER) {
String newSource = source + File.separator + child.getName().getBaseName();
folderMove(newSource, destination, filePattern, includeParentDirectory, messageContext, manager);
}
}
} else if (includeParentDirectory) {
file = manager.resolveFile(destination + File.separator + remoteFile.getName().getBaseName(),
FileConnectorUtils.init(messageContext));
file.createFolder();
remoteFile.moveTo(file);
} else {
if (!file.exists()) {
file.createFolder();
}
remoteFile.moveTo(file);
remoteFile.createFolder();
}
}
示例5: deleteFile
import org.apache.commons.vfs2.FileObject; //导入方法依赖的package包/类
/**
* Delete the file repsented by the file parameter.
*
* @param file the file
*
* @return true, if successful
* @throws MotuException
*/
public boolean deleteFile(FileObject file) throws MotuException {
if (LOG.isDebugEnabled()) {
LOG.debug("deleteFile(FileObject) - entering");
}
boolean deleted = false;
try {
if (file.exists()) {
if (file.getType() != FileType.FILE) {
throw new MotuException(
ErrorType.NETCDF_LOADING,
String.format("Delete file '%s' is rejected: it is a folder. ", file.getName().toString()));
}
deleted = file.delete();
}
} catch (FileSystemException e) {
LOG.error("deleteFile(FileObject)", e);
// throw new MotuException(String.format("Unable to copy file '%s' to '%s'",
// foSrc.getURL().toString(), foDest.getURL().toString()), e);
throw new MotuException(ErrorType.NETCDF_LOADING, String.format("Unable to delete '%s'", file.getName().toString()), e);
}
if (LOG.isDebugEnabled()) {
LOG.debug("deleteFile(FileObject) - exiting");
}
return deleted;
}
示例6: isDirectory
import org.apache.commons.vfs2.FileObject; //导入方法依赖的package包/类
private boolean isDirectory(FileObject fo) throws IOException {
if (fo == null) return false;
if (fo.getType() == FileType.FOLDER) {
return true;
} else {
return false;
}
}