Example #1
0
 protected static void checkEOF(FileRegion region, long writtenBytes) throws IOException {
   if (writtenBytes < region.count()) {
     throw new EOFException(
         "Expected to be able to write "
             + region.count()
             + " bytes, but only wrote "
             + writtenBytes);
   }
 }
Example #2
0
    private void sendFile0(FileRegion region, ChannelFuture future) {
      if (flushTaskInProgress == null) {
        flushTaskInProgress = new FlushTask(region, future);
        try {
          // the first FileRegion to flush so trigger it now!
          doFlushFileRegion(region, future);
        } catch (Throwable cause) {
          region.close();
          future.setFailure(cause);
        }
        return;
      }

      FlushTask task = flushTaskInProgress;
      for (; ; ) {
        FlushTask next = task.next;
        if (next == null) {
          break;
        }
        task = next;
      }
      // there is something that needs to get flushed first so add it as next in the chain
      task.next = new FlushTask(region, future);
    }