// Path: library/src/main/java/org/mariotaku/restfu/http/HttpResponse.java
// public abstract class HttpResponse implements Closeable {
//     public abstract int getStatus();
// 
//     public abstract MultiValueMap<String> getHeaders();
// 
//     public abstract Body getBody();
// 
//     public String getHeader(String name) {
//         if (name == null) throw new NullPointerException();
//         return getHeaders().getFirst(name);
//     }
// 
//     public List<String> getHeaders(String name) {
//         if (name == null) throw new NullPointerException();
//         return getHeaders().get(name);
//     }
// 
//     /**
//      * Returns true if the code is in [200..300), which means the request was
//      * successfully received, understood, and accepted.
//      *
//      * @return True if HTTP response is successful response
//      */
//     public boolean isSuccessful() {
//         final int status = getStatus();
//         return status >= 200 && status < 300;
//     }
// 
//     @Override
//     public String toString() {
//         return "HTTP " + getStatus();
//     }
// }
// 
// Path: library/src/main/java/org/mariotaku/restfu/http/mime/Body.java
// public interface Body extends Closeable {
//     ContentType contentType();
// 
//     String contentEncoding();
// 
//     long length() throws IOException;
// 
//     long writeTo(final OutputStream os) throws IOException;
// 
//     InputStream stream() throws IOException;
// 
//     void close() throws IOException;
// 
// }
// 
// Path: library/src/main/java/org/mariotaku/restfu/http/mime/SimpleBody.java
// public class SimpleBody implements Body {
// 
//     private final ContentType contentType;
//     private final long contentLength;
//     private final InputStream stream;
//     private final String contentEncoding;
// 
//     public SimpleBody(ContentType contentType, String contentEncoding, long contentLength, InputStream stream) throws IOException {
//         this.contentType = contentType;
//         this.contentEncoding = contentEncoding;
//         this.contentLength = contentLength;
//         if ("gzip".equals(contentEncoding)) {
//             this.stream = new StreamingGZIPInputStream(stream);
//         } else {
//             this.stream = stream;
//         }
//     }
// 
//     @Override
//     public ContentType contentType() {
//         return contentType;
//     }
// 
//     @Override
//     public String contentEncoding() {
//         return contentEncoding;
//     }
// 
//     @Override
//     public long length() {
//         return contentLength;
//     }
// 
//     @Override
//     public String toString() {
//         return "BaseTypedData{" +
//                 "contentType=" + contentType +
//                 ", contentLength=" + contentLength +
//                 ", stream=" + stream +
//                 ", contentEncoding='" + contentEncoding + '\'' +
//                 '}';
//     }
// 
//     @Override
//     public long writeTo(OutputStream os) throws IOException {
//         final LengthLimitCopyListener listener = new LengthLimitCopyListener(contentLength);
//         return StreamUtils.copy(stream(), os, listener, listener);
//     }
// 
// 
//     @Override
//     public InputStream stream() {
//         return stream;
//     }
// 
//     @Override
//     public void close() throws IOException {
//         stream.close();
//     }
// 
//     public static Body wrap(Object value) {
//         if (value == null) return null;
//         if (value instanceof Body) {
//             return (Body) value;
//         } else if (value instanceof File) {
//             return new FileBody((File) value);
//         } else if (value instanceof String) {
//             return new StringBody((String) value, Charset.defaultCharset());
//         } else if (value instanceof Number) {
//             return new StringBody(value.toString(), Charset.defaultCharset());
//         } else if (value instanceof Character) {
//             return new StringBody(value.toString(), Charset.defaultCharset());
//         } else if (value instanceof Boolean) {
//             return new StringBody(value.toString(), Charset.defaultCharset());
//         }
//         throw new UnsupportedOperationException(value.getClass().toString());
//     }
// 
//     public static boolean supports(Type value) {
//         if (value instanceof Class) {
//             return supportsClass((Class<?>) value);
//         } else if (value instanceof ParameterizedType) {
//             Type rawType = ((ParameterizedType) value).getRawType();
//             if (rawType instanceof Class) {
//                 return supportsClass((Class<?>) rawType);
//             }
//         }
//         return false;
//     }
// 
//     private static boolean supportsClass(Class<?> value) {
//         if (Body.class.isAssignableFrom(value)) {
//             return true;
//         } else if (value == File.class) {
//             return true;
//         } else if (value == String.class) {
//             return true;
//         } else if (Number.class.isAssignableFrom(value)) {
//             return true;
//         } else if (value == Character.class) {
//             return true;
//         } else if (value == Boolean.class) {
//             return true;
//         }
//         return false;
//     }
// 
//     public static Reader reader(Body data) throws IOException {
//         final ContentType contentType = data.contentType();
//         final Charset charset = contentType != null ? contentType.getCharset() : null;
//         return new InputStreamReader(data.stream(), charset != null ? charset : Charset.defaultCharset());
//     }
// }


import org.jetbrains.annotations.NotNull;
import org.mariotaku.restfu.http.HttpResponse;
import org.mariotaku.restfu.http.mime.Body;
import org.mariotaku.restfu.http.mime.SimpleBody;
import java.io.IOException;
import java.lang.reflect.Type;
/*
 * Copyright (c) 2015 mariotaku
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.mariotaku.restfu;



/**
 * Created by mariotaku on 15/2/6.
 */
public interface RestConverter<F, T, E extends Exception> {

    @NotNull
    T convert(@NotNull F from) throws ConvertException, IOException, E;

    interface Factory<E extends Exception> {

        @NotNull
// Path: library/src/main/java/org/mariotaku/restfu/http/HttpResponse.java
// public abstract class HttpResponse implements Closeable {
//     public abstract int getStatus();
// 
//     public abstract MultiValueMap<String> getHeaders();
// 
//     public abstract Body getBody();
// 
//     public String getHeader(String name) {
//         if (name == null) throw new NullPointerException();
//         return getHeaders().getFirst(name);
//     }
// 
//     public List<String> getHeaders(String name) {
//         if (name == null) throw new NullPointerException();
//         return getHeaders().get(name);
//     }
// 
//     /**
//      * Returns true if the code is in [200..300), which means the request was
//      * successfully received, understood, and accepted.
//      *
//      * @return True if HTTP response is successful response
//      */
//     public boolean isSuccessful() {
//         final int status = getStatus();
//         return status >= 200 && status < 300;
//     }
// 
//     @Override
//     public String toString() {
//         return "HTTP " + getStatus();
//     }
// }
// 
// Path: library/src/main/java/org/mariotaku/restfu/http/mime/Body.java
// public interface Body extends Closeable {
//     ContentType contentType();
// 
//     String contentEncoding();
// 
//     long length() throws IOException;
// 
//     long writeTo(final OutputStream os) throws IOException;
// 
//     InputStream stream() throws IOException;
// 
//     void close() throws IOException;
// 
// }
// 
// Path: library/src/main/java/org/mariotaku/restfu/http/mime/SimpleBody.java
// public class SimpleBody implements Body {
// 
//     private final ContentType contentType;
//     private final long contentLength;
//     private final InputStream stream;
//     private final String contentEncoding;
// 
//     public SimpleBody(ContentType contentType, String contentEncoding, long contentLength, InputStream stream) throws IOException {
//         this.contentType = contentType;
//         this.contentEncoding = contentEncoding;
//         this.contentLength = contentLength;
//         if ("gzip".equals(contentEncoding)) {
//             this.stream = new StreamingGZIPInputStream(stream);
//         } else {
//             this.stream = stream;
//         }
//     }
// 
//     @Override
//     public ContentType contentType() {
//         return contentType;
//     }
// 
//     @Override
//     public String contentEncoding() {
//         return contentEncoding;
//     }
// 
//     @Override
//     public long length() {
//         return contentLength;
//     }
// 
//     @Override
//     public String toString() {
//         return "BaseTypedData{" +
//                 "contentType=" + contentType +
//                 ", contentLength=" + contentLength +
//                 ", stream=" + stream +
//                 ", contentEncoding='" + contentEncoding + '\'' +
//                 '}';
//     }
// 
//     @Override
//     public long writeTo(OutputStream os) throws IOException {
//         final LengthLimitCopyListener listener = new LengthLimitCopyListener(contentLength);
//         return StreamUtils.copy(stream(), os, listener, listener);
//     }
// 
// 
//     @Override
//     public InputStream stream() {
//         return stream;
//     }
// 
//     @Override
//     public void close() throws IOException {
//         stream.close();
//     }
// 
//     public static Body wrap(Object value) {
//         if (value == null) return null;
//         if (value instanceof Body) {
//             return (Body) value;
//         } else if (value instanceof File) {
//             return new FileBody((File) value);
//         } else if (value instanceof String) {
//             return new StringBody((String) value, Charset.defaultCharset());
//         } else if (value instanceof Number) {
//             return new StringBody(value.toString(), Charset.defaultCharset());
//         } else if (value instanceof Character) {
//             return new StringBody(value.toString(), Charset.defaultCharset());
//         } else if (value instanceof Boolean) {
//             return new StringBody(value.toString(), Charset.defaultCharset());
//         }
//         throw new UnsupportedOperationException(value.getClass().toString());
//     }
// 
//     public static boolean supports(Type value) {
//         if (value instanceof Class) {
//             return supportsClass((Class<?>) value);
//         } else if (value instanceof ParameterizedType) {
//             Type rawType = ((ParameterizedType) value).getRawType();
//             if (rawType instanceof Class) {
//                 return supportsClass((Class<?>) rawType);
//             }
//         }
//         return false;
//     }
// 
//     private static boolean supportsClass(Class<?> value) {
//         if (Body.class.isAssignableFrom(value)) {
//             return true;
//         } else if (value == File.class) {
//             return true;
//         } else if (value == String.class) {
//             return true;
//         } else if (Number.class.isAssignableFrom(value)) {
//             return true;
//         } else if (value == Character.class) {
//             return true;
//         } else if (value == Boolean.class) {
//             return true;
//         }
//         return false;
//     }
// 
//     public static Reader reader(Body data) throws IOException {
//         final ContentType contentType = data.contentType();
//         final Charset charset = contentType != null ? contentType.getCharset() : null;
//         return new InputStreamReader(data.stream(), charset != null ? charset : Charset.defaultCharset());
//     }
// }


// Path: library/src/main/java/org/mariotaku/restfu/RestConverter.java
import org.jetbrains.annotations.NotNull;
import org.mariotaku.restfu.http.HttpResponse;
import org.mariotaku.restfu.http.mime.Body;
import org.mariotaku.restfu.http.mime.SimpleBody;
import java.io.IOException;
import java.lang.reflect.Type;

/*
 * Copyright (c) 2015 mariotaku
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.mariotaku.restfu;



/**
 * Created by mariotaku on 15/2/6.
 */
public interface RestConverter<F, T, E extends Exception> {

    @NotNull
    T convert(@NotNull F from) throws ConvertException, IOException, E;

    interface Factory<E extends Exception> {

        @NotNull
        RestConverter<HttpResponse, ?, E> forResponse(@NotNull Type toType) throws ConvertException;