f.login(usr, pwd);
f.changeWorkingDirectory(dir);
f.setFileType(FTP.BINARY_FILE_TYPE);
boolean isCompressed = getCompressOutput(job);
CompressionCodec codec = null;
String extension = "";
if (isCompressed) {
Class<? extends CompressionCodec> codecClass = getOutputCompressorClass(
job, GzipCodec.class);
codec = (CompressionCodec) ReflectionUtils.newInstance(codecClass,
conf);
extension = codec.getDefaultExtension();
}
Path file = getDefaultWorkFile(job, extension);
FileSystem fs = file.getFileSystem(conf);
String filename = file.getName();
if (!isCompressed) {
// FSDataOutputStream fileOut = fs.create(file, false);
OutputStream os = f.appendFileStream(filename);
DataOutputStream fileOut = new DataOutputStream(os);
return new FTPLineRecordWriter<K, V>(fileOut, new String(
keyValueSeparator), f);
} else {
// FSDataOutputStream fileOut = fs.create(file, false);
OutputStream os = f.appendFileStream(filename);
DataOutputStream fileOut = new DataOutputStream(os);
return new FTPLineRecordWriter<K, V>(new DataOutputStream(
codec.createOutputStream(fileOut)), keyValueSeparator, f);
}
}