當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。