Java Code Examples for java.net.HttpURLConnection.getClass()

The following are Jave code examples for showing how to use getClass() of the java.net.HttpURLConnection class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: chromium-net-for-android   File: CronetHttpURLConnectionTest.java   Source Code and License Vote up 7 votes
@SmallTest
@Feature({"Cronet"})
@OnlyRunCronetHttpURLConnection
public void testSetFixedLengthStreamingModeLong() throws Exception {
    URL url = new URL(NativeTestServer.getEchoBodyURL());
    HttpURLConnection connection =
            (HttpURLConnection) url.openConnection();
    connection.setDoOutput(true);
    connection.setRequestMethod("POST");
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
        String dataString = "some very important data";
        byte[] data = dataString.getBytes();
        Class<?> c = connection.getClass();
        Method method = c.getMethod("setFixedLengthStreamingMode",
                new Class[] {long.class});
        method.invoke(connection, (long) data.length);
        OutputStream out = connection.getOutputStream();
        out.write(data);
        assertEquals(200, connection.getResponseCode());
        assertEquals("OK", connection.getResponseMessage());
        assertEquals(dataString, TestUtil.getResponseAsString(connection));
        connection.disconnect();
    }
}