[ome-devel] Add a file annotation
jburel
j.burel at dundee.ac.uk
Fri Feb 20 11:58:36 GMT 2009
Hi Matthias
Follow some code from the OMEROGateway (shoola code base)
You need to use the rawfile store
File file
RawFileStorePrx store = getRawFileService();
OriginalFile save = null;
Format f = (Format)
getQueryService().findByString(Format.class.getName(), "value", format);
oFile = new OriginalFileI();
oFile.setName(omero.rtypes.rstring(file.getName()));
oFile.setPath(omero.rtypes.rstring(file.getAbsolutePath()));
oFile.setSize(omero.rtypes.rlong(file.length()));
oFile.setSha1(omero.rtypes.rstring("pending"));
oFile.setFormat(f);
save = (OriginalFile) saveAndReturnObject(oFile, null);
store.setFileId(save.getId().getValue());
byte[] buf = new byte[INC];
FileInputStream stream = null;
try {
stream = new FileInputStream(file);
long pos = 0;
int rlen;
ByteBuffer bbuf;
while ((rlen = stream.read(buf)) > 0) {
store.write(buf, pos, rlen);
pos += rlen;
bbuf = ByteBuffer.wrap(buf);
bbuf.limit(rlen);
}
stream.close();
} catch (Exception e) {
try {
if (stream != null) stream.close();
} catch (Exception ex) {}
throw new DSAccessException("Cannot upload the file with path " +
file.getAbsolutePath(), e);
}
Then you link the original file to the file annotation.
FileAnnotation fa;
fa.setFile(of)
and save the file annotation
Regards
jmarie
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.openmicroscopy.org.uk/pipermail/ome-devel/attachments/20090220/dd9aca72/attachment.htm
More information about the ome-devel
mailing list