List of usage examples for org.apache.commons.vfs FileType FILE
FileType FILE
To view the source code for org.apache.commons.vfs FileType FILE.
Click Source Link
From source file:org.pentaho.s3.vfs.S3FileObjectTest.java
@Before public void setUp() throws Exception { S3Service s3ServiceMock = mock(S3Service.class); S3Bucket testBucket = new S3Bucket(BUCKET_NAME); S3Object s3Object = new S3Object(OBJECT_NAME); filename = new S3FileName(SCHEME, HOST, PORT, PORT, awsAccessKey, awsSecretKey, "/" + BUCKET_NAME + "/" + OBJECT_NAME, FileType.FILE, null); S3FileName rootFileName = new S3FileName(SCHEME, HOST, PORT, PORT, awsAccessKey, awsSecretKey, "/" + BUCKET_NAME, FileType.FILE, null); S3FileSystem fileSystem = new S3FileSystem(rootFileName, new FileSystemOptions()); fileSystemSpy = spy(fileSystem);//from w w w . j a va 2 s .c om S3FileObject s3FileObject = new S3FileObject(filename, fileSystemSpy); s3FileObjectSpy = spy(s3FileObject); //specify the behaviour of S3 Service when(s3ServiceMock.getBucket(BUCKET_NAME)).thenReturn(testBucket); when(s3ServiceMock.getObject(testBucket, OBJECT_NAME)).thenReturn(s3Object); when(s3ServiceMock.getObject(BUCKET_NAME, OBJECT_NAME)).thenReturn(s3Object); when(s3ServiceMock.createBucket(BUCKET_NAME)).thenThrow(new S3ServiceException()); // throw exception if bucket exists when(fileSystemSpy.getS3Service()).thenReturn(s3ServiceMock); when(s3FileObjectSpy.getS3Bucket()).thenReturn(testBucket); }
From source file:org.richfaces.cdk.rd.JarResourceScanner.java
protected void walk(FileObject file) throws IOException { FileObject[] children = file.getChildren(); for (FileObject child : children) { if (child.getType() != FileType.FILE) { walk(child);//from w w w .j a v a 2 s . c om } else if (isAcceptable(child)) { result.add(child); } } }
From source file:org.sonatype.gshell.commands.vfs.FileInfoCommand.java
public Object execute(final CommandContext context) throws Exception { assert context != null; IO io = context.getIo();/* w w w . j av a 2 s . c o m*/ FileObject file = resolveFile(context, path); io.println("URL: {}", file.getURL()); io.println("Name: {}", file.getName()); io.println("BaseName: {}", file.getName().getBaseName()); io.println("Extension: {}", file.getName().getExtension()); io.println("Path: {}", file.getName().getPath()); io.println("Scheme: {}", file.getName().getScheme()); io.println("URI: {}", file.getName().getURI()); io.println("Root URI: {}", file.getName().getRootURI()); io.println("Parent: {}", file.getName().getParent()); io.println("Type: {}", file.getType()); io.println("Exists: {}", file.exists()); io.println("Readable: {}", file.isReadable()); io.println("Writeable: {}", file.isWriteable()); io.println("Root path: {}", file.getFileSystem().getRoot().getName().getPath()); if (file.exists()) { FileContent content = file.getContent(); FileContentInfo contentInfo = content.getContentInfo(); io.println("Content type: {}", contentInfo.getContentType()); io.println("Content encoding: {}", contentInfo.getContentEncoding()); try { // noinspection unchecked Map<String, Object> attrs = content.getAttributes(); if (attrs != null && !attrs.isEmpty()) { io.println("Attributes:"); for (Map.Entry<String, Object> entry : attrs.entrySet()) { io.println(" {}='{}'", entry.getKey(), entry.getValue()); } } } catch (FileSystemException e) { io.println("File attributes are NOT supported"); } try { Certificate[] certs = content.getCertificates(); if (certs != null && certs.length != 0) { io.println("Certificate:"); for (Certificate cert : certs) { io.println(" {}", cert); } } } catch (FileSystemException e) { io.println("File certificates are NOT supported"); } if (file.getType().equals(FileType.FILE)) { io.println("Size: {} bytes", content.getSize()); } else if (file.getType().hasChildren() && file.isReadable()) { FileObject[] children = file.getChildren(); io.println("Directory with {} files", children.length); for (int iterChildren = 0; iterChildren < children.length; iterChildren++) { io.println("#{}:{}", iterChildren, children[iterChildren].getName()); if (iterChildren > 5) { break; } } } io.println("Last modified: {}", DateFormat.getInstance().format(new Date(content.getLastModifiedTime()))); } else { io.println("The file does not exist"); } FileObjects.close(file); return Result.SUCCESS; }
From source file:org.sonatype.gshell.vfs.provider.truezip.TruezipFileObject.java
/** * Returns the file's type.//from w ww. j a va 2s . c om */ protected FileType doGetType() throws Exception { if (fileObject != null) { return fileObject.getType(); } if (!file.exists() && file.length() < 1) { return FileType.IMAGINARY; } if (file.isDirectory()) { return FileType.FOLDER; } return FileType.FILE; }
From source file:org.vivoweb.harvester.util.FileAide.java
/** * Determines if a file is at the given path * @param path the path to determine if it is a file * @return true if a file, false otherwise * @throws IOException error resolving path *//*from ww w .j a v a 2 s. c o m*/ public static boolean isFile(String path) throws IOException { FileType type = getFileObject(path).getType(); return (type == FileType.FILE || type == FileType.FILE_OR_FOLDER); }
From source file:org.vivoweb.harvester.util.FileAide.java
/** * Get a set of non-hidden direct children of the given path * @param path the path to search under//w w w . j av a2s . co m * @return a set of non-hidden direct children * @throws IOException error resolving path */ public static Set<String> getNonHiddenChildren(String path) throws IOException { Set<String> allFileListing = new HashSet<String>(); for (FileObject file : getFileObject(path).findFiles(Selectors.SELECT_CHILDREN)) { if (!file.isHidden() && (file.getType() == FileType.FILE)) { allFileListing.add(file.getName().getBaseName()); } } return allFileListing; }
From source file:pt.webdetails.cpf.repository.vfs.VfsRepositoryAccess.java
public IRepositoryFile[] listRepositoryFiles(IRepositoryFileFilter fileFilter) { try {/*from www . j av a 2 s. co m*/ FileObject[] files = repo.getChildren(); List<IRepositoryFile> repoFiles = new ArrayList<IRepositoryFile>(); for (FileObject file : files) { if (file.exists() && file.isReadable() && file.getType().equals(FileType.FILE)) { IRepositoryFile repoFile = new VfsRepositoryFile(repo, file); if (fileFilter == null || fileFilter.accept(repoFile)) { repoFiles.add(repoFile); } } } return repoFiles.toArray(new IRepositoryFile[] {}); } catch (FileSystemException e) { throw new RuntimeException("Cannot list repo files", e); } }
From source file:r.base.Files.java
/** * Utility function to extract information about files on the user's file systems. * * @param context current call Context/* w ww . ja v a2 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 */ @Primitive("file.info") public static ListVector fileInfo(@Current Context context, StringVector paths) throws FileSystemException { DoubleVector.Builder size = new DoubleVector.Builder(); LogicalVector.Builder isdir = new LogicalVector.Builder(); IntVector.Builder mode = (IntVector.Builder) new IntVector.Builder().setAttribute(Symbols.CLASS, new StringVector("octmode")); DoubleVector.Builder mtime = new DoubleVector.Builder(); StringVector.Builder exe = new StringVector.Builder(); for (String path : paths) { 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.add(IntVector.NA); isdir.add(IntVector.NA); mode.add(IntVector.NA); mtime.add(DoubleVector.NA); exe.add(StringVector.NA); } } 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:r.base.Files.java
private static void delete(FileObject file, boolean recursive) throws FileSystemException { if (file.exists()) { if (file.getType() == FileType.FILE) { file.delete();/* w w w . j av a 2 s .c om*/ } else if (file.getType() == FileType.FOLDER) { if (file.getChildren().length == 0) { file.delete(); } else if (recursive) { file.delete(); } } } }