I use the following code to copy a javax.sound.midi.Sequence
:
private Object copyObject(Object objSource)
{
Object objDest=null;
try
{
ByteArrayOutputStream bos=new ByteArrayOutputStream();
ObjectOutputStream oos=new ObjectOutputStream(bos);
oos.writeObject(objSource);
oos.flush();
oos.close();
bos.close();
byte[] byteData=bos.toByteArray();
ByteArrayInputStream bais=new ByteArrayInputStream(byteData);
try { objDest=new ObjectInputStream(bais).readObject(); }
catch (ClassNotFoundException e) { e.printStackTrace(); }
}
catch (IOException e) { e.printStackTrace(); }
return objDest;
}
javax.sound.midi.Sequence sequence;
...
javax.sound.midi.Sequence newSequence=(Sequence)copyObject(sequence);
I got the following error :
java.io.NotSerializableException: javax.sound.midi.Sequence
What's the proper way to do this ?