1 25 package org.archive.crawler.datamodel; 26 27 import java.io.File ; 28 import java.io.IOException ; 29 import java.io.ObjectInputStream ; 30 import java.io.Serializable ; 31 32 import org.archive.crawler.util.CheckpointUtils; 33 import org.archive.util.FileUtils; 34 35 41 public class Checkpoint implements Serializable { 42 45 private static final long serialVersionUID = 5121498771788002844L; 46 47 50 private static final String INVALID = "INVALID"; 51 52 55 public static final String VALIDITY_STAMP_FILENAME = "valid"; 56 57 58 private transient String timestamp; 59 private File directory; 60 61 64 protected Checkpoint() { 65 super(); 66 } 67 68 74 public Checkpoint(File checkpointDir) { 75 this.directory = checkpointDir; 76 readValid(); 77 } 78 79 private void readObject(ObjectInputStream s) 80 throws IOException , ClassNotFoundException { 81 s.defaultReadObject(); 82 readValid(); 83 } 84 85 protected void readValid() { 86 File validityStamp = new File (this.directory, 87 VALIDITY_STAMP_FILENAME); 88 if (validityStamp.exists() == false) { 89 this.timestamp = INVALID; 90 } else { 91 try { 92 this.timestamp = FileUtils.readFileAsString(validityStamp). 93 trim(); 94 } catch (IOException e) { 95 e.printStackTrace(); 96 this.timestamp = INVALID; 97 } 98 } 99 } 100 101 105 public boolean isValid() { 106 return timestamp != INVALID; 107 } 108 109 112 public String getName() { 113 return this.directory.getName(); 114 } 115 116 120 public String getDisplayName() { 121 return getName() + " [" + getTimestamp() + "]"; 122 } 123 124 127 public String getTimestamp() { 128 return timestamp; 129 } 130 131 134 public File getDirectory() { 135 return this.directory; 136 } 137 138 142 public boolean hasBdbjeLogs() { 143 boolean decision = false; 144 File bdbjeDir = CheckpointUtils.getBdbSubDirectory(this.directory); 145 if (bdbjeDir.exists()) { 146 String [] files = 147 bdbjeDir.list(CheckpointUtils.getJeLogsFilter()); 148 decision = (files != null && files.length > 0); 149 } 150 return decision; 151 } 152 } | Popular Tags |