Create a temporary file from base64 string using excpture-io

So basically I want to create a temporary file from the contents of the base64 string . Right now, I'm doing this with my own java-io functions. But I would like to achieve the same result using the rapture-io library for scala .

So my question is: can this be achieved with the help of enthusiasm and, if so, how ?

I already looked through the documentation, but not specific enough:

https://github.com/propensive/rapture-io/blob/master/doc/introduction.md

Here is my actual code:

import org.apache.commons.codec.binary.Base64 import java.io.FileOutputStream import java.io.File val data: String = base64StringContent //Base64 String content of the file. val fileName = myFileName val fileExt = myFileExt //It does write the file in my temp folder. val file: File = File.createTempFile(fileName, fileExt) val fileByteArray: Array[Byte] = Base64.decodeBase64(data) val fileOutFile: FileOutputStream = new FileOutputStream(file) fileOutFile.write(fileByteArray) fileOutFile.close() file.deleteOnExit() file 
+6
source share
1 answer

Does this work for you?

 import rapture.fs.platform.posix import rapture.io._ import rapture.core._ import rapture.fs._ import strategy.throwExceptions val tmpFile = (File / "tmp").tempFile(prefix = "yourfileName",suffix = ".extension") "data" >> tmpFile tmpFile.deleteOnExit() tmpFile.delete() 

Not completed on Windows. You may need to use a different delimiter, e.g.. \\ instead of /

 import rapture.fs.platform.windows import rapture.io._ import rapture.core._ import rapture.fs._ import strategy.throwExceptions val tmpFile = (File / "C:" / "Windows" / "Temp" ).tempFile(prefix = "yourfileName",suffix = ".extension") "data" >> tmpFile tmpFile.deleteOnExit() tmpFile.delete() 
+1
source

Source: https://habr.com/ru/post/977662/


All Articles