Uploaded image for project: 'PDFBox'
  1. PDFBox
  2. PDFBOX-1006

Unnecessary using intermediate ByteArrayInputStream to copy from given byte array to OutputStream in FlateFilter::decode

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Trivial
    • Resolution: Fixed
    • Affects Version/s: 1.5.0
    • Fix Version/s: 1.6.0
    • Component/s: None
    • Labels:
      None

      Description

      It is not required to use intermediate ByteArrayInputStream to copy from given byte array to OutputStream. When we have byte[], it's okay just to call write(byte[]) method of OutputStream to write all data at once.

      AS IS:

      // Copy data to ByteArrayInputStream for reading
      bais = new ByteArrayInputStream(baos.toByteArray());
      baos.close();
      baos = null;

      byte[] decodedData = decodePredictor(predictor, colors, bitsPerPixel, columns, bais);
      bais.close();
      bais = new ByteArrayInputStream(decodedData);

      // write decoded data to result
      while ((amountRead = bais.read(buffer)) != -1)

      { result.write(buffer, 0, amountRead); }

      bais.close();
      bais = null;

      TO BE:

      // Copy data to ByteArrayInputStream for reading
      bais = new ByteArrayInputStream(baos.toByteArray());
      baos.close();
      baos = null;

      byte[] decodedData = decodePredictor(predictor, colors, bitsPerPixel, columns, bais);
      bais.close();
      bais = null;

      result.write(decodedData);

        Attachments

          Activity

            People

            • Assignee:
              lehmi Andreas Lehmkühler
              Reporter:
              bsp Sergey Vladimirov
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Time Tracking

                Estimated:
                Original Estimate - 1h
                1h
                Remaining:
                Remaining Estimate - 1h
                1h
                Logged:
                Time Spent - Not Specified
                Not Specified