本文整理匯總了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);
}
}
示例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: 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: 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();
}
示例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);
}
示例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();
}
}
示例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;
}
示例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();
}
示例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();
}
示例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;
}
示例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;
}
示例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);
}
}
示例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);
}
}
示例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;
}
}
示例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;
}