58 |
|
|
59 |
public Block get(BlockId id) throws IOException { |
public Block get(BlockId id) throws IOException { |
60 |
try { |
try { |
61 |
return cache.get(id); |
p("Trying to find the block from the local pool..."); |
62 |
p("Block found from the local pool..." |
return cache.get(id); |
63 |
} catch(FileNotFoundException _) { |
} catch(FileNotFoundException _) { |
64 |
p("Block did't found from the local pool..." |
p("Block didn't found from the local pool..."); |
65 |
Collector c = map.get(id.toString()); |
Collector c = map.get(id.toString()); |
66 |
for(Iterator i=c.blockingIterator(); i.hasNext();) { |
for(Iterator i=c.blockingIterator(); i.hasNext();) { |
67 |
String url = (String)i.next(); |
String url = (String)i.next(); |
68 |
try { |
try { |
69 |
|
p("Trying to connect to: " + url); |
70 |
URLConnection conn = new URL(url).openConnection(); |
URLConnection conn = new URL(url).openConnection(); |
71 |
String contentType = conn.getContentType(); |
String contentType = conn.getContentType(); |
|
p("Trying to connect to: " + url |
|
72 |
if(contentType == null) continue; |
if(contentType == null) continue; |
73 |
BlockOutputStream bos = |
BlockOutputStream bos = |
74 |
cache.getBlockOutputStream(conn.getContentType()); |
cache.getBlockOutputStream(conn.getContentType()); |
75 |
CopyUtil.copy(conn.getInputStream(), bos); |
CopyUtil.copy(conn.getInputStream(), bos); |
76 |
if(bos.getBlockId().equals(id)) |
if(bos.getBlockId().equals(id)) { |
77 |
|
p("Block found @ " + url); |
78 |
return bos.getBlock(); |
return bos.getBlock(); |
79 |
else |
} else { |
80 |
p("Block ids didn't match: "+id+" / "+ |
p("Block ids didn't match: "+id+" / "+ |
81 |
bos.getBlockId()+" (from "+url+")."); |
bos.getBlockId()+" (from "+url+")."); |
82 |
|
} |
83 |
} catch(IOException e) { |
} catch(IOException e) { |
84 |
// next iteration |
// next iteration |
85 |
} |
} |