Java Code Examples for play.vfs.VirtualFile#fromRelativePath()

The following examples show how to use play.vfs.VirtualFile#fromRelativePath() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RouterBenchmark.java    From actframework with Apache License 2.0 6 votes vote down vote up
@BeforeClass
public static void prepare() throws Exception {
    try {
        Field f = Act.class.getDeclaredField("pluginManager");
        f.setAccessible(true);
        f.set(null, new GenericPluginManager());
    } catch (Exception e) {
        throw E.unexpected(e);
    }
    app = App.testInstance();
    UrlPath.testClassInit();
    config = app.config();
    RequestHandlerResolver controllerLookup = new MockRequestHandlerResolver();
    router = new Router(controllerLookup, app);
    InputStream is = TestBase.class.getResourceAsStream("/routes");
    String fc = IO.readContentAsString(is);
    builder = new RouteTableRouterBuilder(fc.split("[\r\n]+"));
    builder.build(router);
    Play.pluginCollection = new PluginCollection();
    URL url = TestBase.class.getResource("/routes");
    Play.applicationPath = new File(FastStr.of(url.getPath()).beforeLast('/').toString());
    Play.routes = VirtualFile.fromRelativePath("routes");
    play.mvc.Router.load("");
}
 
Example 2
Source File: AgentConfigProvider.java    From restcommander with Apache License 2.0 5 votes vote down vote up
public void saveConfigFile(CONFIG_FILE_TYPE configFile,
		String configFileContent) {

	if (configFile == null) {
		models.utils.LogUtils.printLogError("ERROR reading config: configFile is empty.");
	}

	// String nodeGroupConfFileLocation =
	// Play.configuration.getProperty("agentmaster.nodegroup.conf.file.location");

	// in test
	String nodeGroupConfFileLocation = "conf/"
			+ configFile.toString().toLowerCase(Locale.ENGLISH) + ".conf";
	try {

		VirtualFile vf = VirtualFile
				.fromRelativePath(nodeGroupConfFileLocation);
		File realFile = vf.getRealFile();

		boolean append = false;
		FileWriter fw = new FileWriter(realFile, append);
		fw.write(configFileContent);

		fw.close();
		models.utils.LogUtils.printLogNormal("Completed saveConfigFile with size: "
				+ configFileContent.length() + " at "
				+ DateUtils.getNowDateTimeStr());

	} catch (Throwable e) {
		models.utils.LogUtils.printLogError("Error in saveConfigFile."
				+ e.getLocalizedMessage());
		e.printStackTrace();
	}

}
 
Example 3
Source File: AgentUtils.java    From restcommander with Apache License 2.0 5 votes vote down vote up
public static void saveStringToFile(String filePath, String fileContent) {

		if (filePath == null) {
			models.utils.LogUtils.printLogError("ERROR reading filePath: filePath is empty.");
		}

		// String nodeGroupConfFileLocation =
		// Play.configuration.getProperty("agentmaster.nodegroup.conf.file.location");

		// in test
		try {

			VirtualFile vf = VirtualFile.fromRelativePath(filePath);
			File realFile = vf.getRealFile();

			boolean append = false;
			FileWriter fw = new FileWriter(realFile, append);
			fw.write(fileContent);

			fw.close();
			models.utils.LogUtils.printLogNormal("Completed saveStringToFile with size: "
					+ fileContent.length() / VarUtils.CONVERSION_1024
					+ " KB Path: " + filePath + " at "
					+ DateUtils.getNowDateTimeStr());

		} catch (Throwable e) {
			models.utils.LogUtils.printLogError("Error in saveStringToFile."
					+ e.getLocalizedMessage());
			e.printStackTrace();
		}

	}
 
Example 4
Source File: AgentConfigProvider.java    From restcommander with Apache License 2.0 4 votes vote down vote up
/**
 * In the end: will always call
 * updateAllAgentDataFromNodeGroupSourceMetadatas() to initialize
 * NodeGroupDataMap object if needed in allAgentData
 */
public String readConfigFile(CONFIG_FILE_TYPE configFile) {

	if (configFile == null) {
		return "ERROR reading config: configFile is empty.";
	}

	// String nodeGroupConfFileLocation =
	// Play.configuration.getProperty("agentmaster.nodegroup.conf.file.location");

	StringBuilder sb = new StringBuilder();

	// in test
	String nodeGroupConfFileLocation = "conf/"
			+ configFile.toString().toLowerCase(Locale.ENGLISH) + ".conf";
	try {

		VirtualFile vf = VirtualFile
				.fromRelativePath(nodeGroupConfFileLocation);
		File realFile = vf.getRealFile();

		FileReader fr = new FileReader(realFile);
		BufferedReader reader = new BufferedReader(fr);
		String line = null;

		while ((line = reader.readLine()) != null) {
			sb.append(line).append("\n");
		}

		models.utils.LogUtils.printLogNormal("Completed readConfigFile with size: "
				+ sb.toString().length() / 1024.0 + " KB at "
				+ DateUtils.getNowDateTimeStr());

	} catch (Throwable e) {
		models.utils.LogUtils.printLogError("Error in readConfigFile."
				+ e.getLocalizedMessage());
		e.printStackTrace();
	}

	return sb.toString();

}
 
Example 5
Source File: AgentConfigProvider.java    From restcommander with Apache License 2.0 4 votes vote down vote up
public synchronized void updateAggregationMetadatasFromConf() {

		// String nodeGroupConfFileLocation =
		// Play.configuration.getProperty("agentmaster.aggregation.conf.file.location");

		// in test
		try {

			VirtualFile vf = VirtualFile
					.fromRelativePath(ConfUtils.aggregationConfFileLocation);
			File realFile = vf.getRealFile();

			FileReader fr = new FileReader(realFile);
			BufferedReader reader = new BufferedReader(fr);
			String line = null;
			String requestContentLine = null;
			String requestContentTemplate = null;

			String aggregationType = null;

			adp.aggregationMetadatas.clear();
			while ((line = reader.readLine()) != null) {

				// trim the comments or empty lines
				if (line.trim().length() == 0
						|| (line.trim().length() >= 1 && line.trim()
								.startsWith("%"))
						|| line.trim().startsWith("```")) {
					continue;
				}

				aggregationType = line.trim();

				// assuming the next line is the request content: parse it to
				// get the post content
				// fix: trim ending / beging white spaces
				requestContentLine = reader.readLine().trim();
				requestContentTemplate = requestContentLine.replace("```", "");

				adp.aggregationMetadatas.put(aggregationType,
						requestContentTemplate);
			}

			models.utils.LogUtils.printLogNormal
					 ("Completed updateAggregationMetadatasFromConf with size: "
							+ adp.aggregationMetadatas.size()
							+ " at "
							+ DateUtils.getNowDateTimeStr());
			reader.close();
			fr.close();
		} catch (Throwable e) {
			models.utils.LogUtils.printLogError("Error in updateAggregationMetadatasFromConf."
					+ e.getLocalizedMessage());
			e.printStackTrace();
		}

	}
 
Example 6
Source File: AgentConfigProvider.java    From restcommander with Apache License 2.0 4 votes vote down vote up
/**
 * For common http headers
 * 
 * TODO
 */
public synchronized void updateCommonHttpHeaderFromConf() {

	// in test
	try {

		VirtualFile vf = VirtualFile
				.fromRelativePath(ConfUtils.httpHeaderConfFileLocation);
		File realFile = vf.getRealFile();

		FileReader fr = new FileReader(realFile);
		BufferedReader reader = new BufferedReader(fr);
		String httpHeaderType = null;
		String line = null;
		String httpHeaderKey = null;
		String httpHeaderValue = null;
		String httpHeaderValueLine = null;
		// HttpHeaderMetadata
		adp.headerMetadataMap.clear();

		while ((line = reader.readLine()) != null) {

			// trim the comments or empty lines
			if (line.trim().length() == 0
					|| (line.trim().length() >= 1 && line.trim()
							.startsWith("%"))
					|| line.trim().startsWith("```")) {
				continue;
			}

			Map<String, String> headerMap = new HashMap<String, String>();

			httpHeaderType = line.trim();

			boolean startTagParsed = false;
			boolean endTagParsed = false;
			while ((line = reader.readLine()) != null) {
				if (line.equalsIgnoreCase(VarUtils.HTTPHEADER_CONF_TAG_HTTP_HEADER_LIST_START1)) {
					startTagParsed = true;
				} else if (line
						.equalsIgnoreCase(VarUtils.HTTPHEADER_CONF_TAG_HTTP_HEADER_LIST_END1)) {
					endTagParsed = true;
					break;
				} else if (startTagParsed == true && endTagParsed == false) {
					// fixed bug: when fqdn has a space in the end.
					// Assuming FQDN dont have a space in the middle
					String lineTrimmed = line.trim();
					if (lineTrimmed != null && !lineTrimmed.isEmpty()) {

						httpHeaderKey = lineTrimmed;
						httpHeaderValueLine = reader.readLine().trim();
						httpHeaderValue = httpHeaderValueLine.replace(
								"```", "");
						headerMap.put(httpHeaderKey, httpHeaderValue);
					} else {
						continue; // read next line
					}

				}// end else if
			}// end while

			HttpHeaderMetadata httpHeaderMetadata = new HttpHeaderMetadata(
					httpHeaderType, headerMap);
			adp.headerMetadataMap.put(httpHeaderType, httpHeaderMetadata);
		}

		models.utils.LogUtils.printLogNormal
				 ("Completed updateCommonHttpHeaderFromConf headerMap size: "
						+ adp.headerMetadataMap.size()
						+ " at "
						+ DateUtils.getNowDateTimeStr());
		reader.close();
		fr.close();
	} catch (Throwable e) {
		models.utils.LogUtils.printLogError("Error in updateCommonHttpHeaderFromConf.."
				+ e.getLocalizedMessage());
		e.printStackTrace();
	}

}
 
Example 7
Source File: FileIoUtils.java    From restcommander with Apache License 2.0 4 votes vote down vote up
/**
 * This will display all files except for empty.txt refined 20130918
 * 
 * @param folderName
 * @return
 */
public static List<String> getFileNamesInFolder(String folderName) {

	List<String> fileNameList = new ArrayList<String>();

	try {

		VirtualFile virtualDir = VirtualFile.fromRelativePath(folderName);
		List<VirtualFile> virtualFileList = virtualDir.list();

		if (virtualFileList == null) {
			 models.utils.LogUtils.printLogError
					 ("virtualFileList is NULL! in getFileNamesInFolder()"
							+ DateUtils.getNowDateTimeStrSdsm());
		}

		models.utils.LogUtils.printLogNormal("Under folder: " + folderName
				+ ",  File/dir count is " + virtualFileList.size());

		for (int i = 0; i < virtualFileList.size(); i++) {

			if (virtualFileList.get(i).getRealFile().isFile()) {
				String fileName = virtualFileList.get(i).getName();

				if ((!fileName
						.equalsIgnoreCase(VarUtils.FILE_NAME_APP_LOG_EMPTY))) {

					if (VarUtils.IN_DETAIL_DEBUG) {
						models.utils.LogUtils.printLogNormal("File " + fileName);
					}
					fileNameList.add(fileName);
				}
			} else if (virtualFileList.get(i).getRealFile().isDirectory()) {
				models.utils.LogUtils.printLogNormal("Directory "
						+ virtualFileList.get(i).getName());
			}
		}// end for

	} catch (Throwable t) {
		t.printStackTrace();
	}
	return fileNameList;
}
 
Example 8
Source File: FileIoUtils.java    From restcommander with Apache License 2.0 4 votes vote down vote up
/**
 * Output both This will display all files except for empty.txt refined
 * 20130918
 * 
 * @param folderName
 * @return
 */
public static void getFileAndDirNamesInFolder(String folderName,
		List<String> fileNames, List<String> dirNames) {

	if (fileNames == null) {
		fileNames = new ArrayList<String>();
	}

	if (dirNames == null) {
		dirNames = new ArrayList<String>();
	}

	try {

		VirtualFile virtualDir = VirtualFile.fromRelativePath(folderName);
		List<VirtualFile> virtualFileList = virtualDir.list();

		if (virtualFileList == null) {
			 models.utils.LogUtils.printLogError
					 ("virtualFileList is NULL! in getFileNamesInFolder()"
							+ DateUtils.getNowDateTimeStrSdsm());
		}

		models.utils.LogUtils.printLogNormal("Under folder: " + folderName
				+ ",  File/dir count is " + virtualFileList.size());

		for (int i = 0; i < virtualFileList.size(); i++) {

			String fileOrDirName = virtualFileList.get(i).getName();
			if (virtualFileList.get(i).getRealFile().isFile()) {

				if ((!fileOrDirName
						.equalsIgnoreCase(VarUtils.FILE_NAME_APP_LOG_EMPTY))) {

					if (VarUtils.IN_DETAIL_DEBUG) {
						models.utils.LogUtils.printLogNormal("File " + fileOrDirName);
					}
					fileNames.add(fileOrDirName);
				}
			} else if (virtualFileList.get(i).getRealFile().isDirectory()) {
				models.utils.LogUtils.printLogNormal("Directory " + fileOrDirName);
				dirNames.add(fileOrDirName);

			}
		}// end for

	} catch (Throwable t) {
		t.printStackTrace();
	}
}
 
Example 9
Source File: FileIoUtils.java    From restcommander with Apache License 2.0 4 votes vote down vote up
/**
 * This will delete all files and folder under the path. Very careful
 * 20130918
 * 
 * SAFE GUARD: only with adhoc logs
 * 
 * @param folderName
 * @return
 */
public static boolean deleteAllFileAndDirInFolder(String folderName) {

	boolean success = true;

	// safeguard:
	if (!(folderName.contains("adhoc") || folderName.contains("logs"))) {
		 models.utils.LogUtils.printLogError
				 ("Looks like this folder is not logs folder in deleteAllFileAndDirInFolder(). Safeguard activated. "
						+ "NO OPS on this case. Return. ForderName:"
						+ folderName);
		return success;
	}

	try {

		VirtualFile virtualDir = VirtualFile.fromRelativePath(folderName);
		List<VirtualFile> virtualFileList = virtualDir.list();

		if (virtualFileList == null) {
			 models.utils.LogUtils.printLogError
					 ("virtualFileList is NULL! in getFileNamesInFolder()"
							+ DateUtils.getNowDateTimeStrSdsm());
		}

		models.utils.LogUtils.printLogNormal("Delete: Under folder: " + folderName
				+ ",  File/dir count is " + virtualFileList.size());

		for (int i = 0; i < virtualFileList.size(); i++) {

			if (virtualFileList.get(i).getRealFile().isFile()) {
				String fileName = virtualFileList.get(i).getName();

				if ((!fileName
						.equalsIgnoreCase(VarUtils.FILE_NAME_APP_LOG_EMPTY))) {

					if (VarUtils.IN_DETAIL_DEBUG) {
						models.utils.LogUtils.printLogNormal("File " + fileName);
					}

					FileUtils.forceDelete(virtualFileList.get(i)
							.getRealFile());
				}
			} else if (virtualFileList.get(i).getRealFile().isDirectory()) {
				models.utils.LogUtils.printLogNormal("Directory "
						+ virtualFileList.get(i).getName());

				FileUtils.deleteDirectory(virtualFileList.get(i)
						.getRealFile());
			}
		}// end for

	} catch (Throwable t) {
		t.printStackTrace();
		success = false;
	}

	return success;
}
 
Example 10
Source File: LogConsole.java    From restcommander with Apache License 2.0 4 votes vote down vote up
public static String readConfigFile(String fileName, String numLines) {
 int lineCountForDisplay = 0;
 if("all".equalsIgnoreCase(numLines)) {
     lineCountForDisplay = 0;
 } else {
     lineCountForDisplay = Integer.parseInt(numLines);
 }
    if (fileName == null) {
        return "ERROR reading config: configFile is empty.";
    }
    List<String> linesTotal = new ArrayList<String>();
    StringBuilder sb = new StringBuilder();
    
    String logDir = (fileName.contains("models.utils.LogUtils.printLogNormal")) ? "logs/" : "log/";
    
    String logFileLocation = logDir
            + fileName.toString().toLowerCase(Locale.ENGLISH) ;
    try {
       
        VirtualFile vf = VirtualFile
                .fromRelativePath(logFileLocation);
        File realFile = vf.getRealFile();
        FileReader fr = new FileReader(realFile);
        BufferedReader reader = new BufferedReader(fr);
        String line = null;
        while ((line = reader.readLine()) != null) {
            line = line + "<br />";
            linesTotal.add(line);
        }
    } catch (Throwable e) {
        models.utils.LogUtils.printLogError("Error in readConfigFile."
                + e.getLocalizedMessage());
       // e.printStackTrace();
    }
    
    if(VarUtils.IN_DETAIL_DEBUG){
    	models.utils.LogUtils.printLogNormal("linesTotal size:"+linesTotal.size());
    	models.utils.LogUtils.printLogNormal("lineCountForDisplay:"+lineCountForDisplay);
    	
    }
    if(lineCountForDisplay == 0) {
        for (int j= 0; j< linesTotal.size(); j++) {
            sb.append(linesTotal.get(j));
        }
    } else if (linesTotal.size() > lineCountForDisplay) {
        for (int j= (linesTotal.size() - lineCountForDisplay); j< linesTotal.size(); j++) {
            sb.append(linesTotal.get(j));
        }
    } else {
        for (int j= 0; j< linesTotal.size(); j++) {
            sb.append(linesTotal.get(j));
        }
    }
    
    if(VarUtils.IN_DETAIL_DEBUG){
    	models.utils.LogUtils.printLogNormal("linesTotal size:"+linesTotal.size());
    	
    }
    return sb.toString();
}