AtomicFileKt

public final class AtomicFileKt


Summary

Public methods

static final @RequiresApi(value = "17") @NonNull byte[]

Gets the entire content of this file as a byte array.

static final @RequiresApi(value = "17") @NonNull String
AtomicFileKt.readText(
    @NonNull AtomicFile receiver,
    @NonNull Charset charset
)

Gets the entire content of this file as a String using UTF-8 or specified charset.

static final @RequiresApi(value = "17") void
AtomicFileKt.tryWrite(
    @NonNull AtomicFile receiver,
    @NonNull Function1<@NonNull FileOutputStreamUnit> block
)

Perform the write operations inside block on this file.

static final @RequiresApi(value = "17") void
AtomicFileKt.writeBytes(
    @NonNull AtomicFile receiver,
    @NonNull byte[] array
)

Sets the content of this file as an array of bytes.

static final @RequiresApi(value = "17") void
AtomicFileKt.writeText(
    @NonNull AtomicFile receiver,
    @NonNull String text,
    @NonNull Charset charset
)

Sets the content of this file as text encoded using UTF-8 or specified charset.

Public methods

AtomicFileKt.readBytes

@RequiresApi(value = "17")
@NonNull
public static final @RequiresApi(value = "17") byte[] AtomicFileKt.readBytes(@NonNull AtomicFile receiver)

Gets the entire content of this file as a byte array.

This method is not recommended on huge files. It has an internal limitation of 2 GB file size.

AtomicFileKt.readText

@RequiresApi(value = "17")
@NonNull
public static final @RequiresApi(value = "17") String AtomicFileKt.readText(
    @NonNull AtomicFile receiver,
    @NonNull Charset charset
)

Gets the entire content of this file as a String using UTF-8 or specified charset.

This method is not recommended on huge files. It has an internal limitation of 2 GB file size.

AtomicFileKt.tryWrite

@RequiresApi(value = "17")
@NonNull
public static final @RequiresApi(value = "17") void AtomicFileKt.tryWrite(
    @NonNull AtomicFile receiver,
    @NonNull Function1<@NonNull FileOutputStreamUnit> block
)

Perform the write operations inside block on this file. If block throws an exception the write will be failed. Otherwise the write will be applied atomically to the file.

AtomicFileKt.writeBytes

@RequiresApi(value = "17")
@NonNull
public static final @RequiresApi(value = "17") void AtomicFileKt.writeBytes(
    @NonNull AtomicFile receiver,
    @NonNull byte[] array
)

Sets the content of this file as an array of bytes.

AtomicFileKt.writeText

@RequiresApi(value = "17")
@NonNull
public static final @RequiresApi(value = "17") void AtomicFileKt.writeText(
    @NonNull AtomicFile receiver,
    @NonNull String text,
    @NonNull Charset charset
)

Sets the content of this file as text encoded using UTF-8 or specified charset. If this file exists, it becomes overwritten.