當前位置: 首頁>>代碼示例>>Java>>正文


Java FileObject類代碼示例

本文整理匯總了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);
    }
}
 
開發者ID:wso2-extensions,項目名稱:esb-connector-file,代碼行數:26,代碼來源:FileMove.java

示例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();
	}
}
 
開發者ID:yajsw,項目名稱:yajsw,代碼行數:21,代碼來源:FilePropertiesConfiguration.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: 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;
	}

}
 
開發者ID:yajsw,項目名稱:yajsw,代碼行數:24,代碼來源:YajswConfigurationImpl.java

示例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();
}
 
開發者ID:yajsw,項目名稱:yajsw,代碼行數:27,代碼來源:JarBuilder.java

示例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);
}
 
開發者ID:lorthos,項目名稱:incubator-zeppelin-druid,代碼行數:18,代碼來源:VFSNotebookRepo.java

示例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;
}
 
開發者ID:MyCoRe-Org,項目名稱:mycore,代碼行數:36,代碼來源:MCRStore.java

示例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;
    }
}
 
開發者ID:MyCoRe-Org,項目名稱:mycore,代碼行數:24,代碼來源:MCRNode.java

示例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;
}
 
開發者ID:MyCoRe-Org,項目名稱:mycore,代碼行數:22,代碼來源:MCRNode.java

示例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();
}
 
開發者ID:MyCoRe-Org,項目名稱:mycore,代碼行數:23,代碼來源:MCRCStoreVFS.java

示例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));
}
 
開發者ID:lorthos,項目名稱:incubator-zeppelin-druid,代碼行數:26,代碼來源:VFSNotebookRepo.java

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

}
 
開發者ID:danniss,項目名稱:common-vfs2-nfs,代碼行數:26,代碼來源:Main.java

示例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;
}
 
開發者ID:clstoulouse,項目名稱:motu,代碼行數:30,代碼來源:GsiFtpFileObject.java

示例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;
}
 
開發者ID:clstoulouse,項目名稱:motu,代碼行數:33,代碼來源:VFSManager.java

示例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;

}
 
開發者ID:clstoulouse,項目名稱:motu,代碼行數:28,代碼來源:VFSManager.java


注:本文中的org.apache.commons.vfs2.FileObject類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。