DecimalFormat使用','作为默认分组分隔符.
告诉DecimalFormat我们不想要任何分组分隔符的正确方法是什么?我目前使用symbols.setGroupingSeparator('\ 0'),它似乎工作,但它看起来很丑.
DecimalFormatSymbols symbols = new DecimalFormatSymbols();
symbols.setDecimalSeparator('.');
symbols.setGroupingSeparator('\0');
DecimalFormat df = new DecimalFormat();
df.setDecimalFormatSymbols(symbols);
ParsePosition pp = new ParsePosition(0);
Number result = df.parse("44,000.0", pp); // this should fail, as I don't want any grouping separatator char.
if (pp.getIndex() != input.length())
throw new Exception("invalid number: " + input, 0);
Run Code Online (Sandbox Code Playgroud)
告诉DecimalFormat我们不想要任何分组分隔符char的正确方法是什么?
我如何知道何时创建了一个git分支?
我不想知道什么时候第一次提交到那个分支.我想知道什么时候创建了这个分支.
这是一个重现一个工作示例的脚本:
#! /bin/bash
set -x
set -e
mkdir test
cd test
git init
echo "hello" >readme
git add readme
git commit -m "initial import"
date
sleep 5
git checkout -b br1
date # this is the date that I want to find out.
sleep 5
echo "hello_br1" >readme
git commit -a -m "hello_br1"
date
echo "hello_br1_b" >readme
git commit -a -m "hello_br1_b"
git checkout master
echo "hello_master" >readme
git commit -a -m "hello_master"
git branch -a;
git log …Run Code Online (Sandbox Code Playgroud) 这里有一个spring-security示例ldap-xml,它运行ldap服务器并导入LDIF文件以进行测试:
[...]
<s:ldap-server ldif="classpath:users.ldif" port="33389"/>
<s:authentication-manager>
<s:ldap-authentication-provider
group-search-filter="member={0}"
group-search-base="ou=groups"
user-search-base="ou=people"
user-search-filter="uid={0}"
/>
<s:authentication-provider ref='secondLdapProvider' />
</s:authentication-manager>
[...]
Run Code Online (Sandbox Code Playgroud)
[...]
dn: uid=rod,ou=people,dc=springframework,dc=org
objectclass: top
objectclass: person
objectclass: organizationalPerson
objectclass: inetOrgPerson
cn: Rod Johnson
sn: Johnson
uid: rod
userPassword: koala
[...]
Run Code Online (Sandbox Code Playgroud)
我需要修改这个工作示例,其中user-search-criteria基于sAMAccountName而不是uid.我修改users.ldif如下:
[...]
dn: cn=rod,ou=people,dc=springframework,dc=org
objectclass: top
objectclass: person
objectclass: organizationalPerson
objectclass: inetOrgPerson
cn: Rod Johnson
sn: Johnson
sAMAccountName: rod
userPassword: koala
[...]
Run Code Online (Sandbox Code Playgroud)
但是,在导入users时,apached会显示警告.ldif:
OID for name 'samaccountname' was not found within the OID registry
Run Code Online (Sandbox Code Playgroud)
似乎我需要通过修改LDAP模式来添加这个新属性sAMAccountName.如何在ldap-xml示例中执行此操作?
在这个要点示例中,他们使用"changetype:add"修改架构.但是在users.ldif中添加此项会导致错误 …
我有下面的简单代码用于@NonNull使用Maven 测试FindBugs 注释.我执行
mvn clean install
Run Code Online (Sandbox Code Playgroud)
它正确地无法构建,因为print(null)违反了非null条件.
您可以NonNull使用类注释将类中的所有方法参数设置为默认值
@DefaultAnnotation(NonNull.class)
Run Code Online (Sandbox Code Playgroud)
如何NonNull为给定包(和子包)下的所有类中的所有方法参数设置默认值?
src/main/java/test/Hello.java
package test;
import edu.umd.cs.findbugs.annotations.NonNull;
public class Hello {
static public void print(@NonNull Object value) {
System.out.println("value: " + value.toString());
}
static public void main(String[] args) {
if (args.length > 0) {
print(args[0]);
} else {
print(null);
}
}
}
Run Code Online (Sandbox Code Playgroud)
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>hello</groupId>
<artifactId>hello</artifactId>
<version>1.0</version>
<dependencies>
<dependency>
<groupId>net.sourceforge.findbugs</groupId>
<artifactId>annotations</artifactId>
<version>1.3.2</version>
</dependency>
<dependency>
<groupId>net.sourceforge.findbugs</groupId>
<artifactId>jsr305</artifactId> …Run Code Online (Sandbox Code Playgroud) FindBugs中有一个注释来忽略一组错误,例如:
import edu.umd.cs.findbugs.annotations.SuppressWarnings;
@SuppressWarnings(value="DLS_DEAD_LOCAL_STORE", justification="...")
Run Code Online (Sandbox Code Playgroud)
有没有办法使用注释忽略java文件的所有类型的错误?
我知道可以从命令行或配置文件中排除文件:http: //findbugs.sourceforge.net/manual/filter.html
但对于这种特殊情况,我需要定义此排除仅修改该java文件.
在我的新mac OSX 10.8.3中,我安装scala 2.10.0,播放2.1.0和IntelliJ12,并创建一个播放项目,如下所示:
#install brew
> ruby -e "$(curl -fsSL https://raw.github.com/mxcl/homebrew/go)"
> brew --version
0.9.4
# update brew database
> cd $(brew --prefix)
> brew update
> cd $(brew --prefix) && git pull --rebase
# get scala 2.10.0
> brew versions scala
2.10.1 git checkout 79dc6f1 Library/Formula/scala.rb
2.10.0 git checkout 8ca07aa Library/Formula/scala.rb
2.9.2 git checkout 8896425 Library/Formula/scala.rb
...
> git checkout 8ca07aa Library/Formula/scala.rb # 2.10.0
> brew install scala
> scala -version
Scala code runner version 2.10.0 -- Copyright …Run Code Online (Sandbox Code Playgroud) 我有这个简单的测试Scala应用程序,它阻止http请求:
build.sbt
name := "hello"
version := "1.0"
scalaVersion := "2.11.2"
libraryDependencies += "com.typesafe.play" %% "play-ws" % "2.4.0-M1"
Run Code Online (Sandbox Code Playgroud)
Test.scala
import play.api.libs.json._
import play.api.libs.ws._
import scala.concurrent.duration.Duration
import scala.concurrent.{Await, Future}
object Test {
def main(args: Array[String]) = {
val wsClient = WS.client
val body = getBody(wsClient.url("http://example.com/").get())
println(s"body: $body")
}
def getBody(future: Future[WSResponse]) = {
val response = Await.result(future, Duration.Inf);
if (response.status != 200)
throw new Exception(response.statusText);
response.body
}
}
Run Code Online (Sandbox Code Playgroud)
此应用程序失败:
Exception in thread "main" java.lang.RuntimeException: There is no started application
Run Code Online (Sandbox Code Playgroud)
如何解决这个问题?
以下代码按预期工作.在Google Chrome上打开" https://wiki.epfl.ch/ " 页面,然后在Developer Console上执行此代码.注意:页面" https://wiki.epfl.ch/test.php "不存在,因此无法加载,但这不是问题.
response = await fetch(""https://wiki.epfl.ch/lapa-studio/documents/DTS/laser%20tutorial.pdf"");
response.text().then(function(content) {
formData = new FormData();
console.log(content.length);
console.log(content);
formData.append("content", content);
fetch("https://wiki.epfl.ch/test.php", {method: 'POST', body: formData});
})
Run Code Online (Sandbox Code Playgroud)
它记录:
content.length: 57234
content: %PDF-1.3
%?????????
4 0 obj
<< /Length 5 0 R /Filter /FlateDecode >>
stream
x??K??F?????;¢?
...
Run Code Online (Sandbox Code Playgroud)
转到Developer Network选项卡,选择'test.php'页面,导航到"Requested payload:",您可以看到以下内容:
------WebKitFormBoundaryOJOOGb7N43BxCRlv
Content-Disposition: form-data; name="content"
%PDF-1.3
%?????????
4 0 obj
<< /Length 5 0 R /Filter /FlateDecode >>
stream
...
------WebKitFormBoundaryOJOOGb7N43BxCRlv
Run Code Online (Sandbox Code Playgroud)
问题是请求文件是二进制文件(PDF),文本被"损坏".当实际文件大小(使用wget命令获取)为60248字节时,它报告大小为57234字节.
问题是:如何获取和发送二进制数据,而不进行修改?
我试着更换response.text()的response.blob(),如下: …
我需要用maven执行一些测试,并从命令行传递一个参数.
我的java代码应该获取参数:System.getenv("my_parameter1");
我在pom.xml文件中定义参数,如下例所示:(后者,我修改pom.xml以从公共行获取参数mvn clean install -Dmy_parameter1 = value1)
但它不起作用; System.getenv("my_parameter1")返回null.我应该如何在pom.xml文件中定义参数?
的pom.xml
<project>
...
<profiles>
<profile>
<properties>
<my_parameter1>value1</my_parameter1>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<executions>
<execution>
<id>slowTest</id>
<phase>test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<skip>false</skip>
<includes>
<include>**/*Test.java</include>
<include>**/*TestSlow.java</include>
</includes>
<properties>
<my_parameter1>value1</my_parameter1>
</properties>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
Run Code Online (Sandbox Code Playgroud) aether有一个函数来获取给定工件的所有版本,如下所示:
org.sonatype.aether.impl.VersionRangeResolver.resolveVersionRange(
RepositorySystemSession session,
VersionRangeRequest request )
Run Code Online (Sandbox Code Playgroud)
是否有一个以太函数来列出存储库中的所有工件?
或者如何获得该列表?
ps:我知道大多数maven存储库提供了一个人类可读的索引,你可以解析和爬行.这不是一个安全的解决方案,只是一种解决方法,我不是在寻找这种类型的解决方案.