1 package org.robsite.extension.rss; 2 3 /*** 4 * Utilities for temporarily setting the HTTP timeout. 5 * 6 * @author brian_duff@sourceforge.net 7 * @version $Revision: 1.1.1.1 $ 8 */ 9 public final class HTTPUtil 10 { 11 private static String _oldConnectTimeout = null; 12 private static String _oldReadTimeout = null; 13 14 /*** 15 * This class cannot be instantiated. 16 */ 17 private HTTPUtil() {} 18 19 /*** 20 * Set the HTTP timeout to the specified number of milliseconds. 21 * 22 * @param timeout the timeout to use in milliseconds. 23 */ 24 public static void setHTTPTimeout( int milliseconds ) 25 { 26 _oldConnectTimeout = 27 System.getProperty( "sun.net.client.defaultConnectTimeout" ); 28 _oldReadTimeout = 29 System.getProperty( "sun.net.client.defaultReadTimeout" ); 30 31 System.setProperty( "sun.net.client.defaultConnectTimeout", 32 String.valueOf( milliseconds ) ); 33 System.setProperty( "sun.net.client.defaultReadTimeout", 34 String.valueOf( milliseconds ) ); 35 } 36 37 /*** 38 * Reset the HTTP timeout to its default value. 39 */ 40 public static void resetHTTPTimeout() 41 { 42 if ( _oldConnectTimeout == null ) 43 { 44 System.setProperty( "sun.net.client.defaultConnectTimeout", "-1" ); 45 } 46 else 47 { 48 System.setProperty( "sun.net.client.defaultConnectTimeout", 49 _oldConnectTimeout ); 50 _oldConnectTimeout = null; 51 } 52 53 if ( _oldReadTimeout == null ) 54 { 55 System.setProperty( "sun.net.client.defaultReadTimeout", "-1" ); 56 } 57 else 58 { 59 System.setProperty( "sun.net.client.defaultReadTimeout", 60 _oldReadTimeout ); 61 _oldReadTimeout = null; 62 } 63 } 64 }