private static void consumeQuietly ( final HttpURLConnection connection ) { try { int read = 0 ; while ( read != - 1 ) { read = connection . getInputStream ( ) . read ( ) ; } connection . getInputStream ( ) . close ( ) ; read = 0 ; while ( read != - 1 ) { read = connection . getErrorStream ( ) . read ( ) ; } connection . getErrorStream ( ) . close ( ) ; connection . disconnect ( ) ; } catch ( IOException e ) { // no inputStream to close } }
Ensures that the entity content is fully consumed and the content stream if exists is closed .