我有一个模板:
<xsl:template match="paragraph">
...
</xsl:template>
Run Code Online (Sandbox Code Playgroud)
我称之为:
<xsl:apply-templates select="paragraph"/>
Run Code Online (Sandbox Code Playgroud)
对于我需要做的第一个元素:
<xsl:template match="paragraph[1]">
...
<xsl:apply-templates select="."/><!-- I understand that this does not work -->
...
</xsl:template>
Run Code Online (Sandbox Code Playgroud)
如何从模板中调用<xsl:apply-templates select="paragraph"/>
(第一个元素paragraph
)<xsl:template match="paragraph[1]">
?
到目前为止,我有一个像循环.
我解决了这个问题(但我不喜欢):
<xsl:for-each select="paragraph">
<xsl:choose>
<xsl:when test="position() = 1">
...
<xsl:apply-templates select="."/>
...
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="."/>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
Run Code Online (Sandbox Code Playgroud) 我从java调用一个本机函数返回一个byte [].
以下是JNI代码的片段
jbyteArray result;
jbyte *resultType;
result = (*env)->NewByteArray(env, 1);
*resultType =7;
(*env)->SetByteArrayRegion(env, result, 0, 1, resultType);
return result;
Run Code Online (Sandbox Code Playgroud)
这应该创建一个长度为1的字节数组,并将值7存储在其中.我的实际代码应该创建一个动态长度的数组,但是我遇到了与此示例中相同的问题.
现在来解决我的问题 - 在java中,从JNI返回的数组为null.我究竟做错了什么?任何帮助将不胜感激.
(这是gcc 3.3.1
(长篇故事 - 责怪NIST)关于Cygwin.)
我已经编译了一些源文件gcc -c -fPIC ...
来获取.o文件.
然后我做了:
$ gcc -shared -o foo.dll foo.o bar.o
Run Code Online (Sandbox Code Playgroud)
但是当我去使用它时:
$ gcc -o usefoo.exe usefoo.o -L. -lfoo
usefoo.o:usefoo.cpp:(.text+0x2e0): undefined reference to `_get_template_size'
collect2: ld returned 1 exit status
Run Code Online (Sandbox Code Playgroud)
但是,如果使用相同的.o文件,我会这样做:
$ ar rcs libfoo-static.a foo.o bar.o
Run Code Online (Sandbox Code Playgroud)
反对的链接是成功的:
$ gcc -o foo.exe foo.o -L. -lfoo-static
Run Code Online (Sandbox Code Playgroud)
对我来说奇怪的是,正如你在下面看到的那样,有问题的引用存在于.a和.dll中.那么为什么链接到.dll时出错呢?
可以在共享库中找到参考:
$ nm foo.dll|grep get_template
1001b262 T _get_template_size
Run Code Online (Sandbox Code Playgroud)
它也在静态库中:
$ nm libfoo-static.a |grep get_template
00000352 T _get_template_size
Run Code Online (Sandbox Code Playgroud)
这里是对想要使用该函数的文件中生成的符号的引用:
$ nm usefoo.o
00000000 b …
Run Code Online (Sandbox Code Playgroud) 我使用BouncyCastle API和bcprov-jdk15on-147罐子生成CSR.
CertificationRequestInfo certInfo = new CertificationRequestInfo(subject, subKeyInfo, new DERSet(attribute));
org.bouncycastle.operator.ContentSigner sigGen = null;
sigGen = new JcaContentSignerBuilder("SHA1withRSA").setProvider("BC").build(privateKey);
org.bouncycastle.asn1.pkcs.CertificationRequest ctest = new org.bouncycastle.asn1.pkcs.CertificationRequest(certInfo,sigAlgName,new DERBitString(sigGen.getSignature()));
Run Code Online (Sandbox Code Playgroud)
我将这个obejct传递给我的调用函数:
GenerateCSR gcsr = GenerateCSR.getInstance();
System.out.println("Public Key:\n"+gcsr.getPublicKey().toString());
System.out.println("Private Key:\n"+gcsr.getPrivateKey().toString());
org.bouncycastle.asn1.pkcs.CertificationRequest csr = gcsr.getCSR("IMO");
System.out.println("CSR Request Generated!!");
FileWriter fcsr = new FileWriter("C:\\test.txt");
PEMWriter w1 = new PEMWriter(fcsr);
w1.writeObject(csr);
Run Code Online (Sandbox Code Playgroud)
但我得到以下例外:
Exception in thread "main" org.bouncycastle.util.io.pem.PemGenerationException: unknown object passed - can't encode.
at org.bouncycastle.openssl.MiscPEMGenerator.createPemObject(Unknown Source)"
Run Code Online (Sandbox Code Playgroud) 这是jdk1.7.0_04
.
我试图使用Collections.emptyList()
而不是new
在条件中使用我自己的空列表:
List<String> list = (anArray != null) ? Arrays.asList(anArray) : Collections.emptyList();
Run Code Online (Sandbox Code Playgroud)
但是得到以下错误:
error: incompatible types
List<String> list = (anArray != null) ? Arrays.asList(anArray) : Collections.emptyList();
^
required: List<String>
found: List<CAP#1>
where CAP#1 is a fresh type-variable:
CAP#1 extends Object from capture of ? extends Object
1 error
Run Code Online (Sandbox Code Playgroud)
我能够想到我需要改变一些事情:
List<String> list = (anArray != null) ? Arrays.asList(anArray) : Collections.<String>emptyList();
Run Code Online (Sandbox Code Playgroud)
但作为解决这个问题的一部分,我遇到了奇怪的(对我来说,无论如何)情况:
List<String> alwaysEmpty = Collections.emptyList();
Run Code Online (Sandbox Code Playgroud)
编译好,但是:
List<String> alwaysEmpty = (List<String>) Collections.emptyList();
Run Code Online (Sandbox Code Playgroud)
给出以下编译错误:
error: inconvertible types …
Run Code Online (Sandbox Code Playgroud) 我的问题:
我想连接到服务器(不限于HTTPS协议 - 可能是LDAP-over-SSL,可能是SMTPS,可能是IMAPS等),可能正在使用Java默认不信任的证书(因为它们是自签名).
所需的工作流程是尝试连接,检索证书信息,将其呈现给用户,如果他接受,则将其添加到信任库,以便将其信任.
我被困在检索证书.我有代码(请参阅帖子的末尾),我已经从这里和从有关java SSL的问题的答案指向的站点中得到了解释.代码只是创建一个SSLSocket
,启动SSL握手,并询问SSL会话Certificate[]
.当我使用已经可信任的证书连接到服务器时,代码工作正常.但是当我使用自签名证书连接到服务器时,我会得到通常的:
Exception in thread "main" javax.net.ssl.SSLHandshakeException:
sun.security.validator.ValidatorException: PKIX path building failed:
sun.security.provider.certpath.SunCertPathBuilderException: unable to
find valid certification path to requested target
at sun.security.ssl.Alerts.getSSLException(Unknown Source)
at sun.security.ssl.SSLSocketImpl.fatal(Unknown Source)
at sun.security.ssl.Handshaker.fatalSE(Unknown Source)
at sun.security.ssl.Handshaker.fatalSE(Unknown Source)
at sun.security.ssl.ClientHandshaker.serverCertificate(Unknown Source)
[etc]
Run Code Online (Sandbox Code Playgroud)
如果我运行,-Djavax.net.debug=all
我会看到JVM确实检索了自签名证书,但是在它返回证书之前,它会破坏连接以使用不受信任的证书.
看起来像鸡蛋问题.它不会让我看到证书,因为它们不受信任.但我需要看到证书能够将它们添加到信任库,以便它们可信.你怎么突破这个?
例如,如果我将程序运行为:
java SSLTest www.google.com 443
Run Code Online (Sandbox Code Playgroud)
我得到了Google正在使用的证书的打印输出.但如果我把它作为
java SSLTest my.imap.server 993
Run Code Online (Sandbox Code Playgroud)
我得到上面引用的异常.
代码:
import java.io.InputStream;
import java.io.OutputStream;
import java.security.cert.*;
import javax.net.SocketFactory;
import javax.net.ssl.*;
public class SSLTest
{
public static void …
Run Code Online (Sandbox Code Playgroud) (这是 SLES 上的 Java 8 和 Tomcat 8,FWIW。)
当我在多个线程中使用单个实例时,在初始播种后我需要多么担心性能问题SecureRandom
(特别是提供者SHA1PRNG
的算法SUN
) ?是线程安全的,因此这意味着一定程度的潜在争用?SecureRandom
SecureRandom
我在 Java 8 Javadocs 中没有看到任何讨论这一点的内容,SecureRandom
尽管我看到 Javadocs确实特别警告了跨线程Random
使用单个实例时的争用和性能下降。Random
我们正在考虑使用单个实例,因为从我们看来,在我们的方法(用于IV 生成)中SecureRandom
获取新实例的成本太高,因为如果您在使用新实例之前使用几次,那么播种开销就会杀死您。完成了。SecureRandom
encrypt()
SecureRandom
SecureRandom
或者,我们正在考虑让ThreadLocal<SecureRandom>
包含该encrypt()
方法的类有一个静态成员,以便每个SecureRandom
线程使用一个静态成员。我们故意不调用,因为如果我们走这条路线,我们实际上希望实例尽可能长时间地“存活”在 tomcat 线程中(以最小化创建ThreadLocal.remove()
新实例的次数)。SecureRandom
从这里阅读有关ThreadLocal
内存泄漏的内容后,我对这种方法有些担忧。然而,我们实际上从不重新部署 web 应用程序。它用在嵌入式系统中,当 webapp 升级时(这是整个系统升级的一部分,一年只发生几次)Tomcat 完全关闭,新的 war 文件被删除,Tomcat 重新启动。这似乎会让与 Web 应用程序相关的ThreadLocal
泄漏变得毫无意义。
那么,是否有任何关于“有争议”程度的良好数据SecureRandom
,以及对于如何SecureRandom
在重度多线程环境中最正确地使用达成共识?
这曾经可以工作,现在不起作用。我没有更改图像应该流的部分,所以我不知道为什么它不起作用。这是我的代码片段:
File f = new File(filepath);
applicantImage=new ImageDetail(filepath);
Iterator<ImageReader> readers =
ImageIO.getImageReadersBySuffix(applicantImage.getFile_extension());
ImageReader reader = readers.next();
ImageInputStream iis = ImageIO.createImageInputStream(f);
Run Code Online (Sandbox Code Playgroud)
filepath
是映像的绝对文件路径,并且已确认该映像位于服务器上的该位置。一切顺利进行,直到一切顺利ImageIO.createImageInputStream(f)
。现在回来null
了。我读了它在文件中的javadoc。那么,为什么现在返回一个null
?有人知道吗 上面发布的所有代码在我的编辑中均未更改,因此我不明白为什么更改之前有效,为什么现在不起作用。任何帮助深表感谢!谢谢!
最近我试着自己在linux平台上编写一个简单的编译器.
当谈到编译器的后端时,我决定在不使用第三方库的情况下生成ELF格式的二进制文件,例如libelf
.
相反,我想通过使用该write()
函数并控制ELF文件的所有细节,尝试将机器代码直接写入与ELF ABI 相对应的文件中.
这种方法的优点是我可以控制编译器的所有内容.
但我犹豫了.考虑到ELF ABI的详细程度,这种方式是否可行?
我希望有任何建议和指向现有的可用资源.
(这是Java 7
)
我试图在我的基类中放置一些JSON字符串生成方法,而不是在所有子类中使用几乎相同的代码.我试过的第一个天真的东西是:
public abstract class Base
{
[rest of class...]
final public <T extends Base> String toJsonString() throws IOException {
JacksonRepresentation<T> rep =
new JacksonRepresentation<>(MediaType.APPLICATION_JSON, this);
return rep.getText();
}
}
Run Code Online (Sandbox Code Playgroud)
但那不会编译,给出错误:
error: incompatible types
required: JacksonRepresentation<T>
found: JacksonRepresentation<Base>
where T is a type-variable:
T extends Base declared in method <T>toJsonString()
Run Code Online (Sandbox Code Playgroud)
所以我尝试了这个:
public abstract class Base
{
[rest of class...]
final public String toJsonString() throws IOException {
return jsonStringHelper(this);
}
private static <T extends Base> String jsonStringHelper(T object) …
Run Code Online (Sandbox Code Playgroud) java ×7
c ×2
generics ×2
bouncycastle ×1
collections ×1
cygwin ×1
elf ×1
encryption ×1
gcc ×1
jackson ×1
linker ×1
linux ×1
optimization ×1
ssl ×1
thread-local ×1
tomcat ×1
xslt ×1