本文整理匯總了Java中org.springframework.util.ResourceUtils類的典型用法代碼示例。如果您正苦於以下問題:Java ResourceUtils類的具體用法?Java ResourceUtils怎麽用?Java ResourceUtils使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
ResourceUtils類屬於org.springframework.util包,在下文中一共展示了ResourceUtils類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: createGoogleAppsPublicKey
import org.springframework.util.ResourceUtils; //導入依賴的package包/類
/**
* Create the public key.
*
* @throws Exception if key creation ran into an error
*/
protected void createGoogleAppsPublicKey() throws Exception {
if (!isValidConfiguration()) {
LOGGER.debug("Google Apps public key bean will not be created, because it's not configured");
return;
}
final PublicKeyFactoryBean bean = new PublicKeyFactoryBean();
if (this.publicKeyLocation.startsWith(ResourceUtils.CLASSPATH_URL_PREFIX)) {
bean.setLocation(new ClassPathResource(StringUtils.removeStart(this.publicKeyLocation, ResourceUtils.CLASSPATH_URL_PREFIX)));
} else if (this.publicKeyLocation.startsWith(ResourceUtils.FILE_URL_PREFIX)) {
bean.setLocation(new FileSystemResource(StringUtils.removeStart(this.publicKeyLocation, ResourceUtils.FILE_URL_PREFIX)));
} else {
bean.setLocation(new FileSystemResource(this.publicKeyLocation));
}
bean.setAlgorithm(this.keyAlgorithm);
LOGGER.debug("Loading Google Apps public key from [{}] with key algorithm [{}]",
bean.getResource(), bean.getAlgorithm());
bean.afterPropertiesSet();
LOGGER.debug("Creating Google Apps public key instance via [{}]", this.publicKeyLocation);
this.publicKey = bean.getObject();
}
示例2: createGoogleAppsPrivateKey
import org.springframework.util.ResourceUtils; //導入依賴的package包/類
/**
* Create the private key.
*
* @throws Exception if key creation ran into an error
*/
protected void createGoogleAppsPrivateKey() throws Exception {
if (!isValidConfiguration()) {
LOGGER.debug("Google Apps private key bean will not be created, because it's not configured");
return;
}
final PrivateKeyFactoryBean bean = new PrivateKeyFactoryBean();
if (this.privateKeyLocation.startsWith(ResourceUtils.CLASSPATH_URL_PREFIX)) {
bean.setLocation(new ClassPathResource(StringUtils.removeStart(this.privateKeyLocation, ResourceUtils.CLASSPATH_URL_PREFIX)));
} else if (this.privateKeyLocation.startsWith(ResourceUtils.FILE_URL_PREFIX)) {
bean.setLocation(new FileSystemResource(StringUtils.removeStart(this.privateKeyLocation, ResourceUtils.FILE_URL_PREFIX)));
} else {
bean.setLocation(new FileSystemResource(this.privateKeyLocation));
}
bean.setAlgorithm(this.keyAlgorithm);
LOGGER.debug("Loading Google Apps private key from [{}] with key algorithm [{}]",
bean.getLocation(), bean.getAlgorithm());
bean.afterPropertiesSet();
LOGGER.debug("Creating Google Apps private key instance via [{}]", this.privateKeyLocation);
this.privateKey = bean.getObject();
}
示例3: configureSslTrustStore
import org.springframework.util.ResourceUtils; //導入依賴的package包/類
private void configureSslTrustStore(SslContextFactory factory, Ssl ssl) {
if (ssl.getTrustStorePassword() != null) {
factory.setTrustStorePassword(ssl.getTrustStorePassword());
}
if (ssl.getTrustStore() != null) {
try {
URL url = ResourceUtils.getURL(ssl.getTrustStore());
factory.setTrustStoreResource(Resource.newResource(url));
}
catch (IOException ex) {
throw new EmbeddedServletContainerException(
"Could not find trust store '" + ssl.getTrustStore() + "'", ex);
}
}
if (ssl.getTrustStoreType() != null) {
factory.setTrustStoreType(ssl.getTrustStoreType());
}
if (ssl.getTrustStoreProvider() != null) {
factory.setTrustStoreProvider(ssl.getTrustStoreProvider());
}
}
開發者ID:vikrammane23,項目名稱:https-github.com-g0t4-jenkins2-course-spring-boot,代碼行數:22,代碼來源:JettyEmbeddedServletContainerFactory.java
示例4: configureSslKeyStore
import org.springframework.util.ResourceUtils; //導入依賴的package包/類
private void configureSslKeyStore(SslContextFactory factory, Ssl ssl) {
try {
URL url = ResourceUtils.getURL(ssl.getKeyStore());
factory.setKeyStoreResource(Resource.newResource(url));
}
catch (IOException ex) {
throw new EmbeddedServletContainerException(
"Could not find key store '" + ssl.getKeyStore() + "'", ex);
}
if (ssl.getKeyStoreType() != null) {
factory.setKeyStoreType(ssl.getKeyStoreType());
}
if (ssl.getKeyStoreProvider() != null) {
factory.setKeyStoreProvider(ssl.getKeyStoreProvider());
}
}
示例5: 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);
}
示例6: createInstance
import org.springframework.util.ResourceUtils; //導入依賴的package包/類
@Override
public PublicKey createInstance() throws Exception {
try {
final PublicKeyFactoryBean factory = this.publicKeyFactoryBeanClass.newInstance();
if (this.location.startsWith(ResourceUtils.CLASSPATH_URL_PREFIX)) {
factory.setLocation(new ClassPathResource(StringUtils.removeStart(this.location, ResourceUtils.CLASSPATH_URL_PREFIX)));
} else {
factory.setLocation(new FileSystemResource(this.location));
}
factory.setAlgorithm(this.algorithm);
factory.setSingleton(false);
return factory.getObject();
} catch (final Exception e) {
LOGGER.warn(e.getMessage(), e);
throw Throwables.propagate(e);
}
}
示例7: getDataList
import org.springframework.util.ResourceUtils; //導入依賴的package包/類
/**
* 文件列表
* @author eko.zhan at 2017年8月9日 下午8:32:19
* @return
* @throws FileNotFoundException
*/
@ApiOperation(value="獲取文件數據列表", notes="獲取固定路徑下的文件,並返回文件名,文件所在路徑和文件大小")
@RequestMapping(value="getDataList", method=RequestMethod.POST)
public JSONArray getDataList() throws FileNotFoundException{
JSONArray arr = new JSONArray();
File dir = ResourceUtils.getFile("classpath:static/DATAS");
File[] files = dir.listFiles();
for (File file : files){
if (file.isFile()){
JSONObject json = new JSONObject();
json.put("path", file.getPath());
json.put("name", file.getName());
json.put("size", file.length());
arr.add(json);
}
}
return arr;
}
示例8: test1
import org.springframework.util.ResourceUtils; //導入依賴的package包/類
@Test
public void test1() throws FileNotFoundException
{
final File sourceFolder = ResourceUtils.getFile("classpath:bulkimport");
final StripingFilesystemTracker tracker = new StripingFilesystemTracker(directoryAnalyser, new NodeRef("workspace", "SpacesStore", "123"), sourceFolder, Integer.MAX_VALUE);
List<ImportableItem> items = tracker.getImportableItems(Integer.MAX_VALUE);
assertEquals("", 11, items.size());
tracker.incrementLevel();
items = tracker.getImportableItems(Integer.MAX_VALUE);
assertEquals("", 2, items.size());
tracker.incrementLevel();
items = tracker.getImportableItems(Integer.MAX_VALUE);
assertEquals("", 31, items.size());
}
示例9: setUp
import org.springframework.util.ResourceUtils; //導入依賴的package包/類
@SuppressWarnings("deprecation")
@Override
public void setUp() throws Exception
{
auditModelRegistry = (AuditModelRegistryImpl) ctx.getBean("auditModel.modelRegistry");
serviceRegistry = (ServiceRegistry) ctx.getBean(ServiceRegistry.SERVICE_REGISTRY);
auditComponent = (AuditComponent) ctx.getBean("auditComponent");
auditService = serviceRegistry.getAuditService();
transactionService = serviceRegistry.getTransactionService();
transactionServiceImpl = (TransactionServiceImpl) ctx.getBean("transactionService");
nodeService = serviceRegistry.getNodeService();
searchService = serviceRegistry.getSearchService();
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getSystemUserName());
nodeRef = nodeService.getRootNode(StoreRef.STORE_REF_WORKSPACE_SPACESSTORE);
// Register the models
URL modelUrlMnt11072 = ResourceUtils.getURL("classpath:alfresco/testaudit/alfresco-audit-test-mnt-11072.xml");
URL modelUrlMnt16748 = ResourceUtils.getURL("classpath:alfresco/testaudit/alfresco-audit-test-mnt-16748.xml");
auditModelRegistry.registerModel(modelUrlMnt11072);
auditModelRegistry.registerModel(modelUrlMnt16748);
auditModelRegistry.loadAuditModels();
}
示例10: editUserExtend
import org.springframework.util.ResourceUtils; //導入依賴的package包/類
public String editUserExtend(PersonalInfoPersonalOriented userExtend, String lastImgPath, File newFileName) throws Exception {
String tarImg = lastImgPath;
//傳的文件出現變化則更新文件信息
if (!lastImgPath.equals(newFileName.getPath())) {
File lastImg = ResourceUtils.getFile(StaticVar.getToFilePath() + lastImgPath);
//FileUtils.forceDelete(lastImg);
tarImg = "UserSpace" + "/" + userExtend.getUUuid() + "/" + newFileName.getName();
File newImg = ResourceUtils.getFile(StaticVar.getToFilePath() + tarImg);
FileUtils.writeByteArrayToFile(newImg, userExtend.getUImgObj().getBytes("ISO-8859-1"));
}
userExtend.setUHeadImg(tarImg);
registDao.editUserExtend(userExtend);
return tarImg;
}
示例11: getFile
import org.springframework.util.ResourceUtils; //導入依賴的package包/類
/**
* Returns a <code>File</code> handle for this resource. This method does a
* best-effort attempt to locate the bundle resource on the file system. It
* is strongly recommended to use {@link #getInputStream()} method instead
* which works no matter if the bundles are saved (in exploded form or not)
* on the file system.
*
* @return File handle to this resource
* @throws IOException if the resource cannot be resolved as absolute file
* path, i.e. if the resource is not available in a file system
*/
public File getFile() throws IOException {
// locate the file inside the bundle only known prefixes
if (searchType != OsgiResourceUtils.PREFIX_TYPE_UNKNOWN) {
String bundleLocation = bundle.getLocation();
int prefixIndex = bundleLocation.indexOf(ResourceUtils.FILE_URL_PREFIX);
if (prefixIndex > -1) {
bundleLocation = bundleLocation.substring(prefixIndex + ResourceUtils.FILE_URL_PREFIX.length());
}
File file = new File(bundleLocation, path);
if (file.exists()) {
return file;
}
// fall back to the URL discovery (just in case)
}
try {
return ResourceUtils.getFile(getURI(), getDescription());
}
catch (IOException ioe) {
throw (IOException) new FileNotFoundException(getDescription()
+ " cannot be resolved to absolute file path").initCause(ioe);
}
}
示例12: getReader
import org.springframework.util.ResourceUtils; //導入依賴的package包/類
@Override
public Reader getReader(Engine engine, String fileName, Charset charset) throws IOException {
File file;
try {
file = ResourceUtils.getFile(fileName);
} catch (FileNotFoundException e) {
Reader reader = defaultKnowledgeBaseFileProvider.getReader(engine, fileName, charset);
if (reader == null) {
logger.warn("getReader", e);
}
return reader;
}
if (!file.exists()) {
return null;
}
return new InputStreamReader(new FileInputStream(file), charset);
}
示例13: doInternal
import org.springframework.util.ResourceUtils; //導入依賴的package包/類
@Override
public boolean doInternal(MessageReceivedEvent message, BotContext context, String query) throws DiscordException {
if (!message.getMessage().getAttachments().isEmpty()) {
query = message.getMessage().getAttachments().get(0).getUrl();
}
List<String> results = (List<String>) context.getAttribute(ATTR_SEARCH_RESULTS);
if (StringUtils.isNumeric(query) && CollectionUtils.isNotEmpty(results)) {
int index = Integer.parseInt(query) - 1;
query = getChoiceUrl(context, index);
if (query == null) {
messageManager.onQueueError(message.getChannel(), "discord.command.audio.play.select", results.size());
return fail(message);
}
}
message.getTextChannel().sendTyping().queue();
if (!ResourceUtils.isUrl(query)) {
String result = youTubeService.searchForUrl(query);
query = result != null ? result : query;
}
loadAndPlay(message.getTextChannel(), context, message.getMember(), query);
return true;
}
示例14: setup
import org.springframework.util.ResourceUtils; //導入依賴的package包/類
@Before
public void setup() throws Exception
{
super.setup();
permissionService = applicationContext.getBean("permissionService", PermissionService.class);
authorityService = (AuthorityService) applicationContext.getBean("AuthorityService");
auditService = applicationContext.getBean("AuditService", AuditService.class);
AuditModelRegistryImpl auditModelRegistry = (AuditModelRegistryImpl) applicationContext.getBean("auditModel.modelRegistry");
// Register the test model
URL testModelUrl = ResourceUtils.getURL("classpath:alfresco/audit/alfresco-audit-access.xml");
auditModelRegistry.registerModel(testModelUrl);
auditModelRegistry.loadAuditModels();
}
示例15: configureSslKeyStore
import org.springframework.util.ResourceUtils; //導入依賴的package包/類
private void configureSslKeyStore(SslContextFactory factory, Ssl ssl) {
try {
URL url = ResourceUtils.getURL(ssl.getKeyStore());
factory.setKeyStoreResource(Resource.newResource(url));
} catch (IOException ex) {
throw new WebServerException(
"Could not find key store '" + ssl.getKeyStore() + "'", ex);
}
if (ssl.getKeyStoreType() != null) {
factory.setKeyStoreType(ssl.getKeyStoreType());
}
if (ssl.getKeyStoreProvider() != null) {
factory.setKeyStoreProvider(ssl.getKeyStoreProvider());
}
}