public SimpleJsonExtractor(WorkUnitState workUnitState) throws FileSystemException { this.workUnitState = workUnitState; // Resolve the file to pull if (workUnitState.getPropAsBoolean(ConfigurationKeys.SOURCE_CONN_USE_AUTHENTICATION, false)) { // Add authentication credential if authentication is needed UserAuthenticator auth = new StaticUserAuthenticator(workUnitState.getProp(ConfigurationKeys.SOURCE_CONN_DOMAIN, ""), workUnitState.getProp(ConfigurationKeys.SOURCE_CONN_USERNAME), PasswordManager.getInstance(workUnitState) .readPassword(workUnitState.getProp(ConfigurationKeys.SOURCE_CONN_PASSWORD))); FileSystemOptions opts = new FileSystemOptions(); DefaultFileSystemConfigBuilder.getInstance().setUserAuthenticator(opts, auth); this.fileObject = VFS.getManager().resolveFile(workUnitState.getProp(SOURCE_FILE_KEY), opts); } else { this.fileObject = VFS.getManager().resolveFile(workUnitState.getProp(SOURCE_FILE_KEY)); } // Open the file for reading LOGGER.info("Opening file " + this.fileObject.getURL().toString()); this.bufferedReader = this.closer.register(new BufferedReader(new InputStreamReader(this.fileObject.getContent().getInputStream(), ConfigurationKeys.DEFAULT_CHARSET_ENCODING))); }
/** * Initialize step info. Method is final against redefine in descendants. */ @Before public final void beforeCommon() throws Exception { KettleEnvironment.init(); PluginRegistry.addPluginType( CompressionPluginType.getInstance() ); PluginRegistry.init( false ); stepMeta = new StepMeta(); stepMeta.setName( "test" ); trans = new Trans(); trans.setLog( log ); trans.setRunning( true ); transMeta = new TransMeta() { @Override public StepMeta findStep( String name ) { return stepMeta; } }; fs = VFS.getManager(); inPrefix = '/' + this.getClass().getPackage().getName().replace( '.', '/' ) + "/files/"; }
@Before public void setup() throws FileSystemException { fs = VFS.getManager(); filesPath = '/' + this.getClass().getPackage().getName().replace( '.', '/' ) + "/files/"; transName = "LoadFileInput"; transMeta = new TransMeta(); transMeta.setName( transName ); trans = new Trans( transMeta ); stepMetaInterface = spy( new LoadFileInputMeta() ); stepInputFiles = new FileInputList(); Mockito.doReturn( stepInputFiles ).when( stepMetaInterface ).getFiles( any( VariableSpace.class ) ); String stepId = PluginRegistry.getInstance().getPluginId( StepPluginType.class, stepMetaInterface ); stepMeta = new StepMeta( stepId, "Load File Input", stepMetaInterface ); transMeta.addStep( stepMeta ); stepDataInterface = new LoadFileInputData(); stepCopyNr = 0; stepLoadFileInput = new LoadFileInput( stepMeta, stepDataInterface, stepCopyNr, transMeta, trans ); assertSame( stepMetaInterface, stepMeta.getStepMetaInterface() ); runtimeSMI = stepMetaInterface; runtimeSDI = runtimeSMI.getStepData(); inputField = new LoadFileInputField(); ((LoadFileInputMeta) runtimeSMI).setInputFields( new LoadFileInputField[] { inputField } ); stepLoadFileInput.init( runtimeSMI, runtimeSDI ); }
try builder = VFS.getManager().getFileSystemConfigBuilder(scheme);
@Override public InputStream getInputStream(final URL url) throws ConfigurationException { FileObject file; try { final FileSystemOptions opts = getOptions(url.getProtocol()); file = (opts == null) ? VFS.getManager().resolveFile(url.toString()) : VFS.getManager().resolveFile(url.toString(), opts); if (file.getType() != FileType.FILE) { throw new ConfigurationException("Cannot load a configuration from a directory"); } final FileContent content = file.getContent(); if (content == null) { final String msg = "Cannot access content of " + file.getName().getFriendlyURI(); throw new ConfigurationException(msg); } return content.getInputStream(); } catch (final FileSystemException fse) { final String msg = "Unable to access " + url.toString(); throw new ConfigurationException(msg, fse); } }
/** * Starts watching the file system for changes to trigger a bake. * * @param config JBakeConfiguration settings */ public void start(JBakeConfiguration config) { try { FileSystemManager fsMan = VFS.getManager(); FileObject listenPath = fsMan.resolveFile(config.getContentFolder().toURI()); FileObject templateListenPath = fsMan.resolveFile(config.getTemplateFolder().toURI()); FileObject assetPath = fsMan.resolveFile(config.getAssetFolder().toURI()); logger.info("Watching for (content, template, asset) changes in [{}]", config.getSourceFolder().getPath()); DefaultFileMonitor monitor = new DefaultFileMonitor(new CustomFSChangeListener(config)); monitor.setRecursive(true); monitor.addFile(listenPath); monitor.addFile(templateListenPath); monitor.addFile(assetPath); monitor.start(); } catch (FileSystemException e) { logger.error("Problems watching filesystem changes", e); } } }
@Override public OutputStream getOutputStream(final URL url) throws ConfigurationException { try { final FileSystemOptions opts = getOptions(url.getProtocol()); final FileSystemManager fsManager = VFS.getManager(); final FileObject file = (opts == null) ? fsManager.resolveFile(url.toString()) : fsManager.resolveFile(url.toString(), opts); // throw an exception if the target URL is a directory if (file == null || file.getType() == FileType.FOLDER) { throw new ConfigurationException("Cannot save a configuration to a directory"); } final FileContent content = file.getContent(); if (content == null) { throw new ConfigurationException("Cannot access content of " + url); } return content.getOutputStream(); } catch (final FileSystemException fse) { throw new ConfigurationException("Unable to access " + url, fse); } }
@Override public String getFileName(final String path) { if (UriParser.extractScheme(path) == null) { return super.getFileName(path); } try { final FileSystemManager fsManager = VFS.getManager(); final FileName name = fsManager.resolveURI(path); return name.getBaseName(); } catch (final FileSystemException fse) { fse.printStackTrace(); return null; } }
/** * Returns the file that is monitored by this strategy. Note that the return * value can be <b>null </b> under some circumstances. * * @return the monitored file */ protected FileObject getFileObject() { if (!getFileHandler().isLocationDefined()) { return null; } try { final FileSystemManager fsManager = VFS.getManager(); final String uri = resolveFileURI(); if (uri == null) { throw new ConfigurationRuntimeException("Unable to determine file to monitor"); } return fsManager.resolveFile(uri); } catch (final FileSystemException fse) { final String msg = "Unable to monitor " + getFileHandler().getURL().toString(); log.error(msg); throw new ConfigurationRuntimeException(msg, fse); } }
FileSystemManager fsManager = VFS.getManager(); if (fsManager == null) { throw newError("Cannot get virtual file system manager");
@Override public String getBasePath(final String path) { if (UriParser.extractScheme(path) == null) { return super.getBasePath(path); } try { final FileSystemManager fsManager = VFS.getManager(); final FileName name = fsManager.resolveURI(path); return name.getParent().getURI(); } catch (final FileSystemException fse) { fse.printStackTrace(); return null; } }
@Override public URL getURL(final String basePath, final String file) throws MalformedURLException { if ((basePath != null && UriParser.extractScheme(basePath) == null) || (basePath == null && UriParser.extractScheme(file) == null)) { return super.getURL(basePath, file); } try { final FileSystemManager fsManager = VFS.getManager(); FileName path; if (basePath != null && UriParser.extractScheme(file) == null) { final FileName base = fsManager.resolveURI(basePath); path = fsManager.resolveName(base, file); } else { path = fsManager.resolveURI(file); } final URLStreamHandler handler = new VFSURLStreamHandler(path); return new URL(null, path.getURI(), handler); } catch (final FileSystemException fse) { throw new ConfigurationRuntimeException("Could not parse basePath: " + basePath + " and fileName: " + file, fse); } }
final FileSystemManager fsManager = VFS.getManager(); if (url != null)
private FileObject getFileObjectForLocalFile(File file) { try { return VFS.getManager().toFileObject(file); } catch (FileSystemException e) { throw new RuntimeException("Cannot open file: " + file, e); } }
final FileSystemManager fsManager = VFS.getManager();
@Before public void setup() throws IOException { final File zipFile = new File("src/test/resources/test-data/test.zip"); newZipFile = File.createTempFile(getClass().getSimpleName(), ".zip"); newZipFile.deleteOnExit(); FileUtils.copyFile(zipFile, newZipFile); zipFileUri = "zip:file:" + newZipFile.getAbsolutePath() + "!/read-tests/file1.txt"; manager = VFS.getManager(); }
/** * Even if the file name is absolute, the base file must be given. This is an inconsistency in the API, but it is * documented as such. * * @see "VFS-519" */ @Test(expected = NullPointerException.class) public void testResolveFileAbsoluteThrows() throws FileSystemException { final String absolute = new File("/").getAbsoluteFile().toURI().toString(); VFS.getManager().resolveFile((File) null, absolute); }
@Test @Ignore public void testFileNameWithSpaces() throws URISyntaxException, IOException { final File file = new File("target", "a name.txt"); final String fileURL = file.toURI().toURL().toExternalForm(); assertEquals(file.getAbsoluteFile(), new File(file.toURI().getPath())); assertEquals(file.getAbsoluteFile(), new File(new URL(fileURL).toURI().getPath())); final FileSystemManager manager = VFS.getManager(); final FileObject fo = manager.resolveFile(fileURL); assertEquals(file.getAbsoluteFile(), new File(new URL(fo.getURL().toExternalForm()).toURI().getPath())); }
private void testResloveFolderSlash(final String uri, final boolean followRedirect) throws FileSystemException { VFS.getManager().getFilesCache().close(); final FileSystemOptions opts = new FileSystemOptions(); HttpFileSystemConfigBuilder.getInstance().setFollowRedirect(opts, followRedirect); final FileObject file = VFS.getManager().resolveFile(uri, opts); try { checkReadTestsFolder(file); } catch (final FileNotFolderException e) { // Expected: VFS HTTP does not support listing children yet. } }
@Test public void testAttributes() throws Exception { final FileObject file = JarProviderTestCase.getTestJar(VFS.getManager(), "test.jar"); final Map<String, Object> attributes = file.getContent().getAttributes(); Assert.assertEquals("1.0", attributes.get("Manifest-Version")); // Debugging: // this.printAttributes(attributes); }