public ZipInputStream createInputStream() throws IOException {
   ZipInputStream stream = new ZipInputStream(inner.createInputStream());
   if (openEntry) {
     stream.getNextEntry();
   }
   return stream;
 }
  Collection<FileAnnotation> parse(
      final InputStreamProvider file, final Collection<String> sources, final String moduleName)
      throws IOException, DocumentException, SAXException {
    InputStream input = null;
    try {
      input = file.getInputStream();
      Map<String, String> hashToMessageMapping = new HashMap<String, String>();
      Map<String, String> categories = new HashMap<String, String>();
      for (XmlBugInstance bug : preParse(input)) {
        hashToMessageMapping.put(bug.getInstanceHash(), bug.getMessage());
        categories.put(bug.getType(), bug.getCategory());
      }
      IOUtils.closeQuietly(input);

      input = file.getInputStream();
      return parse(input, sources, moduleName, hashToMessageMapping, categories);
    } finally {
      IOUtils.closeQuietly(input);
    }
  }
Esempio n. 3
0
  /**
   * Decodes and sub-samples an image
   *
   * @param is Stream to read image from
   * @param width Max height of returned image
   * @param height Max width of returned image
   * @param config Bitmap target coding
   * @return An image constrained by the given bounds, or null on failure
   */
  public static Bitmap decodeStream(
      InputStreamProvider provider, int width, int height, Bitmap.Config config) {
    InputStream is;

    // Check the size of the image
    BitmapFactory.Options options = new BitmapFactory.Options();
    options.inPreferredConfig = config;
    options.inJustDecodeBounds = true;

    try {
      is = provider.getInputStream();
      BitmapFactory.decodeStream(is, null, options);
    } catch (IOException e) {
      return null;
    }

    if (options.outWidth < 0 || options.outHeight < 0) {
      return null;
    }

    setSampleSize(width, height, options);

    // Reset the stream and decode the image
    Bitmap bm;
    try {
      is = provider.getInputStream();
      bm = BitmapFactory.decodeStream(is, null, options);
    } catch (IOException e) {
      return null;
    }

    // Resize the image to fit the bounds
    if (bm != null) {
      return resize(bm, width, height);
    }

    return null;
  }