Java Code Examples for org.apache.commons.io.FilenameUtils#getFullPath()

The following examples show how to use org.apache.commons.io.FilenameUtils#getFullPath() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FileUtilsEx.java    From pgptool with GNU General Public License v3.0 6 votes vote down vote up
/**
 * bruteforce filename adding index to base filename until vacant filename
 * found.
 */
public static String ensureFileNameVacant(String requestedTargetFile) {
	String ret = requestedTargetFile;
	int idx = 0;
	String basePathName = FilenameUtils.getFullPath(requestedTargetFile)
			+ FilenameUtils.getBaseName(requestedTargetFile);
	String ext = FilenameUtils.getExtension(requestedTargetFile);
	while (new File(ret).exists()) {
		idx++;
		ret = basePathName + "-" + idx;
		if (StringUtils.hasText(ext)) {
			ret += "." + ext;
		}
	}
	return ret;
}
 
Example 2
Source File: ShapefileReader.java    From mrgeo with Apache License 2.0 6 votes vote down vote up
@SuppressFBWarnings(value = {"WEAK_FILENAMEUTILS",
    "PATH_TRAVERSAL_IN"}, justification = "Correctly filtered parameters")
private void readObject(ObjectInputStream in) throws ClassNotFoundException, IOException
{
  fileName = in.readUTF();
  source = Source.values()[in.readInt()];

  if (source == Source.FILE)
  {
    File f = new File(FilenameUtils.getFullPath(fileName), FilenameUtils.getName(fileName));
    if (f.exists())
    {
      load(fileName);
    }
  }
  else
  {
    if (HadoopFileUtils.exists(fileName))
    {
      load(new Path(fileName));
    }
  }
}
 
Example 3
Source File: SwaggerHubUpload.java    From swaggerhub-maven-plugin with Apache License 2.0 6 votes vote down vote up
/**
 * This version of createSaveSCMPluginConfigRequest is for input file based upload
 * @param input
 * @param oasVersion
 * @return
 */
private SaveSCMPluginConfigRequest createSaveSCMPluginConfigRequest(SaveSCMPluginConfigRequest input, String inputFile, String oasVersion, String languageTarget){

    String outputFolder = FilenameUtils.getFullPath(inputFile);
    outputFolder = getOutputFolder(outputFolder);

    SaveSCMPluginConfigRequest saveSCMPluginConfigRequest = new SaveSCMPluginConfigRequest.Builder(input.getOwner(), input.getApi(), input.getVersion())
            .saveSCMPluginConfigRequest(input)
            .oas(oasVersion)
            .target(languageTarget)
            .outputFolder(outputFolder)
            .managedPaths(new String[]{FilenameUtils.getName(inputFile)})
            .outputFile(FilenameUtils.getName(inputFile))
            .build();

    return saveSCMPluginConfigRequest;
}
 
Example 4
Source File: CommonsIOUnitTest.java    From tutorials with MIT License 5 votes vote down vote up
@Test
public void whenUsingFileNameUtils_thenshowdifferentFileOperations() throws IOException {

    String path = getClass().getClassLoader().getResource("fileTest.txt").getPath();

    String fullPath = FilenameUtils.getFullPath(path);
    String extension = FilenameUtils.getExtension(path);
    String baseName = FilenameUtils.getBaseName(path);

    System.out.println("full path" + fullPath);
    System.out.println("Extension" + extension);
    System.out.println("Base name" + baseName);
}
 
Example 5
Source File: ViewLogFileAction.java    From oxTrust with MIT License 5 votes vote down vote up
private Map<Integer, String> prepareLogFiles() {
	Map<Integer, String> logFiles = new HashMap<Integer, String>();

	int fileIndex = 0;
	for (SimpleCustomProperty logTemplate : this.logViewerConfiguration.getLogTemplates()) {
		String logTemplatePattern = logTemplate.getValue2();
		if (StringHelper.isEmpty(logTemplatePattern)) {
			continue;
		}

		String logTemplatePath = FilenameUtils.getFullPath(logTemplatePattern);
		String logTemplateFile = FilenameUtils.getName(logTemplatePattern);

		File logTemplateBaseDir = new File(logTemplatePath);

		FileFilter fileFilter = new AndFileFilter(FileFileFilter.FILE, new WildcardFileFilter(logTemplateFile));
		File[] files = logTemplateBaseDir.listFiles(fileFilter);
		if (files == null) {
			continue;
		}

		for (int i = 0; i < files.length; i++) {
			logFiles.put(fileIndex++, files[i].getPath());
		}
	}

	return logFiles;
}
 
Example 6
Source File: UserManagementServiceBean.java    From cuba with Apache License 2.0 5 votes vote down vote up
private String getLocalizedTemplateContent(String defaultTemplateName, String locale) {
    String localizedTemplate = FilenameUtils.getFullPath(defaultTemplateName)
            + FilenameUtils.getBaseName(defaultTemplateName) +
            "_" + locale +
            "." + FilenameUtils.getExtension(defaultTemplateName);

    return resources.getResourceAsString(localizedTemplate);
}
 
Example 7
Source File: CubaApplicationServlet.java    From cuba with Apache License 2.0 5 votes vote down vote up
@Nullable
protected String getLocalizedTemplateContent(Resources resources, String defaultTemplateName, String locale) {
    String localizedTemplate = FilenameUtils.getFullPath(defaultTemplateName)
            + FilenameUtils.getBaseName(defaultTemplateName) +
            "_" + locale +
            "." + FilenameUtils.getExtension(defaultTemplateName);

    return resources.getResourceAsString(localizedTemplate);
}
 
Example 8
Source File: HistoryQuickSearchTableModel.java    From pgptool with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Object getValueAt(int rowIndex, int columnIndex) {
	DecryptionDialogParameters s = decryptions.get(rowIndex);

	switch (columnIndex) {
	case -1:
		return s;
	case COLUMN_NAME:
		return " " + FilenameUtils.getName(s.getSourceFile());
	case COLUMN_PATH:
		return " " + FilenameUtils.getFullPath(s.getSourceFile());
	default:
		throw new IllegalArgumentException("Wrong column index: " + columnIndex);
	}
}
 
Example 9
Source File: FFMediaLoader.java    From AudioBookConverter with GNU General Public License v2.0 5 votes vote down vote up
static void parseCueChapters(MediaInfoBean mediaInfo) throws IOException {
    String filename = mediaInfo.getFileName();
    File file = new File(FilenameUtils.getFullPath(filename) + FilenameUtils.getBaseName(filename) + ".cue");
    if (file.exists()) {
        String cue = FileUtils.readFileToString(file);

        parseCue(mediaInfo, cue);
    }
}
 
Example 10
Source File: DefinitelyDerefedParamsDriver.java    From NullAway with MIT License 5 votes vote down vote up
MethodParamAnnotations run(String inPaths, String pkgName, boolean includeNonPublicClasses)
    throws IOException, ClassHierarchyException, IllegalArgumentException {
  String outPath = "";
  String firstInPath = inPaths.split(",")[0];
  if (firstInPath.endsWith(".jar") || firstInPath.endsWith(".aar")) {
    outPath =
        FilenameUtils.getFullPath(firstInPath)
            + FilenameUtils.getBaseName(firstInPath)
            + ASTUBX_JAR_SUFFIX;
  } else if (new File(firstInPath).exists()) {
    outPath = FilenameUtils.getFullPath(firstInPath) + DEFAULT_ASTUBX_LOCATION;
  }
  return run(inPaths, pkgName, outPath, false, false, includeNonPublicClasses, DEBUG, VERBOSE);
}
 
Example 11
Source File: CommonsIOUnitTest.java    From tutorials with MIT License 5 votes vote down vote up
@Test
public void whenSortDirWithPathFileComparator_thenFirstFileaaatxt() throws IOException {

    PathFileComparator pathFileComparator = new PathFileComparator(IOCase.INSENSITIVE);
    String path = FilenameUtils.getFullPath(getClass().getClassLoader().getResource("fileTest.txt").getPath());
    File dir = new File(path);
    File[] files = dir.listFiles();

    pathFileComparator.sort(files);

    Assert.assertEquals("aaa.txt", files[0].getName());
}
 
Example 12
Source File: EngineCallback.java    From jqm with Apache License 2.0 5 votes vote down vote up
@Override
public void onNodeConfigurationRead(Node node)
{
    DbConn cnx = Helpers.getNewDbSession();

    // Main log levels comes from configuration
    CommonService.setLogLevel(node.getRootLogLevel());
    this.logLevel = node.getRootLogLevel();

    // Log multicasting (& log4j stdout redirect)
    String gp1 = GlobalParameter.getParameter(cnx, "logFilePerLaunch", "true");
    if ("true".equals(gp1) || "both".equals(gp1))
    {
        oneLogPerLaunch = true;
        RollingFileAppender a = (RollingFileAppender) Logger.getRootLogger().getAppender("rollingfile");
        MultiplexPrintStream s = new MultiplexPrintStream(System.out, FilenameUtils.getFullPath(a.getFile()), "both".equals(gp1));
        System.setOut(s);
        ((ConsoleAppender) Logger.getRootLogger().getAppender("consoleAppender")).setWriter(new OutputStreamWriter(s));
        s = new MultiplexPrintStream(System.err, FilenameUtils.getFullPath(a.getFile()), "both".equals(gp1));
        System.setErr(s);
    }

    // Jetty
    this.server = new JettyServer();
    this.server.start(node, cnx);

    // Deployment scanner
    String gp2 = GlobalParameter.getParameter(cnx, "directoryScannerRoot", "");
    if (!gp2.isEmpty())
    {
        scanner = new DirectoryScanner(gp2, node);
        (new Thread(scanner)).start();
    }

    cnx.close();
}
 
Example 13
Source File: PathUtils.java    From hypergraphql with Apache License 2.0 5 votes vote down vote up
public static String makeAbsolute(final String generalPath, final String path) {

        if(isAbsolute(path)) { // FQ URL or absolute path
            return path;
        } else {
            final String parentPath = FilenameUtils.getFullPath(generalPath);
            return parentPath +
                    (parentPath.endsWith("/") ? "" : "/") +
                    path;
        }
    }
 
Example 14
Source File: HGQLConfigService.java    From hypergraphql with Apache License 2.0 5 votes vote down vote up
private String extractFullSchemaPath(final String hgqlConfigPath, final String schemaPath) {

        LOGGER.debug("HGQL config path: {}, schema path: {}", hgqlConfigPath, schemaPath);
        final String configPath = FilenameUtils.getFullPath(hgqlConfigPath);
        if(StringUtils.isBlank(configPath)) {
            return schemaPath;
        } else {
            final String abs = PathUtils.makeAbsolute(configPath, schemaPath);
            LOGGER.debug("Absolute path: {}", abs);
            return PathUtils.makeAbsolute(configPath, schemaPath);
        }
    }
 
Example 15
Source File: Configuration.java    From chipster with MIT License 4 votes vote down vote up
public Configuration(URL configUrl, List<String> configModules) throws IOException, IllegalConfigurationException {
	this(configUrl.openConnection().getInputStream(), configModules);
	this.configRootURL = new URL(FilenameUtils.getFullPath(configUrl.toString()));
}
 
Example 16
Source File: MPQFileHandle.java    From riiablo with Apache License 2.0 4 votes vote down vote up
@Override
public String path() {
  return FilenameUtils.getFullPath(fileName);
}
 
Example 17
Source File: BartUtility.java    From BART with MIT License 4 votes vote down vote up
public static String generateFolderPath(String filePath) {
    return FilenameUtils.getFullPath(filePath);
}
 
Example 18
Source File: LunaticUtility.java    From Llunatic with GNU General Public License v3.0 4 votes vote down vote up
public static String generateFolderPath(String filePath) {
    return FilenameUtils.getFullPath(filePath);
}
 
Example 19
Source File: SMAMetadataTypes.java    From salesforce-migration-assistant with MIT License 4 votes vote down vote up
/**
 * Creates an SMAMetadata object from a string representation of a file's path and filename.
 *
 * @param filepath
 * @return SMAMetadata
 * @throws Exception
 */
public static SMAMetadata createMetadataObject(String filepath, byte[] data) throws Exception
{
    if (!docAlive)
    {
        initDocument();
    }

    String container = "empty";
    String metadataType = "Invalid";
    boolean destructible = false;
    boolean valid = false;
    boolean metaxml = false;

    File file = new File(filepath);
    String object = file.getName();
    String member = FilenameUtils.removeExtension(object);
    String extension = FilenameUtils.getExtension(filepath);
    String path = FilenameUtils.getFullPath(filepath);

    //Normalize the salesforceMetadata.xml configuration file
    doc.getDocumentElement().normalize();

    NodeList extNodes = doc.getElementsByTagName("extension");

    //Get the node with the corresponding extension and get the relevant information for
    //creating the SMAMetadata object
    for (int iterator = 0; iterator < extNodes.getLength(); iterator++)
    {
        Node curNode = extNodes.item(iterator);

        Element element = (Element) curNode;
        if (element.getAttribute("name").equals(extension))
        {
            container = element.getElementsByTagName("container").item(0).getTextContent();
            metadataType = element.getElementsByTagName("metadata").item(0).getTextContent();
            destructible = Boolean.parseBoolean(element.getElementsByTagName("destructible").item(0).
                    getTextContent());
            valid = true;
            metaxml = Boolean.parseBoolean(element.getElementsByTagName("metaxml").item(0).getTextContent());
            break;
        }
    }

    return new SMAMetadata(extension, container, member, metadataType,
            path, destructible, valid, metaxml, data);
}
 
Example 20
Source File: UriUtils.java    From vividus with Apache License 2.0 3 votes vote down vote up
/**
 * Builds a new URL from base URL and relative URL
 * <br>A <b>base URL</b> - an absolute URL (e.g <code>https://example.com/path</code>).
 * <br>A <b>relative URL</b> pointing to any resource (e.g <code>/other</code>)
 * <br>
 * Examples:
 * <pre>
 * buildNewRelativeUrl(new URI("https://example.com/path"), "/test")  --&gt; https://example.com/test
 * buildNewRelativeUrl(new URI("https://example.com/path/"), "/test") --&gt; https://example.com/test
 * buildNewRelativeUrl(new URI("https://example.com/path"), "test")   --&gt; https://example.com/path/test
 * </pre>
 * @param baseUri Base URL
 * @param relativeUrl A string value of the relative URL
 * @return new URL built from base URL and relative URL
 */
public static URI buildNewRelativeUrl(URI baseUri, String relativeUrl)
{
    String pathToGo = relativeUrl;
    if (!pathToGo.startsWith(String.valueOf(SLASH)))
    {
        String currentPath = FilenameUtils.getFullPath(baseUri.getPath());
        if (currentPath.isEmpty())
        {
            currentPath = String.valueOf(SLASH);
        }
        pathToGo = currentPath + pathToGo;
    }
    return buildNewUrl(baseUri, pathToGo);
}