System.avt

Переключить прокрутку окна
Загрузить этот исходный код

/*
    Реализация среды исполнения языка программирования
    Объектно-ориентированный продвинутый векторный транслятор

    Copyright © 2021, 2024 Малик Разработчик

    Это свободная программа: вы можете перераспространять ее и/или изменять
    ее на условиях Меньшей Стандартной общественной лицензии GNU в том виде,
    в каком она была опубликована Фондом свободного программного обеспечения;
    либо версии 3 лицензии, либо (по вашему выбору) любой более поздней версии.

    Эта программа распространяется в надежде, что она будет полезной,
    но БЕЗО ВСЯКИХ ГАРАНТИЙ; даже без неявной гарантии ТОВАРНОГО ВИДА
    или ПРИГОДНОСТИ ДЛЯ ОПРЕДЕЛЕННЫХ ЦЕЛЕЙ. Подробнее см. в Меньшей Стандартной
    общественной лицензии GNU.

    Вы должны были получить копию Меньшей Стандартной общественной лицензии GNU
    вместе с этой программой. Если это не так, см.
    <https://www.gnu.org/licenses/>.
*/

package avt.lang;

import avt.io.*;
import avt.io.charset.*;
import platform.dependent.*;

public final class System(Object)
{
    public static final DataInputStream in;
    public static final PrintStream out;
    public static final PrintStream err;

    public static {
        ProcessEnvironment env = Runtime.getInstance().currentProcessEnvironment;
        CharEncoder enc = getCharset(env.consoleOutputCharsetName).newEncoder();
        Charset input = getCharset(env.consoleInputCharsetName);
        in = new DataInputStream(env.standardInput, input);
        out = new PrintStream(env.standardOutput, enc);
        err = new PrintStream(env.standardError, enc);
    }

    public static void gc() { Runtime.getInstance().gc(); }

    public static void exit(int exitCode) { Runtime.getInstance().exit(exitCode); }

    public static void setEnv(String name, String value) {
        ProcessEnvironment env = Runtime.getInstance().currentProcessEnvironment;
        if(env instanceof ProcessEnvironmentVariables) ((ProcessEnvironmentVariables) env)[name] = value;
    }

    public static int currentOffsetInMillis() { return Runtime.getInstance().timeBase.currentOffsetInMillis(); }

    public static long currentTimeInMillis() { return Runtime.getInstance().timeBase.currentTimeInMillis(); }

    public static native long identityHashCode(Object instance);

    public static String[] getEnvVars() {
        ProcessEnvironment env = Runtime.getInstance().currentProcessEnvironment;
        return !(env instanceof ProcessEnvironmentVariables) ? null : ((ProcessEnvironmentVariables) env).getEnvironmentVariables();
    }

    public static String getEnv(String name) {
        ProcessEnvironment env = Runtime.getInstance().currentProcessEnvironment;
        return !(env instanceof ProcessEnvironmentVariables) ? null : ((ProcessEnvironmentVariables) env)[name];
    }

    public static String getEntryPointTypeCanonicalName() {
        Class callerType = Thread.callerTypeTrace();
        String callerPackName = callerType == null ? null : callerType.parentPackage.canonicalName;
        if(callerPackName == null || !callerPackName.equals("avtx.application"))
        {
            throw new SecurityException(package.getResourceString("security.caller"));
        }
        return Runtime.getInstance().entryPointTypeCanonicalName;
    }

    public static ProcessEnvironment getCurrentProcessEnv() {
        Class callerType = Thread.callerTypeTrace();
        String callerPackName = callerType == null ? null : callerType.parentPackage.canonicalName;
        if(callerType != Charset.class && (callerPackName == null || !callerPackName.equals("avtx.application")))
        {
            throw new SecurityException(package.getResourceString("security.caller"));
        }
        return Runtime.getInstance().currentProcessEnvironment;
    }

    private static Charset getCharset(String charsetName) {
        try
        {
            return Charset.get(charsetName);
        }
        catch(UnsupportedCharsetNameException exception)
        {
            return Charset.getDefault();
        }
    }

    private () {  }
}