[armedbear-cvs] r13406 - trunk/abcl/src/org/armedbear/lisp
ehuelsmann at common-lisp.net
ehuelsmann at common-lisp.net
Fri Jul 15 16:34:24 UTC 2011
Author: ehuelsmann
Date: Fri Jul 15 09:34:23 2011
New Revision: 13406
Log:
Avoid using a temporary file when copying a random state;
it's complete overkill in the presence of memory (byte array)
backed streams.
Modified:
trunk/abcl/src/org/armedbear/lisp/RandomState.java
Modified: trunk/abcl/src/org/armedbear/lisp/RandomState.java
==============================================================================
--- trunk/abcl/src/org/armedbear/lisp/RandomState.java Thu Jul 14 12:23:11 2011 (r13405)
+++ trunk/abcl/src/org/armedbear/lisp/RandomState.java Fri Jul 15 09:34:23 2011 (r13406)
@@ -35,9 +35,8 @@
import static org.armedbear.lisp.Lisp.*;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.math.BigInteger;
@@ -55,16 +54,14 @@
public RandomState(RandomState rs)
{
try {
- File file = File.createTempFile("MAKE-RANDOM-STATE", null);
- FileOutputStream fileOut = new FileOutputStream(file);
- ObjectOutputStream out = new ObjectOutputStream(fileOut);
+ ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
+ ObjectOutputStream out = new ObjectOutputStream(byteOut);
out.writeObject(rs.random);
out.close();
- FileInputStream fileIn = new FileInputStream(file);
- ObjectInputStream in = new ObjectInputStream(fileIn);
+ ByteArrayInputStream byteIn = new ByteArrayInputStream(byteOut.toByteArray());
+ ObjectInputStream in = new ObjectInputStream(byteIn);
random = (Random) in.readObject();
in.close();
- file.delete(); // FIXME: file leak on exception
}
catch (Throwable t) { // ANY exception gets converted to a lisp error
error(new LispError("Unable to copy random state."));
More information about the armedbear-cvs
mailing list