Please I am quite new to java programming.I am trying to write a class to a bytearrayoutputstream, then pass this data to a simple array.
Then I read and reconstruct the class out of the byte array.
I am doing this using ObjectOutputStream and ObjectInputStream. but I don't understand why I am still getting java.io.InvalidClassException: that my class has no valid constructor. the best help I could find is at java.io.InvalidClassException: no valid constructor.
My code:
// this is the class I am writing to the ByteArrayOutputStream
public class CrtB extends X509v3CertificateBuilder implements Serializable {
private static final long serialVersionUID = 1234509876;
public CrtB(X500nEx arg0, BigInteger arg1, Date arg2, Date arg3,
X500nEx arg4, SubjectPublicKeyInfo arg5) {
super(arg0, arg1, arg2, arg3, arg4, arg5);
}
}
//this how I pass the class to the ByteArrayOutputStream and then reconstruct it
public class Testclass implements Serializable {
public CrtB getCrt(){
subpubInfo=SubjectPubInfo.getInstance(getPublicKey.getEncoded());
certbld=new CrtB(name1, serialNr, start, end,name2, subpubInfo);
return certbld; // certbld is a global variable
}
//writes to the ByteArrayOutputStream
private ByteArrayOutputStream writetoBAS(){
ByteArrayOutputStream bout=null;
try{
bout=new ByteArrayOutputStream();
ObjectOutputStream obj=new ObjectOutputStream(bout);
obj.writeObject(certbld);
obj.close();
}catch(Exception e){
e.printStackTrace();
}
return bout;
}
//read from byte array
private CrtB getbui(byte[] ar){
CrtB b=null;
try {
ByteArrayInputStream bin=new ByteArrayInputStream(ar);
ObjectInputStream oin=new ObjectInputStream(bin);
b=(CrtB)oin.readObject();
System.out.println("successfully transferred");
}catch (Exception e){
e.printStackTrace();
}
return b;
}
public static void main(String[] args) {
Testclass rqR=new Testclass();
rqR.CrtB();
byte[] br=rqR.writeBAS().toByteArray();
CrtB b=rqR.getbui(br);
}
}
Could any one help me or give me a hint.
X509v3CertificateBuilderconstructor not taking the parameters you passed in. @Kayaman Yes, sorry, I'm still waking up. - takendarkkX509v3CertificateBuilder,X500nEx, etc.) -- are these classes ones that you created in the same package, or did you import them from a library? If the later, could you include the import statements in your code? Also, you have two public classes together -- are these in the same file in your program? If they are then it won't compile. - James Dunn