Package com.fasterxml.aalto.util
Class URLUtil
- java.lang.Object
-
- com.fasterxml.aalto.util.URLUtil
-
public final class URLUtil extends java.lang.Object
-
-
Constructor Summary
Constructors Modifier Constructor Description privateURLUtil()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.lang.StringfileToSystemId(java.io.File f)static java.net.URLfileToURL(java.io.File f)This method is added because the default conversion usingfile.toURL()turns out to be rather slow, as it tries to figure out if the file is actually a directory.static java.io.InputStreaminputStreamFromURL(java.net.URL url)Method that tries to get a stream (ideally, optimal one) to read from the specified URL.static java.io.OutputStreamoutputStreamFromURL(java.net.URL url)Method that tries to get a stream (ideally, optimal one) to write to the resource specified by given URL.private static voidthrowIoException(java.net.MalformedURLException mex, java.lang.String sysId)Helper method that tries to fully convert strange URL-specific exception to more general IO exception.static java.net.URLurlFromCurrentDir()Method that tries to create and return URL that denotes current working directory.static java.net.URLurlFromSystemId(java.lang.String sysId)Method that tries to figure out how to create valid URL from a system id, without additional contextual information.static java.net.URLurlFromSystemId(java.lang.String sysId, java.net.URL ctxt)static java.lang.StringurlToSystemId(java.net.URL u)
-
-
-
Method Detail
-
urlFromSystemId
public static java.net.URL urlFromSystemId(java.lang.String sysId) throws java.io.IOExceptionMethod that tries to figure out how to create valid URL from a system id, without additional contextual information. We could perhaps use java.net.URI class in future?- Throws:
java.io.IOException
-
urlFromSystemId
public static java.net.URL urlFromSystemId(java.lang.String sysId, java.net.URL ctxt) throws java.io.IOException- Throws:
java.io.IOException
-
urlFromCurrentDir
public static java.net.URL urlFromCurrentDir() throws java.io.IOExceptionMethod that tries to create and return URL that denotes current working directory. Usually used to create a context, when one is not explicitly passed.- Throws:
java.io.IOException
-
inputStreamFromURL
public static java.io.InputStream inputStreamFromURL(java.net.URL url) throws java.io.IOExceptionMethod that tries to get a stream (ideally, optimal one) to read from the specified URL. Currently it just means creating a simple file input stream if the URL points to a (local) file, and otherwise relying on URL classes input stream creation method.- Throws:
java.io.IOException
-
outputStreamFromURL
public static java.io.OutputStream outputStreamFromURL(java.net.URL url) throws java.io.IOExceptionMethod that tries to get a stream (ideally, optimal one) to write to the resource specified by given URL. Currently it just means creating a simple file output stream if the URL points to a (local) file, and otherwise relying on URL classes input stream creation method.- Throws:
java.io.IOException
-
fileToURL
public static java.net.URL fileToURL(java.io.File f) throws java.io.IOExceptionThis method is added because the default conversion usingfile.toURL()turns out to be rather slow, as it tries to figure out if the file is actually a directory. Now, for our use cases this is irrelevant, so we can optimize out that expensive part.- Throws:
java.io.IOException
-
fileToSystemId
public static java.lang.String fileToSystemId(java.io.File f) throws java.io.IOException- Throws:
java.io.IOException
-
urlToSystemId
public static java.lang.String urlToSystemId(java.net.URL u)
-
throwIoException
private static void throwIoException(java.net.MalformedURLException mex, java.lang.String sysId) throws java.io.IOExceptionHelper method that tries to fully convert strange URL-specific exception to more general IO exception. Also, to try to use JDK 1.4 feature without creating requirement, uses reflection to try to set the root cause, if we are running on JDK1.4- Throws:
java.io.IOException
-
-