+ return Integer.toHexString((int) crc.getValue())
+ .toUpperCase();
+ }
+
+ public static File getThumbnailsDirectory(final File directoryToIndex) {
+ return new File(getThumbnailsDirectoryPath(directoryToIndex));
+ }
+
+ public static String getThumbnailsDirectoryPath(final File directoryToIndex) {
+ return directoryToIndex.getAbsolutePath() + "/"
+ + Constants.THUMBNAILS_DIRECTORY_NAME + "/";
+ }
+
+ public static boolean isMevizGeneratedIndexFile(final File indexFile)
+ throws IOException {
+
+ boolean isMevizFile = false;
+
+ final FileReader fileReader = new FileReader(indexFile);
+ final BufferedReader reader = new BufferedReader(fileReader);
+
+ parseFile:
+ {
+ while (true) {
+ final String line = reader.readLine();
+
+ if (line == null)
+ break parseFile;
+
+ if (line.contains(Constants.HTML_MAGIC_STRING)) {
+ isMevizFile = true;
+ break parseFile;
+ }
+ }
+ }
+
+ reader.close();
+ fileReader.close();
+ return isMevizFile;
+ }
+
+ /**
+ * TODO: URL path component is encoded differently from URL query parameter.
+ * Also some URL encoding might work for HTML on local filesystem, while other
+ * stuff works for web. Things must be cleared up here. Currently they are mixed and
+ * hacked together.
+ */
+ public static String urlEncode(String string) {
+ if (string.startsWith("./"))
+ string = string.substring(2);
+
+ // TODO: get rid of UrlParamEncoder.
+ return UrlParamEncoder.encode(string);
+ //
+// try {
+// return URLEncoder.encode(string, UTF_8).replace("+", "%20");
+// } catch (UnsupportedEncodingException e) {
+// throw new RuntimeException(e);
+// }
+ }
+
+ public static ImageFrame[] readGIF(ImageReader reader) throws IOException {
+ ArrayList<ImageFrame> frames = new ArrayList<ImageFrame>(2);
+
+ int width = -1;
+ int height = -1;
+
+ IIOMetadata metadata = reader.getStreamMetadata();
+ if (metadata != null) {
+ IIOMetadataNode globalRoot = (IIOMetadataNode) metadata.getAsTree(metadata.getNativeMetadataFormatName());
+
+ NodeList globalScreenDescriptor = globalRoot.getElementsByTagName("LogicalScreenDescriptor");
+
+ if (globalScreenDescriptor != null && globalScreenDescriptor.getLength() > 0) {
+ IIOMetadataNode screenDescriptor = (IIOMetadataNode) globalScreenDescriptor.item(0);
+
+ if (screenDescriptor != null) {
+ width = Integer.parseInt(screenDescriptor.getAttribute("logicalScreenWidth"));
+ height = Integer.parseInt(screenDescriptor.getAttribute("logicalScreenHeight"));
+ }
+ }
+ }
+
+ BufferedImage master = null;
+ Graphics2D masterGraphics = null;
+
+ for (int frameIndex = 0;; frameIndex++) {
+ BufferedImage image;
+ try {
+ image = reader.read(frameIndex);
+ } catch (IndexOutOfBoundsException io) {
+ break;
+ }
+
+ if (width == -1 || height == -1) {
+ width = image.getWidth();
+ height = image.getHeight();
+ }