I see this method:
trait Compressioner {
def ioStream(is: InputStream, os: OutputStream, bufferSize: Int = 4096): Int = {
val buffer = new Array[Byte](bufferSize)
@tailrec
def doStream(total: Int): Int = {
val n = is.read(buffer)
if (n == -1) total
else {
os.write(buffer, 0, n)
doStream(total + n)
}
}
doStream(0)
}
So I just wanted to check to see if I understand this. We're initializing a Byte Array (and a byte is 8 bits long and is used to represent a character or letter) and that's our buffer (which is a temporary storage, often in memory).
What is the @ sign?
We then read from the input stream 4096 bytes a time (which is often 4096 characters at a time?). read
returns -1 if there is nothing left and that's our end condition. Otherwise we take our bytes that we read and write it to the output stream. Is that correct interpretation of this? Did I say anything inaccurately?