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

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

Introduction

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

Prototype

public void printStackTrace() 

Source Link

Document

Prints this throwable and its backtrace to the standard error stream.

Usage

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 w  w .  j  a va2s.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:fr.cls.atoll.motu.processor.wps.TestVFS.java

public static void testBugDoReplicateFile() {

    StandardFileSystemManager standardFileSystemManager = new StandardFileSystemManager();
    standardFileSystemManager.setLogger(LogFactory.getLog(VFS.class));
    standardFileSystemManager.setClassLoader(TestVFS.class.getClassLoader());
    try {//  w w w. j av a 2 s  .c om
        URL configUrl = new URL(
                "file:/J:/dev/atoll-v2/atoll-motu/atoll-motu-library/src/main/resources/motuVFSProvider.xml");
        standardFileSystemManager.setConfiguration(configUrl);
        standardFileSystemManager.setCacheStrategy(CacheStrategy.ON_CALL);
        standardFileSystemManager.init();

        String uri = "jar:file:/C:/Documents%20and%20Settings/dearith/.m2/repository/org/jvnet/ogc/iso-19139-d_2006_05_04-schema/1.0.0-PATCH-CLS/iso-19139-d_2006_05_04-schema-1.0.0-PATCH-CLS.jar!/schema/iso19139";
        FileSystemOptions opts = new FileSystemOptions();

        FileObject fileObject = standardFileSystemManager.resolveFile(uri, opts);

    } catch (FileSystemException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

}

From source file:com.stratuscom.harvester.liaison.VirtualFileSystemConfiguration.java

/** Inject the working directory for this application  (which might actually
be a jar file).  This injection is//from w ww. ja v  a2 s.  c om
done using reflection by the ServiceStarterDeployer when the application
is setup.  This way, the Configuration can be loaded without any hard-coded
directories, etc.
@param workingDirectory
 */
public static void setWorkingDirectory(File workingDirectory) {
    /* Before we do anything, setup the class loader for the vfs manager.
     */

    setManagerClassLoader();
    try {
        if (workingDirectory.isDirectory()) {
            FileObject root = VFS.getManager().toFileObject(workingDirectory);
            VirtualFileSystemConfiguration.rootDirectory = root;
        } else { /* Try to create a virtual file system based on the file. */
            FileObject rootFileObject = VFS.getManager().toFileObject(workingDirectory);
            FileObject root = VFS.getManager().createFileSystem(Strings.JAR, rootFileObject);
            VirtualFileSystemConfiguration.rootDirectory = root;
        }
    } catch (FileSystemException ex) {
        /* Problem here is that we can't just throw the exception,
        because we expect to be called reflectively from code in a 
        different classloader, that won't have the exception class.
        So, we have to instead throw an exception that is part of the 
        jre platform.
         */
        log.log(Level.SEVERE, "Problem setting working directory", ex);
        ex.printStackTrace();
        throw new RuntimeException(ex.getMessage());
    }

}

From source file:fr.cls.atoll.motu.library.misc.ftp.TestFtp.java

public static void testSftp() {

    try {//  w w  w .j a v  a  2 s.  c  o m

        // String user = "anonymous";
        // String pass = "email";
        // String server = "ftp.cls.fr";
        //
        // FTPClient client = new FTPClient();
        // client.connect(server);
        // System.out.print(client.getReplyString());
        // int reply = client.getReplyCode();
        // if (!FTPReply.isPositiveCompletion(reply))
        // {
        // throw new IllegalArgumentException("cant connect: " + reply);
        // }
        // if (!client.login(user, pass))
        // {
        // throw new IllegalArgumentException("login failed");
        // }
        // client.enterLocalPassiveMode();
        // client.disconnect();

        FileSystemOptions opts = new FileSystemOptions();
        SftpFileSystemConfigBuilder.getInstance().setUserDirIsRoot(opts, true);
        SftpFileSystemConfigBuilder.getInstance().setStrictHostKeyChecking(opts, "no");
        // SftpFileSystemConfigBuilder.getInstance().setProxyHost(opts, "proxy.cls.fr");
        // SftpFileSystemConfigBuilder.getInstance().setProxyPort(opts, 8080);
        // SftpFileSystemConfigBuilder.getInstance().setProxyType(opts,
        // SftpFileSystemConfigBuilder.PROXY_SOCKS5 );
        // //SftpFileSystemConfigBuilder.getInstance().setProxyType(opts,
        // SftpFileSystemConfigBuilder.PROXY_HTTP );
        //FileObject fo = VFS.getManager().resolveFile("sftp://t:t@CLS-EARITH.pc.cls.fr/AsciiEnvisat.txt", opts);
        String server = "CLS-EARITH.pc.cls.fr";
        String user = "t";
        String pass = "t";

        server = "aviso-motu.cls.fr";
        user = "mapserv";
        pass = "mapserv";
        //            Session sftpClient = SftpClientFactory.createConnection(server, 22, user.toCharArray(), pass.toCharArray(), opts);

        Organizer.getUriAsInputStream(
                "sftp://atoll:atoll@atoll-misgw.vlandata.cls.fr/opt/atoll/misgw-sltac/hoa/publication/inventories/dataset-duacs-ran-global-en-sla-l3__cls-toulouse-fr-sltac-motu-rest.xml");

    } catch (FileSystemException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        // } catch (SocketException e) {
        // // TODO Auto-generated catch block
        // e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (MotuException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

From source file:fr.cls.atoll.motu.library.misc.ftp.TestFtp.java

public static void testFtp() {

    // System.setProperty("http.proxyHost", "proxy.cls.fr"); // adresse IP
    // System.setProperty("http.proxyPort", "8080");
    // System.setProperty("socksProxyHost", "proxy.cls.fr");
    // System.setProperty("socksProxyPort", "1080");

    try {// ww  w  . j  a  v a  2 s . c om

        // String user = "anonymous";
        // String pass = "email";
        // String server = "ftp.cls.fr";
        //
        // FTPClient client = new FTPClient();
        // client.connect(server);
        // System.out.print(client.getReplyString());
        // int reply = client.getReplyCode();
        // if (!FTPReply.isPositiveCompletion(reply))
        // {
        // throw new IllegalArgumentException("cant connect: " + reply);
        // }
        // if (!client.login(user, pass))
        // {
        // throw new IllegalArgumentException("login failed");
        // }
        // client.enterLocalPassiveMode();
        // client.disconnect();

        FileSystemOptions opts = new FileSystemOptions();
        // FtpFileSystemConfigBuilder.getInstance().setUserDirIsRoot(opts, true);

        String server = "proxy.cls.fr";
        String user = "anonymous@ftp.unidata.ucar.edu";
        String pass = "";

        server = "ftp.cls.fr";
        user = "anonymous";
        pass = "email";

        server = "proxy-bureautique.cls.fr";
        user = "misgw@ftp.cmcc.it";
        pass = "myo2010";

        StaticUserAuthenticator auth = new StaticUserAuthenticator(null, user, pass);
        DefaultFileSystemConfigBuilder.getInstance().setUserAuthenticator(opts, auth);
        FileObject fo = VFS.getManager().resolveFile(
                "ftp://proxy-bureautique.cls.fr/GLOBAL_REANALYSIS_PHYS_001_004_a/global-reanalysis-phys-001-004-a-ran-it-cglors-icemod//global-reanalysis-phys-001-004-a-ran-it-cglors-icemod_20090101_20091231_20110331.nc",
                opts);

        FTPClient ftpClient = FtpClientFactory.createConnection(server, 21, user.toCharArray(),
                pass.toCharArray(), ".", opts);
    } catch (FileSystemException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        // } catch (SocketException e) {
        // // TODO Auto-generated catch block
        // e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

From source file:fr.cls.atoll.motu.processor.wps.TestServiceMetadata.java

public static String[] getServiceMetadataSchemaAsString(String schemaPath) throws MotuException {

    List<String> stringList = new ArrayList<String>();
    String localIso19139SchemaPath = "file:///c:/tempVFS/testISO";
    String localIso19139RootSchemaRelPath = "/srv/srv.xsd";
    String localIso19139RootSchemaPath = String.format("%s%s", localIso19139SchemaPath,
            localIso19139RootSchemaRelPath);

    FileObject dest = Organizer.resolveFile(localIso19139RootSchemaPath);
    boolean hasIso19139asLocalSchema = false;
    try {/*w  ww .ja va  2s. c o  m*/
        if (dest != null) {
            hasIso19139asLocalSchema = dest.exists();
        }
    } catch (FileSystemException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }

    if (hasIso19139asLocalSchema) {
        try {
            dest.close();
        } catch (FileSystemException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

    } else {

        // URL url = Organizer.findResource("schema/iso/srv/srv.xsd");
        // URL url =
        // Organizer.findResource("J:/dev/iso/19139/20070417/schema/src/main/resources/iso/19139/20070417/srv/srv.xsd");
        // URL url = Organizer.findResource("iso/19139/20070417/srv/srv.xsd");
        URL url = Organizer.findResource(schemaPath);
        System.out.println(url);

        // String[] arr = url.toString().split("!");

        // FileObject jarFile = Organizer.resolveFile(arr[0]);
        FileObject jarFile = Organizer.resolveFile(url.toString());

        // List the children of the Jar file
        FileObject[] children = null;
        try {
            children = jarFile.getChildren();
        } catch (FileSystemException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        System.out.println("Children of " + jarFile.getName().getURI());
        for (int i = 0; i < children.length; i++) {
            System.out.println(children[i].getName().getBaseName());
        }

        dest = Organizer.resolveFile(localIso19139SchemaPath);
        Organizer.deleteDirectory(dest);

        Organizer.copyFile(jarFile, dest);
    }

    // stringList.add(url.toString());
    // stringList.add("J:/dev/iso/19139/20070417/schema/src/main/resources/iso/19139/20070417/srv/srv.xsd");
    stringList.add(localIso19139RootSchemaPath);
    // stringList.add("C:/Documents and Settings/dearith/Mes documents/Atoll/SchemaIso/srv/serviceMetadata.xsd");
    String[] inS = new String[stringList.size()];
    inS = stringList.toArray(inS);
    return inS;
}

From source file:fr.cls.atoll.motu.library.misc.ftp.TestFtp.java

public static void testVFS(String user, String pwd, String scheme, String host, String file) {

    StandardFileSystemManager fsManager = null;

    try {/*from   www .java2  s.c om*/
        fsManager = new StandardFileSystemManager();
        fsManager.setLogger(_LOG);

        StaticUserAuthenticator auth = new StaticUserAuthenticator(null, user, pwd);

        fsManager.setConfiguration(ConfigLoader.getInstance().get(Organizer.getVFSProviderConfig()));
        fsManager.setCacheStrategy(CacheStrategy.ON_RESOLVE);
        // fsManager.addProvider("moi", new DefaultLocalFileProvider());
        fsManager.init();

        FileSystemOptions opts = new FileSystemOptions();
        FileSystemConfigBuilder fscb = fsManager.getFileSystemConfigBuilder(scheme);
        DefaultFileSystemConfigBuilder.getInstance().setUserAuthenticator(opts, auth);
        DefaultFileSystemConfigBuilder.getInstance().setUserAuthenticator(opts, auth);

        System.out.println(fsManager.getProviderCapabilities(scheme));

        if (fscb instanceof FtpFileSystemConfigBuilder) {
            FtpFileSystemConfigBuilder ftpFscb = (FtpFileSystemConfigBuilder) fscb;
            ftpFscb.setUserDirIsRoot(opts, true);
            ftpFscb.setPassiveMode(opts, true);

        }
        if (fscb instanceof HttpFileSystemConfigBuilder) {
            HttpFileSystemConfigBuilder httpFscb = (HttpFileSystemConfigBuilder) fscb;
            httpFscb.setProxyHost(opts, "proxy.cls.fr");
            httpFscb.setProxyPort(opts, 8080);

        }
        if (fscb instanceof SftpFileSystemConfigBuilder) {
            SftpFileSystemConfigBuilder sftpFscb = (SftpFileSystemConfigBuilder) fscb;
            sftpFscb.setUserDirIsRoot(opts, false);

            // TrustEveryoneUserInfo trustEveryoneUserInfo = new TrustEveryoneUserInfo();
            // trustEveryoneUserInfo.promptYesNo("eddfsdfs");
            // sftpFscb.setUserInfo(opts, new TrustEveryoneUserInfo());
            sftpFscb.setTimeout(opts, 5000);
            // SftpFileSystemConfigBuilder.getInstance().setUserDirIsRoot(opts, true);
            // SftpFileSystemConfigBuilder.getInstance().setStrictHostKeyChecking(opts, "no");

        }
        // FileObject fo =
        // fsManager.resolveFile("ftp://ftp.cls.fr/pub/oceano/AVISO/NRT-SLA/maps/rt/j2/h/msla_rt_j2_err_21564.nc.gz",
        // opts);

        // String uri = String.format("%s://%s/%s", scheme, host, file);
        // String uri = String.format("%s://%s/", scheme, host);
        // FileObject originBase = fsManager.resolveFile(uri, opts);
        // fsManager.setBaseFile(originBase);

        File tempDir = new File("c:/tempVFS");
        // File tempFile = File.createTempFile("AsciiEnvisat", ".txt", tempDir);
        File hostFile = new File(file);
        String fileName = hostFile.getName();
        File newFile = new File(tempDir, fileName);
        newFile.createNewFile();

        DefaultFileReplicator dfr = new DefaultFileReplicator(tempDir);
        fsManager.setTemporaryFileStore(dfr);
        // System.out.println(fsManager.getBaseFile());
        // System.out.println(dfr);
        // System.out.println(fsManager.getTemporaryFileStore());

        // FileObject ff = fsManager.resolveFile("sftp://t:t@CLS-EARITH.pc.cls.fr/AsciiEnvisat.txt",
        // opts);
        String uri = String.format("%s://%s/%s", scheme, host, file);
        FileObject ff = fsManager.resolveFile(uri, opts);
        FileObject dest = fsManager.toFileObject(newFile);

        //ff.getContent().getInputStream();
        dest.copyFrom(ff, Selectors.SELECT_ALL);
        //dest.copyFrom(ff, Selectors.SELECT_ALL);

        //            
        // URL url = ff.getURL();
        //            
        // url.openConnection();
        // URLConnection conn = url.openConnection();
        // InputStream in = conn.getInputStream();
        // in.close();

        // InputStream in = ff.getContent().getInputStream();

    } catch (FileSystemException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (MotuException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } finally {
        // fsManager.close();
        // fsManager.freeUnusedResources();
    }

}

From source file:com.stehno.sanctuary.core.remote.FileSystemRemoteStore.java

@Override
public void deleteFile(File rootDirectory, File file) {
    final FileObject remoteFile;
    try {/*  ww w. j ava  2s .  c  om*/
        remoteFile = findRemoteFile(rootDirectory, file);
        remoteFile.delete();

        if (log.isDebugEnabled())
            log.debug("Deleted: " + remoteFile);

    } catch (FileSystemException e) {
        // FIXME: error
        e.printStackTrace();
    }
}

From source file:com.stehno.sanctuary.core.remote.FileSystemRemoteStore.java

private void storeFile(File rootDirectory, File file, String action) {
    try {// w w  w .  j a  v a  2 s  .c  o m
        FileObject remoteFile = findRemoteFile(rootDirectory, file);

        // TODO: if this fails, it could be a partial copy, save original?
        remoteFile.copyFrom(fileSystemManager.toFileObject(file), new AllFileSelector());

        if (log.isDebugEnabled())
            log.debug(action + ": " + remoteFile);

    } catch (FileSystemException e) {
        // FIXME: error
        e.printStackTrace();
    }
}

From source file:de.unioninvestment.portal.explorer.view.vfs.VFSMainView.java

public void scanDirectory(FileSystemManager fsManager, FileSystemOptions opts, String ftpconn)
        throws IOException {
    try {/*from   w  ww . j  av  a  2s  . c o  m*/
        FileObject fileObject = fsManager.resolveFile(ftpconn, opts);
        FileObject[] files = fileObject.findFiles(new FileTypeSelector(FileType.FOLDER));
        HashMap<String, String> parentMap = new HashMap<String, String>();
        for (FileObject fo : files) {
            String objectName = fo.getName().toString();
            tree.addItem(objectName);
            tree.setItemIcon(objectName, FOLDER);
            if (fo.getParent() != null) {
                String parentName = fo.getParent().getName().toString();
                parentMap.put(objectName, parentName);
            } else
                tree.setItemCaption(objectName, "/");
        }

        // set parents
        logger.log(Level.INFO, "parentMap " + parentMap.size());
        if (parentMap.size() > 0) {
            Iterator<Map.Entry<String, String>> it = parentMap.entrySet().iterator();
            while (it.hasNext()) {
                Map.Entry<String, String> pairs = it.next();
                tree.setParent(pairs.getKey(), pairs.getValue());
                String caption = pairs.getKey().toString().substring(pairs.getValue().toString().length());

                tree.setItemCaption(pairs.getKey(), removeSlash(caption));
                it.remove();
            }
        }
    } catch (FileSystemException e) {
        e.printStackTrace();
    }
}