toResource

通过提供的 ByteArray 直接构建一个 Resource

Return

Resource object representing the ByteArray data.

@JvmName(name = "valueOf")
fun File.toResource(charset: Charset = JvmStringReadableResource.DEFAULT_CHARSET): FileResource(source)

Converts a File to a FileResource. charset 会作为需要使用编码参数的方法的默认编码。 默认使用 JvmStringReadableResource.DEFAULT_CHARSET

Return

The converted FileResource.


@JvmName(name = "valueOf")
fun Path.toResource(charset: Charset = JvmStringReadableResource.DEFAULT_CHARSET, vararg options: OpenOption): PathResource(source)

Converts the given Path to a PathResource with the specified options.

Return

the PathResource representing the converted path

Parameters

charset

读取内容如果需要 Charset 信息时的默认值

options

the options to use for opening the resource (vararg)


@JvmName(name = "valueOf")
fun URL.toResource(charset: Charset = JvmStringReadableResource.DEFAULT_CHARSET): URIResource(source)

Converts the current URL to a URIResource.

使用 URL 构建的 URIResource 在使用 URIResource.stringURIResource.inputStream 时应当不会再产生 IllegalArgumentExceptionMalformedURLException 了,因为 URL 已经初始化好了。 取而代之的是 URL.toResource 可能会产生 URISyntaxException, 因为需要使用 URL.toURI

Return

The converted URIResource.

Parameters

charset

需要使用编码格式时的默认编码值,默认为 JvmStringReadableResource.DEFAULT_CHARSET

Throws


@JvmName(name = "valueOf")
fun URI.toResource(charset: Charset = JvmStringReadableResource.DEFAULT_CHARSET): URIResource(source)

Converts the current URI to a URIResource.

Return

The converted URIResource.

Parameters

charset

需要使用编码格式时的默认编码值,默认为 JvmStringReadableResource.DEFAULT_CHARSET