Modifier and Type | Class and Description |
---|---|
static class |
UrlUtil.HTTPDetails
helper class to set mime details
|
static class |
UrlUtil.URLProtocol
rough classification of protocol type
|
Modifier and Type | Field and Description |
---|---|
static String |
APPLICATION_PDF
pdf, duh...
|
static String |
APPLICATION_PS
ps, duh...
|
static String |
APPLICATION_XML
the preferred value for XML!
|
static String |
APPLICATION_XZIP
zip, maybe?
|
static String |
APPLICATION_ZIP
zip, maybe?
|
static String |
BASE64 |
static String |
BINARY |
static String |
CLOSE |
static String |
CONTENT_ID |
static String |
CONTENT_LENGTH
more commonly used strings
|
static String |
CONTENT_TRANSFER_ENCODING |
static String |
CONTENT_TYPE
more commonly used strings
|
static String |
GET
http get method
|
static String |
HEAD
http head method
|
static String |
KEEPALIVE |
static String |
m_UNCEscape
strings that must be escaped in uncs
|
static String |
m_URIEscape
strings that must be escaped in urls
|
static String |
POST
http post method
|
static String |
TEXT_CSV |
static String |
TEXT_HTML |
static String |
TEXT_PLAIN |
static String |
TEXT_UNKNOWN |
static String |
TEXT_XML |
static String |
VND_JDF |
static String |
VND_JMF |
static String |
VND_XJDF |
static String |
VND_XJMF |
Constructor and Description |
---|
UrlUtil() |
Modifier and Type | Method and Description |
---|---|
static String |
addParameter(String baseUrl,
String key,
String val)
adds a parameter to a given url using either ?
|
static String |
addPath(String baseUrl,
String path)
adds a path to a given url , keeping the parameters
|
static String |
cleanDots(String url)
remove any internal "../" "./" and "//" from a url
|
static String |
cleanHttpURL(String url)
create a "real" url from a user input url
add http://
|
static String |
createHttpUrl(boolean bSecure,
String host,
int port,
String path)
get a prinect url for this host and path
|
static String |
escape(String toEscape,
boolean bEscape128)
standard url escaping
|
static String |
extension(String pathName)
get the filename extension of pathName excluding the '.'
|
static String |
fileToUrl(File f,
boolean bEscape128)
Convert a File to a valid file URL or IRL
note that some internal functions use network protocol and therefor performance may be non-optimal |
static byte[] |
getBytesFromIP(String ip)
get the ip address as a set of bytes with the left byte at pos 0
|
static InputStream |
getCidURLStream(String url,
javax.mail.Multipart multipart)
get a readable inputstream from the CID url
|
static int |
getConnectionTimeout()
Returns connection timeout in milliseconds as integer.
|
static File |
getCreateDirectory(String newDir)
Deprecated.
use FileUtil.getCreateDirectory(newDir);
|
static String |
getExtensionFromMimeType(String contentType)
generates the correct extension for a given mime content type
|
static String |
getFileName(String url,
javax.mail.Multipart mp)
get the file name for a url. extract it from a mime package, if appropriate
|
static String |
getIPFromBytes(byte[] ip)
get the ip address as a string with the left byte at pos 0
|
static String |
getLocalURL(String directory,
String url)
get the local url without directory
schemes in the base url are case insensitive, all others are case sensitive
|
static String |
getMimeTypeFromURL(String url)
generates the correct MIMEType for a given URL and sets it
|
static String |
getParentDirectory(String url)
get the parent directory of a file or url
|
static UrlUtil.URLProtocol |
getProtocol(String url)
returns the general protocol type of a url
|
static String |
getRelativePath(File f,
File fCWD)
returns the relative URL of a file relative to the current working directory
this includes escaping of %20 etc. |
static String |
getRelativeURL(File f,
File baseDir,
boolean bEscape128)
returns the relative URL of a file relative to the current working directory
|
static InputStream |
getURLInputStream(String urlString) |
static InputStream |
getURLInputStream(String urlString,
javax.mail.BodyPart bodyPart)
get the opened input stream for a given url string
|
static UrlPart[] |
getURLParts(HttpURLConnection connection)
get an array of urlparts, regardless of whether this was mime or not if the stream is mime/multipart get also extract that
|
static String |
getURLWithDirectory(String directory,
String url)
concatenate directory and url to a single path IF and only IF url is a relative url
relative urls MUST NOT have a scheme (e.g. file:) |
static boolean |
isCID(String url)
test whether a given url is a cid (cid:)
|
static boolean |
isEscaped(String url)
test whether a given url is escaped as utf-8
|
static boolean |
isFile(String url)
is this a valid file url
|
static boolean |
isFileOK(File f)
checks whether there is a remote chance that the file is useful for reading
|
static boolean |
isFtp(String url)
test whether a given url is an http url (excluding https - @see isHttps)
|
static boolean |
isHttp(String url)
test whether a given url is an http url (excluding https - @see isHttps)
|
static boolean |
isHttps(String url)
test whether a given url is an https url
|
static boolean |
isIRL(String val) |
static boolean |
isMIME(File file)
check whether a file is a mime file only check extensions TODO sniff file rather than check extensions
|
static boolean |
isMIMEExtenstension(String lower)
check whether a file is a mime file
|
static boolean |
isNet(String url)
test whether a given url is any network style url, currently either http, https or ftp
|
static boolean |
isNotCID(String url)
test whether a given url is NOT a cid this may be a local identifier
|
static boolean |
isRedirect(int responseCode)
return true if the response code should redirect
|
static boolean |
isRelativeURL(String url)
if true this url is relative
|
static boolean |
isUNC(String pathName)
test whether a given url is a unc path
|
static boolean |
isURL(String val) |
static boolean |
isWindowsLocalPath(String pathName) |
static boolean |
isXMLType(String contentType)
check whether the mime type is a known xml dialect
|
static boolean |
isZIPType(String contentType)
check whether the mime type is a known zip dialect
|
static File |
moveToDir(IURLSetter parent,
File dir,
boolean overWrite)
Deprecated.
use moveToDir(parent, dir, null, overWrite);
|
static File |
moveToDir(IURLSetter urlSetter,
File dir,
String cwd,
boolean overWrite)
physically store the file at the location specified in dir and also modify parent to reflect the new location
|
static File |
moveToDir(IURLSetter urlSetter,
File dir,
String cwd,
boolean overWrite,
boolean deleteFile)
physically store the file at the location specified in dir and also modify parent to reflect the new location
|
static String |
newExtension(String strWork,
String newExt)
replace the .extension of a file name
|
static String |
normalize(String urlString)
normalize a url string by grinding it through url
|
static String |
prefix(String strWork)
inverse of extension
|
static String |
removeExtension(String pathName)
Deprecated.
use prefix(pathName)
|
static String |
removeProtocol(String url)
remove athe protocol part of a url, if it is specified
|
static void |
setConnectionTimeout(int timeout)
Returns connection timeout in milliseconds as integer.
|
static URL |
stringToURL(String urlString)
Create a URL for any url string using heuristics and escaping
|
static String |
uncToUrl(String unc,
boolean escape128) |
static String |
unEscape(String toEscape)
standard url unescaping
|
static File |
urlToFile(String urlString)
Retrieve a file for a relative or absolute file url
|
static String |
urlToFileName(String urlString) |
static String |
urlToString(URL url)
null safe url to string converter
|
static String |
urlToUNC(String urlString)
Retrieve a UNC path for a relative or absolute file url, any of '/'or "\\" is assumed a path separator
|
static UrlPart |
writerToURL(String strUrl,
IStreamWriter streamWriter,
String method,
String contentType,
UrlUtil.HTTPDetails details)
write the contents of an IStreamWriter to an output URL File: and http: are currently supported Use HttpURLConnection.getInputStream() to retrieve the http response
|
static UrlPart |
writeToURL(String strUrl,
InputStream stream,
String method,
String contentType,
UrlUtil.HTTPDetails details)
write a Stream to an output URL File: and http: are currently supported Use HttpURLConnection.getInputStream() to retrieve the http response
|
public static final String POST
public static final String GET
public static final String HEAD
public static final String KEEPALIVE
public static final String CLOSE
public static final String CONTENT_TRANSFER_ENCODING
public static final String m_URIEscape
public static final String m_UNCEscape
public static final String TEXT_HTML
public static final String TEXT_PLAIN
public static final String TEXT_UNKNOWN
public static final String APPLICATION_XML
public static final String APPLICATION_ZIP
public static final String APPLICATION_XZIP
public static final String APPLICATION_PDF
public static final String APPLICATION_PS
public static final String TEXT_XML
public static final String TEXT_CSV
public static final String VND_JDF
public static final String VND_JMF
public static final String VND_XJDF
public static final String VND_XJMF
public static final String CONTENT_ID
public static final String CONTENT_TYPE
public static final String CONTENT_LENGTH
public static final String BASE64
public static final String BINARY
public static void setConnectionTimeout(int timeout)
public static int getConnectionTimeout()
public static String getRelativeURL(File f, File baseDir, boolean bEscape128)
f
- the file to get the relative url forbaseDir
- the file that describes cwd, if null
cwd is calculatedbEscape128
- if true, escape > 128 (URL), else retain (IRL)public static String createHttpUrl(boolean bSecure, String host, int port, String path)
bSecure
- if true, make httpshost
- hostnameport
- the port, duhpath
- may be nullpublic static String getRelativePath(File f, File fCWD)
f
- the file to get the relative path forfCWD
- the file that describes cwd, if null
cwd is calculated from user.dirpublic static String getFileName(String url, javax.mail.Multipart mp)
url
- mp
- public static InputStream getCidURLStream(String url, javax.mail.Multipart multipart)
url
- the url to get a stream formultipart
- the multipart mime to which the cid refersnull
if broken or non-existentpublic static String extension(String pathName)
pathName
- the pathName to get the extension for@Deprecated public static String removeExtension(String pathName)
pathName
- the pathName to get the extension forpublic static UrlPart[] getURLParts(HttpURLConnection connection)
connection
- public static InputStream getURLInputStream(String urlString, javax.mail.BodyPart bodyPart)
urlString
- bodyPart
- public static InputStream getURLInputStream(String urlString)
urlString
- @Deprecated public static File getCreateDirectory(String newDir)
newDir
- the path or URL of the new directorypublic static String fileToUrl(File f, boolean bEscape128)
f
- the File to parse,bEscape128
- if true, escape non -ascii chars (URI), if false, don't (IRI)public static String urlToFileName(String urlString)
urlString
- the string to parse for a file namepublic static File urlToFile(String urlString)
urlString
- the file url to retrieve a file forpublic static String urlToUNC(String urlString)
urlString
- the file url to retrieve a UNC path forpublic static String uncToUrl(String unc, boolean escape128)
unc
- escape128
- if true escape chars>128public static String urlToString(URL url)
url
- public static String addParameter(String baseUrl, String key, String val)
baseUrl
- the base url - already escaped and ready to gokey
- the key to add - NOT escapedval
- the value to add - NOT escaped - if null nothing is setpublic static String addPath(String baseUrl, String path)
baseUrl
- the base url - already escaped and ready to gopath
- the path to addpublic static String escape(String toEscape, boolean bEscape128)
toEscape
- the string to escapebEscape128
- if true, also escape >128, else leave non-ascii7 as ispublic static String unEscape(String toEscape)
toEscape
- the string to unescapepublic static URL stringToURL(String urlString)
urlString
- the file url to retrieve a file forpublic static boolean isFileOK(File f)
f
- - File to checkpublic static boolean isEscaped(String url)
url
- the url to testpublic static String getExtensionFromMimeType(String contentType)
contentType
- public static String getMimeTypeFromURL(String url)
url
- public static boolean isCID(String url)
url
- the url to testpublic static boolean isNotCID(String url)
url
- the url to testpublic static boolean isFile(String url)
url
- public static boolean isWindowsLocalPath(String pathName)
pathName
- public static boolean isHttp(String url)
url
- the url to testpublic static boolean isFtp(String url)
url
- the url to testpublic static boolean isHttps(String url)
url
- the url to testpublic static boolean isNet(String url)
url
- the url to testpublic static String normalize(String urlString)
urlString
- public static boolean isUNC(String pathName)
pathName
- public static boolean isMIME(File file)
file
- the FILE to checkpublic static UrlUtil.URLProtocol getProtocol(String url)
url
- public static String getIPFromBytes(byte[] ip)
ip
- public static byte[] getBytesFromIP(String ip)
ip
- public static boolean isMIMEExtenstension(String lower)
lower
- public static boolean isIRL(String val)
val
- public static String removeProtocol(String url)
url
- the url string to work onpublic static boolean isURL(String val)
val
- public static String getLocalURL(String directory, String url)
directory
- the url of the directoryurl
- the absolute urlpublic static String getURLWithDirectory(String directory, String url)
directory
- the url of the directoryurl
- the relative url of the filepublic static String getParentDirectory(String url)
url
- public static String cleanDots(String url)
url
- the url to cleanpublic static String cleanHttpURL(String url)
url
- the input urlpublic static UrlPart writeToURL(String strUrl, InputStream stream, String method, String contentType, UrlUtil.HTTPDetails details)
strUrl
- the URL to write tostream
- the input stream to read frommethod
- HEAD, GET or POSTcontentType
- the contenttype to set, if NULL defaults to TEXT/UNKNOWNdetails
- UrlPart
the opened http connection, null in case of errorpublic static UrlPart writerToURL(String strUrl, IStreamWriter streamWriter, String method, String contentType, UrlUtil.HTTPDetails details)
strUrl
- the URL to write tostreamWriter
- the IStreamWriter to read frommethod
- HEAD, GET or POSTcontentType
- the contenttype to set, if NULL defaults to TEXT/UNKNOWNdetails
- UrlPart
the opened http connection, null in case of error@Deprecated public static File moveToDir(IURLSetter parent, File dir, boolean overWrite)
parent
- the parent element, trypically a filespec or previewdir
- the directory to move to. dir is created if it does not exist.
If dir exists and dir is not a directory, the call fails and null is returnedoverWrite
- if true, zapp any old files with the same namepublic static File moveToDir(IURLSetter urlSetter, File dir, String cwd, boolean overWrite)
urlSetter
- the parent element, typically a filespec or previewdir
- the directory to move to. dir is created if it does not exist.
If dir exists and dir is not a directory, the call fails and null is returnedcwd
- the current working dir for local urlsoverWrite
- if true, zapp any old files with the same namepublic static File moveToDir(IURLSetter urlSetter, File dir, String cwd, boolean overWrite, boolean deleteFile)
urlSetter
- the parent element, typically a filespec or previewdir
- the directory to move to. dir is created if it does not exist.
If dir exists and dir is not a directory, the call fails and null is returnedcwd
- the current working dir for local urlsoverWrite
- if true, zapp any old files with the same namepublic static boolean isRelativeURL(String url)
url
- the url string to testpublic static boolean isXMLType(String contentType)
contentType
- public static boolean isZIPType(String contentType)
contentType
- public static String newExtension(String strWork, String newExt)
strWork
- the file pathnewExt
- the new extension (works with or without the initial "."public static String prefix(String strWork)
strWork
- the string to work onpublic static boolean isRedirect(int responseCode)
responseCode
- Copyright © 2018. All rights reserved.