Code refactoring
authorSvjatoslav Agejenko <svjatoslav@svjatoslav.eu>
Mon, 12 Jun 2017 19:46:34 +0000 (22:46 +0300)
committerSvjatoslav Agejenko <svjatoslav@svjatoslav.eu>
Mon, 12 Jun 2017 19:46:34 +0000 (22:46 +0300)
src/main/java/eu/svjatoslav/meviz/htmlindexer/WebIndexer.java

index beaea50..c649d98 100644 (file)
@@ -68,29 +68,26 @@ public class WebIndexer extends AbstractIndexer {
     private DirectoryMetadata getMetadataForPath(final String requestPath)
             throws ClassNotFoundException, IOException {
 
-        final String urlString = globalPrefix +
-                Utils.urlEncode(requestPath) +
-                "/.thumbnails/metadata_6.dat";
+        final String urlString = globalPrefix + Utils.urlEncode(requestPath) +"/.thumbnails/metadata_6.dat";
 
-        IOException exception = null;
-
-        for (int i = 0; i < METADATA_LOAD_TRY_COUNT; i++)
+        for (int i = 0; true; i++)
             try {
-
-                final BufferedInputStream in = new BufferedInputStream(new URL(
-                        urlString).openStream());
-
-                final ObjectInputStream oin = new ObjectInputStream(in);
-                final DirectoryMetadata directory = (DirectoryMetadata) oin
-                        .readObject();
-                in.close();
-
-                return directory;
+                return attemptDirectoryMetadataDownload(urlString);
             } catch (final IOException e) {
-                exception = e;
+                if (i > METADATA_LOAD_TRY_COUNT) throw e;
             }
+    }
+
+    private DirectoryMetadata attemptDirectoryMetadataDownload(String urlString) throws IOException, ClassNotFoundException {
+        final BufferedInputStream inputStream = new BufferedInputStream(new URL(
+                urlString).openStream());
+
+        final ObjectInputStream objectInputStream = new ObjectInputStream(inputStream);
+        final DirectoryMetadata directory = (DirectoryMetadata) objectInputStream
+                .readObject();
+        inputStream.close();
 
-        throw exception;
+        return directory;
     }
 
     @Override