Class AbstractFileResolvingResource
java.lang.Object
nl.basjes.parse.useragent.utils.springframework.core.io.AbstractResource
nl.basjes.parse.useragent.utils.springframework.core.io.AbstractFileResolvingResource
- All Implemented Interfaces:
InputStreamSource,Resource
- Direct Known Subclasses:
ClassPathResource,UrlResource
Abstract base class for resources which resolve URLs into File references,
such as {link UrlResource} or {link ClassPathResource}.
Detects the "file" protocol as well as the JBoss "vfs" protocol in URLs, resolving file system references accordingly.
- Since:
- 3.0
- Author:
- Juergen Hoeller
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionlongThis method reads the entire InputStream to determine the content length.protected voidcustomizeConnection(HttpURLConnection ignoredCon) Customize the given {link HttpURLConnection} before fetching the resource.protected voidCustomize the given {link URLConnection} before fetching the resource.booleanexists()This implementation checks whether a File can be opened, falling back to whether an InputStream can be opened.getFile()This implementation returns a File reference for the underlying class path resource, provided that it refers to a file in the file system.protected FileThis implementation returns a File reference for the given URI-identified resource, provided that it refers to a file in the file system.booleanisFile()This implementation always returnsfalse.protected booleanDetermine whether the given {link URI} represents a file in a file system.Methods inherited from class nl.basjes.parse.useragent.utils.springframework.core.io.AbstractResource
createRelative, equals, getFilename, getURI, getURL, hashCode, isOpen, toStringMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface nl.basjes.parse.useragent.utils.springframework.core.io.InputStreamSource
getInputStreamMethods inherited from interface nl.basjes.parse.useragent.utils.springframework.core.io.Resource
getDescription
-
Constructor Details
-
AbstractFileResolvingResource
public AbstractFileResolvingResource()
-
-
Method Details
-
exists
public boolean exists()Description copied from class:AbstractResourceThis implementation checks whether a File can be opened, falling back to whether an InputStream can be opened.This will cover both directories and content resources.
- Specified by:
existsin interfaceResource- Overrides:
existsin classAbstractResource
-
isFile
public boolean isFile()Description copied from class:AbstractResourceThis implementation always returnsfalse.- Specified by:
isFilein interfaceResource- Overrides:
isFilein classAbstractResource
-
getFile
This implementation returns a File reference for the underlying class path resource, provided that it refers to a file in the file system. see org.springframework.util.ResourceUtils#getFile(java.net.URL, String)- Specified by:
getFilein interfaceResource- Overrides:
getFilein classAbstractResource- Throws:
IOException- in case of general resolution/reading failures see #getInputStream()
-
isFile
Determine whether the given {link URI} represents a file in a file system.- Since:
- 5.0 see #getFile(URI)
-
getFile
This implementation returns a File reference for the given URI-identified resource, provided that it refers to a file in the file system. see org.springframework.util.ResourceUtils#getFile(java.net.URI, String)- Throws:
IOException
-
contentLength
Description copied from class:AbstractResourceThis method reads the entire InputStream to determine the content length.For a custom subclass of
InputStreamResource, we strongly recommend overriding this method with a more optimal implementation, e.g. checking File length, or possibly simply returning -1 if the stream can only be read once. see #getInputStream()- Specified by:
contentLengthin interfaceResource- Overrides:
contentLengthin classAbstractResource- Throws:
IOException- if the resource cannot be resolved (in the file system or as some other known physical resource type)
-
customizeConnection
Customize the given {link URLConnection} before fetching the resource.Calls {link ResourceUtils#useCachesIfNecessary(URLConnection)} and delegates to {link #customizeConnection(HttpURLConnection)} if possible. Can be overridden in subclasses.
- Parameters:
con- the URLConnection to customize- Throws:
IOException- if thrown from URLConnection methods
-
customizeConnection
Customize the given {link HttpURLConnection} before fetching the resource.Can be overridden in subclasses for configuring request headers and timeouts.
- Parameters:
ignoredCon- the HttpURLConnection to customize- Throws:
IOException- if thrown from HttpURLConnection methods
-