Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
ChecksumAlgorithm |
|
| 0.0;0 |
1 | package org.apache.archiva.checksum; | |
2 | ||
3 | /* | |
4 | * Licensed to the Apache Software Foundation (ASF) under one | |
5 | * or more contributor license agreements. See the NOTICE file | |
6 | * distributed with this work for additional information | |
7 | * regarding copyright ownership. The ASF licenses this file | |
8 | * to you under the Apache License, Version 2.0 (the | |
9 | * "License"); you may not use this file except in compliance | |
10 | * with the License. You may obtain a copy of the License at | |
11 | * | |
12 | * http://www.apache.org/licenses/LICENSE-2.0 | |
13 | * | |
14 | * Unless required by applicable law or agreed to in writing, | |
15 | * software distributed under the License is distributed on an | |
16 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | |
17 | * KIND, either express or implied. See the License for the | |
18 | * specific language governing permissions and limitations | |
19 | * under the License. | |
20 | */ | |
21 | ||
22 | import java.io.File; | |
23 | ||
24 | import org.apache.commons.io.FilenameUtils; | |
25 | ||
26 | /** | |
27 | * Enumeration of available ChecksumAlgorithm techniques. | |
28 | * | |
29 | * @version $Id: ChecksumAlgorithm.java 718864 2008-11-19 06:33:35Z brett $ | |
30 | */ | |
31 | 0 | public enum ChecksumAlgorithm { |
32 | 0 | SHA1("SHA-1", "sha1", "SHA1"), |
33 | 0 | MD5("MD5", "md5", "MD5"); |
34 | ||
35 | public static ChecksumAlgorithm getByExtension( File file ) | |
36 | { | |
37 | 0 | String ext = FilenameUtils.getExtension( file.getName() ).toLowerCase(); |
38 | 0 | if ( ChecksumAlgorithm.SHA1.getExt().equals( ext ) ) |
39 | { | |
40 | 0 | return ChecksumAlgorithm.SHA1; |
41 | } | |
42 | 0 | else if ( ChecksumAlgorithm.MD5.getExt().equals( ext ) ) |
43 | { | |
44 | 0 | return ChecksumAlgorithm.MD5; |
45 | } | |
46 | ||
47 | 0 | throw new IllegalArgumentException( "Filename " + file.getName() + " has no associated extension." ); |
48 | } | |
49 | ||
50 | /** | |
51 | * The MessageDigest algorithm for this hash. | |
52 | */ | |
53 | private String algorithm; | |
54 | ||
55 | /** | |
56 | * The file extension for this ChecksumAlgorithm. | |
57 | */ | |
58 | private String ext; | |
59 | ||
60 | /** | |
61 | * The checksum type, the key that you see in checksum files. | |
62 | */ | |
63 | private String type; | |
64 | ||
65 | /** | |
66 | * Construct a ChecksumAlgorithm | |
67 | * | |
68 | * @param algorithm the MessageDigest algorithm | |
69 | * @param ext the file extension. | |
70 | * @param type the checksum type. | |
71 | */ | |
72 | private ChecksumAlgorithm( String algorithm, String ext, String type ) | |
73 | 0 | { |
74 | 0 | this.algorithm = algorithm; |
75 | 0 | this.ext = ext; |
76 | 0 | this.type = type; |
77 | 0 | } |
78 | ||
79 | public String getAlgorithm() | |
80 | { | |
81 | 0 | return algorithm; |
82 | } | |
83 | ||
84 | public String getExt() | |
85 | { | |
86 | 0 | return ext; |
87 | } | |
88 | ||
89 | public String getType() | |
90 | { | |
91 | 0 | return type; |
92 | } | |
93 | ||
94 | ||
95 | } |