[Swift-commit] cog r3898

swift at ci.uchicago.edu swift at ci.uchicago.edu
Thu May 8 18:50:03 CDT 2014


------------------------------------------------------------------------
r3898 | hategan | 2014-05-08 18:48:41 -0500 (Thu, 08 May 2014) | 1 line

patch to use compression in GSS streams when 1.7 style constructor for DeflaterOutputStream is available but still allow compilation on 1.6
------------------------------------------------------------------------
Index: modules/provider-coaster/src/org/globus/cog/coaster/channels/GSSChannel.java
===================================================================
--- modules/provider-coaster/src/org/globus/cog/coaster/channels/GSSChannel.java	(revision 3897)
+++ modules/provider-coaster/src/org/globus/cog/coaster/channels/GSSChannel.java	(working copy)
@@ -12,6 +12,7 @@
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
+import java.lang.reflect.Constructor;
 import java.net.URI;
 import java.util.zip.DeflaterOutputStream;
 import java.util.zip.InflaterInputStream;
@@ -36,11 +37,21 @@
 
 public class GSSChannel extends AbstractTCPChannel {
 	private static final Logger logger = Logger.getLogger(GSSChannel.class);
-
+	
 	private static final boolean streamCompression;
 	
 	static {
-	    streamCompression = "true".equals(System.getProperty("gss.channel.compression.enabled"));
+	    boolean st;
+	    try {
+	        DeflaterOutputStream.class.getConstructor(OutputStream.class, boolean.class);
+	        st = true;
+	    }
+	    catch (Exception e) {
+	        logger.info("Exception caught trying to find DeflaterOutputStream(OutputStream, boolean) " +
+	        		"constructor. Disabling stream compression.");
+	        st = false;
+	    }
+	    streamCompression = st;
 	}
 
 	private GssSocket socket;
@@ -178,7 +189,21 @@
     @Override
     protected void setOutputStream(OutputStream outputStream) {
         if (streamCompression) {
-            super.setOutputStream(new DeflaterOutputStream(outputStream, true));
+            try {
+                /*
+                 * Instantiate DeflaterOutputStream(out, syncFlush) using reflection
+                 * since it is only available in 1.7, but we still want this
+                 * to compile on 1.6. 
+                 */
+                Constructor<DeflaterOutputStream> cons = 
+                    DeflaterOutputStream.class.getConstructor(OutputStream.class, boolean.class);
+                DeflaterOutputStream dos = cons.newInstance(outputStream, true);
+                super.setOutputStream(dos);
+            }
+            catch (Exception e) {
+                logger.warn("Failed to instantiate DeflaterOutputStream", e);
+                throw new RuntimeException(e);
+            }
         }
         else {
             super.setOutputStream(outputStream);



More information about the Swift-commit mailing list