68 |
try { |
try { |
69 |
p("Trying to connect to: " + url); |
p("Trying to connect to: " + url); |
70 |
URLConnection conn = new URL(url).openConnection(); |
URLConnection conn = new URL(url).openConnection(); |
71 |
|
conn.connect(); |
72 |
|
for(int x=0;;x++) { |
73 |
|
Object o = conn.getHeaderField(x); |
74 |
|
if(o == null) break; |
75 |
|
p("HF: "+o); |
76 |
|
} |
77 |
|
p("conn"); |
78 |
String contentType = conn.getContentType(); |
String contentType = conn.getContentType(); |
79 |
|
p("gettype"); |
80 |
if(contentType == null) continue; |
if(contentType == null) continue; |
81 |
|
p("hastype"); |
82 |
|
|
83 |
// The content type may contain spaces like this: |
// The content type may contain spaces like this: |
84 |
// "text/html; charset=utf-8" |
// "text/html; charset=utf-8" |
89 |
contentType = contentType.substring(0, sp) + |
contentType = contentType.substring(0, sp) + |
90 |
contentType.substring(sp+1); |
contentType.substring(sp+1); |
91 |
|
|
92 |
|
p("sp removed"); |
93 |
BlockOutputStream bos = |
BlockOutputStream bos = |
94 |
cache.getBlockOutputStream(contentType); |
cache.getBlockOutputStream(contentType); |
95 |
|
p("bos"); |
96 |
CopyUtil.copy(conn.getInputStream(), bos); |
CopyUtil.copy(conn.getInputStream(), bos); |
97 |
|
p("copied"); |
98 |
if(bos.getBlockId().equals(id)) { |
if(bos.getBlockId().equals(id)) { |
99 |
p("Block found @ " + url); |
p("Block found @ " + url); |
100 |
return bos.getBlock(); |
return bos.getBlock(); |