Mercurial > jhg
annotate src/org/tmatesoft/hg/internal/LineReader.java @ 559:6ca3d0c5b4bc
Commit: tests and fixes for defects discovered
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Mon, 25 Feb 2013 19:48:20 +0100 |
parents | 9edfd5a223b8 |
children | 8cbc2a883d95 |
rev | line source |
---|---|
480
f3fab7a20841
Refactor LineReader utility as stanalone class to facilitate reuse
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
1 /* |
539
9edfd5a223b8
Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
483
diff
changeset
|
2 * Copyright (c) 2012-2013 TMate Software Ltd |
480
f3fab7a20841
Refactor LineReader utility as stanalone class to facilitate reuse
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
3 * |
f3fab7a20841
Refactor LineReader utility as stanalone class to facilitate reuse
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
4 * This program is free software; you can redistribute it and/or modify |
f3fab7a20841
Refactor LineReader utility as stanalone class to facilitate reuse
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
5 * it under the terms of the GNU General Public License as published by |
f3fab7a20841
Refactor LineReader utility as stanalone class to facilitate reuse
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
6 * the Free Software Foundation; version 2 of the License. |
f3fab7a20841
Refactor LineReader utility as stanalone class to facilitate reuse
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
7 * |
f3fab7a20841
Refactor LineReader utility as stanalone class to facilitate reuse
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
8 * This program is distributed in the hope that it will be useful, |
f3fab7a20841
Refactor LineReader utility as stanalone class to facilitate reuse
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
f3fab7a20841
Refactor LineReader utility as stanalone class to facilitate reuse
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
f3fab7a20841
Refactor LineReader utility as stanalone class to facilitate reuse
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
11 * GNU General Public License for more details. |
f3fab7a20841
Refactor LineReader utility as stanalone class to facilitate reuse
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
12 * |
f3fab7a20841
Refactor LineReader utility as stanalone class to facilitate reuse
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
13 * For information on how to redistribute this software under |
f3fab7a20841
Refactor LineReader utility as stanalone class to facilitate reuse
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
14 * the terms of a license other than GNU General Public License |
f3fab7a20841
Refactor LineReader utility as stanalone class to facilitate reuse
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
15 * contact TMate Software at support@hg4j.com |
f3fab7a20841
Refactor LineReader utility as stanalone class to facilitate reuse
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
16 */ |
f3fab7a20841
Refactor LineReader utility as stanalone class to facilitate reuse
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
17 package org.tmatesoft.hg.internal; |
f3fab7a20841
Refactor LineReader utility as stanalone class to facilitate reuse
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
18 |
f3fab7a20841
Refactor LineReader utility as stanalone class to facilitate reuse
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
19 import static org.tmatesoft.hg.util.LogFacility.Severity.Warn; |
f3fab7a20841
Refactor LineReader utility as stanalone class to facilitate reuse
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
20 |
f3fab7a20841
Refactor LineReader utility as stanalone class to facilitate reuse
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
21 import java.io.BufferedReader; |
f3fab7a20841
Refactor LineReader utility as stanalone class to facilitate reuse
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
22 import java.io.File; |
539
9edfd5a223b8
Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
483
diff
changeset
|
23 import java.io.FileInputStream; |
480
f3fab7a20841
Refactor LineReader utility as stanalone class to facilitate reuse
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
24 import java.io.FileReader; |
f3fab7a20841
Refactor LineReader utility as stanalone class to facilitate reuse
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
25 import java.io.IOException; |
539
9edfd5a223b8
Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
483
diff
changeset
|
26 import java.io.InputStreamReader; |
9edfd5a223b8
Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
483
diff
changeset
|
27 import java.io.Reader; |
9edfd5a223b8
Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
483
diff
changeset
|
28 import java.nio.charset.Charset; |
480
f3fab7a20841
Refactor LineReader utility as stanalone class to facilitate reuse
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
29 import java.util.Collection; |
f3fab7a20841
Refactor LineReader utility as stanalone class to facilitate reuse
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
30 |
f3fab7a20841
Refactor LineReader utility as stanalone class to facilitate reuse
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
31 import org.tmatesoft.hg.repo.HgInvalidFileException; |
f3fab7a20841
Refactor LineReader utility as stanalone class to facilitate reuse
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
32 import org.tmatesoft.hg.repo.ext.MqManager; |
f3fab7a20841
Refactor LineReader utility as stanalone class to facilitate reuse
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
33 import org.tmatesoft.hg.util.LogFacility; |
f3fab7a20841
Refactor LineReader utility as stanalone class to facilitate reuse
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
34 |
f3fab7a20841
Refactor LineReader utility as stanalone class to facilitate reuse
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
35 /** |
f3fab7a20841
Refactor LineReader utility as stanalone class to facilitate reuse
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
36 * Handy class to read line-based configuration files |
f3fab7a20841
Refactor LineReader utility as stanalone class to facilitate reuse
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
37 * |
f3fab7a20841
Refactor LineReader utility as stanalone class to facilitate reuse
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
38 * @author Artem Tikhomirov |
f3fab7a20841
Refactor LineReader utility as stanalone class to facilitate reuse
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
39 * @author TMate Software Ltd. |
f3fab7a20841
Refactor LineReader utility as stanalone class to facilitate reuse
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
40 */ |
f3fab7a20841
Refactor LineReader utility as stanalone class to facilitate reuse
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
41 public final class LineReader { |
f3fab7a20841
Refactor LineReader utility as stanalone class to facilitate reuse
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
42 |
f3fab7a20841
Refactor LineReader utility as stanalone class to facilitate reuse
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
43 public interface LineConsumer<T> { |
f3fab7a20841
Refactor LineReader utility as stanalone class to facilitate reuse
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
44 // boolean begin(File f, T paramObj) throws IOException; |
f3fab7a20841
Refactor LineReader utility as stanalone class to facilitate reuse
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
45 boolean consume(String line, T paramObj) throws IOException; |
f3fab7a20841
Refactor LineReader utility as stanalone class to facilitate reuse
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
46 // boolean end(File f, T paramObj) throws IOException; |
f3fab7a20841
Refactor LineReader utility as stanalone class to facilitate reuse
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
47 } |
f3fab7a20841
Refactor LineReader utility as stanalone class to facilitate reuse
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
48 |
f3fab7a20841
Refactor LineReader utility as stanalone class to facilitate reuse
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
49 public static class SimpleLineCollector implements LineReader.LineConsumer<Collection<String>> { |
f3fab7a20841
Refactor LineReader utility as stanalone class to facilitate reuse
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
50 |
f3fab7a20841
Refactor LineReader utility as stanalone class to facilitate reuse
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
51 public boolean consume(String line, Collection<String> result) throws IOException { |
f3fab7a20841
Refactor LineReader utility as stanalone class to facilitate reuse
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
52 result.add(line); |
f3fab7a20841
Refactor LineReader utility as stanalone class to facilitate reuse
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
53 return true; |
f3fab7a20841
Refactor LineReader utility as stanalone class to facilitate reuse
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
54 } |
f3fab7a20841
Refactor LineReader utility as stanalone class to facilitate reuse
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
55 } |
f3fab7a20841
Refactor LineReader utility as stanalone class to facilitate reuse
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
56 |
f3fab7a20841
Refactor LineReader utility as stanalone class to facilitate reuse
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
57 private final File file; |
f3fab7a20841
Refactor LineReader utility as stanalone class to facilitate reuse
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
58 private final LogFacility log; |
539
9edfd5a223b8
Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
483
diff
changeset
|
59 private final Charset encoding; |
480
f3fab7a20841
Refactor LineReader utility as stanalone class to facilitate reuse
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
60 private boolean trimLines = true; |
f3fab7a20841
Refactor LineReader utility as stanalone class to facilitate reuse
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
61 private boolean skipEmpty = true; |
f3fab7a20841
Refactor LineReader utility as stanalone class to facilitate reuse
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
62 private String ignoreThatStarts = null; |
f3fab7a20841
Refactor LineReader utility as stanalone class to facilitate reuse
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
63 |
f3fab7a20841
Refactor LineReader utility as stanalone class to facilitate reuse
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
64 public LineReader(File f, LogFacility logFacility) { |
539
9edfd5a223b8
Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
483
diff
changeset
|
65 this(f, logFacility, null); |
9edfd5a223b8
Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
483
diff
changeset
|
66 } |
9edfd5a223b8
Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
483
diff
changeset
|
67 |
9edfd5a223b8
Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
483
diff
changeset
|
68 public LineReader(File f, LogFacility logFacility, Charset lineEncoding) { |
480
f3fab7a20841
Refactor LineReader utility as stanalone class to facilitate reuse
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
69 file = f; |
f3fab7a20841
Refactor LineReader utility as stanalone class to facilitate reuse
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
70 log = logFacility; |
539
9edfd5a223b8
Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
483
diff
changeset
|
71 encoding = lineEncoding; |
480
f3fab7a20841
Refactor LineReader utility as stanalone class to facilitate reuse
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
72 } |
f3fab7a20841
Refactor LineReader utility as stanalone class to facilitate reuse
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
73 |
f3fab7a20841
Refactor LineReader utility as stanalone class to facilitate reuse
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
74 /** |
f3fab7a20841
Refactor LineReader utility as stanalone class to facilitate reuse
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
75 * default: <code>true</code> |
f3fab7a20841
Refactor LineReader utility as stanalone class to facilitate reuse
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
76 * <code>false</code> to return line as is |
f3fab7a20841
Refactor LineReader utility as stanalone class to facilitate reuse
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
77 */ |
f3fab7a20841
Refactor LineReader utility as stanalone class to facilitate reuse
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
78 public LineReader trimLines(boolean trim) { |
f3fab7a20841
Refactor LineReader utility as stanalone class to facilitate reuse
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
79 trimLines = trim; |
f3fab7a20841
Refactor LineReader utility as stanalone class to facilitate reuse
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
80 return this; |
f3fab7a20841
Refactor LineReader utility as stanalone class to facilitate reuse
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
81 } |
f3fab7a20841
Refactor LineReader utility as stanalone class to facilitate reuse
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
82 |
f3fab7a20841
Refactor LineReader utility as stanalone class to facilitate reuse
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
83 /** |
f3fab7a20841
Refactor LineReader utility as stanalone class to facilitate reuse
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
84 * default: <code>true</code> |
f3fab7a20841
Refactor LineReader utility as stanalone class to facilitate reuse
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
85 * <code>false</code> to pass empty lines to consumer |
f3fab7a20841
Refactor LineReader utility as stanalone class to facilitate reuse
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
86 */ |
f3fab7a20841
Refactor LineReader utility as stanalone class to facilitate reuse
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
87 public LineReader skipEmpty(boolean skip) { |
f3fab7a20841
Refactor LineReader utility as stanalone class to facilitate reuse
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
88 skipEmpty = skip; |
f3fab7a20841
Refactor LineReader utility as stanalone class to facilitate reuse
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
89 return this; |
f3fab7a20841
Refactor LineReader utility as stanalone class to facilitate reuse
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
90 } |
f3fab7a20841
Refactor LineReader utility as stanalone class to facilitate reuse
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
91 |
f3fab7a20841
Refactor LineReader utility as stanalone class to facilitate reuse
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
92 /** |
f3fab7a20841
Refactor LineReader utility as stanalone class to facilitate reuse
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
93 * default: doesn't skip any line. |
f3fab7a20841
Refactor LineReader utility as stanalone class to facilitate reuse
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
94 * set e.g. to "#" or "//" to skip lines that start with such prefix |
f3fab7a20841
Refactor LineReader utility as stanalone class to facilitate reuse
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
95 */ |
f3fab7a20841
Refactor LineReader utility as stanalone class to facilitate reuse
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
96 public LineReader ignoreLineComments(String lineStart) { |
f3fab7a20841
Refactor LineReader utility as stanalone class to facilitate reuse
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
97 ignoreThatStarts = lineStart; |
f3fab7a20841
Refactor LineReader utility as stanalone class to facilitate reuse
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
98 return this; |
f3fab7a20841
Refactor LineReader utility as stanalone class to facilitate reuse
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
99 } |
f3fab7a20841
Refactor LineReader utility as stanalone class to facilitate reuse
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
100 |
f3fab7a20841
Refactor LineReader utility as stanalone class to facilitate reuse
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
101 public <T> void read(LineConsumer<T> consumer, T paramObj) throws HgInvalidFileException { |
f3fab7a20841
Refactor LineReader utility as stanalone class to facilitate reuse
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
102 BufferedReader statusFileReader = null; |
f3fab7a20841
Refactor LineReader utility as stanalone class to facilitate reuse
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
103 try { |
f3fab7a20841
Refactor LineReader utility as stanalone class to facilitate reuse
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
104 // consumer.begin(file, paramObj); |
539
9edfd5a223b8
Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
483
diff
changeset
|
105 Reader fileReader; |
9edfd5a223b8
Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
483
diff
changeset
|
106 if (encoding == null) { |
9edfd5a223b8
Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
483
diff
changeset
|
107 fileReader = new FileReader(file); |
9edfd5a223b8
Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
483
diff
changeset
|
108 } else { |
9edfd5a223b8
Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
483
diff
changeset
|
109 fileReader = new InputStreamReader(new FileInputStream(file)); |
9edfd5a223b8
Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
483
diff
changeset
|
110 } |
9edfd5a223b8
Commit: handle empty repository case
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
483
diff
changeset
|
111 statusFileReader = new BufferedReader(fileReader); |
480
f3fab7a20841
Refactor LineReader utility as stanalone class to facilitate reuse
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
112 String line; |
f3fab7a20841
Refactor LineReader utility as stanalone class to facilitate reuse
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
113 boolean ok = true; |
f3fab7a20841
Refactor LineReader utility as stanalone class to facilitate reuse
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
114 while (ok && (line = statusFileReader.readLine()) != null) { |
f3fab7a20841
Refactor LineReader utility as stanalone class to facilitate reuse
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
115 if (trimLines) { |
f3fab7a20841
Refactor LineReader utility as stanalone class to facilitate reuse
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
116 line = line.trim(); |
f3fab7a20841
Refactor LineReader utility as stanalone class to facilitate reuse
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
117 } |
f3fab7a20841
Refactor LineReader utility as stanalone class to facilitate reuse
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
118 if (ignoreThatStarts != null && line.startsWith(ignoreThatStarts)) { |
f3fab7a20841
Refactor LineReader utility as stanalone class to facilitate reuse
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
119 continue; |
f3fab7a20841
Refactor LineReader utility as stanalone class to facilitate reuse
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
120 } |
f3fab7a20841
Refactor LineReader utility as stanalone class to facilitate reuse
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
121 if (!skipEmpty || line.length() > 0) { |
f3fab7a20841
Refactor LineReader utility as stanalone class to facilitate reuse
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
122 ok = consumer.consume(line, paramObj); |
f3fab7a20841
Refactor LineReader utility as stanalone class to facilitate reuse
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
123 } |
f3fab7a20841
Refactor LineReader utility as stanalone class to facilitate reuse
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
124 } |
f3fab7a20841
Refactor LineReader utility as stanalone class to facilitate reuse
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
125 } catch (IOException ex) { |
f3fab7a20841
Refactor LineReader utility as stanalone class to facilitate reuse
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
126 throw new HgInvalidFileException(ex.getMessage(), ex, file); |
f3fab7a20841
Refactor LineReader utility as stanalone class to facilitate reuse
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
127 } finally { |
483
e31e85cf4d4c
Handle include and unset directives in config files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
480
diff
changeset
|
128 if (statusFileReader != null) { |
e31e85cf4d4c
Handle include and unset directives in config files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
480
diff
changeset
|
129 try { |
e31e85cf4d4c
Handle include and unset directives in config files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
480
diff
changeset
|
130 statusFileReader.close(); |
e31e85cf4d4c
Handle include and unset directives in config files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
480
diff
changeset
|
131 } catch (IOException ex) { |
e31e85cf4d4c
Handle include and unset directives in config files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
480
diff
changeset
|
132 log.dump(MqManager.class, Warn, ex, null); |
e31e85cf4d4c
Handle include and unset directives in config files
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
480
diff
changeset
|
133 } |
480
f3fab7a20841
Refactor LineReader utility as stanalone class to facilitate reuse
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
134 } |
f3fab7a20841
Refactor LineReader utility as stanalone class to facilitate reuse
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
135 // try { |
f3fab7a20841
Refactor LineReader utility as stanalone class to facilitate reuse
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
136 // consumer.end(file, paramObj); |
f3fab7a20841
Refactor LineReader utility as stanalone class to facilitate reuse
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
137 // } catch (IOException ex) { |
f3fab7a20841
Refactor LineReader utility as stanalone class to facilitate reuse
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
138 // log.warn(MqManager.class, ex, null); |
f3fab7a20841
Refactor LineReader utility as stanalone class to facilitate reuse
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
139 // } |
f3fab7a20841
Refactor LineReader utility as stanalone class to facilitate reuse
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
140 } |
f3fab7a20841
Refactor LineReader utility as stanalone class to facilitate reuse
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
141 } |
f3fab7a20841
Refactor LineReader utility as stanalone class to facilitate reuse
Artem Tikhomirov <tikhomirov.artem@gmail.com>
parents:
diff
changeset
|
142 } |