2 * Meviz - Various tools collection to work with multimedia.
3 * Copyright (C) 2012, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of version 2 of the GNU General Public License
7 * as published by the Free Software Foundation.
10 package eu.svjatoslav.meviz.htmlindexer;
12 import java.awt.image.BufferedImage;
14 import java.io.IOException;
15 import java.util.zip.CRC32;
17 import javax.imageio.ImageIO;
21 private static File lastLoadedFile;
23 private static BufferedImage lastLoadedBufferedImage;
26 * Load image into {@link BufferedImage} and return it. Caches last loaded
27 * image to speed up subsequent loading attempts.
29 * @throws ImageFormatError
32 public static BufferedImage getBufferedImage(final File file) throws ImageFormatError, IOException {
33 if (file.equals(lastLoadedFile)) {
34 return lastLoadedBufferedImage;
37 System.out.println("Loading image: " + file.getPath());
38 lastLoadedBufferedImage = ImageIO.read(file);
39 lastLoadedFile = file;
41 if (lastLoadedBufferedImage == null)
42 throw new ImageFormatError("File: " + file + " is not a valid image.");
44 return lastLoadedBufferedImage;
47 public static String getStringCrcAsHex(final String input) {
49 // create a new CRC-calculating object
50 final CRC32 crc = new CRC32();
52 // loop, calculating CRC for each byte of the string
53 // There is no CRC16.update(byte[]) method.
54 for (final byte b : input.getBytes()) {
58 // note use crc.value, not crc.getValue()
59 final String hex = Integer.toHexString((int) crc.getValue()).toUpperCase();
61 // System.out.println("Input string: " + input);
62 // System.out.println("Result: " + hex);