All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.contrastsecurity.cassandra.migration.utils.UrlUtils Maven / Gradle / Ivy

/**
 * Copyright 2010-2015 Axel Fontaine
 * 

* Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at *

* http://www.apache.org/licenses/LICENSE-2.0 *

* Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.contrastsecurity.cassandra.migration.utils; import java.io.File; import java.io.UnsupportedEncodingException; import java.net.URL; import java.net.URLDecoder; /** * Collection of utility methods for working with URLs. */ public class UrlUtils { /** * Prevent instantiation. */ private UrlUtils() { // Do nothing } /** * Retrieves the file path of this URL, with any trailing slashes removed. * * @param url The URL to get the file path for. * @return The file path. */ public static String toFilePath(URL url) { try { String filePath = new File(URLDecoder.decode(url.getPath().replace("+", "%2b"), "UTF-8")).getAbsolutePath(); if (filePath.endsWith("/")) { return filePath.substring(0, filePath.length() - 1); } return filePath; } catch (UnsupportedEncodingException e) { throw new IllegalStateException("Can never happen", e); } } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy