-
Notifications
You must be signed in to change notification settings - Fork 0
/
AsyncFileChannelRadAccessor.kt
61 lines (56 loc) · 2.02 KB
/
AsyncFileChannelRadAccessor.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
@file:JvmMultifileClass
@file:JvmName("Rad")
@file:Suppress("FunctionName", "DeprecatedCallableAddReplaceWith", "DEPRECATION")
package fluxo.io.rad
import androidx.annotation.RequiresApi
import fluxo.io.internal.Blocking
import java.io.File
import java.nio.channels.AsynchronousFileChannel
/**
* Creates a new [RandomAccessData] instance backed by the given [AsynchronousFileChannel].
*
* WARNING: [AsynchronousFileChannel] is super slow for all platforms.
* Seems to be the slowest possible IO API for JVM/Android.
* Also, it often has [OutOfMemoryError] (Direct buffer memory) problems.
*
* **WARNING: Remember to close the [RandomAccessData] when finished
* to properly release resources!*
*
* @param data the underlying channel
* @param offset the offset of the section
* @param size the length of the section
*/
@Blocking
@JvmOverloads
@RequiresApi(26)
@JvmName("forAsyncFileChannel")
@Deprecated("Not recommended for usage, slow and can has OOM problems.")
public fun RadAsyncFileChannelAccessor(
data: AsynchronousFileChannel,
offset: Long = 0L,
size: Long = data.size() - offset,
): RandomAccessData = AsyncFileChannelRad(data, offset = offset, size = size)
/**
* Creates a new [RandomAccessData] instance backed by the given [file][data].
*
* WARNING: [AsynchronousFileChannel] is super slow for all platforms.
* Seems to be the slowest possible IO API for JVM/Android.
* Also, it often has [OutOfMemoryError] (Direct buffer memory) problems.
*
* **WARNING: Remember to close the [RandomAccessData] when finished
* to properly release resources!*
*
* @param data the underlying file
* @param offset the offset of the section
* @param size the length of the section
*/
@Blocking
@JvmOverloads
@RequiresApi(26)
@JvmName("forAsyncFileChannel")
@Deprecated("Not recommended for usage, slow and can has OOM problems.")
public fun RadAsyncFileChannelAccessor(
data: File,
offset: Long = 0L,
size: Long = data.length() - offset,
): RandomAccessData = AsyncFileChannelRad(data, offset = offset, size = size)