List of usage examples for org.apache.commons.vfs2 FileType FILE
FileType FILE
To view the source code for org.apache.commons.vfs2 FileType FILE.
Click Source Link
From source file:net.sourceforge.fullsync.ui.FileObjectChooser.java
private void populateList() throws FileSystemException { FileObject[] children = activeFileObject.getChildren(); Arrays.sort(children, (o1, o2) -> { try {//from w w w .ja v a 2 s. co m if ((o1.getType() == FileType.FOLDER) && (o2.getType() == FileType.FILE)) { return -1; } else if ((o1.getType() == FileType.FILE) && (o2.getType() == FileType.FOLDER)) { return 1; } return o1.getName().getBaseName().compareTo(o2.getName().getBaseName()); } catch (FileSystemException fse) { fse.printStackTrace(); return 0; } }); DateFormat df = DateFormat.getDateTimeInstance(); for (int i = 0; i < children.length; i++) { FileObject data = children[i]; TableItem item; if (tableItems.getItemCount() <= i) { item = new TableItem(tableItems, SWT.NULL); } else { item = tableItems.getItem(i); } item.setText(0, data.getName().getBaseName()); String type = data.getType().getName(); //FIXME: translate type name {file,folder} if (data.getType().hasContent()) { FileContent content = data.getContent(); String contentType = content.getContentInfo().getContentType(); if (null != contentType) { type += " (" + contentType + ")"; //$NON-NLS-1$ //$NON-NLS-2$ } item.setText(1, String.valueOf(content.getSize())); item.setText(3, df.format(new Date(content.getLastModifiedTime()))); } else { item.setText(1, ""); //$NON-NLS-1$ item.setText(3, ""); //$NON-NLS-1$ } item.setText(2, type); if (data.getType() == FileType.FOLDER) { item.setImage(imageRepository.getImage("FS_Folder_Collapsed.gif")); //$NON-NLS-1$ } else { item.setImage(imageRepository.getImage("FS_File_text_plain.gif")); //$NON-NLS-1$ } item.setData(data); } tableItems.setItemCount(children.length); }
From source file:com.sludev.commons.vfs.simpleshell.SimpleShell.java
/** * Does a 'cat' command./* w w w. jav a 2 s. c o m*/ * * @param cmd * @throws SimpleShellException */ public void cat(String[] cmd) throws SimpleShellException { if (cmd.length < 2) { throw new SimpleShellException("USAGE: cat <path>"); } // Locate the file FileObject file; try { file = mgr.resolveFile(cwd, cmd[1]); } catch (FileSystemException ex) { String errMsg = String.format("Error resolving file '%s'", cmd[1]); //log.error( errMsg, ex); throw new SimpleShellException(errMsg, ex); } try { if (file.exists() == false) { // Can't cat a file that doesn't exist System.out.println(String.format("File '%s' does not exist", cmd[1])); return; } } catch (FileSystemException ex) { String errMsg = String.format("Error exists() on file '%s'", cmd[1]); //log.error( errMsg, ex); throw new SimpleShellException(errMsg, ex); } try { if (file.getType() != FileType.FILE) { // Only cat files System.out.println(String.format("File '%s' is not an actual file.", cmd[1])); return; } } catch (FileSystemException ex) { String errMsg = String.format("Error getType() on file '%s'", cmd[1]); //log.error( errMsg, ex); throw new SimpleShellException(errMsg, ex); } try { // Dump the contents to System.out FileUtil.writeContent(file, System.out); } catch (IOException ex) { String errMsg = String.format("Error WriteContent() on file '%s'", cmd[1]); //log.error( errMsg, ex); throw new SimpleShellException(errMsg, ex); } System.out.println(); }
From source file:com.stratuscom.harvester.deployer.StarterServiceDeployer.java
public Properties readStartProperties(FileObject serviceRoot) throws FileSystemException, LocalizedRuntimeException, IOException { /*/*from w ww . j ava2s . co m*/ Read the start.properties file. */ FileObject startProperties = serviceRoot.resolveFile(Strings.START_PROPERTIES); if (startProperties == null || !startProperties.getType().equals(FileType.FILE) || !startProperties.isReadable()) { throw new LocalizedRuntimeException(MessageNames.BUNDLE_NAME, MessageNames.CANT_READ_START_PROPERTIES, new Object[] { Strings.START_PROPERTIES, serviceRoot.getName().getBaseName() }); } Properties startProps = propertiesFileReader.getProperties(startProperties); return startProps; }
From source file:de.innovationgate.wgpublisher.design.fs.AbstractDesignFile.java
protected List<FileObject> getFileContainerFiles() throws FileSystemException, WGDesignSyncException { FileObject[] filesArray = getCodeFile().getChildren(); if (filesArray == null) { throw new WGDesignSyncException("Cannot collect files from directory '" + getCodeFile().getName().getPathDecoded() + "'. Please verify directory existence."); }//from w w w . j av a 2 s. c om List<FileObject> files = new ArrayList<FileObject>(); for (FileObject fileobj : filesArray) { if (fileobj.getType().equals(FileType.FILE) && !isExcludedFileContainerFile(fileobj)) { files.add(fileobj); } } return files; }
From source file:com.app.server.JarDeployer.java
/** * This method obtains the class name for each of the executor services * @param jarFile/* w w w . j a va 2s . c o m*/ * @param classList * @throws FileSystemException */ public void getChildren(FileObject jarFile, CopyOnWriteArrayList classList) throws FileSystemException { if (jarFile.getType() == FileType.FILE) return; FileObject[] children = jarFile.getChildren(); //log.info( "Children of " + jarFile.getName().getURI() ); if (children == null) return; for (int i = 0; i < children.length; i++) { //log.info(children[i].+" "+ children[i].getName().getBaseName() ); if (children[i].getType() == FileType.FILE && children[i].getName().getBaseName().endsWith(".class")) classList.add(children[i].toString().substring(children[i].toString().indexOf('!') + 2)); getChildren(children[i], classList); children[i].close(); //fsManager.closeFileSystem(children[i].getFileSystem()); } }
From source file:com.web.server.JarDeployer.java
/** * This method obtains the class name for each of the executor services * @param jarFile/* ww w . j av a 2 s. c o m*/ * @param classList * @throws FileSystemException */ public void getChildren(FileObject jarFile, CopyOnWriteArrayList classList) throws FileSystemException { if (jarFile.getType() == FileType.FILE) return; FileObject[] children = jarFile.getChildren(); //System.out.println( "Children of " + jarFile.getName().getURI() ); if (children == null) return; for (int i = 0; i < children.length; i++) { //System.out.println(children[i].+" "+ children[i].getName().getBaseName() ); if (children[i].getType() == FileType.FILE && children[i].getName().getBaseName().endsWith(".class")) classList.add(children[i].toString().substring(children[i].toString().indexOf('!') + 2)); getChildren(children[i], classList); children[i].close(); //fsManager.closeFileSystem(children[i].getFileSystem()); } }
From source file:com.app.server.EARDeployer.java
public void obtainUrls(FileObject rootEar, FileObject ear, CopyOnWriteArrayList<URL> fileObjects, CopyOnWriteArrayList<FileObject> warObjects, CopyOnWriteArrayList<FileObject> jarObjects, CopyOnWriteArrayList<FileObject> sarObjects, CopyOnWriteArrayList<FileObject> rarObjects, CopyOnWriteArrayList<FileObject> ezbObjects, StandardFileSystemManager fsManager) throws IOException { FileObject[] childrenJars = ear.getChildren(); for (int childcount = 0; childcount < childrenJars.length; childcount++) { if (childrenJars[childcount].getType() == FileType.FOLDER) { obtainUrls(rootEar, childrenJars[childcount], fileObjects, warObjects, jarObjects, sarObjects, rarObjects, ezbObjects, fsManager); }//from w ww. j a va 2 s . c om // log.info(childrenJars[childcount]); // log.info(childrenJars[childcount].getName().getBaseName()); // log.info(ear.getURL()); if (childrenJars[childcount].getType() == FileType.FILE && (childrenJars[childcount].getName().getBaseName().endsWith(".jar") || childrenJars[childcount].getName().getBaseName().endsWith(".war") || childrenJars[childcount].getName().getBaseName().toLowerCase().endsWith(".rar") || childrenJars[childcount].getName().getBaseName().toLowerCase().endsWith(".sar"))) { // log.info(childrenJars[childcount].getURL()); if ((childrenJars[childcount].getName().getBaseName().toLowerCase().endsWith(".war") || childrenJars[childcount].getName().getBaseName().toLowerCase().endsWith(".jar") || childrenJars[childcount].getName().getBaseName().toLowerCase().endsWith(".rar") || childrenJars[childcount].getName().getBaseName().toLowerCase().endsWith(".sar") || childrenJars[childcount].getName().getBaseName().toLowerCase().endsWith(".ezb")) && !childrenJars[childcount].getURL().toString().trim() .startsWith(rootEar.getURL().toString() + "lib/")) { //File file=new File(serverConfig.getDeploydirectory()+"/"+childrenJars[childcount].getName().getBaseName()); /*if(!file.exists()||(file.exists()&&file.lastModified()!=childrenJars[childcount].getContent().getLastModifiedTime())){ //InputStream fistr=childrenJars[childcount].getContent().getInputStream(); byte[] filyByt=new byte[4096]; FileOutputStream warFile=new FileOutputStream(serverConfig.getDeploydirectory()+"/"+childrenJars[childcount].getName().getBaseName()+".part"); int len=0; while((len=fistr.read(filyByt))!=-1){ warFile.write(filyByt,0,len); } warFile.close(); fistr.close(); new File(serverConfig.getDeploydirectory()+"/"+childrenJars[childcount].getName().getBaseName()+".part").renameTo(file); warObjects.add(childrenJars[childcount]); }*/ if (childrenJars[childcount].getName().getBaseName().toLowerCase().endsWith(".war")) { warObjects.add(childrenJars[childcount]); } else if (childrenJars[childcount].getName().getBaseName().toLowerCase().endsWith(".jar")) { jarObjects.add(childrenJars[childcount]); } else if (childrenJars[childcount].getName().getBaseName().toLowerCase().endsWith(".sar")) { sarObjects.add(childrenJars[childcount]); } else if (childrenJars[childcount].getName().getBaseName().toLowerCase().endsWith(".rar")) { rarObjects.add(childrenJars[childcount]); } else if (childrenJars[childcount].getName().getBaseName().toLowerCase().endsWith(".ezb")) { ezbObjects.add(childrenJars[childcount]); } } else { log.info("ear libs/" + childrenJars[childcount]); fileObjects.add(new URL(childrenJars[childcount].getURL().toString() .replace(rootEar.getURL().toString(), "rsrc:"))); } // log.info(childrenJars[childcount].getURL().toString()+" "+rootEar.getURL()); } else { childrenJars[childcount].close(); } } }
From source file:com.app.server.EARDeployer.java
public static void getClassList(FileObject jarFile, CopyOnWriteArrayList classList, StandardFileSystemManager fsManager) throws FileSystemException { // log.info(jarFile); FileObject nestedFS = null;// ww w . j ava2s .co m FileObject[] children = null; if (jarFile.getURL().toString().trim().endsWith(".jar")) { nestedFS = fsManager.createFileSystem(jarFile); children = nestedFS.resolveFile("/").getChildren(); } else if (jarFile.getType() == FileType.FOLDER) { children = jarFile.getChildren(); } // log.info(); // log.info( "Children of " + jarFile.getName().getURI() ); if (children == null) return; for (int i = 0; i < children.length; i++) { // log.info(children[i].+" "+ // children[i].getName().getBaseName() ); if (children[i].getType() == FileType.FILE && children[i].getName().getBaseName().endsWith(".class")) classList.add(children[i].toString().substring(children[i].toString().lastIndexOf('!') + 2)); getClassList(children[i], classList, fsManager); } }
From source file:de.unioninvestment.portal.explorer.view.vfs.TableView.java
private void addTableItem(Table table, FileObject file) throws FileSystemException { if (file.getType() == FileType.FILE) { Item item = table.addItem(file.getName()); item.getItemProperty(TABLE_PROP_FILE_NAME).setValue(file.getName().toString()); item.getItemProperty(TABLE_PROP_FILE_SIZE).setValue(file.getContent().getSize()); item.getItemProperty(TABLE_PROP_FILE_DATE).setValue(new Date(file.getContent().getLastModifiedTime())); }//from w w w.j ava 2s . c o m }
From source file:fr.cls.atoll.motu.library.misc.vfs.VFSManager.java
/** * Delete the file repsented by the file parameter. * //from w ww . j a v a2 s .c om * @param file the file * * @return true, if successful * @throws MotuException */ public boolean deleteFile(FileObject file) throws MotuException { if (LOG.isDebugEnabled()) { LOG.debug("deleteFile(FileObject) - entering"); } boolean deleted = false; try { if (file.exists()) { if (file.getType() != FileType.FILE) { throw new MotuException(String.format("Delete file '%s' is rejected: it is a folder. ", file.getName().toString())); } deleted = file.delete(); } } catch (FileSystemException e) { LOG.error("deleteFile(FileObject)", e); // throw new MotuException(String.format("Unable to copy file '%s' to '%s'", // foSrc.getURL().toString(), foDest.getURL().toString()), e); throw new MotuException(String.format("Unable to delete '%s'", file.getName().toString()), e); } if (LOG.isDebugEnabled()) { LOG.debug("deleteFile(FileObject) - exiting"); } return deleted; }