當前位置: 首頁>>代碼示例>>Java>>正文


Java ResourceUtils.isJarURL方法代碼示例

本文整理匯總了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);
}
 
開發者ID:apache,項目名稱:incubator-servicecomb-java-chassis,代碼行數:21,代碼來源:AbstractConfigLoader.java

示例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();
}
 
開發者ID:ulisesbocchio,項目名稱:spring-boot-jar-resources,代碼行數:17,代碼來源:JarResource.java

示例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);
}
 
開發者ID:Alfresco,項目名稱:alfresco-repository,代碼行數:38,代碼來源:AbstractContentTransformerTest.java

示例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);
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:41,代碼來源:PersistenceUnitReader.java

示例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();
	}
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:19,代碼來源:AbstractFileResolvingResource.java

示例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();
	}
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:15,代碼來源:AbstractFileResolvingResource.java

示例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;
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:50,代碼來源:DefaultPersistenceUnitManager.java

示例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;
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:54,代碼來源:DefaultPersistenceUnitManager.java

示例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();
}
 
開發者ID:ulisesbocchio,項目名稱:spring-boot-jar-resources,代碼行數:5,代碼來源:JarUtils.java

示例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());
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:15,代碼來源:PathMatchingResourcePatternResolver.java


注:本文中的org.springframework.util.ResourceUtils.isJarURL方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。