2016-06-29 2 views
0

ASN1Object(およびそれを継承するすべてのクラス)は、DER/BERエンコーディングを返すと想定されるgetEncoded()メソッドを持っています。ただし、IOExceptionをスローするとマークされます。ASN1Object.getEncoded()がBouncyCastleにIOExceptionをスローするのはなぜですか?

私は、エンコードがメモリで実行され、IOが実行されないと予想しました。さらに、これはスローまたはキャッチを要求することによって周囲のコードを複雑にします。

throws IOExceptionはなぜですか?

答えて

0

ASN1Object.getEncoded

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だった関連するオブジェクトの一つ以上を意味します。

関連する問題