1 25 package org.archive.io.arc; 26 27 import java.io.File ; 28 import java.io.IOException ; 29 import java.util.Iterator ; 30 import java.util.Map ; 31 import java.util.Set ; 32 33 import org.archive.io.ArchiveRecordHeader; 34 35 36 41 public class ARCRecordMetaData implements ArchiveRecordHeader, ARCConstants { 42 50 protected Map headerFields = null; 51 52 57 private String digest = null; 58 59 64 private String statusCode = null; 65 66 70 private String arc = null; 71 72 private int contentBegin = 0; 73 74 77 protected ARCRecordMetaData() { 78 super(); 79 } 80 81 89 public ARCRecordMetaData(final String arc, Map headerFields) 90 throws IOException { 91 for (Iterator i = REQUIRED_VERSION_1_HEADER_FIELDS.iterator(); 93 i.hasNext(); ) { 94 testRequiredField(headerFields, (String )i.next()); 95 } 96 this.headerFields = headerFields; 97 this.arc = arc; 98 } 99 100 108 protected void testRequiredField(Map fields, String requiredField) 109 throws IOException { 110 if (!fields.containsKey(requiredField)) { 111 throw new IOException ("Required field " + requiredField + 112 " not in meta data."); 113 } 114 } 115 116 126 public String getDate() { 127 return (String ) this.headerFields.get(DATE_FIELD_KEY); 128 } 129 130 133 public long getLength() { 134 return Long.parseLong((String )this.headerFields. 135 get(LENGTH_FIELD_KEY)); 136 } 137 138 141 public String getUrl() { 142 return (String )this.headerFields.get(URL_FIELD_KEY); 143 } 144 145 148 public String getIp() 149 { 150 return (String )this.headerFields.get(IP_HEADER_FIELD_KEY); 151 } 152 153 157 public String getMimetype() { 158 return (String )this.headerFields.get(MIMETYPE_FIELD_KEY); 159 } 160 161 164 public String getVersion() { 165 return (String )this.headerFields.get(VERSION_FIELD_KEY); 166 } 167 168 171 public long getOffset() { 172 return ((Long )this.headerFields.get(ABSOLUTE_OFFSET_KEY)).longValue(); 173 } 174 175 179 public Object getHeaderValue(String key) { 180 return this.headerFields.get(key); 181 } 182 183 186 public Set getHeaderFieldKeys() 187 { 188 return this.headerFields.keySet(); 189 } 190 191 194 public Map getHeaderFields() { 195 return this.headerFields; 196 } 197 198 201 public String getArc() { 202 return this.arc; 203 } 204 205 211 public File getArcFile() { 212 return new File (this.arc); 213 } 214 215 218 public String getDigest() { 219 return this.digest; 220 } 221 222 225 public void setDigest(String d) { 226 this.digest = d; 227 } 228 229 232 public String getStatusCode() { 233 return this.statusCode; 234 } 235 236 239 public void setStatusCode(String statusCode) { 240 this.statusCode = statusCode; 241 } 242 243 public String toString() { 244 return ((this.arc != null)? this.arc: "") + 245 ": " + 246 ((this.headerFields != null)? this.headerFields.toString(): ""); 247 } 248 249 public String getReaderIdentifier() { 250 return this.getArc(); 251 } 252 253 public String getRecordIdentifier() { 254 return getDate() + "/" + getUrl(); 255 } 256 257 public int getContentBegin() { 258 return this.contentBegin; 259 } 260 261 void setContentBegin(final int offset) { 262 this.contentBegin = offset; 263 } 264 } | Popular Tags |