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);
}
Aggregations