Skip to content

Instantly share code, notes, and snippets.

@Oleur
Last active November 24, 2020 15:53
Show Gist options
  • Save Oleur/80d9186635cea25c232c7df764777812 to your computer and use it in GitHub Desktop.
Save Oleur/80d9186635cea25c232c7df764777812 to your computer and use it in GitHub Desktop.
class SmbDataSource(private val dataSpec: DataSpec) : BaseDataSource(/* isNetwork= */ true) {
private val userName: String
private val password: String
private val hostName: String
private val shareName: String
private val path: String
init {
// Get user credentials
val uri = dataSpec.uri
val userInfo = uri.getUserInfo()
userInfo?.let {
val userInfoArray = userInfo.split(":")
username = userInfoArray[0] ?: "";
password = userInfoArray[1] ?: ""
hostname = uri.getHost() :? ""
val dirPath = if (uri.getPath().startsWith("/")) {
uri.getPath().substring(1).split("/", 2) ?: arrayOf("")
} else {
uri.getPath().split("/", 2) ?: arrayOf("")
}
shareName = path[0]
path = path[path.length - 1]
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment