List of usage examples for org.apache.commons.vfs2.provider.local DefaultLocalFileProvider DefaultLocalFileProvider
public DefaultLocalFileProvider()
From source file:com.sludev.commons.vfs2.provider.s3.SS3TestUtils.java
public static void uploadFile(String accntName, String acctHost, String accntKey, String containerName, Path localFile, Path remotePath) throws FileSystemException { DefaultFileSystemManager currMan = new DefaultFileSystemManager(); currMan.addProvider(SS3Constants.S3SCHEME, new SS3FileProvider()); currMan.addProvider("file", new DefaultLocalFileProvider()); currMan.init();//w ww .j a v a2s . c o m StaticUserAuthenticator auth = new StaticUserAuthenticator("", accntName, accntKey); FileSystemOptions opts = new FileSystemOptions(); DefaultFileSystemConfigBuilder.getInstance().setUserAuthenticator(opts, auth); String currUriStr = String.format("%s://%s/%s/%s", SS3Constants.S3SCHEME, acctHost, containerName, remotePath); FileObject currFile = currMan.resolveFile(currUriStr, opts); FileObject currFile2 = currMan.resolveFile(String.format("file://%s", localFile)); currFile.copyFrom(currFile2, Selectors.SELECT_SELF); currFile.close(); currMan.close(); }
From source file:com.sludev.commons.vfs2.provider.azure.AzTestUtils.java
public static void uploadFile(String accntName, String accntHost, String accntKey, String containerName, Path localFile, Path remotePath) throws FileSystemException { DefaultFileSystemManager currMan = new DefaultFileSystemManager(); currMan.addProvider(AzConstants.AZSBSCHEME, new AzFileProvider()); currMan.addProvider("file", new DefaultLocalFileProvider()); currMan.init();//www .ja v a2 s . c o m StaticUserAuthenticator auth = new StaticUserAuthenticator("", accntName, accntKey); FileSystemOptions opts = new FileSystemOptions(); DefaultFileSystemConfigBuilder.getInstance().setUserAuthenticator(opts, auth); String currUriStr = String.format("%s://%s/%s/%s", AzConstants.AZSBSCHEME, accntHost, containerName, remotePath); FileObject currFile = currMan.resolveFile(currUriStr, opts); FileObject currFile2 = currMan.resolveFile(String.format("file://%s", localFile)); currFile.copyFrom(currFile2, Selectors.SELECT_SELF); currFile.close(); currMan.close(); }
From source file:com.sludev.commons.vfs2.provider.azure.AzFileProviderTest.java
/** * /*from w w w .ja v a 2 s . c o 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.vfs2.provider.s3.SS3FileProviderTest.java
/** * Upload a single file to the test bucket. * @throws java.lang.Exception/* w w w . j av a 2s . c o m*/ */ @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.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();//from w ww . ja v a2s . co m mgr = currMan; //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.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 . ja v a 2s. co m 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.s3.SS3FileProviderTest.java
/** * Download a previously uploaded file from the test bucket. * @throws Exception /*from w w w . j a va 2s.c o 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:de.unioninvestment.portal.explorer.view.vfs.VFSMainView.java
public static DefaultFileSystemManager getManager() throws FileSystemException { DefaultFileSystemManager mngr = new DefaultFileSystemManager(); mngr.addProvider("sftp", new SftpFileProvider()); mngr.addProvider("ftp", new FtpFileProvider()); mngr.addProvider("file", new DefaultLocalFileProvider()); mngr.init();//from w ww . j a va 2 s . c o m return mngr; }
From source file:org.kalypso.service.unittests.WebDavRead.java
/** * This function tries to copy a file from a webdav. *//*from w ww.j av a2 s . co m*/ @Test public void testWebDavRead() throws IOException { final DefaultFileSystemManager manager = new DefaultFileSystemManager(); manager.addProvider("webdav", new WebdavFileProvider()); manager.addProvider("file", new DefaultLocalFileProvider()); manager.init(); final FileObject davFile = manager .resolveFile("webdav://albert:gnimfe@ibpm.bjoernsen.de/dav/pub/Test/test.txt"); Assert.assertNotNull(davFile); final File file = new File(FileUtilities.TMP_DIR, "davRead.txt"); final FileObject tmpFile = manager.toFileObject(file); Assert.assertNotNull(tmpFile); InputStream is = null; OutputStream os = null; try { is = davFile.getContent().getInputStream(); os = tmpFile.getContent().getOutputStream(); /* Copying ... */ IOUtils.copy(is, os); is.close(); os.close(); } finally { IOUtils.closeQuietly(is); IOUtils.closeQuietly(os); } Assert.assertTrue(tmpFile.exists()); }
From source file:org.kalypso.service.unittests.WebDavWrite.java
/** * This function tries to copy a file to a webdav. *//*w w w.ja v a 2s . c o m*/ @Test public void testWebDavWrite() throws IOException { final DefaultFileSystemManager manager = new DefaultFileSystemManager(); manager.addProvider("webdav", new WebdavFileProvider()); manager.addProvider("file", new DefaultLocalFileProvider()); manager.addProvider("tmp", new TemporaryFileProvider()); manager.setDefaultProvider(new UrlFileProvider()); manager.setFilesCache(new DefaultFilesCache()); manager.setTemporaryFileStore(new DefaultFileReplicator()); manager.init(); final File file = new File(FileUtilities.TMP_DIR, "davWrite.txt"); final FileObject testFile = manager.toFileObject(file); final FileObject davFile = manager .resolveFile("webdav://albert:gnimfe@ibpm.bjoernsen.de/dav/pub/Test/test.txt"); Assert.assertNotNull(davFile); FileUtil.copyContent(testFile, davFile); Assert.assertTrue(davFile.exists()); }