Class MockHttpURLConnection (1.43.2)
Stay organized with collections
Save and categorize content based on your preferences.
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
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 2024-10-01 UTC.
[{
"type": "thumb-down",
"id": "hardToUnderstand",
"label":"Hard to understand"
},{
"type": "thumb-down",
"id": "incorrectInformationOrSampleCode",
"label":"Incorrect information or sample code"
},{
"type": "thumb-down",
"id": "missingTheInformationSamplesINeed",
"label":"Missing the information/samples I need"
},{
"type": "thumb-down",
"id": "otherDown",
"label":"Other"
}]
[{
"type": "thumb-up",
"id": "easyToUnderstand",
"label":"Easy to understand"
},{
"type": "thumb-up",
"id": "solvedMyProblem",
"label":"Solved my problem"
},{
"type": "thumb-up",
"id": "otherUp",
"label":"Other"
}]
{"lastModified": "Last updated 2024-10-01 UTC."}
[[["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 2024-10-01 UTC."]]