List of usage examples for org.apache.commons.vfs2 FileObject getName
FileName getName();
From source file:org.pentaho.vfs.ui.VfsFileChooserDialog.java
public void fireFileObjectDoubleClicked(FileObject selectedItem) { if (fileDialogMode != VFS_DIALOG_SAVEAS) { // let's try drilling into the file as a new vfs root first String scheme = null;//w w w . j a v a 2 s.c om if (selectedItem.getName().getExtension().contains("jar")) { scheme = "jar:"; } else if (selectedItem.getName().getExtension().contains("zip")) { scheme = "zip:"; } else if (selectedItem.getName().getExtension().contains("gz")) { scheme = "gz:"; } else if (selectedItem.getName().getExtension().contains("war")) { scheme = "war:"; } else if (selectedItem.getName().getExtension().contains("ear")) { scheme = "ear:"; } else if (selectedItem.getName().getExtension().contains("sar")) { scheme = "sar:"; } else if (selectedItem.getName().getExtension().contains("tar")) { scheme = "tar:"; } else if (selectedItem.getName().getExtension().contains("tbz2")) { scheme = "tbz2:"; } else if (selectedItem.getName().getExtension().contains("tgz")) { scheme = "tgz:"; } else if (selectedItem.getName().getExtension().contains("bz2")) { scheme = "bz2:"; } if (scheme != null) { try { FileObject jarFileObject = selectedItem.getFileSystem().getFileSystemManager() .resolveFile(scheme + selectedItem.getName().getURI()); vfsBrowser.resetVfsRoot(jarFileObject); updateParentFileCombo(jarFileObject); vfsBrowser.fileSystemTree.forceFocus(); } catch (FileSystemException e) { e.printStackTrace(); okPressed = true; hideCustomPanelChildren(); dialog.dispose(); } } else { okPressed = true; hideCustomPanelChildren(); dialog.dispose(); } } else { // anything? } }
From source file:org.pentaho.vfs.ui.VfsFileChooserDialog.java
public void setSelectedFile(FileObject selectedFile) { this.selectedFile = selectedFile; if (selectedFile != null) { this.openFileCombo.setText(selectedFile.getName().getURI()); resolveVfsBrowser();//from w w w . ja va 2s .c o m } }
From source file:org.pieShare.pieShareApp.service.fileService.fileListenerService.ApacheDefaultFileListener.java
private File convertFileObject(FileObject object) { return new File(object.getName().getPath()); }
From source file:org.renjin.appengine.AppEngineLocalFilesSystemProviderTest.java
@Test public void test() throws FileSystemException { File basePath = new File(getClass().getResource("/jarfiletest.jar").getFile()).getParentFile(); FileSystemManager dfsm = AppEngineContextFactory .createFileSystemManager(new AppEngineLocalFilesSystemProvider(basePath)); FileObject jarFile = dfsm.resolveFile("/jarfiletest.jar"); assertThat(jarFile.getName().getURI(), equalTo("file:///jarfiletest.jar")); assertThat(jarFile.exists(), equalTo(true)); FileObject jarRoot = dfsm.resolveFile("jar:file:///jarfiletest.jar!/r/library"); assertThat(jarRoot.exists(), equalTo(true)); assertThat(jarRoot.getType(), equalTo(FileType.FOLDER)); assertThat(jarRoot.getChildren().length, equalTo(1)); }
From source file:org.renjin.primitives.files.Files.java
/** * Utility function to extract information about files on the user's file systems. * * @param context current call Context//from w w w. j a v a 2 s. c o m * @param paths the list of files for which to return information * @return list column-oriented table of file information * @throws FileSystemException */ @Internal("file.info") public static ListVector fileInfo(@Current Context context, StringVector paths) throws FileSystemException { DoubleArrayVector.Builder size = new DoubleArrayVector.Builder(); LogicalArrayVector.Builder isdir = new LogicalArrayVector.Builder(); IntArrayVector.Builder mode = (IntArrayVector.Builder) new IntArrayVector.Builder() .setAttribute(Symbols.CLASS, StringVector.valueOf("octmode")); DoubleArrayVector.Builder mtime = new DoubleArrayVector.Builder(); StringVector.Builder exe = new StringVector.Builder(); for (String path : paths) { if (StringVector.isNA(path)) { throw new EvalException("invalid filename argument"); } FileObject file = context.resolveFile(path); if (file.exists()) { if (file.getType() == FileType.FILE) { size.add((int) file.getContent().getSize()); } else { size.add(0); } isdir.add(file.getType() == FileType.FOLDER); mode.add(mode(file)); try { mtime.add(file.getContent().getLastModifiedTime()); } catch (Exception e) { mtime.add(0); } exe.add(file.getName().getBaseName().endsWith(".exe") ? "yes" : "no"); } else { size.addNA(); isdir.addNA(); mode.addNA(); mtime.addNA(); exe.addNA(); } } return ListVector.newNamedBuilder().add("size", size).add("isdir", isdir).add("mode", mode) .add("mtime", mtime).add("ctime", mtime).add("atime", mtime).add("exe", exe).build(); }
From source file:org.renjin.primitives.files.Files.java
/** * {@code list.files} produce a character vector of the names of files in the named directory. * * @param paths a character vector of full path names; the default corresponds to the working * directory getwd(). Missing values will be ignored. * @param pattern an optional regular expression. Only file names which match the regular * expression will be returned.//from w w w .jav a 2s .c om * @param allFiles If FALSE, only the names of visible files are returned. If TRUE, all * file names will be returned. * @param fullNames If TRUE, the directory path is prepended to the file names. If FALSE, * only the file names are returned. * @param recursive Should the listing recurse into directories? * @param ignoreCase Should pattern-matching be case-insensitive? * * If a path does not exist or is not a directory or is unreadable it is skipped, with a warning. * The files are sorted in alphabetical order, on the full path if full.names = TRUE. Directories are included only if recursive = FALSE. * * @return */ @Internal("list.files") public static StringVector listFiles(@Current final Context context, final StringVector paths, final String pattern, final boolean allFiles, final boolean fullNames, final boolean recursive, final boolean ignoreCase, final boolean includeDirs) throws IOException { return new Object() { private final StringVector.Builder result = new StringVector.Builder(); private final RE filter = pattern == null ? null : new ExtendedRE(pattern).ignoreCase(ignoreCase); public StringVector list() throws IOException { for (String path : paths) { FileObject folder = context.resolveFile(path); if (folder.getType() == FileType.FOLDER) { if (allFiles & !recursive) { add(path, "."); add(path, ".."); } for (FileObject child : folder.getChildren()) { if (filter(child)) { add(path, child); } } } } return result.build(); } void add(String path, FileObject file) { if (fullNames) { result.add(path + "/" + file.getName().getBaseName()); } else { result.add(file.getName().getBaseName()); } } void add(String path, String name) throws FileSystemException { if (fullNames) { result.add(path + "/" + name); } else { result.add(name); } } boolean filter(FileObject child) throws FileSystemException { if (!allFiles && isHidden(child)) { return false; } if (recursive && !includeDirs && child.getType() == FileType.FOLDER) { return false; } if (filter != null && !filter.match(child.getName().getBaseName())) { return false; } return true; } private boolean isHidden(FileObject file) throws FileSystemException { return file.isHidden() || file.getName().getBaseName().startsWith("."); } }.list(); }
From source file:org.renjin.primitives.files.Files.java
/** * Helper function to extract a zip entry to the given folder. *//*from ww w . jav a2 s . c o m*/ private static void unzipExtract(ZipInputStream zin, ZipEntry entry, FileObject exdir, boolean junkpaths, boolean overwrite) throws IOException { if (junkpaths) { throw new EvalException("unzip(junpaths=false) not yet implemented"); } FileObject exfile = exdir.resolveFile(entry.getName()); if (exfile.exists() && !overwrite) { throw new EvalException("file to be extracted '%s' already exists", exfile.getName().getURI()); } OutputStream out = exfile.getContent().getOutputStream(); try { byte buffer[] = new byte[64 * 1024]; int bytesRead; while ((bytesRead = zin.read(buffer)) != -1) { out.write(buffer, 0, bytesRead); } } finally { out.close(); } }
From source file:org.wso2.carbon.connector.FileArchiveConnector.java
/** * Archive a file/folder./*ww w. j av a2 s . com*/ * * @param messageContext The message context that is generated for processing the file. * @return return true, if the file/folder is successfully archived, false, if not. * @throws FileSystemException On error parsing the file name, determining if the file exists and getting file type. */ private boolean fileCompress(MessageContext messageContext) throws FileSystemException { String source = (String) ConnectorUtils.lookupTemplateParamater(messageContext, FileConstants.FILE_LOCATION); String destination = (String) ConnectorUtils.lookupTemplateParamater(messageContext, FileConstants.NEW_FILE_LOCATION); StandardFileSystemManager manager = FileConnectorUtils.getManager(); FileSystemOptions opts = FileConnectorUtils.init(messageContext); FileObject fileObj = manager.resolveFile(source, opts); FileObject destObj = manager.resolveFile(destination, opts); if (!fileObj.exists()) { log.error("The File location does not exist."); return false; } if (FileType.FOLDER.equals(fileObj.getType())) { List<FileObject> fileList = new ArrayList<>(); addAllFilesToList(fileObj, fileList); writeZipFiles(fileObj, destObj, fileList); } else { ZipOutputStream outputStream = null; InputStream fileIn = null; try { outputStream = new ZipOutputStream(destObj.getContent().getOutputStream()); fileIn = fileObj.getContent().getInputStream(); ZipEntry zipEntry = new ZipEntry(fileObj.getName().getBaseName()); outputStream.putNextEntry(zipEntry); int length; while ((length = fileIn.read(bytes)) != -1) { outputStream.write(bytes, 0, length); } } catch (IOException e) { throw new SynapseException("Error while writing an array of bytes to the ZipOutputStream", e); } finally { try { // close the file object fileObj.close(); } catch (FileSystemException e) { log.error("Error while closing the source FileObject", e); } try { // close the file object destObj.close(); } catch (FileSystemException e) { log.error("Error while closing the destination FileObject", e); } try { if (outputStream != null) { outputStream.close(); } } catch (IOException e) { log.error("Error while closing ZipOutputStream", e); } try { if (fileIn != null) { fileIn.close(); } } catch (IOException e) { log.error("Error while closing InputStream:", e); } // close the StandardFileSystemManager manager.close(); } } if (log.isDebugEnabled()) { log.debug("File archiving completed." + destination); } return true; }
From source file:org.wso2.carbon.connector.FileArchiveConnector.java
/** * Add the file to zip directory./*from www. j a v a2 s . com*/ * * @param fileObject The fileObject where zip entry data needs to be written. * @param file The fileObject which needs to be archived. * @param outputStream ZipOutputStream. */ private void addToZip(FileObject fileObject, FileObject file, ZipOutputStream outputStream) { InputStream fin = null; try { fin = file.getContent().getInputStream(); String name = file.getName().toString(); String entry = name.substring(fileObject.getName().toString().length() + 1, name.length()); ZipEntry zipEntry = new ZipEntry(entry); outputStream.putNextEntry(zipEntry); int length; while ((length = fin.read(bytes)) != -1) { outputStream.write(bytes, 0, length); } } catch (IOException e) { throw new SynapseException("Unable to write an array of bytes to the ZIP entry data", e); } finally { try { outputStream.closeEntry(); if (fin != null) { fin.close(); } } catch (IOException e) { log.error("Error while closing InputStream", e); } try { fileObject.close(); file.close(); } catch (FileSystemException e) { log.error("Error while closing the FileObject", e); } } }
From source file:org.wso2.carbon.connector.FileArchives.java
/** * @param messageContext The message context that is generated for processing the file * @param source The file to be archived * @param destination Destination of the archived file * @return return status/*from w w w . j a v a2 s . com*/ * @throws SynapseException */ private boolean fileCompress(MessageContext messageContext, String source, String destination) { boolean resultStatus = false; StandardFileSystemManager manager; FileSystemOptions opts = FileConnectorUtils.init(messageContext); try { manager = FileConnectorUtils.getManager(); FileObject fileObj = manager.resolveFile(source, opts); FileObject destObj = manager.resolveFile(destination, opts); if (fileObj.exists()) { if (fileObj.getType() == FileType.FOLDER) { List<FileObject> fileList = new ArrayList<FileObject>(); getAllFiles(fileObj, fileList, messageContext); writeZipFiles(fileObj, destObj, fileList, messageContext); } else { ZipOutputStream outputStream = null; InputStream fileIn = null; try { outputStream = new ZipOutputStream(destObj.getContent().getOutputStream()); fileIn = fileObj.getContent().getInputStream(); ZipEntry zipEntry = new ZipEntry(fileObj.getName().getBaseName()); outputStream.putNextEntry(zipEntry); int length; while ((length = fileIn.read(bytes)) != -1) { outputStream.write(bytes, 0, length); } } catch (Exception e) { log.error("Unable to compress a file." + e.getMessage()); } finally { try { if (outputStream != null) { outputStream.close(); } } catch (IOException e) { log.error("Error while closing ZipOutputStream: " + e.getMessage(), e); } try { if (fileIn != null) { fileIn.close(); } } catch (IOException e) { log.error("Error while closing InputStream: " + e.getMessage(), e); } manager.close(); } } resultStatus = true; if (log.isDebugEnabled()) { log.debug("File archiving completed." + destination); } } else { log.error("The File location does not exist."); resultStatus = false; } } catch (IOException e) { handleException("Unable to process the zip file", e, messageContext); } return resultStatus; }