List of usage examples for org.apache.commons.io FilenameUtils concat
public static String concat(String basePath, String fullFilenameToAdd)
From source file:nl.mpi.lamus.archive.implementation.LamusArchiveFileHelper.java
/** * @see ArchiveFileHelper#getDirectoryForNode(java.lang.String, java.lang.String, nl.mpi.lamus.workspace.model.WorkspaceNode) *///from w ww .j a va2 s. c o m @Override public String getDirectoryForNode(String parentPath, String parentCorpusNamePathToClosestTopNode, WorkspaceNode node) { // Not for top nodes logger.debug("Getting directory for node. parentPath: '" + parentPath + "'; parentCorpusNamePathToClosestTopNode: '" + parentCorpusNamePathToClosestTopNode + "'; node: " + node.toString()); String corpusstructureFolderPlusFilename = corpusstructureDirectoryName + File.separator + FilenameUtils.getName(parentPath); String closestTopNodeName = parentCorpusNamePathToClosestTopNode; if (closestTopNodeName.contains(File.separator)) { closestTopNodeName = parentCorpusNamePathToClosestTopNode.substring(0, parentCorpusNamePathToClosestTopNode.indexOf(File.separator)); } String topNodeBaseDirectory; String topNodeBaseDirectoryPlusAncestorFolders; if (closestTopNodeName.isEmpty()) { // parent is top node topNodeBaseDirectory = parentPath.replace(corpusstructureFolderPlusFilename, ""); topNodeBaseDirectoryPlusAncestorFolders = topNodeBaseDirectory; } else { topNodeBaseDirectory = findTopNodeBaseDirectory(parentPath, closestTopNodeName); topNodeBaseDirectoryPlusAncestorFolders = topNodeBaseDirectory.replace(closestTopNodeName, parentCorpusNamePathToClosestTopNode); } if (WorkspaceNodeType.METADATA.equals(node.getType())) { CmdiProfile nodeProfile = allowedCmdiProfiles.getProfile(node.getProfileSchemaURI().toString()); if ("corpus".equals(nodeProfile.getTranslateType())) { return FilenameUtils.concat(topNodeBaseDirectory, corpusstructureDirectoryName); } else if ("session".equals(nodeProfile.getTranslateType())) { return FilenameUtils.concat(topNodeBaseDirectoryPlusAncestorFolders, metadataDirectoryName); } else { throw new IllegalArgumentException("Metadata should be translated to either corpus or session"); } } else if (WorkspaceNodeType.RESOURCE_WRITTEN.equals(node.getType())) { return FilenameUtils.concat(topNodeBaseDirectoryPlusAncestorFolders, annotationsDirectoryName); } else if (WorkspaceNodeType.RESOURCE_AUDIO.equals(node.getType()) || WorkspaceNodeType.RESOURCE_IMAGE.equals(node.getType()) || WorkspaceNodeType.RESOURCE_VIDEO.equals(node.getType())) { return FilenameUtils.concat(topNodeBaseDirectoryPlusAncestorFolders, mediaDirectoryName); } else if (WorkspaceNodeType.RESOURCE_INFO.equals(node.getType())) { return FilenameUtils.concat(topNodeBaseDirectoryPlusAncestorFolders, infoDirectoryName); } else { throw new IllegalStateException("Not supported node type"); } }
From source file:nl.tudelft.goal.SimpleIDE.FilePanel.java
/** * Updates the tree model so that the children of the given mas node * correspond to the agent files described in the mas file. Any goal files * that are children of the given mas node but are not referenced to in the * mas file will be moved to the null file node. * * @param masNode// ww w . j av a 2 s . c om * The mas node of which the children should be refreshed. * @param showLoadError * If this is <code>false</code>, any GOALException thrown when * getting the agent file names will be ignored. If * <code>true</code>, the user will be notified of them.<br> * Use <code>false</code> when this is called after saving, as * the message should have already been displayed. */ private void refreshMASNode(MASNode masNode) { // Do nothing if the given node is not part of the tree (or null) if (!this.rootNode.isNodeDescendant(masNode)) { return; } // Do nothing if the file is not validated. MASProgram mas = this.platform.getMASProgram(masNode.getBaseFile()); if (mas == null) { return; } // Compare current nodes with current agent files associated with MAS // file. // Get current node children. List<FileNode> currentChildren = getChildrenOf(masNode); // Get the associated files. List<File> currentFiles = new ArrayList<File>(); for (FileNode node : currentChildren) { currentFiles.add(node.getBaseFile()); } // Get new agent files. List<File> newFiles = this.platform.getMASProgram(masNode.getBaseFile()).getAgentFiles(); // Get new emotion file. String emoString = this.platform.getMASProgram(masNode.getBaseFile()).getEmotionFile(); if (emoString != null) { if (new File(emoString).isAbsolute()) { newFiles.add(new File(emoString)); } else { String emoPath = masNode.getBaseFile().getParentFile().getAbsolutePath(); newFiles.add(new File(emoPath, emoString)); } } // Check whether nodes need to be removed, i.e., whether they do not // correspond with any files associated with the MAS file. for (FileNode node : currentChildren) { if (!newFiles.contains(node.getBaseFile())) { // Move node to the spurious file node. appendNode(null, node); } } // CHECK is this always absolute path? String masdir = masNode.getBaseFile().getParent(); // Check whether agent files need to be inserted. for (File agentFile : newFiles) { if (!agentFile.exists()) { // doesn't exist. Suggest to create String path = agentFile.getPath(); File newFile = new File(path); if (!newFile.isAbsolute()) { // If relative, prepend MAS dir. #2926 newFile = new File(FilenameUtils.concat(masdir, agentFile.getPath())); } try { proposeToCreate(this, newFile, Extension.GOAL); this.platform.parseGOALFile(newFile, mas.getKRInterface(newFile)); } catch (GOALUserError ignore) { // this file does not really exist. #2692 // We want to continue here to handle all other GOAL files, // even if user cancelled creation of one of these or IO // error happened. } catch (ParserException e) { // Even in case of serious parse errors we simply skip // the current agent file and continue with the next. // We want to process as many agent files as we can. continue; } } if (!currentFiles.contains(agentFile)) { FileNode newNode; if (Extension.getFileExtension(agentFile) == Extension.EMOTION) { newNode = new EmotionNode(agentFile); } else { newNode = new GOALNode(agentFile); } this.allFiles.add(newNode); // GOALNode newNode = insertGOALfile(agentFile.getAgentFile()); appendNode(masNode, newNode); // also let the tree scroll to the newly added node this.fileTree.scrollPathToVisible(new TreePath(masNode.getPath())); } } refreshSpuriousList(); }
From source file:ome.io.nio.AbstractFileSystemService.java
private String getPath(String prefix, Long id) { String suffix = ""; Long remaining = id;//from w w w . j ava 2s .co m Long dirno = 0L; if (id == null) { throw new NullPointerException("Expecting a not-null id."); } while (remaining > 999) { remaining /= 1000; if (remaining > 0) { Formatter formatter = new Formatter(); dirno = remaining % 1000; suffix = formatter.format("Dir-%03d", dirno).out().toString() + File.separator + suffix; } } String path = FilenameUtils.concat(root, prefix + suffix + id); return path; }
From source file:org.abstracthorizon.proximity.storage.local.ReadOnlyFileSystemStorage.java
public List listItems(String path) { logger.debug("Listing {} in storage directory {}", path, getStorageBaseDir()); List result = new ArrayList(); File target = new File(getStorageBaseDir(), path); if (target.exists()) { if (target.isDirectory()) { File[] files = target.listFiles(); for (int i = 0; i < files.length; i++) { ItemProperties item = loadItemProperties(FilenameUtils.concat(path, files[i].getName())); result.add(item);/*from w ww. j a va2 s . c o m*/ } } else { ItemProperties item = loadItemProperties(path); result.add(item); } } return result; }
From source file:org.abstracthorizon.proximity.storage.remote.CommonsNetFtpRemotePeer.java
/** * Concat paths.//from ww w.j a v a 2 s. c om * * @param path1 the path1 * @param path2 the path2 * * @return the string */ protected String concatPaths(String path1, String path2) { String result = FilenameUtils.concat(path1, path2); return FilenameUtils.separatorsToUnix(result); }
From source file:org.aludratest.impl.log4testing.output.util.OutputUtil.java
/** * Determines the proper target directory path for the provided test situation. * @param testName// www. j av a2 s. c o m * @param ignoreableRoot * @param abbreviating * @param baseDir * @return the path of the related target directory */ public static String targetDirPath(String testName, String ignoreableRoot, boolean abbreviating, File baseDir) { String result = OutputUtil.displayName(testName, ignoreableRoot, abbreviating); String packagePath = result.replaceAll("\\.", Matcher.quoteReplacement(File.separator)); return FilenameUtils.concat(baseDir.getAbsolutePath(), packagePath); }
From source file:org.apache.eagle.alert.engine.perf.TestSerDeserPer.java
@Test public void testSerDeserPerf() throws Exception { Kryo kryo = new Kryo(); String outputPath = FilenameUtils.concat(getTmpPath(), "file.bin"); Output output = new Output(new FileOutputStream(outputPath)); for (int i = 0; i < 1000; i++) { kryo.writeObject(output, constructPE()); }/* w w w.j a va 2 s . c o m*/ output.close(); Input input = new Input(new FileInputStream(outputPath)); PartitionedEvent someObject = kryo.readObject(input, PartitionedEvent.class); input.close(); Assert.assertTrue(someObject.getData().length == 1); }
From source file:org.apache.eagle.alert.engine.perf.TestSerDeserPer.java
@Test public void testSerDeserPerf2() throws Exception { Kryo kryo = new Kryo(); String outputPath = FilenameUtils.concat(getTmpPath(), "file2.bin"); Output output = new Output(new FileOutputStream(outputPath)); for (int i = 0; i < 1000; i++) { kryo.writeObject(output, constructNewPE()); }/*from w w w . ja v a 2 s . c o m*/ output.close(); Input input = new Input(new FileInputStream(outputPath)); NewPartitionedEvent someObject = kryo.readObject(input, NewPartitionedEvent.class); input.close(); Assert.assertTrue(someObject.getData().length == 1); }
From source file:org.apache.eagle.alert.engine.perf.TestSerDeserPer.java
@Test public void testSerDeserPerf3() throws Exception { Kryo kryo = new Kryo(); String outputPath = FilenameUtils.concat(getTmpPath(), "file3.bin"); Output output = new Output(new FileOutputStream(outputPath)); for (int i = 0; i < 1000; i++) { kryo.writeObject(output, constructNewPE2()); }/*from w w w . j a v a2s .co m*/ output.close(); Input input = new Input(new FileInputStream(outputPath)); NewPartitionedEvent2 someObject = kryo.readObject(input, NewPartitionedEvent2.class); input.close(); Assert.assertTrue(someObject.getData().length == 1); }
From source file:org.apache.falcon.regression.core.util.OSUtil.java
public static String concat(String path1, String path2, String... pathParts) { String path = FilenameUtils.concat(path1, path2); for (String pathPart : pathParts) { path = FilenameUtils.concat(path, pathPart); }/*from w w w . ja v a 2 s .co m*/ return path; }