private static List<IDistanceDensityMul> getIDistanceDensityMulList(String url) throws FileNotFoundException, IOException { Configuration conf = HUtils.getConf(); SequenceFile.Reader reader = null; // 多个文件整合,需排序 List<IDistanceDensityMul> allList = new ArrayList<IDistanceDensityMul>(); // 单个文件 List<IDistanceDensityMul> fileList = new ArrayList<IDistanceDensityMul>(); FileStatus[] fss = HUtils.getHDFSPath(url, "true") .getFileSystem(conf) .listStatus(HUtils.getHDFSPath(url, "true")); for (FileStatus f : fss) { if (!f.toString().contains("part")) { continue; // 排除其他文件 } try { reader = new SequenceFile.Reader( conf, Reader.file(f.getPath()), Reader.bufferSize(4096), Reader.start(0)); // <density_i*min_distancd_j> <first:density_i,second:min_distance_j,third:i> // DoubleWritable, IntDoublePairWritable CustomDoubleWritable dkey = (CustomDoubleWritable) ReflectionUtils.newInstance(reader.getKeyClass(), conf); IntDoublePairWritable dvalue = (IntDoublePairWritable) ReflectionUtils.newInstance(reader.getValueClass(), conf); int i = Utils.GETDRAWPICRECORDS_EVERYFILE; while (reader.next(dkey, dvalue) && i > 0) { // 循环读取文件 i--; fileList.add( new IDistanceDensityMul( dvalue.getSecond(), dvalue.getFirst(), dvalue.getThird(), dkey.get())); // 每个文件都是从小到大排序的 } } catch (Exception e) { e.printStackTrace(); } finally { IOUtils.closeStream(reader); } // 整合当前文件的前面若干条记录(Utils.GETDRAWPICRECORDS_EVERYFILE ) if (allList.size() <= 0) { // 第一次可以全部添加 allList.addAll(fileList); } else { combineLists(allList, fileList); } } // for // 第一个点太大了,选择去掉 return allList.subList(1, allList.size()); }
public static XYSeries getXY(String url) { XYSeries xyseries = new XYSeries(""); Path path = new Path(url); Configuration conf = HUtils.getConf(); SequenceFile.Reader reader = null; try { reader = new SequenceFile.Reader( conf, Reader.file(path), Reader.bufferSize(4096), Reader.start(0)); DoubleArrStrWritable dkey = (DoubleArrStrWritable) ReflectionUtils.newInstance(reader.getKeyClass(), conf); DoublePairWritable dvalue = (DoublePairWritable) ReflectionUtils.newInstance(reader.getValueClass(), conf); while (reader.next(dkey, dvalue)) { // 循环读取文件 xyseries.add(dvalue.getFirst(), dvalue.getSecond()); } } catch (Exception e) { e.printStackTrace(); } finally { IOUtils.closeStream(reader); } return xyseries; }
/** * return the x*y * * @param url * @return */ public Double[] getR(String url) { List<Double> list = new ArrayList<Double>(); Path path = new Path(url); Configuration conf = HUtils.getConf(); SequenceFile.Reader reader = null; try { reader = new SequenceFile.Reader( conf, Reader.file(path), Reader.bufferSize(4096), Reader.start(0)); DoubleArrStrWritable dkey = (DoubleArrStrWritable) ReflectionUtils.newInstance(reader.getKeyClass(), conf); DoublePairWritable dvalue = (DoublePairWritable) ReflectionUtils.newInstance(reader.getValueClass(), conf); while (reader.next(dkey, dvalue)) { // 循环读取文件 // list.add(dvalue.getSum()*dvalue.getDistance()); } } catch (Exception e) { e.printStackTrace(); } finally { IOUtils.closeStream(reader); } Double[] dList = new Double[list.size()]; dList = list.toArray(dList); Arrays.sort(dList); return dList; }