resp.setContentType("text/csv");
resp.setHeader("Content-disposition", "attachment;filename="
+ tableName + ".csv");
PrintWriter w = resp.getWriter();
TableModel t = tableManager.getTableModel(tableName);
String inputFormatString = t.getInputFormat();
char fieldDelim = t.getFieldDelim()==null? DEFAULT_FIELD_DELIM:t.getFieldDelim().toCharArray()[0];
char lineDelim = t.getLineDelim() == null ? DEFAULT_LINE_DELIM : t
.getLineDelim().toCharArray()[0];
final Configuration conf = ConfUtil.getDefaultCoreSite();
Profile profile = profileManager.findByUid(user.getUid());
if (profile != null) {
String ugi = profile.getHadoopConf().get("hadoop.hadoop.job.ugi");
if (ugi != null) {
conf.set("hadoop.job.ugi", ugi);
}
}
JobConf confQ = new JobConf(conf);
FileSystem fs = FileSystem.get(confQ);
InputFormat inputFormat;
try {
inputFormat = (InputFormat) ReflectionUtils.newInstance(
Class.forName(inputFormatString), conf);
} catch (ClassNotFoundException e) {
log.error("partition download error", e);
w.write("分区下载失败");
return;
}
RecordReader<Writable, Writable> reader;
FileStatus[] files = fs.listStatus(new Path(pathString));
if (files == null) {
log("无法访问" + pathString + "\n路径不存在或没有访问权限! ");
w.write("无法访问" + pathString + "\n路径不存在或没有访问权限! ");
return;
}
boolean first = true;
for (TableColumnModel col : t.getCols()) {
if (first) {
first = false;
} else {
w.write(',');
}