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

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

Introduction

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

Prototype

public String toString() 

Source Link

Document

Returns a short description of this throwable.

Usage

From source file:com.ewcms.publication.deploy.provider.DeployOperatorBase.java

@Override
public boolean test() throws PublishException {
    FileObject root = null;//  w  ww.  j av a2  s  .  c  o  m
    try {
        root = getRootFileObject();
    } catch (FileSystemException e) {
        logger.error("Test is fail:{}", e.toString());
        throw new PublishException("error.output.notconnect");
    }

    try {
        if (!root.exists()) {
            throw new PublishException("error.output.nodir");
        }
        if (!root.isWriteable()) {
            throw new PublishException("error.output.notwrite");
        }
        root.close();
        return true;
    } catch (FileSystemException e) {
        logger.error("Test  is fail:{}", e.toString());
        return false;
    }
}

From source file:com.ewcms.publication.deploy.provider.DeployOperatorBase.java

@Override
public void copy(byte[] content, String targetPath) throws PublishException {

    String targetFullPath = targetFullPath(builder.getPath(), targetPath);
    logger.debug("Server file's path is {}", targetFullPath);

    FileObject root = null;/*  w  ww  .j a  va  2  s .  c o  m*/
    FileObject target = null;
    try {
        root = getRootFileObject();
        //target = getTargetFileObject(root, targetFullPath);
        //-------------- Windows? ??----------------------
        targetPath = targetPath.replace("\\", "/").replace("//", "/");
        if (targetPath.indexOf("/") == 0) {
            targetPath = targetPath.substring(1);
        }
        target = getTargetFileObject(root, targetPath);
        //--------------------------------------------------------------
        FileContent fileContent = target.getContent();
        OutputStream stream = fileContent.getOutputStream();
        stream.write(content);
        stream.flush();

        stream.close();
        fileContent.close();
        target.close();
        root.close();
    } catch (FileSystemException e) {
        logger.error("Copy {} is error:{}", targetFullPath, e);
        throw new PublishException(e);
    } catch (IOException e) {
        logger.error("Copy {} is error:{}", targetFullPath, e);
        throw new PublishException(e);
    } finally {
        try {
            if (root != null) {
                root.close();
            }
            if (target != null) {
                target.close();
            }
        } catch (Exception e) {
            logger.error("vfs close is error:{}", e.toString());
        }
    }
}

From source file:com.ewcms.publication.deploy.provider.DeployOperatorBase.java

@Override
public void copy(File sourceFile, String targetPath) throws PublishException {
    //TODO ??????
    if (!sourceFile.exists()) {
        logger.debug("Source file path's {} is not exists.", sourceFile.getPath());
        return;//from  w  w w  .ja v  a  2  s .  c  o  m
    }

    String targetFullPath = targetFullPath(builder.getPath(), targetPath);
    logger.debug("Server file's path is {}", targetFullPath);
    logger.debug("Source file's path is {}  ", sourceFile.getPath());

    FileObject root = null;
    FileObject target = null;
    try {
        root = getRootFileObject();
        //target = getTargetFileObject(root, targetFullPath);
        //-------------- Windows? ??----------------------
        targetPath = targetPath.replace("\\", "/").replace("//", "/");
        if (targetPath.indexOf("/") == 0) {
            targetPath = targetPath.substring(1);
        }
        target = getTargetFileObject(root, targetPath);
        //--------------------------------------------------------------
        FileContent fileContent = target.getContent();

        OutputStream out = fileContent.getOutputStream();
        InputStream in = new FileInputStream(sourceFile);

        byte[] buffer = new byte[1024 * 8];
        int len = 0;
        while ((len = in.read(buffer)) > 0) {
            out.write(buffer, 0, len);
        }
        out.flush();

        in.close();
        out.close();
        fileContent.close();
    } catch (FileSystemException e) {
        logger.error("Copy {} is error:{}", targetFullPath, e);
        throw new PublishException(e);
    } catch (IOException e) {
        logger.error("Copy {} is error:{}", targetFullPath, e);
        throw new PublishException(e);
    } finally {
        try {
            if (root != null) {
                root.close();
            }
            if (target != null) {
                target.close();
            }
        } catch (Exception e) {
            logger.error("vfs close is error:{}", e.toString());
        }
    }
}