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


Java ResourceUtils.getFile方法代碼示例

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


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

示例1: 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;
}
 
開發者ID:ekoz,項目名稱:kbase-doc,代碼行數:24,代碼來源:IndexController.java

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

示例3: 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;
}
 
開發者ID:okingjerryo,項目名稱:WeiMusicCommunity-server,代碼行數:17,代碼來源:UserInfoManage.java

示例4: 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);
	}
}
 
開發者ID:eclipse,項目名稱:gemini.blueprint,代碼行數:35,代碼來源:OsgiBundleResource.java

示例5: 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);
}
 
開發者ID:softelnet,項目名稱:sponge,代碼行數:21,代碼來源:SpringKnowledgeBaseFileProvider.java

示例6: init

import org.springframework.util.ResourceUtils; //導入方法依賴的package包/類
private void init() {
    config = new HashMap<String, String>();
    File file = null;
    try {
        file = ResourceUtils.getFile(PROPERTIES_PATH);
    } catch (FileNotFoundException e) {
        LOGGER.warn(String.format("file not found, path:[%s]", PROPERTIES_PATH));
        file = new File(GLOBAL_PROPERTIES_PATH);
        if(!file.exists() || !file.isFile()) {
            LOGGER.warn(String.format("file not found, path:[%s]", PROPERTIES_PATH));
            file = null;
        }
    }
    if(file == null) return;
    PropertiesUtils.convertPropertiesToMap(config, file);
    ip = config.get("ip");
}
 
開發者ID:justimkiss,項目名稱:bee,代碼行數:18,代碼來源:PropertiesFileConfigManager.java

示例7: initProps

import org.springframework.util.ResourceUtils; //導入方法依賴的package包/類
private  <E> void initProps(Class<E> clazz) throws Exception {
	String rcName = clazz.getSimpleName() + ".properties";
	File rcFile = ResourceUtils.getFile("classpath:"+rcName);
	log.debug(rcFile.exists());
	Properties prop=new Properties();  
	prop.load(new InputStreamReader(new FileInputStream(rcFile), Constants.CHARSET));
	Constructor<E> minimalConstructor = getConstructor(clazz, new Class[] {String.class, int.class});
	Constructor<E> additionalConstructor = getConstructor(clazz, new Class[] {String.class, String.class, int.class});
	int ordinal = 0;
	Iterator<Object> keys = prop.keySet().iterator();
	while(keys.hasNext()){
		String key = keys.next().toString();
		String value = prop.getProperty(key);
		if(StringUtils.isEmpty(value))
			minimalConstructor.newInstance(key, ordinal++);
		else
			additionalConstructor.newInstance(key, value, ordinal++);
	}
}
 
開發者ID:simbest,項目名稱:simbest-cores,代碼行數:20,代碼來源:PropertiesDynaEnum.java

示例8: init

import org.springframework.util.ResourceUtils; //導入方法依賴的package包/類
@PostConstruct
private void init()
{
  try 
  {
    ArffLoader loader = new ArffLoader();
    File f = ResourceUtils.getFile(dummyFile);
    loader.setFile(f);
    log.info("Reading file ["+f+"] for creating evaluation dataset");
    instances = loader.getDataSet();
  } catch (Exception e) {
    log.error("EvaluationDatasetGenerator::init [ "+e.getMessage() + "] Will go with a dummy dataset. ");
    log.debug("", e);
    try {
      instances = new RandomRBF().generateExamples();
    } catch (Exception e1) {
      log.debug("", e);
    }
  }
  instances.setClassIndex(instances.numAttributes()-1);
}
 
開發者ID:javanotes,項目名稱:reactive-data,代碼行數:22,代碼來源:CombinerDatasetGenerator.java

示例9: updateFileSystem

import org.springframework.util.ResourceUtils; //導入方法依賴的package包/類
private boolean updateFileSystem(URL url, String name,
		ClassLoaderFile classLoaderFile) {
	if (!isFolderUrl(url.toString())) {
		return false;
	}
	try {
		File folder = ResourceUtils.getFile(url);
		File file = new File(folder, name);
		if (file.exists() && file.canWrite()) {
			if (classLoaderFile.getKind() == Kind.DELETED) {
				return file.delete();
			}
			FileCopyUtils.copy(classLoaderFile.getContents(), file);
			return true;
		}
	}
	catch (IOException ex) {
		// Ignore
	}
	return false;
}
 
開發者ID:philwebb,項目名稱:spring-boot-concourse,代碼行數:22,代碼來源:RestartServer.java

示例10: resourceAsFile

import org.springframework.util.ResourceUtils; //導入方法依賴的package包/類
/**
 * Simplifies calling {@ResourceUtils.getFile} so that a {@link RuntimeException}
 * is thrown rather than a checked {@link FileNotFoundException} exception.
 *
 * @param resourceName e.g. "classpath:folder/file"
 * @return File object
 */
private File resourceAsFile(String resourceName)
{
    try
    {
        return ResourceUtils.getFile(resourceName);
    }
    catch (FileNotFoundException e)
    {
        throw new RuntimeException("Resource "+resourceName+" not found", e);
    }
}
 
開發者ID:Alfresco,項目名稱:alfresco-repository,代碼行數:19,代碼來源:BulkImportTest.java

示例11: getSearchResponseAsJson

import org.springframework.util.ResourceUtils; //導入方法依賴的package包/類
public JSONObject getSearchResponseAsJson(String jsonResponse) throws FileNotFoundException, JSONException
{
    URL url = SpellCheckDecisionManagerTest.class.getClassLoader().getResource(RESOURCE_PREFIX + jsonResponse);
    if (url == null)
    {
        fail("Cannot get the resource: " + jsonResponse);
    }
    
    Reader reader = new FileReader(ResourceUtils.getFile(url));
    JSONObject resultJson = new JSONObject(new JSONTokener(reader));
    return resultJson;
}
 
開發者ID:Alfresco,項目名稱:alfresco-repository,代碼行數:13,代碼來源:SpellCheckDecisionManagerTest.java

示例12: 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

示例13: getToFilePath

import org.springframework.util.ResourceUtils; //導入方法依賴的package包/類
public static String getToFilePath() {
    if (toFilePath.isEmpty()) {
        try {
            File tarPath = ResourceUtils.getFile("classpath:/FileSpace/CommonSpace/default_personal_image.png");
            toFilePath = tarPath.getParentFile().getParentFile().toString() + "/";
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
    }
    return toFilePath;
}
 
開發者ID:okingjerryo,項目名稱:WeiMusicCommunity-server,代碼行數:12,代碼來源:StaticVar.java

示例14: getResourceFile

import org.springframework.util.ResourceUtils; //導入方法依賴的package包/類
private File getResourceFile(String fileName) throws FileNotFoundException
{
    URL url = VersionableAspectTest.class.getClassLoader().getResource(RESOURCE_PREFIX + fileName);
    if (url == null)
    {
        fail("Cannot get the resource: " + fileName);
    }
    return ResourceUtils.getFile(url);
}
 
開發者ID:Alfresco,項目名稱:alfresco-remote-api,代碼行數:10,代碼來源:UploadWebScriptTest.java

示例15: getResourceFile

import org.springframework.util.ResourceUtils; //導入方法依賴的package包/類
private File getResourceFile(String xmlFileName) throws FileNotFoundException
{
    URL url = CustomModelImportTest.class.getClassLoader().getResource(RESOURCE_PREFIX + xmlFileName);
    if (url == null)
    {
        fail("Cannot get the resource: " + xmlFileName);
    }
    return ResourceUtils.getFile(url);
}
 
開發者ID:Alfresco,項目名稱:alfresco-remote-api,代碼行數:10,代碼來源:CustomModelImportTest.java


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