Skip to content

Commit b268517

Browse files
authored
Merge pull request #448 from harawata/use-nio
Use NIO to make modernizer happy
2 parents 33e37ae + d8e82e8 commit b268517

File tree

22 files changed

+126
-124
lines changed

22 files changed

+126
-124
lines changed

.mvn/extensions.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<!--
33
4-
Copyright 2010-2024 the original author or authors.
4+
Copyright 2010-2025 the original author or authors.
55
66
Licensed under the Apache License, Version 2.0 (the "License");
77
you may not use this file except in compliance with the License.

.mvn/settings.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<!--
33
4-
Copyright 2010-2024 the original author or authors.
4+
Copyright 2010-2025 the original author or authors.
55
66
Licensed under the Apache License, Version 2.0 (the "License");
77
you may not use this file except in compliance with the License.

.mvn/wrapper/MavenWrapperDownloader.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import java.net.URL;
2626
import java.nio.file.Files;
2727
import java.nio.file.Path;
28-
import java.nio.file.Paths;
2928
import java.nio.file.StandardCopyOption;
3029
import java.util.concurrent.ThreadLocalRandom;
3130

@@ -46,7 +45,7 @@ public static void main(String[] args) {
4645
log(" - Downloader started");
4746
final URL wrapperUrl = URI.create(args[0]).toURL();
4847
final String jarPath = args[1].replace("..", ""); // Sanitize path
49-
final Path wrapperJarPath = Paths.get(jarPath).toAbsolutePath().normalize();
48+
final Path wrapperJarPath = Path.of(jarPath).toAbsolutePath().normalize();
5049
downloadFileFromURL(wrapperUrl, wrapperJarPath);
5150
log("Done");
5251
} catch (IOException e) {

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#
2-
# Copyright 2010-2022 the original author or authors.
2+
# Copyright 2010-2025 the original author or authors.
33
#
44
# Licensed under the Apache License, Version 2.0 (the "License");
55
# you may not use this file except in compliance with the License.

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@
6363

6464
<properties>
6565
<!-- Java Usage -->
66-
<java.version>8</java.version>
67-
<java.release.version>8</java.release.version>
66+
<java.version>11</java.version>
67+
<java.release.version>11</java.release.version>
6868

6969
<findbugs.onlyAnalyze>org.apache.ibatis.migration</findbugs.onlyAnalyze>
7070
<clirr.comparisonVersion>3.2.0</clirr.comparisonVersion>

src/main/java/org/apache/ibatis/migration/Environment.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2010-2023 the original author or authors.
2+
* Copyright 2010-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,10 +16,11 @@
1616
package org.apache.ibatis.migration;
1717

1818
import java.io.File;
19-
import java.io.FileInputStream;
2019
import java.io.FileNotFoundException;
2120
import java.io.IOException;
21+
import java.io.InputStream;
2222
import java.nio.charset.Charset;
23+
import java.nio.file.Files;
2324
import java.util.ArrayList;
2425
import java.util.Arrays;
2526
import java.util.Collections;
@@ -208,7 +209,7 @@ private boolean isMigrationsKey(String key) {
208209

209210
private Properties loadPropertiesFromFile(File file) {
210211
Properties properties = new Properties();
211-
try (FileInputStream inputStream = new FileInputStream(file)) {
212+
try (InputStream inputStream = Files.newInputStream(file.toPath())) {
212213
properties.load(inputStream);
213214
return properties;
214215
} catch (FileNotFoundException e) {

src/main/java/org/apache/ibatis/migration/MigrationReader.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2010-2023 the original author or authors.
2+
* Copyright 2010-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,13 +16,13 @@
1616
package org.apache.ibatis.migration;
1717

1818
import java.io.File;
19-
import java.io.FileInputStream;
2019
import java.io.FilterReader;
2120
import java.io.IOException;
2221
import java.io.InputStream;
2322
import java.io.InputStreamReader;
2423
import java.io.Reader;
2524
import java.nio.charset.Charset;
25+
import java.nio.file.Files;
2626
import java.util.Properties;
2727

2828
public class MigrationReader extends FilterReader {
@@ -85,7 +85,7 @@ private enum VariableStatus {
8585
}
8686

8787
public MigrationReader(File file, String charset, boolean undo, Properties variables) throws IOException {
88-
this(new FileInputStream(file), charset, undo, variables);
88+
this(Files.newInputStream(file.toPath()), charset, undo, variables);
8989
}
9090

9191
public MigrationReader(InputStream inputStream, String charset, boolean undo, Properties variables) {

src/main/java/org/apache/ibatis/migration/commands/BaseCommand.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2010-2023 the original author or authors.
2+
* Copyright 2010-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -18,8 +18,6 @@
1818
import static org.apache.ibatis.migration.utils.Util.file;
1919

2020
import java.io.File;
21-
import java.io.FileReader;
22-
import java.io.FileWriter;
2321
import java.io.IOException;
2422
import java.io.LineNumberReader;
2523
import java.io.OutputStream;
@@ -28,6 +26,8 @@
2826
import java.io.Reader;
2927
import java.net.URL;
3028
import java.net.URLClassLoader;
29+
import java.nio.file.Files;
30+
import java.nio.file.Path;
3131
import java.text.DecimalFormat;
3232
import java.text.ParseException;
3333
import java.text.SimpleDateFormat;
@@ -161,7 +161,7 @@ protected void copyResourceTo(String resource, File toFile, Properties variables
161161
protected void copyExternalResourceTo(String resource, File toFile, Properties variables) {
162162
printStream.println("Creating: " + toFile.getName());
163163
try {
164-
File sourceFile = new File(resource);
164+
File sourceFile = Path.of(resource).toFile();
165165
copyTemplate(sourceFile, toFile, variables);
166166
} catch (Exception e) {
167167
throw new MigrationException("Error copying " + resource + " to " + toFile.getAbsolutePath() + ". Cause: " + e,
@@ -170,15 +170,15 @@ protected void copyExternalResourceTo(String resource, File toFile, Properties v
170170
}
171171

172172
protected static void copyTemplate(File templateFile, File toFile, Properties variables) throws IOException {
173-
try (FileReader reader = new FileReader(templateFile)) {
173+
try (Reader reader = Files.newBufferedReader(templateFile.toPath())) {
174174
copyTemplate(reader, toFile, variables);
175175
}
176176
}
177177

178178
protected static void copyTemplate(Reader templateReader, File toFile, Properties variables) throws IOException {
179179
VariableReplacer replacer = new VariableReplacer(variables);
180180
try (LineNumberReader reader = new LineNumberReader(templateReader);
181-
PrintWriter writer = new PrintWriter(new FileWriter(toFile))) {
181+
PrintWriter writer = new PrintWriter(Files.newBufferedWriter(toFile.toPath()))) {
182182
String line;
183183
while ((line = reader.readLine()) != null) {
184184
line = replacer.replace(line);
@@ -259,7 +259,7 @@ private ClassLoader getDriverClassLoader() {
259259
private File getCustomDriverPath() {
260260
String customDriverPath = environment().getDriverPath();
261261
if (customDriverPath != null && customDriverPath.length() > 0) {
262-
return new File(customDriverPath);
262+
return Path.of(customDriverPath).toFile();
263263
}
264264
return options.getPaths().getDriverPath();
265265
}

src/main/java/org/apache/ibatis/migration/hook/FileHookScriptFactory.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2010-2023 the original author or authors.
2+
* Copyright 2010-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -58,7 +58,7 @@ public HookScript create(String hookSetting) {
5858
// First segment is language
5959
String scriptLang = segments[0];
6060
// Second segment is file
61-
File scriptFile = new File(hooksDir, segments[1]);
61+
File scriptFile = hooksDir.toPath().resolve(segments[1]).toFile();
6262
// The rest are script dependent options
6363
String[] hookOptions = Arrays.copyOfRange(segments, 2, segments.length);
6464
if (!scriptFile.exists()) {

src/main/java/org/apache/ibatis/migration/hook/Jsr223HookScript.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2010-2023 the original author or authors.
2+
* Copyright 2010-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -16,11 +16,11 @@
1616
package org.apache.ibatis.migration.hook;
1717

1818
import java.io.File;
19-
import java.io.FileInputStream;
2019
import java.io.IOException;
2120
import java.io.InputStreamReader;
2221
import java.io.PrintStream;
2322
import java.nio.charset.Charset;
23+
import java.nio.file.Files;
2424
import java.util.ArrayList;
2525
import java.util.HashMap;
2626
import java.util.List;
@@ -102,8 +102,8 @@ public void execute(Map<String, Object> bindingMap) {
102102
bindings.putAll(bindingMap);
103103
try {
104104
printStream.println(Util.horizontalLine("Applying JSR-223 hook : " + scriptFile.getName(), 80));
105-
try (
106-
InputStreamReader stream = new InputStreamReader(new FileInputStream(scriptFile), Charset.forName(charset))) {
105+
try (InputStreamReader stream = new InputStreamReader(Files.newInputStream(scriptFile.toPath()),
106+
Charset.forName(charset))) {
107107
engine.eval(stream);
108108
}
109109
if (functionName != null || objectName != null && methodName != null) {

0 commit comments

Comments
 (0)