Java BufferedImage Load loadImagesForVVPAT(File ballotFile)

Here you can find the source of loadImagesForVVPAT(File ballotFile)

Description

Loads the VVPAT ready files from the ballot.

License

Open Source License

Parameter

Parameter Description
ballotFile - the ballot file

Return

a map of "image-id" (L**, B**, etc.) to vvpat ready images.

Declaration

public static Map<String, Image> loadImagesForVVPAT(File ballotFile) 

Method Source Code

//package com.java2s;
/**//from  w w w .j av  a2 s .  c  o m
 * This file is part of VoteBox.
 * 
 * VoteBox is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 3 as published by
 * the Free Software Foundation.
 * 
 * You should have received a copy of the GNU General Public License
 * along with VoteBox, found in the root of any distribution or
 * repository containing all or part of VoteBox.
 * 
 * THIS SOFTWARE IS PROVIDED BY WILLIAM MARSH RICE UNIVERSITY, HOUSTON,
 * TX AND IS PROVIDED 'AS IS' AND WITHOUT ANY EXPRESS, IMPLIED OR
 * STATUTORY WARRANTIES, INCLUDING, BUT NOT LIMITED TO, WARRANTIES OF
 * ACCURACY, COMPLETENESS, AND NONINFRINGEMENT.  THE SOFTWARE USER SHALL
 * INDEMNIFY, DEFEND AND HOLD HARMLESS RICE UNIVERSITY AND ITS FACULTY,
 * STAFF AND STUDENTS FROM ANY AND ALL CLAIMS, ACTIONS, DAMAGES, LOSSES,
 * LIABILITIES, COSTS AND EXPENSES, INCLUDING ATTORNEYS' FEES AND COURT
 * COSTS, DIRECTLY OR INDIRECTLY ARISING OUR OF OR IN CONNECTION WITH
 * ACCESS OR USE OF THE SOFTWARE.
 */

import java.awt.Image;

import java.io.File;

import java.util.Enumeration;
import java.util.HashMap;

import java.util.Map;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import javax.imageio.ImageIO;

public class Main {
    /**
     * Loads the VVPAT ready files from the ballot.
     * 
     * @param ballotFile - the ballot file
     * @return a map of "image-id" (L**, B**, etc.) to vvpat ready images.
     */
    public static Map<String, Image> loadImagesForVVPAT(File ballotFile) {
        return loadImagesForVVPAT(ballotFile.getAbsolutePath());
    }

    /**
     * Loads the VVPAT ready files from the ballot.
     * 
     * @param ballotPath - the path to the ballot file
     * @return a map of "image-id" (L**, B**, etc.) to vvpat ready images.
     */
    public static Map<String, Image> loadImagesForVVPAT(String ballotPath) {
        Map<String, Image> vvpatMap = new HashMap<String, Image>();
        try {
            ZipFile file = new ZipFile(ballotPath);
            Enumeration<? extends ZipEntry> entries = file.entries();

            while (entries.hasMoreElements()) {
                ZipEntry entry = entries.nextElement();

                if (entry.getName().endsWith("/vvpat/accept.png"))
                    vvpatMap.put("accept",
                            ImageIO.read(file.getInputStream(entry)));

                if (entry.getName().endsWith("/vvpat/spoil.png"))
                    vvpatMap.put("spoil",
                            ImageIO.read(file.getInputStream(entry)));

                if (entry.getName().endsWith(".png")
                        && entry.getName().contains("/vvpat/")) {
                    String id = entry.getName();
                    id = id.substring(id.lastIndexOf("/vvpat/") + 7);

                    int sub = id.indexOf("_");

                    if (sub == -1)
                        continue;

                    id = id.substring(0, sub);

                    vvpatMap.put(id,
                            ImageIO.read(file.getInputStream(entry)));
                }
            }
        } catch (Exception e) {
            System.out
                    .println("BallotImageHelper ERROR: " + e.getMessage());
            return null;
        }

        return vvpatMap;
    }
}

Related

  1. loadImagefromJar(Object refObj, String fileName)
  2. loadImageFromURL(String imageURL, Component component)
  3. loadImageFromVisualgorithmJar(String imageFileName)
  4. loadImageRessource(Object source, String file)
  5. loadImages(Image[] images, Component comp)
  6. loadResource(String file)