private GeneratedFile openUniqueFile()

in src/main/java/org/apache/bsf/engines/netrexx/NetRexxEngine.java [457:495]


private GeneratedFile openUniqueFile(String directory,String prefix,String suffix)
    {
        File file=null,obj=null;
        FileOutputStream fos=null;
        int max=1000;           // Don't try forever
        GeneratedFile gf=null;
        int i;
        String className = null;
        for(i=max,++uniqueFileOffset;
            fos==null && i>0;
            --i,++uniqueFileOffset)
        {
            // Probably a timing hazard here... ***************
            try
                {
                    className = prefix+uniqueFileOffset;
                    file=new File(directory+File.separatorChar+className+suffix);
                    obj=new File(directory+File.separatorChar+className+".class");
                    if(file!=null && !file.exists() & obj!=null & !obj.exists())
                        fos=new FileOutputStream(file);
                }
            catch(Exception e)
                {
                    // File could not be opened for write, or Security Exception
                    // was thrown. If someone else created the file before we could
                    // open it, that's probably a threading conflict and we don't
                    // bother reporting it.
                    if(!file.exists())
                    {
                        logger.error("openUniqueFile: unexpected "+e);
                    }
                }
        }
        if(fos==null)
            logger.error("openUniqueFile: Failed "+max+"attempts.");
        else
            gf=new GeneratedFile(file,fos,className);
        return gf;
    }