Skip to content
This repository has been archived by the owner on Dec 12, 2021. It is now read-only.

Commit

Permalink
LinkResolver: Formatting fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
javajawa committed Dec 24, 2013
1 parent 48e6b0a commit 5841a7b
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/uk/co/harcourtprogramming/docitten/LinkResolver.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,10 @@ public void uncaughtException(Thread t, Throwable e)
private static String humanReadableByteCount(long bytes)
{
if (bytes < 1024)
{
return bytes + " B";
}

int exp = (int)(Math.log(bytes) / UNIT_SIZE);
return String.format("%.1f %siB", bytes / Math.pow(1024, exp), UNIT_PREFIX.charAt(exp - 1));
}
Expand Down Expand Up @@ -104,9 +107,13 @@ public LinkResolver(String baseURI, RelayCat mess, String target)
{
super(THREAD_GROUP, "LinkResolver [" + baseURI + ']');
if (!PROTOCOL.matcher(baseURI).matches())
{
this.baseURI = URI.create("http://" + baseURI);
}
else
{
this.baseURI = URI.create(baseURI);
}

this.mess = mess;
this.target = target;
Expand Down Expand Up @@ -170,7 +177,9 @@ public void run()
case HttpURLConnection.HTTP_MULT_CHOICE:
case HttpURLConnection.HTTP_SEE_OTHER:
if (conn.getHeaderField("Location") == null)
{
return;
}

curr = resolveLocation(curr, conn.getHeaderField("Location"));
break;
Expand All @@ -182,10 +191,14 @@ public void run()
conn.disconnect();

if (interrupted())
{
return;
}

if (resolved || (++hops == MAX_HOPS))
{
break;
}
}

if (hops == MAX_HOPS)
Expand Down Expand Up @@ -244,7 +257,9 @@ private void fetchData(URL url)

String mime = conn.getContentType();
if (mime == null)
{
mime = "";
}

mime = mime.split(";")[0];

Expand Down Expand Up @@ -294,7 +309,9 @@ private String getTitle(InputStream stream) throws IOException
{
line = pageData.readLine();
if (line == null)
{
break;
}

if (line.contains("<title>"))
{
Expand Down Expand Up @@ -322,10 +339,14 @@ private String getTitle(InputStream stream) throws IOException

if (line.contains("</head>") || line.contains("<body>")
|| line.contains("</HEAD>") || line.contains("<BODY>"))
{
break;
}

if (reading)
{
title += line;
}
}

pageData.close();
Expand Down

0 comments on commit 5841a7b

Please sign in to comment.