Mercurial > hg4j
diff 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 |
line wrap: on
line diff
--- a/src/org/tmatesoft/hg/internal/LineReader.java Tue Feb 05 22:30:21 2013 +0100 +++ b/src/org/tmatesoft/hg/internal/LineReader.java Wed Feb 13 18:44:58 2013 +0100 @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012 TMate Software Ltd + * Copyright (c) 2012-2013 TMate Software Ltd * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -20,8 +20,12 @@ import java.io.BufferedReader; import java.io.File; +import java.io.FileInputStream; import java.io.FileReader; import java.io.IOException; +import java.io.InputStreamReader; +import java.io.Reader; +import java.nio.charset.Charset; import java.util.Collection; import org.tmatesoft.hg.repo.HgInvalidFileException; @@ -52,13 +56,19 @@ private final File file; private final LogFacility log; + private final Charset encoding; private boolean trimLines = true; private boolean skipEmpty = true; private String ignoreThatStarts = null; public LineReader(File f, LogFacility logFacility) { + this(f, logFacility, null); + } + + public LineReader(File f, LogFacility logFacility, Charset lineEncoding) { file = f; log = logFacility; + encoding = lineEncoding; } /** @@ -92,7 +102,13 @@ BufferedReader statusFileReader = null; try { // consumer.begin(file, paramObj); - statusFileReader = new BufferedReader(new FileReader(file)); + Reader fileReader; + if (encoding == null) { + fileReader = new FileReader(file); + } else { + fileReader = new InputStreamReader(new FileInputStream(file)); + } + statusFileReader = new BufferedReader(fileReader); String line; boolean ok = true; while (ok && (line = statusFileReader.readLine()) != null) {