1 package com.atlassian.security.auth.trustedapps;
2
3 import java.io.BufferedReader;
4 import java.io.IOException;
5 import java.io.Reader;
6 import java.util.ArrayList;
7 import java.util.Collections;
8 import java.util.List;
9
10
11
12
13 public class ReaderApplicationRetriever implements ApplicationRetriever
14 {
15 private final ListApplicationRetriever delegate;
16
17 public ReaderApplicationRetriever(Reader reader, EncryptionProvider encryptionProvider)
18 {
19 Null.not("reader", reader);
20 Null.not("encryptionProvider", encryptionProvider);
21
22 this.delegate = new ListApplicationRetriever(encryptionProvider, extract(reader));
23 }
24
25 public Application getApplication() throws RetrievalException
26 {
27 return delegate.getApplication();
28 }
29
30 private List extract(Reader r)
31 {
32 BufferedReader reader = new BufferedReader(r);
33 final List result = new ArrayList();
34
35 try
36 {
37 for (String str = reader.readLine(); str != null; str = reader.readLine())
38 {
39 String line = str.trim();
40 if (line.length() > 0)
41 {
42 result.add(line);
43 }
44 }
45 }
46 catch (IOException e)
47 {
48 throw new RuntimeException(e);
49 }
50 return Collections.unmodifiableList(result);
51 }
52 }