com.github.yoojia.halo.DownloadTransferAdapter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of halo-download Show documentation
Show all versions of halo-download Show documentation
A FAST && THIN && HIGH SCALABLE Java web framework
package com.github.yoojia.halo;
import java.io.File;
import java.io.FileInputStream;
import java.nio.channels.Channels;
import java.nio.channels.FileChannel;
import java.nio.channels.WritableByteChannel;
import java.nio.file.Path;
/**
* @author YOOJIA.CHEN ([email protected])
*/
final class DownloadTransferAdapter {
private final File inputFile;
private DownloadTransferAdapter(Path path) {
inputFile = path.toFile();
}
static DownloadTransferAdapter use(Path path) {
return new DownloadTransferAdapter(path);
}
public void dispatch(HaloResponse response) throws Exception {
try(FileChannel in = new FileInputStream(inputFile).getChannel();
WritableByteChannel out = Channels.newChannel(response.httpResponse.getOutputStream())){
in.transferTo(0, in.size(), out);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy