file

open override fun file(path: String): UrlSource

Creates a ContentSource for path within this root.

A relative path is resolved against the root: against FileSystemSource.pathPrefix on the local file system, and against AbstractRepo.rawSourcePrefix for repositories, where the path begins with the branch name (e.g. "main/src/App.kt"). An absolute file path, or for repositories a full URL (one that starts with a scheme such as https://), is used unchanged.

No containment is applied: .. segments and absolute paths escape a FileSystemSource's directory, and a repository reads any full URL, including file: URLs and internal hosts. Validate a path that comes from user input before passing it here. A repository's UrlSource follows no redirect by default, so a redirect cannot take a validated URL to another host, but nothing bounds the size of what it reads or how long it takes unless AbstractRepo.file is given maxBytes and fetchTimeout.

Return

a ContentSource that can be used to read the file's content

Parameters

path

the path to the file, relative to this root


fun file(path: String, connectTimeout: Duration = DEFAULT_CONNECT_TIMEOUT, readTimeout: Duration = DEFAULT_READ_TIMEOUT, fetchTimeout: Duration = Duration.INFINITE, maxBytes: Long = Long.MAX_VALUE, followRedirects: Boolean = false): UrlSource

Creates a UrlSource for path, as file does, with the given timeouts and limits; see UrlSource for each.

Parameters

path

the path to the file, relative to this root, or a full URL

connectTimeout

the maximum time to wait for a connection (default 10 seconds)

readTimeout

the maximum time to wait for data once connected (default 30 seconds)

fetchTimeout

the maximum time for the whole fetch (default none)

maxBytes

the largest body accepted, in bytes (default no limit)

followRedirects

whether to follow HTTP redirects (default false)


fun file(path: String, connectTimeout: Duration, readTimeout: Duration, fetchTimeout: Duration, maxBytes: Long, followRedirects: Boolean): UrlSource

Creates a UrlSource for path with timeouts given as java.time.Duration and every limit, for Java callers: the overload taking Kotlin durations cannot be called from Java.

Parameters

path

the path to the file, relative to this root, or a full URL

connectTimeout

the maximum time to wait for a connection

readTimeout

the maximum time to wait for data once connected

fetchTimeout

the maximum time for the whole fetch; java.time.Duration.ZERO means none

maxBytes

the largest body accepted, in bytes; Long.MAX_VALUE means no limit

followRedirects

whether to follow HTTP redirects