update to master
[fanfix.git] / library / WebLibrary.java
index 42f7ea5ccadd4eb40d6b86cfd1f6842abab0db50..7381ae368661023aa3ac2a23c643d6f4461ac658 100644 (file)
@@ -126,6 +126,26 @@ public class WebLibrary extends BasicLibrary {
                return new Version();
        }
 
+       /**
+        * Stop the server.
+        * 
+        * @throws IOException
+        *             in case of I/O errors
+        */
+       public void stop() throws IOException {
+               try {
+                       post(WebLibraryUrls.EXIT_URL, null).close();
+               } catch (Exception e) {
+                       try {
+                               Thread.sleep(200);
+                       } catch (InterruptedException e1) {
+                       }
+                       if (getStatus() != Status.UNAVAILABLE) {
+                               throw new IOException("Cannot exit the library", e);
+                       }
+               }
+       }
+
        @Override
        public Status getStatus() {
                try {
@@ -153,11 +173,12 @@ public class WebLibrary extends BasicLibrary {
                InputStream in = post(WebLibraryUrls.getStoryUrlCover(luid));
                try {
                        Image img = new Image(in);
-                       if (img.getSize() > 0) {
-                               return img;
+                       if (img.getSize() == 0) {
+                               img.close();
+                               img = null;
                        }
 
-                       return null;
+                       return img;
                } finally {
                        in.close();
                }
@@ -168,11 +189,12 @@ public class WebLibrary extends BasicLibrary {
                InputStream in = post(WebLibraryUrls.getCoverUrlSource(source));
                try {
                        Image img = new Image(in);
-                       if (img.getSize() > 0) {
-                               return img;
+                       if (img.getSize() == 0) {
+                               img.close();
+                               img = null;
                        }
 
-                       return null;
+                       return img;
                } finally {
                        in.close();
                }
@@ -183,11 +205,12 @@ public class WebLibrary extends BasicLibrary {
                InputStream in = post(WebLibraryUrls.getCoverUrlAuthor(author));
                try {
                        Image img = new Image(in);
-                       if (img.getSize() > 0) {
-                               return img;
+                       if (img.getSize() == 0) {
+                               img.close();
+                               img = null;
                        }
 
-                       return null;
+                       return img;
                } finally {
                        in.close();
                }