java.lang.Object
org.springframework.core.io.AbstractResource
org.cruk.clarity.api.impl.URLInputStreamResource
- All Implemented Interfaces:
InputStreamSource
,Resource
Resource implementation based around a URL. Can be used for any source where
the URL protocol is supported by the JVM.
- Since:
- 2.23
-
Constructor Summary
ConstructorDescriptionCreate a new resource around the given URL.URLInputStreamResource
(URL url, int bufferSize) Create a new resource around the given URL. -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Close the resource's input stream and disconnect the URL connection.long
Get the size of the resource.boolean
Test for equality.boolean
exists()
Check whether the resource exists.protected void
finalize()
Make sure things are closed.Get a description of the resource.getFile()
Get a file object for the URL.Get the file name of the resource.Get the input stream to read the resource content.getURI()
Get the URI of the resource.getURL()
Get the URL of the resource.int
hashCode()
Get a hash code for this URLInputStreamResource.long
Get the last modified time of the resource.toString()
Print this resource in a human readable manner.Methods inherited from class org.springframework.core.io.AbstractResource
createRelative, getFileForLastModifiedCheck, isFile, isOpen, isReadable, readableChannel
-
Constructor Details
-
URLInputStreamResource
Create a new resource around the given URL.- Parameters:
url
- The URL of the resource.- Throws:
IOException
- if the resource cannot be accessed or the URL does not allow connection.
-
URLInputStreamResource
Create a new resource around the given URL.- Parameters:
url
- The URL of the resource.bufferSize
- The size of the buffer around the URL's input stream. If this is zero or less, no buffer will be put in place.- Throws:
IOException
- if the resource cannot be accessed or the URL does not allow connection.
-
-
Method Details
-
finalize
protected void finalize()Make sure things are closed. -
close
public void close()Close the resource's input stream and disconnect the URL connection. -
getFile
Get a file object for the URL.- Specified by:
getFile
in interfaceResource
- Overrides:
getFile
in classAbstractResource
- Returns:
- The file object for the resource if the URL was a local file resource, null if the URL is of any other type.
-
getFilename
Get the file name of the resource.- Specified by:
getFilename
in interfaceResource
- Overrides:
getFilename
in classAbstractResource
- Returns:
- The resource's file name.
-
exists
public boolean exists()Check whether the resource exists. For some protocols this can be done explicitly, but for others this test cannot take place and it is assumed the resource does exist.- Specified by:
exists
in interfaceResource
- Overrides:
exists
in classAbstractResource
- Returns:
- true if the resource exists, false if not.
-
getURL
Get the URL of the resource.- Specified by:
getURL
in interfaceResource
- Overrides:
getURL
in classAbstractResource
- Returns:
- The resource URL.
-
getURI
Get the URI of the resource.- Specified by:
getURI
in interfaceResource
- Overrides:
getURI
in classAbstractResource
- Returns:
- The resource URI.
-
getDescription
Get a description of the resource. For these types, this is the URL in string form.- Returns:
- The URL as a string.
-
getInputStream
Get the input stream to read the resource content. Client code should callclose()
to close this stream and associated resources, but if the stream is closed explicitly it should be fine as long as this object is not used any further.- Returns:
- An input stream.
-
contentLength
public long contentLength()Get the size of the resource.- Specified by:
contentLength
in interfaceResource
- Overrides:
contentLength
in classAbstractResource
- Returns:
- The size in bytes of the resource. Will return -1 if this cannot be determined.
-
lastModified
public long lastModified()Get the last modified time of the resource.- Specified by:
lastModified
in interfaceResource
- Overrides:
lastModified
in classAbstractResource
- Returns:
- The last modified time in milliseconds.
- See Also:
-
equals
Test for equality. Two URLInputStreamResource objects are considered equal if they point to the same resource.- Overrides:
equals
in classAbstractResource
- Parameters:
obj
- The object to test against.- Returns:
- true if obj is another URLInputStreamResource and both it and this have the same URL.
-
hashCode
public int hashCode()Get a hash code for this URLInputStreamResource.- Overrides:
hashCode
in classAbstractResource
- Returns:
- The hash code.
-
toString
Print this resource in a human readable manner.- Overrides:
toString
in classAbstractResource
- Returns:
- The class name and the URL.
-