List of usage examples for org.apache.commons.vfs2.impl DefaultFileSystemManager init
boolean init
To view the source code for org.apache.commons.vfs2.impl DefaultFileSystemManager init.
Click Source Link
From source file:com.sludev.commons.vfs2.provider.s3.SS3FileProviderTest.java
/** * Delete a previously uploaded file.//from w ww .j ava 2s . c o m * * @throws Exception */ @Test public void A006_deleteFile() throws Exception { String currAccountStr = testProperties.getProperty("s3.access.id"); String currKey = testProperties.getProperty("s3.access.secret"); String currContainerStr = testProperties.getProperty("s3.test0001.bucket.name"); String currHost = testProperties.getProperty("s3.host"); String currRegion = testProperties.getProperty("s3.region"); String currFileNameStr; SS3FileProvider currSS3 = new SS3FileProvider(); DefaultFileSystemManager currMan = new DefaultFileSystemManager(); currMan.addProvider(SS3Constants.S3SCHEME, currSS3); currMan.init(); StaticUserAuthenticator auth = new StaticUserAuthenticator("", currAccountStr, currKey); FileSystemOptions opts = new FileSystemOptions(); DefaultFileSystemConfigBuilder.getInstance().setUserAuthenticator(opts, auth); currFileNameStr = "test01.tmp"; String currUriStr = String.format("%s://%s/%s/%s", SS3Constants.S3SCHEME, currHost, currContainerStr, currFileNameStr); FileObject currFile = currMan.resolveFile(currUriStr, opts); log.info(String.format("deleting '%s'", currUriStr)); Boolean delRes = currFile.delete(); Assert.assertTrue(delRes); }
From source file:com.sludev.commons.vfs2.provider.s3.SS3FileProviderTest.java
@Test public void A005_testContent() throws Exception { String currAccountStr = testProperties.getProperty("s3.access.id"); String currKey = testProperties.getProperty("s3.access.secret"); String currContainerStr = testProperties.getProperty("s3.test0001.bucket.name"); String currHost = testProperties.getProperty("s3.host"); String currRegion = testProperties.getProperty("s3.region"); String currFileNameStr;//w ww . ja va 2 s. c o m SS3FileProvider currSS3 = new SS3FileProvider(); DefaultFileSystemManager currMan = new DefaultFileSystemManager(); currMan.addProvider(SS3Constants.S3SCHEME, currSS3); currMan.init(); StaticUserAuthenticator auth = new StaticUserAuthenticator("", currAccountStr, currKey); FileSystemOptions opts = new FileSystemOptions(); DefaultFileSystemConfigBuilder.getInstance().setUserAuthenticator(opts, auth); currFileNameStr = "file05"; String currUriStr = String.format("%s://%s/%s/%s", SS3Constants.S3SCHEME, currHost, currContainerStr, currFileNameStr); FileObject currFile = currMan.resolveFile(currUriStr, opts); FileContent content = currFile.getContent(); long size = content.getSize(); Assert.assertTrue(size >= 0); long modTime = content.getLastModifiedTime(); Assert.assertTrue(modTime > 0); }
From source file:com.sludev.commons.vfs2.provider.s3.SS3FileProviderTest.java
@Test public void A004_getContentSize() throws Exception { String currAccountStr = testProperties.getProperty("s3.access.id"); String currKey = testProperties.getProperty("s3.access.secret"); String currContainerStr = testProperties.getProperty("s3.test0001.bucket.name"); String currHost = testProperties.getProperty("s3.host"); String currRegion = testProperties.getProperty("s3.region"); String currFileNameStr;// ww w. j a va 2 s . c o m SS3FileProvider currSS3 = new SS3FileProvider(); DefaultFileSystemManager currMan = new DefaultFileSystemManager(); currMan.addProvider(SS3Constants.S3SCHEME, currSS3); currMan.init(); StaticUserAuthenticator auth = new StaticUserAuthenticator("", currAccountStr, currKey); FileSystemOptions opts = new FileSystemOptions(); DefaultFileSystemConfigBuilder.getInstance().setUserAuthenticator(opts, auth); currFileNameStr = "test01.tmp"; String currUriStr = String.format("%s://%s/%s/%s", SS3Constants.S3SCHEME, currHost, currContainerStr, currFileNameStr); FileObject currFile = currMan.resolveFile(currUriStr, opts); log.info(String.format("getContent() file '%s'", currUriStr)); FileContent cont = currFile.getContent(); long contSize = cont.getSize(); Assert.assertTrue(contSize > 0); }
From source file:com.sludev.commons.vfs2.provider.s3.SS3FileProviderTest.java
@Test public void A003_exist() throws Exception { String currAccountStr = testProperties.getProperty("s3.access.id"); String currKey = testProperties.getProperty("s3.access.secret"); String currContainerStr = testProperties.getProperty("s3.test0001.bucket.name"); String currHost = testProperties.getProperty("s3.host"); String currRegion = testProperties.getProperty("s3.region"); String currFileNameStr;/*from w w w . j a v a 2 s .c om*/ SS3FileProvider currSS3 = new SS3FileProvider(); DefaultFileSystemManager currMan = new DefaultFileSystemManager(); currMan.addProvider(SS3Constants.S3SCHEME, currSS3); currMan.init(); StaticUserAuthenticator auth = new StaticUserAuthenticator("", currAccountStr, currKey); FileSystemOptions opts = new FileSystemOptions(); DefaultFileSystemConfigBuilder.getInstance().setUserAuthenticator(opts, auth); currFileNameStr = "test01.tmp"; String currUriStr = String.format("%s://%s/%s/%s", SS3Constants.S3SCHEME, currHost, currContainerStr, currFileNameStr); FileObject currFile = currMan.resolveFile(currUriStr, opts); log.info(String.format("exist() file '%s'", currUriStr)); Boolean existRes = currFile.exists(); Assert.assertTrue(existRes); currFileNameStr = "non-existant-file-8632857264.tmp"; currUriStr = String.format("%s://%s/%s/%s", SS3Constants.S3SCHEME, currHost, currContainerStr, currFileNameStr); currFile = currMan.resolveFile(currUriStr, opts); log.info(String.format("exist() file '%s'", currUriStr)); existRes = currFile.exists(); Assert.assertFalse(existRes); }
From source file:com.sludev.commons.vfs2.provider.azure.AzFileProviderTest.java
@Test public void A002_downloadFile() throws Exception { String currAccountStr = testProperties.getProperty("azure.account.name"); String currKey = testProperties.getProperty("azure.account.key"); String currContainerStr = testProperties.getProperty("azure.test0001.container.name"); String currHost = testProperties.getProperty("azure.host"); // <account>.blob.core.windows.net String currFileNameStr;// w w w . j a v a 2s . c om File temp = File.createTempFile("downloadFile01", ".tmp"); DefaultFileSystemManager currMan = new DefaultFileSystemManager(); currMan.addProvider(AzConstants.AZSBSCHEME, new AzFileProvider()); currMan.addProvider("file", new DefaultLocalFileProvider()); currMan.init(); StaticUserAuthenticator auth = new StaticUserAuthenticator("", currAccountStr, currKey); FileSystemOptions opts = new FileSystemOptions(); DefaultFileSystemConfigBuilder.getInstance().setUserAuthenticator(opts, auth); currFileNameStr = "test01.tmp"; String currUriStr = String.format("%s://%s/%s/%s", AzConstants.AZSBSCHEME, currHost, currContainerStr, currFileNameStr); FileObject currFile = currMan.resolveFile(currUriStr, opts); String destStr = String.format("file://%s", temp.getAbsolutePath()); FileObject currFile2 = currMan.resolveFile(destStr); log.info(String.format("copying '%s' to '%s'", currUriStr, destStr)); currFile2.copyFrom(currFile, Selectors.SELECT_SELF); }
From source file:com.sludev.commons.vfs2.provider.azure.AzFileProviderTest.java
/** * /*from www . java 2s . co m*/ */ @Test public void A001_uploadFile() throws Exception { String currAccountStr = testProperties.getProperty("azure.account.name"); String currKey = testProperties.getProperty("azure.account.key"); String currContainerStr = testProperties.getProperty("azure.test0001.container.name"); String currHost = testProperties.getProperty("azure.host"); // <account>.blob.core.windows.net String currFileNameStr; File temp = File.createTempFile("uploadFile01", ".tmp"); try (FileWriter fw = new FileWriter(temp)) { BufferedWriter bw = new BufferedWriter(fw); bw.append("testing..."); bw.flush(); } DefaultFileSystemManager currMan = new DefaultFileSystemManager(); currMan.addProvider(AzConstants.AZSBSCHEME, new AzFileProvider()); currMan.addProvider("file", new DefaultLocalFileProvider()); currMan.init(); StaticUserAuthenticator auth = new StaticUserAuthenticator("", currAccountStr, currKey); FileSystemOptions opts = new FileSystemOptions(); DefaultFileSystemConfigBuilder.getInstance().setUserAuthenticator(opts, auth); currFileNameStr = "test01.tmp"; String currUriStr = String.format("%s://%s/%s/%s", AzConstants.AZSBSCHEME, currHost, currContainerStr, currFileNameStr); FileObject currFile = currMan.resolveFile(currUriStr, opts); FileObject currFile2 = currMan.resolveFile(String.format("file://%s", temp.getAbsolutePath())); currFile.copyFrom(currFile2, Selectors.SELECT_SELF); temp.delete(); }
From source file:com.sludev.commons.vfs.simpleshell.SimpleShell.java
private void Init(String accnt, String key, String cont) throws IOException { conReader = new ConsoleReader(); conReader.setPrompt("AzureShell> "); List<Completer> completors = new LinkedList<>(); String currFileNameStr = "dir1"; AzFileProvider azfp = new AzFileProvider(); StaticUserAuthenticator auth = new StaticUserAuthenticator("", accnt, key); AzFileSystemConfigBuilder.getInstance().setUserAuthenticator(azfp.getDefaultFileSystemOptions(), auth); DefaultFileSystemManager currMan = new DefaultFileSystemManager(); currMan.addProvider(AzConstants.AZSBSCHEME, azfp); currMan.addProvider("file", new DefaultLocalFileProvider()); currMan.init(); mgr = currMan;//from w ww . j a va2 s .c o m //cwd = mgr.resolveFile(System.getProperty("user.dir"));c String currAzURL = String.format("%s://%s/%s/%s", AzConstants.AZSBSCHEME, accnt, cont, currFileNameStr); cwd = mgr.resolveFile(currAzURL); completors.add(new FileNameCompleter()); completors.add(new StringsCompleter(AzConstants.AZSBSCHEME, "file://", currAzURL)); AggregateCompleter aggComp = new AggregateCompleter(completors); ArgumentCompleter argComp = new ArgumentCompleter(aggComp); argComp.setStrict(false); conReader.addCompleter(argComp); Path histPath = Paths.get(System.getProperty("user.home"), ".simpleshellhist"); File histFile = histPath.toFile(); FileHistory fh = new FileHistory(histFile); conReader.setHistory(fh); conReader.setHistoryEnabled(true); Runtime.getRuntime().addShutdownHook(new Thread() { @Override public void run() { try { ((FileHistory) conReader.getHistory()).flush(); } catch (IOException ex) { log.error("Error saving history", ex); } } }); }
From source file:com.sludev.commons.vfs2.provider.s3.SS3FileProviderTest.java
/** * Download a previously uploaded file from the test bucket. * @throws Exception //from w ww .j a va 2 s. co m */ @Test public void A002_downloadFile() throws Exception { String currAccountStr = testProperties.getProperty("s3.access.id"); String currKey = testProperties.getProperty("s3.access.secret"); String currContainerStr = testProperties.getProperty("s3.test0001.bucket.name"); String currHost = testProperties.getProperty("s3.host"); String currRegion = testProperties.getProperty("s3.region"); String currFileNameStr; SS3FileProvider currSS3 = new SS3FileProvider(); // Optional set endpoint //currSS3.setEndpoint(currHost); // Optional set region //currSS3.setRegion(currRegion); File temp = File.createTempFile("downloadFile01", ".tmp"); DefaultFileSystemManager currMan = new DefaultFileSystemManager(); currMan.addProvider(SS3Constants.S3SCHEME, currSS3); currMan.addProvider("file", new DefaultLocalFileProvider()); currMan.init(); StaticUserAuthenticator auth = new StaticUserAuthenticator("", currAccountStr, currKey); FileSystemOptions opts = new FileSystemOptions(); DefaultFileSystemConfigBuilder.getInstance().setUserAuthenticator(opts, auth); currFileNameStr = "test01.tmp"; String currUriStr = String.format("%s://%s/%s/%s", SS3Constants.S3SCHEME, currHost, currContainerStr, currFileNameStr); FileObject currFile = currMan.resolveFile(currUriStr, opts); String destStr = String.format("file://%s", temp.getAbsolutePath()); FileObject currFile2 = currMan.resolveFile(destStr); log.info(String.format("copying '%s' to '%s'", currUriStr, destStr)); currFile2.copyFrom(currFile, Selectors.SELECT_SELF); }
From source file:com.sludev.commons.vfs2.provider.s3.SS3FileProviderTest.java
/** * Upload a single file to the test bucket. * @throws java.lang.Exception//ww w.ja v a 2 s . c om */ @Test public void A001_uploadFile() throws Exception { String currAccountStr = testProperties.getProperty("s3.access.id"); String currKey = testProperties.getProperty("s3.access.secret"); String currContainerStr = testProperties.getProperty("s3.test0001.bucket.name"); String currHost = testProperties.getProperty("s3.host"); String currRegion = testProperties.getProperty("s3.region"); String currFileNameStr; File temp = File.createTempFile("uploadFile01", ".tmp"); try (FileWriter fw = new FileWriter(temp)) { BufferedWriter bw = new BufferedWriter(fw); bw.append("testing..."); bw.flush(); } SS3FileProvider currSS3 = new SS3FileProvider(); // Optional set endpoint //currSS3.setEndpoint(currHost); // Optional set region //currSS3.setRegion(currRegion); DefaultFileSystemManager currMan = new DefaultFileSystemManager(); currMan.addProvider(SS3Constants.S3SCHEME, currSS3); currMan.addProvider("file", new DefaultLocalFileProvider()); currMan.init(); StaticUserAuthenticator auth = new StaticUserAuthenticator("", currAccountStr, currKey); FileSystemOptions opts = new FileSystemOptions(); DefaultFileSystemConfigBuilder.getInstance().setUserAuthenticator(opts, auth); currFileNameStr = "test01.tmp"; String currUriStr = String.format("%s://%s/%s/%s", SS3Constants.S3SCHEME, currHost, currContainerStr, currFileNameStr); FileObject currFile = currMan.resolveFile(currUriStr, opts); FileObject currFile2 = currMan.resolveFile(String.format("file://%s", temp.getAbsolutePath())); currFile.copyFrom(currFile2, Selectors.SELECT_SELF); temp.delete(); }
From source file:com.sludev.commons.vfs2.provider.s3.SS3FileProviderTest.java
/** * By default FileObject.getChildren() will use doListChildrenResolved() if available * /*from w w w.j a v a2 s .co m*/ * @throws Exception */ @Test public void A007_listChildren() throws Exception { String currAccountStr = testProperties.getProperty("s3.access.id"); String currKey = testProperties.getProperty("s3.access.secret"); String currContainerStr = testProperties.getProperty("s3.test0001.bucket.name"); String currHost = testProperties.getProperty("s3.host"); String currRegion = testProperties.getProperty("s3.region"); DefaultFileSystemManager currMan = new DefaultFileSystemManager(); SS3FileProvider currSS3 = new SS3FileProvider(); // Optional set endpoint //currSS3.setEndpoint(currHost); // Optional set region //currSS3.setRegion(currRegion); currMan.addProvider(SS3Constants.S3SCHEME, currSS3); currMan.init(); StaticUserAuthenticator auth = new StaticUserAuthenticator("", currAccountStr, currKey); FileSystemOptions opts = new FileSystemOptions(); DefaultFileSystemConfigBuilder.getInstance().setUserAuthenticator(opts, auth); String currFileNameStr = "uploadFile02"; String currUriStr = String.format("%s://%s/%s/%s", SS3Constants.S3SCHEME, currHost, currContainerStr, currFileNameStr); FileObject currFile = currMan.resolveFile(currUriStr, opts); FileObject[] currObjs = currFile.getChildren(); for (FileObject obj : currObjs) { FileName currName = obj.getName(); Boolean res = obj.exists(); FileType ft = obj.getType(); log.info(String.format("\nNAME.PATH : '%s'\nEXISTS : %b\nTYPE : %s\n\n", currName.getPath(), res, ft)); } }