@Test public void testRemoteMetadataChecksumFilePathSha1() throws IOException { Path expectedFile = getTestOutputDir().resolve("maven-metadata-remote.xml.sha1"); FileUtils.writeStringToFile( expectedFile, FILE_ENCODING, REMOTE_METADATA_SHA1 + " /home/test/repository/examples/metadata/maven-metadata.xml"); Path testfile = getTestResource( "examples/metadata/maven-metadata-remote.xml" ); ChecksummedFile checksummedFile = new ChecksummedFile( testfile ); try { String s = checksummedFile.parseChecksum( expectedFile, ChecksumAlgorithm.SHA1, "maven-metadata-remote.xml", FILE_ENCODING ); Assert.assertEquals( "Checksum doesn't match", REMOTE_METADATA_SHA1, s ); } catch ( ChecksumValidationException e ) { e.printStackTrace(); Assert.fail( "IOException should not occur." ); } }
public String parseChecksum( Path checksumFile, ChecksumAlgorithm checksumAlgorithm, String fileName, Charset encoding ) throws ChecksumValidationException { ChecksumFileContent fc = parseChecksumFile( checksumFile, checksumAlgorithm, encoding ); if ( fc.isFormatMatch() && !isValidChecksumPattern( fc.getFileReference( ), fileName ) ) { throw new ChecksumValidationException(BAD_CHECKSUM_FILE_REF, "The file reference '" + fc.getFileReference( ) + "' in the checksum file does not match expected file: '" + fileName + "'" ); } else if (!fc.isFormatMatch()) { throw new ChecksumValidationException( BAD_CHECKSUM_FILE, "The checksum file content could not be parsed: "+checksumFile ); } return fc.getChecksum( ); }
ChecksummedFile { public String parseChecksum( Path checksumFile, ChecksumAlgorithm checksumAlgorithm, String fileName, Charset encoding ) throws ChecksumValidationException { ChecksumFileContent fc = parseChecksumFile( checksumFile, checksumAlgorithm, encoding ); if ( fc.isFormatMatch() && !isValidChecksumPattern( fc.getFileReference( ), fileName ) ) { throw new ChecksumValidationException(BAD_CHECKSUM_FILE_REF, "The file reference '" + fc.getFileReference( ) + "' in the checksum file does not match expected file: '" + fileName + "'" ); } else if (!fc.isFormatMatch()) { throw new ChecksumValidationException( BAD_CHECKSUM_FILE, "The checksum file content could not be parsed: "+checksumFile ); } return fc.getChecksum( ); } }
ChecksummedFile { public String parseChecksum( Path checksumFile, ChecksumAlgorithm checksumAlgorithm, String fileName, Charset encoding ) throws ChecksumValidationException { ChecksumFileContent fc = parseChecksumFile( checksumFile, checksumAlgorithm, encoding ); if ( fc.isFormatMatch() && !isValidChecksumPattern( fc.getFileReference( ), fileName ) ) { throw new ChecksumValidationException(BAD_CHECKSUM_FILE_REF, "The file reference '" + fc.getFileReference( ) + "' in the checksum file does not match expected file: '" + fileName + "'" ); } else if (!fc.isFormatMatch()) { throw new ChecksumValidationException( BAD_CHECKSUM_FILE, "The checksum file content could not be parsed: "+checksumFile ); } return fc.getChecksum( ); } ChecksummedFile( final Path referenceFile ); }
ChecksummedFile { public String parseChecksum( Path checksumFile, ChecksumAlgorithm checksumAlgorithm, String fileName, Charset encoding ) throws ChecksumValidationException { ChecksumFileContent fc = parseChecksumFile( checksumFile, checksumAlgorithm, encoding ); if ( fc.isFormatMatch() && !isValidChecksumPattern( fc.getFileReference( ), fileName ) ) { throw new ChecksumValidationException(BAD_CHECKSUM_FILE_REF, "The file reference '" + fc.getFileReference( ) + "' in the checksum file does not match expected file: '" + fileName + "'" ); } else if (!fc.isFormatMatch()) { throw new ChecksumValidationException( BAD_CHECKSUM_FILE, "The checksum file content could not be parsed: "+checksumFile ); } return fc.getChecksum( ); } ChecksummedFile( final Path referenceFile ); static ChecksumReference getFromChecksumFile( Path checksumFile ); String calculateChecksum( ChecksumAlgorithm checksumAlgorithm ); Path writeFile(ChecksumAlgorithm checksumAlgorithm ); Path getChecksumFile( ChecksumAlgorithm checksumAlgorithm ); boolean isValidChecksum( ChecksumAlgorithm algorithm); boolean isValidChecksum( ChecksumAlgorithm algorithm, boolean throwExceptions ); boolean isValidChecksums( List<ChecksumAlgorithm> algorithms); boolean isValidChecksums( List<ChecksumAlgorithm> algorithms, boolean throwExceptions); Path getReferenceFile( ); UpdateStatusList fixChecksum(ChecksumAlgorithm algorithm); UpdateStatusList fixChecksums( List<ChecksumAlgorithm> algorithms ); String parseChecksum( Path checksumFile, ChecksumAlgorithm checksumAlgorithm, String fileName, Charset encoding ); ChecksumFileContent parseChecksumFile( Path checksumFile, ChecksumAlgorithm checksumAlgorithm, Charset encoding ); }
ChecksummedFile { public String parseChecksum( Path checksumFile, ChecksumAlgorithm checksumAlgorithm, String fileName, Charset encoding ) throws ChecksumValidationException { ChecksumFileContent fc = parseChecksumFile( checksumFile, checksumAlgorithm, encoding ); if ( fc.isFormatMatch() && !isValidChecksumPattern( fc.getFileReference( ), fileName ) ) { throw new ChecksumValidationException(BAD_CHECKSUM_FILE_REF, "The file reference '" + fc.getFileReference( ) + "' in the checksum file does not match expected file: '" + fileName + "'" ); } else if (!fc.isFormatMatch()) { throw new ChecksumValidationException( BAD_CHECKSUM_FILE, "The checksum file content could not be parsed: "+checksumFile ); } return fc.getChecksum( ); } ChecksummedFile( final Path referenceFile ); static ChecksumReference getFromChecksumFile( Path checksumFile ); String calculateChecksum( ChecksumAlgorithm checksumAlgorithm ); Path writeFile(ChecksumAlgorithm checksumAlgorithm ); Path getChecksumFile( ChecksumAlgorithm checksumAlgorithm ); boolean isValidChecksum( ChecksumAlgorithm algorithm); boolean isValidChecksum( ChecksumAlgorithm algorithm, boolean throwExceptions ); boolean isValidChecksums( List<ChecksumAlgorithm> algorithms); boolean isValidChecksums( List<ChecksumAlgorithm> algorithms, boolean throwExceptions); Path getReferenceFile( ); UpdateStatusList fixChecksum(ChecksumAlgorithm algorithm); UpdateStatusList fixChecksums( List<ChecksumAlgorithm> algorithms ); String parseChecksum( Path checksumFile, ChecksumAlgorithm checksumAlgorithm, String fileName, Charset encoding ); ChecksumFileContent parseChecksumFile( Path checksumFile, ChecksumAlgorithm checksumAlgorithm, Charset encoding );  }