Permalink
Browse files

changed the way it stores processed urls

  • Loading branch information...
jaec committed Jul 4, 2012
1 parent 15dd031 commit bd785db8a8318cd65a46fea17cfd2d3599b468a1
Showing with 23 additions and 23 deletions.
  1. +23 −23 src/com/desdegdl/ObtenerActasPREP.java
@@ -23,7 +23,8 @@
public static final String STOPCRAWLERFILENAME = "/tmp/stopactas";
public static final String WGETPATH = "/usr/local/bin/wget";
private HashMap<String, String> sections = new HashMap<String, String>();
- private List<String> processedURLs = new ArrayList<String>();
+ //private List<String> processedURLs = new ArrayList<String>();
+ private FileWriter pURLsWriter = null;
public ObtenerActasPREP() {
InputStream in = null;
@@ -120,6 +121,14 @@ public ObtenerActasPREP() {
}
}
}
+ } else {
+ try {
+ purlsFile.createNewFile();
+ pURLsWriter = new FileWriter(PURLSFILENAME, true);
+ } catch (IOException exc) {
+ exc.printStackTrace(System.err);
+ System.exit(-1);
+ }
}
}
@@ -134,29 +143,19 @@ private void wget(String url) {
}
}
- private void saveProgress() {
- FileWriter writer = null;
-
+ private void shutdown() {
try {
- File purlsFile = new File(PURLSFILENAME);
-
- if (!purlsFile.exists()) {
- purlsFile.createNewFile();
- }
+ this.pURLsWriter.close();
+ } catch (IOException ex) {
+ Logger.getLogger(ObtenerActasPREP.class.getName()).log(Level.WARNING, ex.getMessage(), ex);
+ }
+ }
- writer = new FileWriter(PURLSFILENAME, true);
- for (String str : this.processedURLs) {
- writer.write(str + System.getProperty("line.separator"));
- }
+ private void addprocessedURL(String url) {
+ try {
+ this.pURLsWriter.write(url + System.clearProperty("line.separator"));
} catch (IOException ex) {
- Logger.getLogger(ObtenerActasPREP.class.getName()).log(Level.SEVERE, ex.getMessage(), ex);
- } finally {
- if (writer != null) {
- try {
- writer.close();
- } catch (IOException ex) {
- }
- }
+ Logger.getLogger(ObtenerActasPREP.class.getName()).log(Level.WARNING, ex.getMessage(), ex);
}
}
@@ -181,7 +180,7 @@ public void getAllActas() {
if (file.exists()) {
file.delete();
f.cancel(true);
- saveProgress();
+ shutdown();
break;
}
@@ -194,7 +193,8 @@ public void getAllActas() {
wget(url);
}
- this.processedURLs.add(res.getFromURL());
+ //this.processedURLs.add(res.getFromURL());
+ addprocessedURL(res.getFromURL());
} catch (InterruptedException ex) {
Logger.getLogger(ObtenerActasPREP.class.getName()).log(Level.SEVERE, ex.getMessage(), ex);
} catch (ExecutionException ex) {

0 comments on commit bd785db

Please sign in to comment.