⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ziphtmlfilesystem.java

📁 swing编写的库存管理程序。毕业设计类
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
    if (StringUtil.endsWithIgnoreCase(file, ".jpeg"))
    {
      return true;
    }
    if (StringUtil.endsWithIgnoreCase(file, ".png"))
    {
      return true;
    }
    if (StringUtil.endsWithIgnoreCase(file, ".gif"))
    {
      return true;
    }
    return false;
  }

  /**
   * Creates a HtmlReference for ImageData. If the target filesystem does not support
   * this reference type, return an empty content reference, but never null.
   * <p>
   * If the image was generated during the report processing or is not in a commonly
   * supported format, then the image is recoded as PNG and the recoded image is
   * included in the data directory.
   * <p>
   * If external referenced data should be copied into the data directory, then
   * the Image content is read and copied into the data directory.
   *
   * @param reference the image reference containing the data.
   *
   * @return the generated HtmlReference, never null.
   *
   * @throws IOException if IO errors occured while creating the reference.
   *
   * @see ZIPHtmlFilesystem#isSupportedImageFormat
   */
  public HtmlReferenceData createImageReference(final ImageReference reference)
      throws IOException
  {
    if (reference.getSourceURL() == null)
    {
      final WaitingImageObserver obs = new WaitingImageObserver(reference.getImage());
      obs.waitImageLoaded();

      final PngEncoder encoder = new PngEncoder(reference.getImage(),
          PngEncoder.ENCODE_ALPHA, PngEncoder.FILTER_NONE, 5);
      final byte[] data = encoder.pngEncode();

      final Object object = comparator.createCompareData(data, isDigestImageCompare() == false);
      String name = (String) encodedImages.get(object);
      if (name == null)
      {
        // encode the picture ...
        final String entryName = dataDirectory + createName("picture") + ".png";
        final ZipEntry ze = new ZipEntry(entryName);
        zipOut.putNextEntry(ze);

        //File dataFile = new File (dataDirectory, createName("picture") + ".png");
        // a png encoder is included in JCommon ...
        zipOut.write(data);

        name = entryName;
        encodedImages.put(object, name);
      }
      return new ImageReferenceData(name);
    }
    else if (isSupportedImageFormat(reference.getSourceURL()) == false)
    {
      final URL url = reference.getSourceURL();
      String name = (String) usedURLs.get(url);
      if (name == null)
      {
        final WaitingImageObserver obs = new WaitingImageObserver(reference.getImage());
        obs.waitImageLoaded();

        final PngEncoder encoder = new PngEncoder(reference.getImage(),
            PngEncoder.ENCODE_ALPHA, PngEncoder.FILTER_NONE, 5);
        final byte[] data = encoder.pngEncode();

        final IOUtils iou = IOUtils.getInstance();
        final String entryName = dataDirectory
            + createName(iou.stripFileExtension(iou.getFileName(url))) + ".png";
        final ZipEntry ze = new ZipEntry(entryName);
        zipOut.putNextEntry(ze);

        //File dataFile = new File (dataDirectory, createName("picture") + ".png");
        // a png encoder is included in JCommon ...
        zipOut.write(data);

        name = entryName;
        // encode the picture ...
        // a png encoder is included in JCommon ...
        usedURLs.put(url, name);
      }
      return new ImageReferenceData(name);
    }
    else if (isCopyExternalImages())
    {
      final URL url = reference.getSourceURL();
      String name = (String) usedURLs.get(url);
      if (name == null)
      {
        final IOUtils iou = IOUtils.getInstance();
        final String entryName = dataDirectory + createName(iou.getFileName(url));
        final ZipEntry ze = new ZipEntry(entryName);
        zipOut.putNextEntry(ze);

        //File dataFile = new File (dataDirectory, createName("picture") + ".png");
        // a png encoder is included in JCommon ...

        final InputStream urlIn = new BufferedInputStream(reference.getSourceURL().openStream());
        IOUtils.getInstance().copyStreams(urlIn, zipOut);
        urlIn.close();

        name = entryName;
        usedURLs.put(url, name);
      }
      return new ImageReferenceData(name);
    }
    else
    {
      final String baseName = reference.getSourceURL().toExternalForm();
      return new ImageReferenceData(baseName);
    }
  }

  /**
   * Creates an unique name for resources in the data directory.
   *
   * @param base the basename.
   * @return the unique name generated using the basename.
   */
  private String createName(final String base)
  {
    CounterReference ref = (CounterReference) usedNames.get(base);
    if (ref == null)
    {
      ref = new CounterReference();
      usedNames.put(base, ref);
      return base;
    }
    else
    {
      ref.increase();
      return base + ref.getCount();
    }
  }

  /**
   * Creates a HtmlReference for StyleSheetData. If the target filesystem does not
   * support external stylesheets, return an inline stylesheet reference.
   *
   * @param styleSheet the stylesheet data, which should be referenced.
   * @return the generated HtmlReference, never null.
   * @throws IOException if IO errors occured while creating the reference.
   */
  public HtmlReferenceData createCSSReference(final String styleSheet)
      throws IOException
  {
    final String entryName = dataDirectory + createName("style") + ".css";
    final ZipEntry ze = new ZipEntry(entryName);
    zipOut.putNextEntry(ze);

    //File dataFile = new File (dataDirectory, createName("picture") + ".png");
    // a png encoder is included in JCommon ...

    zipOut.write(styleSheet.getBytes());

    final String baseName = entryName;
    return new HRefReferenceData(baseName);
  }

  /**
   * Close the Filesystem and write any buffered content. The filesystem will not
   * be accessed, after close was called.
   *
   * @throws IOException if the close operation failed.
   */
  public void close() throws IOException
  {
    final String entryName = createName("report") + ".html";
    final ZipEntry ze = new ZipEntry(entryName);
    zipOut.putNextEntry(ze);

    rootStream.flush();
    rootStream.close();
    final byte[] data = rootBase.toByteArray();
    rootBase = null;

    final InflaterInputStream infIn
        = new InflaterInputStream(new BufferedInputStream(new ByteArrayInputStream(data)));
    IOUtils.getInstance().copyStreams(infIn, zipOut);
    zipOut.closeEntry();
    zipOut.flush();
    zipOut.close();
  }

  /**
   * Returns, whether to use digest image compare instead of internal
   * java methods. This method reduces memory consumption for the price
   * of complexer computations (and reduced execution speed).
   *
   * @return true, if the digest compare should be used, false otherwise.
   */
  public boolean isDigestImageCompare()
  {
    return digestImageCompare;
  }

  /**
   * Defines, whether to use digest image compare instead of internal
   * java methods. This method reduces memory consumption for the price
   * of complexer computations (and reduced execution speed).
   *
   * @param digestImageCompare set to true, if the digest compare should
   * be used, false otherwise.
   */
  public void setDigestImageCompare(final boolean digestImageCompare)
  {
    this.digestImageCompare = digestImageCompare;
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -