From 6651446d2b39a29ac6e208e2dc094babdd8b44d0 Mon Sep 17 00:00:00 2001 From: jihoonl Date: Fri, 16 Oct 2009 23:30:49 +0000 Subject: [PATCH] forgot these files --- .../src/Benchmarks/Spider/dsm/LocalQuery.java | 76 +++++++++++++++++++ .../src/Benchmarks/Spider/dsm/QueryQueue.java | 34 +++++++++ 2 files changed, 110 insertions(+) create mode 100644 Robust/src/Benchmarks/Spider/dsm/LocalQuery.java create mode 100644 Robust/src/Benchmarks/Spider/dsm/QueryQueue.java diff --git a/Robust/src/Benchmarks/Spider/dsm/LocalQuery.java b/Robust/src/Benchmarks/Spider/dsm/LocalQuery.java new file mode 100644 index 00000000..2315b1e5 --- /dev/null +++ b/Robust/src/Benchmarks/Spider/dsm/LocalQuery.java @@ -0,0 +1,76 @@ +public class LocalQuery { + String hostname; + String path; + StringBuffer response; + int depth; + + public LocalQuery(String hostname, String path, int depth) { + this.hostname = new String(hostname); + this.path = new String(path); + response = new StringBuffer(); + this.depth = depth; + } + + public int getDepth() { + return depth; + } + + public String getHostName() { + return hostname; + } + + public String getPath() { + return path; + } + + public void outputFile() { + StringBuffer sb = new StringBuffer(hostname); + sb.append(path); + FileOutputStream fos = new FileOutputStream(sb.toString().replace('/','#')); + fos.write(response.toString().getBytes()); + fos.close(); + } + + public String makewebcanonical(String page) { + StringBuffer b = new StringBuffer(getHostName(page)); + b.append("/"); + b.append(getPathName(page)); + return b.toString(); + } + + public String getHostName(String page) { + String http = new String("http://"); + if (page.indexOf(http) == -1) { + return getHostName(); + } else { + int beginindex = page.indexOf(http) + http.length(); + int endindex = page.indexOf('/',beginindex+1); + if ((beginindex == -1)) { + System.printString("ERROR"); + } + if (endindex == -1) + endindex=page.length(); + return page.subString(beginindex, endindex); + } + } + + public String getPathName(String page) { + String http = new String("http://"); + if (page.indexOf(http) == -1) { + String path = getPath(); + int lastindex = path.lastindexOf('/'); + if (lastindex == -1) + return page; + + StringBuffer sb = new StringBuffer(path.subString(0,lastindex+1)); + sb.append(page); + return sb.toString(); + } else { + int beginindex = page.indexOf(http) + http.length(); + int nextindex = page.indexOf('/',beginindex+1); + if ((beginindex==-1) || (nextindex==-1)) + return new String("index.html"); + return page.subString(nextindex+1, page.length()); + } + } +} diff --git a/Robust/src/Benchmarks/Spider/dsm/QueryQueue.java b/Robust/src/Benchmarks/Spider/dsm/QueryQueue.java new file mode 100644 index 00000000..915bb4b9 --- /dev/null +++ b/Robust/src/Benchmarks/Spider/dsm/QueryQueue.java @@ -0,0 +1,34 @@ +public class QueryQueue { + HashSet queries; + int size; + + public QueryQueue() { + queries = new HashSet(); + size = 0; + } + + public LocalQuery pop() { + if (queries.isEmpty()) + return null; + LocalQuery q = (LocalQuery) queries.iterator().next(); + queries.remove(q); + size--; + return q; + } + + public void push(LocalQuery x) { + queries.add(x); + size++; + } + + public int size() { + return size; + } + + public boolean isEmpty() { + if (size == 0) + return true; + else + return false; + } +} -- 2.34.1