Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Checkm manifest parsing
- Loading branch information
Showing
3 changed files
with
128 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
fcrepo-merritt/src/main/java/org/fcrepo/merritt/checkm/Entry.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package org.fcrepo.merritt.checkm; | ||
|
||
import org.apache.commons.io.IOUtils; | ||
import org.apache.http.HttpResponse; | ||
import org.apache.http.client.HttpClient; | ||
import org.apache.http.client.methods.HttpGet; | ||
import org.apache.http.impl.client.DefaultHttpClient; | ||
import org.apache.http.impl.conn.PoolingClientConnectionManager; | ||
import org.apache.http.util.EntityUtils; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
public class Entry { | ||
final public String fileUrl; | ||
final public String hashAlgorithm; | ||
final public String hashValue; | ||
final public String fileSize; | ||
final public String fileLastModified; | ||
final public String fileName; | ||
|
||
|
||
protected static HttpClient client; | ||
protected static final PoolingClientConnectionManager connectionManager = | ||
new PoolingClientConnectionManager(); | ||
|
||
static { | ||
connectionManager.setMaxTotal(Integer.MAX_VALUE); | ||
connectionManager.setDefaultMaxPerRoute(5); | ||
connectionManager.closeIdleConnections(3, TimeUnit.SECONDS); | ||
client = new DefaultHttpClient(connectionManager); | ||
} | ||
|
||
|
||
public Entry(final String fileUrl, final String hashAlgorithm, final String hashValue, final String fileSize, final String _, final String fileName) { | ||
this.fileUrl = fileUrl; | ||
this.hashAlgorithm = hashAlgorithm; | ||
this.hashValue = hashValue; | ||
this.fileSize = fileSize; | ||
this.fileLastModified = null; | ||
this.fileName = fileName; | ||
} | ||
|
||
public Entry(String[] row) { | ||
this(row[0].trim(), row[1].trim(), row[2].trim(), row[3].trim(), row[4].trim(), row[5].trim()); | ||
} | ||
|
||
public InputStream getSourceInputStream() throws IOException { | ||
final HttpGet manifestRequest = | ||
new HttpGet(fileUrl); | ||
|
||
HttpResponse response = client.execute(manifestRequest); | ||
|
||
return response.getEntity().getContent(); | ||
} | ||
|
||
} |
39 changes: 39 additions & 0 deletions
39
fcrepo-merritt/src/main/java/org/fcrepo/merritt/checkm/Reader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package org.fcrepo.merritt.checkm; | ||
|
||
import org.apache.cxf.helpers.IOUtils; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class Reader { | ||
List<Entry> entries; | ||
|
||
public Reader(InputStream is) throws IOException { | ||
this.entries = parseManifest(IOUtils.readStringFromStream(is)); | ||
} | ||
|
||
private List<Entry> parseManifest(String manifest_body) { | ||
ArrayList<Entry> m = new ArrayList<Entry>(); | ||
|
||
String[] rows = manifest_body.split("\n"); | ||
|
||
for(String row : rows) { | ||
if(row.startsWith("#")) { | ||
continue; | ||
} | ||
|
||
m.add(new Entry(row.split("|"))); | ||
} | ||
|
||
|
||
return m; | ||
} | ||
|
||
public List<Entry> getEntries() { | ||
return entries; | ||
} | ||
|
||
|
||
} |