use of gov.loc.repository.bagit.reader.BagReader in project bagit-java by LibraryOfCongress.
the class ReaderWriterVerifierIntegrationTest method testReaderWriterVersion95.
@Test
public void testReaderWriterVersion95() throws Exception {
BagReader reader = new BagReader();
Path rootDir = Paths.get(this.getClass().getClassLoader().getResource("bags/v0_95/bag").toURI());
Bag bag = reader.read(rootDir);
Path outputDir = Paths.get(folder.newFolder().toURI());
BagWriter.write(bag, outputDir);
testBagsEqual(rootDir, outputDir);
try (BagVerifier verifier = new BagVerifier()) {
verifier.isValid(reader.read(outputDir), true);
}
}
use of gov.loc.repository.bagit.reader.BagReader in project bagit-java by LibraryOfCongress.
the class BagLinterTest method testCheckAgainstProfile.
@Test
public void testCheckAgainstProfile() throws Exception {
Path profileJson = new File("src/test/resources/bagitProfiles/exampleProfile.json").toPath();
Path bagRootPath = new File("src/test/resources/bagitProfileTestBags/profileConformantBag").toPath();
BagReader reader = new BagReader();
Bag bag = reader.read(bagRootPath);
try (InputStream inputStream = Files.newInputStream(profileJson, StandardOpenOption.READ)) {
BagLinter.checkAgainstProfile(inputStream, bag);
}
}
use of gov.loc.repository.bagit.reader.BagReader in project epadd by ePADD.
the class Archive method readArchiveBag.
/* //maps locId (int) to docId (edu.stanford.muse.index.Document) using indexer storage structures
public Integer getLDocIdForContentDocId(String docId){
return indexer.contentDocIds.entrySet().stream().filter(e->docId.equals(e.getValue())).findAny().map(Map.Entry::getKey).orElse(0);
}
public String getDocIdForContentLDocId(Integer ldocId){
return indexer.contentDocIds.get(ldocId);
}*/
/*public Integer getLDocIdForBlobDocId(String docId){
return indexer.blobDocIds.entrySet().stream().filter(e->docId.equals(e.getValue())).findAny().map(Map.Entry::getKey).orElse(0);
}*/
/*public String getDocIdForBlobLDocId(Integer ldocId) {
return indexer.blobDocIds.get(ldocId);
}
*/
// input is a bag present in userdir
public static Bag readArchiveBag(String userdir) {
Path rootDir = Paths.get(userdir);
BagReader reader = new BagReader();
String errorMessage = "";
Bag bag = null;
try {
bag = reader.read(rootDir);
} catch (IOException e) {
e.printStackTrace();
errorMessage = "Could not read directory " + rootDir;
} catch (UnparsableVersionException e) {
e.printStackTrace();
errorMessage = "Bag is of unparsable version: " + e.getMessage();
} catch (MaliciousPathException e) {
e.printStackTrace();
errorMessage = "Malicious path found for the bag: " + e.getMessage();
} catch (UnsupportedAlgorithmException e) {
e.printStackTrace();
errorMessage = "The bag has checksums for unsupported algorithms: " + e.getMessage();
} catch (InvalidBagitFileFormatException e) {
e.printStackTrace();
errorMessage = "The file format of the bag is invalid :" + e.getMessage();
}
// If error in verification return null;
if (!Util.nullOrEmpty(errorMessage))
return null;
else
return bag;
}
use of gov.loc.repository.bagit.reader.BagReader in project bagit-java by LibraryOfCongress.
the class BagVerifierTest method testErrorWhenUnspportedAlgorithmException.
@Test(expected = UnsupportedAlgorithmException.class)
public void testErrorWhenUnspportedAlgorithmException() throws Exception {
Path sha3BagDir = Paths.get(getClass().getClassLoader().getResource("sha3Bag").toURI());
BagReader extendedReader = new BagReader();
Bag bag = extendedReader.read(sha3BagDir);
sut.isValid(bag, true);
}
use of gov.loc.repository.bagit.reader.BagReader in project bagit-java by LibraryOfCongress.
the class BagVerifierTest method testAddSHA3SupportViaExtension.
@Test
public void testAddSHA3SupportViaExtension() throws Exception {
Path sha3BagDir = Paths.get(new File("src/test/resources/sha3Bag").toURI());
MySupportedNameToAlgorithmMapping mapping = new MySupportedNameToAlgorithmMapping();
BagReader extendedReader = new BagReader(mapping);
Bag bag = extendedReader.read(sha3BagDir);
try (BagVerifier extendedSut = new BagVerifier(mapping)) {
extendedSut.isValid(bag, true);
}
}
Aggregations