Exemplo n.º 1
0
 /// <summary>Send a partial content response with the given range.</summary>
 /// <remarks>
 /// Send a partial content response with the given range. If there are
 /// no satisfiable ranges, or if multiple ranges are requested, which
 /// is unsupported, respond with range not satisfiable.
 /// </remarks>
 /// <param name="in">stream to read from</param>
 /// <param name="out">stream to write to</param>
 /// <param name="response">http response to use</param>
 /// <param name="contentLength">for the response header</param>
 /// <param name="ranges">to write to respond with</param>
 /// <exception cref="System.IO.IOException">on error sending the response</exception>
 internal static void SendPartialData(FSDataInputStream @in, OutputStream @out, HttpServletResponse
                                      response, long contentLength, IList <InclusiveByteRange> ranges)
 {
     if (ranges == null || ranges.Count != 1)
     {
         response.SetContentLength(0);
         response.SetStatus(HttpServletResponse.ScRequestedRangeNotSatisfiable);
         response.SetHeader("Content-Range", InclusiveByteRange.To416HeaderRangeString(contentLength
                                                                                       ));
     }
     else
     {
         InclusiveByteRange singleSatisfiableRange = ranges[0];
         long singleLength = singleSatisfiableRange.GetSize(contentLength);
         response.SetStatus(HttpServletResponse.ScPartialContent);
         response.SetHeader("Content-Range", singleSatisfiableRange.ToHeaderRangeString(contentLength
                                                                                        ));
         CopyFromOffset(@in, @out, singleSatisfiableRange.GetFirst(contentLength), singleLength
                        );
     }
 }