Last active
February 26, 2019 11:35
-
-
Save xiyoulaoyuanjia/53d17ba2bf935c6721eb08c0168ce904 to your computer and use it in GitHub Desktop.
解压文件到hdfs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class IOUtils { | |
/** | |
* 解压缩本地文件到hdfs。 | |
* @param srcPath | |
* @param tgtPath | |
*/ | |
public static void gzipFileToHdfs(String srcPath,String tgtPath){ | |
Configuration conf=new Configuration(); | |
GzipCodec zip=new GzipCodec(); | |
if(!srcPath.endsWith(zip.getDefaultExtension())) return; | |
zip.setConf(conf); | |
Path _srcPath=new Path(srcPath); | |
Path _tgtPath=new Path(tgtPath); | |
FileSystem srcDfs; | |
FileSystem tgtDfs; | |
try { | |
srcDfs = _srcPath.getFileSystem(conf); | |
tgtDfs = _tgtPath.getFileSystem(conf); | |
CompressionInputStream input=zip.createInputStream(srcDfs.open(_srcPath)); | |
FSDataOutputStream out=tgtDfs.create(_tgtPath); | |
org.apache.hadoop.io.IOUtils.copyBytes(input,out,conf); | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} | |
} | |
public static void main(String[] args) { | |
// TODO Auto-generated method stub | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment