Coverage Report - com.jcabi.http.Response
 
Classes in this File Line Coverage Branch Coverage Complexity
Response
N/A
N/A
1
 
 1  
 /**
 2  
  * Copyright (c) 2011-2017, jcabi.com
 3  
  * All rights reserved.
 4  
  *
 5  
  * Redistribution and use in source and binary forms, with or without
 6  
  * modification, are permitted provided that the following conditions
 7  
  * are met: 1) Redistributions of source code must retain the above
 8  
  * copyright notice, this list of conditions and the following
 9  
  * disclaimer. 2) Redistributions in binary form must reproduce the above
 10  
  * copyright notice, this list of conditions and the following
 11  
  * disclaimer in the documentation and/or other materials provided
 12  
  * with the distribution. 3) Neither the name of the jcabi.com nor
 13  
  * the names of its contributors may be used to endorse or promote
 14  
  * products derived from this software without specific prior written
 15  
  * permission.
 16  
  *
 17  
  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 18  
  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT
 19  
  * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
 20  
  * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
 21  
  * THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
 22  
  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 23  
  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 24  
  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 25  
  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
 26  
  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 27  
  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
 28  
  * OF THE POSSIBILITY OF SUCH DAMAGE.
 29  
  */
 30  
 package com.jcabi.http;
 31  
 
 32  
 import com.jcabi.aspects.Immutable;
 33  
 import java.util.List;
 34  
 import java.util.Map;
 35  
 
 36  
 /**
 37  
  * RESTful response returned by {@link Request#fetch()}.
 38  
  *
 39  
  * <p>You can get this response from one of implementations of {@link Request}:
 40  
  *
 41  
  * <pre> Response response = new JdkRequest("https://www.google.com")
 42  
  *   .header("Accept", "text/html")
 43  
  *   .fetch();</pre>
 44  
  *
 45  
  * <p>Instances of this interface are immutable and thread-safe.
 46  
  *
 47  
  * @author Yegor Bugayenko (yegor@tpc2.com)
 48  
  * @version $Id: 1c7ec49841f8d2b4f83fcce55ebbf2fc56eb2431 $
 49  
  * @since 0.8
 50  
  * @see com.jcabi.http.request.JdkRequest
 51  
  */
 52  
 @Immutable
 53  
 public interface Response {
 54  
 
 55  
     /**
 56  
      * Get back to the request it's related to.
 57  
      * @return The request we're in
 58  
      */
 59  
     Request back();
 60  
 
 61  
     /**
 62  
      * Get status of the response as a positive integer number.
 63  
      * @return The status code
 64  
      */
 65  
     int status();
 66  
 
 67  
     /**
 68  
      * Get status line reason phrase.
 69  
      * @return The status line reason phrase
 70  
      */
 71  
     String reason();
 72  
 
 73  
     /**
 74  
      * Get a collection of all headers.
 75  
      * @return The headers
 76  
      */
 77  
     Map<String, List<String>> headers();
 78  
 
 79  
     /**
 80  
      * Get body as a string, assuming it's {@code UTF-8} (if there is something
 81  
      * else that can't be translated into a UTF-8 string a runtime exception
 82  
      * will be thrown).
 83  
      *
 84  
      * <p><strong>DISCLAIMER</strong>:
 85  
      * The only encoding supported here is UTF-8. If the body of response
 86  
      * contains any chars that can't be used and should be replaced with
 87  
      * a "replacement character", a {@link RuntimeException} will be thrown. If
 88  
      * you need to use some other encodings, use
 89  
      * {@link #binary()} instead.
 90  
      *
 91  
      * @return The body, as a UTF-8 string
 92  
      */
 93  
     String body();
 94  
 
 95  
     /**
 96  
      * Raw body as a an array of bytes.
 97  
      * @return The body, as a UTF-8 string
 98  
      */
 99  
     byte[] binary();
 100  
 
 101  
     /**
 102  
      * Convert it to another type, by encapsulation.
 103  
      * @param type Type to use
 104  
      * @param <T> Type to use
 105  
      * @return New response
 106  
      * @checkstyle MethodName (3 lines)
 107  
      */
 108  
     @SuppressWarnings("PMD.ShortMethodName")
 109  
     <T extends Response> T as(Class<T> type);
 110  
 
 111  
 }