Package com.helger.commons.io.resource
Class URLResource
- java.lang.Object
-
- com.helger.commons.io.resource.URLResource
-
- All Implemented Interfaces:
IHasInputStream,IHasInputStreamAndReader,IReadableResource,IResourceBase
@Immutable public class URLResource extends Object implements IReadableResource
Implementation of theIReadableResourceinterface for URL objects.- Author:
- Philip Helger
-
-
Field Summary
Fields Modifier and Type Field Description static intDEFAULT_CONNECT_TIMEOUTstatic intDEFAULT_READ_TIMEOUT
-
Constructor Summary
Constructors Constructor Description URLResource(ISimpleURL aURL)URLResource(String sURL)URLResource(URI aURI)URLResource(URL aURL)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanequals(Object o)booleanexists()FilegetAsFile()URIgetAsURI()URLgetAsURL()InputStreamgetInputStream()Get the input stream to read from the object.InputStreamgetInputStream(int nConnectTimeoutMS, int nReadTimeoutMS)InputStreamgetInputStream(int nConnectTimeoutMS, int nReadTimeoutMS, IMutableWrapper<IOException> aExceptionHolder)InputStreamgetInputStream(int nConnectTimeoutMS, int nReadTimeoutMS, Consumer<? super URLConnection> aConnectionModifier, IMutableWrapper<IOException> aExceptionHolder)InputStreamgetInputStream(IMutableWrapper<IOException> aExceptionHolder)static InputStreamgetInputStream(URL aURL)StringgetPath()URLResourcegetReadableCloneForPath(String sPath)Get a new resource of the same implementation type as this object but for a different path.URLResourcegetReadableCloneForPath(URL aURL)StringgetResourceID()inthashCode()static booleanisExplicitURLResource(String sName)Check if the passed resource name is an explicit URL resource.booleanisReadMultiple()Check if theInputStreamfromIHasInputStream.getInputStream()andIHasInputStream.getBufferedInputStream()can be acquired more than once.StringtoString()-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface com.helger.commons.io.IHasInputStream
getBufferedInputStream
-
Methods inherited from interface com.helger.commons.io.IHasInputStreamAndReader
getBufferedReader, getReader
-
-
-
-
Field Detail
-
DEFAULT_CONNECT_TIMEOUT
public static final int DEFAULT_CONNECT_TIMEOUT
- See Also:
- Constant Field Values
-
DEFAULT_READ_TIMEOUT
public static final int DEFAULT_READ_TIMEOUT
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
URLResource
public URLResource(@Nonnull ISimpleURL aURL) throws MalformedURLException
- Throws:
MalformedURLException
-
URLResource
public URLResource(@Nonnull String sURL) throws MalformedURLException
- Throws:
MalformedURLException
-
URLResource
public URLResource(@Nonnull URI aURI) throws MalformedURLException
- Throws:
MalformedURLException
-
-
Method Detail
-
isExplicitURLResource
public static boolean isExplicitURLResource(@Nullable String sName)
Check if the passed resource name is an explicit URL resource.- Parameters:
sName- The name to check. May benull.- Returns:
trueif the passed name is an explicit URL resource.
-
getResourceID
@Nonnull public String getResourceID()
- Specified by:
getResourceIDin interfaceIResourceBase- Returns:
- A non-
nullresource ID used e.g. for system IDs in XML resolving.
-
getPath
@Nonnull public String getPath()
- Specified by:
getPathin interfaceIResourceBase- Returns:
- The requested path. Never
null
-
getInputStream
@Nullable public static InputStream getInputStream(@Nonnull URL aURL)
-
getInputStream
@Nullable public InputStream getInputStream()
Description copied from interface:IHasInputStreamGet the input stream to read from the object. Each time this method is called, a newInputStreamneeds to be created.- Specified by:
getInputStreamin interfaceIHasInputStream- Returns:
nullif resolving failed.
-
getInputStream
@Nullable public InputStream getInputStream(@CheckForSigned int nConnectTimeoutMS, @CheckForSigned int nReadTimeoutMS)
-
getInputStream
@Nullable public InputStream getInputStream(@Nullable IMutableWrapper<IOException> aExceptionHolder)
-
getInputStream
@Nullable public InputStream getInputStream(@CheckForSigned int nConnectTimeoutMS, @CheckForSigned int nReadTimeoutMS, @Nullable IMutableWrapper<IOException> aExceptionHolder)
-
getInputStream
@Nullable public InputStream getInputStream(@CheckForSigned int nConnectTimeoutMS, @CheckForSigned int nReadTimeoutMS, @Nullable Consumer<? super URLConnection> aConnectionModifier, @Nullable IMutableWrapper<IOException> aExceptionHolder)
-
isReadMultiple
public final boolean isReadMultiple()
Description copied from interface:IHasInputStreamCheck if theInputStreamfromIHasInputStream.getInputStream()andIHasInputStream.getBufferedInputStream()can be acquired more than once.- Specified by:
isReadMultiplein interfaceIHasInputStream- Returns:
trueif the input stream can be acquired more than once,falseif not.
-
exists
public boolean exists()
- Specified by:
existsin interfaceIResourceBase- Returns:
trueif the resource exists,falseotherwise.
-
getAsURL
@Nonnull public URL getAsURL()
- Specified by:
getAsURLin interfaceIResourceBase- Returns:
- the URL representation of this resource. May be
nullif this resource cannot be represented as an URL.
-
getAsFile
@Nullable public File getAsFile()
- Specified by:
getAsFilein interfaceIResourceBase- Returns:
- the File representation of this resource. May be
nullif this resource cannot be represented as a file.
-
getReadableCloneForPath
@Nonnull public URLResource getReadableCloneForPath(@Nonnull URL aURL)
-
getReadableCloneForPath
@Nonnull public URLResource getReadableCloneForPath(@Nonnull String sPath)
Description copied from interface:IReadableResourceGet a new resource of the same implementation type as this object but for a different path.- Specified by:
getReadableCloneForPathin interfaceIReadableResource- Parameters:
sPath- The new path to use. May not benull.- Returns:
- The resource of the same implementation but a different path. May
not be
null.
-
-