Send feedback
Class MockHttpURLConnection (1.42.3)
Stay organized with collections
Save and categorize content based on your preferences.
Version 1.42.3 keyboard_arrow_down
public class MockHttpURLConnection extends HttpURLConnection
Static Fields
ERROR_BUF (deprecated)
public static final byte [] ERROR_BUF
Deprecated. As of 1.20. Use #setErrorStream(InputStream) instead.
The error byte array which represents the content when the status code is greater or equal to
400
.
Field Value
public static final byte [] INPUT_BUF
Deprecated. As of 1.20. Use #setInputStream(InputStream) instead.
The input byte array which represents the content when the status code is less then
400
.
Field Value
Constructors
MockHttpURLConnection(URL u)
public MockHttpURLConnection ( URL u )
Parameter
Name Description u
URL
the URL or null
for none
Methods
public MockHttpURLConnection addHeader ( String name , String value )
Sets a custom response header.
Parameters
Returns
connect()
Overrides
Exceptions
disconnect()
Overrides
doOutputCalled()
public final boolean doOutputCalled ()
Returns whether #doOutput was called.
Returns
getChunkLength()
public int getChunkLength ()
Returns
getErrorStream()
public InputStream getErrorStream ()
Returns
Overrides
public String getHeaderField ( String name )
Parameter
Returns
Overrides
public Map<String , List<String> > getHeaderFields ()
Returns
Overrides
public InputStream getInputStream ()
Returns
Overrides
Exceptions
getOutputStream()
public OutputStream getOutputStream ()
Returns
Overrides
Exceptions
getResponseCode()
public int getResponseCode ()
Returns
Overrides
Exceptions
isSetFixedLengthStreamingModeIntCalled()
public boolean isSetFixedLengthStreamingModeIntCalled ()
Returns
isSetFixedLengthStreamingModeLongCalled()
public boolean isSetFixedLengthStreamingModeLongCalled ()
Returns
setDoOutput(boolean dooutput)
public void setDoOutput ( boolean dooutput )
Parameter
Overrides
public MockHttpURLConnection setErrorStream ( InputStream is )
Sets the error stream.
To prevent incidental overwrite, only the first non-null assignment is honored.
Parameter
Returns
setFixedLengthStreamingMode(int contentLength)
public void setFixedLengthStreamingMode ( int contentLength )
Parameter
Name Description contentLength
int
Overrides
setFixedLengthStreamingMode(long contentLength)
public void setFixedLengthStreamingMode ( long contentLength )
Parameter
Name Description contentLength
long
Overrides
public MockHttpURLConnection setInputStream ( InputStream is )
Sets the input stream.
To prevent incidental overwrite, only the first non-null assignment is honored.
Parameter
Returns
setOutputStream(OutputStream outputStream)
public MockHttpURLConnection setOutputStream ( OutputStream outputStream )
Sets the output stream or null
to throw an UnknownServiceException when #getOutputStream() is called.
By default it is null
.
Parameter
Returns
setResponseCode(int responseCode)
public MockHttpURLConnection setResponseCode ( int responseCode )
Sets the HTTP response status code.
Parameter
Name Description responseCode
int
Returns
usingProxy()
public boolean usingProxy ()
Returns
Overrides
Send feedback
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License , and code samples are licensed under the Apache 2.0 License . For details, see the Google Developers Site Policies . Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-01-28 UTC.
Need to tell us more?
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-01-28 UTC."],[],[]]