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
ConstructorsConstructorDescriptionCreate a new resource around the given URL.URLInputStreamResource(URL url, int bufferSize) Create a new resource around the given URL. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Close the resource's input stream and disconnect the URL connection.longGet the size of the resource.booleanTest for equality.booleanexists()Check whether the resource exists.protected voidfinalize()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.inthashCode()Get a hash code for this URLInputStreamResource.longGet 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:
getFilein interfaceResource- Overrides:
getFilein 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:
getFilenamein interfaceResource- Overrides:
getFilenamein 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:
existsin interfaceResource- Overrides:
existsin classAbstractResource- Returns:
- true if the resource exists, false if not.
-
getURL
Get the URL of the resource.- Specified by:
getURLin interfaceResource- Overrides:
getURLin classAbstractResource- Returns:
- The resource URL.
-
getURI
Get the URI of the resource.- Specified by:
getURIin interfaceResource- Overrides:
getURIin 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:
contentLengthin interfaceResource- Overrides:
contentLengthin 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:
lastModifiedin interfaceResource- Overrides:
lastModifiedin 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:
equalsin 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:
hashCodein classAbstractResource- Returns:
- The hash code.
-
toString
Print this resource in a human readable manner.- Overrides:
toStringin classAbstractResource- Returns:
- The class name and the URL.
-