Posted by
P. Daniel Tyreus on
Jul 11, 2005; 6:59pm
URL: http://imagej.273.s1.nabble.com/ImagePlus-into-postgresql-tp3705272p3705273.html
You can do it this way, but you are not using piped streams correctly. They
should be run in threads. See this brieft article for more information:
http://www.devx.com/tips/Tip/13013Regards,
Daniel
CircuSoft Instrumentation
-----Original Message-----
From: ImageJ Interest Group [mailto:
[hidden email]] On Behalf Of Albert
Sent: Monday, July 11, 2005 9:26 AM
To:
[hidden email]
Subject: ImagePlus into postgresql
Hi all,
I have succeded in saving and reading an ImagePlus as a Tiff into a
postgresql database using standard java 1.4.2 and ImageJ classes, but there
are problems: when read, the ImagePlus is black. So either it was not
properly saved, which is what I suspect, or not properly read.
Reading is easy, with the Opener.openAsTiff(Inputstream is, String name),
but the saving can be problematic: I need an InputStream for the
java.sql.PreparedStatement(int, InputStream, int), but the ij.io.TiffEncoder
writes bytes to a DataOutputStream, not to an InputStream! So I'm piping it
one into the other, and I suspect the problems lay at this point, in the
concurrent thread that is writing into the DataOutputStream that
encapsulates the PipedInputStream:
PipedInputStream i_stream = new PipedInputStream(); DataOutputStream
o_stream = new DataOutputStream(new BufferedOutputStream(new
PipedOutputStream(i_stream))); FileInfo fi = img.getFileInfo(); TiffEncoder
te = new TiffEncoder(fi); new ReadOutputStream(te, o_stream).start();
the class ReadOutputStream has this run() method:
public void run() {
try{
//write bytes from TiffEncoder to the
DataOutputStream
te.write(o_stream);
//write bytes to the underlying output stream
o_stream.flush();
//o_stream.close();
}catch(IOException ioe) {
IJ.log("Can't write to output stream:\n" + ioe);
}
}
If the o_stream.flush() is not there, the writing does not happen at
all. But then could this flush() be cutting it short?
Does anyone have experience with this and provide some hints?
What is the best, fastest and easiest way to put an ImagePlus into an
InputStream?
Thanks for any help.
Albert
Albert Cardona
Institute of Neuroinformatics Tel : +41 1 635 3052
University/ETH Zurich Fax : +41 1 635 3053
Winterthurerstrasse 190 acardona (at) ini phys ethz ch
Zurich 8057, Switzerland www.ini.unizh.ch