AtomicFileKt

Added in 1.1.0

public final class AtomicFileKt


Summary

Public methods

static final @NonNull byte[]

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

static final @NonNull String
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 void
tryWrite(
    @NonNull AtomicFile receiver,
    @NonNull Function1<@NonNull FileOutputStreamUnit> block
)

Perform the write operations inside block on this file.

static final void
writeBytes(@NonNull AtomicFile receiver, @NonNull byte[] array)

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

static final void
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

readBytes

public static final @NonNull byte[] 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.

readText

public static final @NonNull String 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.

tryWrite

public static final void 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.

writeBytes

public static final void writeBytes(@NonNull AtomicFile receiver, @NonNull byte[] array)

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

writeText

public static final void 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.