List of usage examples for com.squareup.okhttp RequestBody create
public static RequestBody create(final MediaType contentType, final File file)
From source file:pl.appformation.smash.SmashOkHttp.java
License:Apache License
private static RequestBody convertBody(SmashRequest request, BufferedSource body) throws SmashError { try {//from w w w .ja v a2 s. c o m return RequestBody.create(MediaType.parse(request.getBodyContentType()), body.readUtf8()); } catch (IOException ioe) { throw new SmashError(ioe); } }
From source file:retrofit.converter.GsonConverter.java
License:Apache License
@Override public RequestBody toBody(Object object, Type type) { String json = gson.toJson(object, type); return RequestBody.create(mediaType, json); }
From source file:retrofit.JacksonConverter.java
License:Apache License
@Override public RequestBody toBody(T value) { try {/*from w w w . j av a 2s. c om*/ byte[] bytes = writer.writeValueAsBytes(value); return RequestBody.create(MEDIA_TYPE, bytes); } catch (JsonProcessingException e) { throw new RuntimeException(e); } }
From source file:retrofit.JacksonRequestBodyConverter.java
License:Apache License
@Override public RequestBody convert(T value) throws IOException { byte[] bytes = adapter.writeValueAsBytes(value); return RequestBody.create(MEDIA_TYPE, bytes); }
From source file:retrofit.MoshiConverter.java
License:Apache License
@Override public RequestBody toBody(T value) { Buffer buffer = new Buffer(); try {//from w w w.j a v a2s .c o m adapter.toJson(buffer, value); } catch (IOException e) { throw new AssertionError(e); } return RequestBody.create(MEDIA_TYPE, buffer.snapshot()); }
From source file:retrofit.ProtoConverter.java
License:Apache License
@Override public RequestBody toBody(T value) { byte[] bytes = value.toByteArray(); return RequestBody.create(MEDIA_TYPE, bytes); }
From source file:retrofit.ProtoRequestBodyConverter.java
License:Apache License
@Override public RequestBody convert(T value) throws IOException { byte[] bytes = value.toByteArray(); return RequestBody.create(MEDIA_TYPE, bytes); }
From source file:retrofit.ScalarRequestBodyConverter.java
License:Apache License
@Override public RequestBody convert(T value) throws IOException { return RequestBody.create(MEDIA_TYPE, String.valueOf(value)); }
From source file:retrofit.SimpleXmlConverter.java
License:Apache License
@Override public RequestBody toBody(T value) { Buffer buffer = new Buffer(); try {/* w ww . ja va2s .c om*/ OutputStreamWriter osw = new OutputStreamWriter(buffer.outputStream(), CHARSET); serializer.write(value, osw); osw.flush(); } catch (Exception e) { throw new RuntimeException(e); } return RequestBody.create(MEDIA_TYPE, buffer.readByteString()); }
From source file:retrofit.SimpleXmlRequestBodyConverter.java
License:Apache License
@Override public RequestBody convert(T value) throws IOException { Buffer buffer = new Buffer(); try {/* w ww . j ava 2 s.c om*/ OutputStreamWriter osw = new OutputStreamWriter(buffer.outputStream(), CHARSET); serializer.write(value, osw); osw.flush(); } catch (Exception e) { throw new RuntimeException(e); } return RequestBody.create(MEDIA_TYPE, buffer.readByteString()); }