Example #1
0
 @Override
 public boolean fetch(OutputStream out, String filename) throws IOException {
   MetaFile metaFile = hdfsfilesRepository.getMetaFile(filename);
   SocketStream.writeInteger(metaFile.getLength().intValue(), out);
   HdfsHelper.fetch(out, metaFile.getStorename());
   return true;
 }
Example #2
0
 @Override
 public boolean delete(String filename) throws IOException {
   MetaFile metaFile = hdfsfilesRepository.getMetaFile(filename);
   HdfsHelper.delete(metaFile.getStorename(), false);
   // 删除元数据
   hdfsfilesRepository.delMetaFile(filename);
   return true;
 }
Example #3
0
  @Override
  public void save(InputStream is, int filelen, String filename) throws IOException {
    String md5filename = DigestUtils.md5Hex(filename);
    String hdfsname = basepath + md5filename;

    // 存储到HDFS上
    try {
      HdfsHelper.upload(is, filelen, hdfsname);
    } catch (IOException e) {
      logger.error(e);
      throw e;
    }

    // 添加元数据项
    // TODO: 大文件计划不保存元数据
    MetaFile metaFile = new MetaFile();
    metaFile.setLength(new Long(filelen));
    metaFile.setName(new File(filename).getName());
    metaFile.setStorename(md5filename);
    metaFile.setStorepos(-1L);
    hdfsfilesRepository.addMetaFile(filename, metaFile);
  }