我正在尝试创建一个实用程序类,ReadPropertyUtil.java
用于从属性文件中读取数据.虽然我的类位于util目录下,但我的skyscrapper.properties
文件放在其他目录中.
但是,当我尝试使用属性访问时[ResourceBundle][1]
,我得到异常,无法加载该包.
下面是我如何阅读属性的代码,以及显示我的目录结构的图像.
ReadPropertiesUtil.java
/**
* Properties file name.
*/
private static final String FILENAME = "skyscrapper";
/**
* Resource bundle.
*/
private static ResourceBundle resourceBundle = ResourceBundle.getBundle(FILENAME);
/**
* Method to read the property value.
*
* @param key
* @return
*/
public static String getProperty(final String key) {
String str = null;
if (resourceBundle != null) {
str = resourceBundle.getString(key);
LOGGER.debug("Value found: " + str + " for key: " + key); …
Run Code Online (Sandbox Code Playgroud) 我有一个maven项目分叉并从git repo克隆到我的eclipse上.它建立在Java 8之上.我做的第一件事是执行a
mvn clean install
Run Code Online (Sandbox Code Playgroud)
但我收到以下失败消息:
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Maven 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ Maven ---
[INFO] Deleting /Users/vshukla/git/Prism/target
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ Maven ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory /Users/vshukla/git/Prism/src/main/resources
[INFO]
[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ Maven ---
[INFO] Changes detected - recompiling the module!
[WARNING] File encoding has not …
Run Code Online (Sandbox Code Playgroud) 我试图显示两个HTML页面的不同之处.我试图找出一种方法,如果我可以比较两个网页的HTML源代码(几乎相似),并在视觉上显示/突出显示差异(在UI上).
我尝试了什么:我想拍摄页面的快照然后使用Resemble.js来比较两个图像.但这显示出非常微小的差异,结果是不明确的.
我想过比较DOM结构或源代码,然后显示两个页面在UI上的不同之处.
有什么方法可以实现这个目标吗?我正在使用Selenium- Webdriver来获取快照和HTML源代码.
编辑:
我想我的问题不明确.实际上,我想找出网页HTML内容的差异,以便检测当前正在执行的A/B测试.我首先将html源代码抓取到一个文本文件中,然后使用Java-Diff util将其与之前捕获的HTML源进行比较.这给了我两个文本文件与HTML源不同的实际行.
现在,问题是,我如何在UI上显示这种差异,因为突出显示我发现的区域不同?希望这会使它更清楚.
以下代码显示了不同的行
List<String> original = fileToLines("HTML Source diff/originalSource.txt");
List<String> revised = fileToLines("HTML Source diff/sourceAfterCookieClear.txt");
// Compute diff. Get the Patch object. Patch is the container for computed deltas.
Patch patch = DiffUtils.diff(original, revised);
System.out.println("Printing Deltas\n");
for (Delta delta : patch.getDeltas()) {
String revisedText = delta.getRevised().toString();
String content = revisedText.substring(revisedText.indexOf(" [")+2,revisedText.indexOf("]]"));
writeTextToFile(content,"difference.html");
}
Run Code Online (Sandbox Code Playgroud)
代码形式的任何线索都会有所帮助.
我有一个Get API
返回一个JSON
. 预期的格式是:
{
"value1": "123.00",
"value2": "23.00"
}
Run Code Online (Sandbox Code Playgroud)
这些值位于BigDecimal
对象中:
public class Result{
BigDecimal value1;
BigDecimal value2;
// getters and setters
}
Run Code Online (Sandbox Code Playgroud)
现在,当发出请求时,我创建Result
对象并将这些值填充为BigDecimal
,创建一个列表并返回。我收到的回复是:
{
"value1": 123.00,
"value2": 23.00
}
Run Code Online (Sandbox Code Playgroud)
这些值是正确的,但不是字符串。我怎样才能把它们做成绳子?
我知道我们可以转换BigDecimal
为,String
但我只有 BigDecimal 字段的对象,并且无法向其填充 String 值。
最后,列表是这样制作的:
List<MyObj> obj = Arrays.stream(myObj).collect(Collectors.toList());
Result result = new Result();
obj.forEach(t -> t.mergeToResult(result)); // mergeToResults does all the population like result.setValue1(new BigDecimal(123.00))
return result;
Run Code Online (Sandbox Code Playgroud) 您将获得一个字符串数组,当且仅当所有字符串都可以在一个链中连接时才返回true.
连接条件是,如果一个字符串的最后一个字符与第二个字符串的第一个字符匹配,则可以连接两个字符串.
示例:String []arr ={"abc", "cde", "cad" , "def" , "eac"}
将返回true,因为所有字符串都可以在一个链中连接.
"abc"->"cde"->"eac"->"cad"->"def"
Run Code Online (Sandbox Code Playgroud)
另一个例子:String []arr ={"acb" , "cde", "def", "ead" }
返回False,因为
"cde"->"ead"->"def"
是可能的链但是"acb"被省略了.
注意:没有必要从第一个字符串开始并形成链,如果你从第一个字符串开始,你可能不会得到一个链.如果你从任何其他字符串开始,你可以得到一个链.如果存在可能的链,那么您的解决方案应该返回true.
在第二个例子中,如果假设第一个String “fcb”
,则可能存在一个链,"cde"->"ead"->"def"->"fcb"
因此为True.
可能的解决方案(我在想什么):将每个字符串视为一个图节点,并在条件满足时连接节点.一旦完成,问题就会减少,
if there exists a Hamiltonian Cycle in a graph
,这是NP完全问题.
有人建议一些算法或任何其他解决方案?
我有一个JSON文件,其中读取对象并在div中显示它们.但我只需要显示五个对象而不是全部.
以下是我正在使用的代码
$.each(recentActdata.slice(0,5), function(i, data) {
var ul_data = "<li><h3>"+ renderActionLink(data)+ "</h3></li>";
$("#recentActivities").append(ul_data);
});
Run Code Online (Sandbox Code Playgroud)
但这片似乎不起作用.我的JSON格式是
[
{
"displayValue":"Updated Guidelines",
"link":"#",
"timestamp":"29/06/2013 01:32"
},
{
"displayValue":"Logging",
"link":"#",
"timestamp":"28/06/2013 16:19"
},
{
"displayValue":"Subscribe",
"link":"#",
"timestamp":"21/06/2013 14:30"
},
{
"displayValue":"Artifactory Vs Nexus",
"link":"#",
"timestamp":"21/06/2013 13:39"
},
{
"displayValue":"CTT - Java 7",
"link":"#",
"timestamp":"20/06/2013 13:30"
},
{
"displayValue":"Added Artifactory Server",
"link":"#",
"timestamp":"19/06/2013 23:39"
},
{
"displayValue":"Estimation Template",
"link":"#",
"timestamp":"19/06/2013 23:39"
},
{
"displayValue":"GZIP compression in Tomcat",
"link":"#",
"timestamp":"14/06/2013 23:39"
},
{
"displayValue":"HBase Basics",
"link":"#", …
Run Code Online (Sandbox Code Playgroud) 我试图使用selenium从指定的HTML文件中捕获源代码,但我不知道为什么,我没有得到我们从浏览器中看到的确切源代码.
下面是我在Java文件中捕获源代码的java代码
private static void getHTMLSourceFromURL(String url, String fileName) {
WebDriver driver = new FirefoxDriver();
driver.get(url);
try {
Thread.sleep(5000); //the page gets loaded completely
List<String> pageSource = new ArrayList<String>(Arrays.asList(driver.getPageSource().split("\n")));
writeTextToFile(pageSource, originalFile);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println("quitting webdriver");
driver.quit();
}
/**
* creates file with fileName and writes the content
*
* @param content
* @param fileName
*/
private static void writeTextToFile(List<String> content, String fileName) {
PrintWriter pw = null;
String outputFolder = ".";
File output = null; …
Run Code Online (Sandbox Code Playgroud) 我试图在 mac上安装AWS CLI,但由于 aws 命令无法解析凭证文件而面临一些挑战。所以我决定重新安装整个东西,但在这里再次面临一些问题。
我正在尝试pip uninstall awscli
其中说
Cannot uninstall requirement awscli, not installed
Run Code Online (Sandbox Code Playgroud)
所以,我尝试pip3 install awscli --upgrade --user
这给了我这个:
You are using pip version 6.0.8, however version 9.0.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
Requirement already up-to-date: awscli in ./Library/Python/3.5/lib/python/site-packages
Requirement already up-to-date: rsa<=3.5.0,>=3.1.2 in ./Library/Python/3.5/lib/python/site-packages (from awscli)
Requirement already up-to-date: docutils>=0.10 in ./Library/Python/3.5/lib/python/site-packages (from awscli)
Requirement already up-to-date: PyYAML<=3.12,>=3.10 in ./Library/Python/3.5/lib/python/site-packages (from awscli)
Requirement already up-to-date: …
Run Code Online (Sandbox Code Playgroud) 我有一个任务,我需要(e.g www.yahoo.com)
在我的网页上加载一个URL ,并截取屏幕截图.我使用html2canvas进行截屏并将其附加到页面正文.
URL指定的页面已成功加载到div元素内的iframe中.但是当我尝试截取屏幕截图时,iframe区域显示为空白.
下面是代码previewURL
和screenshot
.
//to preview the URL content
function previewUrl(url,target){
//use timeout coz mousehover fires several times
clearTimeout(window.ht);
window.ht = setTimeout(function(){
var div = document.getElementById(target);
div.innerHTML = '<iframe style="width:100%;height:100%;" frameborder="0" src="' + url + '" />';
},20);
}
function pic() {
html2canvas(document.body, {
onrendered: function(canvas) {
document.body.appendChild(canvas);
}
});
};
Run Code Online (Sandbox Code Playgroud)
HTML部分在这里:
<body>
<input type="button" class="clear-button" onclick="pic();" value="Take Screenshot" >
<a href="http://www.yahoo.com" onmouseover="previewUrl(this.href,'div1')">Hover to load</a>
<div id="div1"></div>
</body>
Run Code Online (Sandbox Code Playgroud)
截图看起来像这样:
我被困住了,不明白为什么会这样.我想类似的东西这 …
我在S3中有一个JSON文件url,我需要解析并从中提取信息。如何在Java中做到这一点?
我已经研究了一些主要使用Python 的解决方案,但不能用Java做到这一点。
我可以使用阅读内容
S3Object object = s3Client.getObject(new GetObjectRequest(bucketName, key));
InputStream objectData = object.getObjectContent();
Run Code Online (Sandbox Code Playgroud)
但我不想下载文件并保留它。我只需要能够使用Gson解析此JSON文件。
我该如何实现?
java ×6
javascript ×3
json ×3
arrays ×2
jquery ×2
algorithm ×1
amazon-s3 ×1
aws-cli ×1
bigdecimal ×1
build ×1
comparison ×1
firefox ×1
get ×1
html ×1
html2canvas ×1
iframe ×1
maven ×1
parsing ×1
pip ×1
properties ×1
python-3.x ×1
rest ×1
selenium ×1
slice ×1
string ×1
webdriver ×1