diff options
author | Olivier Lamy <olamy@apache.org> | 2015-03-23 13:32:46 +1100 |
---|---|---|
committer | Olivier Lamy <olamy@apache.org> | 2015-03-23 14:31:58 +1100 |
commit | f5022a27218c62310e82b62e53de0c5dee78abf2 (patch) | |
tree | ba025c1cb7e502bca5e2df8e3b7bd012f474b8a1 /archiva-modules/archiva-base/archiva-checksum | |
parent | f766714024cfc3ec7615e886887e0cc12ca92622 (diff) | |
download | archiva-f5022a27218c62310e82b62e53de0c5dee78abf2.tar.gz archiva-f5022a27218c62310e82b62e53de0c5dee78abf2.zip |
use 1.7 features for files
Diffstat (limited to 'archiva-modules/archiva-base/archiva-checksum')
2 files changed, 21 insertions, 20 deletions
diff --git a/archiva-modules/archiva-base/archiva-checksum/src/main/java/org/apache/archiva/checksum/Checksum.java b/archiva-modules/archiva-base/archiva-checksum/src/main/java/org/apache/archiva/checksum/Checksum.java index e80925865..c83b9d433 100644 --- a/archiva-modules/archiva-base/archiva-checksum/src/main/java/org/apache/archiva/checksum/Checksum.java +++ b/archiva-modules/archiva-base/archiva-checksum/src/main/java/org/apache/archiva/checksum/Checksum.java @@ -19,6 +19,9 @@ package org.apache.archiva.checksum; * under the License. */ +import org.apache.commons.io.IOUtils; +import org.apache.commons.io.output.NullOutputStream; + import java.io.IOException; import java.io.InputStream; import java.security.DigestInputStream; @@ -26,13 +29,8 @@ import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.util.List; -import org.apache.commons.io.IOUtils; -import org.apache.commons.io.output.NullOutputStream; - /** - * Checksum - simple checksum hashing routines. - * - * + * Checksum - simple checksum hashing routines. */ public class Checksum { @@ -67,8 +65,9 @@ public class Checksum catch ( NoSuchAlgorithmException e ) { // Not really possible, but here none-the-less - throw new IllegalStateException( "Unable to initialize MessageDigest algorithm " + checksumAlgorithm.getAlgorithm() - + " : " + e.getMessage(), e ); + throw new IllegalStateException( + "Unable to initialize MessageDigest algorithm " + checksumAlgorithm.getAlgorithm() + " : " + + e.getMessage(), e ); } } @@ -96,9 +95,10 @@ public class Checksum public Checksum update( InputStream stream ) throws IOException { - DigestInputStream dig = new DigestInputStream( stream, md ); - IOUtils.copy( dig, new NullOutputStream() ); - + try (DigestInputStream dig = new DigestInputStream( stream, md )) + { + IOUtils.copy( dig, new NullOutputStream() ); + } return this; } } diff --git a/archiva-modules/archiva-base/archiva-checksum/src/main/java/org/apache/archiva/checksum/ChecksummedFile.java b/archiva-modules/archiva-base/archiva-checksum/src/main/java/org/apache/archiva/checksum/ChecksummedFile.java index 366e16e0a..2cd0169f0 100644 --- a/archiva-modules/archiva-base/archiva-checksum/src/main/java/org/apache/archiva/checksum/ChecksummedFile.java +++ b/archiva-modules/archiva-base/archiva-checksum/src/main/java/org/apache/archiva/checksum/ChecksummedFile.java @@ -35,7 +35,7 @@ import java.util.regex.Pattern; /** * ChecksummedFile - * + * <p/> * <p>Terminology:</p> * <dl> * <dt>Checksum File</dt> @@ -46,13 +46,13 @@ import java.util.regex.Pattern; * <dt>Reference File</dt> * <dd>The file that is being referenced in the checksum file.</dd> * </dl> - * - * */ public class ChecksummedFile { private final Logger log = LoggerFactory.getLogger( ChecksummedFile.class ); + private static final Pattern METADATA_PATTERN = Pattern.compile( "maven-metadata-\\S*.xml" ); + private final File referenceFile; /** @@ -76,7 +76,7 @@ public class ChecksummedFile throws IOException { - try (InputStream fis = Files.newInputStream( referenceFile.toPath() ) ) + try (InputStream fis = Files.newInputStream( referenceFile.toPath() )) { Checksum checksum = new Checksum( checksumAlgorithm ); checksum.update( fis ); @@ -115,7 +115,7 @@ public class ChecksummedFile * <p> * Given a checksum file, check to see if the file it represents is valid according to the checksum. * </p> - * + * <p/> * <p> * NOTE: Only supports single file checksums of type MD5 or SHA1. * </p> @@ -199,7 +199,8 @@ public class ChecksummedFile } return valid; - } catch ( IOException e ) + } + catch ( IOException e ) { log.warn( "Unable to read / parse checksum: {}", e.getMessage() ); return false; @@ -228,7 +229,6 @@ public class ChecksummedFile return true; } - try (InputStream fis = Files.newInputStream( referenceFile.toPath() )) { // Parse file once, for all checksums. @@ -281,8 +281,8 @@ public class ChecksummedFile private boolean isValidChecksumPattern( String filename, String path ) { // check if it is a remote metadata file - Pattern pattern = Pattern.compile( "maven-metadata-\\S*.xml" ); - Matcher m = pattern.matcher( path ); + + Matcher m = METADATA_PATTERN.matcher( path ); if ( m.matches() ) { return filename.endsWith( path ) || ( "-".equals( filename ) ) || filename.endsWith( "maven-metadata.xml" ); @@ -297,6 +297,7 @@ public class ChecksummedFile * Validate the expected path, and expected checksum algorithm, then return * the trimmed checksum hex string. * </p> + * * @param rawChecksumString * @param expectedHash * @param expectedPath |