Mercurial > jhg
comparison src/org/tmatesoft/hg/internal/LineReader.java @ 539:9edfd5a223b8
Commit: handle empty repository case
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Wed, 13 Feb 2013 18:44:58 +0100 |
parents | e31e85cf4d4c |
children | 8cbc2a883d95 |
comparison
equal
deleted
inserted
replaced
538:dd4f6311af52 | 539:9edfd5a223b8 |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 2012 TMate Software Ltd | 2 * Copyright (c) 2012-2013 TMate Software Ltd |
3 * | 3 * |
4 * This program is free software; you can redistribute it and/or modify | 4 * This program is free software; you can redistribute it and/or modify |
5 * it under the terms of the GNU General Public License as published by | 5 * it under the terms of the GNU General Public License as published by |
6 * the Free Software Foundation; version 2 of the License. | 6 * the Free Software Foundation; version 2 of the License. |
7 * | 7 * |
18 | 18 |
19 import static org.tmatesoft.hg.util.LogFacility.Severity.Warn; | 19 import static org.tmatesoft.hg.util.LogFacility.Severity.Warn; |
20 | 20 |
21 import java.io.BufferedReader; | 21 import java.io.BufferedReader; |
22 import java.io.File; | 22 import java.io.File; |
23 import java.io.FileInputStream; | |
23 import java.io.FileReader; | 24 import java.io.FileReader; |
24 import java.io.IOException; | 25 import java.io.IOException; |
26 import java.io.InputStreamReader; | |
27 import java.io.Reader; | |
28 import java.nio.charset.Charset; | |
25 import java.util.Collection; | 29 import java.util.Collection; |
26 | 30 |
27 import org.tmatesoft.hg.repo.HgInvalidFileException; | 31 import org.tmatesoft.hg.repo.HgInvalidFileException; |
28 import org.tmatesoft.hg.repo.ext.MqManager; | 32 import org.tmatesoft.hg.repo.ext.MqManager; |
29 import org.tmatesoft.hg.util.LogFacility; | 33 import org.tmatesoft.hg.util.LogFacility; |
50 } | 54 } |
51 } | 55 } |
52 | 56 |
53 private final File file; | 57 private final File file; |
54 private final LogFacility log; | 58 private final LogFacility log; |
59 private final Charset encoding; | |
55 private boolean trimLines = true; | 60 private boolean trimLines = true; |
56 private boolean skipEmpty = true; | 61 private boolean skipEmpty = true; |
57 private String ignoreThatStarts = null; | 62 private String ignoreThatStarts = null; |
58 | 63 |
59 public LineReader(File f, LogFacility logFacility) { | 64 public LineReader(File f, LogFacility logFacility) { |
65 this(f, logFacility, null); | |
66 } | |
67 | |
68 public LineReader(File f, LogFacility logFacility, Charset lineEncoding) { | |
60 file = f; | 69 file = f; |
61 log = logFacility; | 70 log = logFacility; |
71 encoding = lineEncoding; | |
62 } | 72 } |
63 | 73 |
64 /** | 74 /** |
65 * default: <code>true</code> | 75 * default: <code>true</code> |
66 * <code>false</code> to return line as is | 76 * <code>false</code> to return line as is |
90 | 100 |
91 public <T> void read(LineConsumer<T> consumer, T paramObj) throws HgInvalidFileException { | 101 public <T> void read(LineConsumer<T> consumer, T paramObj) throws HgInvalidFileException { |
92 BufferedReader statusFileReader = null; | 102 BufferedReader statusFileReader = null; |
93 try { | 103 try { |
94 // consumer.begin(file, paramObj); | 104 // consumer.begin(file, paramObj); |
95 statusFileReader = new BufferedReader(new FileReader(file)); | 105 Reader fileReader; |
106 if (encoding == null) { | |
107 fileReader = new FileReader(file); | |
108 } else { | |
109 fileReader = new InputStreamReader(new FileInputStream(file)); | |
110 } | |
111 statusFileReader = new BufferedReader(fileReader); | |
96 String line; | 112 String line; |
97 boolean ok = true; | 113 boolean ok = true; |
98 while (ok && (line = statusFileReader.readLine()) != null) { | 114 while (ok && (line = statusFileReader.readLine()) != null) { |
99 if (trimLines) { | 115 if (trimLines) { |
100 line = line.trim(); | 116 line = line.trim(); |