// Decompiled by DJ v2.6.6.51 Copyright 2000 Atanas Neshkov  Date: 10/2/2001 11:01:02
// Home Page : http://members.fortunecity.com/neshkov/dj.html  - Check often for new version!
// Decompiler options: packimports(3) 
// Source File Name:   com/macromedia/generator/utils/GenUtils

package com.macromedia.generator.utils;

import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.*;

public class GenUtils
{

    public GenUtils()
    {
    }

    private static boolean _mth0285(File file)
    {
        return !file.exists();
    }

    private static boolean _mth0285(String s)
    {
        if(s == null)
            throw new SecurityException("Unable to create temporary file");
        else
            return _mth0285(new File(s));
    }

    public static boolean createNewFile(File file)
        throws IOException
    {
        boolean flag = false;
        if(isJava2())
            flag = file.createNewFile();
        else
            return _mth0288(file);
        return flag;
    }

    public static File createTempFile(String s, String s1, File file)
        throws IOException
    {
        File file1 = null;
        if(isJava2())
            file1 = File.createTempFile(s, s1, file);
        else
            file1 = sun_createTempFile(s, s1, file);
        return file1;
    }

    public static float getJavaVersion()
    {
        return Float.valueOf(_fld0285).floatValue();
    }

    private static void _mth0286()
    {
        if(_fld0285 == null)
        {
            _fld0285 = System.getProperty("java.version");
            _fld0285 = _fld0285.substring(0, 3);
        }
    }

    public static String getJavaVersionString()
    {
        return _fld0285;
    }

    public static File getParentFile(File file)
    {
        File file1 = null;
        if(isJava2())
        {
            file1 = file.getParentFile();
        } else
        {
            String s = file.getParent();
            if(s != null)
                file1 = new File(s);
        }
        return file1;
    }

    public static Vector hashtableToVector(Hashtable hashtable)
    {
        if(hashtable == null)
            return null;
        int i = hashtable.size();
        Vector vector = new Vector(i);
        for(Enumeration enumeration = hashtable.elements(); enumeration.hasMoreElements(); vector.addElement(enumeration.nextElement()));
        return vector;
    }

    public static boolean isJava2()
    {
        return (double)getJavaVersion() >= 1.2D;
    }

    public static File[] makeFileArray(File file, String as[])
    {
        if(as == null || as.length == 0 || file == null)
            return null;
        File afile[] = new File[as.length];
        for(int i = 0; i < as.length; i++)
            afile[i] = new File(file, as[i]);

        return afile;
    }

    public static String replace(String s, String s1, char c)
    {
        StringBuffer stringbuffer = new StringBuffer();
        int i = 0;
        int j;
        for(j = 0; i >= 0; j = i + s1.length())
        {
            i = s.indexOf(s1, j);
            if(i < 0)
                break;
            stringbuffer.append(s.substring(j, i));
            stringbuffer.append(c);
        }

        stringbuffer.append(s.substring(j, s.length()));
        return stringbuffer.toString();
    }

    private static boolean _mth0287(String s, SecurityManager securitymanager)
        throws IOException
    {
        if(securitymanager != null)
            try
            {
                securitymanager.checkWrite(s);
            }
            catch(SecurityException _ex)
            {
                throw new SecurityException("Unable to create temporary file");
            }
        return _mth0285(s);
    }

    private static boolean _mth0288(File file)
        throws IOException
    {
        SecurityManager securitymanager = System.getSecurityManager();
        if(securitymanager != null)
            securitymanager.checkWrite(file.getPath());
        return _mth0285(file);
    }

    public static File sun_createTempFile(String s, String s1, File file)
        throws IOException
    {
        if(s == null)
            throw new NullPointerException();
        if(s.length() < 3)
            throw new IllegalArgumentException("Prefix string too short");
        String s2 = s1 != null ? s1 : ".tmp";
        synchronized(_fld0286)
        {
            if(file == null)
                throw new IllegalArgumentException("directory is null");
            SecurityManager securitymanager = System.getSecurityManager();
            File file2;
            do
                file2 = _mth0289(s, s2, file);
            while(!_mth0287(file2.getPath(), securitymanager));
            File file1 = file2;
            return file1;
        }
    }

    private static File _mth0289(String s, String s1, File file)
        throws IOException
    {
        if(_fld0287 == -1)
            _fld0287 = (new Random()).nextInt() & 0xffff;
        _fld0287++;
        return new File(file, s + Integer.toString(_fld0287) + s1);
    }

    public static URL toURL(File file)
        throws MalformedURLException
    {
        String s = file.getAbsolutePath();
        if(File.separatorChar != '/')
            s = s.replace(File.separatorChar, '/');
        if(!s.startsWith("/"))
            s = "/" + s;
        if(!s.endsWith("/") && file.isDirectory())
            s = s + "/";
        return new URL("file", "", s);
    }

    private static String _fld0285 = null;
    private static final Object _fld0286 = new Object();
    private static int _fld0287 = -1;

    static 
    {
        _mth0286();
    }
}