數(shù)據(jù)處理器DataHandler簡介

2018-12-27 21:31 更新

DataHandler<T>是數(shù)據(jù)處理器定義描述,定義了請求結(jié)果處理能力。該接口的所有代碼如下。

/*
 * Copyright (C) 2016-2017 mzlion(mzllon@qq.com).
 *
 * 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 com.mzlion.easyokhttp.response.handle;

import java.io.IOException;

/**
 * 數(shù)據(jù)處理定義接口,將得到的響應(yīng)結(jié)果轉(zhuǎn)為所需的數(shù)據(jù)
 *
 * @author mzlion on 2016/12/14.
 * @see JsonDataHandler
 * @see StringDataHandler
 */
public interface DataHandler<T> {

    /**
     * 得到相應(yīng)結(jié)果后,將相應(yīng)數(shù)據(jù)轉(zhuǎn)為需要的數(shù)據(jù)格式
     *
     * @param response 需要轉(zhuǎn)換的對象
     * @return 轉(zhuǎn)換結(jié)果
     * @throws IOException 出現(xiàn)異常
     */
    T handle(final okhttp3.Response response) throws IOException;

}

所以該接口只有一個函數(shù),該函數(shù)提供了將原始數(shù)據(jù)格式轉(zhuǎn)為業(yè)務(wù)所需數(shù)據(jù)格式,框架提供了常用接口處理器實現(xiàn),若以下的處理器無法滿足需求可以自己實現(xiàn)一個處理器。

以上內(nèi)容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號