Convert JInputStream to Base64

  

I convert a JInputStream to base64 with a MemoryStream as intermediary. I need to do that because JInputStream doesn’t extend the base class TStream.
I deliberately simplified the code by removing the try/finally block.
JStream := TAndroidHelper.ContentResolver.openInputStream(StrToJURI(FSelector.Files[I]));
Buffer := TJavaArray<Byte>.Create(JStream.Available);
JStream.Read(Buffer);

MStream := TMemoryStream.Create;
MStream.Write(Buffer.Data^, Buffer.Length);
MStream.position := 0;

SStream := TStringStream.Create(”, TEncoding.ASCII);
Soap.EncdDecd.EncodeStream(MStream, SStream);
Base64Stream := SStream.DataString;
Base64Stream := Base64Stream.Replace(#10, ”);
Base64Stream := Base64Stream.Replace(#13, ”);

Does a method exist to directly convert the data of my JInputSream to base64?

Comments are closed.