Pergunta

I have a Scala application that executes an external process N times (with different parameters) and each time collects an Array[Byte] which is later aggregated into a collection of N Array[Byte] outputs. The question is whether each process output Array[Byte] will end with an EOF? and if so how it can be removed? I do this in Scala using the following code:

// redirect output stream of the external process 
val outputStream = new java.io.ByteArrayOutputStream()
val bufferedOutputStream = new java.io.BufferedOutputStream(outputStream, 1024)
// execute external process
val exitCode : Integer = processBuilder #> bufferedOutputStream !
bufferedOutputStream.flush
// read the content of the output stream as a byte array
val content = outputStream.toByteArray // this gives an Array[Byte]

I need to send every output as input to a third application. Therefore I would need to remove the partial EOF separators that would otherwise cause my third application to fail reading the N outputs.

Foi útil?

Solução

EOF isn't a character, it's an out-of-band condition that indicates the input stream is empty. You can "remove" it just by continuing to write content to the stream.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top