01: package com.completex.objective.components.persistency.type;
02:
03: import com.completex.objective.components.persistency.OdalPersistencyException;
04:
05: import java.io.ByteArrayOutputStream;
06: import java.io.IOException;
07: import java.io.InputStream;
08: import java.sql.SQLException;
09:
10: /**
11: * @author Gennady Krizhevsky
12: */
13: public class DetachedByteArrayInputStreamTypeHandler extends
14: BlobTypeHandler {
15: public Object transformRead(Object data) throws SQLException {
16: if (data == null) {
17: return null;
18: }
19: InputStream in = (InputStream) data;
20: ByteArrayOutputStream bout;
21: try {
22: bout = new ByteArrayOutputStream(in.available());
23: } catch (IOException e) {
24: throw new OdalPersistencyException(
25: "Cannot read input stream", e);
26: }
27: BlobImpl.writeBlob(in, bout);
28: return new DetachedByteArrayInputStream(bout.toByteArray());
29: }
30: }
|