What the heck? I have tested this thoroughly and somewhere between serializing an object out to my file and reading it back in again my data is changing! I'll paste my code below.
What I've already done is the following:
I made a vector. Each time I loop through the code that puts stuff in the vector I clear out the vector. That seems to work. After the vector is made each time, I print it out to a file to see that each vector is different, as it should be. That worked. Then I tried printing out the vector on the line immediately before "writeObject". That worked. Then I tried printing out the vector on the line immediately after "writeObject". That worked too. Then I used the debugger to trace the contents of the vector on the line containing "writeObject". Beautiful, each time the vector is different. So I am thoroughly convinced that I ought to be getting different vectors serialized to my file.
Then when I read things back in from the file the vector is always the same. I can tell that from the debugger and printing the value to a file. I am pretty sure I am reading from the same file I am writing to because when I started having problems I added in a "writeInt" immediately before the "writeObject". This int is a counter. When I read back in with "readInt" the "readObject" it gets the correct number of integers, counting up to 5808, like it's supposed to. So I am convinced that I am progressing through the file holding the serialized data. But even though the int changes, the vector doesn't. I have asked some coworkers but no one knows the answer. DOH!
Any hint would be helpful.
Thanks,
Rebecca
void FindSDProducts(Vector sdMatrices,
String wavFileName) throws IOException {
//Find the product of pair combinations of vectors of numbers which are the standard deviation from the mean energy for each segment in a section.
int counter = 0;
int dotPtr = wavFileName.indexOf(".");
wavFileName = wavFileName.substring(0, dotPtr);
wavFileName = wavFileName.concat(".SDProducts");
FileOutputStream fos = new FileOutputStream(wavFileName);
ObjectOutputStream outSDProducts = new ObjectOutputStream(fos);
Vector innerVector = new Vector();
for (int i = 0; i < sdMatrices.size(); i++) {
innerVector.removeAllElements();
Matrix x = (Matrix) sdMatrices.elementAt(i);
for (int j = 0; j < sdMatrices.size(); j++) {
Matrix y = (Matrix) sdMatrices.elementAt(j);
Matrix xy = new Matrix(1, x.getColumnDimension());
for (int k = 0; k < x.getColumnDimension(); k++) {
double xElement = x.get(0, k);
double yElement = y.get(0, k);
double xyElement = xElement * yElement;
xy.set(0, k, xyElement);
}
innerVector.add(j, xy);
out.flush();
}
counter++;
for (int m = 0; m < 4; m++) {
out.print("\n\t\tInner Vector just after it's been put in: " + m +
" \n\t\t");
Matrix q = (Matrix) innerVector.elementAt(m);
for (int n = 0; n < q.getColumnDimension(); n++) {
out.print(q.get(0, n) + " ");
}
}
outSDProducts.writeInt(counter);
outSDProducts.writeObject(innerVector);
innerVector.removeAllElements();
boolean stuff = innerVector.isEmpty();
//System.err.print(counter + " ");
out.flush();
}
outSDProducts.close();
Vector thisVector = null;
int counter2 = 0;
boolean eof = false;
out.println("Here it is: ");
try {
System.err.println("reading from " + wavFileName);
FileInputStream fis = new FileInputStream(wavFileName);
ObjectInputStream in = new ObjectInputStream(fis);
while (!eof) {
counter2 = in.readInt();
thisVector = (Vector) in.readObject();
out.println("\n" + counter2);
//for (int m = 0; m < thisVector.size(); m++) {
for (int m = 0; m < 4; m++) {
out.print("\n\t\tSD Inner Vector matrix at: " + m + " \n\t\t");
Matrix x = (Matrix) thisVector.elementAt(m);
for (int n = 0; n < x.getColumnDimension(); n++) {
out.print(x.get(0, n) + " ");
out.flush();
}
x = null;
}
//thisVector.clear();
}
in.close();
}
catch (EOFException ex) {
eof = true;
}
catch (IOException ex) {
out.println("Error reading
pattern serialization file " + ex);
}
catch (ClassNotFoundException ex) {
out.println("Error reading pattern serialization file " + ex);
}
}