Last active
December 22, 2015 07:39
-
-
Save gaul/6439757 to your computer and use it in GitHub Desktop.
Demonstrate how to call setFixedLengthStreamingMode with an int argument in Java 6 and with a long argument in Java 7.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Demonstrate how to call setFixedLengthStreamingMode with an int argument in | |
* Java 6 and with a long argument in Java 7. | |
*/ | |
import java.lang.reflect.Method; | |
import java.net.HttpURLConnection; | |
import java.net.URL; | |
public class SetFixedLengthStreamingMode { | |
private static final Method METHOD; | |
static { | |
Method method; | |
try { | |
method = HttpURLConnection.class.getMethod( | |
"setFixedLengthStreamingMode", long.class); | |
} catch (NoSuchMethodException nsme) { | |
try { | |
method = HttpURLConnection.class.getMethod( | |
"setFixedLengthStreamingMode", int.class); | |
} catch (NoSuchMethodException nsme2) { | |
throw new RuntimeException(nsme2); | |
} | |
} | |
METHOD = method; | |
} | |
public static void main(String[] args) throws Exception { | |
URL url = new URL("http://google.com/"); | |
HttpURLConnection conn = (HttpURLConnection) url.openConnection(); | |
METHOD.invoke(conn, 1); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment