hi Josh,
for the OriginalFilesService,
- Code: Select all
ome.io.nio.OriginalFilesService files = (ome.io.nio.OriginalFilesService) ome.system.OmeroContext.getManagedServerContext().getBean("/OMERO/Files");
1.1.
I don't understand the code above.
could you explain how to create an object for OriginalFilesService again?
(the first line is not able to be compiled anyway)
1.2.
what does the second line do?
for the parse function
- Code: Select all
237 protected Iterable<Reader> parse(final OriginalFile file,
238 final OriginalFilesService files,
239 final Map<String, FileParser> parsers) {
240 if (files != null && parsers != null) {
241 if (file != null && file.getMimetype() != null) {
242 String path = files.getFilesPath(file.getId());
243 String format = file.getMimetype();
244 FileParser parser = parsers.get(format);
245 if (parser != null) {
246 return parser.parse(new File(path));
247 } else {
248 parser = parsers.get("*");
249 if (parser != null) {
250 return parser.parse(new File(path));
251 }
252 }
253 }
254 }
255 return FileParser.EMPTY;
256 }
2.1.
what is the FileParser class? How can I import this class?
I was trying to understand it from
http://trac.openmicroscopy.org.uk/ome/wiki/FileParsers, but those links in the webpage are all broken.
2.2.
what is the return output of the FileParser.parse() function? is it the loaded XML file? I want to know exactly what type of the return output is, because I need to parse the XML file later. Hopefully it could be a File object. (before you suggested this, I created an empty File object and loaded the content of the original file using RawFileStorePrx and FileOutputStream like the following code, which turned out to be wrong in this purpose)
- Code: Select all
public static void downloadFile(RawFileStorePrx rawfilestore, OriginalFile originalfile, File file) throws Exception {
int INC = 262144;
Long fileId = originalfile.getId().getValue();
rawfilestore.setFileId(fileId);
Long fileSize = originalfile.getSize().getValue();
String path = file.getAbsolutePath();
int offset = 0;
int length = fileSize.intValue();//Convert.ToInt32(fileSize);//(int)fileSize;
try {
FileOutputStream stream = new FileOutputStream(file);
try {
try {
for (offset = 0; (offset+INC) < fileSize;) {
stream.write(rawfilestore.read(offset, INC));
offset += INC;
}
} finally {
stream.write(rawfilestore.read(offset, length-offset));
stream.close();
}
} catch (Exception e) {
if (stream != null) stream.close();
if (file != null) file.delete();
}
} catch (IOException e) {
if (file != null) file.delete();
//closeService(rawfilestore); //store.close()
rawfilestore.close();
// throw new DSAccessException("Cannot create file " +path, e);
}
rawfilestore.close();//closeService(store); // store.close() throws an exception
}
3.
Since this code is the server side code, I'm not sure how I can easily debug this. Do you have any method that I can debug the code like launching the script from server? (otherwise, I dont have any clue or error message when it does not work)