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


Java Resource.getFilename方法代碼示例

本文整理匯總了Java中org.springframework.core.io.Resource.getFilename方法的典型用法代碼示例。如果您正苦於以下問題:Java Resource.getFilename方法的具體用法?Java Resource.getFilename怎麽用?Java Resource.getFilename使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.springframework.core.io.Resource的用法示例。


在下文中一共展示了Resource.getFilename方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: loadQuery

import org.springframework.core.io.Resource; //導入方法依賴的package包/類
/**
 * Load a SQL query from a file on the classpath.
 * @param resource   The query file resource
 * @return The query
 */
private String loadQuery(Resource resource) {
    try (BufferedReader reader = new BufferedReader(new InputStreamReader(resource.getInputStream()))) {

        StringBuilder builder = new StringBuilder();
        String line;
        while ((line = reader.readLine()) != null) {
            builder.append(line).append("\n");
        }
        return builder.toString();

    } catch (IOException ex) {
        String message = "Error reading query in " + resource.getFilename();
        logger.error(message, ex);
        throw new IllegalArgumentException(message, ex);
    }
}
 
開發者ID:dvsa,項目名稱:mot-automated-testsuite,代碼行數:22,代碼來源:QueryFileLoader.java

示例2: loadContent

import org.springframework.core.io.Resource; //導入方法依賴的package包/類
private Map<String, String> loadContent() throws IOException
{
    ClassPathStoreResourceResolver resourceResolver = new ClassPathStoreResourceResolver(applicationContext);
    Resource[] contentResources = resourceResolver.getResources("classpath*:" + configPath + packageName + "/*.*");
    Map<String, String> content = new HashMap<String, String>();
    for (Resource contentResource : contentResources)
    {
        String fileName = contentResource.getFilename();
        // ignore hidden directories / files
        if (fileName.startsWith("."))
        {
            continue;
        }
        String key = packageName + "/" + fileName;
        String value = convert(contentResource.getInputStream());
        content.put(key, value);
    }
    return content;
}
 
開發者ID:Alfresco,項目名稱:alfresco-remote-api,代碼行數:20,代碼來源:SiteSurfConfig.java

示例3: transform

import org.springframework.core.io.Resource; //導入方法依賴的package包/類
@Override
public Resource transform(HttpServletRequest request, Resource resource, ResourceTransformerChain transformerChain) throws IOException {
    resource = transformerChain.transform(request, resource);

    final String fileName = resource.getFilename();
    final String fileExt = FilenameUtils.getExtension(fileName);
    switch (fileExt) {
        case "js":
        case "json":
        case "css":
        case "html":
            log.trace("format {} supported for Text-Injection", fileExt);
            return transformText(fileName, resource);
        default:
            log.trace("unsupported Resource-Type: {}", fileExt);
            return resource;
    }
}
 
開發者ID:redlink-gmbh,項目名稱:smarti,代碼行數:19,代碼來源:PropertyInjectionTransformer.java

示例4: getDefaultContentType

import org.springframework.core.io.Resource; //導入方法依賴的package包/類
@Override
protected MediaType getDefaultContentType(Resource resource) {
    MediaType contentType = null;
    if (resource instanceof WxMediaResource) {
        contentType = ((WxMediaResource) resource).getContentType();
    }
    if (contentType == null && servletContext != null && resource.getFilename() != null) {
        String mimeType = servletContext.getMimeType(resource.getFilename());
        if (StringUtils.hasText(mimeType)) {
            contentType = MediaType.parseMediaType(mimeType);
        }
    }
    if (contentType != null) {
        return contentType;
    }
    return super.getDefaultContentType(resource);
}
 
開發者ID:FastBootWeixin,項目名稱:FastBootWeixin,代碼行數:18,代碼來源:WxMediaResourceMessageConverter.java

示例5: storeTempMediaToFile

import org.springframework.core.io.Resource; //導入方法依賴的package包/類
/**
 * 保存tempMedia到File
 *
 * @param mediaId
 * @return File
 */
public File storeTempMediaToFile(String mediaId, Resource resource) throws IOException {
    WxMediaResource wxMediaResource = (WxMediaResource) resource;
    if (wxMediaResource.isUrlMedia()) {
        return null;
    }
    String fileName = resource.getFilename();
    if (fileName == null) {
        fileName = mediaId;
    }
    File file = new File(StringUtils.applyRelativePath(defaultTempFilePath, fileName));
    if (file.exists()) {
        return file;
    }
    StoreEntity storeEntity = storeFile(file, mediaId, resource);
    tempMediaFileDb.put(file.getAbsolutePath(), storeEntity);
    tempMediaIdDb.put(mediaId, file.getAbsolutePath());
    db.commit();
    return file;
}
 
開發者ID:FastBootWeixin,項目名稱:FastBootWeixin,代碼行數:26,代碼來源:WxMediaStore.java

示例6: storeMediaToFile

import org.springframework.core.io.Resource; //導入方法依賴的package包/類
/**
 * 保存media到File
 *
 * @param mediaId
 * @return File
 */
public File storeMediaToFile(String mediaId, Resource resource) throws IOException {
    String fileName = resource.getFilename();
    if (fileName == null) {
        fileName = mediaId;
    }
    File file = new File(StringUtils.applyRelativePath(defaultFilePath, fileName));
    if (file.exists()) {
        return file;
    }
    StoreEntity storeEntity = storeFile(file, mediaId, resource);
    mediaFileDb.put(file.getAbsolutePath(), storeEntity);
    mediaIdDb.put(mediaId, file.getAbsolutePath());
    db.commit();
    return file;
}
 
開發者ID:FastBootWeixin,項目名稱:FastBootWeixin,代碼行數:22,代碼來源:WxMediaStore.java

示例7: init

import org.springframework.core.io.Resource; //導入方法依賴的package包/類
@PostConstruct
public void init() throws Exception {
    File dir = new File(baseDir + "/1/avatar");

    if (dir.exists()) {
        return;
    }

    dir.mkdirs();

    Resource[] resources = applicationContext
            .getResources("classpath:/avatar/*");

    if (resources == null) {
        logger.info("cannot find default avatar for user.");

        return;
    }

    for (Resource resource : resources) {
        File file = new File(dir, resource.getFilename());
        FileOutputStream fos = new FileOutputStream(file);

        try {
            FileCopyUtils.copy(resource.getInputStream(), fos);
            fos.flush();
        } finally {
            fos.close();
        }
    }
}
 
開發者ID:zhaojunfei,項目名稱:lemon,代碼行數:32,代碼來源:AvatarInitiator.java

示例8: init

import org.springframework.core.io.Resource; //導入方法依賴的package包/類
@PostConstruct
public void init() throws Exception {
    File dir = new File(baseDir + "/cms/template/default");

    if (dir.exists()) {
        return;
    }

    dir.mkdirs();

    Resource[] resources = applicationContext
            .getResources("classpath:/cms/template/default/*");

    if (resources == null) {
        logger.info("cannot find default template for cms.");

        return;
    }

    for (Resource resource : resources) {
        File file = new File(dir, resource.getFilename());
        FileOutputStream fos = new FileOutputStream(file);

        try {
            FileCopyUtils.copy(resource.getInputStream(), fos);
            fos.flush();
        } finally {
            fos.close();
        }
    }
}
 
開發者ID:zhaojunfei,項目名稱:lemon,代碼行數:32,代碼來源:TemplateInitiator.java

示例9: importBeans

import org.springframework.core.io.Resource; //導入方法依賴的package包/類
/**
 * Import Spring bean definitions from either XML or Groovy sources into the
 * current bean builder instance.
 * @param resourcePattern the resource pattern
 */
public void importBeans(String resourcePattern) throws IOException {
	Resource[] resources =
			ResourcePatternUtils.getResourcePatternResolver(getResourceLoader()).getResources(resourcePattern);
	for (Resource resource : resources) {
		String filename = resource.getFilename();
		if (filename.endsWith(".groovy")) {
			loadBeanDefinitions(resource);
		}
		else if (filename.endsWith(".xml")) {
			this.xmlBeanDefinitionReader.loadBeanDefinitions(resource);
		}
	}
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:19,代碼來源:GroovyBeanDefinitionReader.java

示例10: getFilename

import org.springframework.core.io.Resource; //導入方法依賴的package包/類
/**
 * Return the filename of the given multipart part. This value will be used for the
 * {@code Content-Disposition} header.
 * <p>The default implementation returns {@link Resource#getFilename()} if the part is a
 * {@code Resource}, and {@code null} in other cases. Can be overridden in subclasses.
 * @param part the part to determine the file name for
 * @return the filename, or {@code null} if not known
 */
protected String getFilename(Object part) {
	if (part instanceof Resource) {
		Resource resource = (Resource) part;
		return resource.getFilename();
	}
	else {
		return null;
	}
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:18,代碼來源:FormHttpMessageConverter.java

示例11: getMediaType

import org.springframework.core.io.Resource; //導入方法依賴的package包/類
public static MediaType getMediaType(Resource resource) {
	if(resource.getFilename() == null) {
		return null;
	}
	String mediaType = fileTypeMap.getContentType(resource.getFilename());
	return (StringUtils.hasText(mediaType) ? MediaType.parseMediaType(mediaType) : null);
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:8,代碼來源:ResourceHttpMessageConverter.java

示例12: resolveUrlPath

import org.springframework.core.io.Resource; //導入方法依賴的package包/類
@Override
public String resolveUrlPath(String resourcePath, List<? extends Resource> locations, ResourceResolverChain chain) {
  Resource resolvedResource = resolve(resourcePath, locations);
  if (resolvedResource == null) {
    return null;
  }
  try {
    return resolvedResource.getURL().toString();
  } catch (IOException e) {
    return resolvedResource.getFilename();
  }
}
 
開發者ID:2DV603NordVisaProject,項目名稱:nordvisa_calendar,代碼行數:13,代碼來源:AppConfig.java

示例13: openZipResource

import org.springframework.core.io.Resource; //導入方法依賴的package包/類
/**
 * Open the given resource as a a ZipInputStream.
 * @param resource resource
 * @return ZipInputStream
 */
protected ZipInputStream openZipResource(Resource resource) {
  try {
    return new ZipInputStream(new BufferedInputStream(resource.getInputStream()));
  } catch (IOException e) {
    throw new IllegalMigrationStateException("Could not deploy zip resource for version tag " + resource.getFilename(), e);
  }
}
 
開發者ID:satspeedy,項目名稱:camunda-migrator,代碼行數:13,代碼來源:ZipResourceService.java

示例14: getResourceFileCopy

import org.springframework.core.io.Resource; //導入方法依賴的package包/類
protected File getResourceFileCopy(String resourcePath) throws IOException {
    Resource resource = context.getResource(resourcePath);
    final File tmp = new File(fileManager.getTempDir(), resource.getFilename());
    FileUtils.copyFile(resource.getFile(), tmp);
    FileUtils.forceDeleteOnExit(tmp);
    return tmp;
}
 
開發者ID:react-dev26,項目名稱:NGB-master,代碼行數:8,代碼來源:AbstractJUnitTest.java

示例15: resourcePath

import org.springframework.core.io.Resource; //導入方法依賴的package包/類
public static String resourcePath(Resource resource) {
    URI uri = null;
    try {
        uri = resource.getURI();
    } catch (IOException e) {
        return resource.getFilename();
    }
    String path = uri.getPath();
    if (File.pathSeparator == "/") {
        return path;
    } else {
        return path.substring(1);
    }
}
 
開發者ID:FastBootWeixin,項目名稱:FastBootWeixin,代碼行數:15,代碼來源:WxMediaUtils.java


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