小编ata*_*lor的帖子

如何在groovy中使用SSL与自签名证书?

我有一些资源,我必须使用SSL来访问使用自签名证书.通常,大多数工具都有一个简单的设置,允许无错误地访问这些工具或只是警告.但是,使用JVM执行此操作的正确方法似乎是将签名证书作为CA导入密钥库.

我有一个我想要使用的groovy脚本,但我更喜欢我的脚本在任何任何JVM上独立工作而无需修改密钥库或分发新的密钥库.有没有简单的方法来覆盖认证验证?

ssl groovy self-signed ssl-certificate

12
推荐指数
2
解决办法
2万
查看次数

在groovy中从Set中提取单个值的最佳方法是什么?

如果我知道包含单个元素的Set,那么提取它的最佳方法是什么?我能想到的最好的是这个,但它并不觉得非常时髦:

set = [1] as Set
e = set.toList()[0]
assert e == 1
Run Code Online (Sandbox Code Playgroud)

如果我正在处理一个列表,我有很多很好的方法来获取元素,其中没有一个似乎与集合一起使用:

def list = [1]
e = list[0]
(e) = list
e = list.head()
Run Code Online (Sandbox Code Playgroud)

groovy set

12
推荐指数
2
解决办法
1万
查看次数

如何表示一个空的InputStream

我正在减少InputStreams像这样的流:

InputStream total = input.collect(
    Collectors.reducing(
        empty,
        Item::getInputStream, 
        (is1, is2) -> new SequenceInputStream(is1, is2)));
Run Code Online (Sandbox Code Playgroud)

为了身份InputStream,我正在使用:

InputStream empty = new ByteArrayInputStream(new byte[0]);
Run Code Online (Sandbox Code Playgroud)

这有效,但有没有更好的方法来表示空InputStream

java inputstream java-stream

12
推荐指数
3
解决办法
7246
查看次数

在Boost.Python中公开指针

我有这个非常简单的C++类:

class Tree {
    public:
        Node *head;
};
BOOST_PYTHON_MODULE(myModule)
{

   class_<Tree>("Tree")
        .def_readwrite("head",&Tree::head)
    ;

}
Run Code Online (Sandbox Code Playgroud)

我想从Python访问head变量,但我看到的消息是:

No to_python (by-value) converter found for C++ type: Node*
Run Code Online (Sandbox Code Playgroud)

根据我的理解,这是因为Python没有指针的概念,所以这种情况很糟糕.如何从Python访问head变量?

我知道我应该使用封装,但我目前仍然需要一个非封装解决方案.

c++ python boost boost-python

11
推荐指数
1
解决办法
2446
查看次数

我应该使用托管版本的JQuery吗?哪一个?

我应该使用jquery的本地副本,还是应该链接到Google或Microsoft提供的副本?我主要关注速度.我听说只是从其他域中提取内容可以获得与浏览器限制连接的方式相关的性能优势.特别是,有没有人对谷歌与微软和本地的速度和延迟进行基准测试?

此外,我是否必须同意从第三方链接的任何条件或许可?

hosting jquery

11
推荐指数
3
解决办法
1515
查看次数

将方法添加到元类

我只是在使用Groovy中的元类编程.但突然间,我遇到了一个我无法工作的小问题......

这是一个简单的脚本:

// define simple closure
def printValueClosure = {
 println "The value is: '$delegate'"
}

String.metaClass.printValueClosure = printValueClosure

// works fine
'variable A'.printValueClosure()



// define as method
def printValueMethod(String s){
 println "The value is: '$s'"
}

// how to do this!?
String.metaClass.printValueMethod = this.&printValueMethod(delegate)

'variable B'.printValueMethod()
Run Code Online (Sandbox Code Playgroud)

是否可以使用该方法,但将第一个参数设置为调用对象?使用委托似乎不起作用...不引用调用者的方法的分配是没有问题的.curry在这里工作吗?

谢谢,Ingo

methods groovy metaprogramming metaclass

9
推荐指数
1
解决办法
1万
查看次数

是否有可能在groovy中获取闭包的调用者对象?

是否有可能获得在执行上下文Object中调用a 的引用?ClosureClosure

例如:

public class Example {

    public Example(){
        def a = {return this};
        def b = [];

        b.metaClass.a = a;

        println b.a();
    }
}
Run Code Online (Sandbox Code Playgroud)

我希望这个执行返回b而不是实例Example.

groovy closures

9
推荐指数
1
解决办法
1551
查看次数

如何最好地从groovy中的键列表/值列表中获取地图?

在python中,我可以执行以下操作:

keys = [1, 2, 3]
values = ['a', 'b', 'c']
d = dict(zip(keys, values))

assert d == {1: 'a', 2: 'b', 3: 'c'}
Run Code Online (Sandbox Code Playgroud)

有没有一种很好的方法来构建一个groovy中的地图,从一个键列表和一个值列表开始?

python groovy dictionary

8
推荐指数
3
解决办法
4756
查看次数

如何模拟'新'运算符

我正在测试一些使用java库的groovy代码,我想模拟库调用,因为他们使用网络.所以测试中的代码看起来像:

def verifyInformation(String information) {
    def request = new OusideLibraryRequest().compose(information)
    new OutsideLibraryClient().verify(request)
}
Run Code Online (Sandbox Code Playgroud)

我尝试使用MockFor和StubFor,但我收到的错误如下:

No signature of method: com.myproject.OutsideLibraryTests.MockFor() is applicable for argument types: (java.lang.Class) values: [class com.otherCompany.OusideLibraryRequest]  
Run Code Online (Sandbox Code Playgroud)

我正在使用Grails 2.0.3.

testing grails groovy constructor mocking

8
推荐指数
2
解决办法
6101
查看次数

在转换的情况下Java编译时错误

下面的代码给出了编译时错误类型不匹配:无法从int转换为byte

int i = 10;
byte b = i;
Run Code Online (Sandbox Code Playgroud)

但下面没有

 final int i = 10;
 byte b = i;
Run Code Online (Sandbox Code Playgroud)

我不明白为什么编译器在最终的情况下表现?

java

8
推荐指数
1
解决办法
610
查看次数