当前位置: 首页>>代码示例>>Java>>正文


Java FileObject.exists方法代码示例

本文整理汇总了Java中org.apache.commons.vfs2.FileObject.exists方法的典型用法代码示例。如果您正苦于以下问题:Java FileObject.exists方法的具体用法?Java FileObject.exists怎么用?Java FileObject.exists使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.commons.vfs2.FileObject的用法示例。


在下文中一共展示了FileObject.exists方法的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);
    }
}
 
开发者ID:wso2-extensions,项目名称:esb-connector-file,代码行数:26,代码来源:FileMove.java

示例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));
}
 
开发者ID:lorthos,项目名称:incubator-zeppelin-druid,代码行数:26,代码来源:VFSNotebookRepo.java

示例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;
	}
}
 
开发者ID:yajsw,项目名称:yajsw,代码行数:27,代码来源:YajswConfigurationImpl.java

示例4: 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();
}
 
开发者ID:yajsw,项目名称:yajsw,代码行数:27,代码来源:JarBuilder.java

示例5: 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);
}
 
开发者ID:lorthos,项目名称:incubator-zeppelin-druid,代码行数:18,代码来源:VFSNotebookRepo.java

示例6: 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();
	}

}
 
开发者ID:danniss,项目名称:common-vfs2-nfs,代码行数:26,代码来源:Main.java

示例7: delete

import org.apache.commons.vfs2.FileObject; //导入方法依赖的package包/类
/**
 * Delete all descendents of this file that match a selector.
 * 
 * @param file the file
 * @param selector the selector
 * 
 * @return true, if successful
 * @throws MotuException
 */
public boolean delete(FileObject file, FileSelector selector) throws MotuException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("delete(FileObject, FileSelector) - entering");
    }

    int deleted = 0;
    try {
        if (file.exists()) {
            deleted = file.delete(selector);
        }
    } catch (FileSystemException e) {
        LOG.error("delete(FileObject, FileSelector)", 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);
    }
    boolean returnboolean = (deleted > 0);
    if (LOG.isDebugEnabled()) {
        LOG.debug("delete(FileObject, FileSelector) - exiting");
    }
    return returnboolean;
}
 
开发者ID:clstoulouse,项目名称:motu,代码行数:33,代码来源:VFSManager.java

示例8: 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();

}
 
开发者ID:clstoulouse,项目名称:motu,代码行数:28,代码来源:VFSManager.java

示例9: JnlpSupport

import org.apache.commons.vfs2.FileObject; //导入方法依赖的package包/类
public JnlpSupport(String file) throws ParserConfigurationException,
		SAXException, IOException
{
	FileObject fo = VFSUtils.resolveFile(".", file);
	if (fo == null || !fo.exists())
		throw new FileNotFoundException(file);
	InputStream in = fo.getContent().getInputStream();
	_doc = parseJnlp(in);
	in.close();
}
 
开发者ID:yajsw,项目名称:yajsw,代码行数:11,代码来源:JnlpSupport.java

示例10: create

import org.apache.commons.vfs2.FileObject; //导入方法依赖的package包/类
/**
 * Stores a newly created document under the given ID.
 * 
 * @param xml
 *            the XML document to be stored
 * @param id
 *            the ID under which the document should be stored
 * @return the stored metadata object
 */
public MCRStoredMetadata create(MCRContent xml, int id) throws IOException, JDOMException {
    if (id <= 0) {
        throw new MCRException("ID of metadata object must be a positive integer");
    }
    FileObject fo = getSlot(id);
    if (fo.exists()) {
        String msg = "Metadata object with ID " + id + " already exists in store";
        throw new MCRException(msg);
    }
    fo.createFile();
    MCRStoredMetadata meta = buildMetadataObject(fo, id);
    meta.create(xml);
    return meta;
}
 
开发者ID:MyCoRe-Org,项目名称:mycore,代码行数:24,代码来源:MCRMetadataStore.java

示例11: getRootDir

import org.apache.commons.vfs2.FileObject; //导入方法依赖的package包/类
protected FileObject getRootDir() throws IOException {
  FileObject rootDir = fsManager.resolveFile(getPath("/"));

  if (!rootDir.exists()) {
    throw new IOException("Root path does not exists");
  }

  if (!isDirectory(rootDir)) {
    throw new IOException("Root path is not a directory");
  }

  return rootDir;
}
 
开发者ID:lorthos,项目名称:incubator-zeppelin-druid,代码行数:14,代码来源:VFSNotebookRepo.java

示例12: readAdditionalData

import org.apache.commons.vfs2.FileObject; //导入方法依赖的package包/类
private void readAdditionalData() throws IOException {
    FileObject src = VFS.getManager().resolveFile(fo, dataFile);
    if (!src.exists()) {
        LOGGER.warn("Metadata file is missing, repairing metadata...");
        data = new Element("collection");
        new Document(data);
        repairMetadata();
    }
    try {
        data = new MCRVFSContent(src).asXML().getRootElement();
    } catch (JDOMException | SAXException e) {
        throw new IOException(e);
    }
}
 
开发者ID:MyCoRe-Org,项目名称:mycore,代码行数:15,代码来源:MCRFileCollection.java

示例13: retrieve

import org.apache.commons.vfs2.FileObject; //导入方法依赖的package包/类
/**
 * Returns the file collection stored under the given ID, or null when no
 * collection is stored for the given ID.
 * 
 * @param id
 *            the file collection's ID
 * @return the file collection with the given ID, or null
 */
public MCRFileCollection retrieve(int id) throws IOException {
    FileObject fo = getSlot(id);
    if (!fo.exists()) {
        return null;
    } else {
        return new MCRFileCollection(this, id);
    }
}
 
开发者ID:MyCoRe-Org,项目名称:mycore,代码行数:17,代码来源:MCRFileStore.java

示例14: exists

import org.apache.commons.vfs2.FileObject; //导入方法依赖的package包/类
@Override
protected boolean exists(MCRFile file) {
    try {
        FileObject targetObject = fsManager.resolveFile(getBase(), file.getStorageID());
        return targetObject.exists();
    } catch (FileSystemException e) {
        LOGGER.error(e);
        return false;
    }
}
 
开发者ID:MyCoRe-Org,项目名称:mycore,代码行数:11,代码来源:MCRCStoreVFS.java

示例15: 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;
}
 
开发者ID:wso2-extensions,项目名称:esb-connector-file,代码行数:39,代码来源:FileMove.java


注:本文中的org.apache.commons.vfs2.FileObject.exists方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。