Liberty에서, 각 DataHandler 오브젝트를 한 번만 출력 스트림에 쓸 수 있습니다. DataHandler 오브젝트를 OutputStream 오브젝트에 두 번 이상 쓰면 비어 있는 파일이 생깁니다. javax.activation.DataHandler.writeTo(OutputStream) 메소드를 호출한 후,
DataHandler 오브젝트를 다른 메소드에 전달하고 리턴하거나 향후에 사용하도록 저장할 수 없습니다.
임시 해결책으로, 새 DataHandler 오브젝트를 작성하고
writeTo 메소드를 통해 기존의 DataHandler 오브젝트에서 이미 검색된 컨텐츠로 DataHandler 오브젝트를 초기화할 수 있습니다. 예제:
< span class="Code"> < span class= "JavaType"> 파일 < /span> f = < span class="JavaKeyword"> 새 < /span> 파일 ("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;