Consistent use of NIO.2 for file read/write interactions

Issue: SPR-15748
This commit is contained in:
Juergen Hoeller
2017-07-18 00:54:41 +02:00
parent d56fedc226
commit 12114a9d4c
10 changed files with 118 additions and 125 deletions

View File

@@ -16,9 +16,6 @@
package org.springframework.expression.spel.standard;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.Map;
@@ -244,40 +241,6 @@ public class SpelCompiler implements Opcodes {
}
}
/**
* For debugging purposes, dump the specified byte code into a file on the disk.
* Not yet hooked in, needs conditionally calling based on a sys prop.
* @param expressionText the text of the expression compiled
* @param name the name of the class being used for the compiled expression
* @param bytecode the bytecode for the generated class
*/
@SuppressWarnings("unused")
private static void dump(String expressionText, String name, byte[] bytecode) {
String nameToUse = name.replace('.', '/');
String dir = (nameToUse.indexOf('/') != -1 ? nameToUse.substring(0, nameToUse.lastIndexOf('/')) : "");
String dumpLocation = null;
try {
File tempFile = File.createTempFile("tmp", null);
dumpLocation = tempFile + File.separator + nameToUse + ".class";
tempFile.delete();
File f = new File(tempFile, dir);
f.mkdirs();
// System.out.println("Expression '" + expressionText + "' compiled code dumped to " + dumpLocation);
if (logger.isDebugEnabled()) {
logger.debug("Expression '" + expressionText + "' compiled code dumped to " + dumpLocation);
}
f = new File(dumpLocation);
FileOutputStream fos = new FileOutputStream(f);
fos.write(bytecode);
fos.flush();
fos.close();
}
catch (IOException ex) {
throw new IllegalStateException(
"Unexpected problem dumping class '" + nameToUse + "' into " + dumpLocation, ex);
}
}
/**
* A ChildClassLoader will load the generated compiled expression classes.