All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.atlan.pkg.serde.csv.ThreadSafeWriter.kt Maven / Gradle / Ivy

There is a newer version: 3.1.2
Show newest version
/* SPDX-License-Identifier: Apache-2.0
   Copyright 2023 Atlan Pte. Ltd. */
package com.atlan.pkg.serde.csv

import java.io.Closeable
import java.io.IOException
import java.io.Writer
import java.nio.charset.StandardCharsets
import java.nio.file.Files
import java.nio.file.Paths

/**
 * To allow us to safely parallel-write files across threads.
 */
class ThreadSafeWriter(filePath: String) : Writer(), Closeable {
    private val writer = Files.newBufferedWriter(Paths.get(filePath), StandardCharsets.UTF_8)

    /** {@inheritDoc}  */
    @Synchronized
    @Throws(IOException::class)
    override fun write(
        cbuf: CharArray,
        off: Int,
        len: Int,
    ) {
        writer.write(cbuf, off, len)
    }

    /** {@inheritDoc}  */
    @Synchronized
    @Throws(IOException::class)
    override fun flush() {
        writer.flush()
    }

    /** {@inheritDoc}  */
    @Synchronized
    @Throws(IOException::class)
    override fun close() {
        writer.close()
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy