⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 baseio.java

📁 一个java的免费游戏引擎,里面有文档,和例子
💻 JAVA
字号:
// Decompiled by Jad v1.5.7g. Copyright 2000 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/SiliconValley/Bridge/8617/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi 

package com.golden.gamedev.engine;

import java.io.File;
import java.io.InputStream;
import java.net.URL;

public class BaseIO
{

    public static final int CLASS_URL = 1;
    public static final int WORKING_DIRECTORY = 2;
    public static final int CLASS_LOADER = 3;
    public static final int SYSTEM_LOADER = 4;
    private Class e;
    private ClassLoader f;
    private int g;

    public BaseIO(Class class1, int i)
    {
        e = class1;
        f = class1.getClassLoader();
        g = i;
    }

    public BaseIO(Class class1)
    {
        this(class1, 1);
    }

    public URL getURL(String s, int i)
    {
        URL url = null;
        File file;
        try
        {
            switch(i)
            {
            case 1: // '\001'
                url = e.getResource(s);
                break;

            case 2: // '\002'
                if((file = new File(s)).exists())
                    url = file.toURL();
                break;

            case 3: // '\003'
                url = f.getResource(s);
                break;

            case 4: // '\004'
                url = ClassLoader.getSystemResource(s);
                break;
            }
        }
        catch(Exception _ex) { }
        if(url == null)
            throw new RuntimeException(getException(s, i, "getURL"));
        else
            return url;
    }

    public URL getURL(String s)
    {
        URL url = null;
        try
        {
            url = getURL(s, g);
        }
        catch(Exception exception) { }
        if(url == null)
        {
            int i;
            for(i = 0; url == null && !getModeString(++i).equals("[UNKNOWN-MODE]");)
                try
                {
                    url = getURL(s, i);
                }
                catch(Exception _ex) { }

            if(url == null)
                throw new RuntimeException(getException(s, g, "getURL"));
            g = i;
        }
        return url;
    }

    public InputStream getStream(String s, int i)
    {
        InputStream inputstream = null;
        try
        {
            switch(i)
            {
            case 1: // '\001'
                inputstream = e.getResourceAsStream(s);
                break;

            case 2: // '\002'
                inputstream = (new File(s)).toURL().openStream();
                break;

            case 3: // '\003'
                inputstream = f.getResourceAsStream(s);
                break;

            case 4: // '\004'
                inputstream = ClassLoader.getSystemResourceAsStream(s);
                break;
            }
        }
        catch(Exception _ex) { }
        if(inputstream == null)
            throw new RuntimeException(getException(s, i, "getStream"));
        else
            return inputstream;
    }

    public InputStream getStream(String s)
    {
        InputStream inputstream = null;
        try
        {
            inputstream = getStream(s, g);
        }
        catch(Exception exception) { }
        if(inputstream == null)
        {
            int i;
            for(i = 0; inputstream == null && !getModeString(++i).equals("[UNKNOWN-MODE]");)
                try
                {
                    inputstream = getStream(s, i);
                }
                catch(Exception _ex) { }

            if(inputstream == null)
                throw new RuntimeException(getException(s, g, "getStream"));
            g = i;
        }
        return inputstream;
    }

    public File getFile(String s, int i)
    {
        File file = null;
        try
        {
            switch(i)
            {
            case 1: // '\001'
                file = new File(e.getResource(s).getFile().replaceAll("%20", " "));
                break;

            case 2: // '\002'
                file = new File(s);
                break;

            case 3: // '\003'
                file = new File(f.getResource(s).getFile().replaceAll("%20", " "));
                break;

            case 4: // '\004'
                file = new File(ClassLoader.getSystemResource(s).getFile().replaceAll("%20", " "));
                break;
            }
        }
        catch(Exception _ex) { }
        if(file == null)
            throw new RuntimeException(getException(s, i, "getFile"));
        else
            return file;
    }

    public File getFile(String s)
    {
        File file = null;
        try
        {
            file = getFile(s, g);
        }
        catch(Exception exception) { }
        if(file == null)
        {
            int i;
            for(i = 0; file == null && !getModeString(++i).equals("[UNKNOWN-MODE]");)
                try
                {
                    file = getFile(s, i);
                }
                catch(Exception _ex) { }

            if(file == null)
                throw new RuntimeException(getException(s, g, "getFile"));
            g = i;
        }
        return file;
    }

    public File setFile(String s, int i)
    {
        File file = null;
        try
        {
            switch(i)
            {
            case 1: // '\001'
                file = new File(e.getResource("").getFile().replaceAll("%20", " ") + File.separator + s);
                break;

            case 2: // '\002'
                file = new File(s);
                break;

            case 3: // '\003'
                file = new File(f.getResource("").getFile().replaceAll("%20", " ") + File.separator + s);
                break;

            case 4: // '\004'
                file = new File(ClassLoader.getSystemResource("").getFile().replaceAll("%20", " ") + File.separator + s);
                break;
            }
        }
        catch(Exception _ex) { }
        if(file == null)
            throw new RuntimeException(getException(s, i, "setFile"));
        else
            return file;
    }

    public File setFile(String s)
    {
        File file = null;
        try
        {
            file = setFile(s, g);
        }
        catch(Exception exception) { }
        if(file == null)
        {
            int i;
            for(i = 0; file == null && !getModeString(++i).equals("[UNKNOWN-MODE]");)
                try
                {
                    file = setFile(s, i);
                }
                catch(Exception _ex) { }

            if(file == null)
                throw new RuntimeException(getException(s, g, "setFile"));
            g = i;
        }
        return file;
    }

    public String getRootPath(int i)
    {
        switch(i)
        {
        case 1: // '\001'
            return e.getResource("").toString();

        case 2: // '\002'
            return System.getProperty("user.dir") + File.separator;

        case 3: // '\003'
            return f.getResource("").toString();

        case 4: // '\004'
            return ClassLoader.getSystemResource("").toString();
        }
        return "[UNKNOWN-MODE]";
    }

    public String getModeString(int i)
    {
        switch(i)
        {
        case 1: // '\001'
            return "Class-URL";

        case 2: // '\002'
            return "Working-Directory";

        case 3: // '\003'
            return "Class-Loader";

        case 4: // '\004'
            return "System-Loader";
        }
        return "[UNKNOWN-MODE]";
    }

    public int getMode()
    {
        return g;
    }

    public void setMode(int i)
    {
        g = i;
    }

    protected String getException(String s, int i, String s1)
    {
        return "Resource not found: " + getRootPath(i) + s;
    }

    public void setBase(Class class1)
    {
        e = class1;
        f = class1.getClassLoader();
    }

    public Class getBase()
    {
        return e;
    }

    public ClassLoader getLoader()
    {
        return f;
    }

    public String toString()
    {
        return super.toString() + " " + "[mode=" + getModeString(g) + ", baseClass=" + e + ", classLoader=" + f + "]";
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -