當前位置: 首頁>>代碼示例>>Java>>正文


Java TypedOutput類代碼示例

本文整理匯總了Java中retrofit.mime.TypedOutput的典型用法代碼示例。如果您正苦於以下問題:Java TypedOutput類的具體用法?Java TypedOutput怎麽用?Java TypedOutput使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


TypedOutput類屬於retrofit.mime包,在下文中一共展示了TypedOutput類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: toBody

import retrofit.mime.TypedOutput; //導入依賴的package包/類
@Override
public TypedOutput toBody(Object object) {
    String jsonStr = null;
    try {
        JSONObject jsonObj = toJson(object);
        if (jsonObj != null) {
            jsonStr = jsonObj.toString();
        }

    } catch (JSONException e) {
        // TODO: do something
        e.printStackTrace();
    }

    return new TypedJsonString(jsonStr);
}
 
開發者ID:ticofab,項目名稱:The-Things-Network-Android-SDK,代碼行數:17,代碼來源:JsonConverter.java

示例2: createRequestBody

import retrofit.mime.TypedOutput; //導入依賴的package包/類
private static RequestBody createRequestBody(final TypedOutput body) {
  if (body == null) {
    return null;
  }
  final MediaType mediaType = MediaType.parse(body.mimeType());
  return new RequestBody() {
    @Override public MediaType contentType() {
      return mediaType;
    }

    @Override public void writeTo(BufferedSink sink) throws IOException {
      body.writeTo(sink.outputStream());
    }

    @Override public long contentLength() {
      return body.length();
    }
  };
}
 
開發者ID:JakeWharton,項目名稱:retrofit1-okhttp3-client,代碼行數:20,代碼來源:Ok3Client.java

示例3: toBody

import retrofit.mime.TypedOutput; //導入依賴的package包/類
@SuppressWarnings("unchecked") @Override public TypedOutput toBody(Object object) {
    try {
        // Check if the type contains a parametrized list
        if (List.class.isAssignableFrom(object.getClass())) {
            // Convert the input to a list first, access the first element and serialize the list
            List<Object> list = (List<Object>) object;
            if (list.isEmpty()) {
                return new TypedString("[]");
            } else {
                Object firstElement = list.get(0);
                return new TypedString(LoganSquare.serialize(list, (Class<Object>) firstElement.getClass()));
            }
        } else {
            // Serialize single elements immediately
            return new TypedString(LoganSquare.serialize(object));
        }
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
開發者ID:getsadzeg,項目名稱:AreYouAlive,代碼行數:21,代碼來源:LoganSquareConverter.java

示例4: testPatchResource

import retrofit.mime.TypedOutput; //導入依賴的package包/類
@Test
public void testPatchResource() throws Exception {
    Map<String,Object> fooBar = new LinkedHashMap<>();
    fooBar.put("foo", 1);
    fooBar.put("bar", 2);
    Map <String, Map<String,Object>> properties = new LinkedHashMap<>();
    properties.put("custom_properties", fooBar);

    Gson gson = new GsonBuilder()
            .setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES)
            .setPrettyPrinting()
            .create();
    TypedOutput body = new GsonConverter(gson).toBody(properties);

    Resource resource = client.patchResource(new ResourcesArgs.Builder()
                    .setPath("/0-test")
                    .setBody(body)
                    .build());
    assertTrue("dir".equals(resource.getType()));
    assertEquals(resource.getPath(), new ResourcePath("disk", "/0-test"));
    logger.info("self: " + resource);
}
 
開發者ID:yandex-disk,項目名稱:yandex-disk-restapi-java,代碼行數:23,代碼來源:RestClientTest.java

示例5: toBody

import retrofit.mime.TypedOutput; //導入依賴的package包/類
@SuppressWarnings("unchecked") @Override public TypedOutput toBody(Object object) {
  try {
    // Check if the type contains a parametrized list
    if (List.class.isAssignableFrom(object.getClass())) {
      // Convert the input to a list first, access the first element and serialize the list
      List<Object> list = (List<Object>) object;
      if (list.isEmpty()) {
        return new TypedString("[]");
      } else {
        Object firstElement = list.get(0);
        return new TypedString(
            LoganSquare.serialize(list, (Class<Object>) firstElement.getClass()));
      }
    } else {
      // Serialize single elements immediately
      return new TypedString(LoganSquare.serialize(object));
    }
  } catch (Exception e) {
    throw new RuntimeException(e);
  }
}
 
開發者ID:sockeqwe,項目名稱:SecureBitcoinWallet,代碼行數:22,代碼來源:LoganSquareConverter.java

示例6: GenericHttpRequest

import retrofit.mime.TypedOutput; //導入依賴的package包/類
GenericHttpRequest(Request request) {
    super();
    method = request.getMethod();
    setURI(URI.create(request.getUrl()));

    // Add all headers.
    for (Header header : request.getHeaders()) {
        addHeader(new BasicHeader(header.getName(), header.getValue()));
    }

    // Add the content body, if any.
    TypedOutput body = request.getBody();
    if (body != null) {
        setEntity(new TypedOutputEntity(body));
    }
}
 
開發者ID:goodev,項目名稱:android-discourse,代碼行數:17,代碼來源:ApacheClient.java

示例7: Request

import retrofit.mime.TypedOutput; //導入依賴的package包/類
public Request(String method, String url, List<Header> headers, TypedOutput body) {
    if (method == null) {
        throw new NullPointerException("Method must not be null.");
    }
    if (url == null) {
        throw new NullPointerException("URL must not be null.");
    }
    this.method = method;
    this.url = url;

    if (headers == null) {
        this.headers = Collections.emptyList();
    } else {
        this.headers = Collections.unmodifiableList(new ArrayList<Header>(headers));
    }

    this.body = body;
}
 
開發者ID:goodev,項目名稱:android-discourse,代碼行數:19,代碼來源:Request.java

示例8: toBody

import retrofit.mime.TypedOutput; //導入依賴的package包/類
@SuppressWarnings("unchecked") @Override public TypedOutput toBody(Object object) {
	try {
		// Check if the type contains a parametrized list
		if (List.class.isAssignableFrom(object.getClass())) {
			// Convert the input to a list first, access the first element and serialize the list
			List<Object> list = (List<Object>) object;
			if (list.isEmpty()) {
				return new TypedString("[]");
			} else {
				Object firstElement = list.get(0);
				return new TypedString(LoganSquare.serialize(list, (Class<Object>) firstElement.getClass()));
			}
		} else {
			// Serialize single elements immediately
			return new TypedString(LoganSquare.serialize(object));
		}
	} catch (Exception e) {
		throw new RuntimeException(e);
	}
}
 
開發者ID:yongjhih,項目名稱:converter-logansquare-retrofit,代碼行數:21,代碼來源:LoganSquareConverter.java

示例9: toBody

import retrofit.mime.TypedOutput; //導入依賴的package包/類
@Override
public TypedOutput toBody(Object object) {
    try {
        // Check if the type contains a parametrized list
        if (List.class.isAssignableFrom(object.getClass())) {
            // Convert the input to a list first, access the first element and serialize the list
            List<Object> list = (List<Object>) object;
            if (list.isEmpty()) {
                return new TypedString("[]");
            }
            else {
                Object firstElement = list.get(0);
                return new TypedString(LoganSquare.serialize(list, (Class<Object>) firstElement.getClass()));
            }
        }
        else {
            // Serialize single elements immediately
            return new TypedString(LoganSquare.serialize(object));
        }
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
開發者ID:dinosaurwithakatana,項目名稱:hacker-news-android,代碼行數:24,代碼來源:LoganSquareConvertor.java

示例10: testPOSTDataEcho

import retrofit.mime.TypedOutput; //導入依賴的package包/類
@Test
public void testPOSTDataEcho() throws Exception {
    // Given
    final String postBodyString = "hello";
    HttpRequestClient httpRequestClient = new HttpRequestClient();
    TypedOutput postBody = new TypedString(postBodyString);
    Request request = new Request("POST", HTTP_BIN_ROOT + "/post", null, postBody);

    // When
    final Response response = httpRequestClient.execute(request);
    ObjectMapper objectMapper = new ObjectMapper();
    Map<String, Object> jsonObj = objectMapper.readValue(response.getBody().in(), Map.class);

    // Then
    assertNotNull(response);
    assertThat(response.getStatus(), is(200));
    assertThat(jsonObj.get("data").toString(), is(postBodyString));
}
 
開發者ID:groodt,項目名稱:http-request-retrofit-client,代碼行數:19,代碼來源:HttpRequestClientIntegrationTest.java

示例11: getRequestInfo

import retrofit.mime.TypedOutput; //導入依賴的package包/類
private static Profiler.RequestInformation getRequestInfo(String serverUrl,
                                                          RestMethodInfo methodDetails, Request request)
{
  long contentLength = 0;
  String contentType = null;

  TypedOutput body = request.getBody();
  if (body != null)
  {
    contentLength = body.length();
    contentType = body.mimeType();
  }

  return new Profiler.RequestInformation(methodDetails.requestMethod, serverUrl,
                                         methodDetails.requestUrl, contentLength, contentType);
}
 
開發者ID:toadzky,項目名稱:retrofit-jaxrs,代碼行數:17,代碼來源:RestAdapter.java

示例12: GenericHttpRequest

import retrofit.mime.TypedOutput; //導入依賴的package包/類
GenericHttpRequest(Request request)
{
  super();
  method = request.getMethod();
  setURI(URI.create(request.getUrl()));

  // Add all headers.
  for (Header header : request.getHeaders())
  {
    addHeader(new BasicHeader(header.getName(), header.getValue()));
  }

  // Add the content body, if any.
  TypedOutput body = request.getBody();
  if (body != null)
  {
    setEntity(new TypedOutputEntity(body));
  }
}
 
開發者ID:toadzky,項目名稱:retrofit-jaxrs,代碼行數:20,代碼來源:ApacheClient.java

示例13: Request

import retrofit.mime.TypedOutput; //導入依賴的package包/類
public Request(String method, String url, List<Header> headers, TypedOutput body)
{
  if (method == null)
  {
    throw new NullPointerException("Method must not be null.");
  }
  if (url == null)
  {
    throw new NullPointerException("URL must not be null.");
  }
  this.method = method;
  this.url = url;

  if (headers == null)
  {
    this.headers = Collections.emptyList();
  }
  else
  {
    this.headers = Collections.unmodifiableList(new ArrayList<Header>(headers));
  }

  this.body = body;
}
 
開發者ID:toadzky,項目名稱:retrofit-jaxrs,代碼行數:25,代碼來源:Request.java

示例14: bodyTypedBytes

import retrofit.mime.TypedOutput; //導入依賴的package包/類
@Test
public void bodyTypedBytes()
{
  class Example
  {
    @PUT
    @Path("/")
    Response a(TypedOutput o)
    {
      return null;
    }
  }

  Method method = TestingUtils.getMethod(Example.class, "a");
  RestMethodInfo methodInfo = new RestMethodInfo(method);
  methodInfo.init();

  assertThat(methodInfo.requestParamNames).hasSize(1).containsExactly(new String[]{null});
  assertThat(methodInfo.requestParamUsage).hasSize(1).containsExactly(BODY);
  assertThat(methodInfo.requestType).isEqualTo(SIMPLE);
}
 
開發者ID:toadzky,項目名稱:retrofit-jaxrs,代碼行數:22,代碼來源:RestMethodInfoTest.java

示例15: multipart

import retrofit.mime.TypedOutput; //導入依賴的package包/類
@Test
public void multipart() throws Exception
{
  Map<String, TypedOutput> bodyParams = new LinkedHashMap<String, TypedOutput>();
  bodyParams.put("foo", new TypedString("bar"));
  bodyParams.put("ping", new TypedString("pong"));
  TypedOutput body = TestingUtils.createMultipart(bodyParams);
  Request request = new Request("POST", HOST + "/that/", null, body);

  DummyHttpUrlConnection connection = (DummyHttpUrlConnection) client.openConnection(request);
  client.prepareRequest(connection, request);

  byte[] output = connection.getOutputStream().toByteArray();

  assertThat(connection.getRequestMethod()).isEqualTo("POST");
  assertThat(connection.getURL().toString()).isEqualTo(HOST + "/that/");
  assertThat(connection.getRequestProperties()).hasSize(2);
  assertThat(connection.getRequestProperty("Content-Type")).startsWith("multipart/form-data;");
  assertThat(connection.getRequestProperty("Content-Length")).isEqualTo(String.valueOf(output.length));
  assertThat(output.length).isGreaterThan(0);
}
 
開發者ID:toadzky,項目名稱:retrofit-jaxrs,代碼行數:22,代碼來源:UrlConnectionClientTest.java


注:本文中的retrofit.mime.TypedOutput類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。