Package de.galan.commons.net.flux
Class Response
- java.lang.Object
-
- de.galan.commons.net.flux.Response
-
- All Implemented Interfaces:
AutoCloseable
- Direct Known Subclasses:
MockCommonHttpClient.MockResponse
public class Response extends Object implements AutoCloseable
Represents the reponse to a http service.
-
-
Constructor Summary
Constructors Constructor Description Response(HttpURLConnection connection, InputStream dataStream, int statusCode, String contentEncoding, String contentType, Map<String,String> headerFields)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()StringgetContentEncoding()StringgetContentType()StringgetHeaderField(String name)Map<String,String>getHeaderFields()intgetStatusCode()InputStreamgetStream()byte[]getStreamAsBytearray()Converts the inputstream to a string in UTF-8.StringgetStreamAsString()Converts the inputstream to a string in UTF-8.StringgetStreamAsString(String encoding)Converts the inputstream to a string with the given encoding.StringgetStreamAsString(Charset charset)Converts the inputstream to a string with the given encoding.booleanisClientError()Returns true if the http status code is between 400 and 499booleanisFailed()Returns true if the http status code is not between 200 and 299booleanisInformational()Returns true if the http status code is not between 100 and 199booleanisRedirection()Returns true if the http status code is between 300 and 399booleanisServerError()Returns true if the http status code is between 500 and 599booleanisSucceded()Returns true if the http status code is between 200 and 299voidstoreStream(File file)voidstoreStream(File file, boolean gunzip)
-
-
-
Constructor Detail
-
Response
public Response(HttpURLConnection connection, InputStream dataStream, int statusCode, String contentEncoding, String contentType, Map<String,String> headerFields)
-
-
Method Detail
-
getStream
public InputStream getStream()
-
getStreamAsBytearray
public byte[] getStreamAsBytearray() throws IOExceptionConverts the inputstream to a string in UTF-8. Subsequent the inputstream will be empty/closed.- Throws:
IOException
-
getStreamAsString
public String getStreamAsString() throws IOException
Converts the inputstream to a string in UTF-8. Subsequent the inputstream will be empty/closed.- Throws:
IOException
-
getStreamAsString
public String getStreamAsString(String encoding) throws IOException
Converts the inputstream to a string with the given encoding. Subsequent the inputstream will be empty/closed.- Throws:
IOException
-
getStreamAsString
public String getStreamAsString(Charset charset) throws IOException
Converts the inputstream to a string with the given encoding. Subsequent the inputstream will be empty/closed.- Throws:
IOException
-
storeStream
public void storeStream(File file) throws FileNotFoundException, IOException
- Throws:
FileNotFoundExceptionIOException
-
storeStream
public void storeStream(File file, boolean gunzip) throws FileNotFoundException, IOException
- Throws:
FileNotFoundExceptionIOException
-
getStatusCode
public int getStatusCode()
-
getContentEncoding
public String getContentEncoding()
-
getContentType
public String getContentType()
-
isFailed
public boolean isFailed()
Returns true if the http status code is not between 200 and 299
-
isInformational
public boolean isInformational()
Returns true if the http status code is not between 100 and 199
-
isSucceded
public boolean isSucceded()
Returns true if the http status code is between 200 and 299
-
isRedirection
public boolean isRedirection()
Returns true if the http status code is between 300 and 399
-
isClientError
public boolean isClientError()
Returns true if the http status code is between 400 and 499
-
isServerError
public boolean isServerError()
Returns true if the http status code is between 500 and 599
-
close
public void close()
- Specified by:
closein interfaceAutoCloseable
-
-