Revision 358

tmp/org.txm.utils/META-INF/MANIFEST.MF (revision 358)
1 1
Manifest-Version: 1.0
2 2
Bundle-ManifestVersion: 2
3
Bundle-Name: Utils
3
Bundle-Name: org.txm.utils
4 4
Bundle-SymbolicName: org.txm.utils
5 5
Bundle-Version: 1.0.0.qualifier
6 6
Require-Bundle: org.eclipse.osgi.util;bundle-version="3.3.0";visibility:=reexport,
tmp/org.txm.utils/src/org/txm/utils/io/IOUtils.java (revision 358)
12 12
import java.io.PrintWriter;
13 13
import java.io.UnsupportedEncodingException;
14 14
import java.util.ArrayList;
15
import java.util.regex.Matcher;
16
import java.util.regex.Pattern;
15 17

  
16 18
import org.txm.utils.i18n.DetectBOM;
17 19

  
18 20
public class IOUtils {
19 21
	public static final String UTF8 = "UTF-8";
20 22

  
23
	public static ArrayList<String> findWithGroup(File file, String pattern) throws IOException {
24
		return findWithGroup(file, UTF8, pattern, false);
25
	}
26
	
27
	public static ArrayList<String> findWithGroup(File file, String pattern, boolean normalizeSeparators) throws IOException {
28
		return findWithGroup(file, UTF8, pattern, normalizeSeparators);
29
	}
30
	
31
	public static ArrayList<String> findWithGroup(File file, String encoding, String pattern) throws IOException {
32
		return findWithGroup(file, encoding, pattern, false);
33
	}
34
	
35
	public static ArrayList<String> findWithGroup(File file, String encoding, String pattern, boolean normalizeSeparators) throws IOException {
36
		ArrayList<String> matches = new ArrayList<String>();
37
		String text = IOUtils.getText(file, encoding);
38
		if (normalizeSeparators) text = text.replaceAll("\\s", " ");
39
		
40
		Pattern test = Pattern.compile(pattern);
41
		Matcher m = test.matcher(text);
42
		while (m.find()) {
43
			matches.add(m.group(1));
44
		}
45
		return matches;
46
	}
47
	
21 48
	public static BufferedReader getReader(File file) throws UnsupportedEncodingException, FileNotFoundException {
22 49
		return getReader(file, UTF8);
23 50
	}

Also available in: Unified diff