bonjour
j'ai une fonction pour parser des textes qui marche trés bien mais des que je lui donne un string trés gros (que je upload d'un fichier de 9 ou 10 MO),
ça plente , avec un java heap space.
voilà ma fonction
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
|
public ArrayList MatchMessageBuffer(String regex, StringBuffer message) {
ArrayList groupVec = new ArrayList();
int groups;
PatternMatcher matcher;
PatternCompiler compiler;
Pattern pattern = null;
PatternMatcherInput input;
MatchResult result;
compiler = new Perl5Compiler();
matcher = new Perl5Matcher();
try {
pattern = compiler.compile(regex);
} catch (org.apache.oro.text.regex.MalformedPatternException e) {
groupVec.add("NO MATCH");
}
System.out.println("1*");
input = new PatternMatcherInput(message.toString());
if (matcher.contains(input ,pattern)) {
result = matcher.getMatch();
groups = result.groups();
// Start at 1 because we just printed out group 0
for (int group = 0; group < groups; group++) {
try {
if (result.group(group).length() > 0) {
groupVec.add(result.group(group));
}
else {
groupVec.add("NO MATCH");
}
} catch (java.lang.NullPointerException p) {
groupVec.add("NO MATCH");
}
} //end for
} else {
groupVec.add("NO MATCH");
}
if (groupVec.size() <= 0) {
groupVec.add("NO MATCH");
}
return groupVec;
} |
et ça plente biensure au niveau de
new PatternMatcherInput(message.toString());
la conversion du stringbuffer en string.
merci pour vos aide trés attendu
Partager