Program: 3282
Project: 3282
Buggy source:
/** 
 * Write the actual data out to the response. Some implementation notes, 1) We set a short expires time just in the hopes of preventing someone from overloading the server by clicking reload a bunch of times. I realize that this is nowhere near 100% effective but it may help in some cases and shouldn't hurt anything. 2) We accept partial downloads, thus if you lose a connection half way through most web browser will enable you to resume downloading the bitstream.
 */
public void generate() throws IOException, SAXException, ProcessingException {
  if (this.bitstreamInputStream == null)   return;
  if (isSpider) {
    long modSince=request.getDateHeader("String_Node_Str");
    if (modSince != -1 && item.getLastModified().getTime() < modSince) {
      response.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
      return;
    }
  }
  try {
    if (isSpider || ContextUtil.obtainContext(request).getCurrentUser() == null) {
      response.setDateHeader("String_Node_Str",item.getLastModified().getTime());
    }
  }
 catch (  SQLException e) {
    throw new ProcessingException(e);
  }
  byte[] buffer=new byte[BUFFER_SIZE];
  int length=-1;
  if (isAnonymouslyReadable)   response.setDateHeader("String_Node_Str",System.currentTimeMillis() + expires);
  int threshold=ConfigurationManager.getIntProperty("String_Node_Str");
  if (bitstreamSize > threshold && threshold != 0) {
    String name=bitstreamName;
    try {
      String agent=request.getHeader("String_Node_Str");
      if (agent != null && agent.contains("String_Node_Str"))       name=URLEncoder.encode(name,"String_Node_Str");
 else       if (agent != null && agent.contains("String_Node_Str"))       name=MimeUtility.encodeText(name,"String_Node_Str","String_Node_Str");
    }
 catch (    UnsupportedEncodingException see) {
    }
    response.setHeader("String_Node_Str","String_Node_Str" + name);
  }
  String ranges=null;
  ByteRange byteRange=null;
  if (ranges != null) {
    try {
      ranges=ranges.substring(ranges.indexOf('=') + 1);
      byteRange=new ByteRange(ranges);
    }
 catch (    NumberFormatException e) {
      byteRange=null;
      if (response instanceof HttpResponse) {
        ((HttpResponse)response).setStatus(416);
      }
    }
  }
  if (byteRange != null) {
    String entityLength;
    String entityRange;
    if (this.bitstreamSize != -1) {
      entityLength="String_Node_Str" + this.bitstreamSize;
      entityRange=byteRange.intersection(new ByteRange(0,this.bitstreamSize)).toString();
    }
 else {
      entityLength="String_Node_Str";
      entityRange=byteRange.toString();
    }
    response.setHeader("String_Node_Str",entityRange + "String_Node_Str" + entityLength);
    if (response instanceof HttpResponse) {
      ((HttpResponse)response).setStatus(206);
    }
    int pos=0;
    int posEnd;
    while ((length=this.bitstreamInputStream.read(buffer)) > -1) {
      posEnd=pos + length - 1;
      ByteRange intersection=byteRange.intersection(new ByteRange(pos,posEnd));
      if (intersection != null) {
        out.write(buffer,(int)intersection.getStart() - pos,(int)intersection.length());
      }
      pos+=length;
    }
  }
 else {
    response.setHeader("String_Node_Str",String.valueOf(this.bitstreamSize));
    while ((length=this.bitstreamInputStream.read(buffer)) > -1) {
      out.write(buffer,0,length);
    }
    out.flush();
  }
}

Fixed version (ground truth):
/** 
 * Write the actual data out to the response. Some implementation notes, 1) We set a short expires time just in the hopes of preventing someone from overloading the server by clicking reload a bunch of times. I realize that this is nowhere near 100% effective but it may help in some cases and shouldn't hurt anything. 2) We accept partial downloads, thus if you lose a connection half way through most web browser will enable you to resume downloading the bitstream.
 */
public void generate() throws IOException, SAXException, ProcessingException {
  if (this.bitstreamInputStream == null)   return;
  if (isSpider) {
    long modSince=request.getDateHeader("String_Node_Str");
    if (modSince != -1 && item != null && item.getLastModified().getTime() < modSince) {
      response.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
      return;
    }
  }
  try {
    if (item != null && (isSpider || ContextUtil.obtainContext(request).getCurrentUser() == null)) {
      response.setDateHeader("String_Node_Str",item.getLastModified().getTime());
    }
  }
 catch (  SQLException e) {
    throw new ProcessingException(e);
  }
  byte[] buffer=new byte[BUFFER_SIZE];
  int length=-1;
  if (isAnonymouslyReadable)   response.setDateHeader("String_Node_Str",System.currentTimeMillis() + expires);
  int threshold=ConfigurationManager.getIntProperty("String_Node_Str");
  if (bitstreamSize > threshold && threshold != 0) {
    String name=bitstreamName;
    try {
      String agent=request.getHeader("String_Node_Str");
      if (agent != null && agent.contains("String_Node_Str"))       name=URLEncoder.encode(name,"String_Node_Str");
 else       if (agent != null && agent.contains("String_Node_Str"))       name=MimeUtility.encodeText(name,"String_Node_Str","String_Node_Str");
    }
 catch (    UnsupportedEncodingException see) {
    }
    response.setHeader("String_Node_Str","String_Node_Str" + name);
  }
  String ranges=null;
  ByteRange byteRange=null;
  if (ranges != null) {
    try {
      ranges=ranges.substring(ranges.indexOf('=') + 1);
      byteRange=new ByteRange(ranges);
    }
 catch (    NumberFormatException e) {
      byteRange=null;
      if (response instanceof HttpResponse) {
        ((HttpResponse)response).setStatus(416);
      }
    }
  }
  if (byteRange != null) {
    String entityLength;
    String entityRange;
    if (this.bitstreamSize != -1) {
      entityLength="String_Node_Str" + this.bitstreamSize;
      entityRange=byteRange.intersection(new ByteRange(0,this.bitstreamSize)).toString();
    }
 else {
      entityLength="String_Node_Str";
      entityRange=byteRange.toString();
    }
    response.setHeader("String_Node_Str",entityRange + "String_Node_Str" + entityLength);
    if (response instanceof HttpResponse) {
      ((HttpResponse)response).setStatus(206);
    }
    int pos=0;
    int posEnd;
    while ((length=this.bitstreamInputStream.read(buffer)) > -1) {
      posEnd=pos + length - 1;
      ByteRange intersection=byteRange.intersection(new ByteRange(pos,posEnd));
      if (intersection != null) {
        out.write(buffer,(int)intersection.getStart() - pos,(int)intersection.length());
      }
      pos+=length;
    }
  }
 else {
    response.setHeader("String_Node_Str",String.valueOf(this.bitstreamSize));
    while ((length=this.bitstreamInputStream.read(buffer)) > -1) {
      out.write(buffer,0,length);
    }
    out.flush();
  }
}