Fixed bug where 0 byte pictures were treated incorrectly.
authorSvjatoslav Agejenko <svjatoslav@svjatoslav.eu>
Sun, 7 Dec 2014 20:17:34 +0000 (22:17 +0200)
committerSvjatoslav Agejenko <svjatoslav@svjatoslav.eu>
Sun, 7 Dec 2014 20:17:34 +0000 (22:17 +0200)
src/main/java/eu/svjatoslav/meviz/htmlindexer/Utils.java
src/main/java/eu/svjatoslav/meviz/htmlindexer/metadata/Dimension.java
src/main/java/eu/svjatoslav/meviz/htmlindexer/metadata/fileTypes/AbstractFile.java

index ab711a5..9da4656 100755 (executable)
@@ -1,7 +1,7 @@
 /*
  * Meviz - Various tools collection to work with multimedia.
  * Copyright (C) 2012, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
- * 
+ *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of version 2 of the GNU General Public License
  * as published by the Free Software Foundation.
@@ -24,14 +24,10 @@ import eu.svjatoslav.meviz.htmlindexer.layouts.MixedLayout;
 
 public class Utils {
 
-       private static File lastLoadedFile;
-
-       private static BufferedImage lastLoadedBufferedImage;
-
        /**
         * Load image into {@link BufferedImage} and return it. Caches last loaded
         * image to speed up subsequent loading attempts.
-        * 
+        *
         * @throws ImageFormatError
         * @throws IOException
         */
@@ -44,10 +40,13 @@ public class Utils {
                lastLoadedBufferedImage = ImageIO.read(file);
                lastLoadedFile = file;
 
-               if (lastLoadedBufferedImage == null)
+               if (lastLoadedBufferedImage == null) {
+                       System.out.println("Error reading image: " + file);
                        throw new ImageFormatError("File: " + file
                                        + " is not a valid image.");
 
+               }
+
                return lastLoadedBufferedImage;
        }
 
@@ -122,4 +121,8 @@ public class Utils {
                return isMevizFile;
        }
 
+       private static File lastLoadedFile;
+
+       private static BufferedImage lastLoadedBufferedImage;
+
 }
index 7841783..e9993b1 100755 (executable)
@@ -1,7 +1,7 @@
 /*
  * Meviz - Various tools collection to work with multimedia.
  * Copyright (C) 2012, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
- * 
+ *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of version 2 of the GNU General Public License
  * as published by the Free Software Foundation.
@@ -17,61 +17,67 @@ import java.io.Serializable;
 
 public class Dimension implements Serializable, Comparable<Dimension> {
 
-    private static final long serialVersionUID = -1039288266937331829L;
+       private static final long serialVersionUID = -1039288266937331829L;
 
-    public int width;
-    public int height;
+       public int width;
+       public int height;
 
-    public Dimension() {
-        width = 0;
-        height = 0;
-    }
+       public Dimension() {
+               width = 0;
+               height = 0;
+       }
 
-    public Dimension(final Dimension origial) {
-        width = origial.width;
-        height = origial.height;
-    }
+       public Dimension(final Dimension origial) {
+               width = origial.width;
+               height = origial.height;
+       }
 
-    public Dimension(final int width, final int height) {
-        this.width = width;
-        this.height = height;
-    }
+       public Dimension(final int width, final int height) {
+               this.width = width;
+               this.height = height;
+       }
 
-    @Override
-    public int compareTo(final Dimension anotherDimension) {
-        if (width < anotherDimension.width)
-            return -1;
-        if (width > anotherDimension.width)
-            return 1;
+       @Override
+       public int compareTo(final Dimension anotherDimension) {
+               if (width < anotherDimension.width)
+                       return -1;
+               if (width > anotherDimension.width)
+                       return 1;
 
-        if (height < anotherDimension.height)
-            return -1;
-        if (height > anotherDimension.height)
-            return 1;
+               if (height < anotherDimension.height)
+                       return -1;
+               if (height > anotherDimension.height)
+                       return 1;
 
-        return 0;
-    }
+               return 0;
+       }
 
-    public boolean equals(final Dimension anotherDimension) {
-        if (compareTo(anotherDimension) == 0)
-            return true;
-        return false;
-    }
+       public boolean equals(final Dimension anotherDimension) {
+               if (compareTo(anotherDimension) == 0)
+                       return true;
+               return false;
+       }
 
-    public int getArea() {
-        return width * height;
-    }
+       public int getArea() {
+               return width * height;
+       }
 
-    public java.awt.Dimension getAwtDimension() {
-        return new java.awt.Dimension(width, height);
-    }
+       public java.awt.Dimension getAwtDimension() {
+               return new java.awt.Dimension(width, height);
+       }
 
-    public Dimension getScaled(final double multiplicationFactor) {
-        final Dimension result = new Dimension();
+       public Dimension getScaled(final double multiplicationFactor) {
+               final Dimension result = new Dimension();
 
-        result.width = (int) ((width) * multiplicationFactor);
-        result.height = (int) ((height) * multiplicationFactor);
+               result.width = (int) ((width) * multiplicationFactor);
+               result.height = (int) ((height) * multiplicationFactor);
+
+               return result;
+       }
+
+       @Override
+       public String toString() {
+               return "Dimension [width=" + width + ", height=" + height + "]";
+       }
 
-        return result;
-    }
 }
index 566e944..5c8b105 100644 (file)
@@ -18,7 +18,7 @@ public abstract class AbstractFile implements Serializable {
        /**
         * File length in bytes.
         */
-       private long fileLength;
+       private long fileLength = -1;
 
        private transient boolean metaInfoVerified;