Package com.box.restclientv2.responseparsers

Source Code of com.box.restclientv2.responseparsers.DefaultFileResponseParser

package com.box.restclientv2.responseparsers;

import org.apache.http.HttpResponse;

import com.box.restclientv2.exceptions.BoxRestException;
import com.box.restclientv2.responses.DefaultBoxResponse;
import com.box.restclientv2.responses.IBoxResponse;

/**
* Default implementation for response parser to parse a response with a file InputStream.
*/
public class DefaultFileResponseParser implements IBoxResponseParser {

    @Override
    public Object parse(IBoxResponse response) throws BoxRestException {
        if (!(response instanceof DefaultBoxResponse)) {
            throw new BoxRestException("class mismatch, expected:" + DefaultBoxResponse.class.getName() + ";current:" + response.getClass().getCanonicalName());
        }
        HttpResponse httpResponse = ((DefaultBoxResponse) response).getHttpResponse();
        try {
            return httpResponse.getEntity().getContent();
        }
        catch (Exception e) {
            throw new BoxRestException(e, "Failed to parse response.");
        }
    }
}
TOP

Related Classes of com.box.restclientv2.responseparsers.DefaultFileResponseParser

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.