Description
Java bytes are converted in Swift as Int8 because Java considers bytes to be signed. This results in APIs that accept byte[]
to be converted as [Int8]
in Swift. This makes it really inconvenient to interact with native Data
values in Swift land, since we need to convert Data to [Int8] in order to pass it appropriately to Java APIs.
Data can be easily converted to [Int8] with data.map { Int8(bitPattern: $0 }
, but this results in unnecessary copying, which can make performant sensitive code feel slow.
Ideally, swift-java would provide support, and faster implementations, of these conversions. Not sure what would be all the use cases swift-java should support, but I think at the least java.ioByteArrayInputStream
and java.io.ByteArrayOutputStream
should be part of JavaKitIO
's native offering, and provide simple APIs for converting between these and Data types (the parents java.io.InputStream
and java.io.OutputStream
are already there).