Decode from stream instead of string
See original GitHub issueclass FromString(override val format: StringFormat) : Serializer() {
override fun <T> fromResponseBody(loader: DeserializationStrategy<T>, body: ResponseBody): T {
val string = body.string()
return format.decodeFromString(loader, string)
}
override fun <T> toRequestBody(contentType: MediaType, saver: SerializationStrategy<T>, value: T): RequestBody {
val string = format.encodeToString(saver, value)
return RequestBody.create(contentType, string)
}
}
to
class FromStream(override val format: StringFormat) : Serializer() {
override fun <T> fromResponseBody(loader: DeserializationStrategy<T>, body: ResponseBody): T {
val stream = body.byteStream()
return format.decodeFromStream(loader, stream)
}
override fun <T> toRequestBody(contentType: MediaType, saver: SerializationStrategy<T>, value: T): RequestBody {
val stream = ByteArrayOutputStream()
format.encodeToStream(saver, value, stream)
return RequestBody.create(contentType, stream.toByteArray())
}
}
Issue Analytics
- State:
- Created 2 years ago
- Comments:17 (10 by maintainers)
Top Results From Across the Web
c# - Converting Stream to String and back
I have just tested this and works fine. string test = "Testing 1-2-3"; // convert string to stream byte[] byteArray = Encoding.ASCII.
Read more >C# Convert String to Stream, and Stream to String
Hi All, i am converting string to stream like this: StreamReader Code = new StreamReader(new MemoryStream(Encoding.ASCII.GetBytes(refernceCode)));. As my ...
Read more >Java InputStream to String
In this tutorial, we'll look at how to convert an InputStream to a String. We'll start by using plain Java, including Java8/9 solutions,...
Read more >io — Core tools for working with streams — Python 3.11.1 ...
The TextIOBase ABC extends IOBase . It deals with streams whose bytes represent text, and handles encoding and decoding to and from strings....
Read more >3 Ways to Convert Java 8 Stream to an Array - Lambda ...
toArray(String[]::new ) will convert a Stream of String to an array of String ... hence it's toArray() method also return an int[] instead...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
No, nothing has really changed. Streaming still only works for JSON not all text formats. And the APIs this library uses are still marked as unstable which means we cannot upstream it yet.
No, the APIs we use are still unstable for any format.