Update of /var/cvs/speeltuin/andre/mmget/src/org/mmbase/mmget
In directory james.mmbase.org:/tmp/cvs-serv7225/src/org/mmbase/mmget
Modified Files:
CSSReader.java HTMLReader.java ResourceReWriter.java
ResourceWriter.java UrlReaders.java
Log Message:
HttpURLConnection
See also:
http://cvs.mmbase.org/viewcvs/speeltuin/andre/mmget/src/org/mmbase/mmget
Index: CSSReader.java
===================================================================
RCS file: /var/cvs/speeltuin/andre/mmget/src/org/mmbase/mmget/CSSReader.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -b -r1.4 -r1.5
--- CSSReader.java 23 Mar 2009 22:30:22 -0000 1.4
+++ CSSReader.java 24 Mar 2009 13:32:24 -0000 1.5
@@ -19,12 +19,12 @@
* @import url("mystyle.css");
*
* @author André van Toly
- * @version $Id: CSSReader.java,v 1.4 2009/03/23 22:30:22 andre Exp $
+ * @version $Id: CSSReader.java,v 1.5 2009/03/24 13:32:24 andre Exp $
*/
public final class CSSReader extends UrlReader {
private static final Logger log =
Logging.getLoggerInstance(CSSReader.class);
- private URLConnection uc = null;
+ private HttpURLConnection huc = null;
private BufferedReader inrdr = null;
/*
@@ -37,17 +37,17 @@
public static final String IMPORT_PATTERN = "@import\\s+[\"\'](.*)[\"\']";
private static final Pattern importPattern =
Pattern.compile(IMPORT_PATTERN);
- public CSSReader(URLConnection uc) throws IOException {
- this.uc = uc;
- inrdr = new BufferedReader(new InputStreamReader(uc.getInputStream()));
+ public CSSReader(HttpURLConnection huc) throws IOException {
+ this.huc = huc;
+ inrdr = new BufferedReader(new
InputStreamReader(huc.getInputStream()));
}
protected int getContentType() {
- return MMGet.contentType(uc);
+ return MMGet.contentType(huc);
}
protected URL getUrl() {
- return uc.getURL();
+ return huc.getURL();
}
/**
@@ -87,8 +87,13 @@
}
public void close() throws IOException {
- //log.debug("closing...");
+ log.debug("closing...");
inrdr.close();
+
+ if (huc != null) {
+ log.debug("disconnecting... " + getUrl().toString());
+ huc.disconnect();
+ }
}
}
Index: HTMLReader.java
===================================================================
RCS file: /var/cvs/speeltuin/andre/mmget/src/org/mmbase/mmget/HTMLReader.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -b -r1.5 -r1.6
--- HTMLReader.java 23 Mar 2009 22:30:22 -0000 1.5
+++ HTMLReader.java 24 Mar 2009 13:32:24 -0000 1.6
@@ -15,12 +15,12 @@
* Reads a web resource an returns its tags that may contain links to other
resources.
*
* @author André van Toly
- * @version $Id: HTMLReader.java,v 1.5 2009/03/23 22:30:22 andre Exp $
+ * @version $Id: HTMLReader.java,v 1.6 2009/03/24 13:32:24 andre Exp $
*/
public final class HTMLReader extends UrlReader {
private static final Logger log =
Logging.getLoggerInstance(HTMLReader.class);
- private URLConnection uc = null;
+ private HttpURLConnection huc = null;
private BufferedReader inrdr = null;
/**
@@ -40,9 +40,9 @@
"<script", "<SCRIPT",
};
- public HTMLReader(URLConnection uc) throws IOException {
- this.uc = uc;
- inrdr = new BufferedReader(new InputStreamReader(uc.getInputStream()));
+ public HTMLReader(HttpURLConnection huc) throws IOException {
+ this.huc = huc;
+ inrdr = new BufferedReader(new
InputStreamReader(huc.getInputStream()));
}
/**
@@ -65,11 +65,11 @@
}
protected int getContentType() {
- return MMGet.contentType(uc);
+ return MMGet.contentType(huc);
}
protected URL getUrl() {
- return uc.getURL();
+ return huc.getURL();
}
/**
@@ -141,8 +141,13 @@
}
public void close() throws IOException {
- //log.debug("closing...");
+ log.debug("closing...");
inrdr.close();
+
+ if (huc != null) {
+ log.debug("disconnecting... " + getUrl().toString());
+ huc.disconnect();
+ }
}
}
Index: ResourceReWriter.java
===================================================================
RCS file:
/var/cvs/speeltuin/andre/mmget/src/org/mmbase/mmget/ResourceReWriter.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -b -r1.6 -r1.7
--- ResourceReWriter.java 23 Mar 2009 23:04:58 -0000 1.6
+++ ResourceReWriter.java 24 Mar 2009 13:32:24 -0000 1.7
@@ -12,13 +12,13 @@
* Typically to be used for html and css files.
*
* @author André van Toly
- * @version $Id: ResourceReWriter.java,v 1.6 2009/03/23 23:04:58 andre Exp $
+ * @version $Id: ResourceReWriter.java,v 1.7 2009/03/24 13:32:24 andre Exp $
*/
public final class ResourceReWriter extends ResourceWriter {
private static final Logger log =
Logging.getLoggerInstance(ResourceReWriter.class);
private URL url;
- private HttpURLConnection uc = null;
+ private HttpURLConnection huc = null;
private static String filename;
private static int contenttype;
@@ -29,10 +29,10 @@
public ResourceReWriter(URL url) throws IOException {
super(url);
//log.debug("Trying to download... " + url.toString() + " to " +
filename);
- this.uc = super.uc;
+ this.huc = super.huc;
this.url = getUrl();
- this.contenttype = MMGet.contentType(uc);
+ this.contenttype = MMGet.contentType(huc);
this.filename = makeFilename(url);
}
@@ -48,8 +48,6 @@
/**
* Saves and rewrites the links in the resource to (relative?) ones that
work
* on the filesystem. Only for HTML or CSS (text) files of course.
- * @param url
- * @param uc the already elsewhere created URLConnection for efficiency
*/
private void rewrite() throws IOException {
if (log.isDebugEnabled()) log.debug("REwriting: " + url + " -> file: "
+ filename);
Index: ResourceWriter.java
===================================================================
RCS file:
/var/cvs/speeltuin/andre/mmget/src/org/mmbase/mmget/ResourceWriter.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -b -r1.5 -r1.6
--- ResourceWriter.java 23 Mar 2009 22:30:22 -0000 1.5
+++ ResourceWriter.java 24 Mar 2009 13:32:24 -0000 1.6
@@ -13,13 +13,13 @@
* Writes a resource found on an url to disk.
*
* @author André van Toly
- * @version $Id: ResourceWriter.java,v 1.5 2009/03/23 22:30:22 andre Exp $
+ * @version $Id: ResourceWriter.java,v 1.6 2009/03/24 13:32:24 andre Exp $
*/
public class ResourceWriter {
private static final Logger log =
Logging.getLoggerInstance(ResourceWriter.class);
private URL url;
- protected HttpURLConnection uc = null;
+ protected HttpURLConnection huc = null;
protected static String filename;
protected static int contenttype;
@@ -29,22 +29,22 @@
*/
public ResourceWriter(URL u) throws IOException {
try {
- uc = (HttpURLConnection)getURLConnection(u);
+ huc = getURLConnection(u);
} catch (IOException e) {
log.warn(e);
}
- if (uc == null) {
+ if (huc == null) {
MMGet.ignoredURLs.add(u);
throw new MalformedURLException("Not found/correct? : " + u);
}
this.url = getUrl();
- this.contenttype = MMGet.contentType(uc);
+ this.contenttype = MMGet.contentType(huc);
this.filename = makeFilename(url);
}
protected URL getUrl() {
- return uc.getURL();
+ return huc.getURL();
}
protected String getFilename() {
@@ -56,9 +56,9 @@
}
protected void disconnect() {
- if (uc != null) {
+ if (huc != null) {
//log.debug("disconnecting... " + url.toString());
- uc.disconnect();
+ huc.disconnect();
}
}
@@ -70,11 +70,11 @@
if (f.exists()) {
//log.warn("File '" + f.toString() + "' already exists, deleting
it and saving again.");
- if (f.lastModified() <= uc.getLastModified()) {
+ if (f.lastModified() <= huc.getLastModified()) {
f.delete();
} else {
- log.info("Not modified: " + f.toString() + ", f:" +
f.lastModified() + " uc:" + uc.getLastModified());
+ log.info("Not modified: " + f.toString() + ", f:" +
f.lastModified() + " huc:" + huc.getLastModified());
// MMGet.savedURLs.put(url, filename);
MMGet.addSavedURL(url, filename);
@@ -84,7 +84,7 @@
}
- BufferedInputStream in = new
BufferedInputStream(uc.getInputStream());
+ BufferedInputStream in = new
BufferedInputStream(huc.getInputStream());
BufferedOutputStream out = new BufferedOutputStream(new
FileOutputStream(f));
byte[] buf = new byte[1024];
int b = 0;
@@ -107,8 +107,9 @@
* @param url
* @return a connection or null in case of a bad response (f.e. not a 200)
*/
- private static URLConnection getURLConnection(URL url) throws
SocketException, IOException {
+ private static HttpURLConnection getURLConnection(URL url) throws
SocketException, IOException {
URLConnection uc = url.openConnection();
+ //HttpURLConnection huc
if (url.getProtocol().equals("http") ||
url.getProtocol().equals("https")) {
HttpURLConnection huc = (HttpURLConnection)uc;
int res = huc.getResponseCode();
Index: UrlReaders.java
===================================================================
RCS file: /var/cvs/speeltuin/andre/mmget/src/org/mmbase/mmget/UrlReaders.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -b -r1.4 -r1.5
--- UrlReaders.java 11 Mar 2009 08:34:20 -0000 1.4
+++ UrlReaders.java 24 Mar 2009 13:32:24 -0000 1.5
@@ -16,7 +16,7 @@
* URLConnection.
*
* @author André van Toly
- * @version $Id: UrlReaders.java,v 1.4 2009/03/11 08:34:20 andre Exp $
+ * @version $Id: UrlReaders.java,v 1.5 2009/03/24 13:32:24 andre Exp $
*/
public class UrlReaders {
private static final Logger log =
Logging.getLoggerInstance(UrlReaders.class);
@@ -27,13 +27,13 @@
public static UrlReader getUrlReader(URL url) throws IOException {
- URLConnection uc = url.openConnection();
- contenttype = MMGet.contentType(uc);
+ HttpURLConnection huc = (HttpURLConnection)url.openConnection();
+ contenttype = MMGet.contentType(huc);
if (contenttype == MMGet.CONTENTTYPE_CSS) {
- reader = new CSSReader(uc);
+ reader = new CSSReader(huc);
} else {
- reader = new HTMLReader(uc);
+ reader = new HTMLReader(huc);
}
return reader;
}
_______________________________________________
Cvs mailing list
[email protected]
http://lists.mmbase.org/mailman/listinfo/cvs