当前位置: 首页>>代码示例>>Java>>正文


Java TypedInput类代码示例

本文整理汇总了Java中retrofit.mime.TypedInput的典型用法代码示例。如果您正苦于以下问题:Java TypedInput类的具体用法?Java TypedInput怎么用?Java TypedInput使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


TypedInput类属于retrofit.mime包,在下文中一共展示了TypedInput类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: connectFacebookAccount

import retrofit.mime.TypedInput; //导入依赖的package包/类
/**
 * Connects a user's Facebook account - if already registered with another social medium
 *
 * @param userID
 * @param accessToken
 */
public void connectFacebookAccount(@NonNull long userID, @NonNull String accessToken, @NonNull final PDAPICallback<PDUser> callback){
    JsonObject facebookObject = new JsonObject();
    facebookObject.addProperty("id", userID);
    facebookObject.addProperty("access_token", accessToken);

    JsonObject userObject = new JsonObject();
    userObject.add("facebook", facebookObject);

    JsonObject json = new JsonObject();
    json.add("user", userObject);

    TypedInput body = new TypedByteArray(PDAPIConfig.PD_JSON_MIME_TYPE, json.toString().getBytes());

    Gson gson = new GsonBuilder()
            .registerTypeAdapter(PDUser.class, new PDUserDeserializer())
            .create();

    PopdeemAPI api = getApiInterface(getUserTokenInterceptor(), new GsonConverter(gson));
    api.connectFacebookAccount(body, callback);
}
 
开发者ID:Popdeem,项目名称:Popdeem-SDK-Android,代码行数:27,代码来源:PDAPIClient.java

示例2: connectWithTwitterAccount

import retrofit.mime.TypedInput; //导入依赖的package包/类
/**
 * Connect a users Twitter account
 *
 * @param userID     Twitter User ID
 * @param userToken  Twitter User Token
 * @param userSecret Twitter User Secret
 * @param callback   {@link PDAPICallback} for API result
 */
public void connectWithTwitterAccount(@NonNull String userID, @NonNull String userToken, @NonNull String userSecret, @NonNull final PDAPICallback<PDUser> callback) {
    JsonObject twitterObject = new JsonObject();
    twitterObject.addProperty("social_id", userID);
    twitterObject.addProperty("access_token", userToken);
    twitterObject.addProperty("access_secret", userSecret);

    JsonObject userJson = new JsonObject();
    userJson.add("twitter", twitterObject);

    JsonObject json = new JsonObject();
    json.add("user", userJson);

    TypedInput body = new TypedByteArray(PDAPIConfig.PD_JSON_MIME_TYPE, json.toString().getBytes());

    Gson gson = new GsonBuilder()
            .registerTypeAdapter(PDUser.class, new PDTwitterUserDeserializer())
            .create();

    PopdeemAPI api = getApiInterface(getUserTokenInterceptor(), new GsonConverter(gson));
    api.connectWithTwitterAccount(body, callback);
}
 
开发者ID:Popdeem,项目名称:Popdeem-SDK-Android,代码行数:30,代码来源:PDAPIClient.java

示例3: connectWithInstagramAccount

import retrofit.mime.TypedInput; //导入依赖的package包/类
/**
 * Connect a users Instagram Account
 *
 * @param userId      Instagram User ID
 * @param accessToken Instagram Access Token
 * @param screenName  Users Screen Name
 * @param callback    {@link PDAPICallback} for API result
 */
public void connectWithInstagramAccount(@NonNull String userId, @NonNull String accessToken, @NonNull String screenName, @NonNull final PDAPICallback<PDUser> callback) {
    JsonObject instagramObject = new JsonObject();
    instagramObject.addProperty("id", userId);
    instagramObject.addProperty("access_token", accessToken);
    instagramObject.addProperty("screen_name", screenName);

    JsonObject userJson = new JsonObject();
    userJson.add("instagram", instagramObject);

    JsonObject json = new JsonObject();
    json.add("user", userJson);

    TypedInput body = new TypedByteArray(PDAPIConfig.PD_JSON_MIME_TYPE, json.toString().getBytes());
    Gson gson = new GsonBuilder()
            .registerTypeAdapter(PDUser.class, new PDInstagramUserDeserializer())
            .create();

    PopdeemAPI api = getApiInterface(getUserTokenInterceptor(), new GsonConverter(gson));
    api.connectWithInstagramAccount(body, callback);
}
 
开发者ID:Popdeem,项目名称:Popdeem-SDK-Android,代码行数:29,代码来源:PDAPIClient.java

示例4: disconnectTwitterAccount

import retrofit.mime.TypedInput; //导入依赖的package包/类
/**
 * Disconnect users Twitter account
 *
 * @param accessToken  Twitter access token
 * @param accessSecret Twitter access secret
 * @param twitterId    Users Twitter account ID
 * @param callback     {@link PDAPICallback} for API result
 */
public void disconnectTwitterAccount(String accessToken, String accessSecret, String twitterId, @NonNull final PDAPICallback<PDUser> callback) {
    JsonObject twitterJson = new JsonObject();
    twitterJson.addProperty("access_token", accessToken);
    twitterJson.addProperty("access_secret", accessSecret);
    twitterJson.addProperty("id", twitterId);

    JsonObject userJson = new JsonObject();
    userJson.add("twitter", twitterJson);

    JsonObject jsonBody = new JsonObject();
    jsonBody.add("user", userJson);

    TypedInput body = new TypedByteArray(PDAPIConfig.PD_JSON_MIME_TYPE, jsonBody.toString().getBytes());

    Gson gson = new GsonBuilder()
            .registerTypeAdapter(PDUser.class, new PDTwitterUserDeserializer())
            .create();

    PopdeemAPI api = getApiInterface(getUserTokenInterceptor(), new GsonConverter(gson));
    api.disconnectSocialAccount(body, callback);
}
 
开发者ID:Popdeem,项目名称:Popdeem-SDK-Android,代码行数:30,代码来源:PDAPIClient.java

示例5: disconnectInstagramAccount

import retrofit.mime.TypedInput; //导入依赖的package包/类
/**
 * Disconnect users Instagram Account
 *
 * @param accessToken Instagram access token
 * @param instagramId Users Instagram account ID
 * @param screenName  Users Instagram screen name
 * @param callback    {@link PDAPICallback} for API result
 */
public void disconnectInstagramAccount(String accessToken, String instagramId, String screenName, @NonNull final PDAPICallback<PDUser> callback) {
    JsonObject twitterJson = new JsonObject();
    twitterJson.addProperty("access_token", accessToken);
    twitterJson.addProperty("screen_name", screenName);
    twitterJson.addProperty("id", instagramId);

    JsonObject userJson = new JsonObject();
    userJson.add("instagram", twitterJson);

    JsonObject jsonBody = new JsonObject();
    jsonBody.add("user", userJson);

    TypedInput body = new TypedByteArray(PDAPIConfig.PD_JSON_MIME_TYPE, jsonBody.toString().getBytes());

    Gson gson = new GsonBuilder()
            .registerTypeAdapter(PDUser.class, new PDInstagramUserDeserializer())
            .create();

    PopdeemAPI api = getApiInterface(getUserTokenInterceptor(), new GsonConverter(gson));
    api.disconnectSocialAccount(body, callback);
}
 
开发者ID:Popdeem,项目名称:Popdeem-SDK-Android,代码行数:30,代码来源:PDAPIClient.java

示例6: disconnectFacebookAccount

import retrofit.mime.TypedInput; //导入依赖的package包/类
public void disconnectFacebookAccount(@NonNull final String facebookAccessToken,
                                      @NonNull final String facebookUserID,
                                      @NonNull final PDAPICallback<PDUser> callback) {
    JsonObject facebookObject = new JsonObject();
    facebookObject.addProperty("id", facebookUserID);
    facebookObject.addProperty("access_token", facebookAccessToken);

    JsonObject userObject = new JsonObject();
    userObject.add("facebook", facebookObject);

    JsonObject json = new JsonObject();
    json.add("user", userObject);

    TypedInput body = new TypedByteArray(PDAPIConfig.PD_JSON_MIME_TYPE, json.toString().getBytes());

    Gson gson = new GsonBuilder()
            .registerTypeAdapter(PDUser.class, new PDUserDeserializer())
            .create();

    PopdeemAPI api = getApiInterface(getUserTokenInterceptor(), new GsonConverter(gson));
    api.disconnectSocialAccount(body, callback);
}
 
开发者ID:Popdeem,项目名称:Popdeem-SDK-Android,代码行数:23,代码来源:PDAPIClient.java

示例7: createResponseBody

import retrofit.mime.TypedInput; //导入依赖的package包/类
private static TypedInput createResponseBody(final ResponseBody body) {
  if (body.contentLength() == 0) {
    return null;
  }
  return new TypedInput() {
    @Override public String mimeType() {
      MediaType mediaType = body.contentType();
      return mediaType == null ? null : mediaType.toString();
    }

    @Override public long length() {
      return body.contentLength();
    }

    @Override public InputStream in() throws IOException {
      return body.byteStream();
    }
  };
}
 
开发者ID:JakeWharton,项目名称:retrofit1-okhttp3-client,代码行数:20,代码来源:Ok3Client.java

示例8: responseNoContentType

import retrofit.mime.TypedInput; //导入依赖的package包/类
@Test public void responseNoContentType() throws IOException {
  okhttp3.Response okResponse = new okhttp3.Response.Builder()
      .code(200).message("OK")
      .body(new TestResponseBody("hello", null))
      .addHeader("foo", "bar")
      .addHeader("kit", "kat")
      .protocol(Protocol.HTTP_1_1)
      .request(new okhttp3.Request.Builder()
          .url(HOST + "/foo/bar/")
          .get()
          .build())
      .build();
  Response response = Ok3Client.parseResponse(okResponse);

  assertThat(response.getUrl()).isEqualTo(HOST + "/foo/bar/");
  assertThat(response.getStatus()).isEqualTo(200);
  assertThat(response.getReason()).isEqualTo("OK");
  assertThat(response.getHeaders()) //
      .containsExactly(new Header("foo", "bar"), new Header("kit", "kat"));
  TypedInput responseBody = response.getBody();
  assertThat(responseBody.mimeType()).isNull();
  assertThat(buffer(source(responseBody.in())).readUtf8()).isEqualTo("hello");
}
 
开发者ID:JakeWharton,项目名称:retrofit1-okhttp3-client,代码行数:24,代码来源:Ok3ClientTest.java

示例9: postData

import retrofit.mime.TypedInput; //导入依赖的package包/类
@Override
void postData() throws Exception {
    super.postData();

    mAdapter = new RestAdapter.Builder().setEndpoint(mUrl).build();
    SimplePOST create = mAdapter.create(SimplePOST.class);
    mStartTime = System.currentTimeMillis();
    String json = "{\"foo\":\"kit\",\"bar\":\"kat\"}";
    TypedInput in = new TypedByteArray("application/json", json.getBytes("UTF-8"));
    mResponse = create.postRawJson(in);
    //mResponse = create.getResponse();
    mEndTime = System.currentTimeMillis();

    mStatusCode = mResponse.getStatus();
    if (SC_OK == mStatusCode) {
        mResponseDataSize = mResponse.getBody().in().available();
    }
}
 
开发者ID:bangqu,项目名称:easyapi-apm-demo,代码行数:19,代码来源:RetrofitTest.java

示例10: fromBody

import retrofit.mime.TypedInput; //导入依赖的package包/类
@Override public Object fromBody(TypedInput body, Type type) throws ConversionException {
    try {
        InputStream stream = body.in();
        String responseBodyString = MiniIOUtils.toString(stream);
        if(responseBodyString.contains("<!DOCTYPE html>"))
            return responseBodyString;
        JsonParser parser = new JsonParser();
        JsonObject element = (JsonObject)parser.parse(responseBodyString);
        JsonElement dataObject = element.get("data");
        if (!dataObject.isJsonArray() && type instanceof GenericArrayType) {
            Type componentType = ((GenericArrayType) type).getGenericComponentType();
            Class<?> c = Class.forName(getClassName(componentType));
            return Array.newInstance(c, 0);
        }
        return gson.fromJson(dataObject, type);
    } catch (JsonParseException | IOException | ClassNotFoundException e) {
        throw new ConversionException(e);
    }
}
 
开发者ID:crysehillmes,项目名称:smoothnovelreader,代码行数:20,代码来源:CustomGsonConverter.java

示例11: fromBody

import retrofit.mime.TypedInput; //导入依赖的package包/类
@Override
public Object fromBody(TypedInput body, Type type) throws ConversionException {
    try {
        InputStream stream = body.in();
        String responseBodyString = MiniIOUtils.toString(stream);
        if (responseBodyString.contains("<!DOCTYPE html>"))
            return responseBodyString;
        JsonParser parser = new JsonParser();
        JsonObject element = (JsonObject) parser.parse(responseBodyString);
        JsonElement dataObject = null;
        if (element.has("items") && !(element.has("labels") && element.has("desc") && element.has("curl"))) {
            dataObject = element.get("items");
        } else {
            dataObject = element;
        }
        if (!dataObject.isJsonArray() && type instanceof GenericArrayType) {
            Type componentType = ((GenericArrayType) type).getGenericComponentType();
            Class<?> c = Class.forName(getClassName(componentType));
            return Array.newInstance(c, 0);
        }
        return gson.fromJson(dataObject, type);
    } catch (JsonParseException | IOException | ClassNotFoundException e) {
        throw new ConversionException(e);
    }
}
 
开发者ID:crysehillmes,项目名称:smoothnovelreader,代码行数:26,代码来源:CustomGsonConverter.java

示例12: fromBody

import retrofit.mime.TypedInput; //导入依赖的package包/类
@Override
public Object fromBody(TypedInput body, Type type) throws ConversionException {
    boolean willCloseStream = false; // try to close the stream, if there is no exception thrown
                                     // using tolerant JsonReader
    try {
        JsonReader jsonReader = new JsonReader(new InputStreamReader(body.in()));
        jsonReader.setLenient(true);
        Object o = mGson.fromJson(jsonReader, type);
        willCloseStream = true;
        return o;
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        if (willCloseStream) {
            closeStream(body);
        }
    }

    return super.fromBody(body, type);
}
 
开发者ID:bwzz,项目名称:yyl,代码行数:21,代码来源:MyGsonConvertor.java

示例13: fromBody

import retrofit.mime.TypedInput; //导入依赖的package包/类
@Override public Object fromBody(TypedInput body, Type type) throws ConversionException {
    try {
        // Check if the type contains a parametrized list
        if (ParameterizedType.class.isAssignableFrom(type.getClass())) {
            // Grab the actual type parameter from the parametrized list and delegate to LoganSquare
            ParameterizedType parameterized = (ParameterizedType) type;
            return LoganSquare.parseList(body.in(), (Class) parameterized.getActualTypeArguments()[0]);

        } else {
            // Single elements get parsed immediately
            return LoganSquare.parse(body.in(), (Class) type);
        }
    } catch (Exception e) {
        throw new ConversionException(e);
    }
}
 
开发者ID:getsadzeg,项目名称:AreYouAlive,代码行数:17,代码来源:LoganSquareConverter.java

示例14: fromBody

import retrofit.mime.TypedInput; //导入依赖的package包/类
@Override
public Object fromBody(TypedInput typedInput, Type type) throws ConversionException {
    String text = null;
    try {
        typedInput.in();
        BufferedReader reader = new BufferedReader(new InputStreamReader(typedInput.in()));
        StringBuilder out = new StringBuilder();
        String newLine = System.getProperty("line.separator");
        String line;
        while ((line = reader.readLine()) != null) {
            out.append(line);
            out.append(newLine);
        }
        text = out.toString();
    } catch (IOException ignored) {/*NOP*/ }
    return text;
}
 
开发者ID:percolate,项目名称:foam,代码行数:18,代码来源:GoogleAnalytics.java

示例15: readInputStream

import retrofit.mime.TypedInput; //导入依赖的package包/类
static String readInputStream(TypedInput in) {
    StringBuilder builder = new StringBuilder();
    try {
        BufferedReader bufferedStream
                = new BufferedReader(new InputStreamReader(in.in()));
        try {
            String line;
            while ((line = bufferedStream.readLine()) != null) {
                builder.append(line);
                builder.append('\n');
            }
            return builder.toString();
        } finally {
            bufferedStream.close();
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
    return builder.toString();
}
 
开发者ID:dhis2,项目名称:dhis2-android-dashboard,代码行数:21,代码来源:WebViewFragment.java


注:本文中的retrofit.mime.TypedInput类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。