Search in sources :

Example 1 with TempFileIOChannel

use of org.ballerinalang.nativeimpl.io.channels.TempFileIOChannel in project ballerina by ballerina-lang.

the class EntityBodyHandler method getByteChannelForTempFile.

/**
 * Given a temp file location, create a byte channel.
 *
 * @param temporaryFilePath Temporary file path
 * @return ByteChannel which represent the file channel
 */
public static TempFileIOChannel getByteChannelForTempFile(String temporaryFilePath) {
    FileChannel fileChannel;
    Set<OpenOption> options = new HashSet<>();
    options.add(StandardOpenOption.READ);
    Path path = Paths.get(temporaryFilePath);
    try {
        fileChannel = (FileChannel) Files.newByteChannel(path, options);
    } catch (IOException e) {
        throw new BallerinaException("Error occurred while creating a file channel from a temporary file");
    }
    return new TempFileIOChannel(fileChannel, IOConstants.CHANNEL_BUFFER_SIZE, temporaryFilePath);
}
Also used : Path(java.nio.file.Path) OpenOption(java.nio.file.OpenOption) StandardOpenOption(java.nio.file.StandardOpenOption) TempFileIOChannel(org.ballerinalang.nativeimpl.io.channels.TempFileIOChannel) FileChannel(java.nio.channels.FileChannel) IOException(java.io.IOException) BallerinaIOException(org.ballerinalang.nativeimpl.io.BallerinaIOException) BallerinaException(org.ballerinalang.util.exceptions.BallerinaException) HashSet(java.util.HashSet)

Aggregations

IOException (java.io.IOException)1 FileChannel (java.nio.channels.FileChannel)1 OpenOption (java.nio.file.OpenOption)1 Path (java.nio.file.Path)1 StandardOpenOption (java.nio.file.StandardOpenOption)1 HashSet (java.util.HashSet)1 BallerinaIOException (org.ballerinalang.nativeimpl.io.BallerinaIOException)1 TempFileIOChannel (org.ballerinalang.nativeimpl.io.channels.TempFileIOChannel)1 BallerinaException (org.ballerinalang.util.exceptions.BallerinaException)1