本文整理汇总了Java中org.apache.commons.vfs2.FileObject类的典型用法代码示例。如果您正苦于以下问题:Java FileObject类的具体用法?Java FileObject怎么用?Java FileObject使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
FileObject类属于org.apache.commons.vfs2包,在下文中一共展示了FileObject类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: load
import org.apache.commons.vfs2.FileObject; //导入依赖的package包/类
public void load() throws Exception
{
Reader reader = null;
try
{
FileObject f = VFSUtils.resolveFile(".", _fileName);
InputStream in = f.getContent().getInputStream();
reader = new InputStreamReader(in);
this.read(reader);
}
catch(Exception ex)
{
ex.printStackTrace();
}
finally
{
if (reader != null)
reader.close();
}
}
示例3: fileExists
import org.apache.commons.vfs2.FileObject; //导入依赖的package包/类
private boolean fileExists(String file)
{
try
{
// this hack is no longer required, changed VFS to init without
// providers.xm.
// String current =
// System.getProperty("javax.xml.parsers.DocumentBuilderFactory");
// System.setProperty("javax.xml.parsers.DocumentBuilderFactory",
// "com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl");
DefaultFileSystemManager fsManager = (DefaultFileSystemManager) VFS
.getManager();
// if (current != null)
// System.setProperty("javax.xml.parsers.DocumentBuilderFactory",
// current);
// else
// System.clearProperty("javax.xml.parsers.DocumentBuilderFactory");
FileObject f = VFSUtils.resolveFile(".", file);
return f.exists();
}
catch (FileSystemException e)
{
e.printStackTrace();
return false;
}
}
示例4: isLocalFile
import org.apache.commons.vfs2.FileObject; //导入依赖的package包/类
public boolean isLocalFile()
{
if (_fileConfiguration == null)
return true;
try
{
String name = _fileConfiguration.getURL();
if (name.endsWith(".jnlp"))
return false;
FileObject f = VFSUtils.resolveFile(".", name);
// if we set cache to CacheStrategy.ON_CALL FileObjects are
// decorated to call refresh.
// getContent().getFile() returns the decorated file
return VFSUtils.isLocal(f);
}
catch (Exception ex)
{
ex.printStackTrace();
return true;
}
}
示例5: buildJar
import org.apache.commons.vfs2.FileObject; //导入依赖的package包/类
private void buildJar(String newJar) throws IOException
{
ZipOutputStream out = new ZipOutputStream(new FileOutputStream(newJar ));
FileSystemManager fsManager = VFS.getManager();
for (String jar : _jar2class.keySet())
{
FileObject jarFile;
if (jar.endsWith(".jar"))
jarFile = fsManager.resolveFile( "jar:"+jar );
else
jarFile = fsManager.resolveFile( jar );
for (String file : _jar2class.get(jar))
{
file = file.replaceAll("\\.", "/");
file += ".class";
FileObject f = fsManager.resolveFile(jarFile, file);
if (f.exists())
addFile(f, file, out);
else
System.out.println("file not found "+f);
}
}
out.close();
}
示例6: remove
import org.apache.commons.vfs2.FileObject; //导入依赖的package包/类
@Override
public void remove(String noteId) throws IOException {
FileObject rootDir = fsManager.resolveFile(getPath("/"));
FileObject noteDir = rootDir.resolveFile(noteId, NameScope.CHILD);
if (!noteDir.exists()) {
// nothing to do
return;
}
if (!isDirectory(noteDir)) {
// it is not look like zeppelin note savings
throw new IOException("Can not remove " + noteDir.getName().toString());
}
noteDir.delete(Selectors.SELECT_SELF_AND_CHILDREN);
}
示例7: findMaxID
import org.apache.commons.vfs2.FileObject; //导入依赖的package包/类
/**
* Recursively searches for the highest ID, which is the greatest slot file
* name currently used in the store.
*
* @param dir
* the directory to search
* @param depth
* the subdirectory depth level of the dir
* @return the highest slot file name / ID currently stored
*/
private String findMaxID(final FileObject dir, final int depth) throws FileSystemException {
final FileObject[] children = dir.getChildren();
if (children.length == 0) {
return null;
}
Arrays.sort(children, new MCRFileObjectComparator());
if (depth == slotLength.length) {
return children[children.length - 1].getName().getBaseName();
}
for (int i = children.length - 1; i >= 0; i--) {
final FileObject child = children[i];
if (!child.getType().hasChildren()) {
continue;
}
final String found = findMaxID(child, depth + 1);
if (found != null) {
return found;
}
}
return null;
}
示例8: getFather
import org.apache.commons.vfs2.FileObject; //导入依赖的package包/类
/**
* Returns the FileObject that is the father of all logical children of this
* FileObject. This may not be the current node itself, in case the node is
* a container file, because then intermediate FileObject instances are
* created by Apache VFS.
*
* @return the father of this node's children in VFS
*/
private FileObject getFather() throws IOException {
if (isDirectory()) {
return fo;
} else if (getSize() == 0) {
return null;
} else if (VFS.getManager().canCreateFileSystem(fo)) {
FileObject father = fo;
while (VFS.getManager().canCreateFileSystem(father)) {
father = VFS.getManager().createFileSystem(father);
}
return father;
} else {
return null;
}
}
示例9: getChildren
import org.apache.commons.vfs2.FileObject; //导入依赖的package包/类
/**
* Returns the children of this node. Directories and container files like
* zip or tar may have child nodes.
*
* @return a List of child nodes, which may be empty, in undefined order
*/
public List<MCRNode> getChildren() throws IOException {
List<MCRNode> children = new ArrayList<>();
FileObject father = getFather();
if (father != null) {
FileObject[] childFos = father.getChildren();
for (FileObject childFo : childFos) {
String name = childFo.getName().getBaseName();
MCRNode child = getChild(name);
if (child != null) {
children.add(child);
}
}
}
return children;
}
示例10: doStoreContent
import org.apache.commons.vfs2.FileObject; //导入依赖的package包/类
@Override
protected String doStoreContent(MCRFile file, MCRContentInputStream source) throws Exception {
StringBuilder storageId = new StringBuilder();
String[] slots = buildSlotPath();
// Recursively create directory name
for (String slot : slots) {
storageId.append(slot).append("/");
}
String fileId = buildNextID(file);
storageId.append(fileId);
FileObject targetObject = fsManager.resolveFile(getBase(), storageId.toString());
FileContent targetContent = targetObject.getContent();
try (OutputStream out = targetContent.getOutputStream()) {
IOUtils.copy(source, out);
} finally {
targetContent.close();
}
return storageId.toString();
}
示例11: 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));
}
示例12: main
import org.apache.commons.vfs2.FileObject; //导入依赖的package包/类
public static void main(String[] args) {
try {
FileSystemManager fileSystemManager = VFS.getManager();
FileObject fileObject;
String path = "";
fileObject = fileSystemManager.resolveFile("nfs://10.0.202.122//opt/glog/a.txt");
if (fileObject == null) {
throw new IOException("File cannot be resolved: " + path);
}
if (!fileObject.exists()) {
throw new IOException("File does not exist: " + path);
}
System.out.println(fileObject.getName().getPath());
BufferedReader stream = new BufferedReader(new InputStreamReader(fileObject.getContent().getInputStream(), "utf-8"));
String line = null;
while((line = stream.readLine()) != null) {
System.out.println(line);
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
示例13: doRename
import org.apache.commons.vfs2.FileObject; //导入依赖的package包/类
/**
* Renames the file.
*
* @param newfile the newfile
*
* @throws Exception the exception
*/
@Override
protected void doRename(FileObject newfile) throws Exception {
boolean ok = true;
final GridFTPClient ftpClient = ftpFs.getClient();
try {
String oldName = getName().getPath();
String newName = newfile.getName().getPath();
ftpClient.rename(oldName, newName);
} catch (IOException ioe) {
ok = false;
} catch (ServerException e) {
ok = false;
} finally {
ftpFs.putClient(ftpClient);
}
if (!ok) {
throw new FileSystemException("vfs.provider.gsiftp/rename-file.error", new Object[] { getName().toString(), newfile });
}
this.fileInfo = null;
children = EMPTY_FTP_FILE_MAP;
}
示例14: getUriAsInputStream
import org.apache.commons.vfs2.FileObject; //导入依赖的package包/类
/**
* Gets the uri as input stream.
*
* @param uri the uri
*
* @return the uri as input stream
*
* @throws MotuException the motu exception
*/
public InputStream getUriAsInputStream(String uri) throws MotuException {
if (LOG.isDebugEnabled()) {
LOG.debug("getUriAsInputStream(String) - entering");
}
InputStream in = null;
try {
FileObject fileObject = resolveFile(uri);
if (fileObject != null) {
in = fileObject.getContent().getInputStream();
}
} catch (IOException e) {
LOG.error("getUriAsInputStream(String)", e);
throw new MotuException(ErrorType.NETCDF_LOADING, String.format("'%s' uri file has not be found", uri), e);
}
if (LOG.isDebugEnabled()) {
LOG.debug("getUriAsInputStream(String) - exiting");
}
return in;
}
示例15: deleteDirectory
import org.apache.commons.vfs2.FileObject; //导入依赖的package包/类
/**
* Delete directory.
*
* @param path the path
*
* @return true, if successful
* @throws MotuException
*/
public boolean deleteDirectory(String path) throws MotuException {
if (LOG.isDebugEnabled()) {
LOG.debug("deleteDirectory(String) - entering");
}
StringBuffer stringBuffer = new StringBuffer();
stringBuffer.append(path);
if (!(path.endsWith("/") || path.endsWith("\\"))) {
stringBuffer.append("/");
}
FileObject pathToDelete = resolveFile(stringBuffer.toString());
boolean returnboolean = deleteDirectory(pathToDelete);
if (LOG.isDebugEnabled()) {
LOG.debug("deleteDirectory(String) - exiting");
}
return returnboolean;
}