1515import java .util .Arrays ;
1616import java .util .Date ;
1717import java .util .List ;
18+ import java .util .regex .Matcher ;
19+ import java .util .regex .Pattern ;
1820
1921public class PBSReader {
2022
@@ -38,6 +40,9 @@ public static List<PBSRecord> readPBSFile(InputStream is, Date limitForStartedJo
3840 continue ;
3941 }
4042 PBSRecord record = new PBSRecord ();
43+ /*
44+ Formát řádku logu je timestamp;type;job_id;message následující kód tedy parsuje tyto 4 části.
45+ */
4146 String [] entryParts = line .split (";" );
4247
4348 switch (entryParts [1 ]) {
@@ -76,7 +81,11 @@ public static List<PBSRecord> readPBSFile(InputStream is, Date limitForStartedJo
7681
7782 record .setIdString (entryParts [2 ]);
7883
79- String [] messageParts = entryParts [3 ].split (" " );
84+ /*
85+ Formát message je definován jako položky oddělené mezerou, pokud hodnota obsahuje mezeru, je v uvozovkách.
86+ Ale prakticky se objevuje i hodnota v apostrofech obsahující JSON včetně uvozovek a mezer.
87+ */
88+ String [] messageParts = parseMessageParts (entryParts [3 ]);
8089 PBSMessage pbsMessage = new PBSMessage ();
8190
8291
@@ -260,4 +269,30 @@ private static void applyFixForTorque(PBSMessage pbsMessage, int usedCPUs) {
260269 private static String substringAfter (String s ,char ch ) {
261270 return s .substring (s .indexOf (ch ) + 1 );
262271 }
272+
273+ // Vegenerováno Gemini - Regex logika:
274+ // 1. ([^=\s]+) -> Key
275+ // 2. '([^']*)' -> Value v apostrofech (bere vše, včetně " a mezer, vhodné pro JSON)
276+ // 3. "([^"]*)" -> Value v uvozovkách
277+ // 4. ([^\s"']+) -> Value bez oddělovačů (nesmí obsahovat ' ani ")
278+ private static final Pattern PATTERN = Pattern .compile ("([^=\\ s]+)=(?:'([^']*)'|\" ([^\" ]*)\" |([^\\ s\" ']+))" );
279+
280+ private static String [] parseMessageParts (String line ) {
281+ List <String > list = new ArrayList <>();
282+ Matcher matcher = PATTERN .matcher (line );
283+
284+ while (matcher .find ()) {
285+ String key = matcher .group (1 ); // Key
286+ String value ;
287+ if (matcher .group (2 ) != null ) {
288+ value = matcher .group (2 ); // Single quoted (JSON)
289+ } else if (matcher .group (3 ) != null ) {
290+ value = matcher .group (3 ); // Double quoted
291+ } else {
292+ value = matcher .group (4 ); // Unquoted
293+ }
294+ list .add (key +"=" +value );
295+ }
296+ return list .toArray (new String [0 ]);
297+ }
263298}
0 commit comments