-2

I would like to know if its possible to read binary data from a blobstore and convert it into the desired file type. eg.

I receive binary data representing these files

example.txt
example.jpg
example.pdf

Would I have to parse the files names from the string name and to get the file type, then use those types to encode the binary back to the desired file type?

  • What exactly do you want as your output? – Nulano Mar 05 '17 at 17:06
  • In theory it's possible. I don't know of any library which does this though. – Peter Lawrey Mar 05 '17 at 17:07
  • @Nulano I would want the correctly encoded files as the output? Not just an array of byte data – getting_there Mar 06 '17 at 14:19
  • Binary files (such as pdf, zip, jpg) are encoded as an array of bytes. Just write them to the disk with a `FileOutputStream`. Text files are usually encoded with the system-default encoding. You can try `new String(data)`, or wrap your `InputStream` (or `ByteArrayInputStream`) into a `Reader`. (or you can just write the data as bytes and let the system handle it) – Nulano Mar 06 '17 at 14:46

1 Answers1

0

You just need to save the data exactly as you got it using the name. No conversion needed.

john16384
  • 7,800
  • 2
  • 30
  • 44
  • What do you mean by this? Its an array of byte data. – getting_there Mar 06 '17 at 14:17
  • The files are already in the correct format (the byte array contains bytes representing the JPG format or TXT format). Just because you stored a JPG does not mean that somekind of conversion is happening, it just stored the bytes. Reading them again is therefore just a matter of writing those bytes back to a file. – john16384 Mar 06 '17 at 14:20
  • Ok, that makes sense now that I think about it., Thanks – getting_there Mar 06 '17 at 14:29