commit 02/10/2025
This commit is contained in:
45
src/commandServer/PagingJob.kt
Normal file
45
src/commandServer/PagingJob.kt
Normal file
@@ -0,0 +1,45 @@
|
||||
package commandServer
|
||||
|
||||
import codes.Somecodes.Companion.PagingResult_directory
|
||||
import codes.Somecodes.Companion.filenameformat
|
||||
import org.tinylog.Logger
|
||||
import java.io.ByteArrayOutputStream
|
||||
import java.nio.file.Path
|
||||
import java.time.LocalDateTime
|
||||
|
||||
/**
|
||||
* Class to handle a paging job, storing incoming audio data and metadata.
|
||||
* @param fromIP The IP address from which the paging data is received.
|
||||
* @param broadcastzones The zones to which the paging is broadcasted, is a semicolon-separated string.
|
||||
*/
|
||||
class PagingJob(val fromIP: String, val broadcastzones: String) {
|
||||
val filePath : Path = PagingResult_directory.resolve(LocalDateTime.now().format(filenameformat)+"_RAW.wav")
|
||||
private val bos : ByteArrayOutputStream = ByteArrayOutputStream()
|
||||
var totalBytesReceived = 0; private set
|
||||
var isRunning = true; private set
|
||||
|
||||
|
||||
/**
|
||||
* Adds incoming audio data to the job.
|
||||
* @param data The byte array containing audio data.
|
||||
* @param length The number of bytes to write from the data array.
|
||||
*/
|
||||
fun addData(data: ByteArray, length: Int) {
|
||||
Logger.info{"PagingJob from $fromIP, zones: $broadcastzones, received $length bytes"}
|
||||
bos.write(data, 0, length)
|
||||
totalBytesReceived += length
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the accumulated audio data as a byte array.
|
||||
* @return A byte array containing all received audio data.
|
||||
*/
|
||||
fun GetData(): ByteArray {
|
||||
return bos.toByteArray()
|
||||
}
|
||||
|
||||
fun Close(){
|
||||
bos.close()
|
||||
isRunning = false
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user