You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by su...@apache.org on 2022/06/25 07:59:37 UTC
[groovy] branch master updated: Revert "Construct `InputStream` and `OutputStream` with `Files` methods"
This is an automated email from the ASF dual-hosted git repository.
sunlan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/groovy.git
The following commit(s) were added to refs/heads/master by this push:
new 729d960fc5 Revert "Construct `InputStream` and `OutputStream` with `Files` methods"
729d960fc5 is described below
commit 729d960fc5457a188cf531da74b3cf666e2573d7
Author: Daniel Sun <su...@apache.org>
AuthorDate: Sat Jun 25 15:57:56 2022 +0800
Revert "Construct `InputStream` and `OutputStream` with `Files` methods"
This reverts commit 0c1917456b56bb30cd7e1f1f0fca5da41991e2ec.
`Files` methods" throw incompatible exceptions
---
src/main/java/groovy/util/CharsetToolkit.java | 3 +--
.../org/codehaus/groovy/control/io/FileReaderSource.java | 4 ++--
.../codehaus/groovy/reflection/GeneratedMetaMethod.java | 5 ++---
.../org/codehaus/groovy/runtime/ResourceGroovyMethods.java | 14 +++++++-------
src/main/java/org/codehaus/groovy/tools/GroovyStarter.java | 5 ++---
.../org/codehaus/groovy/tools/javac/JavaStubGenerator.java | 1 +
6 files changed, 15 insertions(+), 17 deletions(-)
diff --git a/src/main/java/groovy/util/CharsetToolkit.java b/src/main/java/groovy/util/CharsetToolkit.java
index fe933016fe..6e2d1351f1 100644
--- a/src/main/java/groovy/util/CharsetToolkit.java
+++ b/src/main/java/groovy/util/CharsetToolkit.java
@@ -28,7 +28,6 @@ import java.io.InputStreamReader;
import java.io.LineNumberReader;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
-import java.nio.file.Files;
import java.util.Collection;
/**
@@ -76,7 +75,7 @@ public class CharsetToolkit {
this.file = file;
this.defaultCharset = getDefaultSystemCharset();
this.charset = null;
- try (InputStream input = Files.newInputStream(file.toPath())) {
+ try (InputStream input = new FileInputStream(file)) {
byte[] bytes = new byte[4096];
int bytesRead = input.read(bytes);
if (bytesRead == -1) {
diff --git a/src/main/java/org/codehaus/groovy/control/io/FileReaderSource.java b/src/main/java/org/codehaus/groovy/control/io/FileReaderSource.java
index 1dec51dea9..44caa25eea 100644
--- a/src/main/java/org/codehaus/groovy/control/io/FileReaderSource.java
+++ b/src/main/java/org/codehaus/groovy/control/io/FileReaderSource.java
@@ -22,6 +22,7 @@ import org.codehaus.groovy.control.CompilerConfiguration;
import java.io.BufferedInputStream;
import java.io.File;
+import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
@@ -29,7 +30,6 @@ import java.io.Reader;
import java.net.URI;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
-import java.nio.file.Files;
/**
* A ReaderSource for source files.
@@ -60,7 +60,7 @@ public class FileReaderSource extends AbstractReaderSource {
// we want to remove the BOM windows adds from a file if the encoding is UTF-8
// in other cases we depend on the charsets
Charset cs = Charset.forName(configuration.getSourceEncoding());
- InputStream in = new BufferedInputStream(Files.newInputStream(file.toPath()));
+ InputStream in = new BufferedInputStream(new FileInputStream(file));
if (UTF8.name().equalsIgnoreCase(cs.name())) {
in.mark(3);
boolean hasBOM = true;
diff --git a/src/main/java/org/codehaus/groovy/reflection/GeneratedMetaMethod.java b/src/main/java/org/codehaus/groovy/reflection/GeneratedMetaMethod.java
index 5d61d65d62..f373e1c08f 100644
--- a/src/main/java/org/codehaus/groovy/reflection/GeneratedMetaMethod.java
+++ b/src/main/java/org/codehaus/groovy/reflection/GeneratedMetaMethod.java
@@ -25,12 +25,11 @@ import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
+import java.io.FileOutputStream;
import java.io.IOException;
import java.io.Serializable;
import java.lang.reflect.Constructor;
import java.lang.reflect.Modifier;
-import java.nio.file.Files;
-import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
@@ -136,7 +135,7 @@ public abstract class GeneratedMetaMethod extends MetaMethod {
try (DataOutputStream out =
new DataOutputStream(
new BufferedOutputStream(
- Files.newOutputStream(Paths.get(file))))) {
+ new FileOutputStream(file)))) {
Map<String, Integer> classes = new LinkedHashMap<String, Integer>();
int nextClassId = 0;
diff --git a/src/main/java/org/codehaus/groovy/runtime/ResourceGroovyMethods.java b/src/main/java/org/codehaus/groovy/runtime/ResourceGroovyMethods.java
index 2decfce7be..9a25ed154c 100644
--- a/src/main/java/org/codehaus/groovy/runtime/ResourceGroovyMethods.java
+++ b/src/main/java/org/codehaus/groovy/runtime/ResourceGroovyMethods.java
@@ -131,7 +131,7 @@ public class ResourceGroovyMethods extends DefaultGroovyMethodsSupport {
* @since 1.5.0
*/
public static ObjectOutputStream newObjectOutputStream(File file) throws IOException {
- return new ObjectOutputStream(Files.newOutputStream(file.toPath()));
+ return new ObjectOutputStream(new FileOutputStream(file));
}
/**
@@ -159,7 +159,7 @@ public class ResourceGroovyMethods extends DefaultGroovyMethodsSupport {
* @since 1.5.0
*/
public static ObjectInputStream newObjectInputStream(File file) throws IOException {
- return new ObjectInputStream(Files.newInputStream(file.toPath()));
+ return new ObjectInputStream(new FileInputStream(file));
}
/**
@@ -172,7 +172,7 @@ public class ResourceGroovyMethods extends DefaultGroovyMethodsSupport {
* @since 1.5.0
*/
public static ObjectInputStream newObjectInputStream(File file, final ClassLoader classLoader) throws IOException {
- return IOGroovyMethods.newObjectInputStream(Files.newInputStream(file.toPath()), classLoader);
+ return IOGroovyMethods.newObjectInputStream(new FileInputStream(file), classLoader);
}
/**
@@ -685,7 +685,7 @@ public class ResourceGroovyMethods extends DefaultGroovyMethodsSupport {
* @since 1.7.1
*/
public static byte[] getBytes(File file) throws IOException {
- return IOGroovyMethods.getBytes(Files.newInputStream(file.toPath()));
+ return IOGroovyMethods.getBytes(new FileInputStream(file));
}
/**
@@ -740,7 +740,7 @@ public class ResourceGroovyMethods extends DefaultGroovyMethodsSupport {
* @since 1.7.1
*/
public static void setBytes(File file, byte[] bytes) throws IOException {
- IOGroovyMethods.setBytes(Files.newOutputStream(file.toPath()), bytes);
+ IOGroovyMethods.setBytes(new FileOutputStream(file), bytes);
}
/**
@@ -1875,7 +1875,7 @@ public class ResourceGroovyMethods extends DefaultGroovyMethodsSupport {
* @since 1.0
*/
public static BufferedOutputStream newOutputStream(File file) throws IOException {
- return new BufferedOutputStream(Files.newOutputStream(file.toPath()));
+ return new BufferedOutputStream(new FileOutputStream(file));
}
/**
@@ -1887,7 +1887,7 @@ public class ResourceGroovyMethods extends DefaultGroovyMethodsSupport {
* @since 1.5.0
*/
public static DataOutputStream newDataOutputStream(File file) throws IOException {
- return new DataOutputStream(Files.newOutputStream(file.toPath()));
+ return new DataOutputStream(new FileOutputStream(file));
}
/**
diff --git a/src/main/java/org/codehaus/groovy/tools/GroovyStarter.java b/src/main/java/org/codehaus/groovy/tools/GroovyStarter.java
index 2e1fce7edc..2dd9a596ab 100644
--- a/src/main/java/org/codehaus/groovy/tools/GroovyStarter.java
+++ b/src/main/java/org/codehaus/groovy/tools/GroovyStarter.java
@@ -18,10 +18,9 @@
*/
package org.codehaus.groovy.tools;
+import java.io.FileInputStream;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
-import java.nio.file.Files;
-import java.nio.file.Paths;
import java.security.PrivilegedAction;
/**
@@ -91,7 +90,7 @@ public class GroovyStarter {
// load configuration file
if (conf!=null) {
try {
- lc.configure(Files.newInputStream(Paths.get(conf)));
+ lc.configure(new FileInputStream(conf));
} catch (Exception e) {
System.err.println("exception while configuring main class loader:");
exit(e);
diff --git a/src/main/java/org/codehaus/groovy/tools/javac/JavaStubGenerator.java b/src/main/java/org/codehaus/groovy/tools/javac/JavaStubGenerator.java
index 205720d846..31a51afbcf 100644
--- a/src/main/java/org/codehaus/groovy/tools/javac/JavaStubGenerator.java
+++ b/src/main/java/org/codehaus/groovy/tools/javac/JavaStubGenerator.java
@@ -58,6 +58,7 @@ import org.objectweb.asm.Opcodes;
import javax.tools.FileObject;
import javax.tools.JavaFileObject;
+
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;