以下两种缓冲方法之间有什么不同(如果有的话)?
Reader r1 = new BufferedReader(new InputStreamReader(in, "UTF-8"), bufferSize);
Reader r2 = new InputStreamReader(new BufferedInputStream(in, bufferSize), "UTF-8");
Run Code Online (Sandbox Code Playgroud) 我的application.ymlSpring Boot应用程序有一个配置文件,它定义了两个配置文件(如文档中所述).
启用生产配置文件后,我想将http.maxConnections系统属性设置为自定义值,例如
spring:
profiles:
active: dev
---
spring:
profiles: dev
---
spring:
profiles: production
http:
maxConnections: 15
Run Code Online (Sandbox Code Playgroud)
但这实际上并没有设置系统级属性; 它似乎只是创建一个应用程序级属性.我在比较启动时通过http:// locahost:8080/env和JMX控制台验证了这一点
java -jar -Dspring.profiles.active=production myapp.jar
Run Code Online (Sandbox Code Playgroud)
与
java -Dhttp.maxConnections=15 myapp.jar
Run Code Online (Sandbox Code Playgroud)
我想我可以@Conditional在"生产"配置文件中创建一个bean,它System.setProperty根据我的application.yml-defined属性以编程方式调用,但是单独通过配置文件有更简单的方法吗?
我有一个复杂的html表单,使用java脚本动态创建.
我想在java中将键值对的映射作为Map并存储它们.
这是我的控制器来获取提交的数据.
@RequestMapping(value="/create", method=RequestMethod.POST,
consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
public String createRole(Hashmap<String, Object) keyVals) {
....
}
Run Code Online (Sandbox Code Playgroud)
但我的地图是空的.
如何在Spring mvc控制器中将表单数据作为名称 - 值对的映射?
我正在尝试readAttributes使用 groovy 的metaClass约定来模拟静态方法之一,但实际方法被调用。
这就是我嘲笑静态函数的方式:
def "test"() {
File file = fold.newFile('file.txt')
Files.metaClass.static.readAttributes = { path, cls ->
null
}
when:
fileUtil.fileCreationTime(file)
then:
1 * fileUtil.LOG.debug('null attribute')
}
Run Code Online (Sandbox Code Playgroud)
我在这里做错了吗?
我的java方法
public Object fileCreationTime(File file) {
try {
BasicFileAttributes attributes = Files.readAttributes(file.toPath(), BasicFileAttributes.class);
if(attributes == null) {
LOG.debug("null attribute");
}
//doSomething
} catch (IOException exception) {
//doSomething
}
return new Object();
}
Run Code Online (Sandbox Code Playgroud) 我在AngularJS 2中有一个基类,restClient使用这个方法从API调用数据:
public getInfoDataBooleanRequest(url: string): InfoDataBoolean {
return this.http.get(this.urlApiPrefix + url, this.createRequestOptions())
.toPromise()
.then(response => <InfoDataBoolean>response.json())
.catch(this.handleError);
}
Run Code Online (Sandbox Code Playgroud)
其中InfoDataBoolean是一个具有两个属性的类:
export class InfoDataBoolean {
public data: boolean;
public error: string;
}
Run Code Online (Sandbox Code Playgroud)
我有另一个课,我打电话给我的服务方法.这个调用在一个方法里面,我想从InfoDataBoolean返回数据,而不是像这样的类InfoDataBoolean.
public isLogged(): boolean {
return this.getInfoDataBooleanRequest('islogged').then(x => {
let result: InfoDataBoolean = x;
if(result.error !== "1") {
console.log('Success is failed');
return false;
}
return result.data;
});
}
Run Code Online (Sandbox Code Playgroud)
输出console.log(isLogged()):
ZoneAwarePromise {__ zone_symbol__state:null,__ zone_symbol__value:Array [0]}
但是,我想回到true或false从我的方法isLogged().
我怎样才能做到这一点?
我想知道如何使用 Groovy/Spock 模拟类中的某些私有变量。假设我们有这样的代码:
public class Car {
private Engine engine;
public void drive(){
System.out.println("test");
if (engine.isState()) {
// Do something
} else {
// Do something
}
}
}
Run Code Online (Sandbox Code Playgroud)
在 Mockito 中我可以写:
@Mock
private Engine engine;
@InjectMocks
private Car car = new Car();
@Test
public void drive() {
when(engine.isState()).thenReturn(true);
car.drive();
}
Run Code Online (Sandbox Code Playgroud)
但我不知道如何在 Spock 中做同样的事情。@InjectMocksSpock 中相当于什么?
我正在使用Selenium和Spock来测试我的应用程序.运行需要来自Maven或我的IDE的系统属性的测试就像一个魅力,但Gradle正在获取空值.
@Shared
private int waitTimeout = System.getProperty("waitTimeout", "10").toInteger()
@Shared
protected String apolloURL = System.getProperty("apolloURL")
Run Code Online (Sandbox Code Playgroud)
也许我做错了什么?
当我打开Chrome(v35)DevTools并检查一个对象时,控制台可以向我展示嵌套在函数中的东西,包括标记为""函数范围"的东西.
例如,在查看stackoverflow.com时,我可以看到有一个$包含另一个函数的全局对象Callbacks.Callbacks同样$,具有包含Closure和的功能范围Global.

window.$.Callbacks.????chrome.function???(window.$.Callbacks)我问的原因是因为我正在寻找内存泄漏,并希望根据对象类型和属性名称搜索函数闭包中保存的对象.
我正在尝试将我的第一个Gradle项目上载到Maven Central。为此,我遵循了Sonatype的文档,并创建了一个uploadArchives生成元数据的任务。
uploadArchives {
repositories {
mavenDeployer {
beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }
repository(url: "https://oss.sonatype.org/service/local/staging/deploy/maven2/") {
authentication(userName: ossrhUsername, password: ossrhPassword)
}
snapshotRepository(url: "https://oss.sonatype.org/content/repositories/snapshots/") {
authentication(userName: ossrhUsername, password: ossrhPassword)
}
...etc. etc.
Run Code Online (Sandbox Code Playgroud)
该任务引用了两个属性,“ ossrhUsername”和“ ossrhPassword”,我应该在其中定义它们gradle.properties;但是,如果我没有gradle.properties这些属性,则即使对于非uploadArchives任务,构建也会因错误而失败。
$ gradlew test
Run Code Online (Sandbox Code Playgroud)
无法获得类型为org.gradle.api.publication.maven.internal.deployer.DefaultGroovyMavenDeployer的对象的未知属性'ossrhUsername'。
我希望构建成功(uploadArchives当然除了任务之外)而不必在gradle.properties文件中定义这些属性。
我该怎么做呢?
仅为pom.xmlMaven Central上传管理一个单独的目录会更简单吗?
编辑识别出的潜在重复项是关于将凭证外部化的地方。我的问题是,即使没有将凭据外部化,如何确保Gradle构建仍能成功执行gradle.properties。我希望其他人能够克隆存储库并执行Gradle,而不必定义OSSRH凭证属性。
给定一个序列序列的类型,如何将其转换为单个扁平的序列类型?考虑以下Ceylon代码:
Integer[] range(Integer max) {
return [ for (idx in 1..max) idx ];
}
Integer[] prod(Integer max, Integer occurrences) {
Integer[][] nestedSequence = [for (occurrence in 1..occurrences) range(max)];
return // ??? something to produce a flattened sequence
}
assert (prod(2, 2) == [1, 2, 1, 2]);
Run Code Online (Sandbox Code Playgroud)
我是第一次尝试使用Ceylon,并在教程和API文档中摸索着.该解压方法看起来有点接近我所需要的,但不完全是.
我正在尝试从原始数组中创建一个List
int[] values={4,5,2,3,42,60,20};
List<Integer> greaterThan4 =
Arrays.stream(values)
.filter(value -> value > 4)
.collect(Collectors.toList());
Run Code Online (Sandbox Code Playgroud)
但是最后一个函数collect给了我一个错误,因为它需要其他参数.它需要3个参数Supplier,ObjIntConsumer和BiConsumer.
当我看到只是使用collect(Collectors.toList());并获取列表的不同示例时,我不明白为什么它需要3个参数.
我做错了什么?
我有一个Spock规范来测试一个需要的方法java.util.Date.
def "special dates are identified correctly"() {
expect:
isSpecialDay(Date.parse('yyyy/MM/dd', date)) == special
where:
date | special
'2010/01/01' | false
'2011/01/01' | true
'2012/01/01' | true
'2013/01/01' | false
'2014/01/01' | true
// and lots more...
}
Run Code Online (Sandbox Code Playgroud)
我想确保TimeZone对我的方法实现没有影响(即2011年1月1日是特殊的,无论我是在EST还是GMT或其他什么).有没有办法可以在一次运行中重复执行测试方法,每次执行时使用不同的默认时区?
我可以在TimeZone的"where"块中添加第三列,但是额外的维度会使表格太大而不符合我的喜好.
目前,我在每个测试运行中设置一个随机默认值,但我不喜欢我的测试不可重复的事实,如果出现故障,则在断言消息中不捕获有问题的TimeZone.
@Shared TimeZone defaultTz = TimeZone.getDefault()
def setupSpec() {
def tzIds = TimeZone.getAvailableIDs()
def randomTzId = tzIds[new Random().nextInt(tzIds.length)]
def randomTz = TimeZone.getTimeZone(randomTzId)
println "Using TimeZone $randomTz for test spec"
TimeZone.setDefault(TimeZone.getTimeZone(randomTzId));
}
def cleanupSpec() {
TimeZone.setDefault(defaultTz)
}
Run Code Online (Sandbox Code Playgroud) java ×5
spock ×4
groovy ×3
gradle ×2
unit-testing ×2
angular ×1
buffering ×1
ceylon ×1
java-8 ×1
java-io ×1
java-stream ×1
javascript ×1
maven ×1
mockito ×1
scope ×1
selenium ×1
sequence ×1
spring ×1
spring-boot ×1
spring-mvc ×1
timezone ×1