本文整理了Java中okio.Buffer.outputStream()
方法的一些代码示例,展示了Buffer.outputStream()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Buffer.outputStream()
方法的具体详情如下:
包路径:okio.Buffer
类名称:Buffer
方法名:outputStream
暂无
代码示例来源:origin: square/retrofit
@Override public RequestBody convert(final T value) throws IOException {
Buffer buffer = new Buffer();
try {
Marshaller marshaller = context.createMarshaller();
XMLStreamWriter xmlWriter = xmlOutputFactory.createXMLStreamWriter(
buffer.outputStream(), JaxbConverterFactory.XML.charset().name());
marshaller.marshal(value, xmlWriter);
} catch (JAXBException | XMLStreamException e) {
throw new RuntimeException(e);
}
return RequestBody.create(JaxbConverterFactory.XML, buffer.readByteString());
}
}
代码示例来源:origin: square/retrofit
@Override public RequestBody convert(T value) throws IOException {
Buffer buffer = new Buffer();
try {
OutputStreamWriter osw = new OutputStreamWriter(buffer.outputStream(), CHARSET);
serializer.write(value, osw);
osw.flush();
} catch (RuntimeException | IOException e) {
throw e;
} catch (Exception e) {
throw new RuntimeException(e);
}
return RequestBody.create(MEDIA_TYPE, buffer.readByteString());
}
}
代码示例来源:origin: square/okio
private ByteString serialize(Object o) throws IOException {
Buffer buffer = new Buffer();
try (ObjectOutputStream objectOut = new ObjectOutputStream(buffer.outputStream())) {
objectOut.writeObject(o);
}
return buffer.readByteString();
}
代码示例来源:origin: square/retrofit
@Override public RequestBody convert(T value) throws IOException {
Buffer buffer = new Buffer();
Writer writer = new OutputStreamWriter(buffer.outputStream(), UTF_8);
JsonWriter jsonWriter = gson.newJsonWriter(writer);
adapter.write(jsonWriter, value);
jsonWriter.close();
return RequestBody.create(MEDIA_TYPE, buffer.readByteString());
}
}
代码示例来源:origin: amitshekhariitbhu/Fast-Android-Networking
@Override
public RequestBody convert(T value) throws IOException {
Buffer buffer = new Buffer();
Writer writer = new OutputStreamWriter(buffer.outputStream(), UTF_8);
JsonWriter jsonWriter = gson.newJsonWriter(writer);
adapter.write(jsonWriter, value);
jsonWriter.close();
return RequestBody.create(MEDIA_TYPE, buffer.readByteString());
}
}
代码示例来源:origin: com.squareup.retrofit2/converter-gson
@Override public RequestBody convert(T value) throws IOException {
Buffer buffer = new Buffer();
Writer writer = new OutputStreamWriter(buffer.outputStream(), UTF_8);
JsonWriter jsonWriter = gson.newJsonWriter(writer);
adapter.write(jsonWriter, value);
jsonWriter.close();
return RequestBody.create(MEDIA_TYPE, buffer.readByteString());
}
}
代码示例来源:origin: square/wire
private static ByteString serialize(Message message) throws Exception {
Buffer buffer = new Buffer();
ObjectOutputStream stream = new ObjectOutputStream(buffer.outputStream());
stream.writeObject(message);
stream.flush();
return buffer.readByteString();
}
代码示例来源:origin: k9mail/k-9
@Before
public void setUp() throws Exception {
buffer = new Buffer();
smtpDataStuffing = new SmtpDataStuffing(buffer.outputStream());
}
代码示例来源:origin: square/okio
/** Use DeflaterOutputStream to deflate source. */
private Buffer deflate(ByteString source) throws IOException {
Buffer result = new Buffer();
Sink sink = Okio.sink(new DeflaterOutputStream(result.outputStream()));
sink.write(new Buffer().write(source), source.size());
sink.close();
return result;
}
代码示例来源:origin: k9mail/k-9
private int getSizeOfSerializedBody(TextBody textBody) throws IOException, MessagingException {
Buffer buffer = new Buffer();
textBody.writeTo(buffer.outputStream());
return buffer.readByteString().size();
}
}
代码示例来源:origin: k9mail/k-9
@Test
public void fetchPart_withTextSection_shouldProcessImapResponses() throws Exception {
ImapFolder folder = createFolder("Folder");
prepareImapFolderForOpen(OPEN_MODE_RO);
folder.open(OPEN_MODE_RO);
ImapMessage message = createImapMessage("1");
Part part = createPlainTextPart("1.1");
setupSingleFetchResponseToCallback();
folder.fetchPart(message, part, null, new DefaultBodyFactory());
ArgumentCaptor<Body> bodyArgumentCaptor = ArgumentCaptor.forClass(Body.class);
verify(part).setBody(bodyArgumentCaptor.capture());
Body body = bodyArgumentCaptor.getValue();
Buffer buffer = new Buffer();
body.writeTo(buffer.outputStream());
assertEquals("text", buffer.readUtf8());
}
代码示例来源:origin: googlemaps/google-maps-services-java
LocalTestServerContext(BufferedImage image) throws IOException {
this.server = new MockWebServer();
Buffer buffer = new Buffer();
ImageIO.write(image, "png", buffer.outputStream());
MockResponse response = new MockResponse();
response.setHeader("Content-Type", "image/png");
response.setBody(buffer);
server.enqueue(response);
server.start();
this.context =
new GeoApiContext.Builder()
.apiKey("AIzaFakeKey")
.baseUrlOverride("http://127.0.0.1:" + server.getPort())
.build();
}
代码示例来源:origin: com.squareup.retrofit/converter-gson
@Override public RequestBody convert(T value) throws IOException {
Buffer buffer = new Buffer();
Writer writer = new OutputStreamWriter(buffer.outputStream(), UTF_8);
try {
gson.toJson(value, type, writer);
writer.flush();
} catch (IOException e) {
throw new AssertionError(e); // Writing to Buffer does no I/O.
}
return RequestBody.create(MEDIA_TYPE, buffer.readByteString());
}
}
代码示例来源:origin: Lauzy/TicktockMusic
@Override
public RequestBody convert(@NonNull T value) throws IOException {
Buffer buffer = new Buffer();
Writer writer = new OutputStreamWriter(buffer.outputStream(), UTF_8);
JsonWriter jsonWriter = gson.newJsonWriter(writer);
adapter.write(jsonWriter, value);
jsonWriter.close();
return RequestBody.create(MEDIA_TYPE, buffer.readByteString());
}
}
代码示例来源:origin: lionoggo/Akit-Reader
@Override
public RequestBody convert(T value) throws IOException {
Buffer buffer = new Buffer();
Writer writer = new OutputStreamWriter(buffer.outputStream(), UTF_8);
JsonWriter jsonWriter = gson.newJsonWriter(writer);
adapter.write(jsonWriter, value);
jsonWriter.close();
return RequestBody.create(MEDIA_TYPE, buffer.readByteString());
}
}
代码示例来源:origin: lionoggo/FastApp
@Override
public RequestBody convert(T value) throws IOException {
Buffer buffer = new Buffer();
Writer writer = new OutputStreamWriter(buffer.outputStream(), UTF_8);
JsonWriter jsonWriter = gson.newJsonWriter(writer);
adapter.write(jsonWriter, value);
jsonWriter.close();
return RequestBody.create(MEDIA_TYPE, buffer.readByteString());
}
}
代码示例来源:origin: lionoggo/FastApp
@Override
public RequestBody convert(T value) throws IOException {
Buffer buffer = new Buffer();
Writer writer = new OutputStreamWriter(buffer.outputStream(), UTF_8);
JsonWriter jsonWriter = gson.newJsonWriter(writer);
adapter.write(jsonWriter, value);
jsonWriter.close();
return RequestBody.create(MEDIA_TYPE, buffer.readByteString());
}
}
代码示例来源:origin: lionoggo/Akit-Reader
@Override
public RequestBody convert(T value) throws IOException {
Buffer buffer = new Buffer();
Writer writer = new OutputStreamWriter(buffer.outputStream(), UTF_8);
JsonWriter jsonWriter = gson.newJsonWriter(writer);
adapter.write(jsonWriter, value);
jsonWriter.close();
return RequestBody.create(MEDIA_TYPE, buffer.readByteString());
}
}
代码示例来源:origin: vaibhav-sinha/kong-java-client
@Override
public RequestBody convert(T value) throws IOException {
Buffer buffer = new Buffer();
Writer writer = new OutputStreamWriter(buffer.outputStream(), UTF_8);
JsonWriter jsonWriter = gson.newJsonWriter(writer);
adapter.write(jsonWriter, value);
jsonWriter.close();
return RequestBody.create(MEDIA_TYPE, buffer.readByteString());
}
}
代码示例来源:origin: flipkart-incubator/proteus
@Override
public RequestBody convert(T value) throws IOException {
TypeAdapter<T> adapter = getAdapter();
Buffer buffer = new Buffer();
Writer writer = new OutputStreamWriter(buffer.outputStream(), UTF_8);
JsonWriter jsonWriter = gson.newJsonWriter(writer);
jsonWriter.setSerializeNulls(true);
adapter.write(jsonWriter, value);
jsonWriter.close();
return RequestBody.create(MEDIA_TYPE, buffer.readByteString());
}
}
内容来源于网络,如有侵权,请联系作者删除!