Exemplo n.º 1
0
  @Override
  public ByteBuffer downloadChunk(String id) throws TException {
    TimeCacheMap<Object, Object> downloaders = data.getDownloaders();
    Object obj = downloaders.get(id);
    if (obj == null) {
      throw new TException("Could not find input stream for that id");
    }

    try {
      if (obj instanceof BufferFileInputStream) {
        BufferFileInputStream is = (BufferFileInputStream) obj;
        byte[] ret = is.read();
        if (ret != null) {
          downloaders.put(id, (BufferFileInputStream) is);
          return ByteBuffer.wrap(ret);
        }
      } else {
        throw new TException("Object isn't BufferFileInputStream for " + id);
      }
    } catch (IOException e) {
      LOG.error("BufferFileInputStream read failed when downloadChunk ", e);
      throw new TException(e);
    }
    byte[] empty = {};
    return ByteBuffer.wrap(empty);
  }
Exemplo n.º 2
0
  @Override
  public String beginFileDownload(String file) throws TException {
    BufferFileInputStream is = null;
    String id = null;
    try {
      is = new BufferFileInputStream(file);
      id = UUID.randomUUID().toString();
      data.getDownloaders().put(id, is);
    } catch (FileNotFoundException e) {
      LOG.error(e + "file:" + file + " not found");
      throw new TException(e);
    }

    return id;
  }