本文整理匯總了Java中org.springframework.util.ResourceUtils.isJarURL方法的典型用法代碼示例。如果您正苦於以下問題:Java ResourceUtils.isJarURL方法的具體用法?Java ResourceUtils.isJarURL怎麽用?Java ResourceUtils.isJarURL使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.springframework.util.ResourceUtils
的用法示例。
在下文中一共展示了ResourceUtils.isJarURL方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: doSort
import org.springframework.util.ResourceUtils; //導入方法依賴的package包/類
private int doSort(ConfigModelWrapper w1, ConfigModelWrapper w2) {
ConfigModel m1 = w1.model;
ConfigModel m2 = w2.model;
boolean isM1Jar = ResourceUtils.isJarURL(m1.getUrl());
boolean isM2Jar = ResourceUtils.isJarURL(m2.getUrl());
if (isM1Jar != isM2Jar) {
if (isM1Jar) {
return -1;
}
return 1;
}
// min order load first
int result = Integer.compare(m1.getOrder(), m2.getOrder());
if (result != 0) {
return result;
}
return doFinalSort(w1, w2);
}
示例2: getFile
import org.springframework.util.ResourceUtils; //導入方法依賴的package包/類
@Override
public File getFile() throws IOException {
URL resourceUrl = getURL();
if(ResourceUtils.isJarURL(resourceUrl)) {
File tempFile = FILE_REGISTRY.get(resourceUrl);
if(tempFile == null || !tempFile.exists()) {
log.debug("Extracting File for URL: {}", resourceUrl);
tempFile = JarUtils.getFile(delegate, extractPath);
FILE_REGISTRY.put(resourceUrl, tempFile);
} else {
log.debug("File found in registry for URL: {}", resourceUrl);
}
return new File(tempFile.toURI());
}
return delegate.getFile();
}
示例3: loadNamedQuickTestFile
import org.springframework.util.ResourceUtils; //導入方法依賴的package包/類
/**
* Helper method to load one of the "The quick brown fox" files from the
* classpath.
*
* @param quickname file required, eg <b>quick.txt</b>
* @return Returns a test resource loaded from the classpath or <tt>null</tt> if
* no resource could be found.
* @throws IOException
*/
public static File loadNamedQuickTestFile(String quickname) throws IOException
{
String quickNameAndPath = "quick/" + quickname;
URL url = AbstractContentTransformerTest.class.getClassLoader().getResource(quickNameAndPath);
if (url == null)
{
return null;
}
if (ResourceUtils.isJarURL(url))
{
if (logger.isDebugEnabled())
{
logger.debug("Using a temp file for quick resource that's in a jar." + quickNameAndPath);
}
try
{
InputStream is = AbstractContentTransformerTest.class.getClassLoader().getResourceAsStream(quickNameAndPath);
File tempFile = TempFileProvider.createTempFile(is, quickname, ".tmp");
return tempFile;
}
catch (Exception error)
{
logger.error("Failed to load a quick file from a jar. "+error);
return null;
}
}
return ResourceUtils.getFile(url);
}
示例4: determinePersistenceUnitRootUrl
import org.springframework.util.ResourceUtils; //導入方法依賴的package包/類
/**
* Determine the persistence unit root URL based on the given resource
* (which points to the {@code persistence.xml} file we're reading).
* @param resource the resource to check
* @return the corresponding persistence unit root URL
* @throws IOException if the checking failed
*/
protected URL determinePersistenceUnitRootUrl(Resource resource) throws IOException {
URL originalURL = resource.getURL();
// If we get an archive, simply return the jar URL (section 6.2 from the JPA spec)
if (ResourceUtils.isJarURL(originalURL)) {
return ResourceUtils.extractJarFileURL(originalURL);
}
// check META-INF folder
String urlToString = originalURL.toExternalForm();
if (!urlToString.contains(META_INF)) {
if (logger.isInfoEnabled()) {
logger.info(resource.getFilename() +
" should be located inside META-INF directory; cannot determine persistence unit root URL for " +
resource);
}
return null;
}
if (urlToString.lastIndexOf(META_INF) == urlToString.lastIndexOf('/') - (1 + META_INF.length())) {
if (logger.isInfoEnabled()) {
logger.info(resource.getFilename() +
" is not located in the root of META-INF directory; cannot determine persistence unit root URL for " +
resource);
}
return null;
}
String persistenceUnitRoot = urlToString.substring(0, urlToString.lastIndexOf(META_INF));
if (persistenceUnitRoot.endsWith("/")) {
persistenceUnitRoot = persistenceUnitRoot.substring(0, persistenceUnitRoot.length() - 1);
}
return new URL(persistenceUnitRoot);
}
示例5: getFileForLastModifiedCheck
import org.springframework.util.ResourceUtils; //導入方法依賴的package包/類
/**
* This implementation determines the underlying File
* (or jar file, in case of a resource in a jar/zip).
*/
@Override
protected File getFileForLastModifiedCheck() throws IOException {
URL url = getURL();
if (ResourceUtils.isJarURL(url)) {
URL actualUrl = ResourceUtils.extractArchiveURL(url);
if (actualUrl.getProtocol().startsWith(ResourceUtils.URL_PROTOCOL_VFS)) {
return VfsResourceDelegate.getResource(actualUrl).getFile();
}
return ResourceUtils.getFile(actualUrl, "Jar URL");
}
else {
return getFile();
}
}
示例6: lastModified
import org.springframework.util.ResourceUtils; //導入方法依賴的package包/類
@Override
public long lastModified() throws IOException {
URL url = getURL();
if (ResourceUtils.isFileURL(url) || ResourceUtils.isJarURL(url)) {
// Proceed with file system resolution...
return super.lastModified();
}
else {
// Try a URL connection last-modified header...
URLConnection con = url.openConnection();
customizeConnection(con);
return con.getLastModified();
}
}
示例7: buildDefaultPersistenceUnitInfo
import org.springframework.util.ResourceUtils; //導入方法依賴的package包/類
/**
* Perform Spring-based scanning for entity classes.
* @see #setPackagesToScan
*/
private SpringPersistenceUnitInfo buildDefaultPersistenceUnitInfo() {
SpringPersistenceUnitInfo scannedUnit = new SpringPersistenceUnitInfo();
scannedUnit.setPersistenceUnitName(this.defaultPersistenceUnitName);
scannedUnit.setExcludeUnlistedClasses(true);
if (this.packagesToScan != null) {
for (String pkg : this.packagesToScan) {
try {
String pattern = ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX +
ClassUtils.convertClassNameToResourcePath(pkg) + ENTITY_CLASS_RESOURCE_PATTERN;
Resource[] resources = this.resourcePatternResolver.getResources(pattern);
MetadataReaderFactory readerFactory = new CachingMetadataReaderFactory(this.resourcePatternResolver);
for (Resource resource : resources) {
if (resource.isReadable()) {
MetadataReader reader = readerFactory.getMetadataReader(resource);
String className = reader.getClassMetadata().getClassName();
if (matchesFilter(reader, readerFactory)) {
scannedUnit.addManagedClassName(className);
if (scannedUnit.getPersistenceUnitRootUrl() == null) {
URL url = resource.getURL();
if (ResourceUtils.isJarURL(url)) {
scannedUnit.setPersistenceUnitRootUrl(ResourceUtils.extractJarFileURL(url));
}
}
}
}
}
}
catch (IOException ex) {
throw new PersistenceException("Failed to scan classpath for unlisted entity classes", ex);
}
}
}
if (this.mappingResources != null) {
for (String mappingFileName : this.mappingResources) {
scannedUnit.addMappingFileName(mappingFileName);
}
}
else if (useOrmXmlForDefaultPersistenceUnit()) {
scannedUnit.addMappingFileName(DEFAULT_ORM_XML_RESOURCE);
}
return scannedUnit;
}
示例8: buildDefaultPersistenceUnitInfo
import org.springframework.util.ResourceUtils; //導入方法依賴的package包/類
/**
* Perform Spring-based scanning for entity classes.
* @see #setPackagesToScan
*/
private SpringPersistenceUnitInfo buildDefaultPersistenceUnitInfo() {
SpringPersistenceUnitInfo scannedUnit = new SpringPersistenceUnitInfo();
scannedUnit.setPersistenceUnitName(this.defaultPersistenceUnitName);
scannedUnit.setExcludeUnlistedClasses(true);
if (this.packagesToScan != null) {
for (String pkg : this.packagesToScan) {
try {
String pattern = ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX +
ClassUtils.convertClassNameToResourcePath(pkg) + CLASS_RESOURCE_PATTERN;
Resource[] resources = this.resourcePatternResolver.getResources(pattern);
MetadataReaderFactory readerFactory = new CachingMetadataReaderFactory(this.resourcePatternResolver);
for (Resource resource : resources) {
if (resource.isReadable()) {
MetadataReader reader = readerFactory.getMetadataReader(resource);
String className = reader.getClassMetadata().getClassName();
if (matchesFilter(reader, readerFactory)) {
scannedUnit.addManagedClassName(className);
if (scannedUnit.getPersistenceUnitRootUrl() == null) {
URL url = resource.getURL();
if (ResourceUtils.isJarURL(url)) {
scannedUnit.setPersistenceUnitRootUrl(ResourceUtils.extractJarFileURL(url));
}
}
}
else if (className.endsWith(PACKAGE_INFO_SUFFIX)) {
scannedUnit.addManagedPackage(
className.substring(0, className.length() - PACKAGE_INFO_SUFFIX.length()));
}
}
}
}
catch (IOException ex) {
throw new PersistenceException("Failed to scan classpath for unlisted entity classes", ex);
}
}
}
if (this.mappingResources != null) {
for (String mappingFileName : this.mappingResources) {
scannedUnit.addMappingFileName(mappingFileName);
}
}
else if (useOrmXmlForDefaultPersistenceUnit()) {
scannedUnit.addMappingFileName(DEFAULT_ORM_XML_RESOURCE);
}
return scannedUnit;
}
示例9: getFile
import org.springframework.util.ResourceUtils; //導入方法依賴的package包/類
@SneakyThrows
public static File getFile(Resource resource, String extractPath) {
return ResourceUtils.isJarURL(resource.getURL()) ? getFromJar(resource, extractPath) : resource.getFile();
}
示例10: isJarResource
import org.springframework.util.ResourceUtils; //導入方法依賴的package包/類
/**
* Return whether the given resource handle indicates a jar resource
* that the {@code doFindPathMatchingJarResources} method can handle.
* <p>The default implementation checks against the URL protocols
* "jar", "zip" and "wsjar" (the latter are used by BEA WebLogic Server
* and IBM WebSphere, respectively, but can be treated like jar files).
* @param resource the resource handle to check
* (usually the root directory to start path matching from)
* @see #doFindPathMatchingJarResources
* @see org.springframework.util.ResourceUtils#isJarURL
*/
protected boolean isJarResource(Resource resource) throws IOException {
return ResourceUtils.isJarURL(resource.getURL());
}