[jboss-svn-commits] JBL Code SVN: r8169 - 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
Sun Dec 10 07:12:20 EST 2006


Author: estebanschifman
Date: 2006-12-10 07:12:17 -0500 (Sun, 10 Dec 2006)
New Revision: 8169

Modified:
   labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/couriers/CourierUtil.java
Log:
Fix potential bugs in CourierUtil (diffs between Linux & Windows behaviour)

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	2006-12-09 21:29:35 UTC (rev 8168)
+++ labs/jbossesb/trunk/product/core/rosetta/src/org/jboss/soa/esb/couriers/CourierUtil.java	2006-12-10 12:12:17 UTC (rev 8169)
@@ -118,9 +118,17 @@
 	{
 		File tmpFile = File.createTempFile("EsbFileCourier_", ".__esbPart",directory);
 		Serializable serial = Util.serialize(message);
-		ObjectOutputStream writer = new ObjectOutputStream(new FileOutputStream(tmpFile));
-		writer.writeObject(serial);
-		writer.close();
+		FileOutputStream writer = null;
+		try
+		{
+			writer = new FileOutputStream(tmpFile);
+			new ObjectOutputStream(writer).writeObject(serial);
+		}
+		finally 
+		{
+			if (null!=writer)
+				writer.close(); 
+		}
 		return tmpFile;
 	}
 
@@ -128,35 +136,31 @@
 		throws FileNotFoundException,IOException,ClassNotFoundException, ClassCastException
 			,ParserConfigurationException, SAXException , CourierException 
 	{
-		ObjectInputStream reader = null;
+		FileInputStream reader = null;
 		Serializable serial = null;
 		try
 		{ 
-			reader = new ObjectInputStream(new FileInputStream(from));
-			serial = (Serializable)reader.readObject(); 
+			reader = new FileInputStream(from);
+			serial = (Serializable)new ObjectInputStream(reader).readObject(); 
 		}
 		catch (Exception e)
 		{
 			_logger.debug("When this happens in Windows, file can't be renamed or deleted");
 			throw new CourierException(e);
 		}
-		finally {	reader.close(); }
+		finally 
+		{
+			if (null!=reader)
+				reader.close(); 
+		}
 		return Util.deserialize(serial);
 	}
 	
-	public static void deliverMessage(Message message)
-		throws URISyntaxException, CourierException
-	{
-		EPR toEpr = message.getHeader().getCall().getTo();
-		Courier courier = CourierFactory.getCourier(toEpr);
-		courier.deliver(message);
-	}
-
 	public static byte[] bytesFromLocalFile(File from)
 		throws IOException
 	{
-		ObjectInputStream in = new ObjectInputStream(new FileInputStream(from));
 		ByteArrayOutputStream out = new ByteArrayOutputStream();
+		FileInputStream in = new FileInputStream(from);
 		byte[] buff = new byte[1000];
 		int iQ = 0;
 		try
@@ -167,8 +171,8 @@
 		}
 		finally
 		{
-			in.close();
-			out.close();
+			if (null!=in)	in.close();
+			if (null!=out)	out.close();
 		}
 		return out.toByteArray();
 	}
@@ -176,10 +180,26 @@
 	public static void bytesToLocalFile(byte[] bytes, File to)
 		throws IOException
 	{
-		ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(to));
-		out.write(bytes);
-		out.close();
+		FileOutputStream out = null;
+		try
+		{
+			out =new FileOutputStream(to);
+			out.write(bytes);
+		}
+		finally 
+		{
+			if (null!=out)
+				out.close(); 
+		}
 	}
 	
+	public static void deliverMessage(Message message)
+		throws URISyntaxException, CourierException
+	{
+		EPR toEpr = message.getHeader().getCall().getTo();
+		Courier courier = CourierFactory.getCourier(toEpr);
+		courier.deliver(message);
+	}
+	
 	protected static Logger _logger = Logger.getLogger(CourierUtil.class);
 }




More information about the jboss-svn-commits mailing list