code: public static void getFileServerForPartialFiles(OutputStream outstream,
        String filename, InputStream infile, DataTransferThrottler throttler,
        long startPosition, long lengthToSend) throws IOException {
      byte buf[] = new byte[BUFFER_SIZE];
      try {
        int num = 1;
        while (num > 0) {
          num = infile.read(buf, 0,
              Math.min(BUFFER_SIZE,
                  (int) Math.min(lengthToSend, Integer.MAX_VALUE)));
          lengthToSend -= num;
          if (num <= 0) {
            break;
          }
          try {
            outstream.write(buf, 0, num);
          } catch (Exception e) {
            // silently ignore. connection might have been closed
            break;
          }
          if (throttler != null) {
            throttler.throttle(num);
          }
        }
        if (lengthToSend > 0) {
          LOG.warn("Could not serve requested number of bytes. Left with "
              + lengthToSend + " bytes for file: " + filename);
        }
      } finally {
        if (infile != null) {
          infile.close();
        }
      }
    }
docs: A server-side method to respond to a getfile http request
  Copies the contents of the local file into the output stream,
  starting at the given position, sending lengthToSend bytes.