List of usage examples for org.apache.commons.vfs2 FileObject getName
FileName getName();
From source file:com.sludev.commons.vfs.simpleshell.SimpleShell.java
/** * Does an 'ls' command./*from ww w . j a va 2 s.c om*/ * * @param cmd * @throws org.apache.commons.vfs2.FileSystemException */ public void ls(final String[] cmd) throws FileSystemException { int pos = 1; final boolean recursive; if (cmd.length > pos && cmd[pos].equals("-R")) { recursive = true; pos++; } else { recursive = false; } final FileObject file; if (cmd.length > pos) { file = mgr.resolveFile(cwd, cmd[pos]); } else { file = cwd; } switch (file.getType()) { case FOLDER: // List the contents System.out.println("Contents of " + file.getName()); listChildren(file, recursive, ""); break; case FILE: // Stat the file System.out.println(file.getName()); final FileContent content = file.getContent(); System.out.println("Size: " + content.getSize() + " bytes."); final DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM); final String lastMod = dateFormat.format(new Date(content.getLastModifiedTime())); System.out.println("Last modified: " + lastMod); break; case IMAGINARY: System.out.println(String.format("File '%s' is IMAGINARY", file.getName())); break; default: log.error(String.format("Unkown type '%d' on '%s'", file.getType(), file.getName())); break; } }
From source file:com.streamsets.pipeline.stage.origin.remote.FTPRemoteDownloadSourceDelegate.java
private long getModTime(FileObject fileObject) throws FileSystemException { long modTime = fileObject.getContent().getLastModifiedTime(); if (supportsMDTM) { FtpClient ftpClient = null;//from ww w .j a v a2 s . c o m FtpFileSystem ftpFileSystem = (FtpFileSystem) remoteDir.getFileSystem(); try { ftpClient = ftpFileSystem.getClient(); FTPClient rawFtpClient = (FTPClient) getFtpClient.invoke(ftpClient); String path = fileObject.getName().getPath(); if (conf.userDirIsRoot && path.startsWith("/")) { // Remove the leading slash to turn it into a proper relative path path = path.substring(1); } FTPFile ftpFile = rawFtpClient.mdtmFile(path); if (ftpFile != null) { modTime = ftpFile.getTimestamp().getTimeInMillis(); } } catch (Exception e) { LOG.trace("Ignoring Exception from MDTM command and falling back to basic timestamp", e); } finally { if (ftpClient != null) { ftpFileSystem.putClient(ftpClient); } } } return modTime; }
From source file:com.streamsets.pipeline.stage.origin.remote.RemoteDownloadSource.java
private void queueFiles() throws FileSystemException { remoteDir.refresh();/*w w w . j a va 2 s . c om*/ for (FileObject remoteFile : remoteDir.getChildren()) { if (remoteFile.getType().toString().equals("folder")) continue; long lastModified = remoteFile.getContent().getLastModifiedTime(); RemoteFile tempFile = new RemoteFile(remoteFile.getName().getBaseName(), lastModified, remoteFile); if (shouldQueue(tempFile)) { // If we are done with all files, the files with the final mtime might get re-ingested over and over. // So if it is the one of those, don't pull it in. fileQueue.add(tempFile); } } }
From source file:com.web.server.EJBDeployer.java
@Override public void fileDeleted(FileChangeEvent arg0) throws Exception { FileObject baseFile = arg0.getFile(); if (baseFile.getName().getURI().endsWith(".jar")) { System.out.println(jarEJBMap.get(baseFile.getName().getURI())); EJBContext ejbContext = jarEJBMap.get(baseFile.getName().getURI()); if (ejbContext != null) { HashMap<String, Class> bindings = ejbContext.getRemoteBindings(); Set<String> remoteBindings = bindings.keySet(); Iterator<String> remoteBinding = remoteBindings.iterator(); while (remoteBinding.hasNext()) { String binding = (String) remoteBinding.next(); registry.unbind(binding); System.out.println("unregistering the class" + bindings.get(binding)); }// w w w . j a v a 2 s.c o m jarEJBMap.remove(baseFile.getName().getURI()); } ConcurrentHashMap<String, MDBContext> mdbContexts = jarMDBMap.get(baseFile.getName().getURI()); MDBContext mdbContext; if (mdbContexts != null) { Iterator<String> mdbnames = mdbContexts.keySet().iterator(); while (mdbnames.hasNext()) { String mdbname = mdbnames.next(); mdbContext = mdbContexts.get(mdbname); if (mdbContext.getConsumer() != null) { mdbContext.getConsumer().setMessageListener(null); mdbContext.getConsumer().close(); } if (mdbContext.getSession() != null) mdbContext.getSession().close(); if (mdbContext.getConnection() != null) mdbContext.getConnection().close(); mdbContexts.remove(mdbname); } jarMDBMap.remove(baseFile.getName().getURI()); } } System.out.println(baseFile.getName().getURI() + " UnDeployed"); }
From source file:hadoopInstaller.installation.UploadConfiguration.java
private String getLocalFileContents(String fileName) throws InstallationError { log.debug("HostInstallation.LoadingLocal", //$NON-NLS-1$ fileName);//w ww . j av a 2 s . com FileObject localFile; String localFileContents = new String(); try { localFile = filesToUpload.resolveFile(fileName); if (localFile.exists()) { localFileContents = IOUtils.toString(localFile.getContent().getInputStream()); } } catch (IOException e) { throw new InstallationError(e, "HostInstallation.CouldNotOpen", //$NON-NLS-1$ fileName); } try { localFile.close(); } catch (FileSystemException e) { log.warn("HostInstallation.CouldNotClose", //$NON-NLS-1$ localFile.getName().getURI()); } log.debug("HostInstallation.LoadedLocal", //$NON-NLS-1$ fileName); return localFileContents; }
From source file:architecture.ee.jdbc.sqlquery.factory.impl.AbstractSqlQueryFactory.java
protected void loadResourceLocations() { List<FileObject> list = new ArrayList<FileObject>(); Repository repository = Bootstrap.getBootstrapComponent(Repository.class); /**/*w w w . java 2s. c o m*/ * log.debug("searching sql in jar ..."); * if(!isEmpty(this.sqlLocations)){ for(Resource sqlLocation : * sqlLocations ){ if(sqlLocation == null) continue; * * * // log.debug(sqlLocation.toString()); } } **/ /* * String value = * repository.getSetupApplicationProperties().getStringProperty( * "resources.sql", ""); String[] resources = StringUtils.split(value); * if( resources.length > 0 ){ log.debug( * "using custom sql resources instade of " + resourceLocations ); for( * String path : resources ){ try { FileObject f = * VFSUtils.resolveFile(path); if (f.exists()) { list.add(f); } } catch * (Throwable e) { log.warn(path + " not found.", e); } } }else{ for * (String path : resourceLocations) { try { FileObject f = * VFSUtils.resolveFile(path); if (f.exists()) { list.add(f); } } catch * (Throwable e) { log.warn(path + " not found.", e); } } } */ try { log.debug("searching sql ..."); ClassLoader cl = Thread.currentThread().getContextClassLoader(); Enumeration<URL> paths = cl.getResources("sql/"); do { if (!paths.hasMoreElements()) break; URL url = paths.nextElement(); String pathToUse = "jar:" + url.getPath(); log.debug("target:" + pathToUse); FileObject fo = VFSUtils.resolveFile(pathToUse); FileObject[] selected = findSqlFiles(fo); for (FileObject f : selected) { if (!list.contains(f)) { list.add(f); } } } while (true); } catch (Throwable e) { log.warn(e); } for (FileObject fo : list) { try { log.debug("sql : " + fo.getName()); if (!configuration.isResourceLoaded(fo.getName().getURI())) { buildSqlFromInputStream(fo.getContent().getInputStream(), configuration); configuration.addLoadedResource(fo.getName().getURI()); } } catch (FileSystemException e) { log.warn(e); } } }
From source file:de.innovationgate.wgpublisher.design.fs.FileSystemDesignSource.java
public WGADesign getDesign(final String name) throws WGADesignRetrievalException { try {/* w w w. ja va 2s .c o m*/ // Design archive (obsolete) if (name.startsWith(DESIGNNAMEPREFIX_ARCHIVE)) { String designName = name.substring(DESIGNNAMEPREFIX_ARCHIVE.length()); FileObject designFile = _dir.resolveFile(designName + ARCHIVED_DESIGN_EXTENSION); if (!designFile.exists()) { return null; } WGADesign design = new WGADesign(); design.setSource(this); design.setName(name); design.setTitle(designFile.getName().getBaseName()); design.setDescription("Design at location " + designFile.getURL().toString()); return design; } // Additional directory else if (name.startsWith(DESIGNNAMEPREFIX_ADDITIONALDIR)) { String designName = name.substring(DESIGNNAMEPREFIX_ADDITIONALDIR.length()); String dirPath = _additionalDirs.get(designName); if (dirPath == null) { return null; } FileObject dir = VFS.getManager().resolveFile((String) dirPath); if (!dir.exists() || !dir.getType().equals(FileType.FOLDER)) { return null; } FileObject syncInfo = DesignDirectory.getDesignDefinitionFile(dir); // Non-empty directories without syncinfo may not be used as design directories if (syncInfo == null && dir.getChildren().length != 0) { return null; } WGADesign design = new WGADesign(); design.setSource(this); design.setName(DESIGNNAMEPREFIX_ADDITIONALDIR + name); design.setTitle(dir.getName().getBaseName()); design.setDescription("Design at location " + dir.getURL().toString()); design.setConfig(loadConfig(syncInfo)); design.setOverlayData(loadOverlayData(syncInfo)); return design; } // Regular design in configured directory else { _dir.refresh(); FileObject child = _dir.resolveFile(name); if (!child.exists()) { return null; } FileObject resolvedChild = WGUtils.resolveDirLink(child); if (!resolvedChild.getType().equals(FileType.FOLDER)) { return null; } FileObject syncInfo = DesignDirectory.getDesignDefinitionFile(resolvedChild); // Non-empty directories without syncinfo may not be used as design directories if (syncInfo == null && child.getChildren().length != 0) { return null; } WGADesign design = new WGADesign(); design.setSource(this); design.setName(child.getName().getBaseName()); design.setTitle(child.getName().getBaseName()); design.setDescription("Design at location " + child.getURL().toString()); design.setConfig(loadConfig(syncInfo)); design.setOverlayData(loadOverlayData(syncInfo)); return design; } } catch (FileSystemException e) { throw new WGADesignRetrievalException("Exception retrieving file system designs", e); } }
From source file:com.mirth.connect.util.MessageImporter.java
private void importVfsFile(FileObject file, MessageWriter messageWriter, int[] result) throws InterruptedException, MessageImportException { InputStream inputStream = null; try {/*from w w w . java 2 s. c o m*/ inputStream = file.getContent().getInputStream(); // scan the first XML_SCAN_BUFFER_SIZE bytes in the file to see if it contains message xml char[] cbuf = new char[XML_SCAN_BUFFER_SIZE]; new InputStreamReader(inputStream, CHARSET).read(cbuf); if (StringUtils.contains(new String(cbuf), OPEN_ELEMENT)) { logger.debug("Importing file: " + file.getName().getURI()); // re-open the input stream to reposition it at the beginning of the stream inputStream.close(); inputStream = file.getContent().getInputStream(); importMessagesFromInputStream(inputStream, messageWriter, result); } } catch (IOException e) { throw new MessageImportException(e); } finally { IOUtils.closeQuietly(inputStream); } }
From source file:com.stratuscom.harvester.deployer.StarterServiceDeployer.java
void createWorkDirectoryFor(ApplicationEnvironment env) throws IOException { FileObject managerDir = fileUtility.getWorkingDirectory(env.getApplicationManagerName()); FileObject workingDir = managerDir.resolveFile(env.getServiceName()); if (!workingDir.exists()) { workingDir.createFolder();//from w ww . j a v a 2s .c om } File workingDirFile = new File(workingDir.getName().getPath()); env.setWorkingDirectory(workingDirFile); }
From source file:com.app.server.SARDeployer.java
/** * This method extracts the SAR archive and configures for the SAR and starts the services * @param file/* w w w . j a v a 2 s . c o m*/ * @param warDirectoryPath * @throws IOException */ public void extractSarDeploy(ClassLoader cL, Object... args) throws IOException { CopyOnWriteArrayList classPath = null; File file = null; String fileName = ""; String fileWithPath = ""; if (args[0] instanceof File) { classPath = new CopyOnWriteArrayList(); file = (File) args[0]; fileWithPath = file.getAbsolutePath(); ZipFile zip = new ZipFile(file); ZipEntry ze = null; fileName = file.getName(); fileName = fileName.substring(0, fileName.indexOf('.')); fileName += "sar"; String fileDirectory; Enumeration<? extends ZipEntry> entries = zip.entries(); int numBytes; while (entries.hasMoreElements()) { ze = entries.nextElement(); // //log.info("Unzipping " + ze.getName()); String filePath = serverConfig.getDeploydirectory() + "/" + fileName + "/" + ze.getName(); if (!ze.isDirectory()) { fileDirectory = filePath.substring(0, filePath.lastIndexOf('/')); } else { fileDirectory = filePath; } // //log.info(fileDirectory); createDirectory(fileDirectory); if (!ze.isDirectory()) { FileOutputStream fout = new FileOutputStream(filePath); byte[] inputbyt = new byte[8192]; InputStream istream = zip.getInputStream(ze); while ((numBytes = istream.read(inputbyt, 0, inputbyt.length)) >= 0) { fout.write(inputbyt, 0, numBytes); } fout.close(); istream.close(); if (ze.getName().endsWith(".jar")) { classPath.add(filePath); } } } zip.close(); } else if (args[0] instanceof FileObject) { FileObject fileObj = (FileObject) args[0]; fileName = fileObj.getName().getBaseName(); try { fileWithPath = fileObj.getURL().toURI().toString(); } catch (URISyntaxException e) { // TODO Auto-generated catch block e.printStackTrace(); } fileName = fileName.substring(0, fileName.indexOf('.')); fileName += "sar"; classPath = unpack(fileObj, new File(serverConfig.getDeploydirectory() + "/" + fileName + "/"), (StandardFileSystemManager) args[1]); } URLClassLoader loader = (URLClassLoader) ClassLoader.getSystemClassLoader(); URL[] urls = loader.getURLs(); WebClassLoader sarClassLoader; if (cL != null) { sarClassLoader = new WebClassLoader(urls, cL); } else { sarClassLoader = new WebClassLoader(urls); } for (int index = 0; index < classPath.size(); index++) { // log.info("file:"+classPath.get(index)); sarClassLoader.addURL(new URL("file:" + classPath.get(index))); } sarClassLoader.addURL(new URL("file:" + serverConfig.getDeploydirectory() + "/" + fileName + "/")); //log.info(sarClassLoader.geturlS()); sarsMap.put(fileWithPath, sarClassLoader); try { Sar sar = (Sar) sardigester.parse(new InputSource(new FileInputStream( serverConfig.getDeploydirectory() + "/" + fileName + "/META-INF/" + "mbean-service.xml"))); CopyOnWriteArrayList mbeans = sar.getMbean(); //log.info(mbeanServer); ObjectName objName, classLoaderObjectName = new ObjectName("com.app.server:classLoader=" + fileName); if (!mbeanServer.isRegistered(classLoaderObjectName)) { mbeanServer.registerMBean(sarClassLoader, classLoaderObjectName); } else { mbeanServer.unregisterMBean(classLoaderObjectName); mbeanServer.registerMBean(sarClassLoader, classLoaderObjectName); ; } for (int index = 0; index < mbeans.size(); index++) { Mbean mbean = (Mbean) mbeans.get(index); //log.info(mbean.getObjectname()); //log.info(mbean.getCls()); objName = new ObjectName(mbean.getObjectname()); Class service = sarClassLoader.loadClass(mbean.getCls()); if (mbeanServer.isRegistered(objName)) { //mbs.invoke(objName, "stopService", null, null); //mbs.invoke(objName, "destroy", null, null); mbeanServer.unregisterMBean(objName); } mbeanServer.createMBean(service.getName(), objName, classLoaderObjectName); //mbs.registerMBean(obj, objName); CopyOnWriteArrayList attrlist = mbean.getMbeanAttribute(); if (attrlist != null) { for (int count = 0; count < attrlist.size(); count++) { MBeanAttribute attr = (MBeanAttribute) attrlist.get(count); Attribute mbeanattribute = new Attribute(attr.getName(), attr.getValue()); mbeanServer.setAttribute(objName, mbeanattribute); } } Attribute mbeanattribute = new Attribute("ObjectName", objName); mbeanServer.setAttribute(objName, mbeanattribute); if (((String) mbeanServer.getAttribute(objName, "Deployer")).equals("true")) { mbeanServer.invoke(objName, "init", new Object[] { deployerList }, new String[] { Vector.class.getName() }); } mbeanServer.invoke(objName, "init", new Object[] { serviceList, serverConfig, mbeanServer }, new String[] { Vector.class.getName(), ServerConfig.class.getName(), MBeanServer.class.getName() }); mbeanServer.invoke(objName, "start", null, null); serviceListObjName.put(fileWithPath, objName); } } catch (Exception e) { log.error("Could not able to deploy sar archive " + fileWithPath, e); // TODO Auto-generated catch block //e.printStackTrace(); } }