Changeset 13406


Ignore:
Timestamp:
07/15/11 16:34:23 (10 years ago)
Author:
ehuelsmann
Message:

Avoid using a temporary file when copying a random state;
it's complete overkill in the presence of memory (byte array)
backed streams.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/abcl/src/org/armedbear/lisp/RandomState.java

    r12298 r13406  
    3636import static org.armedbear.lisp.Lisp.*;
    3737
    38 import java.io.File;
    39 import java.io.FileInputStream;
    40 import java.io.FileOutputStream;
     38import java.io.ByteArrayInputStream;
     39import java.io.ByteArrayOutputStream;
    4140import java.io.ObjectInputStream;
    4241import java.io.ObjectOutputStream;
     
    5655    {
    5756        try {
    58             File file = File.createTempFile("MAKE-RANDOM-STATE", null);
    59             FileOutputStream fileOut = new FileOutputStream(file);
    60             ObjectOutputStream out = new ObjectOutputStream(fileOut);
     57            ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
     58            ObjectOutputStream out = new ObjectOutputStream(byteOut);
    6159            out.writeObject(rs.random);
    6260            out.close();
    63             FileInputStream fileIn = new FileInputStream(file);
    64             ObjectInputStream in = new ObjectInputStream(fileIn);
     61            ByteArrayInputStream byteIn = new ByteArrayInputStream(byteOut.toByteArray());
     62            ObjectInputStream in = new ObjectInputStream(byteIn);
    6563            random = (Random) in.readObject();
    6664            in.close();
    67             file.delete(); // FIXME: file leak on exception
    6865        }
    6966        catch (Throwable t) { // ANY exception gets converted to a lisp error
Note: See TracChangeset for help on using the changeset viewer.