Skip to content

Instantly share code, notes, and snippets.

@Oleur
Created November 24, 2020 14:10
Show Gist options
  • Save Oleur/8e4ff807f868e7a54482f7f3ae70e278 to your computer and use it in GitHub Desktop.
Save Oleur/8e4ff807f868e7a54482f7f3ae70e278 to your computer and use it in GitHub Desktop.
class SmbDataSource(private val dataSpec: DataSpec) : BaseDataSource(/* isNetwork= */ true) {
private var bytesRemaining: Long
@Throws(IOException::class)
override fun read(buffer: ByteArray, offset: Int, readLength) {
if (readLength == 0) {
return 0
} else if (bytesRemaining == 0) {
return C.RESULT_END_OF_INPUT
}
// Here we are going to read the input stream and get the number of bytes read
var bytesRead = -1
try {
val bytesToRead = if (bytesRemaining == C.LENGTH_UNSET) readLength else min(bytesRemaining, readLength)
bytesRead = inputStream.read(buffer, offset, bytesToRead)
} catch (e: IOException) {
throw IOException(e)
}
if (bytesRead == -1) {
if (bytesRemaining != C.LENGTH_UNSET) {
// End of stream reached having not read sufficient data.
throw new IOException(new EOFException());
}
return C.RESULT_END_OF_INPUT;
}
if (bytesRemaining != C.LENGTH_UNSET) {
bytesRemaining -= bytesRead;
}
return bytesRead;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment