Send feedback
Class MockHttpURLConnection (1.43.2)
Stay organized with collections
Save and categorize content based on your preferences.
Version 1.43.2 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
Type
Description
byte []
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
Type
Description
byte []
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.
connect()
Overrides
disconnect()
Overrides
doOutputCalled()
public final boolean doOutputCalled ()
Returns whether #doOutput was called.
getChunkLength()
public int getChunkLength ()
Returns
Type
Description
int
getErrorStream()
public InputStream getErrorStream ()
Overrides
public String getHeaderField ( String name )
Parameter
Name
Description
name
String
Returns
Type
Description
String
Overrides
public Map<String , List<String> > getHeaderFields ()
Overrides
public InputStream getInputStream ()
Overrides
getOutputStream()
public OutputStream getOutputStream ()
Overrides
getResponseCode()
public int getResponseCode ()
Returns
Type
Description
int
Overrides
isSetFixedLengthStreamingModeIntCalled()
public boolean isSetFixedLengthStreamingModeIntCalled ()
isSetFixedLengthStreamingModeLongCalled()
public boolean isSetFixedLengthStreamingModeLongCalled ()
setDoOutput(boolean dooutput)
public void setDoOutput ( boolean dooutput )
Parameter
Name
Description
dooutput
boolean
Overrides
public MockHttpURLConnection setErrorStream ( InputStream is )
Sets the error stream.
To prevent incidental overwrite, only the first non-null assignment is honored.
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.
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
.
setResponseCode(int responseCode)
public MockHttpURLConnection setResponseCode ( int responseCode )
Sets the HTTP response status code.
Parameter
Name
Description
responseCode
int
usingProxy()
public boolean usingProxy ()
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."],[],[]]