Adding source to collect all localisation texts
[gigi.git] / util-testing / org / cacert / gigi / localisation / FileIterable.java
1 package org.cacert.gigi.localisation;
2 import java.io.BufferedReader;
3 import java.io.File;
4 import java.io.FileInputStream;
5 import java.io.IOError;
6 import java.io.IOException;
7 import java.io.InputStreamReader;
8 import java.util.Iterator;
9
10 public class FileIterable implements Iterable<String> {
11         File f;
12
13         public FileIterable(File f) {
14                 this.f = f;
15         }
16
17         @Override
18         public Iterator<String> iterator() {
19                 try {
20                         return new Iterator<String>() {
21                                 BufferedReader br = new BufferedReader(new InputStreamReader(
22                                                 new FileInputStream(f), "UTF-8"));
23                                 String s = null;
24                                 private void getNext() {
25                                         if (s == null) {
26                                                 try {
27                                                         s = br.readLine();
28                                                 } catch (IOException e) {
29                                                         throw new IOError(e);
30                                                 }
31                                         }
32                                 }
33                                 @Override
34                                 public boolean hasNext() {
35                                         getNext();
36                                         return s != null;
37                                 }
38
39                                 @Override
40                                 public String next() {
41                                         String out = s;
42                                         s = null;
43                                         return out;
44                                 }
45                         };
46                 } catch (IOException e) {
47                         throw new IOError(e);
48                 }
49         }
50 }