コード例 #1
0
ファイル: SplitStream.java プロジェクト: gspandy/divconq
  // make sure we don't return without first releasing the file reference content
  @Override
  public ReturnOption handle(FileDescriptor file, ByteBuf data) {
    if (file == FileDescriptor.FINAL) return this.downstream.handle(file, data);

    ByteBuf in = data;

    if (in != null) {
      while (in.isReadable()) {
        int amt = Math.min(in.readableBytes(), this.size - this.currchunk);

        ByteBuf out = in.copy(in.readerIndex(), amt);

        in.skipBytes(amt);
        this.currchunk += amt;

        boolean eof = (this.currchunk == this.size) || (!in.isReadable() && file.isEof());

        this.nextMessage(out, file, eof);

        if (eof) {
          this.seqnum++;
          this.currchunk = 0;
        }
      }

      in.release();
    } else if (file.isEof()) {
      this.nextMessage(null, file, false);
    }

    // write all messages in the queue
    while (this.outlist.size() > 0) {
      ReturnOption ret = this.downstream.handle(this.outlist.remove(0), this.outbuf.remove(0));

      if (ret != ReturnOption.CONTINUE) return ret;
    }

    return ReturnOption.CONTINUE;
  }
コード例 #2
0
ファイル: SplitStream.java プロジェクト: gspandy/divconq
  public void nextMessage(ByteBuf out, FileDescriptor curr, boolean eof) {
    // create the output message
    FileDescriptor blk = new FileDescriptor();

    blk.setModTime(System.currentTimeMillis());

    // keep the path, just vary the name to the template
    blk.setPath(curr.path().resolvePeer("/" + this.template.replace("%seq%", this.seqnum + "")));

    blk.setEof(eof);

    if (eof) blk.setSize(this.currchunk);
    else blk.setSize(0); // don't know yet

    this.outlist.add(blk);
    this.outbuf.add(out);
  }