Example usage for org.apache.commons.vfs2 FileType toString

List of usage examples for org.apache.commons.vfs2 FileType toString

Introduction

In this page you can find the example usage for org.apache.commons.vfs2 FileType toString.

Prototype

@Override
public String toString() 

Source Link

Document

Returns the name of this type.

Usage

From source file:org.wso2.carbon.transport.file.connector.server.FileConsumer.java

/**
 * Do the file processing operation for the given set of properties. Do the
 * checks and pass the control to processFile method
 *//*from w w  w  . j a  va  2  s. c  o  m*/
public void consume() throws FileServerConnectorException {
    if (log.isDebugEnabled()) {
        log.debug("Polling for directory or file : " + FileTransportUtils.maskURLPassword(fileURI));
    }

    // If file/folder found proceed to the processing stage
    try {
        boolean isFileExists;
        try {
            isFileExists = fileObject.exists();
        } catch (FileSystemException e) {
            throw new FileServerConnectorException("Error occurred when determining whether the file at URI : "
                    + FileTransportUtils.maskURLPassword(fileURI) + " exists. " + e);
        }

        boolean isFileReadable;
        try {
            isFileReadable = fileObject.isReadable();
        } catch (FileSystemException e) {
            throw new FileServerConnectorException("Error occurred when determining whether the file at URI : "
                    + FileTransportUtils.maskURLPassword(fileURI) + " is readable. " + e);
        }

        if (isFileExists && isFileReadable) {
            FileType fileType;
            try {
                fileType = fileObject.getType();
            } catch (FileSystemException e) {
                throw new FileServerConnectorException("Error occurred when determining whether file: "
                        + FileTransportUtils.maskURLPassword(fileURI) + " is a file or a folder", e);
            }

            if (fileType == FileType.FILE) {
                processFile(fileObject);
                deleteFile(fileObject);
            } else if (fileType == FileType.FOLDER) {
                FileObject[] children = null;
                try {
                    children = fileObject.getChildren();
                } catch (FileSystemException ignored) {
                    if (log.isDebugEnabled()) {
                        log.debug("The file does not exist, or is not a folder, or an error "
                                + "has occurred when trying to list the children. File URI : "
                                + FileTransportUtils.maskURLPassword(fileURI), ignored);
                    }
                }

                // if this is a file that would translate to a single message
                if (children == null || children.length == 0) {
                    if (log.isDebugEnabled()) {
                        log.debug("Folder at " + FileTransportUtils.maskURLPassword(fileURI) + " is empty.");
                    }
                } else {
                    directoryHandler(children);
                }
            } else {
                throw new FileServerConnectorException("File: " + FileTransportUtils.maskURLPassword(fileURI)
                        + " is neither a file or " + "a folder"
                        + (fileType == null ? "" : ". Found file type: " + fileType.toString()));
            }
        } else {
            throw new FileServerConnectorException("Unable to access or read file or directory : "
                    + FileTransportUtils.maskURLPassword(fileURI) + ". Reason: "
                    + (isFileExists ? (isFileReadable ? "Unknown reason" : "The file can not be read!")
                            : "The file does not exist!"));
        }
    } finally {
        try {
            fileObject.close();
        } catch (FileSystemException e) {
            log.warn("Could not close file at URI: " + FileTransportUtils.maskURLPassword(fileURI), e);
        }
    }
    if (log.isDebugEnabled()) {
        log.debug("End : Scanning directory or file : " + FileTransportUtils.maskURLPassword(fileURI));
    }
}