Hi Matt,
Matt Culbreth <
mattcu...@gmail.com> writes:
> I'm using slurp to read data from a file and send it to a stream, but
> sometimes that's failing. I've got a theory that it has to do with
> slurp not reading binary data correctly. Is that true? Do I need to
> go down to the lower level Java classes and build a byte array using
> InputFileStream and .read()?
Yep, you're spot on. The problem is that slurp reads data as
characters, not bytes, so they'll likely be interpreted as UTF-8
(depends on your locale settings unless you set it explicitly) which
will mess them up if they're not actually UTF-8 characters.
You should indeed use byte arrays or DataInputStream or ByteBuffer or
similar (depending on what sort of manipulation you need to do) rather
than strings when working with non-textual data. Note that
c.c.duck-streams (now known as
c.c.io) 'copy multimethod when given
streams or byte arrays (not reader, writers or strings) will do the
right thing.