[jboss-svn-commits] JBL Code SVN: r8787 - labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/couriers.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Wed Jan 10 05:10:09 EST 2007
Author: mark.little at jboss.com
Date: 2007-01-10 05:10:06 -0500 (Wed, 10 Jan 2007)
New Revision: 8787
Modified:
labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/couriers/CourierUtil.java
Log:
fixed corrupted stream bug.
Modified: labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/couriers/CourierUtil.java
===================================================================
--- labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/couriers/CourierUtil.java 2007-01-09 22:46:34 UTC (rev 8786)
+++ labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/couriers/CourierUtil.java 2007-01-10 10:10:06 UTC (rev 8787)
@@ -31,6 +31,7 @@
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
+import java.io.StreamCorruptedException;
import java.lang.reflect.Method;
import java.net.URISyntaxException;
import java.util.ArrayList;
@@ -181,6 +182,8 @@
{
writer = new FileOutputStream(tmpFile);
new ObjectOutputStream(writer).writeObject(serial);
+
+ writer.flush();
}
finally
{
@@ -197,22 +200,50 @@
{
FileInputStream reader = null;
Serializable serial = null;
- try
+ int retry = 10; // TODO magic number
+
+ /*
+ * Just because a file is in the file system doesn't mean it
+ * has been completely written!
+ */
+
+ while (retry > 0)
{
- reader = new FileInputStream(from);
- serial = (Serializable) new ObjectInputStream(reader).readObject();
- return Util.deserialize(serial);
+ try
+ {
+ reader = new FileInputStream(from);
+ serial = (Serializable) new ObjectInputStream(reader).readObject();
+ return Util.deserialize(serial);
+ }
+ catch (StreamCorruptedException ex)
+ {
+ // file present but not ready to read - wait
+
+ retry--;
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+
+ _logger.debug(from+" "+e.toString());
+ throw new CourierException(e);
+ }
+ finally
+ {
+ if (null != reader)
+ reader.close();
+ }
+
+ try
+ {
+ Thread.sleep(1000); // TODO magic number
+ }
+ catch (Exception ex)
+ {
+ }
}
- catch (Exception e)
- {
- _logger.debug(e);
- throw new CourierException(e);
- }
- finally
- {
- if (null != reader)
- reader.close();
- }
+
+ throw new IOException();
}
public static byte[] bytesFromLocalFile(File from) throws IOException
More information about the jboss-svn-commits
mailing list