本文整理汇总了Java中org.apache.commons.vfs2.FileObject.moveTo方法的典型用法代码示例。如果您正苦于以下问题:Java FileObject.moveTo方法的具体用法?Java FileObject.moveTo怎么用?Java FileObject.moveTo使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.vfs2.FileObject
的用法示例。
在下文中一共展示了FileObject.moveTo方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: moveFileWithPattern
import org.apache.commons.vfs2.FileObject; //导入方法依赖的package包/类
/**
* @param remoteFile Location of the file
* @param destination New file location
* @param filePattern Pattern of the file
* @param manager Standard file system manager
* @param messageContext The message context that is generated for processing the file
* @throws IOException
*/
private void moveFileWithPattern(FileObject remoteFile, String destination, String filePattern,
StandardFileSystemManager manager, MessageContext messageContext) throws IOException {
FilePattenMatcher patternMatcher = new FilePattenMatcher(filePattern);
try {
if (patternMatcher.validate(remoteFile.getName().getBaseName())) {
FileObject file = manager.resolveFile(destination, FileConnectorUtils.init(messageContext));
if (!file.exists()) {
file.createFolder();
}
file = manager.resolveFile(destination + File.separator + remoteFile.getName().getBaseName(),
FileConnectorUtils.init(messageContext));
remoteFile.moveTo(file);
}
} catch (IOException e) {
log.error("Error occurred while moving a file. " + e.getMessage(), e);
}
}
示例2: save
import org.apache.commons.vfs2.FileObject; //导入方法依赖的package包/类
@Override
public synchronized void save(Note note) throws IOException {
GsonBuilder gsonBuilder = new GsonBuilder();
gsonBuilder.setPrettyPrinting();
Gson gson = gsonBuilder.create();
String json = gson.toJson(note);
FileObject rootDir = getRootDir();
FileObject noteDir = rootDir.resolveFile(note.id(), NameScope.CHILD);
if (!noteDir.exists()) {
noteDir.createFolder();
}
if (!isDirectory(noteDir)) {
throw new IOException(noteDir.getName().toString() + " is not a directory");
}
FileObject noteJson = noteDir.resolveFile(".note.json", NameScope.CHILD);
// false means not appending. creates file if not exists
OutputStream out = noteJson.getContent().getOutputStream(false);
out.write(json.getBytes(conf.getString(ConfVars.ZEPPELIN_ENCODING)));
out.close();
noteJson.moveTo(noteDir.resolveFile("note.json", NameScope.CHILD));
}
示例3: fileMove
import org.apache.commons.vfs2.FileObject; //导入方法依赖的package包/类
/**
* Move the file
*
* @param destination New location of the folder
* @param remoteFile Location of the file
* @param messageContext The message context that is processed by a handler in the handle method
* @param manager Standard file system manager
*/
private void fileMove(String destination, FileObject remoteFile, MessageContext messageContext,
StandardFileSystemManager manager) throws IOException {
FileObject file = manager.resolveFile(destination, FileConnectorUtils.init(messageContext));
if (FileConnectorUtils.isFolder(file)) {
if (!file.exists()) {
file.createFolder();
}
file = manager.resolveFile(destination + File.separator + remoteFile.getName().getBaseName(),
FileConnectorUtils.init(messageContext));
} else if (!file.exists()) {
file.createFile();
}
remoteFile.moveTo(file);
}
示例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();
}
}