List of usage examples for org.apache.commons.vfs2 FileType FOLDER
FileType FOLDER
To view the source code for org.apache.commons.vfs2 FileType FOLDER.
Click Source Link
From source file:ShowProperties.java
public static void main(String[] args) throws FileSystemException { if (args.length == 0) { System.err.println("Please pass the name of a file as parameter."); System.err.println("e.g. java org.apache.commons.vfs2.example.ShowProperties LICENSE.txt"); return;/*from w ww . j a v a2s . c om*/ } for (int i = 0; i < args.length; i++) { try { FileSystemManager mgr = VFS.getManager(); System.out.println(); System.out.println("Parsing: " + args[i]); FileObject file = mgr.resolveFile(args[i]); System.out.println("URL: " + file.getURL()); System.out.println("getName(): " + file.getName()); System.out.println("BaseName: " + file.getName().getBaseName()); System.out.println("Extension: " + file.getName().getExtension()); System.out.println("Path: " + file.getName().getPath()); System.out.println("Scheme: " + file.getName().getScheme()); System.out.println("URI: " + file.getName().getURI()); System.out.println("Root URI: " + file.getName().getRootURI()); System.out.println("Parent: " + file.getName().getParent()); System.out.println("Type: " + file.getType()); System.out.println("Exists: " + file.exists()); System.out.println("Readable: " + file.isReadable()); System.out.println("Writeable: " + file.isWriteable()); System.out.println("Root path: " + file.getFileSystem().getRoot().getName().getPath()); if (file.exists()) { if (file.getType().equals(FileType.FILE)) { System.out.println("Size: " + file.getContent().getSize() + " bytes"); } else if (file.getType().equals(FileType.FOLDER) && file.isReadable()) { FileObject[] children = file.getChildren(); System.out.println("Directory with " + children.length + " files"); for (int iterChildren = 0; iterChildren < children.length; iterChildren++) { System.out.println("#" + iterChildren + ": " + children[iterChildren].getName()); if (iterChildren > 5) { break; } } } System.out.println("Last modified: " + DateFormat.getInstance().format(new Date(file.getContent().getLastModifiedTime()))); } else { System.out.println("The file does not exist"); } file.close(); } catch (FileSystemException ex) { ex.printStackTrace(); } } }
From source file:com.gs.obevo.util.vfs.DirectoryFileFilter.java
@Override public boolean accept(FileSelectInfo fileInfo) { try {// w w w . j a va 2 s. c o m return fileInfo.getFile().getType() == FileType.FOLDER; } catch (FileSystemException e) { throw new RuntimeException(e); } }
From source file:architecture.common.util.vfs.VFSUtils.java
public static boolean isFolder(FileObject fo) { try {//from w w w . j av a 2 s . c o m if (fo.getType() == FileType.FOLDER) return true; } catch (FileSystemException e) { log.warn(e); } return false; }
From source file:com.gs.obevo.util.vfs.BasicFileSelector.java
@Override public boolean traverseDescendents(FileSelectInfo fileInfo) throws Exception { if (fileInfo.getFile().getType() == FileType.FOLDER && fileInfo.getDepth() == 0) { return true; } else if (this.directoryFilter != null) { return this.directoryFilter.accept(fileInfo); } else {/* w w w.j a v a 2 s. c o m*/ return this.traverseDescendents; } }
From source file:com.github.junrar.vfs2.provider.rar.RARFileObject.java
@Override protected FileType doGetType() { if (header == null || header.isDirectory()) { return FileType.FOLDER; } else {/* w w w . ja va2s . co m*/ return FileType.FILE; } }
From source file:com.github.junrar.vfs2.provider.rar.RARFileProvider.java
/** * Creates a layered file system. This method is called if the file system * is not cached.// ww w . ja va 2s . c o m * * @param scheme * The URI scheme. * @param file * The file to create the file system on top of. * @return The file system. */ @Override protected FileSystem doCreateFileSystem(final String scheme, final FileObject file, final FileSystemOptions fileSystemOptions) throws FileSystemException { final AbstractFileName rootName = new LayeredFileName(scheme, file.getName(), FileName.ROOT_PATH, FileType.FOLDER); return new RARFileSystem(rootName, file, fileSystemOptions); }
From source file:com.wipro.ats.bdre.filemon.FileMonitor.java
@Override public void fileCreated(FileChangeEvent fileChangeEvent) throws Exception { FileObject obj = fileChangeEvent.getFile(); LOGGER.debug("File Created " + obj.getURL()); String dirPath = obj.getParent().getName().getPath(); LOGGER.debug("Full path " + obj.getName().getPath()); //Don't process anything with _archive if (dirPath.startsWith(monDir + "/" + archiveDirName)) { return;// w w w.jav a 2 s . c om } //Don't process directory if (obj.getType() == FileType.FOLDER) { return; } String fileName = obj.getName().getPath(); //Checking if the file name matches with the given pattern if (fileName.matches(filePattern)) { FileContent fc = obj.getContent(); LOGGER.debug("Matched File Pattern by " + fileName); putEligibleFileInfoInMap(fileName, fc); } }
From source file:com.wipro.ats.bdre.tdimport.FileMonitor.java
@Override public void fileCreated(FileChangeEvent fileChangeEvent) throws Exception { FileObject obj = fileChangeEvent.getFile(); LOGGER.debug("File Created " + obj.getURL()); String dirPath = obj.getParent().getName().getPath(); LOGGER.debug("Full path " + obj.getName().getPath()); //Don't process anything with _archive if (dirPath.startsWith(monDir + "/" + archiveDirName)) { return;/*from w w w. jav a 2s.com*/ } //Don't process directory if (obj.getType() == FileType.FOLDER) { return; } String fileName = obj.getName().getPath(); //Checking if the file name matches with the given pattern if (fileName.matches(filePattern)) { FileContent fc = obj.getContent(); LOGGER.debug("Matched File Pattern by " + fileName); putEligibleFileInfoInMap(obj.getName().getBaseName(), fc); } }
From source file:edu.byu.nlp.data.docs.VectorDocumentDatasetBuilder.java
/** * See class description./*from w w w .j a v a2 s . c om*/ * * @throws FileSystemException if there is a problem finding the specified directories on the * filesystem. */ public VectorDocumentDatasetBuilder(String basedir, String dataset, String split) throws FileSystemException { // TODO: consider taking the FileObject as a parameter FileSystemManager fsManager = VFS.getManager(); if (fsManager instanceof DefaultFileSystemManager) { ((DefaultFileSystemManager) fsManager).setBaseFile(new File(".")); } this.basedir = fsManager.resolveFile(basedir); Preconditions.checkNotNull(this.basedir, "%s cannot be resolved", basedir); Preconditions.checkArgument(this.basedir.getType() == FileType.FOLDER); FileObject indices = this.basedir.getChild("indices"); Preconditions.checkNotNull(indices, "cannot find indices directory in %s", basedir); FileObject datasetDir = indices.getChild(dataset); Preconditions.checkNotNull(datasetDir, "cannot find index for dataset %s", dataset); this.indexDirectory = datasetDir.getChild(split); Preconditions.checkNotNull(indexDirectory, "cannot find split %s", split); Preconditions.checkArgument(indexDirectory.getType() == FileType.FOLDER); }
From source file:coria2015.server.ContentServlet.java
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { final URL url; IMAGE_URI = "/recipe/image/"; if (request.getRequestURI().startsWith(IMAGE_URI)) { String recipeName = URLDecoder.decode(request.getRequestURI().substring(IMAGE_URI.length()), "UTF-8") .replace(" ", "-"); String name = recipeImages.get(recipeName); File file = new File(imagePath, name); url = file.toURI().toURL();/*from w ww. j a va 2s.c o m*/ } else { url = ContentServlet.class.getResource(format("/web%s", request.getRequestURI())); } if (url != null) { FileSystemManager fsManager = VFS.getManager(); FileObject file = fsManager.resolveFile(url.toExternalForm()); if (file.getType() == FileType.FOLDER) { response.setStatus(HttpServletResponse.SC_MOVED_PERMANENTLY); response.setHeader("Location", format("%sindex.html", request.getRequestURI())); return; } String filename = url.getFile(); if (filename.endsWith(".html")) response.setContentType("text/html"); else if (filename.endsWith(".png")) response.setContentType("image/png"); else if (filename.endsWith(".css")) response.setContentType("text/css"); response.setStatus(HttpServletResponse.SC_OK); final ServletOutputStream out = response.getOutputStream(); InputStream in = url.openStream(); byte[] buffer = new byte[8192]; int read; while ((read = in.read(buffer)) > 0) { out.write(buffer, 0, read); } out.flush(); in.close(); return; } // Not found error404(request, response); }