本文整理匯總了Java中org.springframework.util.StringUtils.applyRelativePath方法的典型用法代碼示例。如果您正苦於以下問題:Java StringUtils.applyRelativePath方法的具體用法?Java StringUtils.applyRelativePath怎麽用?Java StringUtils.applyRelativePath使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.springframework.util.StringUtils
的用法示例。
在下文中一共展示了StringUtils.applyRelativePath方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: storeResource
import org.springframework.util.StringUtils; //導入方法依賴的package包/類
/**
* 保存Resource到持久化,這個實現中是文件
*
* @param mediaEntity
* @return File
*/
@Override
public Resource storeResource(MediaEntity mediaEntity) throws IOException {
if (!(mediaEntity.getResource() instanceof WxMediaResource)) {
return null;
}
WxMediaResource wxMediaResource = (WxMediaResource) mediaEntity.getResource();
if (wxMediaResource.isUrlMedia()) {
return null;
}
String fileName = wxMediaResource.getFilename();
if (fileName == null) {
fileName = mediaEntity.getMediaId();
}
File file = new File(StringUtils.applyRelativePath(Type.TEMP.equals(mediaEntity.getStoreType()) ? defaultTempFilePath : defaultFilePath, fileName));
if (file.exists()) {
return new FileSystemResource(file);
}
file.createNewFile();
file.setLastModified(System.currentTimeMillis());
FileCopyUtils.copy(mediaEntity.getResource().getInputStream(), new FileOutputStream(file));
mediaEntity.setResourcePath(file.getAbsolutePath());
store(mediaEntity);
return new FileSystemResource(file);
}
示例2: storeTempMediaToFile
import org.springframework.util.StringUtils; //導入方法依賴的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;
}
示例3: storeMediaToFile
import org.springframework.util.StringUtils; //導入方法依賴的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;
}
示例4: getFile
import org.springframework.util.StringUtils; //導入方法依賴的package包/類
public synchronized File getFile(String path) throws IOException {
if (this.file == null) {
// 拿到臨時文件路徑
String pathToUse = StringUtils.applyRelativePath(path, this.filename);
this.file = new File(pathToUse);
if (!this.file.exists()) {
this.file.getParentFile().mkdirs();
this.file.createNewFile();
}
FileCopyUtils.copy(this.getBody(), file);
}
return this.file;
}
示例5: createRelative
import org.springframework.util.StringUtils; //導入方法依賴的package包/類
@Override
public Resource createRelative(String mediaId) throws IOException {
if (isFileResource) {
String pathToUse = StringUtils.applyRelativePath(StringUtils.cleanPath(file.getPath()), mediaId);
return new WxMediaResource(new File(pathToUse));
}
return WxContextUtils.getBean(WxApiService.class).getTempMedia(mediaId);
}
示例6: createRelative
import org.springframework.util.StringUtils; //導入方法依賴的package包/類
/**
* This implementation creates a ServletContextResource, applying the given path
* relative to the path of the underlying file of this resource descriptor.
* @see org.springframework.util.StringUtils#applyRelativePath(String, String)
*/
@Override
public Resource createRelative(String relativePath) {
String pathToUse = StringUtils.applyRelativePath(this.path, relativePath);
return new ServletContextResource(this.servletContext, pathToUse);
}
示例7: createRelative
import org.springframework.util.StringUtils; //導入方法依賴的package包/類
/**
* Returns a resource relative to this resource. This implementation creates
* an <code>OsgiBundleResource</code>, applying the given path relative to
* the path of the underlying resource of this descriptor.
*
* @param relativePath the relative path (relative to this resource)
* @return the resource handle for the relative resource
* @throws IOException if the relative resource cannot be determined
* @see org.springframework.util.StringUtils#applyRelativePath(String,
* String)
*/
public Resource createRelative(String relativePath) {
String pathToUse = StringUtils.applyRelativePath(this.path, relativePath);
return new OsgiBundleResource(this.bundle, pathToUse);
}