List of usage examples for org.apache.commons.vfs2 FileObject createFolder
void createFolder() throws FileSystemException;
From source file:org.pentaho.hadoop.shim.HadoopRunningOnClusterTest.java
@BeforeClass public static void setup() throws Exception { // Create a test hadoop configuration FileObject ramRoot = VFS.getManager().resolveFile(CONFIG_PROPERTY_CLASSPATH); if (ramRoot.exists()) { ramRoot.delete(new AllFileSelector()); }/*from w ww . j a va 2 s. c o m*/ ramRoot.createFolder(); // Create the implementation jars ramRoot.resolveFile("hadoop-mapreduce-client-app-2.7.0-mapr-1602.jar").createFile(); ramRoot.resolveFile("hadoop-mapreduce-client-common-2.7.0-mapr-1602.jar").createFile(); ramRoot.resolveFile("hadoop-mapreduce-client-contrib-2.7.0-mapr-1602.jar").createFile(); ramRoot.resolveFile("hadoop-mapreduce-client-core-2.7.0-mapr-1602.jar").createFile(); ramRoot.resolveFile("hadoop-mapreduce-client-hs-2.7.0-mapr-1602.jar").createFile(); pmrFolder = tempFolder.newFolder("pmr"); urlTestResources = Thread.currentThread().getContextClassLoader().getResource(PMR_PROPERTIES); Files.copy(Paths.get(urlTestResources.toURI()), Paths.get(pmrFolder.getAbsolutePath(), PMR_PROPERTIES)); }
From source file:org.pentaho.metaverse.impl.VfsLineageWriter.java
protected FileObject getOutputDirectoryAsFile(LineageHolder holder) { try {/*www . j a va 2s. com*/ FileObject dateRootFolder = getDateFolder(holder); dateRootFolder.createFolder(); String id = holder.getId() == null ? "unknown_artifact" : holder.getId(); if (id.startsWith(File.separator)) { // For *nix id = id.substring(1); } else if (Const.isWindows() && id.charAt(1) == ':') { // For windows id = id.replaceFirst(Pattern.quote(":"), ""); } try { FileObject folder = dateRootFolder.resolveFile(id); folder.createFolder(); if (folder.isFile()) { // must be a folder throw new IllegalStateException( Messages.getErrorString("ERROR.OutputFolderWrongType", folder.getName().getPath())); } return folder; } catch (Exception e) { log.error(Messages.getErrorString("ERROR.CouldNotCreateFile"), e); return null; } } catch (Exception e) { log.error(Messages.getErrorString("ERROR.CouldNotCreateFile"), e); throw new IllegalStateException(e); } }
From source file:org.pentaho.vfs.ui.VfsBrowser.java
public boolean createFolder(String folderName) throws FileSystemException { FileObject newFolder = getSelectedFileObject().resolveFile(folderName); if (newFolder.exists()) { throw new FileSystemException("vfs.provider/create-folder.error", folderName); }/*from w w w. j av a 2 s . c om*/ newFolder.createFolder(); TreeItem newFolderTreeItem = new TreeItem(fileSystemTree.getSelection()[0], SWT.NONE); newFolderTreeItem.setData(newFolder); newFolderTreeItem.setData("isLoaded", Boolean.TRUE); //$NON-NLS-1$ newFolderTreeItem.setImage(getFolderImage(newFolderTreeItem.getDisplay())); populateTreeItemText(newFolderTreeItem, newFolder); fileSystemTree.setSelection(newFolderTreeItem); setSelectedFileObject(newFolder); fireFileObjectSelected(); return true; }
From source file:org.renjin.primitives.files.Files.java
/** * Creates the last element of the path, unless recursive = TRUE. Trailing path separators are * removed.//from w w w . ja va 2 s . c o m * @param context the current call Context * @param path the path * @param showWarnings should the warnings on failure be shown? * @param recursive Should elements of the path other than the last be created? If true, like Unix's mkdir -p * @param mode the file mode to be used on Unix-alikes: it will be coerced by as.octmode. * (currently ignored by renjin) * @return true if the operation succeeded for each of the files attempted. * Using a missing value for a path name will always be regarded as a failure. * returns false if the directory already exists * @throws FileSystemException */ @Internal("dir.create") public static SEXP dirCreate(@Current Context context, String path, boolean showWarnings, boolean recursive, int mode) throws FileSystemException { FileObject dir = context.resolveFile(path); dir.createFolder(); // TODO: return correct value and implement warnings documented above context.setInvisibleFlag(); return new LogicalArrayVector(true); }
From source file:org.wso2.carbon.connector.FileCopyConnector.java
/** * Copy the file or folder from source to destination. * * @param messageContext The message context that is generated for processing the file. * @param opts FileSystemOptions. * @return return true, if file/folder is successfully copied. *//*from w w w .j a va 2 s . c om*/ private boolean copyFile(String source, MessageContext messageContext, FileSystemOptions opts) { String destination = (String) ConnectorUtils.lookupTemplateParamater(messageContext, FileConstants.NEW_FILE_LOCATION); String filePattern = (String) ConnectorUtils.lookupTemplateParamater(messageContext, FileConstants.FILE_PATTERN); String includeParentDir = (String) ConnectorUtils.lookupTemplateParamater(messageContext, FileConstants.INCLUDE_PARENT_DIRECTORY); boolean includeParentDirectory = FileConstants.DEFAULT_INCLUDE_PARENT_DIRECTORY; if (StringUtils.isNotEmpty(includeParentDir)) { includeParentDirectory = Boolean.parseBoolean(includeParentDir); } boolean resultStatus = false; StandardFileSystemManager manager = FileConnectorUtils.getManager(); FileObject souFile = null; FileObject destFile = null; try { souFile = manager.resolveFile(source, opts); destFile = manager.resolveFile(destination, opts); if (!souFile.exists()) { log.error("The File Location does not exist."); return false; } if (StringUtils.isNotEmpty(filePattern)) { FileObject[] children = souFile.getChildren(); for (FileObject child : children) { if (FileType.FILE.equals(child.getType())) { copy(child, destination, filePattern, opts, manager); } else if (FileType.FOLDER.equals(child.getType())) { String newSource = source + File.separator + child.getName().getBaseName(); copyFile(newSource, messageContext, opts); } } } else { if (FileType.FILE.equals(souFile.getType())) { String name = souFile.getName().getBaseName(); FileObject outFile = manager.resolveFile(destination + File.separator + name, opts); outFile.copyFrom(souFile, Selectors.SELECT_ALL); } else if (FileType.FOLDER.equals(souFile.getType())) { if (includeParentDirectory) { destFile = manager .resolveFile(destination + File.separator + souFile.getName().getBaseName(), opts); destFile.createFolder(); } destFile.copyFrom(souFile, Selectors.SELECT_ALL); } if (log.isDebugEnabled()) { log.debug("File copying completed from " + source + "to" + destination); } } } catch (FileSystemException e) { throw new SynapseException("Unable to copy a file/folder", e); } finally { manager.close(); } try { souFile.close(); destFile.close(); } catch (FileSystemException e) { log.error("Error while closing the FileObject", e); } return true; }
From source file:org.wso2.carbon.connector.FileCreate.java
/** * Create a file with Apache commons//w ww.ja va2 s. c o m * * @param source Location of the file/folder * @param content Content in a file * @param encoding Encoding type * @param messageContext The message context that is generated for processing the file * @return Return the status */ private boolean createFile(String source, String content, String encoding, MessageContext messageContext) { boolean resultStatus = false; StandardFileSystemManager manager; try { OutputStream out = null; manager = FileConnectorUtils.getManager(); if (manager != null) { FileObject sourceFile = manager.resolveFile(source, FileConnectorUtils.init(messageContext)); try { if (FileConnectorUtils.isFolder(sourceFile)) { sourceFile.createFolder(); } else { if (StringUtils.isEmpty(content)) { sourceFile.createFile(); } else { FileContent fileContent = sourceFile.getContent(); out = fileContent.getOutputStream(true); if (StringUtils.isEmpty(encoding)) { IOUtils.write(content, out, DEFAULT_ENCODING); } else { IOUtils.write(content, out, encoding); } } } resultStatus = true; if (log.isDebugEnabled()) { log.debug("File creation completed with " + source); } } finally { try { if (sourceFile != null) { sourceFile.close(); } } catch (FileSystemException e) { log.error("Error while closing FileObject: " + e.getMessage(), e); } try { if (out != null) { out.close(); } } catch (IOException e) { log.error("Error while closing OutputStream: " + e.getMessage(), e); } manager.close(); } } } catch (IOException e) { handleException("Unable to create a file/folder.", e, messageContext); } return resultStatus; }
From source file:org.wso2.carbon.connector.FileCreateConnector.java
/** * Create a new file/folder./*ww w . j a va 2 s .c o m*/ * * @param messageContext The message context that is generated for processing the file. * @return true, if the file/folder is successfully created. */ private boolean createFile(MessageContext messageContext) throws FileSystemException { String source = (String) ConnectorUtils.lookupTemplateParamater(messageContext, FileConstants.FILE_LOCATION); String content = (String) ConnectorUtils.lookupTemplateParamater(messageContext, FileConstants.CONTENT); String encoding = (String) ConnectorUtils.lookupTemplateParamater(messageContext, FileConstants.ENCODING); if (StringUtils.isEmpty(encoding)) { encoding = FileConstants.DEFAULT_ENCODING; } StandardFileSystemManager manager = FileConnectorUtils.getManager(); FileObject sourceFile = manager.resolveFile(source, FileConnectorUtils.init(messageContext)); if (FileConnectorUtils.isFolder(sourceFile)) { sourceFile.createFolder(); } else { if (StringUtils.isEmpty(content)) { sourceFile.createFile(); } else { OutputStream out = sourceFile.getContent().getOutputStream(); try { IOUtils.write(content, out, encoding); } catch (IOException e) { throw new SynapseException("Error while writing the file content", e); } finally { try { // close the file object sourceFile.close(); } catch (FileSystemException e) { log.error("Error while closing FileObject", e); } try { if (out != null) { out.close(); } } catch (IOException e) { log.error("Error while closing OutputStream", e); } // close the StandardFileSystemManager manager.close(); } } if (log.isDebugEnabled()) { log.debug("File creation completed with " + source); } } return true; }
From source file:org.wso2.carbon.connector.FileMove.java
/** * Move the files/*from ww w. j a v a2s .co m*/ * * @param source Location of the file * @param destination Destination of the file * @return return a resultStatus */ private boolean moveFile(String source, String destination, MessageContext messageContext) { boolean resultStatus = false; StandardFileSystemManager manager = null; try { manager = FileConnectorUtils.getManager(); // Create remote object FileObject remoteFile = manager.resolveFile(source, FileConnectorUtils.init(messageContext)); if (remoteFile.exists()) { FileObject file = manager.resolveFile(destination, FileConnectorUtils.init(messageContext)); if (!file.exists()) { file.createFolder(); } if (remoteFile.getType() == FileType.FOLDER) { remoteFile.moveTo(file); } else if (remoteFile.getType() == FileType.FILE) { FileObject newFile = manager.resolveFile( destination + File.separator + remoteFile.getName().getBaseName(), FileConnectorUtils.init(messageContext)); remoteFile.moveTo(newFile); } resultStatus = true; if (log.isDebugEnabled()) { log.debug("File move completed from " + source + " to " + destination); } } else { log.error("The file/folder location does not exist."); resultStatus = false; } } catch (IOException e) { handleException("Unable to move a file/folder.", e, messageContext); } finally { if (manager != null) { manager.close(); } } return resultStatus; }
From source file:org.wso2.carbon.connector.FileMoveConnector.java
/** * Move the file to the target directory. * * @param destination The target location of the folder to be moved. * @param remoteFile Location of the remote file. * @param manager Standard file system manager. * @param opts Configured file system options. * @throws FileSystemException On error parsing the file name, determining if the file exists and creating the * file/folder. *///from ww w . j a v a2 s.co m private void moveFile(String destination, FileObject remoteFile, StandardFileSystemManager manager, FileSystemOptions opts) throws FileSystemException { FileObject file = manager.resolveFile(destination, opts); if (FileConnectorUtils.isFolder(file)) { if (!file.exists()) { file.createFolder(); } file = manager.resolveFile(destination + File.separator + remoteFile.getName().getBaseName(), opts); } else if (!file.exists()) { file.createFile(); } remoteFile.moveTo(file); }
From source file:org.wso2.carbon.connector.FileMoveConnector.java
/** * Move the folder to the target directory. * * @param destination The target location of the folder to move folder. * @param source Location of the source folder. * @param includeParentDirectory Boolean type to include the parent directory. * @param manager Standard file system manager. * @param opts Configured file system options. *//*from ww w . jav a2s .c o m*/ private void moveFolder(String source, String destination, String filePattern, boolean includeParentDirectory, StandardFileSystemManager manager, FileSystemOptions opts) throws FileSystemException { FileObject remoteFile = manager.resolveFile(source, opts); FileObject file = manager.resolveFile(destination, opts); if (StringUtils.isNotEmpty(filePattern)) { FileObject[] children = remoteFile.getChildren(); for (FileObject child : children) { if (FileType.FILE.equals(child.getType())) { moveFileWithPattern(child, destination, filePattern, manager, opts); } else if (FileType.FOLDER.equals(child.getType())) { String newSource = source + File.separator + child.getName().getBaseName(); moveFolder(newSource, destination, filePattern, includeParentDirectory, manager, opts); } } } else if (includeParentDirectory) { FileObject destFile = manager .resolveFile(destination + File.separator + remoteFile.getName().getBaseName(), opts); destFile.createFolder(); remoteFile.moveTo(destFile); } else { if (!file.exists()) { file.createFolder(); } remoteFile.moveTo(file); remoteFile.createFolder(); } }