1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.rat.analysis;
20
21 import org.apache.commons.io.IOUtils;
22 import org.apache.rat.api.Document;
23 import org.apache.rat.document.IDocumentAnalyser;
24 import org.apache.rat.document.RatDocumentAnalysisException;
25
26 import java.io.IOException;
27 import java.io.Reader;
28
29 public class DocumentHeaderAnalyser implements IDocumentAnalyser {
30
31 private final IHeaderMatcher matcher;
32
33 public DocumentHeaderAnalyser(final IHeaderMatcher matcher) {
34 super();
35 this.matcher = matcher;
36 }
37
38 public void analyse(Document document) throws RatDocumentAnalysisException {
39 Reader reader = null;
40 try {
41 reader = document.reader();
42
43 HeaderCheckWorker worker = new HeaderCheckWorker(reader, matcher, document);
44 worker.read();
45 } catch (IOException e) {
46 throw new RatDocumentAnalysisException("Cannot read header", e);
47 } catch (RatHeaderAnalysisException e) {
48 throw new RatDocumentAnalysisException("Cannot analyse header", e);
49 } finally {
50 IOUtils.closeQuietly(reader);
51 }
52 }
53
54 }