Skip to content

Commit e02d0c6

Browse files
committed
Replace JDK11 code with JDK6 compatible code to avoid warns/errs during dev only.
1 parent d3a05b5 commit e02d0c6

File tree

2 files changed

+32
-10
lines changed

2 files changed

+32
-10
lines changed

src/support/lombok/eclipse/dependencies/DownloadEclipseDependencies.java

+31-9
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
package lombok.eclipse.dependencies;
22

33
import java.io.BufferedInputStream;
4+
import java.io.ByteArrayInputStream;
45
import java.io.File;
6+
import java.io.FileOutputStream;
57
import java.io.FilenameFilter;
68
import java.io.IOException;
79
import java.io.InputStream;
810
import java.io.InputStreamReader;
11+
import java.io.OutputStream;
912
import java.net.HttpURLConnection;
1013
import java.net.MalformedURLException;
1114
import java.net.URL;
12-
import java.nio.file.Files;
13-
import java.nio.file.Path;
14-
import java.nio.file.Paths;
15-
import java.nio.file.StandardCopyOption;
15+
import java.nio.charset.StandardCharsets;
1616
import java.util.Arrays;
1717
import java.util.regex.Matcher;
1818
import java.util.regex.Pattern;
@@ -70,18 +70,34 @@ private static String readUrlAsString(String url) throws MalformedURLException,
7070
}
7171

7272
private static void downloadFile(String filename, String repositoryUrl, String target) throws IOException {
73-
Files.createDirectories(Paths.get(target));
74-
Path targetFile = Paths.get(target, filename);
75-
if (Files.exists(targetFile)) {
73+
new File(target).mkdirs();
74+
File targetFile = new File(target, filename);
75+
if (targetFile.exists()) {
7676
System.out.println("File '" + filename + "' already exists");
7777
return;
7878
}
7979
System.out.print("Downloading '" + filename + "'... ");
80+
InputStream in = null;
81+
OutputStream out = null;
8082
try {
81-
Files.copy(getStreamForUrl(repositoryUrl + filename), targetFile, StandardCopyOption.REPLACE_EXISTING);
83+
in = getStreamForUrl(repositoryUrl + filename);
84+
out = new FileOutputStream(targetFile);
85+
copy(in, out);
8286
System.out.println("[done]");
8387
} catch(IOException e) {
8488
System.out.println("[error]");
89+
} finally {
90+
if (in != null) try { in.close(); } catch (Exception ignore) {}
91+
if (out != null) out.close();
92+
}
93+
}
94+
95+
private static void copy(InputStream from, OutputStream to) throws IOException {
96+
byte[] b = new byte[4096];
97+
while (true) {
98+
int r = from.read(b);
99+
if (r == -1) return;
100+
to.write(b, 0, r);
85101
}
86102
}
87103

@@ -126,6 +142,12 @@ private static void writeEclipseLibrary(String target, String eclipseVersion) th
126142
sb.append("</library>\n");
127143
sb.append("</eclipse-userlibraries>\n");
128144

129-
Files.writeString(Paths.get(target, eclipseVersion + ".userlibraries"), sb.toString());
145+
OutputStream out = null;
146+
try {
147+
out = new FileOutputStream(new File(target, eclipseVersion + ".userlibraries"));
148+
copy(new ByteArrayInputStream(sb.toString().getBytes(StandardCharsets.UTF_8)), out);
149+
} finally {
150+
if (out != null) out.close();
151+
}
130152
}
131153
}

src/utils/lombok/core/LombokImmutableList.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public static <T> LombokImmutableList<T> of(T a, T b, T c, T d, T e) {
5757
return new LombokImmutableList<T>(new Object[] {a, b, c, d, e});
5858
}
5959

60-
public static <T> LombokImmutableList<T> of(T a, T b, T c, T d, T e, T f, T... g) {
60+
@SafeVarargs public static <T> LombokImmutableList<T> of(T a, T b, T c, T d, T e, T f, T... g) {
6161
Object[] rest = g == null ? new Object[] {null} : g;
6262
Object[] val = new Object[rest.length + 6];
6363
System.arraycopy(rest, 0, val, 6, rest.length);

0 commit comments

Comments
 (0)