From: Svjatoslav Agejenko Date: Mon, 12 Jun 2017 19:46:34 +0000 (+0300) Subject: Code refactoring X-Git-Tag: meviz-1.2~39 X-Git-Url: http://www2.svjatoslav.eu/gitweb/?a=commitdiff_plain;h=10d7d28a798d1e54e2dfd24fef8478756e07a891;p=meviz.git Code refactoring --- diff --git a/src/main/java/eu/svjatoslav/meviz/htmlindexer/WebIndexer.java b/src/main/java/eu/svjatoslav/meviz/htmlindexer/WebIndexer.java index beaea50..c649d98 100644 --- a/src/main/java/eu/svjatoslav/meviz/htmlindexer/WebIndexer.java +++ b/src/main/java/eu/svjatoslav/meviz/htmlindexer/WebIndexer.java @@ -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