本文整理匯總了Java中org.apache.commons.vfs2.FileType類的典型用法代碼示例。如果您正苦於以下問題:Java FileType類的具體用法?Java FileType怎麽用?Java FileType使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
FileType類屬於org.apache.commons.vfs2包,在下文中一共展示了FileType類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: doGetType
import org.apache.commons.vfs2.FileType; //導入依賴的package包/類
/**
* Determines the type of the file, returns null if the file does not
* exist.
*/
@Override
protected FileType doGetType() throws Exception
{
if (!file.exists())
{
return FileType.IMAGINARY;
}
else if (file.isDirectory())
{
return FileType.FOLDER;
}
else if (file.isFile())
{
return FileType.FILE;
}
throw new FileSystemException("vfs.provider.Nfs/get-type.error", getName());
}
示例2: doGetType
import org.apache.commons.vfs2.FileType; //導入依賴的package包/類
/**
* Determines the type of the file, returns null if the file does not exist.
*
* @return the file type
*
* @throws Exception the exception
*/
@Override
protected FileType doGetType() throws Exception {
// log.debug("relative path:" + relPath);
if (this.fileInfo == null) {
return FileType.IMAGINARY;
} else if (this.fileInfo.isDirectory()) {
return FileType.FOLDER;
} else if (this.fileInfo.isFile()) {
return FileType.FILE;
} else if (this.fileInfo.isSoftLink()) {
return FileType.FILE; // getLinkDestination().getType();
}
throw new FileSystemException("vfs.provider.gsiftp/get-type.error", getName());
}
示例3: listChildren
import org.apache.commons.vfs2.FileType; //導入依賴的package包/類
/**
* Lists the children of a folder.
*/
public void listChildren(final FileObject dir,
final boolean recursive,
final String prefix)
throws FileSystemException
{
final FileObject[] children = dir.getChildren();
for (int i = 0; i < children.length; i++)
{
final FileObject child = children[i];
System.out.print(prefix);
System.out.print(child.getName().getBaseName());
if (child.getType() == FileType.FOLDER)
{
System.out.println("/");
if (recursive)
{
listChildren(child, recursive, prefix + " ");
}
}
else
{
System.out.println();
}
}
}
示例4: pointToItself
import org.apache.commons.vfs2.FileType; //導入依賴的package包/類
public static boolean pointToItself(FileObject fileObject) throws FileSystemException {
if (!fileObject.getURL().getProtocol().equalsIgnoreCase("file") && FileType.FILE.equals(fileObject.getType())) {
LOGGER.debug("Checking if {} is pointing to itself", fileObject.getName().getFriendlyURI());
FileObject[] children = VFSUtils.getChildren(fileObject);
LOGGER.debug("Children number of {} is {}", fileObject.getName().getFriendlyURI(), children.length);
if (children.length == 1) {
FileObject child = children[0];
if (child.getContent().getSize() != child.getContent().getSize()) {
return false;
}
if (child.getName().getBaseName().equals(fileObject.getName().getBaseName())) {
return true;
}
}
}
return false;
}
示例5: doInBackground
import org.apache.commons.vfs2.FileType; //導入依賴的package包/類
@Override
protected Void doInBackground() throws Exception {
try {
for (FileObject f : selectedFiles) {
if (f.getType() == FileType.FOLDER) {
continue;
}
final FileObjectToImport fileObjectToImport = new FileObjectToImport(
f,
f.getName(),
new FileSize(f.getContent().getSize()),
Level.FINEST,
OpenMode.FROM_START,
CanParse.NOT_TESTED);
publish(fileObjectToImport);
}
return null;
} catch (Exception e) {
return null;
}
}
示例6: findResources
import org.apache.commons.vfs2.FileType; //導入依賴的package包/類
private static Resources findResources(FileObject rootDir, String inputEncoding) throws IOException {
Resources result = new Resources();
FileObject[] allFiles = rootDir.findFiles(new AllFileSelector());
for(int i = 0; i < allFiles.length; i++) {
FileObject file = allFiles[i];
if (file.getType() == FileType.FOLDER) {
continue;
}
MediaType mediaType = MediatypeService.determineMediaType(file.getName().getBaseName());
if(mediaType == null) {
continue;
}
String href = file.getName().toString().substring(rootDir.getName().toString().length() + 1);
byte[] resourceData = IOUtils.toByteArray(file.getContent().getInputStream());
if(mediaType == MediatypeService.XHTML && ! nl.siegmann.epublib.Constants.CHARACTER_ENCODING.equalsIgnoreCase(inputEncoding)) {
resourceData = ResourceUtil.recode(inputEncoding, nl.siegmann.epublib.Constants.CHARACTER_ENCODING, resourceData);
}
Resource fileResource = new Resource(null, resourceData, href, mediaType);
result.add(fileResource);
}
return result;
}
示例7: getChildren
import org.apache.commons.vfs2.FileType; //導入依賴的package包/類
/**
* Get a list of direct descendants of the given resource. Note that attempts to get a list of
* children does <em>not</em> result in an error. Instead an error message is
* logged and an empty ArrayList returned.
*
* @return A <code>ArrayList</code> of VFSResources
*/
public List<String> getChildren() {
init();
List<String> list = new ArrayList<>();
try {
if (resourceImpl != null && resourceImpl.exists()
&& resourceImpl.getType() == FileType.FOLDER) {
for (FileObject child : resourceImpl.getChildren()) {
list.add(normalize(child.getName().getURI()));
}
}
} catch (IOException e) {
Message.debug(e);
Message.verbose(e.getLocalizedMessage());
}
return list;
}
示例8: doGetType
import org.apache.commons.vfs2.FileType; //導入依賴的package包/類
/**
* Determines the type of this file. Must not return null. The return
* value of this method is cached, so the implementation can be expensive.
*/
@Override
protected FileType doGetType() throws Exception
{
// Use the GET method to probe the file.
method = new GetMethod();
setupMethod(method);
final HttpClient client = fileSystem.getClient();
final int status = client.executeMethod(method);
method.releaseConnection();
if (status == HttpURLConnection.HTTP_OK)
{
return FileType.FILE;
}
else if (status == HttpURLConnection.HTTP_NOT_FOUND
|| status == HttpURLConnection.HTTP_GONE)
{
return FileType.IMAGINARY;
}
else
{
throw new FileSystemException("vfs.provider.http/head.error", getName());
}
}
示例9: cp
import org.apache.commons.vfs2.FileType; //導入依賴的package包/類
/**
* Does a 'cp' command.
*/
private void cp(final String[] cmd) throws Exception
{
if (cmd.length < 3)
{
throw new Exception("USAGE: cp <src> <dest>");
}
final FileObject src = mgr.resolveFile(cwd, cmd[1]);
FileObject dest = mgr.resolveFile(cwd, cmd[2]);
if (dest.exists() && dest.getType() == FileType.FOLDER)
{
dest = dest.resolveFile(src.getName().getBaseName());
}
dest.copyFrom(src, Selectors.SELECT_ALL);
}
示例10: listChildren
import org.apache.commons.vfs2.FileType; //導入依賴的package包/類
/**
* Lists the children of a folder.
*/
private void listChildren(final FileObject dir,
final boolean recursive,
final String prefix)
throws FileSystemException
{
final FileObject[] children = dir.getChildren();
for (int i = 0; i < children.length; i++)
{
final FileObject child = children[i];
System.out.print(prefix);
System.out.print(child.getName().getBaseName());
if (child.getType() == FileType.FOLDER)
{
System.out.println("/");
if (recursive)
{
listChildren(child, recursive, prefix + " ");
}
}
else
{
System.out.println();
}
}
}
示例11: testExists
import org.apache.commons.vfs2.FileType; //導入依賴的package包/類
/**
* Tests existence determination.
*/
public void testExists() throws Exception
{
// Test a file
FileObject file = getReadFolder().resolveFile("file1.txt");
assertTrue("file exists", file.exists());
assertTrue("file exists", file.getType() != FileType.IMAGINARY);
// Test a folder
file = getReadFolder().resolveFile("dir1");
assertTrue("folder exists", file.exists());
assertTrue("folder exists", file.getType() != FileType.IMAGINARY);
// Test an unknown file
file = getReadFolder().resolveFile("unknown-child");
assertTrue("unknown file does not exist", !file.exists());
assertTrue("unknown file does not exist",
file.getType() == FileType.IMAGINARY);
// Test an unknown file in an unknown folder
file = getReadFolder().resolveFile("unknown-folder/unknown-child");
assertTrue("unknown file does not exist", !file.exists());
assertTrue("unknown file does not exist",
file.getType() == FileType.IMAGINARY);
}
示例12: doGetType
import org.apache.commons.vfs2.FileType; //導入依賴的package包/類
/**
* Determines the type of the file, returns null if the file does not
* exist.
*/
@Override
protected FileType doGetType() throws Exception
{
if (part == null)
{
return FileType.IMAGINARY;
}
if (isMultipart())
{
// we cant have children ...
return FileType.FILE_OR_FOLDER;
}
return FileType.FILE;
}
示例13: doGetType
import org.apache.commons.vfs2.FileType; //導入依賴的package包/類
/**
* Determines the type of the file, returns null if the file does not
* exist.
*/
@Override
protected FileType doGetType() throws Exception
{
if (!file.exists())
{
return FileType.IMAGINARY;
}
else if (file.isDirectory())
{
return FileType.FOLDER;
}
else if (file.isFile())
{
return FileType.FILE;
}
throw new FileSystemException("vfs.provider.smb/get-type.error", getName());
}
示例14: setZipEntry
import org.apache.commons.vfs2.FileType; //導入依賴的package包/類
/**
* Sets the details for this file object.
*/
protected void setZipEntry(final ZipEntry entry)
{
if (this.entry != null)
{
return;
}
if ((entry == null) || (entry.isDirectory()))
{
type = FileType.FOLDER;
}
else
{
type = FileType.FILE;
}
this.entry = entry;
}
示例15: doGetType
import org.apache.commons.vfs2.FileType; //導入依賴的package包/類
/**
* Returns the file's type.
*/
@Override
protected FileType doGetType() throws Exception
{
// JDK BUG: 6192331
// if (!file.exists())
if (!file.exists() && file.length() < 1)
{
return FileType.IMAGINARY;
}
if (file.isDirectory())
{
return FileType.FOLDER;
}
// In doubt, treat an existing file as file
// if (file.isFile())
// {
return FileType.FILE;
// }
// throw new FileSystemException("vfs.provider.local/get-type.error", file);
}