使用HDFS文件系统在线浏览视频音频
JAVA API 读取hdfs系统文件
支持音频与视频
public void preview(String fpath, HttpServletRequest req, HttpServletResponse resp) throws IOException {
if (fpath == null)
return;
String filename = HADOOP_URL + fpath;
Configuration config = new Configuration();
FileSystem fs = null;
FSDataInputStream in = null;
try {
fs = FileSystem.get(URI.create(filename), config);
in = fs.open(new Path(filename));
} catch (IOException e) {
e.printStackTrace();
}
final long fileLen = fs.getFileStatus(new Path(filename)).getLen();
String range = req.getHeader("Range");
resp.setHeader("Content-type", "video/mp3");
OutputStream out = resp.getOutputStream();
if (range == null) {
filename = fpath.substring(fpath.lastIndexOf("/") + 1);
resp.setHeader("Content-Disposition", "attachment; filename=" + filename);
resp.setContentType("application/octet-stream");
resp.setContentLength((int) fileLen);
IOUtils.