1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package net.oneandone.maven.plugins.billofmaterials;
17
18 import com.google.common.base.Function;
19 import com.google.common.hash.HashCode;
20 import com.google.common.hash.HashFunction;
21 import com.google.common.io.Files;
22 import java.io.File;
23 import java.io.IOException;
24
25
26
27
28
29 final class ToBomStringFunction implements Function<File, String> {
30
31
32
33 private final HashFunction hashFunction;
34
35
36
37
38 ToBomStringFunction(HashFunction hashFunction) {
39 this.hashFunction = hashFunction;
40 }
41
42 @Override
43 public String apply(final File file) {
44 final HashCode hash;
45 try {
46 hash = Files.hash(file, hashFunction);
47 } catch (IOException e) {
48 throw new IllegalArgumentException("Could not create hash for " + file, e);
49 }
50 return hash + " " + file.getName();
51 }
52
53 }