Guest User

Untitled

a guest
Apr 21st, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.51 KB | None | 0 0
  1. fun localFileFromRequestUri(basePath: File, uri: URI): File {
  2. val basePathElements = basePath.absolutePath.split(File.separator).filter { it.isNotEmpty() }.toMutableSet()
  3. val clientPathElements = uri.path.substring(1).split(File.separatorChar)
  4. val filteredPathElements = clientPathElements.mapNotNull {
  5. if (!basePathElements.remove(it)) {
  6. it
  7. } else {
  8. null
  9. }
  10. }.joinToString(separator = File.separator) { it }
  11.  
  12. return File(basePath, filteredPathElements)
  13. }
Add Comment
Please, Sign In to add comment