Esamina l'utilizzo dell'oggetto javax.activation.DataHandler

In Liberty, ogni oggetto DataHandler può essere scritto in un flusso di output una sola volta. La scrittura di un oggetto DataHandler in un oggetto OutputStream più di una volta genera un file vuoto. Una volta chiamato il metodo javax.activation.DataHandler.writeTo(OutputStream), non è possibile trasferire l'oggetto DataHandler ad un altro metodo, restituirlo o memorizzarlo per un utilizzo successivo.

Come soluzione temporanea, è possibile creare un nuovo oggetto DataHandler ed inizializzare l'oggetto DataHandler con il contenuto che è già stato recuperato dall'oggetto DataHandler esistente utilizzando il metodo writeTo. Ad esempio:

< span class="Code"> < span class= "JavaType"> File < /span> f = < span class="JavaKeyword"> nuovo < /span> File ("received_image");
if (f.exists()) {
f.delete();
}

FileOutputStream fos = new FileOutputStream(f);

// Write the DataHandler object to the output stream.
img_in.writeTo(fos);

// Create a new DataHandler object and initialize it with
// the content that was retrieved using the writeTo method above.

FileDataSource fos_out = new FileDataSource(f);

DataHandler img_out = new DataHandler(fos_out);


return img_out;