List of usage examples for org.apache.commons.vfs2 FileType IMAGINARY
FileType IMAGINARY
To view the source code for org.apache.commons.vfs2 FileType IMAGINARY.
Click Source Link
From source file:com.github.songsheng.vfs2.provider.nfs.NfsFileObject.java
/** * Determines the type of the file, returns null if the file does not * exist.//from w ww . j a va 2s.c o m */ @Override protected FileType doGetType() throws Exception { if (!file.exists()) { return FileType.IMAGINARY; } else if (file.isDirectory()) { return FileType.FOLDER; } else if (file.isFile()) { return FileType.FILE; } throw new FileSystemException("vfs.provider.Nfs/get-type.error", getName()); }
From source file:com.seer.datacruncher.spring.IsSuccessfulConnectionController.java
private String checkServiceRunning(int service, String connID) { String success = "true"; String url = ""; ConnectionsEntity conn = connectionsDao.find(Long.parseLong(connID)); DefaultFileSystemManager fsManager = null; FileObject fileObject = null; String userName = ""; String password = ""; String hostName = ""; String port = ""; String inputDirectory = ""; String fileName = ""; int connType = 1; if (conn != null) { userName = conn.getUserName();//w w w . java2 s. c om password = conn.getPassword(); hostName = conn.getHost(); port = conn.getPort(); inputDirectory = conn.getDirectory(); fileName = conn.getFileName(); connType = conn.getIdConnType(); } if (connType == GenericType.DownloadTypeConn) { if (fileName == null || fileName.trim().length() == 0) { return "false"; } else { fileName = "/" + fileName; } } else { fileName = ""; } try { fsManager = (DefaultFileSystemManager) VFS.getManager(); if (service == Servers.SAMBA.getDbCode()) { if (!fsManager.hasProvider("smb")) { fsManager.addProvider("smb", new SmbFileProvider()); } url = "smb://" + userName + ":" + password + "@" + hostName + ":" + port + "/" + inputDirectory + fileName; } else if (service == Servers.HTTP.getDbCode()) { if (!fsManager.hasProvider("http")) { fsManager.addProvider("http", new HttpFileProvider()); } url = "http://" + hostName + ":" + port + "/" + inputDirectory + fileName; } else if (service == Servers.FTP.getDbCode()) { if (!fsManager.hasProvider("ftp")) { fsManager.addProvider("ftp", new FtpFileProvider()); } url = "ftp://" + userName + ":" + password + "@" + hostName + ":" + port + "/" + inputDirectory + fileName; } fileObject = fsManager.resolveFile(url); if (fileObject == null || !fileObject.exists()) { success = "false"; } if (connType == GenericType.DownloadTypeConn) { if (fileObject.getType().equals(FileType.IMAGINARY)) { success = "false"; } byte data[] = new byte[(int) fileObject.getContent().getSize()]; fileObject.getContent().getInputStream().read(data); } } catch (Exception ex) { success = "false"; } finally { try { if (fileObject != null) { fileObject.close(); } if (fsManager != null) { fsManager.freeUnusedResources(); fsManager.close(); fsManager = null; } } catch (Exception ex) { } finally { fileObject = null; fsManager = null; } } return success; }
From source file:com.seer.datacruncher.spring.ConnectionsFileDownloadController.java
private String getFileContent(long connId, ConnectionsEntity connectionEntity) { String content = ""; DefaultFileSystemManager fsManager = null; FileObject fileObject = null; try {/*from ww w . j a v a2s. c om*/ fsManager = (DefaultFileSystemManager) VFS.getManager(); int serviceId = connectionEntity.getService(); String hostName = connectionEntity.getHost(); String port = connectionEntity.getPort(); String userName = connectionEntity.getUserName(); String password = connectionEntity.getPassword(); String inputDirectory = connectionEntity.getDirectory(); String fileName = connectionEntity.getFileName(); log.info("Trying to Server polling at server [" + hostName + ":" + port + "] with user[" + userName + "]."); String url = ""; if (serviceId == Servers.SAMBA.getDbCode()) { if (!fsManager.hasProvider("smb")) { fsManager.addProvider("smb", new SmbFileProvider()); } url = "smb://" + userName + ":" + password + "@" + hostName + ":" + port + "/" + inputDirectory + "/" + fileName; } else if (serviceId == Servers.HTTP.getDbCode()) { if (!fsManager.hasProvider("http")) { fsManager.addProvider("http", new HttpFileProvider()); } url = "http://" + hostName + ":" + port + "/" + inputDirectory + "/" + fileName; } else if (serviceId == Servers.FTP.getDbCode()) { if (!fsManager.hasProvider("ftp")) { fsManager.addProvider("ftp", new SmbFileProvider()); } url = "ftp://" + userName + ":" + password + "@" + hostName + ":" + port + "/" + inputDirectory + "/" + fileName; } fileObject = fsManager.resolveFile(url); if (fileObject == null || !fileObject.exists() || fileObject.getType().equals(FileType.IMAGINARY)) { return null; } BufferedReader fileReader = new BufferedReader( new InputStreamReader(fileObject.getContent().getInputStream())); StringBuilder sb = new StringBuilder(); String line; while ((line = fileReader.readLine()) != null) { sb.append(line); } content = sb.toString(); } catch (Exception ex) { } finally { try { if (fileObject != null) { fileObject.close(); } if (fsManager != null) { fsManager.freeUnusedResources(); fsManager.close(); fsManager = null; } } catch (Exception ex) { } finally { fileObject = null; fsManager = null; } } return content; }
From source file:com.sludev.commons.vfs2.provider.azure.AzFileObject.java
/** * Callback for checking the type of the current FileObject. Typically can * be of type.../* w ww.ja v a 2 s . c o m*/ * FILE for regular remote files * FOLDER for regular remote containers * IMAGINARY for a path that does not exist remotely. * * @return * @throws Exception */ @Override protected FileType doGetType() throws Exception { FileType res; Pair<String, String> path = getContainerAndPath(); if (currBlob.exists()) { res = FileType.FILE; } else { // Blob Service does not have folders. Just files with path separators in // their names. // Here's the trick for folders. // // Do a listing on that prefix. If it returns anything, after not // existing, then it's a folder. String prefix = path.getRight(); if (prefix.endsWith("/") == false) { // We need folders ( prefixes ) to end with a slash prefix += "/"; } Iterable<ListBlobItem> blobs = null; if (prefix.equals("/")) { // Special root path case. List the root blobs with no prefix blobs = currContainer.listBlobs(); } else { blobs = currContainer.listBlobs(prefix); } if (blobs.iterator().hasNext()) { res = FileType.FOLDER; } else { res = FileType.IMAGINARY; } } return res; }
From source file:com.sludev.commons.vfs2.provider.s3.SS3FileObject.java
/** * Callback for checking the type of the current FileObject. Typically can * be of type...//from w w w . jav a2 s .c o m * FILE for regular remote files * FOLDER for regular remote containers * IMAGINARY for a path that does not exist remotely. * * @return * @throws Exception */ @Override protected FileType doGetType() throws Exception { FileType res; Pair<String, String> path = getContainerAndPath(); if (objectExists(path.getLeft(), path.getRight())) { res = FileType.FILE; } else { // Blob Service does not have folders. Just files with path separators in // their names. // Here's the trick for folders. // // Do a listing on that prefix. If it returns anything, after not // existing, then it's a folder. String prefix = path.getRight(); if (prefix.endsWith("/") == false) { // We need folders ( prefixes ) to end with a slash prefix += "/"; } ObjectListing blobs = null; if (prefix.equals("/")) { // Special root path case. List the root blobs with no prefix blobs = fileSystem.getClient().listObjects(path.getLeft()); } else { blobs = fileSystem.getClient().listObjects(path.getLeft(), prefix); } if (blobs.getObjectSummaries().isEmpty()) { res = FileType.IMAGINARY; } else { res = FileType.FOLDER; } } return res; }
From source file:com.sshtools.appframework.ui.IconStore.java
public Icon getIconForFile(FileObject file, int size, boolean useMagic) { try {//from w w w . j a va 2 s. c o m if (file.getType().equals(FileType.FILE)) { MIMEEntry mime = mimeCache.get(file); if (mime == null) { mime = mimeService.getMimeTypeForFile(file, useMagic); } if (mime != null) { mimeCache.cache(file, mime); } if (mime != null && mime.getIcon() != null) { Icon icon = getIcon(mime.getIcon(), size); if (icon != null) { return icon; } } if (mime != null && mime.getGenericIcon() != null) { Icon icon = getIcon(mime.getGenericIcon(), size); if (icon != null) { return icon; } } if (mime != null && mime.getSubclasses() != null) { for (String subclass : mime.getSubclasses()) { Icon icon = getIcon(subclass, size); if (icon != null) { return icon; } } } return getIcon("text-x-generic", size); } else if (file.getType().equals(FileType.FOLDER)) { return getIcon("folder", size); } else if (file.getType().equals(FileType.IMAGINARY)) { return getIcon("emblem-unreadable", size); } else { return getIcon("text-x-generic", size); } } catch (Exception fse) { LOG.debug("Failed to load icon.", fse); return getIcon("dialog-error", size); } }
From source file:fr.cls.atoll.motu.library.misc.vfs.provider.gsiftp.GsiFtpFileObject.java
/** * Called when the children of this file change. * /*from w w w . j a v a 2s. c om*/ * @param child the child * @param newType the new type */ @Override protected void onChildrenChanged(FileName child, FileType newType) { if (children != null && newType.equals(FileType.IMAGINARY)) { try { children.remove(UriParser.decode(child.getBaseName())); } catch (FileSystemException e) { throw new RuntimeException(e.getMessage()); } } else { // if child was added we have to rescan the children // TODO - get rid of this children = null; } }
From source file:fr.cls.atoll.motu.library.misc.vfs.provider.gsiftp.GsiFtpFileObject.java
/** * Called when the type or content of this file changes. * //w w w .j av a 2 s .c o m * @throws IOException Signals that an I/O exception has occurred. */ @Override protected void onChange() throws IOException { children = null; if (getType().equals(FileType.IMAGINARY)) { // file is deleted, avoid server lookup this.fileInfo = null; return; } getInfo(true); }
From source file:fr.cls.atoll.motu.library.misc.vfs.provider.gsiftp.GsiFtpFileObject.java
/** * Determines the type of the file, returns null if the file does not exist. * //w ww . j a v a 2s . c o m * @return the file type * * @throws Exception the exception */ @Override protected FileType doGetType() throws Exception { // log.debug("relative path:" + relPath); if (this.fileInfo == null) { return FileType.IMAGINARY; } else if (this.fileInfo.isDirectory()) { return FileType.FOLDER; } else if (this.fileInfo.isFile()) { return FileType.FILE; } else if (this.fileInfo.isSoftLink()) { return FileType.FILE; // getLinkDestination().getType(); } throw new FileSystemException("vfs.provider.gsiftp/get-type.error", getName()); }
From source file:org.apache.accumulo.start.classloader.vfs.providers.HdfsFileObject.java
@Override protected FileType doGetType() throws Exception { try {//from ww w . j a v a2s . c om doAttach(); if (null == stat) { return FileType.IMAGINARY; } if (stat.isDirectory()) { return FileType.FOLDER; } else { return FileType.FILE; } } catch (final FileNotFoundException fnfe) { return FileType.IMAGINARY; } }