jaroslav@1260: /** jaroslav@1260: * Back 2 Browser Bytecode Translator jaroslav@1260: * Copyright (C) 2012 Jaroslav Tulach jaroslav@1260: * jaroslav@1260: * This program is free software: you can redistribute it and/or modify jaroslav@1260: * it under the terms of the GNU General Public License as published by jaroslav@1260: * the Free Software Foundation, version 2 of the License. jaroslav@1260: * jaroslav@1260: * This program is distributed in the hope that it will be useful, jaroslav@1260: * but WITHOUT ANY WARRANTY; without even the implied warranty of jaroslav@1260: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the jaroslav@1260: * GNU General Public License for more details. jaroslav@1260: * jaroslav@1260: * You should have received a copy of the GNU General Public License jaroslav@1260: * along with this program. Look for COPYING file in the top folder. jaroslav@1260: * If not, see http://opensource.org/licenses/GPL-2.0. jaroslav@1260: */ jaroslav@1260: package java.lang; jaroslav@1260: jaroslav@1322: import java.io.ByteArrayInputStream; jaroslav@1322: import java.io.ByteArrayOutputStream; jaroslav@1322: import java.io.InputStream; jaroslav@1322: import java.io.PrintStream; jaroslav@1279: import org.apidesign.bck2brwsr.core.JavaScriptBody; jaroslav@1279: jaroslav@1260: /** Poor man's re-implementation of most important System methods. jaroslav@1260: * jaroslav@1260: * @author Jaroslav Tulach jaroslav@1260: */ jaroslav@1260: public class System { jaroslav@1260: private System() { jaroslav@1260: } jaroslav@1260: jaroslav@1260: public static void arraycopy(Object value, int srcBegin, Object dst, int dstBegin, int count) { jaroslav@1260: org.apidesign.bck2brwsr.emul.lang.System.arraycopy(value, srcBegin, dst, dstBegin, count); jaroslav@1260: } jaroslav@1260: jaroslav@1260: public static long currentTimeMillis() { jaroslav@1260: return org.apidesign.bck2brwsr.emul.lang.System.currentTimeMillis(); jaroslav@1260: } jaroslav@1260: jaroslav@1260: public static int identityHashCode(Object obj) { jaroslav@1260: return obj.defaultHashCode(); jaroslav@1260: } jaroslav@1260: jaroslav@1260: public static String getProperty(String name) { jaroslav@1328: if ("os.name".equals(name)) { jaroslav@1328: return userAgent(); jaroslav@1328: } jaroslav@1260: return null; jaroslav@1260: } jaroslav@1260: jaroslav@1328: @JavaScriptBody(args = {}, body = "return navigator.userAgent;") jaroslav@1328: private static native String userAgent(); jaroslav@1328: jaroslav@1260: public static String getProperty(String key, String def) { jaroslav@1260: return def; jaroslav@1260: } jaroslav@1260: jaroslav@1260: /** jaroslav@1260: * Returns the system-dependent line separator string. It always jaroslav@1260: * returns the same value - the initial value of the {@linkplain jaroslav@1260: * #getProperty(String) system property} {@code line.separator}. jaroslav@1260: * jaroslav@1260: *

On UNIX systems, it returns {@code "\n"}; on Microsoft jaroslav@1260: * Windows systems it returns {@code "\r\n"}. jaroslav@1260: */ jaroslav@1260: public static String lineSeparator() { jaroslav@1260: return "\n"; jaroslav@1260: } jaroslav@1279: jaroslav@1279: @JavaScriptBody(args = { "exitCode" }, body = "window.close();") jaroslav@1279: public static void exit(int exitCode) { jaroslav@1279: } jaroslav@1322: jaroslav@1322: public final static InputStream in; jaroslav@1322: jaroslav@1322: public final static PrintStream out; jaroslav@1322: jaroslav@1322: public final static PrintStream err; jaroslav@1322: jaroslav@1322: static { jaroslav@1322: in = new ByteArrayInputStream(new byte[0]); jaroslav@1322: out = err = new PrintStream(new ByteArrayOutputStream()); jaroslav@1322: } jaroslav@1322: jaroslav@1260: }