Here you can find the source of getPath(final Object resource)
This method returns the path of a given resource which can be instance of File, URL, URI or String.
Parameter | Description |
---|---|
resource | instance of File, URL, URI, or String path. |
Parameter | Description |
---|---|
MalformedURLException | an exception |
private static String getPath(final Object resource) throws MalformedURLException
//package com.java2s; /*//from w w w . j av a 2 s . c o m * Geotoolkit - An Open Source Java GIS Toolkit * http://www.geotoolkit.org * * (C) 2008 - 2009, Geomatys * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. */ import java.io.File; import java.net.MalformedURLException; import java.net.URI; import java.net.URL; public class Main { /** * <p>This method returns the path of a given resource which can be * instance of File, URL, URI or String. Returns null in other cases.</p> * * @param resource instance of File, URL, URI, or String path. * @return The resource path. * @throws MalformedURLException */ private static String getPath(final Object resource) throws MalformedURLException { String extractPath = null; if (resource instanceof File) { extractPath = ((File) resource).getPath(); } else if (resource instanceof URL) { extractPath = ((URL) resource).getPath(); } else if (resource instanceof URI) { extractPath = (((URI) resource).toURL()).getPath(); } else if (resource instanceof String) { extractPath = (String) resource; } return extractPath; } }