[英]Why does ASN1Object.getEncoded() throw IOException in BouncyCastle?
ASN1Object
(以及所有繼承它的類)具有一個getEncoded()
方法,該方法應返回DER / BER編碼。 但是,它被標記為引發IOException。
我希望編碼可以在內存中完成,而無需執行任何IO。 此外,這需要拋出或嘗試捕獲來使周圍的代碼復雜化。
為什么在那里throws IOException
?
public byte[] getEncoded()
throws IOException
{
ByteArrayOutputStream bOut = new ByteArrayOutputStream();
ASN1OutputStream aOut = new ASN1OutputStream(bOut);
aOut.writeObject(this); // This is where the throws happens.
return bOut.toByteArray();
}
ASN1OutputStream.writeObject
:
public void writeObject(
ASN1Encodable obj)
throws IOException
{
if (obj != null)
{
obj.toASN1Primitive().encode(this);
}
else
{
throw new IOException("null object detected");
}
}
除非子類重寫了getEncoded
,否則在此上下文中的IOException
意味着所涉及的一個或多個對象為null。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.