提交 e8c86a37 编写于 作者: D Daniel Trebbien 提交者: Oleg Nenashev

Use fileToPath() (#3219)

* Use fileToPath()

This is a follow-up to PR 3210 on GitHub. See:
https://github.com/jenkinsci/jenkins/pull/3210#discussion_r160045107

* Switch two File.toPath() calls to Util.fileToPath()

* Delete an unused import
上级 cdf18d9b
......@@ -193,13 +193,11 @@ public class Util {
StringBuilder str = new StringBuilder((int)logfile.length());
try (BufferedReader r = Files.newBufferedReader(logfile.toPath(), charset)) {
try (BufferedReader r = Files.newBufferedReader(fileToPath(logfile), charset)) {
char[] buf = new char[1024];
int len;
while ((len = r.read(buf, 0, buf.length)) > 0)
str.append(buf, 0, len);
} catch (InvalidPathException e) {
throw new IOException(e);
}
return str.toString();
......
......@@ -64,7 +64,6 @@ import hudson.model.queue.WorkUnitContext;
import hudson.security.ACL;
import hudson.security.AccessControlled;
import java.nio.file.Files;
import java.nio.file.InvalidPathException;
import jenkins.security.QueueItemAuthenticatorProvider;
import jenkins.util.Timer;
import hudson.triggers.SafeTimerTask;
......@@ -377,15 +376,13 @@ public class Queue extends ResourceController implements Saveable {
// first try the old format
File queueFile = getQueueFile();
if (queueFile.exists()) {
try (BufferedReader in = Files.newBufferedReader(queueFile.toPath(), Charset.defaultCharset())) {
try (BufferedReader in = Files.newBufferedReader(Util.fileToPath(queueFile), Charset.defaultCharset())) {
String line;
while ((line = in.readLine()) != null) {
AbstractProject j = Jenkins.getInstance().getItemByFullName(line, AbstractProject.class);
if (j != null)
j.scheduleBuild();
}
} catch (InvalidPathException e) {
throw new IOException(e);
}
// discard the queue file now that we are done
queueFile.delete();
......
......@@ -25,6 +25,8 @@ package hudson.util;
import com.google.common.collect.*;
import hudson.Util;
import java.nio.file.Files;
import java.nio.file.InvalidPathException;
import javax.annotation.Nonnull;
......@@ -69,12 +71,10 @@ public class TextFile {
public String read() throws IOException {
StringWriter out = new StringWriter();
PrintWriter w = new PrintWriter(out);
try (BufferedReader in = Files.newBufferedReader(file.toPath(), StandardCharsets.UTF_8)) {
try (BufferedReader in = Files.newBufferedReader(Util.fileToPath(file), StandardCharsets.UTF_8)) {
String line;
while ((line = in.readLine()) != null)
w.println(line);
} catch (InvalidPathException e) {
throw new IOException(e);
}
return out.toString();
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册