id
int32
0
12.9k
code
sequencelengths
2
264k
7,700
[ "<s>", "package", "simple", ";", "public", "interface", "Greeter", "{", "String", "hello", "(", ")", ";", "}", "</s>" ]
7,701
[ "<s>", "package", "erjang", ";", "import", "java", ".", "io", ".", "File", ";", "import", "erjang", ".", "m", ".", "erlang", ".", "ErlConvert", ";", "import", "junit", ".", "framework", ".", "TestCase", ";", "public", "abstract", "class", "AbstractErjangTestCase", "extends", "TestCase", "{", "protected", "File", "file", ";", "public", "AbstractErjangTestCase", "(", "File", "file", ")", "{", "super", "(", "file", ".", "getName", "(", ")", ")", ";", "this", ".", "file", "=", "file", ";", "}", "public", "AbstractErjangTestCase", "(", "String", "name", ")", "{", "super", "(", "name", ")", ";", "file", "=", "new", "File", "(", "name", ")", ";", "}", "public", "void", "setFile", "(", "File", "file", ")", "{", "this", ".", "file", "=", "file", ";", "this", ".", "setName", "(", "file", ".", "getName", "(", ")", ")", ";", "}", "protected", "EObject", "processOutput", "(", "byte", "[", "]", "bin", ")", "{", "int", "offset", "=", "0", ";", "int", "len", "=", "bin", ".", "length", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "len", "-", "6", ";", "i", "++", ")", "{", "if", "(", "bin", "[", "i", "+", "0", "]", "==", "'D'", "&&", "bin", "[", "i", "+", "1", "]", "==", "'A'", "&&", "bin", "[", "i", "+", "2", "]", "==", "'T'", "&&", "bin", "[", "i", "+", "3", "]", "==", "'A'", "&&", "bin", "[", "i", "+", "4", "]", "==", "':'", "&&", "bin", "[", "i", "+", "5", "]", "==", "':'", ")", "{", "offset", "=", "i", "+", "6", ";", "break", ";", "}", "}", "EBinary", "binOutput", "=", "new", "EBinary", "(", "bin", ",", "offset", ",", "len", "-", "offset", ")", ";", "try", "{", "return", "ErlConvert", ".", "binary_to_term", "(", "binOutput", ")", ";", "}", "catch", "(", "Throwable", "e", ")", "{", "System", ".", "err", ".", "println", "(", "\"\"", "+", "e", ")", ";", "System", ".", "err", ".", "println", "(", "\"Output", "is:", "\"", "+", "binOutput", ")", ";", "System", ".", "err", ".", "println", "(", "\"\"", "+", "new", "EBinary", "(", "bin", ")", "+", "\"\"", "+", "offset", ")", ";", "return", "null", ";", "}", "}", "}", "</s>" ]
7,702
[ "<s>", "package", "erjang", ";", "import", "java", ".", "io", ".", "File", ";", "import", "java", ".", "io", ".", "ByteArrayOutputStream", ";", "import", "java", ".", "io", ".", "InputStream", ";", "import", "java", ".", "io", ".", "IOException", ";", "import", "java", ".", "util", ".", "*", ";", "import", "erjang", ".", "m", ".", "erlang", ".", "ErlConvert", ";", "import", "junit", ".", "framework", ".", "TestResult", ";", "import", "junit", ".", "framework", ".", "Assert", ";", "import", "junit", ".", "framework", ".", "AssertionFailedError", ";", "public", "class", "OfflineComparisonTestCase", "extends", "AbstractTestCaseWithoutErlangNodeAccess", "{", "public", "OfflineComparisonTestCase", "(", "String", "name", ")", "{", "super", "(", "name", ")", ";", "}", "public", "OfflineComparisonTestCase", "(", "File", "file", ")", "{", "super", "(", "file", ")", ";", "}", "@", "Override", "public", "String", "toString", "(", ")", "{", "return", "\"\"", "+", "file", ".", "getName", "(", ")", ";", "}", "}", "</s>" ]
7,703
[ "<s>", "package", "erjang", ";", "import", "java", ".", "io", ".", "File", ";", "import", "junit", ".", "framework", ".", "TestResult", ";", "import", "erjang", ".", "beam", ".", "Compiler", ";", "public", "class", "TestCompileFile", "extends", "AbstractErjangTestCase", "{", "public", "TestCompileFile", "(", "String", "name", ")", "{", "super", "(", "name", ")", ";", "}", "@", "Override", "public", "String", "toString", "(", ")", "{", "return", "\"compiling", "\"", "+", "file", ".", "getName", "(", ")", ";", "}", "@", "Override", "public", "int", "countTestCases", "(", ")", "{", "return", "1", ";", "}", "@", "Override", "public", "void", "run", "(", "TestResult", "result", ")", "{", "result", ".", "startTest", "(", "this", ")", ";", "try", "{", "Compiler", ".", "main", "(", "new", "String", "[", "]", "{", "file", ".", "getAbsolutePath", "(", ")", "}", ")", ";", "}", "catch", "(", "Throwable", "e", ")", "{", "result", ".", "addError", "(", "this", ",", "e", ")", ";", "}", "result", ".", "endTest", "(", "this", ")", ";", "}", "}", "</s>" ]
7,704
[ "<s>", "package", "erjang", ";", "import", "java", ".", "io", ".", "File", ";", "public", "class", "PropertyTestCase", "extends", "AbstractTestCaseWithoutErlangNodeAccess", "{", "public", "PropertyTestCase", "(", "String", "name", ")", "{", "super", "(", "name", ")", ";", "}", "public", "PropertyTestCase", "(", "File", "file", ")", "{", "super", "(", "file", ")", ";", "}", "@", "Override", "public", "String", "toString", "(", ")", "{", "return", "\"\"", "+", "file", ".", "getName", "(", ")", "+", "\"\"", ";", "}", "}", "</s>" ]
7,705
[ "<s>", "package", "erjang", ";", "import", "java", ".", "util", ".", "Iterator", ";", "import", "java", ".", "util", ".", "NoSuchElementException", ";", "import", "junit", ".", "framework", ".", "TestCase", ";", "public", "class", "EObjectIteratorTest", "extends", "TestCase", "{", "public", "void", "testNil", "(", ")", "throws", "Exception", "{", "Iterator", "<", "EObject", ">", "it", "=", "new", "EObjectIterator", "(", "ERT", ".", "NIL", ")", ";", "assertNotNull", "(", "it", ")", ";", "assertFalse", "(", "it", ".", "hasNext", "(", ")", ")", ";", "}", "public", "void", "testNull", "(", ")", "throws", "Exception", "{", "Iterator", "<", "EObject", ">", "it", "=", "new", "EObjectIterator", "(", "null", ")", ";", "assertNotNull", "(", "it", ")", ";", "assertFalse", "(", "it", ".", "hasNext", "(", ")", ")", ";", "}", "public", "void", "testEString", "(", ")", "throws", "Exception", "{", "EString", "message", "=", "EString", ".", "fromString", "(", "\"\"", ")", ";", "Iterator", "<", "EObject", ">", "it", "=", "new", "EObjectIterator", "(", "message", ")", ";", "assertNotNull", "(", "it", ")", ";", "assertTrue", "(", "it", ".", "hasNext", "(", ")", ")", ";", "EObject", "o", "=", "it", ".", "next", "(", ")", ";", "assertNotNull", "(", "o", ")", ";", "assertEquals", "(", "message", ",", "o", ")", ";", "assertFalse", "(", "it", ".", "hasNext", "(", ")", ")", ";", "try", "{", "it", ".", "next", "(", ")", ";", "fail", "(", "\"\"", ")", ";", "}", "catch", "(", "NoSuchElementException", "t", ")", "{", "}", "}", "public", "void", "testEInt", "(", ")", "throws", "Exception", "{", "EInteger", "num", "=", "ESmall", ".", "make", "(", "42", ")", ";", "Iterator", "<", "EObject", ">", "it", "=", "new", "EObjectIterator", "(", "num", ")", ";", "assertNotNull", "(", "it", ")", ";", "assertTrue", "(", "it", ".", "hasNext", "(", ")", ")", ";", "EObject", "o", "=", "it", ".", "next", "(", ")", ";", "assertNotNull", "(", "o", ")", ";", "assertEquals", "(", "num", ",", "o", ")", ";", "assertFalse", "(", "it", ".", "hasNext", "(", ")", ")", ";", "try", "{", "it", ".", "next", "(", ")", ";", "fail", "(", "\"\"", ")", ";", "}", "catch", "(", "NoSuchElementException", "t", ")", "{", "}", "}", "public", "void", "testSeqWithSingleNil", "(", ")", "throws", "Exception", "{", "ESeq", "seq", "=", "ESeq", ".", "fromArray", "(", "new", "EObject", "[", "]", "{", "ERT", ".", "NIL", "}", ")", ";", "assertEquals", "(", "1", ",", "seq", ".", "length", "(", ")", ")", ";", "Iterator", "<", "EObject", ">", "it", "=", "seq", ".", "iterator", "(", ")", ";", "assertNotNull", "(", "it", ")", ";", "assertTrue", "(", "it", ".", "hasNext", "(", ")", ")", ";", "EObject", "o", "=", "it", ".", "next", "(", ")", ";", "assertNotNull", "(", "o", ")", ";", "assertTrue", "(", "o", ".", "isNil", "(", ")", ")", ";", "assertEquals", "(", "ERT", ".", "NIL", ",", "o", ")", ";", "assertFalse", "(", "it", ".", "hasNext", "(", ")", ")", ";", "try", "{", "it", ".", "next", "(", ")", ";", "fail", "(", "\"\"", ")", ";", "}", "catch", "(", "NoSuchElementException", "t", ")", "{", "}", "}", "public", "void", "testSeqWithTwoNils", "(", ")", "throws", "Exception", "{", "ESeq", "seq", "=", "ESeq", ".", "fromArray", "(", "new", "EObject", "[", "]", "{", "ERT", ".", "NIL", ",", "ERT", ".", "NIL", "}", ")", ";", "assertEquals", "(", "2", ",", "seq", ".", "length", "(", ")", ")", ";", "Iterator", "<", "EObject", ">", "it", "=", "seq", ".", "iterator", "(", ")", ";", "assertNotNull", "(", "it", ")", ";", "assertTrue", "(", "it", ".", "hasNext", "(", ")", ")", ";", "EObject", "o", "=", "it", ".", "next", "(", ")", ";", "assertNotNull", "(", "o", ")", ";", "assertTrue", "(", "o", ".", "isNil", "(", ")", ")", ";", "assertEquals", "(", "ERT", ".", "NIL", ",", "o", ")", ";", "assertTrue", "(", "it", ".", "hasNext", "(", ")", ")", ";", "o", "=", "it", ".", "next", "(", ")", ";", "assertNotNull", "(", "o", ")", ";", "assertTrue", "(", "o", ".", "isNil", "(", ")", ")", ";", "assertEquals", "(", "ERT", ".", "NIL", ",", "o", ")", ";", "assertFalse", "(", "it", ".", "hasNext", "(", ")", ")", ";", "try", "{", "it", ".", "next", "(", ")", ";", "fail", "(", "\"\"", ")", ";", "}", "catch", "(", "NoSuchElementException", "t", ")", "{", "}", "}", "public", "void", "testSeqWithSingleObject", "(", ")", "throws", "Exception", "{", "EObject", "first", "=", "EString", ".", "fromString", "(", "\"Hello\"", ")", ";", "ESeq", "seq", "=", "ESeq", ".", "fromArray", "(", "new", "EObject", "[", "]", "{", "first", "}", ")", ";", "assertEquals", "(", "1", ",", "seq", ".", "length", "(", ")", ")", ";", "Iterator", "<", "EObject", ">", "it", "=", "seq", ".", "iterator", "(", ")", ";", "assertNotNull", "(", "it", ")", ";", "assertTrue", "(", "it", ".", "hasNext", "(", ")", ")", ";", "EObject", "o", "=", "it", ".", "next", "(", ")", ";", "assertNotNull", "(", "o", ")", ";", "assertEquals", "(", "first", ",", "o", ")", ";", "assertFalse", "(", "it", ".", "hasNext", "(", ")", ")", ";", "try", "{", "it", ".", "next", "(", ")", ";", "fail", "(", "\"\"", ")", ";", "}", "catch", "(", "NoSuchElementException", "t", ")", "{", "}", "}", "public", "void", "testSeqWithTwoObjects", "(", ")", "throws", "Exception", "{", "EObject", "first", "=", "EString", ".", "fromString", "(", "\"Hello\"", ")", ";", "EObject", "second", "=", "EString", ".", "fromString", "(", "\"World\"", ")", ";", "ESeq", "seq", "=", "ESeq", ".", "fromArray", "(", "new", "EObject", "[", "]", "{", "first", ",", "second", "}", ")", ";", "assertEquals", "(", "2", ",", "seq", ".", "length", "(", ")", ")", ";", "Iterator", "<", "EObject", ">", "it", "=", "seq", ".", "iterator", "(", ")", ";", "assertNotNull", "(", "it", ")", ";", "assertTrue", "(", "it", ".", "hasNext", "(", ")", ")", ";", "EObject", "o", "=", "it", ".", "next", "(", ")", ";", "assertNotNull", "(", "o", ")", ";", "assertEquals", "(", "first", ",", "o", ")", ";", "assertTrue", "(", "it", ".", "hasNext", "(", ")", ")", ";", "o", "=", "it", ".", "next", "(", ")", ";", "assertNotNull", "(", "o", ")", ";", "assertEquals", "(", "second", ",", "o", ")", ";", "assertFalse", "(", "it", ".", "hasNext", "(", ")", ")", ";", "try", "{", "it", ".", "next", "(", ")", ";", "fail", "(", "\"\"", ")", ";", "}", "catch", "(", "NoSuchElementException", "t", ")", "{", "}", "}", "public", "void", "testSeqWithThreeObjects", "(", ")", "throws", "Exception", "{", "EObject", "first", "=", "EString", ".", "fromString", "(", "\"Hello\"", ")", ";", "EObject", "second", "=", "EString", ".", "fromString", "(", "\"World\"", ")", ";", "EObject", "third", "=", "ESmall", ".", "make", "(", "42", ")", ";", "ESeq", "seq", "=", "ESeq", ".", "fromArray", "(", "new", "EObject", "[", "]", "{", "first", ",", "second", ",", "third", "}", ")", ";", "assertEquals", "(", "3", ",", "seq", ".", "length", "(", ")", ")", ";", "Iterator", "<", "EObject", ">", "it", "=", "seq", ".", "iterator", "(", ")", ";", "assertNotNull", "(", "it", ")", ";", "assertTrue", "(", "it", ".", "hasNext", "(", ")", ")", ";", "EObject", "o", "=", "it", ".", "next", "(", ")", ";", "assertNotNull", "(", "o", ")", ";", "assertEquals", "(", "first", ",", "o", ")", ";", "assertTrue", "(", "it", ".", "hasNext", "(", ")", ")", ";", "o", "=", "it", ".", "next", "(", ")", ";", "assertNotNull", "(", "o", ")", ";", "assertEquals", "(", "second", ",", "o", ")", ";", "assertTrue", "(", "it", ".", "hasNext", "(", ")", ")", ";", "o", "=", "it", ".", "next", "(", ")", ";", "assertNotNull", "(", "o", ")", ";", "assertEquals", "(", "third", ",", "o", ")", ";", "assertFalse", "(", "it", ".", "hasNext", "(", ")", ")", ";", "try", "{", "it", ".", "next", "(", ")", ";", "fail", "(", "\"\"", ")", ";", "}", "catch", "(", "NoSuchElementException", "t", ")", "{", "}", "}", "}", "</s>" ]
7,706
[ "<s>", "package", "erjang", ";", "import", "java", ".", "io", ".", "ByteArrayOutputStream", ";", "import", "java", ".", "io", ".", "InputStream", ";", "import", "java", ".", "io", ".", "IOException", ";", "class", "OutputCollectorThread", "extends", "Thread", "{", "InputStream", "in", ";", "ByteArrayOutputStream", "acc", "=", "new", "ByteArrayOutputStream", "(", ")", ";", "byte", "[", "]", "buf", "=", "new", "byte", "[", "1024", "]", ";", "public", "OutputCollectorThread", "(", "InputStream", "in", ")", "{", "this", ".", "in", "=", "in", ";", "}", "@", "Override", "public", "void", "run", "(", ")", "{", "try", "{", "int", "len", ";", "while", "(", "(", "len", "=", "in", ".", "read", "(", "buf", ")", ")", ">", "0", ")", "{", "acc", ".", "write", "(", "buf", ",", "0", ",", "len", ")", ";", "}", "}", "catch", "(", "IOException", "ioe", ")", "{", "System", ".", "err", ".", "println", "(", "\"I/O", "error:", "\"", "+", "ioe", ")", ";", "try", "{", "in", ".", "close", "(", ")", ";", "}", "catch", "(", "IOException", "ioe2", ")", "{", "}", "}", "}", "public", "byte", "[", "]", "getResult", "(", ")", "{", "return", "acc", ".", "toByteArray", "(", ")", ";", "}", "}", "</s>" ]
7,707
[ "<s>", "package", "erjang", ";", "import", "java", ".", "io", ".", "File", ";", "import", "java", ".", "io", ".", "ByteArrayOutputStream", ";", "import", "java", ".", "io", ".", "InputStream", ";", "import", "java", ".", "io", ".", "IOException", ";", "import", "java", ".", "util", ".", "*", ";", "import", "erjang", ".", "m", ".", "erlang", ".", "ErlConvert", ";", "import", "junit", ".", "framework", ".", "TestResult", ";", "import", "junit", ".", "framework", ".", "Assert", ";", "import", "junit", ".", "framework", ".", "AssertionFailedError", ";", "public", "class", "TestCaseWithErlangNodeAccess", "extends", "AbstractErjangTestCase", "{", "static", "final", "String", "RUN_WRAPPER_HOME", "=", "\"src/test/erl\"", ";", "static", "final", "String", "ERL_NODE_NAME", "=", "\"\"", ";", "static", "final", "String", "THIS_NODE_NAME", "=", "\"\"", ";", "static", "final", "EObject", "POSITIVE_RESULT", "=", "ETuple", ".", "make", "(", "EAtom", ".", "intern", "(", "\"run_result\"", ")", ",", "EAtom", ".", "intern", "(", "\"true\"", ")", ")", ";", "public", "TestCaseWithErlangNodeAccess", "(", "String", "name", ")", "{", "super", "(", "name", ")", ";", "}", "@", "Override", "public", "String", "toString", "(", ")", "{", "return", "\"\"", "+", "file", ".", "getName", "(", ")", "+", "\"\"", ";", "}", "@", "Override", "public", "int", "countTestCases", "(", ")", "{", "return", "1", ";", "}", "@", "Override", "public", "void", "run", "(", "TestResult", "result", ")", "{", "result", ".", "startTest", "(", "this", ")", ";", "String", "rawOutput", "=", "null", ";", "try", "{", "String", "hostName", "=", "java", ".", "net", ".", "InetAddress", ".", "getLocalHost", "(", ")", ".", "getCanonicalHostName", "(", ")", ";", "TestUtil", ".", "erl_compile", "(", "RUN_WRAPPER_HOME", "+", "File", ".", "separator", "+", "\"\"", ")", ";", "TestUtil", ".", "erl_compile", "(", "file", ".", "getAbsolutePath", "(", ")", ")", ";", "Process", "erl_process", "=", "TestUtil", ".", "startErlProcess", "(", "ERL_NODE_NAME", ",", "hostName", ")", ";", "String", "[", "]", "rawOutputArray", "=", "new", "String", "[", "1", "]", ";", "EObject", "output", "=", "do_run", "(", "file", ",", "TestUtil", ".", "get_ej", "(", ")", ",", "ERL_NODE_NAME", ",", "hostName", ",", "rawOutputArray", ")", ";", "rawOutput", "=", "rawOutputArray", "[", "0", "]", ";", "TestUtil", ".", "stopProcess", "(", "erl_process", ")", ";", "Assert", ".", "assertEquals", "(", "POSITIVE_RESULT", ",", "output", ")", ";", "}", "catch", "(", "AssertionFailedError", "e", ")", "{", "if", "(", "rawOutput", "!=", "null", ")", "System", ".", "err", ".", "println", "(", "rawOutput", ")", ";", "result", ".", "addFailure", "(", "this", ",", "e", ")", ";", "}", "catch", "(", "Throwable", "e", ")", "{", "result", ".", "addError", "(", "this", ",", "e", ")", ";", "}", "result", ".", "endTest", "(", "this", ")", ";", "}", "private", "EObject", "do_run", "(", "File", "file", ",", "String", "prog", ",", "String", "erlNodeName", ",", "String", "hostName", ",", "String", "[", "]", "outputDest", ")", "throws", "Exception", "{", "String", "moduleName", "=", "TestUtil", ".", "trimExtension", "(", "file", ".", "getName", "(", ")", ")", ";", "String", "[", "]", "cmd", "=", "new", "String", "[", "]", "{", "prog", ",", "\"-noinput\"", ",", "TestUtil", ".", "nodeNameSwitch", "(", "hostName", ")", ",", "THIS_NODE_NAME", "+", "\"@\"", "+", "hostName", ",", "\"-other\"", ",", "erlNodeName", ",", "\"-pa\"", ",", "TestUtil", ".", "TEST_BEAM_DIR", ",", "\"-pa\"", ",", "TestUtil", ".", "TRIQ_HOME", "+", "File", ".", "separator", "+", "\"ebin\"", ",", "\"-sasl\"", ",", "\"\"", ",", "\"false\"", ",", "\"-s\"", ",", "\"run_wrapper\"", ",", "\"run\"", ",", "\"erlang\"", ",", "moduleName", ",", "\"300\"", ",", "\"-s\"", ",", "\"erlang\"", ",", "\"halt\"", "}", ";", "byte", "[", "]", "bin", "=", "TestUtil", ".", "execGetBinaryOutput", "(", "cmd", ")", ";", "outputDest", "[", "0", "]", "=", "EString", ".", "make", "(", "bin", ",", "0", ",", "bin", ".", "length", ")", ".", "stringValue", "(", ")", ";", "return", "processOutput", "(", "bin", ")", ";", "}", "}", "</s>" ]
7,708
[ "<s>", "package", "erjang", ";", "import", "java", ".", "io", ".", "File", ";", "import", "java", ".", "io", ".", "IOException", ";", "import", "java", ".", "util", ".", "Arrays", ";", "public", "abstract", "class", "TestUtil", "{", "static", "final", "String", "OTP_HOME", "=", "ErjangConfig", ".", "getString", "(", "\"\"", ")", ";", "static", "final", "String", "ERTS_VSN", "=", "ErjangConfig", ".", "getString", "(", "\"\"", ")", ";", "static", "final", "String", "ERLC_PRG", "=", "OTP_HOME", "+", "File", ".", "separator", "+", "\"bin\"", "+", "File", ".", "separator", "+", "\"erlc\"", ";", "static", "final", "String", "ERL_PRG", "=", "OTP_HOME", "+", "File", ".", "separator", "+", "\"bin\"", "+", "File", ".", "separator", "+", "\"erl\"", ";", "static", "final", "String", "EJ_PRG", "=", "\"./ej\"", ";", "static", "final", "String", "TEST_BEAM_DIR", "=", "\"\"", ";", "static", "final", "String", "TRIQ_HOME", "=", "ErjangConfig", ".", "getString", "(", "\"\"", ")", ";", "public", "static", "String", "get_ej", "(", ")", "{", "String", "ej", "=", "EJ_PRG", ";", "if", "(", "System", ".", "getProperty", "(", "\"os.name\"", ")", ".", "startsWith", "(", "\"Windows\"", ")", ")", "{", "ej", "=", "\"ej.bat\"", ";", "}", "return", "ej", ";", "}", "public", "static", "void", "erl_compile", "(", "String", "fileName", ")", "throws", "Exception", "{", "execGetOutput", "(", "new", "String", "[", "]", "{", "ERLC_PRG", ",", "\"-o\"", ",", "TEST_BEAM_DIR", ",", "\"-pa\"", ",", "TRIQ_HOME", "+", "File", ".", "separator", "+", "\"ebin\"", ",", "\"-I\"", ",", "TRIQ_HOME", "+", "File", ".", "separator", "+", "\"include\"", ",", "fileName", "}", ")", ";", "}", "public", "static", "String", "execGetOutput", "(", "String", "[", "]", "cmd", ")", "throws", "Exception", "{", "byte", "[", "]", "output", "=", "execGetBinaryOutput", "(", "cmd", ")", ";", "return", "output", ".", "toString", "(", ")", ";", "}", "public", "static", "byte", "[", "]", "execGetBinaryOutput", "(", "String", "[", "]", "cmd", ")", "throws", "Exception", "{", "Runtime", "rt", "=", "Runtime", ".", "getRuntime", "(", ")", ";", "Process", "p", "=", "rt", ".", "exec", "(", "cmd", ")", ";", "OutputCollectorThread", "outThread", "=", "new", "OutputCollectorThread", "(", "p", ".", "getInputStream", "(", ")", ")", ";", "OutputCollectorThread", "errThread", "=", "new", "OutputCollectorThread", "(", "p", ".", "getErrorStream", "(", ")", ")", ";", "outThread", ".", "start", "(", ")", ";", "errThread", ".", "start", "(", ")", ";", "outThread", ".", "join", "(", ")", ";", "errThread", ".", "join", "(", ")", ";", "int", "exitCode", "=", "p", ".", "waitFor", "(", ")", ";", "if", "(", "exitCode", "!=", "0", ")", "{", "System", ".", "err", ".", "println", "(", "\"Exitcode=\"", "+", "exitCode", "+", "\"", "for", "\"", "+", "cmd", "[", "0", "]", ")", ";", "System", ".", "err", ".", "println", "(", "\"Err//output=\"", "+", "new", "String", "(", "errThread", ".", "getResult", "(", ")", ")", "+", "\"//\"", "+", "new", "String", "(", "outThread", ".", "getResult", "(", ")", ")", ")", ";", "}", "assert", "(", "exitCode", "==", "0", ")", ";", "return", "Arrays", ".", "copyOf", "(", "outThread", ".", "getResult", "(", ")", ",", "outThread", ".", "getResult", "(", ")", ".", "length", ")", ";", "}", "public", "static", "String", "trimExtension", "(", "String", "fileName", ")", "{", "int", "i", "=", "fileName", ".", "lastIndexOf", "(", "'.'", ")", ";", "if", "(", "i", ">=", "0", ")", "fileName", "=", "fileName", ".", "substring", "(", "0", ",", "i", ")", ";", "return", "fileName", ";", "}", "public", "static", "Process", "startErlProcess", "(", "String", "nodeName", ",", "String", "hostName", ")", "throws", "IOException", "{", "String", "[", "]", "cmd", "=", "new", "String", "[", "]", "{", "ERL_PRG", ",", "\"-noinput\"", ",", "nodeNameSwitch", "(", "hostName", ")", ",", "nodeName", "+", "\"@\"", "+", "hostName", ",", "\"-pa\"", ",", "TestUtil", ".", "TEST_BEAM_DIR", ",", "\"-pa\"", ",", "TRIQ_HOME", "+", "File", ".", "separator", "+", "\"ebin\"", ",", "\"-sasl\"", ",", "\"\"", ",", "\"false\"", ",", "\"-noinput\"", "}", ";", "Runtime", "rt", "=", "Runtime", ".", "getRuntime", "(", ")", ";", "Process", "p", "=", "rt", ".", "exec", "(", "cmd", ")", ";", "return", "p", ";", "}", "public", "static", "void", "stopProcess", "(", "Process", "p", ")", "{", "p", ".", "destroy", "(", ")", ";", "}", "public", "static", "String", "nodeNameSwitch", "(", "String", "hostName", ")", "{", "return", "(", "hostName", ".", "indexOf", "(", "'.'", ")", ">=", "0", ")", "?", "\"-name\"", ":", "\"-sname\"", ";", "}", "}", "</s>" ]
7,709
[ "<s>", "package", "erjang", ";", "import", "junit", ".", "framework", ".", "Assert", ";", "import", "junit", ".", "framework", ".", "AssertionFailedError", ";", "import", "junit", ".", "framework", ".", "TestResult", ";", "import", "java", ".", "io", ".", "File", ";", "public", "abstract", "class", "AbstractTestCaseWithoutErlangNodeAccess", "extends", "AbstractErjangTestCase", "{", "static", "final", "String", "RUN_WRAPPER_HOME", "=", "\"src/test/erl\"", ";", "public", "AbstractTestCaseWithoutErlangNodeAccess", "(", "String", "name", ")", "{", "super", "(", "name", ")", ";", "}", "public", "AbstractTestCaseWithoutErlangNodeAccess", "(", "File", "file", ")", "{", "super", "(", "file", ")", ";", "}", "@", "Override", "public", "abstract", "String", "toString", "(", ")", ";", "@", "Override", "public", "int", "countTestCases", "(", ")", "{", "return", "1", ";", "}", "@", "Override", "public", "void", "run", "(", "TestResult", "result", ")", "{", "result", ".", "startTest", "(", "this", ")", ";", "try", "{", "TestUtil", ".", "erl_compile", "(", "RUN_WRAPPER_HOME", "+", "File", ".", "separator", "+", "\"\"", ")", ";", "TestUtil", ".", "erl_compile", "(", "file", ".", "getAbsolutePath", "(", ")", ")", ";", "EObject", "expected", "=", "do_run", "(", "file", ",", "TestUtil", ".", "ERL_PRG", ")", ";", "EObject", "actual", "=", "do_run", "(", "file", ",", "TestUtil", ".", "get_ej", "(", ")", ")", ";", "Assert", ".", "assertEquals", "(", "expected", ",", "actual", ")", ";", "}", "catch", "(", "AssertionFailedError", "e", ")", "{", "result", ".", "addFailure", "(", "this", ",", "e", ")", ";", "}", "catch", "(", "Throwable", "e", ")", "{", "result", ".", "addError", "(", "this", ",", "e", ")", ";", "}", "result", ".", "endTest", "(", "this", ")", ";", "}", "protected", "EObject", "do_run", "(", "File", "file", ",", "String", "prog", ")", "throws", "Exception", "{", "String", "moduleName", "=", "TestUtil", ".", "trimExtension", "(", "file", ".", "getName", "(", ")", ")", ";", "String", "[", "]", "cmd", "=", "new", "String", "[", "]", "{", "prog", ",", "\"-noinput\"", ",", "\"-pa\"", ",", "TestUtil", ".", "TEST_BEAM_DIR", ",", "\"-sasl\"", ",", "\"\"", ",", "\"false\"", ",", "\"-s\"", ",", "\"run_wrapper\"", ",", "\"run\"", ",", "\"erlang\"", ",", "moduleName", ",", "\"10\"", ",", "\"-s\"", ",", "\"erlang\"", ",", "\"halt\"", "}", ";", "byte", "[", "]", "bin", "=", "TestUtil", ".", "execGetBinaryOutput", "(", "cmd", ")", ";", "return", "processOutput", "(", "bin", ")", ";", "}", "}", "</s>" ]
7,710
[ "<s>", "package", "erjang", ";", "import", "java", ".", "math", ".", "BigInteger", ";", "import", "junit", ".", "framework", ".", "TestCase", ";", "public", "class", "ENTest", "extends", "TestCase", "{", "public", "void", "testAdd", "(", ")", "{", "tryAdd", "(", "1", ",", "1", ")", ";", "tryAdd", "(", "Integer", ".", "MIN_VALUE", ",", "0", ")", ";", "tryAdd", "(", "Integer", ".", "MIN_VALUE", ",", "-", "1", ")", ";", "tryAdd", "(", "Integer", ".", "MIN_VALUE", ",", "Integer", ".", "MIN_VALUE", ")", ";", "tryAdd", "(", "Integer", ".", "MAX_VALUE", ",", "Integer", ".", "MAX_VALUE", ")", ";", "tryAdd", "(", "Integer", ".", "MAX_VALUE", ",", "0", ")", ";", "tryAdd", "(", "Integer", ".", "MAX_VALUE", ",", "-", "1", ")", ";", "tryAdd", "(", "Integer", ".", "MAX_VALUE", ",", "1", ")", ";", "}", "public", "void", "testMult", "(", ")", "{", "tryMult", "(", "1", ",", "1", ")", ";", "tryMult", "(", "Integer", ".", "MIN_VALUE", ",", "0", ")", ";", "tryMult", "(", "Integer", ".", "MIN_VALUE", ",", "-", "1", ")", ";", "tryMult", "(", "Integer", ".", "MIN_VALUE", ",", "Integer", ".", "MIN_VALUE", ")", ";", "tryMult", "(", "Integer", ".", "MAX_VALUE", ",", "Integer", ".", "MAX_VALUE", ")", ";", "tryMult", "(", "Integer", ".", "MAX_VALUE", ",", "0", ")", ";", "tryMult", "(", "Integer", ".", "MAX_VALUE", ",", "-", "1", ")", ";", "tryMult", "(", "Integer", ".", "MAX_VALUE", ",", "1", ")", ";", "}", "void", "tryAdd", "(", "int", "i1", ",", "int", "i2", ")", "{", "assertEquals", "(", "slow_add", "(", "i1", ",", "i2", ")", ",", "EN", ".", "add", "(", "i1", ",", "i2", ")", ")", ";", "}", "void", "tryMult", "(", "int", "i1", ",", "int", "i2", ")", "{", "assertEquals", "(", "slow_mul", "(", "i1", ",", "i2", ")", ",", "EN", ".", "mult", "(", "i1", ",", "i2", ")", ")", ";", "}", "ENumber", "slow_add", "(", "int", "i1", ",", "int", "i2", ")", "{", "long", "l", "=", "(", "long", ")", "i1", "+", "(", "long", ")", "i2", ";", "if", "(", "l", ">=", "Integer", ".", "MIN_VALUE", "&&", "l", "<=", "Integer", ".", "MAX_VALUE", ")", "return", "new", "ESmall", "(", "(", "int", ")", "l", ")", ";", "else", "return", "new", "EBig", "(", "l", ")", ";", "}", "static", "BigInteger", "INT_MIN", "=", "BigInteger", ".", "valueOf", "(", "Integer", ".", "MIN_VALUE", ")", ";", "static", "BigInteger", "INT_MAX", "=", "BigInteger", ".", "valueOf", "(", "Integer", ".", "MAX_VALUE", ")", ";", "ENumber", "slow_mul", "(", "int", "i1", ",", "int", "i2", ")", "{", "BigInteger", "b1", "=", "BigInteger", ".", "valueOf", "(", "i1", ")", ";", "BigInteger", "b2", "=", "BigInteger", ".", "valueOf", "(", "i2", ")", ";", "BigInteger", "res", "=", "b1", ".", "multiply", "(", "b2", ")", ";", "if", "(", "res", ".", "compareTo", "(", "INT_MIN", ")", "<", "0", ")", "return", "new", "EBig", "(", "res", ")", ";", "if", "(", "res", ".", "compareTo", "(", "INT_MAX", ")", ">", "0", ")", "return", "new", "EBig", "(", "res", ")", ";", "assertEquals", "(", "res", ",", "BigInteger", ".", "valueOf", "(", "res", ".", "intValue", "(", ")", ")", ")", ";", "return", "new", "ESmall", "(", "res", ".", "intValue", "(", ")", ")", ";", "}", "}", "</s>" ]
7,711
[ "<s>", "package", "erjang", ";", "import", "java", ".", "io", ".", "File", ";", "import", "java", ".", "io", ".", "FileOutputStream", ";", "import", "java", ".", "util", ".", "ArrayList", ";", "import", "java", ".", "util", ".", "HashMap", ";", "import", "java", ".", "util", ".", "List", ";", "import", "java", ".", "util", ".", "Map", ";", "import", "junit", ".", "framework", ".", "Test", ";", "import", "junit", ".", "framework", ".", "TestSuite", ";", "public", "class", "AllTests", "{", "static", "final", "String", "OTP_HOME", "=", "ErjangConfig", ".", "getString", "(", "\"\"", ")", ";", "public", "static", "Test", "suite", "(", ")", "{", "TestSuite", "suite", "=", "new", "TestSuite", "(", "\"\"", ")", ";", "TestSuite", "otpCompileSuite", "=", "new", "TestSuite", "(", "\"\"", ")", ";", "suite", ".", "addTest", "(", "otpCompileSuite", ")", ";", "TestSuite", "coverageRunSuite", "=", "new", "TestSuite", "(", "\"\"", ")", ";", "Map", "<", "File", ",", "List", "<", "File", ">", ">", "testsErl", "=", "new", "HashMap", "<", "File", ",", "List", "<", "File", ">", ">", "(", ")", ";", "find_files", "(", "testsErl", ",", "new", "File", "(", "\"\"", ")", ",", "\".erl\"", ")", ";", "buildTestHierarchy", "(", "testsErl", ",", "coverageRunSuite", ",", "OfflineComparisonTestCase", ".", "class", ")", ";", "suite", ".", "addTest", "(", "coverageRunSuite", ")", ";", "return", "suite", ";", "}", "protected", "static", "void", "buildTestHierarchy", "(", "Map", "<", "File", ",", "List", "<", "File", ">", ">", "tests", ",", "TestSuite", "suite", ",", "Class", "<", "?", "extends", "AbstractErjangTestCase", ">", "clazz", ")", "{", "TestSuite", "ts", "=", "null", ";", "for", "(", "File", "key", ":", "tests", ".", "keySet", "(", ")", ")", "{", "ts", "=", "new", "TestSuite", "(", "key", ".", "getPath", "(", ")", ")", ";", "suite", ".", "addTest", "(", "ts", ")", ";", "for", "(", "File", "sub", ":", "tests", ".", "get", "(", "key", ")", ")", "{", "try", "{", "AbstractErjangTestCase", "tc", "=", "clazz", ".", "newInstance", "(", ")", ";", "tc", ".", "setFile", "(", "sub", ")", ";", "ts", ".", "addTest", "(", "tc", ")", ";", "}", "catch", "(", "Exception", "e", ")", "{", "throw", "new", "IllegalArgumentException", "(", "\"\"", "+", "clazz", ")", ";", "}", "}", "}", "}", "static", "void", "find_files", "(", "Map", "<", "File", ",", "List", "<", "File", ">", ">", "tests", ",", "File", "dir", ",", "String", "ext", ")", "{", "List", "<", "File", ">", "ts", "=", "null", ";", "if", "(", "!", "dir", ".", "isDirectory", "(", ")", ")", "throw", "new", "IllegalArgumentException", "(", "\"\"", "+", "dir", ")", ";", "for", "(", "File", "file", ":", "dir", ".", "listFiles", "(", ")", ")", "{", "if", "(", "file", ".", "isDirectory", "(", ")", ")", "{", "find_files", "(", "tests", ",", "file", ",", "ext", ")", ";", "}", "else", "if", "(", "file", ".", "getName", "(", ")", ".", "endsWith", "(", "ext", ")", ")", "{", "if", "(", "ts", "==", "null", ")", "{", "System", ".", "err", ".", "println", "(", "\"added..", "\"", "+", "dir", ")", ";", "ts", "=", "new", "ArrayList", "<", "File", ">", "(", ")", ";", "tests", ".", "put", "(", "dir", ",", "ts", ")", ";", "}", "ts", ".", "add", "(", "file", ")", ";", "}", "}", "}", "public", "static", "void", "main", "(", "String", "[", "]", "args", ")", "{", "if", "(", "args", ".", "length", "==", "0", ")", "{", "throw", "new", "IllegalArgumentException", "(", "\"\"", ")", ";", "}", "Map", "<", "File", ",", "List", "<", "File", ">", ">", "testsOTP", "=", "new", "HashMap", "<", "File", ",", "List", "<", "File", ">", ">", "(", ")", ";", "find_files", "(", "testsOTP", ",", "new", "File", "(", "OTP_HOME", ")", ",", "\".beam\"", ")", ";", "generateTestClasses", "(", "args", "[", "0", "]", ",", "testsOTP", ",", "TestCompileFile", ".", "class", ")", ";", "Map", "<", "File", ",", "List", "<", "File", ">", ">", "testsDet", "=", "new", "HashMap", "<", "File", ",", "List", "<", "File", ">", ">", "(", ")", ";", "find_files", "(", "testsDet", ",", "new", "File", "(", "\"\"", ")", ",", "\".erl\"", ")", ";", "generateTestClasses", "(", "args", "[", "0", "]", ",", "testsDet", ",", "OfflineComparisonTestCase", ".", "class", ")", ";", "Map", "<", "File", ",", "List", "<", "File", ">", ">", "testsProp", "=", "new", "HashMap", "<", "File", ",", "List", "<", "File", ">", ">", "(", ")", ";", "find_files", "(", "testsProp", ",", "new", "File", "(", "\"\"", ")", ",", "\".erl\"", ")", ";", "generateTestClasses", "(", "args", "[", "0", "]", ",", "testsProp", ",", "PropertyTestCase", ".", "class", ")", ";", "Map", "<", "File", ",", "List", "<", "File", ">", ">", "testsPropNode", "=", "new", "HashMap", "<", "File", ",", "List", "<", "File", ">", ">", "(", ")", ";", "find_files", "(", "testsPropNode", ",", "new", "File", "(", "\"\"", ")", ",", "\".erl\"", ")", ";", "generateTestClasses", "(", "args", "[", "0", "]", ",", "testsPropNode", ",", "TestCaseWithErlangNodeAccess", ".", "class", ")", ";", "}", "protected", "static", "void", "generateTestClasses", "(", "String", "path", ",", "Map", "<", "File", ",", "List", "<", "File", ">", ">", "tests", ",", "Class", "<", "?", "extends", "AbstractErjangTestCase", ">", "clazz", ")", "{", "for", "(", "File", "key", ":", "tests", ".", "keySet", "(", ")", ")", "{", "for", "(", "File", "sub", ":", "tests", ".", "get", "(", "key", ")", ")", "{", "String", "name", "=", "TestClassGenerator", ".", "classNameFor", "(", "sub", ")", ";", "String", "content", "=", "TestClassGenerator", ".", "generateClassSource", "(", "clazz", ",", "sub", ")", ";", "try", "{", "File", "file", "=", "new", "File", "(", "path", "+", "File", ".", "separator", "+", "name", "+", "\".java\"", ")", ";", "System", ".", "out", ".", "println", "(", "\"\"", "+", "file", ".", "getName", "(", ")", ")", ";", "file", ".", "createNewFile", "(", ")", ";", "FileOutputStream", "fop", "=", "new", "FileOutputStream", "(", "file", ")", ";", "fop", ".", "write", "(", "content", ".", "getBytes", "(", ")", ")", ";", "fop", ".", "flush", "(", ")", ";", "fop", ".", "close", "(", ")", ";", "}", "catch", "(", "Exception", "e", ")", "{", "throw", "new", "IllegalStateException", "(", "e", ")", ";", "}", "}", "}", "}", "}", "</s>" ]
7,712
[ "<s>", "package", "erjang", ";", "import", "java", ".", "io", ".", "File", ";", "public", "abstract", "class", "TestClassGenerator", "{", "protected", "static", "String", "generateClassSource", "(", "Class", "<", "?", "extends", "AbstractErjangTestCase", ">", "clazz", ",", "File", "file", ")", "{", "StringBuffer", "s", "=", "new", "StringBuffer", "(", ")", ";", "String", "name", "=", "classNameFor", "(", "file", ")", ";", "String", "path", "=", "getPath", "(", "file", ")", ";", "s", ".", "append", "(", "getPackage", "(", ")", ")", ";", "s", ".", "append", "(", "getImports", "(", ")", ")", ";", "s", ".", "append", "(", "getClassStart", "(", "clazz", ",", "name", ")", ")", ";", "s", ".", "append", "(", "getConstructor", "(", "name", ",", "path", ")", ")", ";", "s", ".", "append", "(", "getSuite", "(", "name", ")", ")", ";", "s", ".", "append", "(", "getClassEnd", "(", ")", ")", ";", "return", "s", ".", "toString", "(", ")", ";", "}", "protected", "static", "String", "getPackage", "(", ")", "{", "return", "\"\"", ";", "}", "protected", "static", "String", "getImports", "(", ")", "{", "StringBuffer", "s", "=", "new", "StringBuffer", "(", ")", ";", "s", ".", "append", "(", "\"\"", ")", ";", "s", ".", "append", "(", "\"\"", ")", ";", "return", "s", ".", "toString", "(", ")", ";", "}", "public", "static", "String", "classNameFor", "(", "File", "file", ")", "{", "String", "name", "=", "file", ".", "getName", "(", ")", ";", "name", "=", "name", ".", "replace", "(", "'.'", ",", "'_'", ")", ";", "name", "=", "name", ".", "replace", "(", "'-'", ",", "'_'", ")", ";", "return", "name", "+", "\"_TEST\"", ";", "}", "protected", "static", "String", "getPath", "(", "File", "file", ")", "{", "String", "path", "=", "file", ".", "getAbsolutePath", "(", ")", ";", "path", "=", "path", ".", "replace", "(", "\"\\\\\"", ",", "\"\\\\\\\\\"", ")", ";", "return", "path", ";", "}", "protected", "static", "String", "getClassStart", "(", "Class", "<", "?", "extends", "AbstractErjangTestCase", ">", "clazz", ",", "String", "name", ")", "{", "return", "\"\"", "+", "name", "+", "\"", "extends", "\"", "+", "clazz", ".", "getName", "(", ")", "+", "\"", "{nn\"", ";", "}", "protected", "static", "String", "getConstructor", "(", "String", "name", ",", "String", "path", ")", "{", "StringBuffer", "s", "=", "new", "StringBuffer", "(", ")", ";", "s", ".", "append", "(", "\"tpublic", "\"", "+", "name", "+", "\"()", "{n\"", ")", ";", "s", ".", "append", "(", "\"ttsuper(\\\"\"", "+", "path", "+", "\"\\\");n\"", ")", ";", "s", ".", "append", "(", "\"t}nn\"", ")", ";", "return", "s", ".", "toString", "(", ")", ";", "}", "protected", "static", "String", "getSuite", "(", "String", "name", ")", "{", "StringBuffer", "s", "=", "new", "StringBuffer", "(", ")", ";", "s", ".", "append", "(", "\"\"", ")", ";", "s", ".", "append", "(", "\"\"", "+", "name", "+", "\"();n\"", ")", ";", "s", ".", "append", "(", "\"t}n\"", ")", ";", "return", "s", ".", "toString", "(", ")", ";", "}", "protected", "static", "String", "getClassEnd", "(", ")", "{", "return", "\"}\"", ";", "}", "}", "</s>" ]
7,713
[ "<s>", "package", "com", ".", "jcraft", ".", "jzlib", ";", "final", "class", "Adler32", "{", "static", "final", "private", "int", "BASE", "=", "65521", ";", "static", "final", "private", "int", "NMAX", "=", "5552", ";", "long", "adler32", "(", "long", "adler", ",", "byte", "[", "]", "buf", ",", "int", "index", ",", "int", "len", ")", "{", "if", "(", "buf", "==", "null", ")", "{", "return", "1L", ";", "}", "long", "s1", "=", "adler", "&", "0xffff", ";", "long", "s2", "=", "(", "adler", ">>", "16", ")", "&", "0xffff", ";", "int", "k", ";", "while", "(", "len", ">", "0", ")", "{", "k", "=", "len", "<", "NMAX", "?", "len", ":", "NMAX", ";", "len", "-=", "k", ";", "while", "(", "k", ">=", "16", ")", "{", "s1", "+=", "buf", "[", "index", "++", "]", "&", "0xff", ";", "s2", "+=", "s1", ";", "s1", "+=", "buf", "[", "index", "++", "]", "&", "0xff", ";", "s2", "+=", "s1", ";", "s1", "+=", "buf", "[", "index", "++", "]", "&", "0xff", ";", "s2", "+=", "s1", ";", "s1", "+=", "buf", "[", "index", "++", "]", "&", "0xff", ";", "s2", "+=", "s1", ";", "s1", "+=", "buf", "[", "index", "++", "]", "&", "0xff", ";", "s2", "+=", "s1", ";", "s1", "+=", "buf", "[", "index", "++", "]", "&", "0xff", ";", "s2", "+=", "s1", ";", "s1", "+=", "buf", "[", "index", "++", "]", "&", "0xff", ";", "s2", "+=", "s1", ";", "s1", "+=", "buf", "[", "index", "++", "]", "&", "0xff", ";", "s2", "+=", "s1", ";", "s1", "+=", "buf", "[", "index", "++", "]", "&", "0xff", ";", "s2", "+=", "s1", ";", "s1", "+=", "buf", "[", "index", "++", "]", "&", "0xff", ";", "s2", "+=", "s1", ";", "s1", "+=", "buf", "[", "index", "++", "]", "&", "0xff", ";", "s2", "+=", "s1", ";", "s1", "+=", "buf", "[", "index", "++", "]", "&", "0xff", ";", "s2", "+=", "s1", ";", "s1", "+=", "buf", "[", "index", "++", "]", "&", "0xff", ";", "s2", "+=", "s1", ";", "s1", "+=", "buf", "[", "index", "++", "]", "&", "0xff", ";", "s2", "+=", "s1", ";", "s1", "+=", "buf", "[", "index", "++", "]", "&", "0xff", ";", "s2", "+=", "s1", ";", "s1", "+=", "buf", "[", "index", "++", "]", "&", "0xff", ";", "s2", "+=", "s1", ";", "k", "-=", "16", ";", "}", "if", "(", "k", "!=", "0", ")", "{", "do", "{", "s1", "+=", "buf", "[", "index", "++", "]", "&", "0xff", ";", "s2", "+=", "s1", ";", "}", "while", "(", "--", "k", "!=", "0", ")", ";", "}", "s1", "%=", "BASE", ";", "s2", "%=", "BASE", ";", "}", "return", "(", "s2", "<<", "16", ")", "|", "s1", ";", "}", "}", "</s>" ]
7,714
[ "<s>", "package", "com", ".", "jcraft", ".", "jzlib", ";", "public", "final", "class", "Deflate", "{", "static", "final", "private", "int", "MAX_MEM_LEVEL", "=", "9", ";", "static", "final", "private", "int", "Z_DEFAULT_COMPRESSION", "=", "-", "1", ";", "static", "final", "private", "int", "MAX_WBITS", "=", "15", ";", "static", "final", "private", "int", "DEF_MEM_LEVEL", "=", "8", ";", "static", "class", "Config", "{", "int", "good_length", ";", "int", "max_lazy", ";", "int", "nice_length", ";", "int", "max_chain", ";", "int", "func", ";", "Config", "(", "int", "good_length", ",", "int", "max_lazy", ",", "int", "nice_length", ",", "int", "max_chain", ",", "int", "func", ")", "{", "this", ".", "good_length", "=", "good_length", ";", "this", ".", "max_lazy", "=", "max_lazy", ";", "this", ".", "nice_length", "=", "nice_length", ";", "this", ".", "max_chain", "=", "max_chain", ";", "this", ".", "func", "=", "func", ";", "}", "}", "static", "final", "private", "int", "STORED", "=", "0", ";", "static", "final", "private", "int", "FAST", "=", "1", ";", "static", "final", "private", "int", "SLOW", "=", "2", ";", "static", "final", "private", "Config", "[", "]", "config_table", ";", "static", "{", "config_table", "=", "new", "Config", "[", "10", "]", ";", "config_table", "[", "0", "]", "=", "new", "Config", "(", "0", ",", "0", ",", "0", ",", "0", ",", "STORED", ")", ";", "config_table", "[", "1", "]", "=", "new", "Config", "(", "4", ",", "4", ",", "8", ",", "4", ",", "FAST", ")", ";", "config_table", "[", "2", "]", "=", "new", "Config", "(", "4", ",", "5", ",", "16", ",", "8", ",", "FAST", ")", ";", "config_table", "[", "3", "]", "=", "new", "Config", "(", "4", ",", "6", ",", "32", ",", "32", ",", "FAST", ")", ";", "config_table", "[", "4", "]", "=", "new", "Config", "(", "4", ",", "4", ",", "16", ",", "16", ",", "SLOW", ")", ";", "config_table", "[", "5", "]", "=", "new", "Config", "(", "8", ",", "16", ",", "32", ",", "32", ",", "SLOW", ")", ";", "config_table", "[", "6", "]", "=", "new", "Config", "(", "8", ",", "16", ",", "128", ",", "128", ",", "SLOW", ")", ";", "config_table", "[", "7", "]", "=", "new", "Config", "(", "8", ",", "32", ",", "128", ",", "256", ",", "SLOW", ")", ";", "config_table", "[", "8", "]", "=", "new", "Config", "(", "32", ",", "128", ",", "258", ",", "1024", ",", "SLOW", ")", ";", "config_table", "[", "9", "]", "=", "new", "Config", "(", "32", ",", "258", ",", "258", ",", "4096", ",", "SLOW", ")", ";", "}", "static", "final", "private", "String", "[", "]", "z_errmsg", "=", "{", "\"\"", ",", "\"stream", "end\"", ",", "\"\"", ",", "\"file", "error\"", ",", "\"stream", "error\"", ",", "\"data", "error\"", ",", "\"\"", ",", "\"buffer", "error\"", ",", "\"\"", ",", "\"\"", "}", ";", "static", "final", "private", "int", "NeedMore", "=", "0", ";", "static", "final", "private", "int", "BlockDone", "=", "1", ";", "static", "final", "private", "int", "FinishStarted", "=", "2", ";", "static", "final", "private", "int", "FinishDone", "=", "3", ";", "static", "final", "private", "int", "PRESET_DICT", "=", "0x20", ";", "static", "final", "private", "int", "Z_FILTERED", "=", "1", ";", "static", "final", "private", "int", "Z_HUFFMAN_ONLY", "=", "2", ";", "static", "final", "private", "int", "Z_DEFAULT_STRATEGY", "=", "0", ";", "static", "final", "private", "int", "Z_NO_FLUSH", "=", "0", ";", "static", "final", "private", "int", "Z_PARTIAL_FLUSH", "=", "1", ";", "static", "final", "private", "int", "Z_SYNC_FLUSH", "=", "2", ";", "static", "final", "private", "int", "Z_FULL_FLUSH", "=", "3", ";", "static", "final", "private", "int", "Z_FINISH", "=", "4", ";", "static", "final", "private", "int", "Z_OK", "=", "0", ";", "static", "final", "private", "int", "Z_STREAM_END", "=", "1", ";", "static", "final", "private", "int", "Z_NEED_DICT", "=", "2", ";", "static", "final", "private", "int", "Z_ERRNO", "=", "-", "1", ";", "static", "final", "private", "int", "Z_STREAM_ERROR", "=", "-", "2", ";", "static", "final", "private", "int", "Z_DATA_ERROR", "=", "-", "3", ";", "static", "final", "private", "int", "Z_MEM_ERROR", "=", "-", "4", ";", "static", "final", "private", "int", "Z_BUF_ERROR", "=", "-", "5", ";", "static", "final", "private", "int", "Z_VERSION_ERROR", "=", "-", "6", ";", "static", "final", "private", "int", "INIT_STATE", "=", "42", ";", "static", "final", "private", "int", "BUSY_STATE", "=", "113", ";", "static", "final", "private", "int", "FINISH_STATE", "=", "666", ";", "static", "final", "private", "int", "Z_DEFLATED", "=", "8", ";", "static", "final", "private", "int", "STORED_BLOCK", "=", "0", ";", "static", "final", "private", "int", "STATIC_TREES", "=", "1", ";", "static", "final", "private", "int", "DYN_TREES", "=", "2", ";", "static", "final", "private", "int", "Z_BINARY", "=", "0", ";", "static", "final", "private", "int", "Z_ASCII", "=", "1", ";", "static", "final", "private", "int", "Z_UNKNOWN", "=", "2", ";", "static", "final", "private", "int", "Buf_size", "=", "8", "*", "2", ";", "static", "final", "private", "int", "REP_3_6", "=", "16", ";", "static", "final", "private", "int", "REPZ_3_10", "=", "17", ";", "static", "final", "private", "int", "REPZ_11_138", "=", "18", ";", "static", "final", "private", "int", "MIN_MATCH", "=", "3", ";", "static", "final", "private", "int", "MAX_MATCH", "=", "258", ";", "static", "final", "private", "int", "MIN_LOOKAHEAD", "=", "(", "MAX_MATCH", "+", "MIN_MATCH", "+", "1", ")", ";", "static", "final", "private", "int", "MAX_BITS", "=", "15", ";", "static", "final", "private", "int", "D_CODES", "=", "30", ";", "static", "final", "private", "int", "BL_CODES", "=", "19", ";", "static", "final", "private", "int", "LENGTH_CODES", "=", "29", ";", "static", "final", "private", "int", "LITERALS", "=", "256", ";", "static", "final", "private", "int", "L_CODES", "=", "(", "LITERALS", "+", "1", "+", "LENGTH_CODES", ")", ";", "static", "final", "private", "int", "HEAP_SIZE", "=", "(", "2", "*", "L_CODES", "+", "1", ")", ";", "static", "final", "private", "int", "END_BLOCK", "=", "256", ";", "ZStream", "strm", ";", "int", "status", ";", "byte", "[", "]", "pending_buf", ";", "int", "pending_buf_size", ";", "int", "pending_out", ";", "int", "pending", ";", "int", "noheader", ";", "byte", "data_type", ";", "byte", "method", ";", "int", "last_flush", ";", "int", "w_size", ";", "int", "w_bits", ";", "int", "w_mask", ";", "byte", "[", "]", "window", ";", "int", "window_size", ";", "short", "[", "]", "prev", ";", "short", "[", "]", "head", ";", "int", "ins_h", ";", "int", "hash_size", ";", "int", "hash_bits", ";", "int", "hash_mask", ";", "int", "hash_shift", ";", "int", "block_start", ";", "int", "match_length", ";", "int", "prev_match", ";", "int", "match_available", ";", "int", "strstart", ";", "int", "match_start", ";", "int", "lookahead", ";", "int", "prev_length", ";", "int", "max_chain_length", ";", "int", "max_lazy_match", ";", "int", "level", ";", "int", "strategy", ";", "int", "good_match", ";", "int", "nice_match", ";", "short", "[", "]", "dyn_ltree", ";", "short", "[", "]", "dyn_dtree", ";", "short", "[", "]", "bl_tree", ";", "Tree", "l_desc", "=", "new", "Tree", "(", ")", ";", "Tree", "d_desc", "=", "new", "Tree", "(", ")", ";", "Tree", "bl_desc", "=", "new", "Tree", "(", ")", ";", "short", "[", "]", "bl_count", "=", "new", "short", "[", "MAX_BITS", "+", "1", "]", ";", "int", "[", "]", "heap", "=", "new", "int", "[", "2", "*", "L_CODES", "+", "1", "]", ";", "int", "heap_len", ";", "int", "heap_max", ";", "byte", "[", "]", "depth", "=", "new", "byte", "[", "2", "*", "L_CODES", "+", "1", "]", ";", "int", "l_buf", ";", "int", "lit_bufsize", ";", "int", "last_lit", ";", "int", "d_buf", ";", "int", "opt_len", ";", "int", "static_len", ";", "int", "matches", ";", "int", "last_eob_len", ";", "short", "bi_buf", ";", "int", "bi_valid", ";", "Deflate", "(", ")", "{", "dyn_ltree", "=", "new", "short", "[", "HEAP_SIZE", "*", "2", "]", ";", "dyn_dtree", "=", "new", "short", "[", "(", "2", "*", "D_CODES", "+", "1", ")", "*", "2", "]", ";", "bl_tree", "=", "new", "short", "[", "(", "2", "*", "BL_CODES", "+", "1", ")", "*", "2", "]", ";", "}", "void", "lm_init", "(", ")", "{", "window_size", "=", "2", "*", "w_size", ";", "head", "[", "hash_size", "-", "1", "]", "=", "0", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "hash_size", "-", "1", ";", "i", "++", ")", "{", "head", "[", "i", "]", "=", "0", ";", "}", "max_lazy_match", "=", "Deflate", ".", "config_table", "[", "level", "]", ".", "max_lazy", ";", "good_match", "=", "Deflate", ".", "config_table", "[", "level", "]", ".", "good_length", ";", "nice_match", "=", "Deflate", ".", "config_table", "[", "level", "]", ".", "nice_length", ";", "max_chain_length", "=", "Deflate", ".", "config_table", "[", "level", "]", ".", "max_chain", ";", "strstart", "=", "0", ";", "block_start", "=", "0", ";", "lookahead", "=", "0", ";", "match_length", "=", "prev_length", "=", "MIN_MATCH", "-", "1", ";", "match_available", "=", "0", ";", "ins_h", "=", "0", ";", "}", "void", "tr_init", "(", ")", "{", "l_desc", ".", "dyn_tree", "=", "dyn_ltree", ";", "l_desc", ".", "stat_desc", "=", "StaticTree", ".", "static_l_desc", ";", "d_desc", ".", "dyn_tree", "=", "dyn_dtree", ";", "d_desc", ".", "stat_desc", "=", "StaticTree", ".", "static_d_desc", ";", "bl_desc", ".", "dyn_tree", "=", "bl_tree", ";", "bl_desc", ".", "stat_desc", "=", "StaticTree", ".", "static_bl_desc", ";", "bi_buf", "=", "0", ";", "bi_valid", "=", "0", ";", "last_eob_len", "=", "8", ";", "init_block", "(", ")", ";", "}", "void", "init_block", "(", ")", "{", "for", "(", "int", "i", "=", "0", ";", "i", "<", "L_CODES", ";", "i", "++", ")", "dyn_ltree", "[", "i", "*", "2", "]", "=", "0", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "D_CODES", ";", "i", "++", ")", "dyn_dtree", "[", "i", "*", "2", "]", "=", "0", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "BL_CODES", ";", "i", "++", ")", "bl_tree", "[", "i", "*", "2", "]", "=", "0", ";", "dyn_ltree", "[", "END_BLOCK", "*", "2", "]", "=", "1", ";", "opt_len", "=", "static_len", "=", "0", ";", "last_lit", "=", "matches", "=", "0", ";", "}", "void", "pqdownheap", "(", "short", "[", "]", "tree", ",", "int", "k", ")", "{", "int", "v", "=", "heap", "[", "k", "]", ";", "int", "j", "=", "k", "<<", "1", ";", "while", "(", "j", "<=", "heap_len", ")", "{", "if", "(", "j", "<", "heap_len", "&&", "smaller", "(", "tree", ",", "heap", "[", "j", "+", "1", "]", ",", "heap", "[", "j", "]", ",", "depth", ")", ")", "{", "j", "++", ";", "}", "if", "(", "smaller", "(", "tree", ",", "v", ",", "heap", "[", "j", "]", ",", "depth", ")", ")", "break", ";", "heap", "[", "k", "]", "=", "heap", "[", "j", "]", ";", "k", "=", "j", ";", "j", "<<=", "1", ";", "}", "heap", "[", "k", "]", "=", "v", ";", "}", "static", "boolean", "smaller", "(", "short", "[", "]", "tree", ",", "int", "n", ",", "int", "m", ",", "byte", "[", "]", "depth", ")", "{", "short", "tn2", "=", "tree", "[", "n", "*", "2", "]", ";", "short", "tm2", "=", "tree", "[", "m", "*", "2", "]", ";", "return", "(", "tn2", "<", "tm2", "||", "(", "tn2", "==", "tm2", "&&", "depth", "[", "n", "]", "<=", "depth", "[", "m", "]", ")", ")", ";", "}", "void", "scan_tree", "(", "short", "[", "]", "tree", ",", "int", "max_code", ")", "{", "int", "n", ";", "int", "prevlen", "=", "-", "1", ";", "int", "curlen", ";", "int", "nextlen", "=", "tree", "[", "0", "*", "2", "+", "1", "]", ";", "int", "count", "=", "0", ";", "int", "max_count", "=", "7", ";", "int", "min_count", "=", "4", ";", "if", "(", "nextlen", "==", "0", ")", "{", "max_count", "=", "138", ";", "min_count", "=", "3", ";", "}", "tree", "[", "(", "max_code", "+", "1", ")", "*", "2", "+", "1", "]", "=", "(", "short", ")", "0xffff", ";", "for", "(", "n", "=", "0", ";", "n", "<=", "max_code", ";", "n", "++", ")", "{", "curlen", "=", "nextlen", ";", "nextlen", "=", "tree", "[", "(", "n", "+", "1", ")", "*", "2", "+", "1", "]", ";", "if", "(", "++", "count", "<", "max_count", "&&", "curlen", "==", "nextlen", ")", "{", "continue", ";", "}", "else", "if", "(", "count", "<", "min_count", ")", "{", "bl_tree", "[", "curlen", "*", "2", "]", "+=", "count", ";", "}", "else", "if", "(", "curlen", "!=", "0", ")", "{", "if", "(", "curlen", "!=", "prevlen", ")", "bl_tree", "[", "curlen", "*", "2", "]", "++", ";", "bl_tree", "[", "REP_3_6", "*", "2", "]", "++", ";", "}", "else", "if", "(", "count", "<=", "10", ")", "{", "bl_tree", "[", "REPZ_3_10", "*", "2", "]", "++", ";", "}", "else", "{", "bl_tree", "[", "REPZ_11_138", "*", "2", "]", "++", ";", "}", "count", "=", "0", ";", "prevlen", "=", "curlen", ";", "if", "(", "nextlen", "==", "0", ")", "{", "max_count", "=", "138", ";", "min_count", "=", "3", ";", "}", "else", "if", "(", "curlen", "==", "nextlen", ")", "{", "max_count", "=", "6", ";", "min_count", "=", "3", ";", "}", "else", "{", "max_count", "=", "7", ";", "min_count", "=", "4", ";", "}", "}", "}", "int", "build_bl_tree", "(", ")", "{", "int", "max_blindex", ";", "scan_tree", "(", "dyn_ltree", ",", "l_desc", ".", "max_code", ")", ";", "scan_tree", "(", "dyn_dtree", ",", "d_desc", ".", "max_code", ")", ";", "bl_desc", ".", "build_tree", "(", "this", ")", ";", "for", "(", "max_blindex", "=", "BL_CODES", "-", "1", ";", "max_blindex", ">=", "3", ";", "max_blindex", "--", ")", "{", "if", "(", "bl_tree", "[", "Tree", ".", "bl_order", "[", "max_blindex", "]", "*", "2", "+", "1", "]", "!=", "0", ")", "break", ";", "}", "opt_len", "+=", "3", "*", "(", "max_blindex", "+", "1", ")", "+", "5", "+", "5", "+", "4", ";", "return", "max_blindex", ";", "}", "void", "send_all_trees", "(", "int", "lcodes", ",", "int", "dcodes", ",", "int", "blcodes", ")", "{", "int", "rank", ";", "send_bits", "(", "lcodes", "-", "257", ",", "5", ")", ";", "send_bits", "(", "dcodes", "-", "1", ",", "5", ")", ";", "send_bits", "(", "blcodes", "-", "4", ",", "4", ")", ";", "for", "(", "rank", "=", "0", ";", "rank", "<", "blcodes", ";", "rank", "++", ")", "{", "send_bits", "(", "bl_tree", "[", "Tree", ".", "bl_order", "[", "rank", "]", "*", "2", "+", "1", "]", ",", "3", ")", ";", "}", "send_tree", "(", "dyn_ltree", ",", "lcodes", "-", "1", ")", ";", "send_tree", "(", "dyn_dtree", ",", "dcodes", "-", "1", ")", ";", "}", "void", "send_tree", "(", "short", "[", "]", "tree", ",", "int", "max_code", ")", "{", "int", "n", ";", "int", "prevlen", "=", "-", "1", ";", "int", "curlen", ";", "int", "nextlen", "=", "tree", "[", "0", "*", "2", "+", "1", "]", ";", "int", "count", "=", "0", ";", "int", "max_count", "=", "7", ";", "int", "min_count", "=", "4", ";", "if", "(", "nextlen", "==", "0", ")", "{", "max_count", "=", "138", ";", "min_count", "=", "3", ";", "}", "for", "(", "n", "=", "0", ";", "n", "<=", "max_code", ";", "n", "++", ")", "{", "curlen", "=", "nextlen", ";", "nextlen", "=", "tree", "[", "(", "n", "+", "1", ")", "*", "2", "+", "1", "]", ";", "if", "(", "++", "count", "<", "max_count", "&&", "curlen", "==", "nextlen", ")", "{", "continue", ";", "}", "else", "if", "(", "count", "<", "min_count", ")", "{", "do", "{", "send_code", "(", "curlen", ",", "bl_tree", ")", ";", "}", "while", "(", "--", "count", "!=", "0", ")", ";", "}", "else", "if", "(", "curlen", "!=", "0", ")", "{", "if", "(", "curlen", "!=", "prevlen", ")", "{", "send_code", "(", "curlen", ",", "bl_tree", ")", ";", "count", "--", ";", "}", "send_code", "(", "REP_3_6", ",", "bl_tree", ")", ";", "send_bits", "(", "count", "-", "3", ",", "2", ")", ";", "}", "else", "if", "(", "count", "<=", "10", ")", "{", "send_code", "(", "REPZ_3_10", ",", "bl_tree", ")", ";", "send_bits", "(", "count", "-", "3", ",", "3", ")", ";", "}", "else", "{", "send_code", "(", "REPZ_11_138", ",", "bl_tree", ")", ";", "send_bits", "(", "count", "-", "11", ",", "7", ")", ";", "}", "count", "=", "0", ";", "prevlen", "=", "curlen", ";", "if", "(", "nextlen", "==", "0", ")", "{", "max_count", "=", "138", ";", "min_count", "=", "3", ";", "}", "else", "if", "(", "curlen", "==", "nextlen", ")", "{", "max_count", "=", "6", ";", "min_count", "=", "3", ";", "}", "else", "{", "max_count", "=", "7", ";", "min_count", "=", "4", ";", "}", "}", "}", "final", "void", "put_byte", "(", "byte", "[", "]", "p", ",", "int", "start", ",", "int", "len", ")", "{", "System", ".", "arraycopy", "(", "p", ",", "start", ",", "pending_buf", ",", "pending", ",", "len", ")", ";", "pending", "+=", "len", ";", "}", "final", "void", "put_byte", "(", "byte", "c", ")", "{", "pending_buf", "[", "pending", "++", "]", "=", "c", ";", "}", "final", "void", "put_short", "(", "int", "w", ")", "{", "put_byte", "(", "(", "byte", ")", "(", "w", ")", ")", ";", "put_byte", "(", "(", "byte", ")", "(", "w", ">>>", "8", ")", ")", ";", "}", "final", "void", "putShortMSB", "(", "int", "b", ")", "{", "put_byte", "(", "(", "byte", ")", "(", "b", ">>", "8", ")", ")", ";", "put_byte", "(", "(", "byte", ")", "(", "b", ")", ")", ";", "}", "final", "void", "send_code", "(", "int", "c", ",", "short", "[", "]", "tree", ")", "{", "int", "c2", "=", "c", "*", "2", ";", "send_bits", "(", "(", "tree", "[", "c2", "]", "&", "0xffff", ")", ",", "(", "tree", "[", "c2", "+", "1", "]", "&", "0xffff", ")", ")", ";", "}", "void", "send_bits", "(", "int", "value", ",", "int", "length", ")", "{", "int", "len", "=", "length", ";", "if", "(", "bi_valid", ">", "(", "int", ")", "Buf_size", "-", "len", ")", "{", "int", "val", "=", "value", ";", "bi_buf", "|=", "(", "(", "val", "<<", "bi_valid", ")", "&", "0xffff", ")", ";", "put_short", "(", "bi_buf", ")", ";", "bi_buf", "=", "(", "short", ")", "(", "val", ">>>", "(", "Buf_size", "-", "bi_valid", ")", ")", ";", "bi_valid", "+=", "len", "-", "Buf_size", ";", "}", "else", "{", "bi_buf", "|=", "(", "(", "(", "value", ")", "<<", "bi_valid", ")", "&", "0xffff", ")", ";", "bi_valid", "+=", "len", ";", "}", "}", "void", "_tr_align", "(", ")", "{", "send_bits", "(", "STATIC_TREES", "<<", "1", ",", "3", ")", ";", "send_code", "(", "END_BLOCK", ",", "StaticTree", ".", "static_ltree", ")", ";", "bi_flush", "(", ")", ";", "if", "(", "1", "+", "last_eob_len", "+", "10", "-", "bi_valid", "<", "9", ")", "{", "send_bits", "(", "STATIC_TREES", "<<", "1", ",", "3", ")", ";", "send_code", "(", "END_BLOCK", ",", "StaticTree", ".", "static_ltree", ")", ";", "bi_flush", "(", ")", ";", "}", "last_eob_len", "=", "7", ";", "}", "boolean", "_tr_tally", "(", "int", "dist", ",", "int", "lc", ")", "{", "pending_buf", "[", "d_buf", "+", "last_lit", "*", "2", "]", "=", "(", "byte", ")", "(", "dist", ">>>", "8", ")", ";", "pending_buf", "[", "d_buf", "+", "last_lit", "*", "2", "+", "1", "]", "=", "(", "byte", ")", "dist", ";", "pending_buf", "[", "l_buf", "+", "last_lit", "]", "=", "(", "byte", ")", "lc", ";", "last_lit", "++", ";", "if", "(", "dist", "==", "0", ")", "{", "dyn_ltree", "[", "lc", "*", "2", "]", "++", ";", "}", "else", "{", "matches", "++", ";", "dist", "--", ";", "dyn_ltree", "[", "(", "Tree", ".", "_length_code", "[", "lc", "]", "+", "LITERALS", "+", "1", ")", "*", "2", "]", "++", ";", "dyn_dtree", "[", "Tree", ".", "d_code", "(", "dist", ")", "*", "2", "]", "++", ";", "}", "if", "(", "(", "last_lit", "&", "0x1fff", ")", "==", "0", "&&", "level", ">", "2", ")", "{", "int", "out_length", "=", "last_lit", "*", "8", ";", "int", "in_length", "=", "strstart", "-", "block_start", ";", "int", "dcode", ";", "for", "(", "dcode", "=", "0", ";", "dcode", "<", "D_CODES", ";", "dcode", "++", ")", "{", "out_length", "+=", "(", "int", ")", "dyn_dtree", "[", "dcode", "*", "2", "]", "*", "(", "5L", "+", "Tree", ".", "extra_dbits", "[", "dcode", "]", ")", ";", "}", "out_length", ">>>=", "3", ";", "if", "(", "(", "matches", "<", "(", "last_lit", "/", "2", ")", ")", "&&", "out_length", "<", "in_length", "/", "2", ")", "return", "true", ";", "}", "return", "(", "last_lit", "==", "lit_bufsize", "-", "1", ")", ";", "}", "void", "compress_block", "(", "short", "[", "]", "ltree", ",", "short", "[", "]", "dtree", ")", "{", "int", "dist", ";", "int", "lc", ";", "int", "lx", "=", "0", ";", "int", "code", ";", "int", "extra", ";", "if", "(", "last_lit", "!=", "0", ")", "{", "do", "{", "dist", "=", "(", "(", "pending_buf", "[", "d_buf", "+", "lx", "*", "2", "]", "<<", "8", ")", "&", "0xff00", ")", "|", "(", "pending_buf", "[", "d_buf", "+", "lx", "*", "2", "+", "1", "]", "&", "0xff", ")", ";", "lc", "=", "(", "pending_buf", "[", "l_buf", "+", "lx", "]", ")", "&", "0xff", ";", "lx", "++", ";", "if", "(", "dist", "==", "0", ")", "{", "send_code", "(", "lc", ",", "ltree", ")", ";", "}", "else", "{", "code", "=", "Tree", ".", "_length_code", "[", "lc", "]", ";", "send_code", "(", "code", "+", "LITERALS", "+", "1", ",", "ltree", ")", ";", "extra", "=", "Tree", ".", "extra_lbits", "[", "code", "]", ";", "if", "(", "extra", "!=", "0", ")", "{", "lc", "-=", "Tree", ".", "base_length", "[", "code", "]", ";", "send_bits", "(", "lc", ",", "extra", ")", ";", "}", "dist", "--", ";", "code", "=", "Tree", ".", "d_code", "(", "dist", ")", ";", "send_code", "(", "code", ",", "dtree", ")", ";", "extra", "=", "Tree", ".", "extra_dbits", "[", "code", "]", ";", "if", "(", "extra", "!=", "0", ")", "{", "dist", "-=", "Tree", ".", "base_dist", "[", "code", "]", ";", "send_bits", "(", "dist", ",", "extra", ")", ";", "}", "}", "}", "while", "(", "lx", "<", "last_lit", ")", ";", "}", "send_code", "(", "END_BLOCK", ",", "ltree", ")", ";", "last_eob_len", "=", "ltree", "[", "END_BLOCK", "*", "2", "+", "1", "]", ";", "}", "void", "set_data_type", "(", ")", "{", "int", "n", "=", "0", ";", "int", "ascii_freq", "=", "0", ";", "int", "bin_freq", "=", "0", ";", "while", "(", "n", "<", "7", ")", "{", "bin_freq", "+=", "dyn_ltree", "[", "n", "*", "2", "]", ";", "n", "++", ";", "}", "while", "(", "n", "<", "128", ")", "{", "ascii_freq", "+=", "dyn_ltree", "[", "n", "*", "2", "]", ";", "n", "++", ";", "}", "while", "(", "n", "<", "LITERALS", ")", "{", "bin_freq", "+=", "dyn_ltree", "[", "n", "*", "2", "]", ";", "n", "++", ";", "}", "data_type", "=", "(", "byte", ")", "(", "bin_freq", ">", "(", "ascii_freq", ">>>", "2", ")", "?", "Z_BINARY", ":", "Z_ASCII", ")", ";", "}", "void", "bi_flush", "(", ")", "{", "if", "(", "bi_valid", "==", "16", ")", "{", "put_short", "(", "bi_buf", ")", ";", "bi_buf", "=", "0", ";", "bi_valid", "=", "0", ";", "}", "else", "if", "(", "bi_valid", ">=", "8", ")", "{", "put_byte", "(", "(", "byte", ")", "bi_buf", ")", ";", "bi_buf", ">>>=", "8", ";", "bi_valid", "-=", "8", ";", "}", "}", "void", "bi_windup", "(", ")", "{", "if", "(", "bi_valid", ">", "8", ")", "{", "put_short", "(", "bi_buf", ")", ";", "}", "else", "if", "(", "bi_valid", ">", "0", ")", "{", "put_byte", "(", "(", "byte", ")", "bi_buf", ")", ";", "}", "bi_buf", "=", "0", ";", "bi_valid", "=", "0", ";", "}", "void", "copy_block", "(", "int", "buf", ",", "int", "len", ",", "boolean", "header", ")", "{", "int", "index", "=", "0", ";", "bi_windup", "(", ")", ";", "last_eob_len", "=", "8", ";", "if", "(", "header", ")", "{", "put_short", "(", "(", "short", ")", "len", ")", ";", "put_short", "(", "(", "short", ")", "~", "len", ")", ";", "}", "put_byte", "(", "window", ",", "buf", ",", "len", ")", ";", "}", "void", "flush_block_only", "(", "boolean", "eof", ")", "{", "_tr_flush_block", "(", "block_start", ">=", "0", "?", "block_start", ":", "-", "1", ",", "strstart", "-", "block_start", ",", "eof", ")", ";", "block_start", "=", "strstart", ";", "strm", ".", "flush_pending", "(", ")", ";", "}", "int", "deflate_stored", "(", "int", "flush", ")", "{", "int", "max_block_size", "=", "0xffff", ";", "int", "max_start", ";", "if", "(", "max_block_size", ">", "pending_buf_size", "-", "5", ")", "{", "max_block_size", "=", "pending_buf_size", "-", "5", ";", "}", "while", "(", "true", ")", "{", "if", "(", "lookahead", "<=", "1", ")", "{", "fill_window", "(", ")", ";", "if", "(", "lookahead", "==", "0", "&&", "flush", "==", "Z_NO_FLUSH", ")", "return", "NeedMore", ";", "if", "(", "lookahead", "==", "0", ")", "break", ";", "}", "strstart", "+=", "lookahead", ";", "lookahead", "=", "0", ";", "max_start", "=", "block_start", "+", "max_block_size", ";", "if", "(", "strstart", "==", "0", "||", "strstart", ">=", "max_start", ")", "{", "lookahead", "=", "(", "int", ")", "(", "strstart", "-", "max_start", ")", ";", "strstart", "=", "(", "int", ")", "max_start", ";", "flush_block_only", "(", "false", ")", ";", "if", "(", "strm", ".", "avail_out", "==", "0", ")", "return", "NeedMore", ";", "}", "if", "(", "strstart", "-", "block_start", ">=", "w_size", "-", "MIN_LOOKAHEAD", ")", "{", "flush_block_only", "(", "false", ")", ";", "if", "(", "strm", ".", "avail_out", "==", "0", ")", "return", "NeedMore", ";", "}", "}", "flush_block_only", "(", "flush", "==", "Z_FINISH", ")", ";", "if", "(", "strm", ".", "avail_out", "==", "0", ")", "return", "(", "flush", "==", "Z_FINISH", ")", "?", "FinishStarted", ":", "NeedMore", ";", "return", "flush", "==", "Z_FINISH", "?", "FinishDone", ":", "BlockDone", ";", "}", "void", "_tr_stored_block", "(", "int", "buf", ",", "int", "stored_len", ",", "boolean", "eof", ")", "{", "send_bits", "(", "(", "STORED_BLOCK", "<<", "1", ")", "+", "(", "eof", "?", "1", ":", "0", ")", ",", "3", ")", ";", "copy_block", "(", "buf", ",", "stored_len", ",", "true", ")", ";", "}", "void", "_tr_flush_block", "(", "int", "buf", ",", "int", "stored_len", ",", "boolean", "eof", ")", "{", "int", "opt_lenb", ",", "static_lenb", ";", "int", "max_blindex", "=", "0", ";", "if", "(", "level", ">", "0", ")", "{", "if", "(", "data_type", "==", "Z_UNKNOWN", ")", "set_data_type", "(", ")", ";", "l_desc", ".", "build_tree", "(", "this", ")", ";", "d_desc", ".", "build_tree", "(", "this", ")", ";", "max_blindex", "=", "build_bl_tree", "(", ")", ";", "opt_lenb", "=", "(", "opt_len", "+", "3", "+", "7", ")", ">>>", "3", ";", "static_lenb", "=", "(", "static_len", "+", "3", "+", "7", ")", ">>>", "3", ";", "if", "(", "static_lenb", "<=", "opt_lenb", ")", "opt_lenb", "=", "static_lenb", ";", "}", "else", "{", "opt_lenb", "=", "static_lenb", "=", "stored_len", "+", "5", ";", "}", "if", "(", "stored_len", "+", "4", "<=", "opt_lenb", "&&", "buf", "!=", "-", "1", ")", "{", "_tr_stored_block", "(", "buf", ",", "stored_len", ",", "eof", ")", ";", "}", "else", "if", "(", "static_lenb", "==", "opt_lenb", ")", "{", "send_bits", "(", "(", "STATIC_TREES", "<<", "1", ")", "+", "(", "eof", "?", "1", ":", "0", ")", ",", "3", ")", ";", "compress_block", "(", "StaticTree", ".", "static_ltree", ",", "StaticTree", ".", "static_dtree", ")", ";", "}", "else", "{", "send_bits", "(", "(", "DYN_TREES", "<<", "1", ")", "+", "(", "eof", "?", "1", ":", "0", ")", ",", "3", ")", ";", "send_all_trees", "(", "l_desc", ".", "max_code", "+", "1", ",", "d_desc", ".", "max_code", "+", "1", ",", "max_blindex", "+", "1", ")", ";", "compress_block", "(", "dyn_ltree", ",", "dyn_dtree", ")", ";", "}", "init_block", "(", ")", ";", "if", "(", "eof", ")", "{", "bi_windup", "(", ")", ";", "}", "}", "void", "fill_window", "(", ")", "{", "int", "n", ",", "m", ";", "int", "p", ";", "int", "more", ";", "do", "{", "more", "=", "(", "window_size", "-", "lookahead", "-", "strstart", ")", ";", "if", "(", "more", "==", "0", "&&", "strstart", "==", "0", "&&", "lookahead", "==", "0", ")", "{", "more", "=", "w_size", ";", "}", "else", "if", "(", "more", "==", "-", "1", ")", "{", "more", "--", ";", "}", "else", "if", "(", "strstart", ">=", "w_size", "+", "w_size", "-", "MIN_LOOKAHEAD", ")", "{", "System", ".", "arraycopy", "(", "window", ",", "w_size", ",", "window", ",", "0", ",", "w_size", ")", ";", "match_start", "-=", "w_size", ";", "strstart", "-=", "w_size", ";", "block_start", "-=", "w_size", ";", "n", "=", "hash_size", ";", "p", "=", "n", ";", "do", "{", "m", "=", "(", "head", "[", "--", "p", "]", "&", "0xffff", ")", ";", "head", "[", "p", "]", "=", "(", "m", ">=", "w_size", "?", "(", "short", ")", "(", "m", "-", "w_size", ")", ":", "0", ")", ";", "}", "while", "(", "--", "n", "!=", "0", ")", ";", "n", "=", "w_size", ";", "p", "=", "n", ";", "do", "{", "m", "=", "(", "prev", "[", "--", "p", "]", "&", "0xffff", ")", ";", "prev", "[", "p", "]", "=", "(", "m", ">=", "w_size", "?", "(", "short", ")", "(", "m", "-", "w_size", ")", ":", "0", ")", ";", "}", "while", "(", "--", "n", "!=", "0", ")", ";", "more", "+=", "w_size", ";", "}", "if", "(", "strm", ".", "avail_in", "==", "0", ")", "return", ";", "n", "=", "strm", ".", "read_buf", "(", "window", ",", "strstart", "+", "lookahead", ",", "more", ")", ";", "lookahead", "+=", "n", ";", "if", "(", "lookahead", ">=", "MIN_MATCH", ")", "{", "ins_h", "=", "window", "[", "strstart", "]", "&", "0xff", ";", "ins_h", "=", "(", "(", "(", "ins_h", ")", "<<", "hash_shift", ")", "^", "(", "window", "[", "strstart", "+", "1", "]", "&", "0xff", ")", ")", "&", "hash_mask", ";", "}", "}", "while", "(", "lookahead", "<", "MIN_LOOKAHEAD", "&&", "strm", ".", "avail_in", "!=", "0", ")", ";", "}", "int", "deflate_fast", "(", "int", "flush", ")", "{", "int", "hash_head", "=", "0", ";", "boolean", "bflush", ";", "while", "(", "true", ")", "{", "if", "(", "lookahead", "<", "MIN_LOOKAHEAD", ")", "{", "fill_window", "(", ")", ";", "if", "(", "lookahead", "<", "MIN_LOOKAHEAD", "&&", "flush", "==", "Z_NO_FLUSH", ")", "{", "return", "NeedMore", ";", "}", "if", "(", "lookahead", "==", "0", ")", "break", ";", "}", "if", "(", "lookahead", ">=", "MIN_MATCH", ")", "{", "ins_h", "=", "(", "(", "(", "ins_h", ")", "<<", "hash_shift", ")", "^", "(", "window", "[", "(", "strstart", ")", "+", "(", "MIN_MATCH", "-", "1", ")", "]", "&", "0xff", ")", ")", "&", "hash_mask", ";", "hash_head", "=", "(", "head", "[", "ins_h", "]", "&", "0xffff", ")", ";", "prev", "[", "strstart", "&", "w_mask", "]", "=", "head", "[", "ins_h", "]", ";", "head", "[", "ins_h", "]", "=", "(", "short", ")", "strstart", ";", "}", "if", "(", "hash_head", "!=", "0L", "&&", "(", "(", "strstart", "-", "hash_head", ")", "&", "0xffff", ")", "<=", "w_size", "-", "MIN_LOOKAHEAD", ")", "{", "if", "(", "strategy", "!=", "Z_HUFFMAN_ONLY", ")", "{", "match_length", "=", "longest_match", "(", "hash_head", ")", ";", "}", "}", "if", "(", "match_length", ">=", "MIN_MATCH", ")", "{", "bflush", "=", "_tr_tally", "(", "strstart", "-", "match_start", ",", "match_length", "-", "MIN_MATCH", ")", ";", "lookahead", "-=", "match_length", ";", "if", "(", "match_length", "<=", "max_lazy_match", "&&", "lookahead", ">=", "MIN_MATCH", ")", "{", "match_length", "--", ";", "do", "{", "strstart", "++", ";", "ins_h", "=", "(", "(", "ins_h", "<<", "hash_shift", ")", "^", "(", "window", "[", "(", "strstart", ")", "+", "(", "MIN_MATCH", "-", "1", ")", "]", "&", "0xff", ")", ")", "&", "hash_mask", ";", "hash_head", "=", "(", "head", "[", "ins_h", "]", "&", "0xffff", ")", ";", "prev", "[", "strstart", "&", "w_mask", "]", "=", "head", "[", "ins_h", "]", ";", "head", "[", "ins_h", "]", "=", "(", "short", ")", "strstart", ";", "}", "while", "(", "--", "match_length", "!=", "0", ")", ";", "strstart", "++", ";", "}", "else", "{", "strstart", "+=", "match_length", ";", "match_length", "=", "0", ";", "ins_h", "=", "window", "[", "strstart", "]", "&", "0xff", ";", "ins_h", "=", "(", "(", "(", "ins_h", ")", "<<", "hash_shift", ")", "^", "(", "window", "[", "strstart", "+", "1", "]", "&", "0xff", ")", ")", "&", "hash_mask", ";", "}", "}", "else", "{", "bflush", "=", "_tr_tally", "(", "0", ",", "window", "[", "strstart", "]", "&", "0xff", ")", ";", "lookahead", "--", ";", "strstart", "++", ";", "}", "if", "(", "bflush", ")", "{", "flush_block_only", "(", "false", ")", ";", "if", "(", "strm", ".", "avail_out", "==", "0", ")", "return", "NeedMore", ";", "}", "}", "flush_block_only", "(", "flush", "==", "Z_FINISH", ")", ";", "if", "(", "strm", ".", "avail_out", "==", "0", ")", "{", "if", "(", "flush", "==", "Z_FINISH", ")", "return", "FinishStarted", ";", "else", "return", "NeedMore", ";", "}", "return", "flush", "==", "Z_FINISH", "?", "FinishDone", ":", "BlockDone", ";", "}", "int", "deflate_slow", "(", "int", "flush", ")", "{", "int", "hash_head", "=", "0", ";", "boolean", "bflush", ";", "while", "(", "true", ")", "{", "if", "(", "lookahead", "<", "MIN_LOOKAHEAD", ")", "{", "fill_window", "(", ")", ";", "if", "(", "lookahead", "<", "MIN_LOOKAHEAD", "&&", "flush", "==", "Z_NO_FLUSH", ")", "{", "return", "NeedMore", ";", "}", "if", "(", "lookahead", "==", "0", ")", "break", ";", "}", "if", "(", "lookahead", ">=", "MIN_MATCH", ")", "{", "ins_h", "=", "(", "(", "(", "ins_h", ")", "<<", "hash_shift", ")", "^", "(", "window", "[", "(", "strstart", ")", "+", "(", "MIN_MATCH", "-", "1", ")", "]", "&", "0xff", ")", ")", "&", "hash_mask", ";", "hash_head", "=", "(", "head", "[", "ins_h", "]", "&", "0xffff", ")", ";", "prev", "[", "strstart", "&", "w_mask", "]", "=", "head", "[", "ins_h", "]", ";", "head", "[", "ins_h", "]", "=", "(", "short", ")", "strstart", ";", "}", "prev_length", "=", "match_length", ";", "prev_match", "=", "match_start", ";", "match_length", "=", "MIN_MATCH", "-", "1", ";", "if", "(", "hash_head", "!=", "0", "&&", "prev_length", "<", "max_lazy_match", "&&", "(", "(", "strstart", "-", "hash_head", ")", "&", "0xffff", ")", "<=", "w_size", "-", "MIN_LOOKAHEAD", ")", "{", "if", "(", "strategy", "!=", "Z_HUFFMAN_ONLY", ")", "{", "match_length", "=", "longest_match", "(", "hash_head", ")", ";", "}", "if", "(", "match_length", "<=", "5", "&&", "(", "strategy", "==", "Z_FILTERED", "||", "(", "match_length", "==", "MIN_MATCH", "&&", "strstart", "-", "match_start", ">", "4096", ")", ")", ")", "{", "match_length", "=", "MIN_MATCH", "-", "1", ";", "}", "}", "if", "(", "prev_length", ">=", "MIN_MATCH", "&&", "match_length", "<=", "prev_length", ")", "{", "int", "max_insert", "=", "strstart", "+", "lookahead", "-", "MIN_MATCH", ";", "bflush", "=", "_tr_tally", "(", "strstart", "-", "1", "-", "prev_match", ",", "prev_length", "-", "MIN_MATCH", ")", ";", "lookahead", "-=", "prev_length", "-", "1", ";", "prev_length", "-=", "2", ";", "do", "{", "if", "(", "++", "strstart", "<=", "max_insert", ")", "{", "ins_h", "=", "(", "(", "(", "ins_h", ")", "<<", "hash_shift", ")", "^", "(", "window", "[", "(", "strstart", ")", "+", "(", "MIN_MATCH", "-", "1", ")", "]", "&", "0xff", ")", ")", "&", "hash_mask", ";", "hash_head", "=", "(", "head", "[", "ins_h", "]", "&", "0xffff", ")", ";", "prev", "[", "strstart", "&", "w_mask", "]", "=", "head", "[", "ins_h", "]", ";", "head", "[", "ins_h", "]", "=", "(", "short", ")", "strstart", ";", "}", "}", "while", "(", "--", "prev_length", "!=", "0", ")", ";", "match_available", "=", "0", ";", "match_length", "=", "MIN_MATCH", "-", "1", ";", "strstart", "++", ";", "if", "(", "bflush", ")", "{", "flush_block_only", "(", "false", ")", ";", "if", "(", "strm", ".", "avail_out", "==", "0", ")", "return", "NeedMore", ";", "}", "}", "else", "if", "(", "match_available", "!=", "0", ")", "{", "bflush", "=", "_tr_tally", "(", "0", ",", "window", "[", "strstart", "-", "1", "]", "&", "0xff", ")", ";", "if", "(", "bflush", ")", "{", "flush_block_only", "(", "false", ")", ";", "}", "strstart", "++", ";", "lookahead", "--", ";", "if", "(", "strm", ".", "avail_out", "==", "0", ")", "return", "NeedMore", ";", "}", "else", "{", "match_available", "=", "1", ";", "strstart", "++", ";", "lookahead", "--", ";", "}", "}", "if", "(", "match_available", "!=", "0", ")", "{", "bflush", "=", "_tr_tally", "(", "0", ",", "window", "[", "strstart", "-", "1", "]", "&", "0xff", ")", ";", "match_available", "=", "0", ";", "}", "flush_block_only", "(", "flush", "==", "Z_FINISH", ")", ";", "if", "(", "strm", ".", "avail_out", "==", "0", ")", "{", "if", "(", "flush", "==", "Z_FINISH", ")", "return", "FinishStarted", ";", "else", "return", "NeedMore", ";", "}", "return", "flush", "==", "Z_FINISH", "?", "FinishDone", ":", "BlockDone", ";", "}", "int", "longest_match", "(", "int", "cur_match", ")", "{", "int", "chain_length", "=", "max_chain_length", ";", "int", "scan", "=", "strstart", ";", "int", "match", ";", "int", "len", ";", "int", "best_len", "=", "prev_length", ";", "int", "limit", "=", "strstart", ">", "(", "w_size", "-", "MIN_LOOKAHEAD", ")", "?", "strstart", "-", "(", "w_size", "-", "MIN_LOOKAHEAD", ")", ":", "0", ";", "int", "nice_match", "=", "this", ".", "nice_match", ";", "int", "wmask", "=", "w_mask", ";", "int", "strend", "=", "strstart", "+", "MAX_MATCH", ";", "byte", "scan_end1", "=", "window", "[", "scan", "+", "best_len", "-", "1", "]", ";", "byte", "scan_end", "=", "window", "[", "scan", "+", "best_len", "]", ";", "if", "(", "prev_length", ">=", "good_match", ")", "{", "chain_length", ">>=", "2", ";", "}", "if", "(", "nice_match", ">", "lookahead", ")", "nice_match", "=", "lookahead", ";", "do", "{", "match", "=", "cur_match", ";", "if", "(", "window", "[", "match", "+", "best_len", "]", "!=", "scan_end", "||", "window", "[", "match", "+", "best_len", "-", "1", "]", "!=", "scan_end1", "||", "window", "[", "match", "]", "!=", "window", "[", "scan", "]", "||", "window", "[", "++", "match", "]", "!=", "window", "[", "scan", "+", "1", "]", ")", "continue", ";", "scan", "+=", "2", ";", "match", "++", ";", "do", "{", "}", "while", "(", "window", "[", "++", "scan", "]", "==", "window", "[", "++", "match", "]", "&&", "window", "[", "++", "scan", "]", "==", "window", "[", "++", "match", "]", "&&", "window", "[", "++", "scan", "]", "==", "window", "[", "++", "match", "]", "&&", "window", "[", "++", "scan", "]", "==", "window", "[", "++", "match", "]", "&&", "window", "[", "++", "scan", "]", "==", "window", "[", "++", "match", "]", "&&", "window", "[", "++", "scan", "]", "==", "window", "[", "++", "match", "]", "&&", "window", "[", "++", "scan", "]", "==", "window", "[", "++", "match", "]", "&&", "window", "[", "++", "scan", "]", "==", "window", "[", "++", "match", "]", "&&", "scan", "<", "strend", ")", ";", "len", "=", "MAX_MATCH", "-", "(", "int", ")", "(", "strend", "-", "scan", ")", ";", "scan", "=", "strend", "-", "MAX_MATCH", ";", "if", "(", "len", ">", "best_len", ")", "{", "match_start", "=", "cur_match", ";", "best_len", "=", "len", ";", "if", "(", "len", ">=", "nice_match", ")", "break", ";", "scan_end1", "=", "window", "[", "scan", "+", "best_len", "-", "1", "]", ";", "scan_end", "=", "window", "[", "scan", "+", "best_len", "]", ";", "}", "}", "while", "(", "(", "cur_match", "=", "(", "prev", "[", "cur_match", "&", "wmask", "]", "&", "0xffff", ")", ")", ">", "limit", "&&", "--", "chain_length", "!=", "0", ")", ";", "if", "(", "best_len", "<=", "lookahead", ")", "return", "best_len", ";", "return", "lookahead", ";", "}", "int", "deflateInit", "(", "ZStream", "strm", ",", "int", "level", ",", "int", "bits", ")", "{", "return", "deflateInit2", "(", "strm", ",", "level", ",", "Z_DEFLATED", ",", "bits", ",", "DEF_MEM_LEVEL", ",", "Z_DEFAULT_STRATEGY", ")", ";", "}", "int", "deflateInit", "(", "ZStream", "strm", ",", "int", "level", ")", "{", "return", "deflateInit", "(", "strm", ",", "level", ",", "MAX_WBITS", ")", ";", "}", "int", "deflateInit2", "(", "ZStream", "strm", ",", "int", "level", ",", "int", "method", ",", "int", "windowBits", ",", "int", "memLevel", ",", "int", "strategy", ")", "{", "int", "noheader", "=", "0", ";", "strm", ".", "msg", "=", "null", ";", "if", "(", "level", "==", "Z_DEFAULT_COMPRESSION", ")", "level", "=", "6", ";", "if", "(", "windowBits", "<", "0", ")", "{", "noheader", "=", "1", ";", "windowBits", "=", "-", "windowBits", ";", "}", "if", "(", "memLevel", "<", "1", "||", "memLevel", ">", "MAX_MEM_LEVEL", "||", "method", "!=", "Z_DEFLATED", "||", "windowBits", "<", "9", "||", "windowBits", ">", "15", "||", "level", "<", "0", "||", "level", ">", "9", "||", "strategy", "<", "0", "||", "strategy", ">", "Z_HUFFMAN_ONLY", ")", "{", "return", "Z_STREAM_ERROR", ";", "}", "strm", ".", "dstate", "=", "(", "Deflate", ")", "this", ";", "this", ".", "noheader", "=", "noheader", ";", "w_bits", "=", "windowBits", ";", "w_size", "=", "1", "<<", "w_bits", ";", "w_mask", "=", "w_size", "-", "1", ";", "hash_bits", "=", "memLevel", "+", "7", ";", "hash_size", "=", "1", "<<", "hash_bits", ";", "hash_mask", "=", "hash_size", "-", "1", ";", "hash_shift", "=", "(", "(", "hash_bits", "+", "MIN_MATCH", "-", "1", ")", "/", "MIN_MATCH", ")", ";", "window", "=", "new", "byte", "[", "w_size", "*", "2", "]", ";", "prev", "=", "new", "short", "[", "w_size", "]", ";", "head", "=", "new", "short", "[", "hash_size", "]", ";", "lit_bufsize", "=", "1", "<<", "(", "memLevel", "+", "6", ")", ";", "pending_buf", "=", "new", "byte", "[", "lit_bufsize", "*", "4", "]", ";", "pending_buf_size", "=", "lit_bufsize", "*", "4", ";", "d_buf", "=", "lit_bufsize", "/", "2", ";", "l_buf", "=", "(", "1", "+", "2", ")", "*", "lit_bufsize", ";", "this", ".", "level", "=", "level", ";", "this", ".", "strategy", "=", "strategy", ";", "this", ".", "method", "=", "(", "byte", ")", "method", ";", "return", "deflateReset", "(", "strm", ")", ";", "}", "int", "deflateReset", "(", "ZStream", "strm", ")", "{", "strm", ".", "total_in", "=", "strm", ".", "total_out", "=", "0", ";", "strm", ".", "msg", "=", "null", ";", "strm", ".", "data_type", "=", "Z_UNKNOWN", ";", "pending", "=", "0", ";", "pending_out", "=", "0", ";", "if", "(", "noheader", "<", "0", ")", "{", "noheader", "=", "0", ";", "}", "status", "=", "(", "noheader", "!=", "0", ")", "?", "BUSY_STATE", ":", "INIT_STATE", ";", "strm", ".", "adler", "=", "strm", ".", "_adler", ".", "adler32", "(", "0", ",", "null", ",", "0", ",", "0", ")", ";", "last_flush", "=", "Z_NO_FLUSH", ";", "tr_init", "(", ")", ";", "lm_init", "(", ")", ";", "return", "Z_OK", ";", "}", "int", "deflateEnd", "(", ")", "{", "if", "(", "status", "!=", "INIT_STATE", "&&", "status", "!=", "BUSY_STATE", "&&", "status", "!=", "FINISH_STATE", ")", "{", "return", "Z_STREAM_ERROR", ";", "}", "pending_buf", "=", "null", ";", "head", "=", "null", ";", "prev", "=", "null", ";", "window", "=", "null", ";", "return", "status", "==", "BUSY_STATE", "?", "Z_DATA_ERROR", ":", "Z_OK", ";", "}", "int", "deflateParams", "(", "ZStream", "strm", ",", "int", "_level", ",", "int", "_strategy", ")", "{", "int", "err", "=", "Z_OK", ";", "if", "(", "_level", "==", "Z_DEFAULT_COMPRESSION", ")", "{", "_level", "=", "6", ";", "}", "if", "(", "_level", "<", "0", "||", "_level", ">", "9", "||", "_strategy", "<", "0", "||", "_strategy", ">", "Z_HUFFMAN_ONLY", ")", "{", "return", "Z_STREAM_ERROR", ";", "}", "if", "(", "config_table", "[", "level", "]", ".", "func", "!=", "config_table", "[", "_level", "]", ".", "func", "&&", "strm", ".", "total_in", "!=", "0", ")", "{", "err", "=", "strm", ".", "deflate", "(", "Z_PARTIAL_FLUSH", ")", ";", "}", "if", "(", "level", "!=", "_level", ")", "{", "level", "=", "_level", ";", "max_lazy_match", "=", "config_table", "[", "level", "]", ".", "max_lazy", ";", "good_match", "=", "config_table", "[", "level", "]", ".", "good_length", ";", "nice_match", "=", "config_table", "[", "level", "]", ".", "nice_length", ";", "max_chain_length", "=", "config_table", "[", "level", "]", ".", "max_chain", ";", "}", "strategy", "=", "_strategy", ";", "return", "err", ";", "}", "int", "deflateSetDictionary", "(", "ZStream", "strm", ",", "byte", "[", "]", "dictionary", ",", "int", "dictLength", ")", "{", "int", "length", "=", "dictLength", ";", "int", "index", "=", "0", ";", "if", "(", "dictionary", "==", "null", "||", "status", "!=", "INIT_STATE", ")", "return", "Z_STREAM_ERROR", ";", "strm", ".", "adler", "=", "strm", ".", "_adler", ".", "adler32", "(", "strm", ".", "adler", ",", "dictionary", ",", "0", ",", "dictLength", ")", ";", "if", "(", "length", "<", "MIN_MATCH", ")", "return", "Z_OK", ";", "if", "(", "length", ">", "w_size", "-", "MIN_LOOKAHEAD", ")", "{", "length", "=", "w_size", "-", "MIN_LOOKAHEAD", ";", "index", "=", "dictLength", "-", "length", ";", "}", "System", ".", "arraycopy", "(", "dictionary", ",", "index", ",", "window", ",", "0", ",", "length", ")", ";", "strstart", "=", "length", ";", "block_start", "=", "length", ";", "ins_h", "=", "window", "[", "0", "]", "&", "0xff", ";", "ins_h", "=", "(", "(", "(", "ins_h", ")", "<<", "hash_shift", ")", "^", "(", "window", "[", "1", "]", "&", "0xff", ")", ")", "&", "hash_mask", ";", "for", "(", "int", "n", "=", "0", ";", "n", "<=", "length", "-", "MIN_MATCH", ";", "n", "++", ")", "{", "ins_h", "=", "(", "(", "(", "ins_h", ")", "<<", "hash_shift", ")", "^", "(", "window", "[", "(", "n", ")", "+", "(", "MIN_MATCH", "-", "1", ")", "]", "&", "0xff", ")", ")", "&", "hash_mask", ";", "prev", "[", "n", "&", "w_mask", "]", "=", "head", "[", "ins_h", "]", ";", "head", "[", "ins_h", "]", "=", "(", "short", ")", "n", ";", "}", "return", "Z_OK", ";", "}", "int", "deflate", "(", "ZStream", "strm", ",", "int", "flush", ")", "{", "int", "old_flush", ";", "if", "(", "flush", ">", "Z_FINISH", "||", "flush", "<", "0", ")", "{", "return", "Z_STREAM_ERROR", ";", "}", "if", "(", "strm", ".", "next_out", "==", "null", "||", "(", "strm", ".", "next_in", "==", "null", "&&", "strm", ".", "avail_in", "!=", "0", ")", "||", "(", "status", "==", "FINISH_STATE", "&&", "flush", "!=", "Z_FINISH", ")", ")", "{", "strm", ".", "msg", "=", "z_errmsg", "[", "Z_NEED_DICT", "-", "(", "Z_STREAM_ERROR", ")", "]", ";", "return", "Z_STREAM_ERROR", ";", "}", "if", "(", "strm", ".", "avail_out", "==", "0", ")", "{", "strm", ".", "msg", "=", "z_errmsg", "[", "Z_NEED_DICT", "-", "(", "Z_BUF_ERROR", ")", "]", ";", "return", "Z_BUF_ERROR", ";", "}", "this", ".", "strm", "=", "strm", ";", "old_flush", "=", "last_flush", ";", "last_flush", "=", "flush", ";", "if", "(", "status", "==", "INIT_STATE", ")", "{", "int", "header", "=", "(", "Z_DEFLATED", "+", "(", "(", "w_bits", "-", "8", ")", "<<", "4", ")", ")", "<<", "8", ";", "int", "level_flags", "=", "(", "(", "level", "-", "1", ")", "&", "0xff", ")", ">>", "1", ";", "if", "(", "level_flags", ">", "3", ")", "level_flags", "=", "3", ";", "header", "|=", "(", "level_flags", "<<", "6", ")", ";", "if", "(", "strstart", "!=", "0", ")", "header", "|=", "PRESET_DICT", ";", "header", "+=", "31", "-", "(", "header", "%", "31", ")", ";", "status", "=", "BUSY_STATE", ";", "putShortMSB", "(", "header", ")", ";", "if", "(", "strstart", "!=", "0", ")", "{", "putShortMSB", "(", "(", "int", ")", "(", "strm", ".", "adler", ">>>", "16", ")", ")", ";", "putShortMSB", "(", "(", "int", ")", "(", "strm", ".", "adler", "&", "0xffff", ")", ")", ";", "}", "strm", ".", "adler", "=", "strm", ".", "_adler", ".", "adler32", "(", "0", ",", "null", ",", "0", ",", "0", ")", ";", "}", "if", "(", "pending", "!=", "0", ")", "{", "strm", ".", "flush_pending", "(", ")", ";", "if", "(", "strm", ".", "avail_out", "==", "0", ")", "{", "last_flush", "=", "-", "1", ";", "return", "Z_OK", ";", "}", "}", "else", "if", "(", "strm", ".", "avail_in", "==", "0", "&&", "flush", "<=", "old_flush", "&&", "flush", "!=", "Z_FINISH", ")", "{", "strm", ".", "msg", "=", "z_errmsg", "[", "Z_NEED_DICT", "-", "(", "Z_BUF_ERROR", ")", "]", ";", "return", "Z_BUF_ERROR", ";", "}", "if", "(", "status", "==", "FINISH_STATE", "&&", "strm", ".", "avail_in", "!=", "0", ")", "{", "strm", ".", "msg", "=", "z_errmsg", "[", "Z_NEED_DICT", "-", "(", "Z_BUF_ERROR", ")", "]", ";", "return", "Z_BUF_ERROR", ";", "}", "if", "(", "strm", ".", "avail_in", "!=", "0", "||", "lookahead", "!=", "0", "||", "(", "flush", "!=", "Z_NO_FLUSH", "&&", "status", "!=", "FINISH_STATE", ")", ")", "{", "int", "bstate", "=", "-", "1", ";", "switch", "(", "config_table", "[", "level", "]", ".", "func", ")", "{", "case", "STORED", ":", "bstate", "=", "deflate_stored", "(", "flush", ")", ";", "break", ";", "case", "FAST", ":", "bstate", "=", "deflate_fast", "(", "flush", ")", ";", "break", ";", "case", "SLOW", ":", "bstate", "=", "deflate_slow", "(", "flush", ")", ";", "break", ";", "default", ":", "}", "if", "(", "bstate", "==", "FinishStarted", "||", "bstate", "==", "FinishDone", ")", "{", "status", "=", "FINISH_STATE", ";", "}", "if", "(", "bstate", "==", "NeedMore", "||", "bstate", "==", "FinishStarted", ")", "{", "if", "(", "strm", ".", "avail_out", "==", "0", ")", "{", "last_flush", "=", "-", "1", ";", "}", "return", "Z_OK", ";", "}", "if", "(", "bstate", "==", "BlockDone", ")", "{", "if", "(", "flush", "==", "Z_PARTIAL_FLUSH", ")", "{", "_tr_align", "(", ")", ";", "}", "else", "{", "_tr_stored_block", "(", "0", ",", "0", ",", "false", ")", ";", "if", "(", "flush", "==", "Z_FULL_FLUSH", ")", "{", "for", "(", "int", "i", "=", "0", ";", "i", "<", "hash_size", ";", "i", "++", ")", "head", "[", "i", "]", "=", "0", ";", "}", "}", "strm", ".", "flush_pending", "(", ")", ";", "if", "(", "strm", ".", "avail_out", "==", "0", ")", "{", "last_flush", "=", "-", "1", ";", "return", "Z_OK", ";", "}", "}", "}", "if", "(", "flush", "!=", "Z_FINISH", ")", "return", "Z_OK", ";", "if", "(", "noheader", "!=", "0", ")", "return", "Z_STREAM_END", ";", "putShortMSB", "(", "(", "int", ")", "(", "strm", ".", "adler", ">>>", "16", ")", ")", ";", "putShortMSB", "(", "(", "int", ")", "(", "strm", ".", "adler", "&", "0xffff", ")", ")", ";", "strm", ".", "flush_pending", "(", ")", ";", "noheader", "=", "-", "1", ";", "return", "pending", "!=", "0", "?", "Z_OK", ":", "Z_STREAM_END", ";", "}", "}", "</s>" ]
7,715
[ "<s>", "package", "com", ".", "jcraft", ".", "jzlib", ";", "import", "java", ".", "io", ".", "*", ";", "public", "class", "ZInputStream", "extends", "FilterInputStream", "{", "protected", "ZStream", "z", "=", "new", "ZStream", "(", ")", ";", "protected", "int", "bufsize", "=", "512", ";", "protected", "int", "flush", "=", "JZlib", ".", "Z_NO_FLUSH", ";", "protected", "byte", "[", "]", "buf", "=", "new", "byte", "[", "bufsize", "]", ",", "buf1", "=", "new", "byte", "[", "1", "]", ";", "protected", "boolean", "compress", ";", "protected", "InputStream", "in", "=", "null", ";", "public", "ZInputStream", "(", "InputStream", "in", ")", "{", "this", "(", "in", ",", "false", ")", ";", "}", "public", "ZInputStream", "(", "InputStream", "in", ",", "boolean", "nowrap", ")", "{", "super", "(", "in", ")", ";", "this", ".", "in", "=", "in", ";", "z", ".", "inflateInit", "(", "nowrap", ")", ";", "compress", "=", "false", ";", "z", ".", "next_in", "=", "buf", ";", "z", ".", "next_in_index", "=", "0", ";", "z", ".", "avail_in", "=", "0", ";", "}", "public", "ZInputStream", "(", "InputStream", "in", ",", "int", "level", ")", "{", "super", "(", "in", ")", ";", "this", ".", "in", "=", "in", ";", "z", ".", "deflateInit", "(", "level", ")", ";", "compress", "=", "true", ";", "z", ".", "next_in", "=", "buf", ";", "z", ".", "next_in_index", "=", "0", ";", "z", ".", "avail_in", "=", "0", ";", "}", "public", "int", "read", "(", ")", "throws", "IOException", "{", "if", "(", "read", "(", "buf1", ",", "0", ",", "1", ")", "==", "-", "1", ")", "return", "(", "-", "1", ")", ";", "return", "(", "buf1", "[", "0", "]", "&", "0xFF", ")", ";", "}", "private", "boolean", "nomoreinput", "=", "false", ";", "public", "int", "read", "(", "byte", "[", "]", "b", ",", "int", "off", ",", "int", "len", ")", "throws", "IOException", "{", "if", "(", "len", "==", "0", ")", "return", "(", "0", ")", ";", "int", "err", ";", "z", ".", "next_out", "=", "b", ";", "z", ".", "next_out_index", "=", "off", ";", "z", ".", "avail_out", "=", "len", ";", "do", "{", "if", "(", "(", "z", ".", "avail_in", "==", "0", ")", "&&", "(", "!", "nomoreinput", ")", ")", "{", "z", ".", "next_in_index", "=", "0", ";", "z", ".", "avail_in", "=", "in", ".", "read", "(", "buf", ",", "0", ",", "bufsize", ")", ";", "if", "(", "z", ".", "avail_in", "==", "-", "1", ")", "{", "z", ".", "avail_in", "=", "0", ";", "nomoreinput", "=", "true", ";", "}", "}", "if", "(", "compress", ")", "err", "=", "z", ".", "deflate", "(", "flush", ")", ";", "else", "err", "=", "z", ".", "inflate", "(", "flush", ")", ";", "if", "(", "nomoreinput", "&&", "(", "err", "==", "JZlib", ".", "Z_BUF_ERROR", ")", ")", "return", "(", "-", "1", ")", ";", "if", "(", "err", "!=", "JZlib", ".", "Z_OK", "&&", "err", "!=", "JZlib", ".", "Z_STREAM_END", ")", "throw", "new", "ZStreamException", "(", "(", "compress", "?", "\"de\"", ":", "\"in\"", ")", "+", "\"flating:", "\"", "+", "z", ".", "msg", ")", ";", "if", "(", "(", "nomoreinput", "||", "err", "==", "JZlib", ".", "Z_STREAM_END", ")", "&&", "(", "z", ".", "avail_out", "==", "len", ")", ")", "return", "(", "-", "1", ")", ";", "}", "while", "(", "z", ".", "avail_out", "==", "len", "&&", "err", "==", "JZlib", ".", "Z_OK", ")", ";", "return", "(", "len", "-", "z", ".", "avail_out", ")", ";", "}", "public", "long", "skip", "(", "long", "n", ")", "throws", "IOException", "{", "int", "len", "=", "512", ";", "if", "(", "n", "<", "len", ")", "len", "=", "(", "int", ")", "n", ";", "byte", "[", "]", "tmp", "=", "new", "byte", "[", "len", "]", ";", "return", "(", "(", "long", ")", "read", "(", "tmp", ")", ")", ";", "}", "public", "int", "getFlushMode", "(", ")", "{", "return", "(", "flush", ")", ";", "}", "public", "void", "setFlushMode", "(", "int", "flush", ")", "{", "this", ".", "flush", "=", "flush", ";", "}", "public", "long", "getTotalIn", "(", ")", "{", "return", "z", ".", "total_in", ";", "}", "public", "long", "getTotalOut", "(", ")", "{", "return", "z", ".", "total_out", ";", "}", "public", "void", "close", "(", ")", "throws", "IOException", "{", "in", ".", "close", "(", ")", ";", "}", "}", "</s>" ]
7,716
[ "<s>", "package", "com", ".", "jcraft", ".", "jzlib", ";", "public", "class", "ZStreamException", "extends", "java", ".", "io", ".", "IOException", "{", "public", "ZStreamException", "(", ")", "{", "super", "(", ")", ";", "}", "public", "ZStreamException", "(", "String", "s", ")", "{", "super", "(", "s", ")", ";", "}", "}", "</s>" ]
7,717
[ "<s>", "package", "com", ".", "jcraft", ".", "jzlib", ";", "final", "class", "StaticTree", "{", "static", "final", "private", "int", "MAX_BITS", "=", "15", ";", "static", "final", "private", "int", "BL_CODES", "=", "19", ";", "static", "final", "private", "int", "D_CODES", "=", "30", ";", "static", "final", "private", "int", "LITERALS", "=", "256", ";", "static", "final", "private", "int", "LENGTH_CODES", "=", "29", ";", "static", "final", "private", "int", "L_CODES", "=", "(", "LITERALS", "+", "1", "+", "LENGTH_CODES", ")", ";", "static", "final", "int", "MAX_BL_BITS", "=", "7", ";", "static", "final", "short", "[", "]", "static_ltree", "=", "{", "12", ",", "8", ",", "140", ",", "8", ",", "76", ",", "8", ",", "204", ",", "8", ",", "44", ",", "8", ",", "172", ",", "8", ",", "108", ",", "8", ",", "236", ",", "8", ",", "28", ",", "8", ",", "156", ",", "8", ",", "92", ",", "8", ",", "220", ",", "8", ",", "60", ",", "8", ",", "188", ",", "8", ",", "124", ",", "8", ",", "252", ",", "8", ",", "2", ",", "8", ",", "130", ",", "8", ",", "66", ",", "8", ",", "194", ",", "8", ",", "34", ",", "8", ",", "162", ",", "8", ",", "98", ",", "8", ",", "226", ",", "8", ",", "18", ",", "8", ",", "146", ",", "8", ",", "82", ",", "8", ",", "210", ",", "8", ",", "50", ",", "8", ",", "178", ",", "8", ",", "114", ",", "8", ",", "242", ",", "8", ",", "10", ",", "8", ",", "138", ",", "8", ",", "74", ",", "8", ",", "202", ",", "8", ",", "42", ",", "8", ",", "170", ",", "8", ",", "106", ",", "8", ",", "234", ",", "8", ",", "26", ",", "8", ",", "154", ",", "8", ",", "90", ",", "8", ",", "218", ",", "8", ",", "58", ",", "8", ",", "186", ",", "8", ",", "122", ",", "8", ",", "250", ",", "8", ",", "6", ",", "8", ",", "134", ",", "8", ",", "70", ",", "8", ",", "198", ",", "8", ",", "38", ",", "8", ",", "166", ",", "8", ",", "102", ",", "8", ",", "230", ",", "8", ",", "22", ",", "8", ",", "150", ",", "8", ",", "86", ",", "8", ",", "214", ",", "8", ",", "54", ",", "8", ",", "182", ",", "8", ",", "118", ",", "8", ",", "246", ",", "8", ",", "14", ",", "8", ",", "142", ",", "8", ",", "78", ",", "8", ",", "206", ",", "8", ",", "46", ",", "8", ",", "174", ",", "8", ",", "110", ",", "8", ",", "238", ",", "8", ",", "30", ",", "8", ",", "158", ",", "8", ",", "94", ",", "8", ",", "222", ",", "8", ",", "62", ",", "8", ",", "190", ",", "8", ",", "126", ",", "8", ",", "254", ",", "8", ",", "1", ",", "8", ",", "129", ",", "8", ",", "65", ",", "8", ",", "193", ",", "8", ",", "33", ",", "8", ",", "161", ",", "8", ",", "97", ",", "8", ",", "225", ",", "8", ",", "17", ",", "8", ",", "145", ",", "8", ",", "81", ",", "8", ",", "209", ",", "8", ",", "49", ",", "8", ",", "177", ",", "8", ",", "113", ",", "8", ",", "241", ",", "8", ",", "9", ",", "8", ",", "137", ",", "8", ",", "73", ",", "8", ",", "201", ",", "8", ",", "41", ",", "8", ",", "169", ",", "8", ",", "105", ",", "8", ",", "233", ",", "8", ",", "25", ",", "8", ",", "153", ",", "8", ",", "89", ",", "8", ",", "217", ",", "8", ",", "57", ",", "8", ",", "185", ",", "8", ",", "121", ",", "8", ",", "249", ",", "8", ",", "5", ",", "8", ",", "133", ",", "8", ",", "69", ",", "8", ",", "197", ",", "8", ",", "37", ",", "8", ",", "165", ",", "8", ",", "101", ",", "8", ",", "229", ",", "8", ",", "21", ",", "8", ",", "149", ",", "8", ",", "85", ",", "8", ",", "213", ",", "8", ",", "53", ",", "8", ",", "181", ",", "8", ",", "117", ",", "8", ",", "245", ",", "8", ",", "13", ",", "8", ",", "141", ",", "8", ",", "77", ",", "8", ",", "205", ",", "8", ",", "45", ",", "8", ",", "173", ",", "8", ",", "109", ",", "8", ",", "237", ",", "8", ",", "29", ",", "8", ",", "157", ",", "8", ",", "93", ",", "8", ",", "221", ",", "8", ",", "61", ",", "8", ",", "189", ",", "8", ",", "125", ",", "8", ",", "253", ",", "8", ",", "19", ",", "9", ",", "275", ",", "9", ",", "147", ",", "9", ",", "403", ",", "9", ",", "83", ",", "9", ",", "339", ",", "9", ",", "211", ",", "9", ",", "467", ",", "9", ",", "51", ",", "9", ",", "307", ",", "9", ",", "179", ",", "9", ",", "435", ",", "9", ",", "115", ",", "9", ",", "371", ",", "9", ",", "243", ",", "9", ",", "499", ",", "9", ",", "11", ",", "9", ",", "267", ",", "9", ",", "139", ",", "9", ",", "395", ",", "9", ",", "75", ",", "9", ",", "331", ",", "9", ",", "203", ",", "9", ",", "459", ",", "9", ",", "43", ",", "9", ",", "299", ",", "9", ",", "171", ",", "9", ",", "427", ",", "9", ",", "107", ",", "9", ",", "363", ",", "9", ",", "235", ",", "9", ",", "491", ",", "9", ",", "27", ",", "9", ",", "283", ",", "9", ",", "155", ",", "9", ",", "411", ",", "9", ",", "91", ",", "9", ",", "347", ",", "9", ",", "219", ",", "9", ",", "475", ",", "9", ",", "59", ",", "9", ",", "315", ",", "9", ",", "187", ",", "9", ",", "443", ",", "9", ",", "123", ",", "9", ",", "379", ",", "9", ",", "251", ",", "9", ",", "507", ",", "9", ",", "7", ",", "9", ",", "263", ",", "9", ",", "135", ",", "9", ",", "391", ",", "9", ",", "71", ",", "9", ",", "327", ",", "9", ",", "199", ",", "9", ",", "455", ",", "9", ",", "39", ",", "9", ",", "295", ",", "9", ",", "167", ",", "9", ",", "423", ",", "9", ",", "103", ",", "9", ",", "359", ",", "9", ",", "231", ",", "9", ",", "487", ",", "9", ",", "23", ",", "9", ",", "279", ",", "9", ",", "151", ",", "9", ",", "407", ",", "9", ",", "87", ",", "9", ",", "343", ",", "9", ",", "215", ",", "9", ",", "471", ",", "9", ",", "55", ",", "9", ",", "311", ",", "9", ",", "183", ",", "9", ",", "439", ",", "9", ",", "119", ",", "9", ",", "375", ",", "9", ",", "247", ",", "9", ",", "503", ",", "9", ",", "15", ",", "9", ",", "271", ",", "9", ",", "143", ",", "9", ",", "399", ",", "9", ",", "79", ",", "9", ",", "335", ",", "9", ",", "207", ",", "9", ",", "463", ",", "9", ",", "47", ",", "9", ",", "303", ",", "9", ",", "175", ",", "9", ",", "431", ",", "9", ",", "111", ",", "9", ",", "367", ",", "9", ",", "239", ",", "9", ",", "495", ",", "9", ",", "31", ",", "9", ",", "287", ",", "9", ",", "159", ",", "9", ",", "415", ",", "9", ",", "95", ",", "9", ",", "351", ",", "9", ",", "223", ",", "9", ",", "479", ",", "9", ",", "63", ",", "9", ",", "319", ",", "9", ",", "191", ",", "9", ",", "447", ",", "9", ",", "127", ",", "9", ",", "383", ",", "9", ",", "255", ",", "9", ",", "511", ",", "9", ",", "0", ",", "7", ",", "64", ",", "7", ",", "32", ",", "7", ",", "96", ",", "7", ",", "16", ",", "7", ",", "80", ",", "7", ",", "48", ",", "7", ",", "112", ",", "7", ",", "8", ",", "7", ",", "72", ",", "7", ",", "40", ",", "7", ",", "104", ",", "7", ",", "24", ",", "7", ",", "88", ",", "7", ",", "56", ",", "7", ",", "120", ",", "7", ",", "4", ",", "7", ",", "68", ",", "7", ",", "36", ",", "7", ",", "100", ",", "7", ",", "20", ",", "7", ",", "84", ",", "7", ",", "52", ",", "7", ",", "116", ",", "7", ",", "3", ",", "8", ",", "131", ",", "8", ",", "67", ",", "8", ",", "195", ",", "8", ",", "35", ",", "8", ",", "163", ",", "8", ",", "99", ",", "8", ",", "227", ",", "8", "}", ";", "static", "final", "short", "[", "]", "static_dtree", "=", "{", "0", ",", "5", ",", "16", ",", "5", ",", "8", ",", "5", ",", "24", ",", "5", ",", "4", ",", "5", ",", "20", ",", "5", ",", "12", ",", "5", ",", "28", ",", "5", ",", "2", ",", "5", ",", "18", ",", "5", ",", "10", ",", "5", ",", "26", ",", "5", ",", "6", ",", "5", ",", "22", ",", "5", ",", "14", ",", "5", ",", "30", ",", "5", ",", "1", ",", "5", ",", "17", ",", "5", ",", "9", ",", "5", ",", "25", ",", "5", ",", "5", ",", "5", ",", "21", ",", "5", ",", "13", ",", "5", ",", "29", ",", "5", ",", "3", ",", "5", ",", "19", ",", "5", ",", "11", ",", "5", ",", "27", ",", "5", ",", "7", ",", "5", ",", "23", ",", "5", "}", ";", "static", "StaticTree", "static_l_desc", "=", "new", "StaticTree", "(", "static_ltree", ",", "Tree", ".", "extra_lbits", ",", "LITERALS", "+", "1", ",", "L_CODES", ",", "MAX_BITS", ")", ";", "static", "StaticTree", "static_d_desc", "=", "new", "StaticTree", "(", "static_dtree", ",", "Tree", ".", "extra_dbits", ",", "0", ",", "D_CODES", ",", "MAX_BITS", ")", ";", "static", "StaticTree", "static_bl_desc", "=", "new", "StaticTree", "(", "null", ",", "Tree", ".", "extra_blbits", ",", "0", ",", "BL_CODES", ",", "MAX_BL_BITS", ")", ";", "short", "[", "]", "static_tree", ";", "int", "[", "]", "extra_bits", ";", "int", "extra_base", ";", "int", "elems", ";", "int", "max_length", ";", "StaticTree", "(", "short", "[", "]", "static_tree", ",", "int", "[", "]", "extra_bits", ",", "int", "extra_base", ",", "int", "elems", ",", "int", "max_length", ")", "{", "this", ".", "static_tree", "=", "static_tree", ";", "this", ".", "extra_bits", "=", "extra_bits", ";", "this", ".", "extra_base", "=", "extra_base", ";", "this", ".", "elems", "=", "elems", ";", "this", ".", "max_length", "=", "max_length", ";", "}", "}", "</s>" ]
7,718
[ "<s>", "package", "com", ".", "jcraft", ".", "jzlib", ";", "final", "class", "Tree", "{", "static", "final", "private", "int", "MAX_BITS", "=", "15", ";", "static", "final", "private", "int", "BL_CODES", "=", "19", ";", "static", "final", "private", "int", "D_CODES", "=", "30", ";", "static", "final", "private", "int", "LITERALS", "=", "256", ";", "static", "final", "private", "int", "LENGTH_CODES", "=", "29", ";", "static", "final", "private", "int", "L_CODES", "=", "(", "LITERALS", "+", "1", "+", "LENGTH_CODES", ")", ";", "static", "final", "private", "int", "HEAP_SIZE", "=", "(", "2", "*", "L_CODES", "+", "1", ")", ";", "static", "final", "int", "MAX_BL_BITS", "=", "7", ";", "static", "final", "int", "END_BLOCK", "=", "256", ";", "static", "final", "int", "REP_3_6", "=", "16", ";", "static", "final", "int", "REPZ_3_10", "=", "17", ";", "static", "final", "int", "REPZ_11_138", "=", "18", ";", "static", "final", "int", "[", "]", "extra_lbits", "=", "{", "0", ",", "0", ",", "0", ",", "0", ",", "0", ",", "0", ",", "0", ",", "0", ",", "1", ",", "1", ",", "1", ",", "1", ",", "2", ",", "2", ",", "2", ",", "2", ",", "3", ",", "3", ",", "3", ",", "3", ",", "4", ",", "4", ",", "4", ",", "4", ",", "5", ",", "5", ",", "5", ",", "5", ",", "0", "}", ";", "static", "final", "int", "[", "]", "extra_dbits", "=", "{", "0", ",", "0", ",", "0", ",", "0", ",", "1", ",", "1", ",", "2", ",", "2", ",", "3", ",", "3", ",", "4", ",", "4", ",", "5", ",", "5", ",", "6", ",", "6", ",", "7", ",", "7", ",", "8", ",", "8", ",", "9", ",", "9", ",", "10", ",", "10", ",", "11", ",", "11", ",", "12", ",", "12", ",", "13", ",", "13", "}", ";", "static", "final", "int", "[", "]", "extra_blbits", "=", "{", "0", ",", "0", ",", "0", ",", "0", ",", "0", ",", "0", ",", "0", ",", "0", ",", "0", ",", "0", ",", "0", ",", "0", ",", "0", ",", "0", ",", "0", ",", "0", ",", "2", ",", "3", ",", "7", "}", ";", "static", "final", "byte", "[", "]", "bl_order", "=", "{", "16", ",", "17", ",", "18", ",", "0", ",", "8", ",", "7", ",", "9", ",", "6", ",", "10", ",", "5", ",", "11", ",", "4", ",", "12", ",", "3", ",", "13", ",", "2", ",", "14", ",", "1", ",", "15", "}", ";", "static", "final", "int", "Buf_size", "=", "8", "*", "2", ";", "static", "final", "int", "DIST_CODE_LEN", "=", "512", ";", "static", "final", "byte", "[", "]", "_dist_code", "=", "{", "0", ",", "1", ",", "2", ",", "3", ",", "4", ",", "4", ",", "5", ",", "5", ",", "6", ",", "6", ",", "6", ",", "6", ",", "7", ",", "7", ",", "7", ",", "7", ",", "8", ",", "8", ",", "8", ",", "8", ",", "8", ",", "8", ",", "8", ",", "8", ",", "9", ",", "9", ",", "9", ",", "9", ",", "9", ",", "9", ",", "9", ",", "9", ",", "10", ",", "10", ",", "10", ",", "10", ",", "10", ",", "10", ",", "10", ",", "10", ",", "10", ",", "10", ",", "10", ",", "10", ",", "10", ",", "10", ",", "10", ",", "10", ",", "11", ",", "11", ",", "11", ",", "11", ",", "11", ",", "11", ",", "11", ",", "11", ",", "11", ",", "11", ",", "11", ",", "11", ",", "11", ",", "11", ",", "11", ",", "11", ",", "12", ",", "12", ",", "12", ",", "12", ",", "12", ",", "12", ",", "12", ",", "12", ",", "12", ",", "12", ",", "12", ",", "12", ",", "12", ",", "12", ",", "12", ",", "12", ",", "12", ",", "12", ",", "12", ",", "12", ",", "12", ",", "12", ",", "12", ",", "12", ",", "12", ",", "12", ",", "12", ",", "12", ",", "12", ",", "12", ",", "12", ",", "12", ",", "13", ",", "13", ",", "13", ",", "13", ",", "13", ",", "13", ",", "13", ",", "13", ",", "13", ",", "13", ",", "13", ",", "13", ",", "13", ",", "13", ",", "13", ",", "13", ",", "13", ",", "13", ",", "13", ",", "13", ",", "13", ",", "13", ",", "13", ",", "13", ",", "13", ",", "13", ",", "13", ",", "13", ",", "13", ",", "13", ",", "13", ",", "13", ",", "14", ",", "14", ",", "14", ",", "14", ",", "14", ",", "14", ",", "14", ",", "14", ",", "14", ",", "14", ",", "14", ",", "14", ",", "14", ",", "14", ",", "14", ",", "14", ",", "14", ",", "14", ",", "14", ",", "14", ",", "14", ",", "14", ",", "14", ",", "14", ",", "14", ",", "14", ",", "14", ",", "14", ",", "14", ",", "14", ",", "14", ",", "14", ",", "14", ",", "14", ",", "14", ",", "14", ",", "14", ",", "14", ",", "14", ",", "14", ",", "14", ",", "14", ",", "14", ",", "14", ",", "14", ",", "14", ",", "14", ",", "14", ",", "14", ",", "14", ",", "14", ",", "14", ",", "14", ",", "14", ",", "14", ",", "14", ",", "14", ",", "14", ",", "14", ",", "14", ",", "14", ",", "14", ",", "14", ",", "14", ",", "15", ",", "15", ",", "15", ",", "15", ",", "15", ",", "15", ",", "15", ",", "15", ",", "15", ",", "15", ",", "15", ",", "15", ",", "15", ",", "15", ",", "15", ",", "15", ",", "15", ",", "15", ",", "15", ",", "15", ",", "15", ",", "15", ",", "15", ",", "15", ",", "15", ",", "15", ",", "15", ",", "15", ",", "15", ",", "15", ",", "15", ",", "15", ",", "15", ",", "15", ",", "15", ",", "15", ",", "15", ",", "15", ",", "15", ",", "15", ",", "15", ",", "15", ",", "15", ",", "15", ",", "15", ",", "15", ",", "15", ",", "15", ",", "15", ",", "15", ",", "15", ",", "15", ",", "15", ",", "15", ",", "15", ",", "15", ",", "15", ",", "15", ",", "15", ",", "15", ",", "15", ",", "15", ",", "15", ",", "15", ",", "0", ",", "0", ",", "16", ",", "17", ",", "18", ",", "18", ",", "19", ",", "19", ",", "20", ",", "20", ",", "20", ",", "20", ",", "21", ",", "21", ",", "21", ",", "21", ",", "22", ",", "22", ",", "22", ",", "22", ",", "22", ",", "22", ",", "22", ",", "22", ",", "23", ",", "23", ",", "23", ",", "23", ",", "23", ",", "23", ",", "23", ",", "23", ",", "24", ",", "24", ",", "24", ",", "24", ",", "24", ",", "24", ",", "24", ",", "24", ",", "24", ",", "24", ",", "24", ",", "24", ",", "24", ",", "24", ",", "24", ",", "24", ",", "25", ",", "25", ",", "25", ",", "25", ",", "25", ",", "25", ",", "25", ",", "25", ",", "25", ",", "25", ",", "25", ",", "25", ",", "25", ",", "25", ",", "25", ",", "25", ",", "26", ",", "26", ",", "26", ",", "26", ",", "26", ",", "26", ",", "26", ",", "26", ",", "26", ",", "26", ",", "26", ",", "26", ",", "26", ",", "26", ",", "26", ",", "26", ",", "26", ",", "26", ",", "26", ",", "26", ",", "26", ",", "26", ",", "26", ",", "26", ",", "26", ",", "26", ",", "26", ",", "26", ",", "26", ",", "26", ",", "26", ",", "26", ",", "27", ",", "27", ",", "27", ",", "27", ",", "27", ",", "27", ",", "27", ",", "27", ",", "27", ",", "27", ",", "27", ",", "27", ",", "27", ",", "27", ",", "27", ",", "27", ",", "27", ",", "27", ",", "27", ",", "27", ",", "27", ",", "27", ",", "27", ",", "27", ",", "27", ",", "27", ",", "27", ",", "27", ",", "27", ",", "27", ",", "27", ",", "27", ",", "28", ",", "28", ",", "28", ",", "28", ",", "28", ",", "28", ",", "28", ",", "28", ",", "28", ",", "28", ",", "28", ",", "28", ",", "28", ",", "28", ",", "28", ",", "28", ",", "28", ",", "28", ",", "28", ",", "28", ",", "28", ",", "28", ",", "28", ",", "28", ",", "28", ",", "28", ",", "28", ",", "28", ",", "28", ",", "28", ",", "28", ",", "28", ",", "28", ",", "28", ",", "28", ",", "28", ",", "28", ",", "28", ",", "28", ",", "28", ",", "28", ",", "28", ",", "28", ",", "28", ",", "28", ",", "28", ",", "28", ",", "28", ",", "28", ",", "28", ",", "28", ",", "28", ",", "28", ",", "28", ",", "28", ",", "28", ",", "28", ",", "28", ",", "28", ",", "28", ",", "28", ",", "28", ",", "28", ",", "28", ",", "29", ",", "29", ",", "29", ",", "29", ",", "29", ",", "29", ",", "29", ",", "29", ",", "29", ",", "29", ",", "29", ",", "29", ",", "29", ",", "29", ",", "29", ",", "29", ",", "29", ",", "29", ",", "29", ",", "29", ",", "29", ",", "29", ",", "29", ",", "29", ",", "29", ",", "29", ",", "29", ",", "29", ",", "29", ",", "29", ",", "29", ",", "29", ",", "29", ",", "29", ",", "29", ",", "29", ",", "29", ",", "29", ",", "29", ",", "29", ",", "29", ",", "29", ",", "29", ",", "29", ",", "29", ",", "29", ",", "29", ",", "29", ",", "29", ",", "29", ",", "29", ",", "29", ",", "29", ",", "29", ",", "29", ",", "29", ",", "29", ",", "29", ",", "29", ",", "29", ",", "29", ",", "29", ",", "29", ",", "29", "}", ";", "static", "final", "byte", "[", "]", "_length_code", "=", "{", "0", ",", "1", ",", "2", ",", "3", ",", "4", ",", "5", ",", "6", ",", "7", ",", "8", ",", "8", ",", "9", ",", "9", ",", "10", ",", "10", ",", "11", ",", "11", ",", "12", ",", "12", ",", "12", ",", "12", ",", "13", ",", "13", ",", "13", ",", "13", ",", "14", ",", "14", ",", "14", ",", "14", ",", "15", ",", "15", ",", "15", ",", "15", ",", "16", ",", "16", ",", "16", ",", "16", ",", "16", ",", "16", ",", "16", ",", "16", ",", "17", ",", "17", ",", "17", ",", "17", ",", "17", ",", "17", ",", "17", ",", "17", ",", "18", ",", "18", ",", "18", ",", "18", ",", "18", ",", "18", ",", "18", ",", "18", ",", "19", ",", "19", ",", "19", ",", "19", ",", "19", ",", "19", ",", "19", ",", "19", ",", "20", ",", "20", ",", "20", ",", "20", ",", "20", ",", "20", ",", "20", ",", "20", ",", "20", ",", "20", ",", "20", ",", "20", ",", "20", ",", "20", ",", "20", ",", "20", ",", "21", ",", "21", ",", "21", ",", "21", ",", "21", ",", "21", ",", "21", ",", "21", ",", "21", ",", "21", ",", "21", ",", "21", ",", "21", ",", "21", ",", "21", ",", "21", ",", "22", ",", "22", ",", "22", ",", "22", ",", "22", ",", "22", ",", "22", ",", "22", ",", "22", ",", "22", ",", "22", ",", "22", ",", "22", ",", "22", ",", "22", ",", "22", ",", "23", ",", "23", ",", "23", ",", "23", ",", "23", ",", "23", ",", "23", ",", "23", ",", "23", ",", "23", ",", "23", ",", "23", ",", "23", ",", "23", ",", "23", ",", "23", ",", "24", ",", "24", ",", "24", ",", "24", ",", "24", ",", "24", ",", "24", ",", "24", ",", "24", ",", "24", ",", "24", ",", "24", ",", "24", ",", "24", ",", "24", ",", "24", ",", "24", ",", "24", ",", "24", ",", "24", ",", "24", ",", "24", ",", "24", ",", "24", ",", "24", ",", "24", ",", "24", ",", "24", ",", "24", ",", "24", ",", "24", ",", "24", ",", "25", ",", "25", ",", "25", ",", "25", ",", "25", ",", "25", ",", "25", ",", "25", ",", "25", ",", "25", ",", "25", ",", "25", ",", "25", ",", "25", ",", "25", ",", "25", ",", "25", ",", "25", ",", "25", ",", "25", ",", "25", ",", "25", ",", "25", ",", "25", ",", "25", ",", "25", ",", "25", ",", "25", ",", "25", ",", "25", ",", "25", ",", "25", ",", "26", ",", "26", ",", "26", ",", "26", ",", "26", ",", "26", ",", "26", ",", "26", ",", "26", ",", "26", ",", "26", ",", "26", ",", "26", ",", "26", ",", "26", ",", "26", ",", "26", ",", "26", ",", "26", ",", "26", ",", "26", ",", "26", ",", "26", ",", "26", ",", "26", ",", "26", ",", "26", ",", "26", ",", "26", ",", "26", ",", "26", ",", "26", ",", "27", ",", "27", ",", "27", ",", "27", ",", "27", ",", "27", ",", "27", ",", "27", ",", "27", ",", "27", ",", "27", ",", "27", ",", "27", ",", "27", ",", "27", ",", "27", ",", "27", ",", "27", ",", "27", ",", "27", ",", "27", ",", "27", ",", "27", ",", "27", ",", "27", ",", "27", ",", "27", ",", "27", ",", "27", ",", "27", ",", "27", ",", "28", "}", ";", "static", "final", "int", "[", "]", "base_length", "=", "{", "0", ",", "1", ",", "2", ",", "3", ",", "4", ",", "5", ",", "6", ",", "7", ",", "8", ",", "10", ",", "12", ",", "14", ",", "16", ",", "20", ",", "24", ",", "28", ",", "32", ",", "40", ",", "48", ",", "56", ",", "64", ",", "80", ",", "96", ",", "112", ",", "128", ",", "160", ",", "192", ",", "224", ",", "0", "}", ";", "static", "final", "int", "[", "]", "base_dist", "=", "{", "0", ",", "1", ",", "2", ",", "3", ",", "4", ",", "6", ",", "8", ",", "12", ",", "16", ",", "24", ",", "32", ",", "48", ",", "64", ",", "96", ",", "128", ",", "192", ",", "256", ",", "384", ",", "512", ",", "768", ",", "1024", ",", "1536", ",", "2048", ",", "3072", ",", "4096", ",", "6144", ",", "8192", ",", "12288", ",", "16384", ",", "24576", "}", ";", "static", "int", "d_code", "(", "int", "dist", ")", "{", "return", "(", "(", "dist", ")", "<", "256", "?", "_dist_code", "[", "dist", "]", ":", "_dist_code", "[", "256", "+", "(", "(", "dist", ")", ">>>", "7", ")", "]", ")", ";", "}", "short", "[", "]", "dyn_tree", ";", "int", "max_code", ";", "StaticTree", "stat_desc", ";", "void", "gen_bitlen", "(", "Deflate", "s", ")", "{", "short", "[", "]", "tree", "=", "dyn_tree", ";", "short", "[", "]", "stree", "=", "stat_desc", ".", "static_tree", ";", "int", "[", "]", "extra", "=", "stat_desc", ".", "extra_bits", ";", "int", "base", "=", "stat_desc", ".", "extra_base", ";", "int", "max_length", "=", "stat_desc", ".", "max_length", ";", "int", "h", ";", "int", "n", ",", "m", ";", "int", "bits", ";", "int", "xbits", ";", "short", "f", ";", "int", "overflow", "=", "0", ";", "for", "(", "bits", "=", "0", ";", "bits", "<=", "MAX_BITS", ";", "bits", "++", ")", "s", ".", "bl_count", "[", "bits", "]", "=", "0", ";", "tree", "[", "s", ".", "heap", "[", "s", ".", "heap_max", "]", "*", "2", "+", "1", "]", "=", "0", ";", "for", "(", "h", "=", "s", ".", "heap_max", "+", "1", ";", "h", "<", "HEAP_SIZE", ";", "h", "++", ")", "{", "n", "=", "s", ".", "heap", "[", "h", "]", ";", "bits", "=", "tree", "[", "tree", "[", "n", "*", "2", "+", "1", "]", "*", "2", "+", "1", "]", "+", "1", ";", "if", "(", "bits", ">", "max_length", ")", "{", "bits", "=", "max_length", ";", "overflow", "++", ";", "}", "tree", "[", "n", "*", "2", "+", "1", "]", "=", "(", "short", ")", "bits", ";", "if", "(", "n", ">", "max_code", ")", "continue", ";", "s", ".", "bl_count", "[", "bits", "]", "++", ";", "xbits", "=", "0", ";", "if", "(", "n", ">=", "base", ")", "xbits", "=", "extra", "[", "n", "-", "base", "]", ";", "f", "=", "tree", "[", "n", "*", "2", "]", ";", "s", ".", "opt_len", "+=", "f", "*", "(", "bits", "+", "xbits", ")", ";", "if", "(", "stree", "!=", "null", ")", "s", ".", "static_len", "+=", "f", "*", "(", "stree", "[", "n", "*", "2", "+", "1", "]", "+", "xbits", ")", ";", "}", "if", "(", "overflow", "==", "0", ")", "return", ";", "do", "{", "bits", "=", "max_length", "-", "1", ";", "while", "(", "s", ".", "bl_count", "[", "bits", "]", "==", "0", ")", "bits", "--", ";", "s", ".", "bl_count", "[", "bits", "]", "--", ";", "s", ".", "bl_count", "[", "bits", "+", "1", "]", "+=", "2", ";", "s", ".", "bl_count", "[", "max_length", "]", "--", ";", "overflow", "-=", "2", ";", "}", "while", "(", "overflow", ">", "0", ")", ";", "for", "(", "bits", "=", "max_length", ";", "bits", "!=", "0", ";", "bits", "--", ")", "{", "n", "=", "s", ".", "bl_count", "[", "bits", "]", ";", "while", "(", "n", "!=", "0", ")", "{", "m", "=", "s", ".", "heap", "[", "--", "h", "]", ";", "if", "(", "m", ">", "max_code", ")", "continue", ";", "if", "(", "tree", "[", "m", "*", "2", "+", "1", "]", "!=", "bits", ")", "{", "s", ".", "opt_len", "+=", "(", "(", "long", ")", "bits", "-", "(", "long", ")", "tree", "[", "m", "*", "2", "+", "1", "]", ")", "*", "(", "long", ")", "tree", "[", "m", "*", "2", "]", ";", "tree", "[", "m", "*", "2", "+", "1", "]", "=", "(", "short", ")", "bits", ";", "}", "n", "--", ";", "}", "}", "}", "void", "build_tree", "(", "Deflate", "s", ")", "{", "short", "[", "]", "tree", "=", "dyn_tree", ";", "short", "[", "]", "stree", "=", "stat_desc", ".", "static_tree", ";", "int", "elems", "=", "stat_desc", ".", "elems", ";", "int", "n", ",", "m", ";", "int", "max_code", "=", "-", "1", ";", "int", "node", ";", "s", ".", "heap_len", "=", "0", ";", "s", ".", "heap_max", "=", "HEAP_SIZE", ";", "for", "(", "n", "=", "0", ";", "n", "<", "elems", ";", "n", "++", ")", "{", "if", "(", "tree", "[", "n", "*", "2", "]", "!=", "0", ")", "{", "s", ".", "heap", "[", "++", "s", ".", "heap_len", "]", "=", "max_code", "=", "n", ";", "s", ".", "depth", "[", "n", "]", "=", "0", ";", "}", "else", "{", "tree", "[", "n", "*", "2", "+", "1", "]", "=", "0", ";", "}", "}", "while", "(", "s", ".", "heap_len", "<", "2", ")", "{", "node", "=", "s", ".", "heap", "[", "++", "s", ".", "heap_len", "]", "=", "(", "max_code", "<", "2", "?", "++", "max_code", ":", "0", ")", ";", "tree", "[", "node", "*", "2", "]", "=", "1", ";", "s", ".", "depth", "[", "node", "]", "=", "0", ";", "s", ".", "opt_len", "--", ";", "if", "(", "stree", "!=", "null", ")", "s", ".", "static_len", "-=", "stree", "[", "node", "*", "2", "+", "1", "]", ";", "}", "this", ".", "max_code", "=", "max_code", ";", "for", "(", "n", "=", "s", ".", "heap_len", "/", "2", ";", "n", ">=", "1", ";", "n", "--", ")", "s", ".", "pqdownheap", "(", "tree", ",", "n", ")", ";", "node", "=", "elems", ";", "do", "{", "n", "=", "s", ".", "heap", "[", "1", "]", ";", "s", ".", "heap", "[", "1", "]", "=", "s", ".", "heap", "[", "s", ".", "heap_len", "--", "]", ";", "s", ".", "pqdownheap", "(", "tree", ",", "1", ")", ";", "m", "=", "s", ".", "heap", "[", "1", "]", ";", "s", ".", "heap", "[", "--", "s", ".", "heap_max", "]", "=", "n", ";", "s", ".", "heap", "[", "--", "s", ".", "heap_max", "]", "=", "m", ";", "tree", "[", "node", "*", "2", "]", "=", "(", "short", ")", "(", "tree", "[", "n", "*", "2", "]", "+", "tree", "[", "m", "*", "2", "]", ")", ";", "s", ".", "depth", "[", "node", "]", "=", "(", "byte", ")", "(", "Math", ".", "max", "(", "s", ".", "depth", "[", "n", "]", ",", "s", ".", "depth", "[", "m", "]", ")", "+", "1", ")", ";", "tree", "[", "n", "*", "2", "+", "1", "]", "=", "tree", "[", "m", "*", "2", "+", "1", "]", "=", "(", "short", ")", "node", ";", "s", ".", "heap", "[", "1", "]", "=", "node", "++", ";", "s", ".", "pqdownheap", "(", "tree", ",", "1", ")", ";", "}", "while", "(", "s", ".", "heap_len", ">=", "2", ")", ";", "s", ".", "heap", "[", "--", "s", ".", "heap_max", "]", "=", "s", ".", "heap", "[", "1", "]", ";", "gen_bitlen", "(", "s", ")", ";", "gen_codes", "(", "tree", ",", "max_code", ",", "s", ".", "bl_count", ")", ";", "}", "static", "void", "gen_codes", "(", "short", "[", "]", "tree", ",", "int", "max_code", ",", "short", "[", "]", "bl_count", ")", "{", "short", "[", "]", "next_code", "=", "new", "short", "[", "MAX_BITS", "+", "1", "]", ";", "short", "code", "=", "0", ";", "int", "bits", ";", "int", "n", ";", "for", "(", "bits", "=", "1", ";", "bits", "<=", "MAX_BITS", ";", "bits", "++", ")", "{", "next_code", "[", "bits", "]", "=", "code", "=", "(", "short", ")", "(", "(", "code", "+", "bl_count", "[", "bits", "-", "1", "]", ")", "<<", "1", ")", ";", "}", "for", "(", "n", "=", "0", ";", "n", "<=", "max_code", ";", "n", "++", ")", "{", "int", "len", "=", "tree", "[", "n", "*", "2", "+", "1", "]", ";", "if", "(", "len", "==", "0", ")", "continue", ";", "tree", "[", "n", "*", "2", "]", "=", "(", "short", ")", "(", "bi_reverse", "(", "next_code", "[", "len", "]", "++", ",", "len", ")", ")", ";", "}", "}", "static", "int", "bi_reverse", "(", "int", "code", ",", "int", "len", ")", "{", "int", "res", "=", "0", ";", "do", "{", "res", "|=", "code", "&", "1", ";", "code", ">>>=", "1", ";", "res", "<<=", "1", ";", "}", "while", "(", "--", "len", ">", "0", ")", ";", "return", "res", ">>>", "1", ";", "}", "}", "</s>" ]
7,719
[ "<s>", "package", "com", ".", "jcraft", ".", "jzlib", ";", "final", "class", "InfBlocks", "{", "static", "final", "private", "int", "MANY", "=", "1440", ";", "static", "final", "private", "int", "[", "]", "inflate_mask", "=", "{", "0x00000000", ",", "0x00000001", ",", "0x00000003", ",", "0x00000007", ",", "0x0000000f", ",", "0x0000001f", ",", "0x0000003f", ",", "0x0000007f", ",", "0x000000ff", ",", "0x000001ff", ",", "0x000003ff", ",", "0x000007ff", ",", "0x00000fff", ",", "0x00001fff", ",", "0x00003fff", ",", "0x00007fff", ",", "0x0000ffff", "}", ";", "static", "final", "int", "[", "]", "border", "=", "{", "16", ",", "17", ",", "18", ",", "0", ",", "8", ",", "7", ",", "9", ",", "6", ",", "10", ",", "5", ",", "11", ",", "4", ",", "12", ",", "3", ",", "13", ",", "2", ",", "14", ",", "1", ",", "15", "}", ";", "static", "final", "private", "int", "Z_OK", "=", "0", ";", "static", "final", "private", "int", "Z_STREAM_END", "=", "1", ";", "static", "final", "private", "int", "Z_NEED_DICT", "=", "2", ";", "static", "final", "private", "int", "Z_ERRNO", "=", "-", "1", ";", "static", "final", "private", "int", "Z_STREAM_ERROR", "=", "-", "2", ";", "static", "final", "private", "int", "Z_DATA_ERROR", "=", "-", "3", ";", "static", "final", "private", "int", "Z_MEM_ERROR", "=", "-", "4", ";", "static", "final", "private", "int", "Z_BUF_ERROR", "=", "-", "5", ";", "static", "final", "private", "int", "Z_VERSION_ERROR", "=", "-", "6", ";", "static", "final", "private", "int", "TYPE", "=", "0", ";", "static", "final", "private", "int", "LENS", "=", "1", ";", "static", "final", "private", "int", "STORED", "=", "2", ";", "static", "final", "private", "int", "TABLE", "=", "3", ";", "static", "final", "private", "int", "BTREE", "=", "4", ";", "static", "final", "private", "int", "DTREE", "=", "5", ";", "static", "final", "private", "int", "CODES", "=", "6", ";", "static", "final", "private", "int", "DRY", "=", "7", ";", "static", "final", "private", "int", "DONE", "=", "8", ";", "static", "final", "private", "int", "BAD", "=", "9", ";", "int", "mode", ";", "int", "left", ";", "int", "table", ";", "int", "index", ";", "int", "[", "]", "blens", ";", "int", "[", "]", "bb", "=", "new", "int", "[", "1", "]", ";", "int", "[", "]", "tb", "=", "new", "int", "[", "1", "]", ";", "InfCodes", "codes", "=", "new", "InfCodes", "(", ")", ";", "int", "last", ";", "int", "bitk", ";", "int", "bitb", ";", "int", "[", "]", "hufts", ";", "byte", "[", "]", "window", ";", "int", "end", ";", "int", "read", ";", "int", "write", ";", "Object", "checkfn", ";", "long", "check", ";", "InfTree", "inftree", "=", "new", "InfTree", "(", ")", ";", "InfBlocks", "(", "ZStream", "z", ",", "Object", "checkfn", ",", "int", "w", ")", "{", "hufts", "=", "new", "int", "[", "MANY", "*", "3", "]", ";", "window", "=", "new", "byte", "[", "w", "]", ";", "end", "=", "w", ";", "this", ".", "checkfn", "=", "checkfn", ";", "mode", "=", "TYPE", ";", "reset", "(", "z", ",", "null", ")", ";", "}", "void", "reset", "(", "ZStream", "z", ",", "long", "[", "]", "c", ")", "{", "if", "(", "c", "!=", "null", ")", "c", "[", "0", "]", "=", "check", ";", "if", "(", "mode", "==", "BTREE", "||", "mode", "==", "DTREE", ")", "{", "}", "if", "(", "mode", "==", "CODES", ")", "{", "codes", ".", "free", "(", "z", ")", ";", "}", "mode", "=", "TYPE", ";", "bitk", "=", "0", ";", "bitb", "=", "0", ";", "read", "=", "write", "=", "0", ";", "if", "(", "checkfn", "!=", "null", ")", "z", ".", "adler", "=", "check", "=", "z", ".", "_adler", ".", "adler32", "(", "0L", ",", "null", ",", "0", ",", "0", ")", ";", "}", "int", "proc", "(", "ZStream", "z", ",", "int", "r", ")", "{", "int", "t", ";", "int", "b", ";", "int", "k", ";", "int", "p", ";", "int", "n", ";", "int", "q", ";", "int", "m", ";", "{", "p", "=", "z", ".", "next_in_index", ";", "n", "=", "z", ".", "avail_in", ";", "b", "=", "bitb", ";", "k", "=", "bitk", ";", "}", "{", "q", "=", "write", ";", "m", "=", "(", "int", ")", "(", "q", "<", "read", "?", "read", "-", "q", "-", "1", ":", "end", "-", "q", ")", ";", "}", "while", "(", "true", ")", "{", "switch", "(", "mode", ")", "{", "case", "TYPE", ":", "while", "(", "k", "<", "(", "3", ")", ")", "{", "if", "(", "n", "!=", "0", ")", "{", "r", "=", "Z_OK", ";", "}", "else", "{", "bitb", "=", "b", ";", "bitk", "=", "k", ";", "z", ".", "avail_in", "=", "n", ";", "z", ".", "total_in", "+=", "p", "-", "z", ".", "next_in_index", ";", "z", ".", "next_in_index", "=", "p", ";", "write", "=", "q", ";", "return", "inflate_flush", "(", "z", ",", "r", ")", ";", "}", ";", "n", "--", ";", "b", "|=", "(", "z", ".", "next_in", "[", "p", "++", "]", "&", "0xff", ")", "<<", "k", ";", "k", "+=", "8", ";", "}", "t", "=", "(", "int", ")", "(", "b", "&", "7", ")", ";", "last", "=", "t", "&", "1", ";", "switch", "(", "t", ">>>", "1", ")", "{", "case", "0", ":", "{", "b", ">>>=", "(", "3", ")", ";", "k", "-=", "(", "3", ")", ";", "}", "t", "=", "k", "&", "7", ";", "{", "b", ">>>=", "(", "t", ")", ";", "k", "-=", "(", "t", ")", ";", "}", "mode", "=", "LENS", ";", "break", ";", "case", "1", ":", "{", "int", "[", "]", "bl", "=", "new", "int", "[", "1", "]", ";", "int", "[", "]", "bd", "=", "new", "int", "[", "1", "]", ";", "int", "[", "]", "[", "]", "tl", "=", "new", "int", "[", "1", "]", "[", "]", ";", "int", "[", "]", "[", "]", "td", "=", "new", "int", "[", "1", "]", "[", "]", ";", "InfTree", ".", "inflate_trees_fixed", "(", "bl", ",", "bd", ",", "tl", ",", "td", ",", "z", ")", ";", "codes", ".", "init", "(", "bl", "[", "0", "]", ",", "bd", "[", "0", "]", ",", "tl", "[", "0", "]", ",", "0", ",", "td", "[", "0", "]", ",", "0", ",", "z", ")", ";", "}", "{", "b", ">>>=", "(", "3", ")", ";", "k", "-=", "(", "3", ")", ";", "}", "mode", "=", "CODES", ";", "break", ";", "case", "2", ":", "{", "b", ">>>=", "(", "3", ")", ";", "k", "-=", "(", "3", ")", ";", "}", "mode", "=", "TABLE", ";", "break", ";", "case", "3", ":", "{", "b", ">>>=", "(", "3", ")", ";", "k", "-=", "(", "3", ")", ";", "}", "mode", "=", "BAD", ";", "z", ".", "msg", "=", "\"\"", ";", "r", "=", "Z_DATA_ERROR", ";", "bitb", "=", "b", ";", "bitk", "=", "k", ";", "z", ".", "avail_in", "=", "n", ";", "z", ".", "total_in", "+=", "p", "-", "z", ".", "next_in_index", ";", "z", ".", "next_in_index", "=", "p", ";", "write", "=", "q", ";", "return", "inflate_flush", "(", "z", ",", "r", ")", ";", "}", "break", ";", "case", "LENS", ":", "while", "(", "k", "<", "(", "32", ")", ")", "{", "if", "(", "n", "!=", "0", ")", "{", "r", "=", "Z_OK", ";", "}", "else", "{", "bitb", "=", "b", ";", "bitk", "=", "k", ";", "z", ".", "avail_in", "=", "n", ";", "z", ".", "total_in", "+=", "p", "-", "z", ".", "next_in_index", ";", "z", ".", "next_in_index", "=", "p", ";", "write", "=", "q", ";", "return", "inflate_flush", "(", "z", ",", "r", ")", ";", "}", ";", "n", "--", ";", "b", "|=", "(", "z", ".", "next_in", "[", "p", "++", "]", "&", "0xff", ")", "<<", "k", ";", "k", "+=", "8", ";", "}", "if", "(", "(", "(", "(", "~", "b", ")", ">>>", "16", ")", "&", "0xffff", ")", "!=", "(", "b", "&", "0xffff", ")", ")", "{", "mode", "=", "BAD", ";", "z", ".", "msg", "=", "\"\"", ";", "r", "=", "Z_DATA_ERROR", ";", "bitb", "=", "b", ";", "bitk", "=", "k", ";", "z", ".", "avail_in", "=", "n", ";", "z", ".", "total_in", "+=", "p", "-", "z", ".", "next_in_index", ";", "z", ".", "next_in_index", "=", "p", ";", "write", "=", "q", ";", "return", "inflate_flush", "(", "z", ",", "r", ")", ";", "}", "left", "=", "(", "b", "&", "0xffff", ")", ";", "b", "=", "k", "=", "0", ";", "mode", "=", "left", "!=", "0", "?", "STORED", ":", "(", "last", "!=", "0", "?", "DRY", ":", "TYPE", ")", ";", "break", ";", "case", "STORED", ":", "if", "(", "n", "==", "0", ")", "{", "bitb", "=", "b", ";", "bitk", "=", "k", ";", "z", ".", "avail_in", "=", "n", ";", "z", ".", "total_in", "+=", "p", "-", "z", ".", "next_in_index", ";", "z", ".", "next_in_index", "=", "p", ";", "write", "=", "q", ";", "return", "inflate_flush", "(", "z", ",", "r", ")", ";", "}", "if", "(", "m", "==", "0", ")", "{", "if", "(", "q", "==", "end", "&&", "read", "!=", "0", ")", "{", "q", "=", "0", ";", "m", "=", "(", "int", ")", "(", "q", "<", "read", "?", "read", "-", "q", "-", "1", ":", "end", "-", "q", ")", ";", "}", "if", "(", "m", "==", "0", ")", "{", "write", "=", "q", ";", "r", "=", "inflate_flush", "(", "z", ",", "r", ")", ";", "q", "=", "write", ";", "m", "=", "(", "int", ")", "(", "q", "<", "read", "?", "read", "-", "q", "-", "1", ":", "end", "-", "q", ")", ";", "if", "(", "q", "==", "end", "&&", "read", "!=", "0", ")", "{", "q", "=", "0", ";", "m", "=", "(", "int", ")", "(", "q", "<", "read", "?", "read", "-", "q", "-", "1", ":", "end", "-", "q", ")", ";", "}", "if", "(", "m", "==", "0", ")", "{", "bitb", "=", "b", ";", "bitk", "=", "k", ";", "z", ".", "avail_in", "=", "n", ";", "z", ".", "total_in", "+=", "p", "-", "z", ".", "next_in_index", ";", "z", ".", "next_in_index", "=", "p", ";", "write", "=", "q", ";", "return", "inflate_flush", "(", "z", ",", "r", ")", ";", "}", "}", "}", "r", "=", "Z_OK", ";", "t", "=", "left", ";", "if", "(", "t", ">", "n", ")", "t", "=", "n", ";", "if", "(", "t", ">", "m", ")", "t", "=", "m", ";", "System", ".", "arraycopy", "(", "z", ".", "next_in", ",", "p", ",", "window", ",", "q", ",", "t", ")", ";", "p", "+=", "t", ";", "n", "-=", "t", ";", "q", "+=", "t", ";", "m", "-=", "t", ";", "if", "(", "(", "left", "-=", "t", ")", "!=", "0", ")", "break", ";", "mode", "=", "last", "!=", "0", "?", "DRY", ":", "TYPE", ";", "break", ";", "case", "TABLE", ":", "while", "(", "k", "<", "(", "14", ")", ")", "{", "if", "(", "n", "!=", "0", ")", "{", "r", "=", "Z_OK", ";", "}", "else", "{", "bitb", "=", "b", ";", "bitk", "=", "k", ";", "z", ".", "avail_in", "=", "n", ";", "z", ".", "total_in", "+=", "p", "-", "z", ".", "next_in_index", ";", "z", ".", "next_in_index", "=", "p", ";", "write", "=", "q", ";", "return", "inflate_flush", "(", "z", ",", "r", ")", ";", "}", ";", "n", "--", ";", "b", "|=", "(", "z", ".", "next_in", "[", "p", "++", "]", "&", "0xff", ")", "<<", "k", ";", "k", "+=", "8", ";", "}", "table", "=", "t", "=", "(", "b", "&", "0x3fff", ")", ";", "if", "(", "(", "t", "&", "0x1f", ")", ">", "29", "||", "(", "(", "t", ">>", "5", ")", "&", "0x1f", ")", ">", "29", ")", "{", "mode", "=", "BAD", ";", "z", ".", "msg", "=", "\"\"", ";", "r", "=", "Z_DATA_ERROR", ";", "bitb", "=", "b", ";", "bitk", "=", "k", ";", "z", ".", "avail_in", "=", "n", ";", "z", ".", "total_in", "+=", "p", "-", "z", ".", "next_in_index", ";", "z", ".", "next_in_index", "=", "p", ";", "write", "=", "q", ";", "return", "inflate_flush", "(", "z", ",", "r", ")", ";", "}", "t", "=", "258", "+", "(", "t", "&", "0x1f", ")", "+", "(", "(", "t", ">>", "5", ")", "&", "0x1f", ")", ";", "if", "(", "blens", "==", "null", "||", "blens", ".", "length", "<", "t", ")", "{", "blens", "=", "new", "int", "[", "t", "]", ";", "}", "else", "{", "for", "(", "int", "i", "=", "0", ";", "i", "<", "t", ";", "i", "++", ")", "{", "blens", "[", "i", "]", "=", "0", ";", "}", "}", "{", "b", ">>>=", "(", "14", ")", ";", "k", "-=", "(", "14", ")", ";", "}", "index", "=", "0", ";", "mode", "=", "BTREE", ";", "case", "BTREE", ":", "while", "(", "index", "<", "4", "+", "(", "table", ">>>", "10", ")", ")", "{", "while", "(", "k", "<", "(", "3", ")", ")", "{", "if", "(", "n", "!=", "0", ")", "{", "r", "=", "Z_OK", ";", "}", "else", "{", "bitb", "=", "b", ";", "bitk", "=", "k", ";", "z", ".", "avail_in", "=", "n", ";", "z", ".", "total_in", "+=", "p", "-", "z", ".", "next_in_index", ";", "z", ".", "next_in_index", "=", "p", ";", "write", "=", "q", ";", "return", "inflate_flush", "(", "z", ",", "r", ")", ";", "}", ";", "n", "--", ";", "b", "|=", "(", "z", ".", "next_in", "[", "p", "++", "]", "&", "0xff", ")", "<<", "k", ";", "k", "+=", "8", ";", "}", "blens", "[", "border", "[", "index", "++", "]", "]", "=", "b", "&", "7", ";", "{", "b", ">>>=", "(", "3", ")", ";", "k", "-=", "(", "3", ")", ";", "}", "}", "while", "(", "index", "<", "19", ")", "{", "blens", "[", "border", "[", "index", "++", "]", "]", "=", "0", ";", "}", "bb", "[", "0", "]", "=", "7", ";", "t", "=", "inftree", ".", "inflate_trees_bits", "(", "blens", ",", "bb", ",", "tb", ",", "hufts", ",", "z", ")", ";", "if", "(", "t", "!=", "Z_OK", ")", "{", "r", "=", "t", ";", "if", "(", "r", "==", "Z_DATA_ERROR", ")", "{", "blens", "=", "null", ";", "mode", "=", "BAD", ";", "}", "bitb", "=", "b", ";", "bitk", "=", "k", ";", "z", ".", "avail_in", "=", "n", ";", "z", ".", "total_in", "+=", "p", "-", "z", ".", "next_in_index", ";", "z", ".", "next_in_index", "=", "p", ";", "write", "=", "q", ";", "return", "inflate_flush", "(", "z", ",", "r", ")", ";", "}", "index", "=", "0", ";", "mode", "=", "DTREE", ";", "case", "DTREE", ":", "while", "(", "true", ")", "{", "t", "=", "table", ";", "if", "(", "!", "(", "index", "<", "258", "+", "(", "t", "&", "0x1f", ")", "+", "(", "(", "t", ">>", "5", ")", "&", "0x1f", ")", ")", ")", "{", "break", ";", "}", "int", "[", "]", "h", ";", "int", "i", ",", "j", ",", "c", ";", "t", "=", "bb", "[", "0", "]", ";", "while", "(", "k", "<", "(", "t", ")", ")", "{", "if", "(", "n", "!=", "0", ")", "{", "r", "=", "Z_OK", ";", "}", "else", "{", "bitb", "=", "b", ";", "bitk", "=", "k", ";", "z", ".", "avail_in", "=", "n", ";", "z", ".", "total_in", "+=", "p", "-", "z", ".", "next_in_index", ";", "z", ".", "next_in_index", "=", "p", ";", "write", "=", "q", ";", "return", "inflate_flush", "(", "z", ",", "r", ")", ";", "}", ";", "n", "--", ";", "b", "|=", "(", "z", ".", "next_in", "[", "p", "++", "]", "&", "0xff", ")", "<<", "k", ";", "k", "+=", "8", ";", "}", "if", "(", "tb", "[", "0", "]", "==", "-", "1", ")", "{", "}", "t", "=", "hufts", "[", "(", "tb", "[", "0", "]", "+", "(", "b", "&", "inflate_mask", "[", "t", "]", ")", ")", "*", "3", "+", "1", "]", ";", "c", "=", "hufts", "[", "(", "tb", "[", "0", "]", "+", "(", "b", "&", "inflate_mask", "[", "t", "]", ")", ")", "*", "3", "+", "2", "]", ";", "if", "(", "c", "<", "16", ")", "{", "b", ">>>=", "(", "t", ")", ";", "k", "-=", "(", "t", ")", ";", "blens", "[", "index", "++", "]", "=", "c", ";", "}", "else", "{", "i", "=", "c", "==", "18", "?", "7", ":", "c", "-", "14", ";", "j", "=", "c", "==", "18", "?", "11", ":", "3", ";", "while", "(", "k", "<", "(", "t", "+", "i", ")", ")", "{", "if", "(", "n", "!=", "0", ")", "{", "r", "=", "Z_OK", ";", "}", "else", "{", "bitb", "=", "b", ";", "bitk", "=", "k", ";", "z", ".", "avail_in", "=", "n", ";", "z", ".", "total_in", "+=", "p", "-", "z", ".", "next_in_index", ";", "z", ".", "next_in_index", "=", "p", ";", "write", "=", "q", ";", "return", "inflate_flush", "(", "z", ",", "r", ")", ";", "}", ";", "n", "--", ";", "b", "|=", "(", "z", ".", "next_in", "[", "p", "++", "]", "&", "0xff", ")", "<<", "k", ";", "k", "+=", "8", ";", "}", "b", ">>>=", "(", "t", ")", ";", "k", "-=", "(", "t", ")", ";", "j", "+=", "(", "b", "&", "inflate_mask", "[", "i", "]", ")", ";", "b", ">>>=", "(", "i", ")", ";", "k", "-=", "(", "i", ")", ";", "i", "=", "index", ";", "t", "=", "table", ";", "if", "(", "i", "+", "j", ">", "258", "+", "(", "t", "&", "0x1f", ")", "+", "(", "(", "t", ">>", "5", ")", "&", "0x1f", ")", "||", "(", "c", "==", "16", "&&", "i", "<", "1", ")", ")", "{", "blens", "=", "null", ";", "mode", "=", "BAD", ";", "z", ".", "msg", "=", "\"\"", ";", "r", "=", "Z_DATA_ERROR", ";", "bitb", "=", "b", ";", "bitk", "=", "k", ";", "z", ".", "avail_in", "=", "n", ";", "z", ".", "total_in", "+=", "p", "-", "z", ".", "next_in_index", ";", "z", ".", "next_in_index", "=", "p", ";", "write", "=", "q", ";", "return", "inflate_flush", "(", "z", ",", "r", ")", ";", "}", "c", "=", "c", "==", "16", "?", "blens", "[", "i", "-", "1", "]", ":", "0", ";", "do", "{", "blens", "[", "i", "++", "]", "=", "c", ";", "}", "while", "(", "--", "j", "!=", "0", ")", ";", "index", "=", "i", ";", "}", "}", "tb", "[", "0", "]", "=", "-", "1", ";", "{", "int", "[", "]", "bl", "=", "new", "int", "[", "1", "]", ";", "int", "[", "]", "bd", "=", "new", "int", "[", "1", "]", ";", "int", "[", "]", "tl", "=", "new", "int", "[", "1", "]", ";", "int", "[", "]", "td", "=", "new", "int", "[", "1", "]", ";", "bl", "[", "0", "]", "=", "9", ";", "bd", "[", "0", "]", "=", "6", ";", "t", "=", "table", ";", "t", "=", "inftree", ".", "inflate_trees_dynamic", "(", "257", "+", "(", "t", "&", "0x1f", ")", ",", "1", "+", "(", "(", "t", ">>", "5", ")", "&", "0x1f", ")", ",", "blens", ",", "bl", ",", "bd", ",", "tl", ",", "td", ",", "hufts", ",", "z", ")", ";", "if", "(", "t", "!=", "Z_OK", ")", "{", "if", "(", "t", "==", "Z_DATA_ERROR", ")", "{", "blens", "=", "null", ";", "mode", "=", "BAD", ";", "}", "r", "=", "t", ";", "bitb", "=", "b", ";", "bitk", "=", "k", ";", "z", ".", "avail_in", "=", "n", ";", "z", ".", "total_in", "+=", "p", "-", "z", ".", "next_in_index", ";", "z", ".", "next_in_index", "=", "p", ";", "write", "=", "q", ";", "return", "inflate_flush", "(", "z", ",", "r", ")", ";", "}", "codes", ".", "init", "(", "bl", "[", "0", "]", ",", "bd", "[", "0", "]", ",", "hufts", ",", "tl", "[", "0", "]", ",", "hufts", ",", "td", "[", "0", "]", ",", "z", ")", ";", "}", "mode", "=", "CODES", ";", "case", "CODES", ":", "bitb", "=", "b", ";", "bitk", "=", "k", ";", "z", ".", "avail_in", "=", "n", ";", "z", ".", "total_in", "+=", "p", "-", "z", ".", "next_in_index", ";", "z", ".", "next_in_index", "=", "p", ";", "write", "=", "q", ";", "if", "(", "(", "r", "=", "codes", ".", "proc", "(", "this", ",", "z", ",", "r", ")", ")", "!=", "Z_STREAM_END", ")", "{", "return", "inflate_flush", "(", "z", ",", "r", ")", ";", "}", "r", "=", "Z_OK", ";", "codes", ".", "free", "(", "z", ")", ";", "p", "=", "z", ".", "next_in_index", ";", "n", "=", "z", ".", "avail_in", ";", "b", "=", "bitb", ";", "k", "=", "bitk", ";", "q", "=", "write", ";", "m", "=", "(", "int", ")", "(", "q", "<", "read", "?", "read", "-", "q", "-", "1", ":", "end", "-", "q", ")", ";", "if", "(", "last", "==", "0", ")", "{", "mode", "=", "TYPE", ";", "break", ";", "}", "mode", "=", "DRY", ";", "case", "DRY", ":", "write", "=", "q", ";", "r", "=", "inflate_flush", "(", "z", ",", "r", ")", ";", "q", "=", "write", ";", "m", "=", "(", "int", ")", "(", "q", "<", "read", "?", "read", "-", "q", "-", "1", ":", "end", "-", "q", ")", ";", "if", "(", "read", "!=", "write", ")", "{", "bitb", "=", "b", ";", "bitk", "=", "k", ";", "z", ".", "avail_in", "=", "n", ";", "z", ".", "total_in", "+=", "p", "-", "z", ".", "next_in_index", ";", "z", ".", "next_in_index", "=", "p", ";", "write", "=", "q", ";", "return", "inflate_flush", "(", "z", ",", "r", ")", ";", "}", "mode", "=", "DONE", ";", "case", "DONE", ":", "r", "=", "Z_STREAM_END", ";", "bitb", "=", "b", ";", "bitk", "=", "k", ";", "z", ".", "avail_in", "=", "n", ";", "z", ".", "total_in", "+=", "p", "-", "z", ".", "next_in_index", ";", "z", ".", "next_in_index", "=", "p", ";", "write", "=", "q", ";", "return", "inflate_flush", "(", "z", ",", "r", ")", ";", "case", "BAD", ":", "r", "=", "Z_DATA_ERROR", ";", "bitb", "=", "b", ";", "bitk", "=", "k", ";", "z", ".", "avail_in", "=", "n", ";", "z", ".", "total_in", "+=", "p", "-", "z", ".", "next_in_index", ";", "z", ".", "next_in_index", "=", "p", ";", "write", "=", "q", ";", "return", "inflate_flush", "(", "z", ",", "r", ")", ";", "default", ":", "r", "=", "Z_STREAM_ERROR", ";", "bitb", "=", "b", ";", "bitk", "=", "k", ";", "z", ".", "avail_in", "=", "n", ";", "z", ".", "total_in", "+=", "p", "-", "z", ".", "next_in_index", ";", "z", ".", "next_in_index", "=", "p", ";", "write", "=", "q", ";", "return", "inflate_flush", "(", "z", ",", "r", ")", ";", "}", "}", "}", "void", "free", "(", "ZStream", "z", ")", "{", "reset", "(", "z", ",", "null", ")", ";", "window", "=", "null", ";", "hufts", "=", "null", ";", "}", "void", "set_dictionary", "(", "byte", "[", "]", "d", ",", "int", "start", ",", "int", "n", ")", "{", "System", ".", "arraycopy", "(", "d", ",", "start", ",", "window", ",", "0", ",", "n", ")", ";", "read", "=", "write", "=", "n", ";", "}", "int", "sync_point", "(", ")", "{", "return", "mode", "==", "LENS", "?", "1", ":", "0", ";", "}", "int", "inflate_flush", "(", "ZStream", "z", ",", "int", "r", ")", "{", "int", "n", ";", "int", "p", ";", "int", "q", ";", "p", "=", "z", ".", "next_out_index", ";", "q", "=", "read", ";", "n", "=", "(", "int", ")", "(", "(", "q", "<=", "write", "?", "write", ":", "end", ")", "-", "q", ")", ";", "if", "(", "n", ">", "z", ".", "avail_out", ")", "n", "=", "z", ".", "avail_out", ";", "if", "(", "n", "!=", "0", "&&", "r", "==", "Z_BUF_ERROR", ")", "r", "=", "Z_OK", ";", "z", ".", "avail_out", "-=", "n", ";", "z", ".", "total_out", "+=", "n", ";", "if", "(", "checkfn", "!=", "null", ")", "z", ".", "adler", "=", "check", "=", "z", ".", "_adler", ".", "adler32", "(", "check", ",", "window", ",", "q", ",", "n", ")", ";", "System", ".", "arraycopy", "(", "window", ",", "q", ",", "z", ".", "next_out", ",", "p", ",", "n", ")", ";", "p", "+=", "n", ";", "q", "+=", "n", ";", "if", "(", "q", "==", "end", ")", "{", "q", "=", "0", ";", "if", "(", "write", "==", "end", ")", "write", "=", "0", ";", "n", "=", "write", "-", "q", ";", "if", "(", "n", ">", "z", ".", "avail_out", ")", "n", "=", "z", ".", "avail_out", ";", "if", "(", "n", "!=", "0", "&&", "r", "==", "Z_BUF_ERROR", ")", "r", "=", "Z_OK", ";", "z", ".", "avail_out", "-=", "n", ";", "z", ".", "total_out", "+=", "n", ";", "if", "(", "checkfn", "!=", "null", ")", "z", ".", "adler", "=", "check", "=", "z", ".", "_adler", ".", "adler32", "(", "check", ",", "window", ",", "q", ",", "n", ")", ";", "System", ".", "arraycopy", "(", "window", ",", "q", ",", "z", ".", "next_out", ",", "p", ",", "n", ")", ";", "p", "+=", "n", ";", "q", "+=", "n", ";", "}", "z", ".", "next_out_index", "=", "p", ";", "read", "=", "q", ";", "return", "r", ";", "}", "}", "</s>" ]
7,720
[ "<s>", "package", "com", ".", "jcraft", ".", "jzlib", ";", "final", "class", "InfTree", "{", "static", "final", "private", "int", "MANY", "=", "1440", ";", "static", "final", "private", "int", "Z_OK", "=", "0", ";", "static", "final", "private", "int", "Z_STREAM_END", "=", "1", ";", "static", "final", "private", "int", "Z_NEED_DICT", "=", "2", ";", "static", "final", "private", "int", "Z_ERRNO", "=", "-", "1", ";", "static", "final", "private", "int", "Z_STREAM_ERROR", "=", "-", "2", ";", "static", "final", "private", "int", "Z_DATA_ERROR", "=", "-", "3", ";", "static", "final", "private", "int", "Z_MEM_ERROR", "=", "-", "4", ";", "static", "final", "private", "int", "Z_BUF_ERROR", "=", "-", "5", ";", "static", "final", "private", "int", "Z_VERSION_ERROR", "=", "-", "6", ";", "static", "final", "int", "fixed_bl", "=", "9", ";", "static", "final", "int", "fixed_bd", "=", "5", ";", "static", "final", "int", "[", "]", "fixed_tl", "=", "{", "96", ",", "7", ",", "256", ",", "0", ",", "8", ",", "80", ",", "0", ",", "8", ",", "16", ",", "84", ",", "8", ",", "115", ",", "82", ",", "7", ",", "31", ",", "0", ",", "8", ",", "112", ",", "0", ",", "8", ",", "48", ",", "0", ",", "9", ",", "192", ",", "80", ",", "7", ",", "10", ",", "0", ",", "8", ",", "96", ",", "0", ",", "8", ",", "32", ",", "0", ",", "9", ",", "160", ",", "0", ",", "8", ",", "0", ",", "0", ",", "8", ",", "128", ",", "0", ",", "8", ",", "64", ",", "0", ",", "9", ",", "224", ",", "80", ",", "7", ",", "6", ",", "0", ",", "8", ",", "88", ",", "0", ",", "8", ",", "24", ",", "0", ",", "9", ",", "144", ",", "83", ",", "7", ",", "59", ",", "0", ",", "8", ",", "120", ",", "0", ",", "8", ",", "56", ",", "0", ",", "9", ",", "208", ",", "81", ",", "7", ",", "17", ",", "0", ",", "8", ",", "104", ",", "0", ",", "8", ",", "40", ",", "0", ",", "9", ",", "176", ",", "0", ",", "8", ",", "8", ",", "0", ",", "8", ",", "136", ",", "0", ",", "8", ",", "72", ",", "0", ",", "9", ",", "240", ",", "80", ",", "7", ",", "4", ",", "0", ",", "8", ",", "84", ",", "0", ",", "8", ",", "20", ",", "85", ",", "8", ",", "227", ",", "83", ",", "7", ",", "43", ",", "0", ",", "8", ",", "116", ",", "0", ",", "8", ",", "52", ",", "0", ",", "9", ",", "200", ",", "81", ",", "7", ",", "13", ",", "0", ",", "8", ",", "100", ",", "0", ",", "8", ",", "36", ",", "0", ",", "9", ",", "168", ",", "0", ",", "8", ",", "4", ",", "0", ",", "8", ",", "132", ",", "0", ",", "8", ",", "68", ",", "0", ",", "9", ",", "232", ",", "80", ",", "7", ",", "8", ",", "0", ",", "8", ",", "92", ",", "0", ",", "8", ",", "28", ",", "0", ",", "9", ",", "152", ",", "84", ",", "7", ",", "83", ",", "0", ",", "8", ",", "124", ",", "0", ",", "8", ",", "60", ",", "0", ",", "9", ",", "216", ",", "82", ",", "7", ",", "23", ",", "0", ",", "8", ",", "108", ",", "0", ",", "8", ",", "44", ",", "0", ",", "9", ",", "184", ",", "0", ",", "8", ",", "12", ",", "0", ",", "8", ",", "140", ",", "0", ",", "8", ",", "76", ",", "0", ",", "9", ",", "248", ",", "80", ",", "7", ",", "3", ",", "0", ",", "8", ",", "82", ",", "0", ",", "8", ",", "18", ",", "85", ",", "8", ",", "163", ",", "83", ",", "7", ",", "35", ",", "0", ",", "8", ",", "114", ",", "0", ",", "8", ",", "50", ",", "0", ",", "9", ",", "196", ",", "81", ",", "7", ",", "11", ",", "0", ",", "8", ",", "98", ",", "0", ",", "8", ",", "34", ",", "0", ",", "9", ",", "164", ",", "0", ",", "8", ",", "2", ",", "0", ",", "8", ",", "130", ",", "0", ",", "8", ",", "66", ",", "0", ",", "9", ",", "228", ",", "80", ",", "7", ",", "7", ",", "0", ",", "8", ",", "90", ",", "0", ",", "8", ",", "26", ",", "0", ",", "9", ",", "148", ",", "84", ",", "7", ",", "67", ",", "0", ",", "8", ",", "122", ",", "0", ",", "8", ",", "58", ",", "0", ",", "9", ",", "212", ",", "82", ",", "7", ",", "19", ",", "0", ",", "8", ",", "106", ",", "0", ",", "8", ",", "42", ",", "0", ",", "9", ",", "180", ",", "0", ",", "8", ",", "10", ",", "0", ",", "8", ",", "138", ",", "0", ",", "8", ",", "74", ",", "0", ",", "9", ",", "244", ",", "80", ",", "7", ",", "5", ",", "0", ",", "8", ",", "86", ",", "0", ",", "8", ",", "22", ",", "192", ",", "8", ",", "0", ",", "83", ",", "7", ",", "51", ",", "0", ",", "8", ",", "118", ",", "0", ",", "8", ",", "54", ",", "0", ",", "9", ",", "204", ",", "81", ",", "7", ",", "15", ",", "0", ",", "8", ",", "102", ",", "0", ",", "8", ",", "38", ",", "0", ",", "9", ",", "172", ",", "0", ",", "8", ",", "6", ",", "0", ",", "8", ",", "134", ",", "0", ",", "8", ",", "70", ",", "0", ",", "9", ",", "236", ",", "80", ",", "7", ",", "9", ",", "0", ",", "8", ",", "94", ",", "0", ",", "8", ",", "30", ",", "0", ",", "9", ",", "156", ",", "84", ",", "7", ",", "99", ",", "0", ",", "8", ",", "126", ",", "0", ",", "8", ",", "62", ",", "0", ",", "9", ",", "220", ",", "82", ",", "7", ",", "27", ",", "0", ",", "8", ",", "110", ",", "0", ",", "8", ",", "46", ",", "0", ",", "9", ",", "188", ",", "0", ",", "8", ",", "14", ",", "0", ",", "8", ",", "142", ",", "0", ",", "8", ",", "78", ",", "0", ",", "9", ",", "252", ",", "96", ",", "7", ",", "256", ",", "0", ",", "8", ",", "81", ",", "0", ",", "8", ",", "17", ",", "85", ",", "8", ",", "131", ",", "82", ",", "7", ",", "31", ",", "0", ",", "8", ",", "113", ",", "0", ",", "8", ",", "49", ",", "0", ",", "9", ",", "194", ",", "80", ",", "7", ",", "10", ",", "0", ",", "8", ",", "97", ",", "0", ",", "8", ",", "33", ",", "0", ",", "9", ",", "162", ",", "0", ",", "8", ",", "1", ",", "0", ",", "8", ",", "129", ",", "0", ",", "8", ",", "65", ",", "0", ",", "9", ",", "226", ",", "80", ",", "7", ",", "6", ",", "0", ",", "8", ",", "89", ",", "0", ",", "8", ",", "25", ",", "0", ",", "9", ",", "146", ",", "83", ",", "7", ",", "59", ",", "0", ",", "8", ",", "121", ",", "0", ",", "8", ",", "57", ",", "0", ",", "9", ",", "210", ",", "81", ",", "7", ",", "17", ",", "0", ",", "8", ",", "105", ",", "0", ",", "8", ",", "41", ",", "0", ",", "9", ",", "178", ",", "0", ",", "8", ",", "9", ",", "0", ",", "8", ",", "137", ",", "0", ",", "8", ",", "73", ",", "0", ",", "9", ",", "242", ",", "80", ",", "7", ",", "4", ",", "0", ",", "8", ",", "85", ",", "0", ",", "8", ",", "21", ",", "80", ",", "8", ",", "258", ",", "83", ",", "7", ",", "43", ",", "0", ",", "8", ",", "117", ",", "0", ",", "8", ",", "53", ",", "0", ",", "9", ",", "202", ",", "81", ",", "7", ",", "13", ",", "0", ",", "8", ",", "101", ",", "0", ",", "8", ",", "37", ",", "0", ",", "9", ",", "170", ",", "0", ",", "8", ",", "5", ",", "0", ",", "8", ",", "133", ",", "0", ",", "8", ",", "69", ",", "0", ",", "9", ",", "234", ",", "80", ",", "7", ",", "8", ",", "0", ",", "8", ",", "93", ",", "0", ",", "8", ",", "29", ",", "0", ",", "9", ",", "154", ",", "84", ",", "7", ",", "83", ",", "0", ",", "8", ",", "125", ",", "0", ",", "8", ",", "61", ",", "0", ",", "9", ",", "218", ",", "82", ",", "7", ",", "23", ",", "0", ",", "8", ",", "109", ",", "0", ",", "8", ",", "45", ",", "0", ",", "9", ",", "186", ",", "0", ",", "8", ",", "13", ",", "0", ",", "8", ",", "141", ",", "0", ",", "8", ",", "77", ",", "0", ",", "9", ",", "250", ",", "80", ",", "7", ",", "3", ",", "0", ",", "8", ",", "83", ",", "0", ",", "8", ",", "19", ",", "85", ",", "8", ",", "195", ",", "83", ",", "7", ",", "35", ",", "0", ",", "8", ",", "115", ",", "0", ",", "8", ",", "51", ",", "0", ",", "9", ",", "198", ",", "81", ",", "7", ",", "11", ",", "0", ",", "8", ",", "99", ",", "0", ",", "8", ",", "35", ",", "0", ",", "9", ",", "166", ",", "0", ",", "8", ",", "3", ",", "0", ",", "8", ",", "131", ",", "0", ",", "8", ",", "67", ",", "0", ",", "9", ",", "230", ",", "80", ",", "7", ",", "7", ",", "0", ",", "8", ",", "91", ",", "0", ",", "8", ",", "27", ",", "0", ",", "9", ",", "150", ",", "84", ",", "7", ",", "67", ",", "0", ",", "8", ",", "123", ",", "0", ",", "8", ",", "59", ",", "0", ",", "9", ",", "214", ",", "82", ",", "7", ",", "19", ",", "0", ",", "8", ",", "107", ",", "0", ",", "8", ",", "43", ",", "0", ",", "9", ",", "182", ",", "0", ",", "8", ",", "11", ",", "0", ",", "8", ",", "139", ",", "0", ",", "8", ",", "75", ",", "0", ",", "9", ",", "246", ",", "80", ",", "7", ",", "5", ",", "0", ",", "8", ",", "87", ",", "0", ",", "8", ",", "23", ",", "192", ",", "8", ",", "0", ",", "83", ",", "7", ",", "51", ",", "0", ",", "8", ",", "119", ",", "0", ",", "8", ",", "55", ",", "0", ",", "9", ",", "206", ",", "81", ",", "7", ",", "15", ",", "0", ",", "8", ",", "103", ",", "0", ",", "8", ",", "39", ",", "0", ",", "9", ",", "174", ",", "0", ",", "8", ",", "7", ",", "0", ",", "8", ",", "135", ",", "0", ",", "8", ",", "71", ",", "0", ",", "9", ",", "238", ",", "80", ",", "7", ",", "9", ",", "0", ",", "8", ",", "95", ",", "0", ",", "8", ",", "31", ",", "0", ",", "9", ",", "158", ",", "84", ",", "7", ",", "99", ",", "0", ",", "8", ",", "127", ",", "0", ",", "8", ",", "63", ",", "0", ",", "9", ",", "222", ",", "82", ",", "7", ",", "27", ",", "0", ",", "8", ",", "111", ",", "0", ",", "8", ",", "47", ",", "0", ",", "9", ",", "190", ",", "0", ",", "8", ",", "15", ",", "0", ",", "8", ",", "143", ",", "0", ",", "8", ",", "79", ",", "0", ",", "9", ",", "254", ",", "96", ",", "7", ",", "256", ",", "0", ",", "8", ",", "80", ",", "0", ",", "8", ",", "16", ",", "84", ",", "8", ",", "115", ",", "82", ",", "7", ",", "31", ",", "0", ",", "8", ",", "112", ",", "0", ",", "8", ",", "48", ",", "0", ",", "9", ",", "193", ",", "80", ",", "7", ",", "10", ",", "0", ",", "8", ",", "96", ",", "0", ",", "8", ",", "32", ",", "0", ",", "9", ",", "161", ",", "0", ",", "8", ",", "0", ",", "0", ",", "8", ",", "128", ",", "0", ",", "8", ",", "64", ",", "0", ",", "9", ",", "225", ",", "80", ",", "7", ",", "6", ",", "0", ",", "8", ",", "88", ",", "0", ",", "8", ",", "24", ",", "0", ",", "9", ",", "145", ",", "83", ",", "7", ",", "59", ",", "0", ",", "8", ",", "120", ",", "0", ",", "8", ",", "56", ",", "0", ",", "9", ",", "209", ",", "81", ",", "7", ",", "17", ",", "0", ",", "8", ",", "104", ",", "0", ",", "8", ",", "40", ",", "0", ",", "9", ",", "177", ",", "0", ",", "8", ",", "8", ",", "0", ",", "8", ",", "136", ",", "0", ",", "8", ",", "72", ",", "0", ",", "9", ",", "241", ",", "80", ",", "7", ",", "4", ",", "0", ",", "8", ",", "84", ",", "0", ",", "8", ",", "20", ",", "85", ",", "8", ",", "227", ",", "83", ",", "7", ",", "43", ",", "0", ",", "8", ",", "116", ",", "0", ",", "8", ",", "52", ",", "0", ",", "9", ",", "201", ",", "81", ",", "7", ",", "13", ",", "0", ",", "8", ",", "100", ",", "0", ",", "8", ",", "36", ",", "0", ",", "9", ",", "169", ",", "0", ",", "8", ",", "4", ",", "0", ",", "8", ",", "132", ",", "0", ",", "8", ",", "68", ",", "0", ",", "9", ",", "233", ",", "80", ",", "7", ",", "8", ",", "0", ",", "8", ",", "92", ",", "0", ",", "8", ",", "28", ",", "0", ",", "9", ",", "153", ",", "84", ",", "7", ",", "83", ",", "0", ",", "8", ",", "124", ",", "0", ",", "8", ",", "60", ",", "0", ",", "9", ",", "217", ",", "82", ",", "7", ",", "23", ",", "0", ",", "8", ",", "108", ",", "0", ",", "8", ",", "44", ",", "0", ",", "9", ",", "185", ",", "0", ",", "8", ",", "12", ",", "0", ",", "8", ",", "140", ",", "0", ",", "8", ",", "76", ",", "0", ",", "9", ",", "249", ",", "80", ",", "7", ",", "3", ",", "0", ",", "8", ",", "82", ",", "0", ",", "8", ",", "18", ",", "85", ",", "8", ",", "163", ",", "83", ",", "7", ",", "35", ",", "0", ",", "8", ",", "114", ",", "0", ",", "8", ",", "50", ",", "0", ",", "9", ",", "197", ",", "81", ",", "7", ",", "11", ",", "0", ",", "8", ",", "98", ",", "0", ",", "8", ",", "34", ",", "0", ",", "9", ",", "165", ",", "0", ",", "8", ",", "2", ",", "0", ",", "8", ",", "130", ",", "0", ",", "8", ",", "66", ",", "0", ",", "9", ",", "229", ",", "80", ",", "7", ",", "7", ",", "0", ",", "8", ",", "90", ",", "0", ",", "8", ",", "26", ",", "0", ",", "9", ",", "149", ",", "84", ",", "7", ",", "67", ",", "0", ",", "8", ",", "122", ",", "0", ",", "8", ",", "58", ",", "0", ",", "9", ",", "213", ",", "82", ",", "7", ",", "19", ",", "0", ",", "8", ",", "106", ",", "0", ",", "8", ",", "42", ",", "0", ",", "9", ",", "181", ",", "0", ",", "8", ",", "10", ",", "0", ",", "8", ",", "138", ",", "0", ",", "8", ",", "74", ",", "0", ",", "9", ",", "245", ",", "80", ",", "7", ",", "5", ",", "0", ",", "8", ",", "86", ",", "0", ",", "8", ",", "22", ",", "192", ",", "8", ",", "0", ",", "83", ",", "7", ",", "51", ",", "0", ",", "8", ",", "118", ",", "0", ",", "8", ",", "54", ",", "0", ",", "9", ",", "205", ",", "81", ",", "7", ",", "15", ",", "0", ",", "8", ",", "102", ",", "0", ",", "8", ",", "38", ",", "0", ",", "9", ",", "173", ",", "0", ",", "8", ",", "6", ",", "0", ",", "8", ",", "134", ",", "0", ",", "8", ",", "70", ",", "0", ",", "9", ",", "237", ",", "80", ",", "7", ",", "9", ",", "0", ",", "8", ",", "94", ",", "0", ",", "8", ",", "30", ",", "0", ",", "9", ",", "157", ",", "84", ",", "7", ",", "99", ",", "0", ",", "8", ",", "126", ",", "0", ",", "8", ",", "62", ",", "0", ",", "9", ",", "221", ",", "82", ",", "7", ",", "27", ",", "0", ",", "8", ",", "110", ",", "0", ",", "8", ",", "46", ",", "0", ",", "9", ",", "189", ",", "0", ",", "8", ",", "14", ",", "0", ",", "8", ",", "142", ",", "0", ",", "8", ",", "78", ",", "0", ",", "9", ",", "253", ",", "96", ",", "7", ",", "256", ",", "0", ",", "8", ",", "81", ",", "0", ",", "8", ",", "17", ",", "85", ",", "8", ",", "131", ",", "82", ",", "7", ",", "31", ",", "0", ",", "8", ",", "113", ",", "0", ",", "8", ",", "49", ",", "0", ",", "9", ",", "195", ",", "80", ",", "7", ",", "10", ",", "0", ",", "8", ",", "97", ",", "0", ",", "8", ",", "33", ",", "0", ",", "9", ",", "163", ",", "0", ",", "8", ",", "1", ",", "0", ",", "8", ",", "129", ",", "0", ",", "8", ",", "65", ",", "0", ",", "9", ",", "227", ",", "80", ",", "7", ",", "6", ",", "0", ",", "8", ",", "89", ",", "0", ",", "8", ",", "25", ",", "0", ",", "9", ",", "147", ",", "83", ",", "7", ",", "59", ",", "0", ",", "8", ",", "121", ",", "0", ",", "8", ",", "57", ",", "0", ",", "9", ",", "211", ",", "81", ",", "7", ",", "17", ",", "0", ",", "8", ",", "105", ",", "0", ",", "8", ",", "41", ",", "0", ",", "9", ",", "179", ",", "0", ",", "8", ",", "9", ",", "0", ",", "8", ",", "137", ",", "0", ",", "8", ",", "73", ",", "0", ",", "9", ",", "243", ",", "80", ",", "7", ",", "4", ",", "0", ",", "8", ",", "85", ",", "0", ",", "8", ",", "21", ",", "80", ",", "8", ",", "258", ",", "83", ",", "7", ",", "43", ",", "0", ",", "8", ",", "117", ",", "0", ",", "8", ",", "53", ",", "0", ",", "9", ",", "203", ",", "81", ",", "7", ",", "13", ",", "0", ",", "8", ",", "101", ",", "0", ",", "8", ",", "37", ",", "0", ",", "9", ",", "171", ",", "0", ",", "8", ",", "5", ",", "0", ",", "8", ",", "133", ",", "0", ",", "8", ",", "69", ",", "0", ",", "9", ",", "235", ",", "80", ",", "7", ",", "8", ",", "0", ",", "8", ",", "93", ",", "0", ",", "8", ",", "29", ",", "0", ",", "9", ",", "155", ",", "84", ",", "7", ",", "83", ",", "0", ",", "8", ",", "125", ",", "0", ",", "8", ",", "61", ",", "0", ",", "9", ",", "219", ",", "82", ",", "7", ",", "23", ",", "0", ",", "8", ",", "109", ",", "0", ",", "8", ",", "45", ",", "0", ",", "9", ",", "187", ",", "0", ",", "8", ",", "13", ",", "0", ",", "8", ",", "141", ",", "0", ",", "8", ",", "77", ",", "0", ",", "9", ",", "251", ",", "80", ",", "7", ",", "3", ",", "0", ",", "8", ",", "83", ",", "0", ",", "8", ",", "19", ",", "85", ",", "8", ",", "195", ",", "83", ",", "7", ",", "35", ",", "0", ",", "8", ",", "115", ",", "0", ",", "8", ",", "51", ",", "0", ",", "9", ",", "199", ",", "81", ",", "7", ",", "11", ",", "0", ",", "8", ",", "99", ",", "0", ",", "8", ",", "35", ",", "0", ",", "9", ",", "167", ",", "0", ",", "8", ",", "3", ",", "0", ",", "8", ",", "131", ",", "0", ",", "8", ",", "67", ",", "0", ",", "9", ",", "231", ",", "80", ",", "7", ",", "7", ",", "0", ",", "8", ",", "91", ",", "0", ",", "8", ",", "27", ",", "0", ",", "9", ",", "151", ",", "84", ",", "7", ",", "67", ",", "0", ",", "8", ",", "123", ",", "0", ",", "8", ",", "59", ",", "0", ",", "9", ",", "215", ",", "82", ",", "7", ",", "19", ",", "0", ",", "8", ",", "107", ",", "0", ",", "8", ",", "43", ",", "0", ",", "9", ",", "183", ",", "0", ",", "8", ",", "11", ",", "0", ",", "8", ",", "139", ",", "0", ",", "8", ",", "75", ",", "0", ",", "9", ",", "247", ",", "80", ",", "7", ",", "5", ",", "0", ",", "8", ",", "87", ",", "0", ",", "8", ",", "23", ",", "192", ",", "8", ",", "0", ",", "83", ",", "7", ",", "51", ",", "0", ",", "8", ",", "119", ",", "0", ",", "8", ",", "55", ",", "0", ",", "9", ",", "207", ",", "81", ",", "7", ",", "15", ",", "0", ",", "8", ",", "103", ",", "0", ",", "8", ",", "39", ",", "0", ",", "9", ",", "175", ",", "0", ",", "8", ",", "7", ",", "0", ",", "8", ",", "135", ",", "0", ",", "8", ",", "71", ",", "0", ",", "9", ",", "239", ",", "80", ",", "7", ",", "9", ",", "0", ",", "8", ",", "95", ",", "0", ",", "8", ",", "31", ",", "0", ",", "9", ",", "159", ",", "84", ",", "7", ",", "99", ",", "0", ",", "8", ",", "127", ",", "0", ",", "8", ",", "63", ",", "0", ",", "9", ",", "223", ",", "82", ",", "7", ",", "27", ",", "0", ",", "8", ",", "111", ",", "0", ",", "8", ",", "47", ",", "0", ",", "9", ",", "191", ",", "0", ",", "8", ",", "15", ",", "0", ",", "8", ",", "143", ",", "0", ",", "8", ",", "79", ",", "0", ",", "9", ",", "255", "}", ";", "static", "final", "int", "[", "]", "fixed_td", "=", "{", "80", ",", "5", ",", "1", ",", "87", ",", "5", ",", "257", ",", "83", ",", "5", ",", "17", ",", "91", ",", "5", ",", "4097", ",", "81", ",", "5", ",", "5", ",", "89", ",", "5", ",", "1025", ",", "85", ",", "5", ",", "65", ",", "93", ",", "5", ",", "16385", ",", "80", ",", "5", ",", "3", ",", "88", ",", "5", ",", "513", ",", "84", ",", "5", ",", "33", ",", "92", ",", "5", ",", "8193", ",", "82", ",", "5", ",", "9", ",", "90", ",", "5", ",", "2049", ",", "86", ",", "5", ",", "129", ",", "192", ",", "5", ",", "24577", ",", "80", ",", "5", ",", "2", ",", "87", ",", "5", ",", "385", ",", "83", ",", "5", ",", "25", ",", "91", ",", "5", ",", "6145", ",", "81", ",", "5", ",", "7", ",", "89", ",", "5", ",", "1537", ",", "85", ",", "5", ",", "97", ",", "93", ",", "5", ",", "24577", ",", "80", ",", "5", ",", "4", ",", "88", ",", "5", ",", "769", ",", "84", ",", "5", ",", "49", ",", "92", ",", "5", ",", "12289", ",", "82", ",", "5", ",", "13", ",", "90", ",", "5", ",", "3073", ",", "86", ",", "5", ",", "193", ",", "192", ",", "5", ",", "24577", "}", ";", "static", "final", "int", "[", "]", "cplens", "=", "{", "3", ",", "4", ",", "5", ",", "6", ",", "7", ",", "8", ",", "9", ",", "10", ",", "11", ",", "13", ",", "15", ",", "17", ",", "19", ",", "23", ",", "27", ",", "31", ",", "35", ",", "43", ",", "51", ",", "59", ",", "67", ",", "83", ",", "99", ",", "115", ",", "131", ",", "163", ",", "195", ",", "227", ",", "258", ",", "0", ",", "0", "}", ";", "static", "final", "int", "[", "]", "cplext", "=", "{", "0", ",", "0", ",", "0", ",", "0", ",", "0", ",", "0", ",", "0", ",", "0", ",", "1", ",", "1", ",", "1", ",", "1", ",", "2", ",", "2", ",", "2", ",", "2", ",", "3", ",", "3", ",", "3", ",", "3", ",", "4", ",", "4", ",", "4", ",", "4", ",", "5", ",", "5", ",", "5", ",", "5", ",", "0", ",", "112", ",", "112", "}", ";", "static", "final", "int", "[", "]", "cpdist", "=", "{", "1", ",", "2", ",", "3", ",", "4", ",", "5", ",", "7", ",", "9", ",", "13", ",", "17", ",", "25", ",", "33", ",", "49", ",", "65", ",", "97", ",", "129", ",", "193", ",", "257", ",", "385", ",", "513", ",", "769", ",", "1025", ",", "1537", ",", "2049", ",", "3073", ",", "4097", ",", "6145", ",", "8193", ",", "12289", ",", "16385", ",", "24577", "}", ";", "static", "final", "int", "[", "]", "cpdext", "=", "{", "0", ",", "0", ",", "0", ",", "0", ",", "1", ",", "1", ",", "2", ",", "2", ",", "3", ",", "3", ",", "4", ",", "4", ",", "5", ",", "5", ",", "6", ",", "6", ",", "7", ",", "7", ",", "8", ",", "8", ",", "9", ",", "9", ",", "10", ",", "10", ",", "11", ",", "11", ",", "12", ",", "12", ",", "13", ",", "13", "}", ";", "static", "final", "int", "BMAX", "=", "15", ";", "int", "[", "]", "hn", "=", "null", ";", "int", "[", "]", "v", "=", "null", ";", "int", "[", "]", "c", "=", "null", ";", "int", "[", "]", "r", "=", "null", ";", "int", "[", "]", "u", "=", "null", ";", "int", "[", "]", "x", "=", "null", ";", "private", "int", "huft_build", "(", "int", "[", "]", "b", ",", "int", "bindex", ",", "int", "n", ",", "int", "s", ",", "int", "[", "]", "d", ",", "int", "[", "]", "e", ",", "int", "[", "]", "t", ",", "int", "[", "]", "m", ",", "int", "[", "]", "hp", ",", "int", "[", "]", "hn", ",", "int", "[", "]", "v", ")", "{", "int", "a", ";", "int", "f", ";", "int", "g", ";", "int", "h", ";", "int", "i", ";", "int", "j", ";", "int", "k", ";", "int", "l", ";", "int", "mask", ";", "int", "p", ";", "int", "q", ";", "int", "w", ";", "int", "xp", ";", "int", "y", ";", "int", "z", ";", "p", "=", "0", ";", "i", "=", "n", ";", "do", "{", "c", "[", "b", "[", "bindex", "+", "p", "]", "]", "++", ";", "p", "++", ";", "i", "--", ";", "}", "while", "(", "i", "!=", "0", ")", ";", "if", "(", "c", "[", "0", "]", "==", "n", ")", "{", "t", "[", "0", "]", "=", "-", "1", ";", "m", "[", "0", "]", "=", "0", ";", "return", "Z_OK", ";", "}", "l", "=", "m", "[", "0", "]", ";", "for", "(", "j", "=", "1", ";", "j", "<=", "BMAX", ";", "j", "++", ")", "if", "(", "c", "[", "j", "]", "!=", "0", ")", "break", ";", "k", "=", "j", ";", "if", "(", "l", "<", "j", ")", "{", "l", "=", "j", ";", "}", "for", "(", "i", "=", "BMAX", ";", "i", "!=", "0", ";", "i", "--", ")", "{", "if", "(", "c", "[", "i", "]", "!=", "0", ")", "break", ";", "}", "g", "=", "i", ";", "if", "(", "l", ">", "i", ")", "{", "l", "=", "i", ";", "}", "m", "[", "0", "]", "=", "l", ";", "for", "(", "y", "=", "1", "<<", "j", ";", "j", "<", "i", ";", "j", "++", ",", "y", "<<=", "1", ")", "{", "if", "(", "(", "y", "-=", "c", "[", "j", "]", ")", "<", "0", ")", "{", "return", "Z_DATA_ERROR", ";", "}", "}", "if", "(", "(", "y", "-=", "c", "[", "i", "]", ")", "<", "0", ")", "{", "return", "Z_DATA_ERROR", ";", "}", "c", "[", "i", "]", "+=", "y", ";", "x", "[", "1", "]", "=", "j", "=", "0", ";", "p", "=", "1", ";", "xp", "=", "2", ";", "while", "(", "--", "i", "!=", "0", ")", "{", "x", "[", "xp", "]", "=", "(", "j", "+=", "c", "[", "p", "]", ")", ";", "xp", "++", ";", "p", "++", ";", "}", "i", "=", "0", ";", "p", "=", "0", ";", "do", "{", "if", "(", "(", "j", "=", "b", "[", "bindex", "+", "p", "]", ")", "!=", "0", ")", "{", "v", "[", "x", "[", "j", "]", "++", "]", "=", "i", ";", "}", "p", "++", ";", "}", "while", "(", "++", "i", "<", "n", ")", ";", "n", "=", "x", "[", "g", "]", ";", "x", "[", "0", "]", "=", "i", "=", "0", ";", "p", "=", "0", ";", "h", "=", "-", "1", ";", "w", "=", "-", "l", ";", "u", "[", "0", "]", "=", "0", ";", "q", "=", "0", ";", "z", "=", "0", ";", "for", "(", ";", "k", "<=", "g", ";", "k", "++", ")", "{", "a", "=", "c", "[", "k", "]", ";", "while", "(", "a", "--", "!=", "0", ")", "{", "while", "(", "k", ">", "w", "+", "l", ")", "{", "h", "++", ";", "w", "+=", "l", ";", "z", "=", "g", "-", "w", ";", "z", "=", "(", "z", ">", "l", ")", "?", "l", ":", "z", ";", "if", "(", "(", "f", "=", "1", "<<", "(", "j", "=", "k", "-", "w", ")", ")", ">", "a", "+", "1", ")", "{", "f", "-=", "a", "+", "1", ";", "xp", "=", "k", ";", "if", "(", "j", "<", "z", ")", "{", "while", "(", "++", "j", "<", "z", ")", "{", "if", "(", "(", "f", "<<=", "1", ")", "<=", "c", "[", "++", "xp", "]", ")", "break", ";", "f", "-=", "c", "[", "xp", "]", ";", "}", "}", "}", "z", "=", "1", "<<", "j", ";", "if", "(", "hn", "[", "0", "]", "+", "z", ">", "MANY", ")", "{", "return", "Z_DATA_ERROR", ";", "}", "u", "[", "h", "]", "=", "q", "=", "hn", "[", "0", "]", ";", "hn", "[", "0", "]", "+=", "z", ";", "if", "(", "h", "!=", "0", ")", "{", "x", "[", "h", "]", "=", "i", ";", "r", "[", "0", "]", "=", "(", "byte", ")", "j", ";", "r", "[", "1", "]", "=", "(", "byte", ")", "l", ";", "j", "=", "i", ">>>", "(", "w", "-", "l", ")", ";", "r", "[", "2", "]", "=", "(", "int", ")", "(", "q", "-", "u", "[", "h", "-", "1", "]", "-", "j", ")", ";", "System", ".", "arraycopy", "(", "r", ",", "0", ",", "hp", ",", "(", "u", "[", "h", "-", "1", "]", "+", "j", ")", "*", "3", ",", "3", ")", ";", "}", "else", "{", "t", "[", "0", "]", "=", "q", ";", "}", "}", "r", "[", "1", "]", "=", "(", "byte", ")", "(", "k", "-", "w", ")", ";", "if", "(", "p", ">=", "n", ")", "{", "r", "[", "0", "]", "=", "128", "+", "64", ";", "}", "else", "if", "(", "v", "[", "p", "]", "<", "s", ")", "{", "r", "[", "0", "]", "=", "(", "byte", ")", "(", "v", "[", "p", "]", "<", "256", "?", "0", ":", "32", "+", "64", ")", ";", "r", "[", "2", "]", "=", "v", "[", "p", "++", "]", ";", "}", "else", "{", "r", "[", "0", "]", "=", "(", "byte", ")", "(", "e", "[", "v", "[", "p", "]", "-", "s", "]", "+", "16", "+", "64", ")", ";", "r", "[", "2", "]", "=", "d", "[", "v", "[", "p", "++", "]", "-", "s", "]", ";", "}", "f", "=", "1", "<<", "(", "k", "-", "w", ")", ";", "for", "(", "j", "=", "i", ">>>", "w", ";", "j", "<", "z", ";", "j", "+=", "f", ")", "{", "System", ".", "arraycopy", "(", "r", ",", "0", ",", "hp", ",", "(", "q", "+", "j", ")", "*", "3", ",", "3", ")", ";", "}", "for", "(", "j", "=", "1", "<<", "(", "k", "-", "1", ")", ";", "(", "i", "&", "j", ")", "!=", "0", ";", "j", ">>>=", "1", ")", "{", "i", "^=", "j", ";", "}", "i", "^=", "j", ";", "mask", "=", "(", "1", "<<", "w", ")", "-", "1", ";", "while", "(", "(", "i", "&", "mask", ")", "!=", "x", "[", "h", "]", ")", "{", "h", "--", ";", "w", "-=", "l", ";", "mask", "=", "(", "1", "<<", "w", ")", "-", "1", ";", "}", "}", "}", "return", "y", "!=", "0", "&&", "g", "!=", "1", "?", "Z_BUF_ERROR", ":", "Z_OK", ";", "}", "int", "inflate_trees_bits", "(", "int", "[", "]", "c", ",", "int", "[", "]", "bb", ",", "int", "[", "]", "tb", ",", "int", "[", "]", "hp", ",", "ZStream", "z", ")", "{", "int", "result", ";", "initWorkArea", "(", "19", ")", ";", "hn", "[", "0", "]", "=", "0", ";", "result", "=", "huft_build", "(", "c", ",", "0", ",", "19", ",", "19", ",", "null", ",", "null", ",", "tb", ",", "bb", ",", "hp", ",", "hn", ",", "v", ")", ";", "if", "(", "result", "==", "Z_DATA_ERROR", ")", "{", "z", ".", "msg", "=", "\"\"", ";", "}", "else", "if", "(", "result", "==", "Z_BUF_ERROR", "||", "bb", "[", "0", "]", "==", "0", ")", "{", "z", ".", "msg", "=", "\"\"", ";", "result", "=", "Z_DATA_ERROR", ";", "}", "return", "result", ";", "}", "int", "inflate_trees_dynamic", "(", "int", "nl", ",", "int", "nd", ",", "int", "[", "]", "c", ",", "int", "[", "]", "bl", ",", "int", "[", "]", "bd", ",", "int", "[", "]", "tl", ",", "int", "[", "]", "td", ",", "int", "[", "]", "hp", ",", "ZStream", "z", ")", "{", "int", "result", ";", "initWorkArea", "(", "288", ")", ";", "hn", "[", "0", "]", "=", "0", ";", "result", "=", "huft_build", "(", "c", ",", "0", ",", "nl", ",", "257", ",", "cplens", ",", "cplext", ",", "tl", ",", "bl", ",", "hp", ",", "hn", ",", "v", ")", ";", "if", "(", "result", "!=", "Z_OK", "||", "bl", "[", "0", "]", "==", "0", ")", "{", "if", "(", "result", "==", "Z_DATA_ERROR", ")", "{", "z", ".", "msg", "=", "\"\"", ";", "}", "else", "if", "(", "result", "!=", "Z_MEM_ERROR", ")", "{", "z", ".", "msg", "=", "\"\"", ";", "result", "=", "Z_DATA_ERROR", ";", "}", "return", "result", ";", "}", "initWorkArea", "(", "288", ")", ";", "result", "=", "huft_build", "(", "c", ",", "nl", ",", "nd", ",", "0", ",", "cpdist", ",", "cpdext", ",", "td", ",", "bd", ",", "hp", ",", "hn", ",", "v", ")", ";", "if", "(", "result", "!=", "Z_OK", "||", "(", "bd", "[", "0", "]", "==", "0", "&&", "nl", ">", "257", ")", ")", "{", "if", "(", "result", "==", "Z_DATA_ERROR", ")", "{", "z", ".", "msg", "=", "\"\"", ";", "}", "else", "if", "(", "result", "==", "Z_BUF_ERROR", ")", "{", "z", ".", "msg", "=", "\"\"", ";", "result", "=", "Z_DATA_ERROR", ";", "}", "else", "if", "(", "result", "!=", "Z_MEM_ERROR", ")", "{", "z", ".", "msg", "=", "\"\"", ";", "result", "=", "Z_DATA_ERROR", ";", "}", "return", "result", ";", "}", "return", "Z_OK", ";", "}", "static", "int", "inflate_trees_fixed", "(", "int", "[", "]", "bl", ",", "int", "[", "]", "bd", ",", "int", "[", "]", "[", "]", "tl", ",", "int", "[", "]", "[", "]", "td", ",", "ZStream", "z", ")", "{", "bl", "[", "0", "]", "=", "fixed_bl", ";", "bd", "[", "0", "]", "=", "fixed_bd", ";", "tl", "[", "0", "]", "=", "fixed_tl", ";", "td", "[", "0", "]", "=", "fixed_td", ";", "return", "Z_OK", ";", "}", "private", "void", "initWorkArea", "(", "int", "vsize", ")", "{", "if", "(", "hn", "==", "null", ")", "{", "hn", "=", "new", "int", "[", "1", "]", ";", "v", "=", "new", "int", "[", "vsize", "]", ";", "c", "=", "new", "int", "[", "BMAX", "+", "1", "]", ";", "r", "=", "new", "int", "[", "3", "]", ";", "u", "=", "new", "int", "[", "BMAX", "]", ";", "x", "=", "new", "int", "[", "BMAX", "+", "1", "]", ";", "}", "if", "(", "v", ".", "length", "<", "vsize", ")", "{", "v", "=", "new", "int", "[", "vsize", "]", ";", "}", "for", "(", "int", "i", "=", "0", ";", "i", "<", "vsize", ";", "i", "++", ")", "{", "v", "[", "i", "]", "=", "0", ";", "}", "for", "(", "int", "i", "=", "0", ";", "i", "<", "BMAX", "+", "1", ";", "i", "++", ")", "{", "c", "[", "i", "]", "=", "0", ";", "}", "for", "(", "int", "i", "=", "0", ";", "i", "<", "3", ";", "i", "++", ")", "{", "r", "[", "i", "]", "=", "0", ";", "}", "System", ".", "arraycopy", "(", "c", ",", "0", ",", "u", ",", "0", ",", "BMAX", ")", ";", "System", ".", "arraycopy", "(", "c", ",", "0", ",", "x", ",", "0", ",", "BMAX", "+", "1", ")", ";", "}", "}", "</s>" ]
7,721
[ "<s>", "package", "com", ".", "jcraft", ".", "jzlib", ";", "import", "java", ".", "io", ".", "*", ";", "public", "class", "ZOutputStream", "extends", "OutputStream", "{", "protected", "ZStream", "z", "=", "new", "ZStream", "(", ")", ";", "protected", "int", "bufsize", "=", "512", ";", "protected", "int", "flush", "=", "JZlib", ".", "Z_NO_FLUSH", ";", "protected", "byte", "[", "]", "buf", "=", "new", "byte", "[", "bufsize", "]", ",", "buf1", "=", "new", "byte", "[", "1", "]", ";", "protected", "boolean", "compress", ";", "protected", "OutputStream", "out", ";", "public", "ZOutputStream", "(", "OutputStream", "out", ")", "{", "super", "(", ")", ";", "this", ".", "out", "=", "out", ";", "z", ".", "inflateInit", "(", ")", ";", "compress", "=", "false", ";", "}", "public", "ZOutputStream", "(", "OutputStream", "out", ",", "int", "level", ")", "{", "this", "(", "out", ",", "level", ",", "false", ")", ";", "}", "public", "ZOutputStream", "(", "OutputStream", "out", ",", "int", "level", ",", "boolean", "nowrap", ")", "{", "super", "(", ")", ";", "this", ".", "out", "=", "out", ";", "z", ".", "deflateInit", "(", "level", ",", "nowrap", ")", ";", "compress", "=", "true", ";", "}", "public", "void", "write", "(", "int", "b", ")", "throws", "IOException", "{", "buf1", "[", "0", "]", "=", "(", "byte", ")", "b", ";", "write", "(", "buf1", ",", "0", ",", "1", ")", ";", "}", "public", "void", "write", "(", "byte", "b", "[", "]", ",", "int", "off", ",", "int", "len", ")", "throws", "IOException", "{", "if", "(", "len", "==", "0", ")", "return", ";", "int", "err", ";", "z", ".", "next_in", "=", "b", ";", "z", ".", "next_in_index", "=", "off", ";", "z", ".", "avail_in", "=", "len", ";", "do", "{", "z", ".", "next_out", "=", "buf", ";", "z", ".", "next_out_index", "=", "0", ";", "z", ".", "avail_out", "=", "bufsize", ";", "if", "(", "compress", ")", "err", "=", "z", ".", "deflate", "(", "flush", ")", ";", "else", "err", "=", "z", ".", "inflate", "(", "flush", ")", ";", "if", "(", "err", "!=", "JZlib", ".", "Z_OK", ")", "throw", "new", "ZStreamException", "(", "(", "compress", "?", "\"de\"", ":", "\"in\"", ")", "+", "\"flating:", "\"", "+", "z", ".", "msg", ")", ";", "out", ".", "write", "(", "buf", ",", "0", ",", "bufsize", "-", "z", ".", "avail_out", ")", ";", "}", "while", "(", "z", ".", "avail_in", ">", "0", "||", "z", ".", "avail_out", "==", "0", ")", ";", "}", "public", "int", "getFlushMode", "(", ")", "{", "return", "(", "flush", ")", ";", "}", "public", "void", "setFlushMode", "(", "int", "flush", ")", "{", "this", ".", "flush", "=", "flush", ";", "}", "public", "void", "finish", "(", ")", "throws", "IOException", "{", "int", "err", ";", "do", "{", "z", ".", "next_out", "=", "buf", ";", "z", ".", "next_out_index", "=", "0", ";", "z", ".", "avail_out", "=", "bufsize", ";", "if", "(", "compress", ")", "{", "err", "=", "z", ".", "deflate", "(", "JZlib", ".", "Z_FINISH", ")", ";", "}", "else", "{", "err", "=", "z", ".", "inflate", "(", "JZlib", ".", "Z_FINISH", ")", ";", "}", "if", "(", "err", "!=", "JZlib", ".", "Z_STREAM_END", "&&", "err", "!=", "JZlib", ".", "Z_OK", ")", "throw", "new", "ZStreamException", "(", "(", "compress", "?", "\"de\"", ":", "\"in\"", ")", "+", "\"flating:", "\"", "+", "z", ".", "msg", ")", ";", "if", "(", "bufsize", "-", "z", ".", "avail_out", ">", "0", ")", "{", "out", ".", "write", "(", "buf", ",", "0", ",", "bufsize", "-", "z", ".", "avail_out", ")", ";", "}", "}", "while", "(", "z", ".", "avail_in", ">", "0", "||", "z", ".", "avail_out", "==", "0", ")", ";", "flush", "(", ")", ";", "}", "public", "void", "end", "(", ")", "{", "if", "(", "z", "==", "null", ")", "return", ";", "if", "(", "compress", ")", "{", "z", ".", "deflateEnd", "(", ")", ";", "}", "else", "{", "z", ".", "inflateEnd", "(", ")", ";", "}", "z", ".", "free", "(", ")", ";", "z", "=", "null", ";", "}", "public", "void", "close", "(", ")", "throws", "IOException", "{", "try", "{", "try", "{", "finish", "(", ")", ";", "}", "catch", "(", "IOException", "ignored", ")", "{", "}", "}", "finally", "{", "end", "(", ")", ";", "out", ".", "close", "(", ")", ";", "out", "=", "null", ";", "}", "}", "public", "long", "getTotalIn", "(", ")", "{", "return", "z", ".", "total_in", ";", "}", "public", "long", "getTotalOut", "(", ")", "{", "return", "z", ".", "total_out", ";", "}", "public", "void", "flush", "(", ")", "throws", "IOException", "{", "out", ".", "flush", "(", ")", ";", "}", "}", "</s>" ]
7,722
[ "<s>", "package", "com", ".", "jcraft", ".", "jzlib", ";", "final", "public", "class", "ZStream", "{", "static", "final", "private", "int", "MAX_WBITS", "=", "15", ";", "static", "final", "private", "int", "DEF_WBITS", "=", "MAX_WBITS", ";", "static", "final", "private", "int", "Z_NO_FLUSH", "=", "0", ";", "static", "final", "private", "int", "Z_PARTIAL_FLUSH", "=", "1", ";", "static", "final", "private", "int", "Z_SYNC_FLUSH", "=", "2", ";", "static", "final", "private", "int", "Z_FULL_FLUSH", "=", "3", ";", "static", "final", "private", "int", "Z_FINISH", "=", "4", ";", "static", "final", "private", "int", "MAX_MEM_LEVEL", "=", "9", ";", "static", "public", "final", "int", "Z_OK", "=", "0", ";", "static", "public", "final", "int", "Z_STREAM_END", "=", "1", ";", "static", "public", "final", "int", "Z_NEED_DICT", "=", "2", ";", "static", "public", "final", "int", "Z_ERRNO", "=", "-", "1", ";", "static", "public", "final", "int", "Z_STREAM_ERROR", "=", "-", "2", ";", "static", "public", "final", "int", "Z_DATA_ERROR", "=", "-", "3", ";", "static", "public", "final", "int", "Z_MEM_ERROR", "=", "-", "4", ";", "static", "public", "final", "int", "Z_BUF_ERROR", "=", "-", "5", ";", "static", "public", "final", "int", "Z_VERSION_ERROR", "=", "-", "6", ";", "public", "byte", "[", "]", "next_in", ";", "public", "int", "next_in_index", ";", "public", "int", "avail_in", ";", "public", "long", "total_in", ";", "public", "byte", "[", "]", "next_out", ";", "public", "int", "next_out_index", ";", "public", "int", "avail_out", ";", "public", "long", "total_out", ";", "public", "String", "msg", ";", "Deflate", "dstate", ";", "Inflate", "istate", ";", "int", "data_type", ";", "public", "long", "adler", ";", "Adler32", "_adler", "=", "new", "Adler32", "(", ")", ";", "public", "int", "inflateInit", "(", ")", "{", "return", "inflateInit", "(", "DEF_WBITS", ")", ";", "}", "public", "int", "inflateInit", "(", "boolean", "nowrap", ")", "{", "return", "inflateInit", "(", "DEF_WBITS", ",", "nowrap", ")", ";", "}", "public", "int", "inflateInit", "(", "int", "w", ")", "{", "return", "inflateInit", "(", "w", ",", "false", ")", ";", "}", "public", "int", "inflateInit", "(", "int", "w", ",", "boolean", "nowrap", ")", "{", "istate", "=", "new", "Inflate", "(", ")", ";", "return", "istate", ".", "inflateInit", "(", "this", ",", "nowrap", "?", "-", "w", ":", "w", ")", ";", "}", "public", "int", "inflate", "(", "int", "f", ")", "{", "if", "(", "istate", "==", "null", ")", "return", "Z_STREAM_ERROR", ";", "return", "istate", ".", "inflate", "(", "this", ",", "f", ")", ";", "}", "public", "int", "inflateEnd", "(", ")", "{", "if", "(", "istate", "==", "null", ")", "return", "Z_STREAM_ERROR", ";", "int", "ret", "=", "istate", ".", "inflateEnd", "(", "this", ")", ";", "istate", "=", "null", ";", "return", "ret", ";", "}", "public", "int", "inflateSync", "(", ")", "{", "if", "(", "istate", "==", "null", ")", "return", "Z_STREAM_ERROR", ";", "return", "istate", ".", "inflateSync", "(", "this", ")", ";", "}", "public", "int", "inflateSetDictionary", "(", "byte", "[", "]", "dictionary", ",", "int", "dictLength", ")", "{", "if", "(", "istate", "==", "null", ")", "return", "Z_STREAM_ERROR", ";", "return", "istate", ".", "inflateSetDictionary", "(", "this", ",", "dictionary", ",", "dictLength", ")", ";", "}", "public", "int", "deflateInit", "(", "int", "level", ")", "{", "return", "deflateInit", "(", "level", ",", "MAX_WBITS", ")", ";", "}", "public", "int", "deflateInit", "(", "int", "level", ",", "boolean", "nowrap", ")", "{", "return", "deflateInit", "(", "level", ",", "MAX_WBITS", ",", "nowrap", ")", ";", "}", "public", "int", "deflateInit", "(", "int", "level", ",", "int", "bits", ")", "{", "return", "deflateInit", "(", "level", ",", "bits", ",", "false", ")", ";", "}", "public", "int", "deflateInit", "(", "int", "level", ",", "int", "bits", ",", "boolean", "nowrap", ")", "{", "dstate", "=", "new", "Deflate", "(", ")", ";", "return", "dstate", ".", "deflateInit", "(", "this", ",", "level", ",", "nowrap", "?", "-", "bits", ":", "bits", ")", ";", "}", "public", "int", "deflateInit", "(", "int", "level", ",", "int", "method", ",", "int", "windowBits", ",", "int", "memLevel", ",", "int", "strategy", ")", "{", "dstate", "=", "new", "Deflate", "(", ")", ";", "return", "dstate", ".", "deflateInit2", "(", "this", ",", "level", ",", "method", ",", "windowBits", ",", "memLevel", ",", "strategy", ")", ";", "}", "public", "int", "deflate", "(", "int", "flush", ")", "{", "if", "(", "dstate", "==", "null", ")", "{", "return", "Z_STREAM_ERROR", ";", "}", "return", "dstate", ".", "deflate", "(", "this", ",", "flush", ")", ";", "}", "public", "int", "deflateEnd", "(", ")", "{", "if", "(", "dstate", "==", "null", ")", "return", "Z_STREAM_ERROR", ";", "int", "ret", "=", "dstate", ".", "deflateEnd", "(", ")", ";", "dstate", "=", "null", ";", "return", "ret", ";", "}", "public", "int", "deflateParams", "(", "int", "level", ",", "int", "strategy", ")", "{", "if", "(", "dstate", "==", "null", ")", "return", "Z_STREAM_ERROR", ";", "return", "dstate", ".", "deflateParams", "(", "this", ",", "level", ",", "strategy", ")", ";", "}", "public", "int", "deflateSetDictionary", "(", "byte", "[", "]", "dictionary", ",", "int", "dictLength", ")", "{", "if", "(", "dstate", "==", "null", ")", "return", "Z_STREAM_ERROR", ";", "return", "dstate", ".", "deflateSetDictionary", "(", "this", ",", "dictionary", ",", "dictLength", ")", ";", "}", "void", "flush_pending", "(", ")", "{", "int", "len", "=", "dstate", ".", "pending", ";", "if", "(", "len", ">", "avail_out", ")", "len", "=", "avail_out", ";", "if", "(", "len", "==", "0", ")", "return", ";", "if", "(", "dstate", ".", "pending_buf", ".", "length", "<=", "dstate", ".", "pending_out", "||", "next_out", ".", "length", "<=", "next_out_index", "||", "dstate", ".", "pending_buf", ".", "length", "<", "(", "dstate", ".", "pending_out", "+", "len", ")", "||", "next_out", ".", "length", "<", "(", "next_out_index", "+", "len", ")", ")", "{", "System", ".", "out", ".", "println", "(", "dstate", ".", "pending_buf", ".", "length", "+", "\",", "\"", "+", "dstate", ".", "pending_out", "+", "\",", "\"", "+", "next_out", ".", "length", "+", "\",", "\"", "+", "next_out_index", "+", "\",", "\"", "+", "len", ")", ";", "System", ".", "out", ".", "println", "(", "\"avail_out=\"", "+", "avail_out", ")", ";", "}", "System", ".", "arraycopy", "(", "dstate", ".", "pending_buf", ",", "dstate", ".", "pending_out", ",", "next_out", ",", "next_out_index", ",", "len", ")", ";", "next_out_index", "+=", "len", ";", "dstate", ".", "pending_out", "+=", "len", ";", "total_out", "+=", "len", ";", "avail_out", "-=", "len", ";", "dstate", ".", "pending", "-=", "len", ";", "if", "(", "dstate", ".", "pending", "==", "0", ")", "{", "dstate", ".", "pending_out", "=", "0", ";", "}", "}", "int", "read_buf", "(", "byte", "[", "]", "buf", ",", "int", "start", ",", "int", "size", ")", "{", "int", "len", "=", "avail_in", ";", "if", "(", "len", ">", "size", ")", "len", "=", "size", ";", "if", "(", "len", "==", "0", ")", "return", "0", ";", "avail_in", "-=", "len", ";", "if", "(", "dstate", ".", "noheader", "==", "0", ")", "{", "adler", "=", "_adler", ".", "adler32", "(", "adler", ",", "next_in", ",", "next_in_index", ",", "len", ")", ";", "}", "System", ".", "arraycopy", "(", "next_in", ",", "next_in_index", ",", "buf", ",", "start", ",", "len", ")", ";", "next_in_index", "+=", "len", ";", "total_in", "+=", "len", ";", "return", "len", ";", "}", "public", "void", "free", "(", ")", "{", "next_in", "=", "null", ";", "next_out", "=", "null", ";", "msg", "=", "null", ";", "_adler", "=", "null", ";", "}", "}", "</s>" ]
7,723
[ "<s>", "package", "com", ".", "jcraft", ".", "jzlib", ";", "final", "class", "Inflate", "{", "static", "final", "private", "int", "MAX_WBITS", "=", "15", ";", "static", "final", "private", "int", "PRESET_DICT", "=", "0x20", ";", "static", "final", "int", "Z_NO_FLUSH", "=", "0", ";", "static", "final", "int", "Z_PARTIAL_FLUSH", "=", "1", ";", "static", "final", "int", "Z_SYNC_FLUSH", "=", "2", ";", "static", "final", "int", "Z_FULL_FLUSH", "=", "3", ";", "static", "final", "int", "Z_FINISH", "=", "4", ";", "static", "final", "private", "int", "Z_DEFLATED", "=", "8", ";", "static", "final", "private", "int", "Z_OK", "=", "0", ";", "static", "final", "private", "int", "Z_STREAM_END", "=", "1", ";", "static", "final", "private", "int", "Z_NEED_DICT", "=", "2", ";", "static", "final", "private", "int", "Z_ERRNO", "=", "-", "1", ";", "static", "final", "private", "int", "Z_STREAM_ERROR", "=", "-", "2", ";", "static", "final", "private", "int", "Z_DATA_ERROR", "=", "-", "3", ";", "static", "final", "private", "int", "Z_MEM_ERROR", "=", "-", "4", ";", "static", "final", "private", "int", "Z_BUF_ERROR", "=", "-", "5", ";", "static", "final", "private", "int", "Z_VERSION_ERROR", "=", "-", "6", ";", "static", "final", "private", "int", "METHOD", "=", "0", ";", "static", "final", "private", "int", "FLAG", "=", "1", ";", "static", "final", "private", "int", "DICT4", "=", "2", ";", "static", "final", "private", "int", "DICT3", "=", "3", ";", "static", "final", "private", "int", "DICT2", "=", "4", ";", "static", "final", "private", "int", "DICT1", "=", "5", ";", "static", "final", "private", "int", "DICT0", "=", "6", ";", "static", "final", "private", "int", "BLOCKS", "=", "7", ";", "static", "final", "private", "int", "CHECK4", "=", "8", ";", "static", "final", "private", "int", "CHECK3", "=", "9", ";", "static", "final", "private", "int", "CHECK2", "=", "10", ";", "static", "final", "private", "int", "CHECK1", "=", "11", ";", "static", "final", "private", "int", "DONE", "=", "12", ";", "static", "final", "private", "int", "BAD", "=", "13", ";", "int", "mode", ";", "int", "method", ";", "long", "[", "]", "was", "=", "new", "long", "[", "1", "]", ";", "long", "need", ";", "int", "marker", ";", "int", "nowrap", ";", "int", "wbits", ";", "InfBlocks", "blocks", ";", "int", "inflateReset", "(", "ZStream", "z", ")", "{", "if", "(", "z", "==", "null", "||", "z", ".", "istate", "==", "null", ")", "return", "Z_STREAM_ERROR", ";", "z", ".", "total_in", "=", "z", ".", "total_out", "=", "0", ";", "z", ".", "msg", "=", "null", ";", "z", ".", "istate", ".", "mode", "=", "z", ".", "istate", ".", "nowrap", "!=", "0", "?", "BLOCKS", ":", "METHOD", ";", "z", ".", "istate", ".", "blocks", ".", "reset", "(", "z", ",", "null", ")", ";", "return", "Z_OK", ";", "}", "int", "inflateEnd", "(", "ZStream", "z", ")", "{", "if", "(", "blocks", "!=", "null", ")", "blocks", ".", "free", "(", "z", ")", ";", "blocks", "=", "null", ";", "return", "Z_OK", ";", "}", "int", "inflateInit", "(", "ZStream", "z", ",", "int", "w", ")", "{", "z", ".", "msg", "=", "null", ";", "blocks", "=", "null", ";", "nowrap", "=", "0", ";", "if", "(", "w", "<", "0", ")", "{", "w", "=", "-", "w", ";", "nowrap", "=", "1", ";", "}", "if", "(", "w", "<", "8", "||", "w", ">", "15", ")", "{", "inflateEnd", "(", "z", ")", ";", "return", "Z_STREAM_ERROR", ";", "}", "wbits", "=", "w", ";", "z", ".", "istate", ".", "blocks", "=", "new", "InfBlocks", "(", "z", ",", "z", ".", "istate", ".", "nowrap", "!=", "0", "?", "null", ":", "this", ",", "1", "<<", "w", ")", ";", "inflateReset", "(", "z", ")", ";", "return", "Z_OK", ";", "}", "int", "inflate", "(", "ZStream", "z", ",", "int", "f", ")", "{", "int", "r", ";", "int", "b", ";", "if", "(", "z", "==", "null", "||", "z", ".", "istate", "==", "null", "||", "z", ".", "next_in", "==", "null", ")", "return", "Z_STREAM_ERROR", ";", "f", "=", "f", "==", "Z_FINISH", "?", "Z_BUF_ERROR", ":", "Z_OK", ";", "r", "=", "Z_BUF_ERROR", ";", "while", "(", "true", ")", "{", "switch", "(", "z", ".", "istate", ".", "mode", ")", "{", "case", "METHOD", ":", "if", "(", "z", ".", "avail_in", "==", "0", ")", "return", "r", ";", "r", "=", "f", ";", "z", ".", "avail_in", "--", ";", "z", ".", "total_in", "++", ";", "if", "(", "(", "(", "z", ".", "istate", ".", "method", "=", "z", ".", "next_in", "[", "z", ".", "next_in_index", "++", "]", ")", "&", "0xf", ")", "!=", "Z_DEFLATED", ")", "{", "z", ".", "istate", ".", "mode", "=", "BAD", ";", "z", ".", "msg", "=", "\"\"", ";", "z", ".", "istate", ".", "marker", "=", "5", ";", "break", ";", "}", "if", "(", "(", "z", ".", "istate", ".", "method", ">>", "4", ")", "+", "8", ">", "z", ".", "istate", ".", "wbits", ")", "{", "z", ".", "istate", ".", "mode", "=", "BAD", ";", "z", ".", "msg", "=", "\"\"", ";", "z", ".", "istate", ".", "marker", "=", "5", ";", "break", ";", "}", "z", ".", "istate", ".", "mode", "=", "FLAG", ";", "case", "FLAG", ":", "if", "(", "z", ".", "avail_in", "==", "0", ")", "return", "r", ";", "r", "=", "f", ";", "z", ".", "avail_in", "--", ";", "z", ".", "total_in", "++", ";", "b", "=", "(", "z", ".", "next_in", "[", "z", ".", "next_in_index", "++", "]", ")", "&", "0xff", ";", "if", "(", "(", "(", "(", "z", ".", "istate", ".", "method", "<<", "8", ")", "+", "b", ")", "%", "31", ")", "!=", "0", ")", "{", "z", ".", "istate", ".", "mode", "=", "BAD", ";", "z", ".", "msg", "=", "\"\"", ";", "z", ".", "istate", ".", "marker", "=", "5", ";", "break", ";", "}", "if", "(", "(", "b", "&", "PRESET_DICT", ")", "==", "0", ")", "{", "z", ".", "istate", ".", "mode", "=", "BLOCKS", ";", "break", ";", "}", "z", ".", "istate", ".", "mode", "=", "DICT4", ";", "case", "DICT4", ":", "if", "(", "z", ".", "avail_in", "==", "0", ")", "return", "r", ";", "r", "=", "f", ";", "z", ".", "avail_in", "--", ";", "z", ".", "total_in", "++", ";", "z", ".", "istate", ".", "need", "=", "(", "(", "z", ".", "next_in", "[", "z", ".", "next_in_index", "++", "]", "&", "0xff", ")", "<<", "24", ")", "&", "0xff000000L", ";", "z", ".", "istate", ".", "mode", "=", "DICT3", ";", "case", "DICT3", ":", "if", "(", "z", ".", "avail_in", "==", "0", ")", "return", "r", ";", "r", "=", "f", ";", "z", ".", "avail_in", "--", ";", "z", ".", "total_in", "++", ";", "z", ".", "istate", ".", "need", "+=", "(", "(", "z", ".", "next_in", "[", "z", ".", "next_in_index", "++", "]", "&", "0xff", ")", "<<", "16", ")", "&", "0xff0000L", ";", "z", ".", "istate", ".", "mode", "=", "DICT2", ";", "case", "DICT2", ":", "if", "(", "z", ".", "avail_in", "==", "0", ")", "return", "r", ";", "r", "=", "f", ";", "z", ".", "avail_in", "--", ";", "z", ".", "total_in", "++", ";", "z", ".", "istate", ".", "need", "+=", "(", "(", "z", ".", "next_in", "[", "z", ".", "next_in_index", "++", "]", "&", "0xff", ")", "<<", "8", ")", "&", "0xff00L", ";", "z", ".", "istate", ".", "mode", "=", "DICT1", ";", "case", "DICT1", ":", "if", "(", "z", ".", "avail_in", "==", "0", ")", "return", "r", ";", "r", "=", "f", ";", "z", ".", "avail_in", "--", ";", "z", ".", "total_in", "++", ";", "z", ".", "istate", ".", "need", "+=", "(", "z", ".", "next_in", "[", "z", ".", "next_in_index", "++", "]", "&", "0xffL", ")", ";", "z", ".", "adler", "=", "z", ".", "istate", ".", "need", ";", "z", ".", "istate", ".", "mode", "=", "DICT0", ";", "return", "Z_NEED_DICT", ";", "case", "DICT0", ":", "z", ".", "istate", ".", "mode", "=", "BAD", ";", "z", ".", "msg", "=", "\"\"", ";", "z", ".", "istate", ".", "marker", "=", "0", ";", "return", "Z_STREAM_ERROR", ";", "case", "BLOCKS", ":", "r", "=", "z", ".", "istate", ".", "blocks", ".", "proc", "(", "z", ",", "r", ")", ";", "if", "(", "r", "==", "Z_DATA_ERROR", ")", "{", "z", ".", "istate", ".", "mode", "=", "BAD", ";", "z", ".", "istate", ".", "marker", "=", "0", ";", "break", ";", "}", "if", "(", "r", "==", "Z_OK", ")", "{", "r", "=", "f", ";", "}", "if", "(", "r", "!=", "Z_STREAM_END", ")", "{", "return", "r", ";", "}", "r", "=", "f", ";", "z", ".", "istate", ".", "blocks", ".", "reset", "(", "z", ",", "z", ".", "istate", ".", "was", ")", ";", "if", "(", "z", ".", "istate", ".", "nowrap", "!=", "0", ")", "{", "z", ".", "istate", ".", "mode", "=", "DONE", ";", "break", ";", "}", "z", ".", "istate", ".", "mode", "=", "CHECK4", ";", "case", "CHECK4", ":", "if", "(", "z", ".", "avail_in", "==", "0", ")", "return", "r", ";", "r", "=", "f", ";", "z", ".", "avail_in", "--", ";", "z", ".", "total_in", "++", ";", "z", ".", "istate", ".", "need", "=", "(", "(", "z", ".", "next_in", "[", "z", ".", "next_in_index", "++", "]", "&", "0xff", ")", "<<", "24", ")", "&", "0xff000000L", ";", "z", ".", "istate", ".", "mode", "=", "CHECK3", ";", "case", "CHECK3", ":", "if", "(", "z", ".", "avail_in", "==", "0", ")", "return", "r", ";", "r", "=", "f", ";", "z", ".", "avail_in", "--", ";", "z", ".", "total_in", "++", ";", "z", ".", "istate", ".", "need", "+=", "(", "(", "z", ".", "next_in", "[", "z", ".", "next_in_index", "++", "]", "&", "0xff", ")", "<<", "16", ")", "&", "0xff0000L", ";", "z", ".", "istate", ".", "mode", "=", "CHECK2", ";", "case", "CHECK2", ":", "if", "(", "z", ".", "avail_in", "==", "0", ")", "return", "r", ";", "r", "=", "f", ";", "z", ".", "avail_in", "--", ";", "z", ".", "total_in", "++", ";", "z", ".", "istate", ".", "need", "+=", "(", "(", "z", ".", "next_in", "[", "z", ".", "next_in_index", "++", "]", "&", "0xff", ")", "<<", "8", ")", "&", "0xff00L", ";", "z", ".", "istate", ".", "mode", "=", "CHECK1", ";", "case", "CHECK1", ":", "if", "(", "z", ".", "avail_in", "==", "0", ")", "return", "r", ";", "r", "=", "f", ";", "z", ".", "avail_in", "--", ";", "z", ".", "total_in", "++", ";", "z", ".", "istate", ".", "need", "+=", "(", "z", ".", "next_in", "[", "z", ".", "next_in_index", "++", "]", "&", "0xffL", ")", ";", "if", "(", "(", "(", "int", ")", "(", "z", ".", "istate", ".", "was", "[", "0", "]", ")", ")", "!=", "(", "(", "int", ")", "(", "z", ".", "istate", ".", "need", ")", ")", ")", "{", "z", ".", "istate", ".", "mode", "=", "BAD", ";", "z", ".", "msg", "=", "\"\"", ";", "z", ".", "istate", ".", "marker", "=", "5", ";", "break", ";", "}", "z", ".", "istate", ".", "mode", "=", "DONE", ";", "case", "DONE", ":", "return", "Z_STREAM_END", ";", "case", "BAD", ":", "return", "Z_DATA_ERROR", ";", "default", ":", "return", "Z_STREAM_ERROR", ";", "}", "}", "}", "int", "inflateSetDictionary", "(", "ZStream", "z", ",", "byte", "[", "]", "dictionary", ",", "int", "dictLength", ")", "{", "int", "index", "=", "0", ";", "int", "length", "=", "dictLength", ";", "if", "(", "z", "==", "null", "||", "z", ".", "istate", "==", "null", "||", "z", ".", "istate", ".", "mode", "!=", "DICT0", ")", "return", "Z_STREAM_ERROR", ";", "if", "(", "z", ".", "_adler", ".", "adler32", "(", "1L", ",", "dictionary", ",", "0", ",", "dictLength", ")", "!=", "z", ".", "adler", ")", "{", "return", "Z_DATA_ERROR", ";", "}", "z", ".", "adler", "=", "z", ".", "_adler", ".", "adler32", "(", "0", ",", "null", ",", "0", ",", "0", ")", ";", "if", "(", "length", ">=", "(", "1", "<<", "z", ".", "istate", ".", "wbits", ")", ")", "{", "length", "=", "(", "1", "<<", "z", ".", "istate", ".", "wbits", ")", "-", "1", ";", "index", "=", "dictLength", "-", "length", ";", "}", "z", ".", "istate", ".", "blocks", ".", "set_dictionary", "(", "dictionary", ",", "index", ",", "length", ")", ";", "z", ".", "istate", ".", "mode", "=", "BLOCKS", ";", "return", "Z_OK", ";", "}", "static", "private", "byte", "[", "]", "mark", "=", "{", "(", "byte", ")", "0", ",", "(", "byte", ")", "0", ",", "(", "byte", ")", "0xff", ",", "(", "byte", ")", "0xff", "}", ";", "int", "inflateSync", "(", "ZStream", "z", ")", "{", "int", "n", ";", "int", "p", ";", "int", "m", ";", "long", "r", ",", "w", ";", "if", "(", "z", "==", "null", "||", "z", ".", "istate", "==", "null", ")", "return", "Z_STREAM_ERROR", ";", "if", "(", "z", ".", "istate", ".", "mode", "!=", "BAD", ")", "{", "z", ".", "istate", ".", "mode", "=", "BAD", ";", "z", ".", "istate", ".", "marker", "=", "0", ";", "}", "if", "(", "(", "n", "=", "z", ".", "avail_in", ")", "==", "0", ")", "return", "Z_BUF_ERROR", ";", "p", "=", "z", ".", "next_in_index", ";", "m", "=", "z", ".", "istate", ".", "marker", ";", "while", "(", "n", "!=", "0", "&&", "m", "<", "4", ")", "{", "if", "(", "z", ".", "next_in", "[", "p", "]", "==", "mark", "[", "m", "]", ")", "{", "m", "++", ";", "}", "else", "if", "(", "z", ".", "next_in", "[", "p", "]", "!=", "0", ")", "{", "m", "=", "0", ";", "}", "else", "{", "m", "=", "4", "-", "m", ";", "}", "p", "++", ";", "n", "--", ";", "}", "z", ".", "total_in", "+=", "p", "-", "z", ".", "next_in_index", ";", "z", ".", "next_in_index", "=", "p", ";", "z", ".", "avail_in", "=", "n", ";", "z", ".", "istate", ".", "marker", "=", "m", ";", "if", "(", "m", "!=", "4", ")", "{", "return", "Z_DATA_ERROR", ";", "}", "r", "=", "z", ".", "total_in", ";", "w", "=", "z", ".", "total_out", ";", "inflateReset", "(", "z", ")", ";", "z", ".", "total_in", "=", "r", ";", "z", ".", "total_out", "=", "w", ";", "z", ".", "istate", ".", "mode", "=", "BLOCKS", ";", "return", "Z_OK", ";", "}", "int", "inflateSyncPoint", "(", "ZStream", "z", ")", "{", "if", "(", "z", "==", "null", "||", "z", ".", "istate", "==", "null", "||", "z", ".", "istate", ".", "blocks", "==", "null", ")", "return", "Z_STREAM_ERROR", ";", "return", "z", ".", "istate", ".", "blocks", ".", "sync_point", "(", ")", ";", "}", "}", "</s>" ]
7,724
[ "<s>", "package", "com", ".", "jcraft", ".", "jzlib", ";", "final", "class", "InfCodes", "{", "static", "final", "private", "int", "[", "]", "inflate_mask", "=", "{", "0x00000000", ",", "0x00000001", ",", "0x00000003", ",", "0x00000007", ",", "0x0000000f", ",", "0x0000001f", ",", "0x0000003f", ",", "0x0000007f", ",", "0x000000ff", ",", "0x000001ff", ",", "0x000003ff", ",", "0x000007ff", ",", "0x00000fff", ",", "0x00001fff", ",", "0x00003fff", ",", "0x00007fff", ",", "0x0000ffff", "}", ";", "static", "final", "private", "int", "Z_OK", "=", "0", ";", "static", "final", "private", "int", "Z_STREAM_END", "=", "1", ";", "static", "final", "private", "int", "Z_NEED_DICT", "=", "2", ";", "static", "final", "private", "int", "Z_ERRNO", "=", "-", "1", ";", "static", "final", "private", "int", "Z_STREAM_ERROR", "=", "-", "2", ";", "static", "final", "private", "int", "Z_DATA_ERROR", "=", "-", "3", ";", "static", "final", "private", "int", "Z_MEM_ERROR", "=", "-", "4", ";", "static", "final", "private", "int", "Z_BUF_ERROR", "=", "-", "5", ";", "static", "final", "private", "int", "Z_VERSION_ERROR", "=", "-", "6", ";", "static", "final", "private", "int", "START", "=", "0", ";", "static", "final", "private", "int", "LEN", "=", "1", ";", "static", "final", "private", "int", "LENEXT", "=", "2", ";", "static", "final", "private", "int", "DIST", "=", "3", ";", "static", "final", "private", "int", "DISTEXT", "=", "4", ";", "static", "final", "private", "int", "COPY", "=", "5", ";", "static", "final", "private", "int", "LIT", "=", "6", ";", "static", "final", "private", "int", "WASH", "=", "7", ";", "static", "final", "private", "int", "END", "=", "8", ";", "static", "final", "private", "int", "BADCODE", "=", "9", ";", "int", "mode", ";", "int", "len", ";", "int", "[", "]", "tree", ";", "int", "tree_index", "=", "0", ";", "int", "need", ";", "int", "lit", ";", "int", "get", ";", "int", "dist", ";", "byte", "lbits", ";", "byte", "dbits", ";", "int", "[", "]", "ltree", ";", "int", "ltree_index", ";", "int", "[", "]", "dtree", ";", "int", "dtree_index", ";", "InfCodes", "(", ")", "{", "}", "void", "init", "(", "int", "bl", ",", "int", "bd", ",", "int", "[", "]", "tl", ",", "int", "tl_index", ",", "int", "[", "]", "td", ",", "int", "td_index", ",", "ZStream", "z", ")", "{", "mode", "=", "START", ";", "lbits", "=", "(", "byte", ")", "bl", ";", "dbits", "=", "(", "byte", ")", "bd", ";", "ltree", "=", "tl", ";", "ltree_index", "=", "tl_index", ";", "dtree", "=", "td", ";", "dtree_index", "=", "td_index", ";", "tree", "=", "null", ";", "}", "int", "proc", "(", "InfBlocks", "s", ",", "ZStream", "z", ",", "int", "r", ")", "{", "int", "j", ";", "int", "[", "]", "t", ";", "int", "tindex", ";", "int", "e", ";", "int", "b", "=", "0", ";", "int", "k", "=", "0", ";", "int", "p", "=", "0", ";", "int", "n", ";", "int", "q", ";", "int", "m", ";", "int", "f", ";", "p", "=", "z", ".", "next_in_index", ";", "n", "=", "z", ".", "avail_in", ";", "b", "=", "s", ".", "bitb", ";", "k", "=", "s", ".", "bitk", ";", "q", "=", "s", ".", "write", ";", "m", "=", "q", "<", "s", ".", "read", "?", "s", ".", "read", "-", "q", "-", "1", ":", "s", ".", "end", "-", "q", ";", "while", "(", "true", ")", "{", "switch", "(", "mode", ")", "{", "case", "START", ":", "if", "(", "m", ">=", "258", "&&", "n", ">=", "10", ")", "{", "s", ".", "bitb", "=", "b", ";", "s", ".", "bitk", "=", "k", ";", "z", ".", "avail_in", "=", "n", ";", "z", ".", "total_in", "+=", "p", "-", "z", ".", "next_in_index", ";", "z", ".", "next_in_index", "=", "p", ";", "s", ".", "write", "=", "q", ";", "r", "=", "inflate_fast", "(", "lbits", ",", "dbits", ",", "ltree", ",", "ltree_index", ",", "dtree", ",", "dtree_index", ",", "s", ",", "z", ")", ";", "p", "=", "z", ".", "next_in_index", ";", "n", "=", "z", ".", "avail_in", ";", "b", "=", "s", ".", "bitb", ";", "k", "=", "s", ".", "bitk", ";", "q", "=", "s", ".", "write", ";", "m", "=", "q", "<", "s", ".", "read", "?", "s", ".", "read", "-", "q", "-", "1", ":", "s", ".", "end", "-", "q", ";", "if", "(", "r", "!=", "Z_OK", ")", "{", "mode", "=", "r", "==", "Z_STREAM_END", "?", "WASH", ":", "BADCODE", ";", "break", ";", "}", "}", "need", "=", "lbits", ";", "tree", "=", "ltree", ";", "tree_index", "=", "ltree_index", ";", "mode", "=", "LEN", ";", "case", "LEN", ":", "j", "=", "need", ";", "while", "(", "k", "<", "(", "j", ")", ")", "{", "if", "(", "n", "!=", "0", ")", "r", "=", "Z_OK", ";", "else", "{", "s", ".", "bitb", "=", "b", ";", "s", ".", "bitk", "=", "k", ";", "z", ".", "avail_in", "=", "n", ";", "z", ".", "total_in", "+=", "p", "-", "z", ".", "next_in_index", ";", "z", ".", "next_in_index", "=", "p", ";", "s", ".", "write", "=", "q", ";", "return", "s", ".", "inflate_flush", "(", "z", ",", "r", ")", ";", "}", "n", "--", ";", "b", "|=", "(", "z", ".", "next_in", "[", "p", "++", "]", "&", "0xff", ")", "<<", "k", ";", "k", "+=", "8", ";", "}", "tindex", "=", "(", "tree_index", "+", "(", "b", "&", "inflate_mask", "[", "j", "]", ")", ")", "*", "3", ";", "b", ">>>=", "(", "tree", "[", "tindex", "+", "1", "]", ")", ";", "k", "-=", "(", "tree", "[", "tindex", "+", "1", "]", ")", ";", "e", "=", "tree", "[", "tindex", "]", ";", "if", "(", "e", "==", "0", ")", "{", "lit", "=", "tree", "[", "tindex", "+", "2", "]", ";", "mode", "=", "LIT", ";", "break", ";", "}", "if", "(", "(", "e", "&", "16", ")", "!=", "0", ")", "{", "get", "=", "e", "&", "15", ";", "len", "=", "tree", "[", "tindex", "+", "2", "]", ";", "mode", "=", "LENEXT", ";", "break", ";", "}", "if", "(", "(", "e", "&", "64", ")", "==", "0", ")", "{", "need", "=", "e", ";", "tree_index", "=", "tindex", "/", "3", "+", "tree", "[", "tindex", "+", "2", "]", ";", "break", ";", "}", "if", "(", "(", "e", "&", "32", ")", "!=", "0", ")", "{", "mode", "=", "WASH", ";", "break", ";", "}", "mode", "=", "BADCODE", ";", "z", ".", "msg", "=", "\"\"", ";", "r", "=", "Z_DATA_ERROR", ";", "s", ".", "bitb", "=", "b", ";", "s", ".", "bitk", "=", "k", ";", "z", ".", "avail_in", "=", "n", ";", "z", ".", "total_in", "+=", "p", "-", "z", ".", "next_in_index", ";", "z", ".", "next_in_index", "=", "p", ";", "s", ".", "write", "=", "q", ";", "return", "s", ".", "inflate_flush", "(", "z", ",", "r", ")", ";", "case", "LENEXT", ":", "j", "=", "get", ";", "while", "(", "k", "<", "(", "j", ")", ")", "{", "if", "(", "n", "!=", "0", ")", "r", "=", "Z_OK", ";", "else", "{", "s", ".", "bitb", "=", "b", ";", "s", ".", "bitk", "=", "k", ";", "z", ".", "avail_in", "=", "n", ";", "z", ".", "total_in", "+=", "p", "-", "z", ".", "next_in_index", ";", "z", ".", "next_in_index", "=", "p", ";", "s", ".", "write", "=", "q", ";", "return", "s", ".", "inflate_flush", "(", "z", ",", "r", ")", ";", "}", "n", "--", ";", "b", "|=", "(", "z", ".", "next_in", "[", "p", "++", "]", "&", "0xff", ")", "<<", "k", ";", "k", "+=", "8", ";", "}", "len", "+=", "(", "b", "&", "inflate_mask", "[", "j", "]", ")", ";", "b", ">>=", "j", ";", "k", "-=", "j", ";", "need", "=", "dbits", ";", "tree", "=", "dtree", ";", "tree_index", "=", "dtree_index", ";", "mode", "=", "DIST", ";", "case", "DIST", ":", "j", "=", "need", ";", "while", "(", "k", "<", "(", "j", ")", ")", "{", "if", "(", "n", "!=", "0", ")", "r", "=", "Z_OK", ";", "else", "{", "s", ".", "bitb", "=", "b", ";", "s", ".", "bitk", "=", "k", ";", "z", ".", "avail_in", "=", "n", ";", "z", ".", "total_in", "+=", "p", "-", "z", ".", "next_in_index", ";", "z", ".", "next_in_index", "=", "p", ";", "s", ".", "write", "=", "q", ";", "return", "s", ".", "inflate_flush", "(", "z", ",", "r", ")", ";", "}", "n", "--", ";", "b", "|=", "(", "z", ".", "next_in", "[", "p", "++", "]", "&", "0xff", ")", "<<", "k", ";", "k", "+=", "8", ";", "}", "tindex", "=", "(", "tree_index", "+", "(", "b", "&", "inflate_mask", "[", "j", "]", ")", ")", "*", "3", ";", "b", ">>=", "tree", "[", "tindex", "+", "1", "]", ";", "k", "-=", "tree", "[", "tindex", "+", "1", "]", ";", "e", "=", "(", "tree", "[", "tindex", "]", ")", ";", "if", "(", "(", "e", "&", "16", ")", "!=", "0", ")", "{", "get", "=", "e", "&", "15", ";", "dist", "=", "tree", "[", "tindex", "+", "2", "]", ";", "mode", "=", "DISTEXT", ";", "break", ";", "}", "if", "(", "(", "e", "&", "64", ")", "==", "0", ")", "{", "need", "=", "e", ";", "tree_index", "=", "tindex", "/", "3", "+", "tree", "[", "tindex", "+", "2", "]", ";", "break", ";", "}", "mode", "=", "BADCODE", ";", "z", ".", "msg", "=", "\"\"", ";", "r", "=", "Z_DATA_ERROR", ";", "s", ".", "bitb", "=", "b", ";", "s", ".", "bitk", "=", "k", ";", "z", ".", "avail_in", "=", "n", ";", "z", ".", "total_in", "+=", "p", "-", "z", ".", "next_in_index", ";", "z", ".", "next_in_index", "=", "p", ";", "s", ".", "write", "=", "q", ";", "return", "s", ".", "inflate_flush", "(", "z", ",", "r", ")", ";", "case", "DISTEXT", ":", "j", "=", "get", ";", "while", "(", "k", "<", "(", "j", ")", ")", "{", "if", "(", "n", "!=", "0", ")", "r", "=", "Z_OK", ";", "else", "{", "s", ".", "bitb", "=", "b", ";", "s", ".", "bitk", "=", "k", ";", "z", ".", "avail_in", "=", "n", ";", "z", ".", "total_in", "+=", "p", "-", "z", ".", "next_in_index", ";", "z", ".", "next_in_index", "=", "p", ";", "s", ".", "write", "=", "q", ";", "return", "s", ".", "inflate_flush", "(", "z", ",", "r", ")", ";", "}", "n", "--", ";", "b", "|=", "(", "z", ".", "next_in", "[", "p", "++", "]", "&", "0xff", ")", "<<", "k", ";", "k", "+=", "8", ";", "}", "dist", "+=", "(", "b", "&", "inflate_mask", "[", "j", "]", ")", ";", "b", ">>=", "j", ";", "k", "-=", "j", ";", "mode", "=", "COPY", ";", "case", "COPY", ":", "f", "=", "q", "-", "dist", ";", "while", "(", "f", "<", "0", ")", "{", "f", "+=", "s", ".", "end", ";", "}", "while", "(", "len", "!=", "0", ")", "{", "if", "(", "m", "==", "0", ")", "{", "if", "(", "q", "==", "s", ".", "end", "&&", "s", ".", "read", "!=", "0", ")", "{", "q", "=", "0", ";", "m", "=", "q", "<", "s", ".", "read", "?", "s", ".", "read", "-", "q", "-", "1", ":", "s", ".", "end", "-", "q", ";", "}", "if", "(", "m", "==", "0", ")", "{", "s", ".", "write", "=", "q", ";", "r", "=", "s", ".", "inflate_flush", "(", "z", ",", "r", ")", ";", "q", "=", "s", ".", "write", ";", "m", "=", "q", "<", "s", ".", "read", "?", "s", ".", "read", "-", "q", "-", "1", ":", "s", ".", "end", "-", "q", ";", "if", "(", "q", "==", "s", ".", "end", "&&", "s", ".", "read", "!=", "0", ")", "{", "q", "=", "0", ";", "m", "=", "q", "<", "s", ".", "read", "?", "s", ".", "read", "-", "q", "-", "1", ":", "s", ".", "end", "-", "q", ";", "}", "if", "(", "m", "==", "0", ")", "{", "s", ".", "bitb", "=", "b", ";", "s", ".", "bitk", "=", "k", ";", "z", ".", "avail_in", "=", "n", ";", "z", ".", "total_in", "+=", "p", "-", "z", ".", "next_in_index", ";", "z", ".", "next_in_index", "=", "p", ";", "s", ".", "write", "=", "q", ";", "return", "s", ".", "inflate_flush", "(", "z", ",", "r", ")", ";", "}", "}", "}", "s", ".", "window", "[", "q", "++", "]", "=", "s", ".", "window", "[", "f", "++", "]", ";", "m", "--", ";", "if", "(", "f", "==", "s", ".", "end", ")", "f", "=", "0", ";", "len", "--", ";", "}", "mode", "=", "START", ";", "break", ";", "case", "LIT", ":", "if", "(", "m", "==", "0", ")", "{", "if", "(", "q", "==", "s", ".", "end", "&&", "s", ".", "read", "!=", "0", ")", "{", "q", "=", "0", ";", "m", "=", "q", "<", "s", ".", "read", "?", "s", ".", "read", "-", "q", "-", "1", ":", "s", ".", "end", "-", "q", ";", "}", "if", "(", "m", "==", "0", ")", "{", "s", ".", "write", "=", "q", ";", "r", "=", "s", ".", "inflate_flush", "(", "z", ",", "r", ")", ";", "q", "=", "s", ".", "write", ";", "m", "=", "q", "<", "s", ".", "read", "?", "s", ".", "read", "-", "q", "-", "1", ":", "s", ".", "end", "-", "q", ";", "if", "(", "q", "==", "s", ".", "end", "&&", "s", ".", "read", "!=", "0", ")", "{", "q", "=", "0", ";", "m", "=", "q", "<", "s", ".", "read", "?", "s", ".", "read", "-", "q", "-", "1", ":", "s", ".", "end", "-", "q", ";", "}", "if", "(", "m", "==", "0", ")", "{", "s", ".", "bitb", "=", "b", ";", "s", ".", "bitk", "=", "k", ";", "z", ".", "avail_in", "=", "n", ";", "z", ".", "total_in", "+=", "p", "-", "z", ".", "next_in_index", ";", "z", ".", "next_in_index", "=", "p", ";", "s", ".", "write", "=", "q", ";", "return", "s", ".", "inflate_flush", "(", "z", ",", "r", ")", ";", "}", "}", "}", "r", "=", "Z_OK", ";", "s", ".", "window", "[", "q", "++", "]", "=", "(", "byte", ")", "lit", ";", "m", "--", ";", "mode", "=", "START", ";", "break", ";", "case", "WASH", ":", "if", "(", "k", ">", "7", ")", "{", "k", "-=", "8", ";", "n", "++", ";", "p", "--", ";", "}", "s", ".", "write", "=", "q", ";", "r", "=", "s", ".", "inflate_flush", "(", "z", ",", "r", ")", ";", "q", "=", "s", ".", "write", ";", "m", "=", "q", "<", "s", ".", "read", "?", "s", ".", "read", "-", "q", "-", "1", ":", "s", ".", "end", "-", "q", ";", "if", "(", "s", ".", "read", "!=", "s", ".", "write", ")", "{", "s", ".", "bitb", "=", "b", ";", "s", ".", "bitk", "=", "k", ";", "z", ".", "avail_in", "=", "n", ";", "z", ".", "total_in", "+=", "p", "-", "z", ".", "next_in_index", ";", "z", ".", "next_in_index", "=", "p", ";", "s", ".", "write", "=", "q", ";", "return", "s", ".", "inflate_flush", "(", "z", ",", "r", ")", ";", "}", "mode", "=", "END", ";", "case", "END", ":", "r", "=", "Z_STREAM_END", ";", "s", ".", "bitb", "=", "b", ";", "s", ".", "bitk", "=", "k", ";", "z", ".", "avail_in", "=", "n", ";", "z", ".", "total_in", "+=", "p", "-", "z", ".", "next_in_index", ";", "z", ".", "next_in_index", "=", "p", ";", "s", ".", "write", "=", "q", ";", "return", "s", ".", "inflate_flush", "(", "z", ",", "r", ")", ";", "case", "BADCODE", ":", "r", "=", "Z_DATA_ERROR", ";", "s", ".", "bitb", "=", "b", ";", "s", ".", "bitk", "=", "k", ";", "z", ".", "avail_in", "=", "n", ";", "z", ".", "total_in", "+=", "p", "-", "z", ".", "next_in_index", ";", "z", ".", "next_in_index", "=", "p", ";", "s", ".", "write", "=", "q", ";", "return", "s", ".", "inflate_flush", "(", "z", ",", "r", ")", ";", "default", ":", "r", "=", "Z_STREAM_ERROR", ";", "s", ".", "bitb", "=", "b", ";", "s", ".", "bitk", "=", "k", ";", "z", ".", "avail_in", "=", "n", ";", "z", ".", "total_in", "+=", "p", "-", "z", ".", "next_in_index", ";", "z", ".", "next_in_index", "=", "p", ";", "s", ".", "write", "=", "q", ";", "return", "s", ".", "inflate_flush", "(", "z", ",", "r", ")", ";", "}", "}", "}", "void", "free", "(", "ZStream", "z", ")", "{", "}", "int", "inflate_fast", "(", "int", "bl", ",", "int", "bd", ",", "int", "[", "]", "tl", ",", "int", "tl_index", ",", "int", "[", "]", "td", ",", "int", "td_index", ",", "InfBlocks", "s", ",", "ZStream", "z", ")", "{", "int", "t", ";", "int", "[", "]", "tp", ";", "int", "tp_index", ";", "int", "e", ";", "int", "b", ";", "int", "k", ";", "int", "p", ";", "int", "n", ";", "int", "q", ";", "int", "m", ";", "int", "ml", ";", "int", "md", ";", "int", "c", ";", "int", "d", ";", "int", "r", ";", "int", "tp_index_t_3", ";", "p", "=", "z", ".", "next_in_index", ";", "n", "=", "z", ".", "avail_in", ";", "b", "=", "s", ".", "bitb", ";", "k", "=", "s", ".", "bitk", ";", "q", "=", "s", ".", "write", ";", "m", "=", "q", "<", "s", ".", "read", "?", "s", ".", "read", "-", "q", "-", "1", ":", "s", ".", "end", "-", "q", ";", "ml", "=", "inflate_mask", "[", "bl", "]", ";", "md", "=", "inflate_mask", "[", "bd", "]", ";", "do", "{", "while", "(", "k", "<", "(", "20", ")", ")", "{", "n", "--", ";", "b", "|=", "(", "z", ".", "next_in", "[", "p", "++", "]", "&", "0xff", ")", "<<", "k", ";", "k", "+=", "8", ";", "}", "t", "=", "b", "&", "ml", ";", "tp", "=", "tl", ";", "tp_index", "=", "tl_index", ";", "tp_index_t_3", "=", "(", "tp_index", "+", "t", ")", "*", "3", ";", "if", "(", "(", "e", "=", "tp", "[", "tp_index_t_3", "]", ")", "==", "0", ")", "{", "b", ">>=", "(", "tp", "[", "tp_index_t_3", "+", "1", "]", ")", ";", "k", "-=", "(", "tp", "[", "tp_index_t_3", "+", "1", "]", ")", ";", "s", ".", "window", "[", "q", "++", "]", "=", "(", "byte", ")", "tp", "[", "tp_index_t_3", "+", "2", "]", ";", "m", "--", ";", "continue", ";", "}", "do", "{", "b", ">>=", "(", "tp", "[", "tp_index_t_3", "+", "1", "]", ")", ";", "k", "-=", "(", "tp", "[", "tp_index_t_3", "+", "1", "]", ")", ";", "if", "(", "(", "e", "&", "16", ")", "!=", "0", ")", "{", "e", "&=", "15", ";", "c", "=", "tp", "[", "tp_index_t_3", "+", "2", "]", "+", "(", "(", "int", ")", "b", "&", "inflate_mask", "[", "e", "]", ")", ";", "b", ">>=", "e", ";", "k", "-=", "e", ";", "while", "(", "k", "<", "(", "15", ")", ")", "{", "n", "--", ";", "b", "|=", "(", "z", ".", "next_in", "[", "p", "++", "]", "&", "0xff", ")", "<<", "k", ";", "k", "+=", "8", ";", "}", "t", "=", "b", "&", "md", ";", "tp", "=", "td", ";", "tp_index", "=", "td_index", ";", "tp_index_t_3", "=", "(", "tp_index", "+", "t", ")", "*", "3", ";", "e", "=", "tp", "[", "tp_index_t_3", "]", ";", "do", "{", "b", ">>=", "(", "tp", "[", "tp_index_t_3", "+", "1", "]", ")", ";", "k", "-=", "(", "tp", "[", "tp_index_t_3", "+", "1", "]", ")", ";", "if", "(", "(", "e", "&", "16", ")", "!=", "0", ")", "{", "e", "&=", "15", ";", "while", "(", "k", "<", "(", "e", ")", ")", "{", "n", "--", ";", "b", "|=", "(", "z", ".", "next_in", "[", "p", "++", "]", "&", "0xff", ")", "<<", "k", ";", "k", "+=", "8", ";", "}", "d", "=", "tp", "[", "tp_index_t_3", "+", "2", "]", "+", "(", "b", "&", "inflate_mask", "[", "e", "]", ")", ";", "b", ">>=", "(", "e", ")", ";", "k", "-=", "(", "e", ")", ";", "m", "-=", "c", ";", "if", "(", "q", ">=", "d", ")", "{", "r", "=", "q", "-", "d", ";", "if", "(", "q", "-", "r", ">", "0", "&&", "2", ">", "(", "q", "-", "r", ")", ")", "{", "s", ".", "window", "[", "q", "++", "]", "=", "s", ".", "window", "[", "r", "++", "]", ";", "s", ".", "window", "[", "q", "++", "]", "=", "s", ".", "window", "[", "r", "++", "]", ";", "c", "-=", "2", ";", "}", "else", "{", "System", ".", "arraycopy", "(", "s", ".", "window", ",", "r", ",", "s", ".", "window", ",", "q", ",", "2", ")", ";", "q", "+=", "2", ";", "r", "+=", "2", ";", "c", "-=", "2", ";", "}", "}", "else", "{", "r", "=", "q", "-", "d", ";", "do", "{", "r", "+=", "s", ".", "end", ";", "}", "while", "(", "r", "<", "0", ")", ";", "e", "=", "s", ".", "end", "-", "r", ";", "if", "(", "c", ">", "e", ")", "{", "c", "-=", "e", ";", "if", "(", "q", "-", "r", ">", "0", "&&", "e", ">", "(", "q", "-", "r", ")", ")", "{", "do", "{", "s", ".", "window", "[", "q", "++", "]", "=", "s", ".", "window", "[", "r", "++", "]", ";", "}", "while", "(", "--", "e", "!=", "0", ")", ";", "}", "else", "{", "System", ".", "arraycopy", "(", "s", ".", "window", ",", "r", ",", "s", ".", "window", ",", "q", ",", "e", ")", ";", "q", "+=", "e", ";", "r", "+=", "e", ";", "e", "=", "0", ";", "}", "r", "=", "0", ";", "}", "}", "if", "(", "q", "-", "r", ">", "0", "&&", "c", ">", "(", "q", "-", "r", ")", ")", "{", "do", "{", "s", ".", "window", "[", "q", "++", "]", "=", "s", ".", "window", "[", "r", "++", "]", ";", "}", "while", "(", "--", "c", "!=", "0", ")", ";", "}", "else", "{", "System", ".", "arraycopy", "(", "s", ".", "window", ",", "r", ",", "s", ".", "window", ",", "q", ",", "c", ")", ";", "q", "+=", "c", ";", "r", "+=", "c", ";", "c", "=", "0", ";", "}", "break", ";", "}", "else", "if", "(", "(", "e", "&", "64", ")", "==", "0", ")", "{", "t", "+=", "tp", "[", "tp_index_t_3", "+", "2", "]", ";", "t", "+=", "(", "b", "&", "inflate_mask", "[", "e", "]", ")", ";", "tp_index_t_3", "=", "(", "tp_index", "+", "t", ")", "*", "3", ";", "e", "=", "tp", "[", "tp_index_t_3", "]", ";", "}", "else", "{", "z", ".", "msg", "=", "\"\"", ";", "c", "=", "z", ".", "avail_in", "-", "n", ";", "c", "=", "(", "k", ">>", "3", ")", "<", "c", "?", "k", ">>", "3", ":", "c", ";", "n", "+=", "c", ";", "p", "-=", "c", ";", "k", "-=", "c", "<<", "3", ";", "s", ".", "bitb", "=", "b", ";", "s", ".", "bitk", "=", "k", ";", "z", ".", "avail_in", "=", "n", ";", "z", ".", "total_in", "+=", "p", "-", "z", ".", "next_in_index", ";", "z", ".", "next_in_index", "=", "p", ";", "s", ".", "write", "=", "q", ";", "return", "Z_DATA_ERROR", ";", "}", "}", "while", "(", "true", ")", ";", "break", ";", "}", "if", "(", "(", "e", "&", "64", ")", "==", "0", ")", "{", "t", "+=", "tp", "[", "tp_index_t_3", "+", "2", "]", ";", "t", "+=", "(", "b", "&", "inflate_mask", "[", "e", "]", ")", ";", "tp_index_t_3", "=", "(", "tp_index", "+", "t", ")", "*", "3", ";", "if", "(", "(", "e", "=", "tp", "[", "tp_index_t_3", "]", ")", "==", "0", ")", "{", "b", ">>=", "(", "tp", "[", "tp_index_t_3", "+", "1", "]", ")", ";", "k", "-=", "(", "tp", "[", "tp_index_t_3", "+", "1", "]", ")", ";", "s", ".", "window", "[", "q", "++", "]", "=", "(", "byte", ")", "tp", "[", "tp_index_t_3", "+", "2", "]", ";", "m", "--", ";", "break", ";", "}", "}", "else", "if", "(", "(", "e", "&", "32", ")", "!=", "0", ")", "{", "c", "=", "z", ".", "avail_in", "-", "n", ";", "c", "=", "(", "k", ">>", "3", ")", "<", "c", "?", "k", ">>", "3", ":", "c", ";", "n", "+=", "c", ";", "p", "-=", "c", ";", "k", "-=", "c", "<<", "3", ";", "s", ".", "bitb", "=", "b", ";", "s", ".", "bitk", "=", "k", ";", "z", ".", "avail_in", "=", "n", ";", "z", ".", "total_in", "+=", "p", "-", "z", ".", "next_in_index", ";", "z", ".", "next_in_index", "=", "p", ";", "s", ".", "write", "=", "q", ";", "return", "Z_STREAM_END", ";", "}", "else", "{", "z", ".", "msg", "=", "\"\"", ";", "c", "=", "z", ".", "avail_in", "-", "n", ";", "c", "=", "(", "k", ">>", "3", ")", "<", "c", "?", "k", ">>", "3", ":", "c", ";", "n", "+=", "c", ";", "p", "-=", "c", ";", "k", "-=", "c", "<<", "3", ";", "s", ".", "bitb", "=", "b", ";", "s", ".", "bitk", "=", "k", ";", "z", ".", "avail_in", "=", "n", ";", "z", ".", "total_in", "+=", "p", "-", "z", ".", "next_in_index", ";", "z", ".", "next_in_index", "=", "p", ";", "s", ".", "write", "=", "q", ";", "return", "Z_DATA_ERROR", ";", "}", "}", "while", "(", "true", ")", ";", "}", "while", "(", "m", ">=", "258", "&&", "n", ">=", "10", ")", ";", "c", "=", "z", ".", "avail_in", "-", "n", ";", "c", "=", "(", "k", ">>", "3", ")", "<", "c", "?", "k", ">>", "3", ":", "c", ";", "n", "+=", "c", ";", "p", "-=", "c", ";", "k", "-=", "c", "<<", "3", ";", "s", ".", "bitb", "=", "b", ";", "s", ".", "bitk", "=", "k", ";", "z", ".", "avail_in", "=", "n", ";", "z", ".", "total_in", "+=", "p", "-", "z", ".", "next_in_index", ";", "z", ".", "next_in_index", "=", "p", ";", "s", ".", "write", "=", "q", ";", "return", "Z_OK", ";", "}", "}", "</s>" ]
7,725
[ "<s>", "package", "com", ".", "jcraft", ".", "jzlib", ";", "final", "public", "class", "JZlib", "{", "private", "static", "final", "String", "version", "=", "\"1.0.2\"", ";", "public", "static", "String", "version", "(", ")", "{", "return", "version", ";", "}", "static", "final", "public", "int", "Z_NO_COMPRESSION", "=", "0", ";", "static", "final", "public", "int", "Z_BEST_SPEED", "=", "1", ";", "static", "final", "public", "int", "Z_BEST_COMPRESSION", "=", "9", ";", "static", "final", "public", "int", "Z_DEFAULT_COMPRESSION", "=", "(", "-", "1", ")", ";", "static", "final", "public", "int", "Z_FILTERED", "=", "1", ";", "static", "final", "public", "int", "Z_HUFFMAN_ONLY", "=", "2", ";", "static", "final", "public", "int", "Z_DEFAULT_STRATEGY", "=", "0", ";", "static", "final", "public", "int", "Z_NO_FLUSH", "=", "0", ";", "static", "final", "public", "int", "Z_PARTIAL_FLUSH", "=", "1", ";", "static", "final", "public", "int", "Z_SYNC_FLUSH", "=", "2", ";", "static", "final", "public", "int", "Z_FULL_FLUSH", "=", "3", ";", "static", "final", "public", "int", "Z_FINISH", "=", "4", ";", "static", "final", "public", "int", "Z_OK", "=", "0", ";", "static", "final", "public", "int", "Z_STREAM_END", "=", "1", ";", "static", "final", "public", "int", "Z_NEED_DICT", "=", "2", ";", "static", "final", "public", "int", "Z_ERRNO", "=", "-", "1", ";", "static", "final", "public", "int", "Z_STREAM_ERROR", "=", "-", "2", ";", "static", "final", "public", "int", "Z_DATA_ERROR", "=", "-", "3", ";", "static", "final", "public", "int", "Z_MEM_ERROR", "=", "-", "4", ";", "static", "final", "public", "int", "Z_BUF_ERROR", "=", "-", "5", ";", "static", "final", "public", "int", "Z_VERSION_ERROR", "=", "-", "6", ";", "}", "</s>" ]
7,726
[ "<s>", "package", "erjang", ";", "import", "java", ".", "io", ".", "IOException", ";", "import", "java", ".", "nio", ".", "ByteBuffer", ";", "import", "java", ".", "util", ".", "Map", ";", "import", "java", ".", "util", ".", "LinkedList", ";", "import", "java", ".", "util", ".", "concurrent", ".", "ConcurrentHashMap", ";", "import", "java", ".", "util", ".", "concurrent", ".", "atomic", ".", "AtomicInteger", ";", "import", "java", ".", "util", ".", "logging", ".", "Level", ";", "import", "java", ".", "util", ".", "logging", ".", "Logger", ";", "import", "erjang", ".", "driver", ".", "EDriverTask", ";", "import", "kilim", ".", "Pausable", ";", "public", "class", "EPeer", "extends", "EAbstractNode", "{", "static", "Logger", "log", "=", "Logger", ".", "getLogger", "(", "\"erjang.dist\"", ")", ";", "protected", "static", "final", "byte", "passThrough", "=", "(", "byte", ")", "0x70", ";", "protected", "static", "final", "byte", "distHeader", "=", "(", "byte", ")", "131", ";", "protected", "static", "final", "byte", "version", "=", "(", "byte", ")", "0x83", ";", "protected", "static", "final", "int", "LINK", "=", "1", ";", "protected", "static", "final", "int", "SEND", "=", "2", ";", "protected", "static", "final", "int", "EXIT", "=", "3", ";", "protected", "static", "final", "int", "UNLINK", "=", "4", ";", "protected", "static", "final", "int", "NODE_LINK", "=", "5", ";", "protected", "static", "final", "int", "REG_SEND", "=", "6", ";", "protected", "static", "final", "int", "GROUP_LEADER", "=", "7", ";", "protected", "static", "final", "int", "EXIT2", "=", "8", ";", "protected", "static", "final", "int", "SEND_TT", "=", "12", ";", "protected", "static", "final", "int", "EXIT_TT", "=", "13", ";", "protected", "static", "final", "int", "REG_SEND_TT", "=", "16", ";", "protected", "static", "final", "int", "EXIT2_TT", "=", "18", ";", "protected", "static", "final", "int", "MONITOR_P", "=", "19", ";", "protected", "static", "final", "int", "DEMONITOR_P", "=", "20", ";", "protected", "static", "final", "int", "MONITOR_P_EXIT", "=", "21", ";", "private", "static", "final", "EAtom", "am_", "=", "EAtom", ".", "intern", "(", "\"\"", ")", ";", "static", "ConcurrentHashMap", "<", "EAtom", ",", "EPeer", ">", "peers", "=", "new", "ConcurrentHashMap", "<", "EAtom", ",", "EPeer", ">", "(", ")", ";", "private", "EInternalPort", "port", ";", "private", "LinkedList", "<", "ByteBuffer", "[", "]", ">", "port_queue", ";", "public", "EPeer", "(", "EAtom", "node", ",", "int", "creation", ",", "EInternalPort", "port", ",", "int", "flags", ",", "int", "version", ")", "{", "super", "(", "node", ")", ";", "this", ".", "flags", "=", "flags", ";", "this", ".", "creation", "=", "creation", ";", "this", ".", "port", "=", "port", ";", "this", ".", "ntype", "=", "version", "==", "5", "?", "NTYPE_R6", ":", "0", ";", "this", ".", "port_queue", "=", "(", "this", ".", "port", "==", "null", ")", "?", "new", "LinkedList", "<", "ByteBuffer", "[", "]", ">", "(", ")", ":", "null", ";", "}", "private", "void", "setPort", "(", "EInternalPort", "port", ")", "throws", "Pausable", "{", "assert", "(", "port", "!=", "null", ")", ";", "assert", "(", "this", ".", "port", "==", "null", ")", ";", "assert", "(", "this", ".", "port_queue", "!=", "null", ")", ";", "EDriverTask", "task", "=", "port", ".", "task", "(", ")", ";", "assert", "(", "task", "!=", "null", ")", ";", "try", "{", "while", "(", "true", ")", "{", "ByteBuffer", "[", "]", "msg", ";", "synchronized", "(", "this", ")", "{", "if", "(", "port_queue", ".", "isEmpty", "(", ")", ")", "{", "this", ".", "port", "=", "port", ";", "this", ".", "port_queue", "=", "null", ";", "break", ";", "}", "msg", "=", "port_queue", ".", "removeFirst", "(", ")", ";", "assert", "(", "msg", "!=", "null", ")", ";", "}", "task", ".", "outputv", "(", "null", ",", "msg", ")", ";", "}", "}", "catch", "(", "IOException", "e", ")", "{", "e", ".", "printStackTrace", "(", ")", ";", "close_and_finish", "(", "port", ")", ";", "}", "}", "private", "void", "send_to_port", "(", "ByteBuffer", "[", "]", "ev", ",", "EHandle", "sender", ")", "throws", "Pausable", "{", "EInternalPort", "port", ";", "synchronized", "(", "this", ")", "{", "port", "=", "this", ".", "port", ";", "if", "(", "port", "==", "null", ")", "{", "assert", "(", "port_queue", "!=", "null", ")", ";", "port_queue", ".", "addLast", "(", "ev", ")", ";", "return", ";", "}", "}", "assert", "(", "port", "!=", "null", ")", ";", "EDriverTask", "task", "=", "port", ".", "task", "(", ")", ";", "if", "(", "task", "!=", "null", ")", "{", "try", "{", "task", ".", "outputv", "(", "null", ",", "ev", ")", ";", "}", "catch", "(", "IOException", "e", ")", "{", "e", ".", "printStackTrace", "(", ")", ";", "close_and_finish", "(", "port", ")", ";", "}", "}", "else", "{", "log", ".", "warning", "(", "\"\"", "+", "port", "+", "\",", "this=\"", "+", "this", "+", "\",", "sender=\"", "+", "sender", "+", "\")\"", ")", ";", "}", "}", "public", "static", "EPeer", "get_or_create", "(", "EAtom", "node", ",", "int", "creation", ",", "int", "flags", ",", "int", "version", ")", "{", "EPeer", "peer", "=", "peers", ".", "get", "(", "node", ")", ";", "if", "(", "peer", "!=", "null", ")", "{", "return", "peer", ";", "}", "peer", "=", "new", "EPeer", "(", "node", ",", "creation", ",", "null", ",", "flags", ",", "version", ")", ";", "peers", ".", "put", "(", "node", ",", "peer", ")", ";", "return", "peer", ";", "}", "public", "static", "EPeer", "get_or_create", "(", "EAtom", "node", ",", "int", "creation", ",", "EInternalPort", "port", ",", "int", "flags", ",", "int", "version", ")", "throws", "Pausable", "{", "EPeer", "peer", "=", "peers", ".", "get", "(", "node", ")", ";", "if", "(", "peer", "!=", "null", ")", "{", "boolean", "do_set_port", ";", "synchronized", "(", "peer", ")", "{", "do_set_port", "=", "(", "peer", ".", "port", "==", "null", "&&", "port", "!=", "null", ")", ";", "}", "if", "(", "do_set_port", ")", "{", "peer", ".", "setPort", "(", "port", ")", ";", "}", "else", "if", "(", "port", "!=", "null", ")", "{", "log", ".", "warning", "(", "\"\"", "+", "peer", ".", "port", "+", "\"\"", "+", "port", "+", "\")\"", ")", ";", "}", "return", "peer", ";", "}", "peer", "=", "new", "EPeer", "(", "node", ",", "creation", ",", "port", ",", "flags", ",", "version", ")", ";", "peers", ".", "put", "(", "node", ",", "peer", ")", ";", "return", "peer", ";", "}", "public", "void", "net_message", "(", "EInternalPort", "port", ",", "ByteBuffer", "hdr", ",", "ByteBuffer", "buf", ")", "throws", "Pausable", "{", "try", "{", "net_message2", "(", "port", ",", "hdr", ",", "buf", ")", ";", "}", "catch", "(", "IOException", "e", ")", "{", "close_and_finish", "(", "port", ")", ";", "}", "}", "EAtom", "[", "]", "[", "]", "atom_cache", ";", "{", "atom_cache", "=", "new", "EAtom", "[", "8", "]", "[", "]", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "8", ";", "i", "++", ")", "{", "atom_cache", "[", "i", "]", "=", "new", "EAtom", "[", "256", "]", ";", "}", "}", "public", "void", "net_message2", "(", "EInternalPort", "port", ",", "ByteBuffer", "hdr", ",", "ByteBuffer", "buf", ")", "throws", "IOException", ",", "Pausable", "{", "if", "(", "buf", ".", "remaining", "(", ")", "==", "0", ")", "{", "log", ".", "fine", "(", "\"\"", "+", "this", ".", "node", ")", ";", "return", ";", "}", "if", "(", "hdr", "!=", "null", "&&", "hdr", ".", "remaining", "(", ")", "!=", "0", ")", "{", "close_and_finish", "(", "port", ")", ";", "return", ";", "}", "EInputStream", "ibuf", "=", "new", "EInputStream", "(", "buf", ".", "array", "(", ")", ",", "buf", ".", "arrayOffset", "(", ")", "+", "buf", ".", "position", "(", ")", ",", "buf", ".", "remaining", "(", ")", ",", "flags", ")", ";", "int", "start", "=", "ibuf", ".", "getPos", "(", ")", ";", "receive_loop", ":", "do", "{", "int", "first", "=", "ibuf", ".", "read1", "(", ")", ";", "EAtom", "[", "]", "atom_cache_refs", ";", "switch", "(", "first", ")", "{", "case", "131", ":", "if", "(", "!", "process_distribution_header", "(", "port", ",", "ibuf", ")", ")", "return", ";", "case", "passThrough", ":", "break", ";", "default", ":", "close_and_finish", "(", "port", ")", ";", "return", ";", "}", "EObject", "reason", "=", "null", ";", "EAtom", "cookie", "=", "null", ";", "EObject", "tmp", "=", "null", ";", "ETuple", "head", "=", "null", ";", "EAtom", "toName", ";", "EPID", "to", ";", "EPID", "from", ";", "int", "tag", ";", "tmp", "=", "ibuf", ".", "read_any", "(", ")", ";", "if", "(", "(", "head", "=", "tmp", ".", "testTuple", "(", ")", ")", "==", "null", ")", "{", "break", "receive_loop", ";", "}", "if", "(", "log", ".", "isLoggable", "(", "Level", ".", "FINE", ")", ")", "{", "log", ".", "fine", "(", "\"\"", "+", "tmp", ")", ";", "}", "ESmall", "tag_sm", ";", "if", "(", "(", "tag_sm", "=", "head", ".", "elm", "(", "1", ")", ".", "testSmall", "(", ")", ")", "==", "null", ")", "{", "break", "receive_loop", ";", "}", "tag", "=", "tag_sm", ".", "value", ";", "switch", "(", "tag", ")", "{", "case", "LINK", ":", "{", "EPID", "from_pid", "=", "head", ".", "elm", "(", "2", ")", ".", "testPID", "(", ")", ";", "EInternalPID", "to_pid", "=", "head", ".", "elm", "(", "3", ")", ".", "testInternalPID", "(", ")", ";", "if", "(", "!", "to_pid", ".", "link_oneway", "(", "from_pid", ")", ")", "{", "dsig_exit", "(", "to_pid", ",", "from_pid", ",", "ERT", ".", "am_noproc", ")", ";", "}", "return", ";", "}", "case", "UNLINK", ":", "{", "EPID", "from_pid", "=", "head", ".", "elm", "(", "2", ")", ".", "testPID", "(", ")", ";", "EInternalPID", "to_pid", "=", "head", ".", "elm", "(", "3", ")", ".", "testInternalPID", "(", ")", ";", "if", "(", "to_pid", "!=", "null", "&&", "from_pid", "!=", "null", ")", "{", "to_pid", ".", "unlink_oneway", "(", "from_pid", ")", ";", "}", "return", ";", "}", "case", "SEND", ":", "{", "EObject", "msg", "=", "ibuf", ".", "read_any", "(", ")", ";", "if", "(", "log", ".", "isLoggable", "(", "Level", ".", "FINE", ")", ")", "log", ".", "fine", "(", "\"\"", "+", "msg", ")", ";", "EHandle", "dst", "=", "head", ".", "elm", "(", "3", ")", ".", "testHandle", "(", ")", ";", "if", "(", "dst", "==", "null", ")", "throw", "new", "IOException", "(", "\"\"", ")", ";", "if", "(", "dst", "!=", "null", ")", "{", "dst", ".", "send", "(", "null", ",", "msg", ")", ";", "}", "return", ";", "}", "case", "REG_SEND", ":", "case", "REG_SEND_TT", ":", "{", "EObject", "msg", "=", "ibuf", ".", "read_any", "(", ")", ";", "if", "(", "log", ".", "isLoggable", "(", "Level", ".", "FINE", ")", ")", "log", ".", "fine", "(", "\"\"", "+", "msg", ")", ";", "EAtom", "toname", "=", "head", ".", "elm", "(", "4", ")", ".", "testAtom", "(", ")", ";", "if", "(", "toname", "==", "null", ")", "throw", "new", "IOException", "(", "\"\"", ")", ";", "EHandle", "dst", "=", "ERT", ".", "whereis", "(", "toname", ")", ".", "testHandle", "(", ")", ";", "if", "(", "dst", "!=", "null", ")", "{", "dst", ".", "sendb", "(", "msg", ")", ";", "}", "return", ";", "}", "case", "EXIT", ":", "case", "EXIT2", ":", "{", "EPID", "from_pid", "=", "head", ".", "elm", "(", "2", ")", ".", "testPID", "(", ")", ";", "EPID", "to_proc", "=", "head", ".", "elm", "(", "3", ")", ".", "testPID", "(", ")", ";", "reason", "=", "head", ".", "elm", "(", "4", ")", ";", "to_proc", ".", "exit_signal", "(", "from_pid", ",", "reason", ",", "false", ")", ";", "return", ";", "}", "case", "MONITOR_P", ":", "{", "EPID", "from_pid", "=", "head", ".", "elm", "(", "2", ")", ".", "testPID", "(", ")", ";", "EPID", "to_proc", "=", "head", ".", "elm", "(", "3", ")", ".", "testPID", "(", ")", ";", "ERef", "ref", "=", "head", ".", "elm", "(", "4", ")", ".", "testReference", "(", ")", ";", "if", "(", "to_proc", "==", "null", ")", "{", "EAtom", "am", "=", "head", ".", "elm", "(", "3", ")", ".", "testAtom", "(", ")", ";", "if", "(", "am", "==", "null", ")", "{", "throw", "new", "IOException", "(", "\"\"", "+", "head", ")", ";", "}", "to_proc", "=", "ERT", ".", "whereis", "(", "am", ")", ".", "testPID", "(", ")", ";", "}", "if", "(", "to_proc", "==", "null", ")", "{", "throw", "new", "IOException", "(", "\"\"", "+", "head", ")", ";", "}", "if", "(", "!", "to_proc", ".", "add_monitor", "(", "from_pid", ",", "ref", ")", ")", "{", "dsig_send_monitor_exit", "(", "to_proc", ",", "from_pid", ",", "ref", ",", "ERT", ".", "am_noproc", ")", ";", "}", "return", ";", "}", "case", "DEMONITOR_P", ":", "{", "EPID", "from_pid", "=", "head", ".", "elm", "(", "2", ")", ".", "testPID", "(", ")", ";", "EPID", "to_proc", "=", "head", ".", "elm", "(", "3", ")", ".", "testPID", "(", ")", ";", "ERef", "ref", "=", "head", ".", "elm", "(", "4", ")", ".", "testReference", "(", ")", ";", "if", "(", "to_proc", "==", "null", ")", "{", "EAtom", "am", "=", "head", ".", "elm", "(", "3", ")", ".", "testAtom", "(", ")", ";", "if", "(", "am", "==", "null", ")", "{", "throw", "new", "IOException", "(", "\"\"", "+", "head", ")", ";", "}", "to_proc", "=", "ERT", ".", "whereis", "(", "am", ")", ".", "testPID", "(", ")", ";", "}", "if", "(", "to_proc", "==", "null", ")", "{", "throw", "new", "IOException", "(", "\"\"", "+", "head", ")", ";", "}", "to_proc", ".", "remove_monitor", "(", "from_pid", ",", "ref", ",", "false", ")", ";", "return", ";", "}", "case", "MONITOR_P_EXIT", ":", "{", "EPID", "from_pid", "=", "head", ".", "elm", "(", "2", ")", ".", "testPID", "(", ")", ";", "EPID", "to_proc", "=", "head", ".", "elm", "(", "3", ")", ".", "testPID", "(", ")", ";", "ERef", "ref", "=", "head", ".", "elm", "(", "4", ")", ".", "testReference", "(", ")", ";", "reason", "=", "head", ".", "elm", "(", "5", ")", ";", "if", "(", "to_proc", "==", "null", ")", "{", "EAtom", "am", "=", "head", ".", "elm", "(", "3", ")", ".", "testAtom", "(", ")", ";", "if", "(", "am", "==", "null", ")", "{", "throw", "new", "IOException", "(", "\"\"", "+", "head", ")", ";", "}", "to_proc", "=", "ERT", ".", "whereis", "(", "am", ")", ".", "testPID", "(", ")", ";", "}", "if", "(", "to_proc", "==", "null", ")", "{", "throw", "new", "IOException", "(", "\"\"", "+", "head", ")", ";", "}", "to_proc", ".", "send_monitor_exit", "(", "from_pid", ",", "ref", ",", "reason", ")", ";", "return", ";", "}", "default", ":", "throw", "new", "NotImplemented", "(", "\"dmesg:", "\"", "+", "head", ")", ";", "}", "}", "while", "(", "false", ")", ";", "}", "private", "boolean", "process_distribution_header", "(", "EInternalPort", "port", ",", "EInputStream", "ibuf", ")", "throws", "IOException", "{", "EAtom", "[", "]", "atom_cache_refs", ";", "log", ".", "fine", "(", "\"\"", ")", ";", "int", "datum", "=", "ibuf", ".", "read1", "(", ")", ";", "if", "(", "datum", "!=", "68", ")", "{", "close_and_finish", "(", "port", ")", ";", "return", "false", ";", "}", "int", "numberOfAtomCacheRefs", "=", "ibuf", ".", "read1", "(", ")", "&", "0xff", ";", "atom_cache_refs", "=", "new", "EAtom", "[", "numberOfAtomCacheRefs", "]", ";", "if", "(", "numberOfAtomCacheRefs", "==", "0", ")", "{", "}", "else", "{", "int", "nflag_bytes", "=", "numberOfAtomCacheRefs", "/", "2", "+", "1", ";", "byte", "[", "]", "flags", "=", "new", "byte", "[", "nflag_bytes", "*", "2", "]", ";", "int", "pos", "=", "0", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "nflag_bytes", ";", "i", "++", ")", "{", "int", "twoflags", "=", "ibuf", ".", "read1", "(", ")", "&", "0xff", ";", "flags", "[", "pos", "++", "]", "=", "(", "byte", ")", "(", "twoflags", "&", "0xf", ")", ";", "flags", "[", "pos", "++", "]", "=", "(", "byte", ")", "(", "twoflags", ">>>", "4", ")", ";", "}", "boolean", "longAtoms", "=", "(", "flags", "[", "numberOfAtomCacheRefs", "]", "&", "0x01", ")", "==", "1", ";", "if", "(", "longAtoms", ")", "{", "log", ".", "fine", "(", "\"LONGATOMS!\"", ")", ";", "}", "for", "(", "int", "i", "=", "0", ";", "i", "<", "numberOfAtomCacheRefs", ";", "i", "++", ")", "{", "int", "segment_index", "=", "flags", "[", "i", "]", "&", "7", ";", "int", "index", "=", "ibuf", ".", "read1", "(", ")", ";", "if", "(", "log", ".", "isLoggable", "(", "Level", ".", "FINE", ")", ")", "log", ".", "fine", "(", "\"cache[\"", "+", "i", "+", "\"]", "->", "ref[\"", "+", "segment_index", "+", "\"][\"", "+", "index", "+", "\"]\"", ")", ";", "if", "(", "(", "flags", "[", "i", "]", "&", "8", ")", "==", "8", ")", "{", "int", "len", "=", "ibuf", ".", "read1", "(", ")", "&", "0xff", ";", "if", "(", "longAtoms", ")", "{", "len", "<<=", "8", ";", "len", "|=", "(", "ibuf", ".", "read1", "(", ")", "&", "0xff", ")", ";", "}", "byte", "[", "]", "atom_text", "=", "new", "byte", "[", "len", "]", ";", "ibuf", ".", "read", "(", "atom_text", ")", ";", "atom_cache", "[", "segment_index", "]", "[", "index", "]", "=", "EAtom", ".", "intern", "(", "atom_text", ")", ";", "}", "else", "{", "}", "atom_cache_refs", "[", "i", "]", "=", "atom_cache", "[", "segment_index", "]", "[", "index", "]", ";", "if", "(", "log", ".", "isLoggable", "(", "Level", ".", "FINE", ")", ")", "log", ".", "fine", "(", "\"", "=>", "\"", "+", "atom_cache_refs", "[", "i", "]", ")", ";", "}", "ibuf", ".", "setAtomCacheRefs", "(", "atom_cache_refs", ")", ";", "}", "return", "true", ";", "}", "private", "void", "close_and_finish", "(", "EInternalPort", "port", ")", "{", "port", ".", "task", "(", ")", ".", "exit", "(", "ERT", ".", "am_killed", ")", ";", "}", "public", "static", "EAbstractNode", "get", "(", "EAtom", "node", ")", "{", "if", "(", "node", "==", "ERT", ".", "getLocalNode", "(", ")", ".", "node", "(", ")", ")", "return", "ERT", ".", "getLocalNode", "(", ")", ";", "return", "peers", ".", "get", "(", "node", ")", ";", "}", "void", "dsig_cast", "(", "EHandle", "sender", ",", "ETuple", "hdr", ")", "throws", "Pausable", "{", "ByteBuffer", "disthdr", "=", "ByteBuffer", ".", "allocate", "(", "3", ")", ";", "disthdr", ".", "put", "(", "(", "byte", ")", "131", ")", ";", "disthdr", ".", "put", "(", "(", "byte", ")", "68", ")", ";", "disthdr", ".", "put", "(", "(", "byte", ")", "0", ")", ";", "disthdr", ".", "flip", "(", ")", ";", "EOutputStream", "eos", "=", "new", "EOutputStream", "(", "1024", ",", "flags", ")", ";", "hdr", ".", "encode", "(", "eos", ")", ";", "ByteBuffer", "barr", "=", "eos", ".", "toByteBuffer", "(", ")", ";", "ByteBuffer", "[", "]", "ev", "=", "new", "ByteBuffer", "[", "]", "{", "disthdr", ",", "barr", "}", ";", "send_to_port", "(", "ev", ",", "sender", ")", ";", "}", "int", "dsig_cast", "(", "EHandle", "sender", ",", "ETuple", "hdr", ",", "EObject", "payload", ")", "throws", "Pausable", "{", "ByteBuffer", "disthdr", "=", "ByteBuffer", ".", "allocate", "(", "3", ")", ";", "disthdr", ".", "put", "(", "(", "byte", ")", "131", ")", ";", "disthdr", ".", "put", "(", "(", "byte", ")", "68", ")", ";", "disthdr", ".", "put", "(", "(", "byte", ")", "0", ")", ";", "disthdr", ".", "flip", "(", ")", ";", "EOutputStream", "eos", "=", "new", "EOutputStream", "(", "1024", ",", "flags", ")", ";", "hdr", ".", "encode", "(", "eos", ")", ";", "payload", ".", "encode", "(", "eos", ")", ";", "ByteBuffer", "barr", "=", "eos", ".", "toByteBuffer", "(", ")", ";", "ByteBuffer", "[", "]", "ev", "=", "new", "ByteBuffer", "[", "]", "{", "disthdr", ",", "barr", "}", ";", "send_to_port", "(", "ev", ",", "sender", ")", ";", "return", "eos", ".", "size", "(", ")", ";", "}", "public", "int", "dsig_send", "(", "EHandle", "sender", ",", "EExternalPID", "pid", ",", "EObject", "msg", ")", "throws", "Pausable", "{", "ETuple", "hdr", "=", "ETuple", ".", "make", "(", "ERT", ".", "box", "(", "SEND", ")", ",", "(", "EAtom", ")", "am_", ",", "pid", ")", ";", "return", "dsig_cast", "(", "sender", ",", "hdr", ",", "msg", ")", ";", "}", "public", "void", "dsig_send_monitor_exit", "(", "EHandle", "sender", ",", "EPID", "to_pid", ",", "ERef", "ref", ",", "EObject", "reason", ")", "throws", "Pausable", "{", "ETuple", "hdr", "=", "ETuple", ".", "make", "(", "ERT", ".", "box", "(", "MONITOR_P_EXIT", ")", ",", "sender", ",", "to_pid", ",", "ref", ",", "reason", ")", ";", "dsig_cast", "(", "sender", ",", "hdr", ")", ";", "}", "public", "void", "dsig_monitor", "(", "EHandle", "sender", ",", "EObject", "to_pid", ",", "ERef", "ref", ")", "throws", "Pausable", "{", "ETuple", "hdr", "=", "ETuple", ".", "make", "(", "ERT", ".", "box", "(", "MONITOR_P", ")", ",", "sender", ",", "to_pid", ",", "ref", ")", ";", "dsig_cast", "(", "sender", ",", "hdr", ")", ";", "}", "public", "void", "dsig_exit", "(", "EHandle", "sender", ",", "EPID", "to_pid", ",", "EObject", "reason", ")", "throws", "Pausable", "{", "ETuple", "hdr", "=", "ETuple", ".", "make", "(", "ERT", ".", "box", "(", "EXIT", ")", ",", "sender", ",", "to_pid", ",", "reason", ")", ";", "dsig_cast", "(", "sender", ",", "hdr", ")", ";", "}", "public", "void", "dsig_link", "(", "EHandle", "sender", ",", "EExternalPID", "to_pid", ")", "throws", "Pausable", "{", "ETuple", "hdr", "=", "ETuple", ".", "make", "(", "ERT", ".", "box", "(", "LINK", ")", ",", "sender", ",", "to_pid", ")", ";", "dsig_cast", "(", "sender", ",", "hdr", ")", ";", "}", "public", "void", "dsig_unlink", "(", "EHandle", "sender", ",", "EExternalPID", "to_pid", ")", "throws", "Pausable", "{", "ETuple", "hdr", "=", "ETuple", ".", "make", "(", "ERT", ".", "box", "(", "UNLINK", ")", ",", "sender", ",", "to_pid", ")", ";", "dsig_cast", "(", "sender", ",", "hdr", ")", ";", "}", "public", "void", "dsig_demonitor", "(", "EHandle", "sender", ",", "ERef", "ref", ",", "EObject", "to_pid_or_name", ")", "throws", "Pausable", "{", "ETuple", "hdr", "=", "ETuple", ".", "make", "(", "ERT", ".", "box", "(", "DEMONITOR_P", ")", ",", "sender", ",", "to_pid_or_name", ",", "ref", ")", ";", "dsig_cast", "(", "sender", ",", "hdr", ")", ";", "}", "public", "EObject", "dsig_reg_send", "(", "EInternalPID", "sender", ",", "EAtom", "to_name", ",", "EObject", "msg", ")", "throws", "Pausable", "{", "ETuple", "hdr", "=", "ETuple", ".", "make", "(", "ERT", ".", "box", "(", "REG_SEND", ")", ",", "sender", ",", "am_", ",", "to_name", ")", ";", "dsig_cast", "(", "sender", ",", "hdr", ",", "msg", ")", ";", "return", "msg", ";", "}", "public", "static", "ESeq", "getRemoteNodes", "(", ")", "{", "EAtom", "[", "]", "nodes", "=", "peers", ".", "keySet", "(", ")", ".", "toArray", "(", "new", "EAtom", "[", "0", "]", ")", ";", "ESeq", "reply", "=", "ERT", ".", "NIL", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "nodes", ".", "length", ";", "i", "++", ")", "{", "reply", "=", "reply", ".", "cons", "(", "nodes", "[", "i", "]", ")", ";", "}", "return", "reply", ";", "}", "}", "</s>" ]
7,727
[ "<s>", "package", "erjang", ";", "public", "class", "ENode", "extends", "ELocalNode", "{", "public", "boolean", "connect", "(", "EAtom", "node", ")", "{", "return", "false", ";", "}", "public", "boolean", "isALive", "(", ")", "{", "return", "node", "(", ")", "!=", "am_nonode_at_nohost", ";", "}", "}", "</s>" ]
7,728
[ "<s>", "package", "erjang", ".", "driver", ";", "import", "static", "erjang", ".", "EPort", ".", "am_arg0", ";", "import", "static", "erjang", ".", "EPort", ".", "am_args", ";", "import", "static", "erjang", ".", "EPort", ".", "am_binary", ";", "import", "static", "erjang", ".", "EPort", ".", "am_cd", ";", "import", "static", "erjang", ".", "EPort", ".", "am_close", ";", "import", "static", "erjang", ".", "EPort", ".", "am_env", ";", "import", "static", "erjang", ".", "EPort", ".", "am_eof", ";", "import", "static", "erjang", ".", "EPort", ".", "am_exit_status", ";", "import", "static", "erjang", ".", "EPort", ".", "am_hide", ";", "import", "static", "erjang", ".", "EPort", ".", "am_in", ";", "import", "static", "erjang", ".", "EPort", ".", "am_line", ";", "import", "static", "erjang", ".", "EPort", ".", "am_nouse_stdio", ";", "import", "static", "erjang", ".", "EPort", ".", "am_out", ";", "import", "static", "erjang", ".", "EPort", ".", "am_packet", ";", "import", "static", "erjang", ".", "EPort", ".", "am_stream", ";", "import", "static", "erjang", ".", "EPort", ".", "am_use_stdio", ";", "import", "java", ".", "io", ".", "IOException", ";", "import", "java", ".", "nio", ".", "ByteBuffer", ";", "import", "java", ".", "nio", ".", "channels", ".", "SelectableChannel", ";", "import", "java", ".", "util", ".", "ArrayList", ";", "import", "java", ".", "util", ".", "HashMap", ";", "import", "java", ".", "util", ".", "List", ";", "import", "java", ".", "util", ".", "concurrent", ".", "ConcurrentHashMap", ";", "import", "java", ".", "util", ".", "logging", ".", "Level", ";", "import", "java", ".", "util", ".", "logging", ".", "Logger", ";", "import", "kilim", ".", "Pausable", ";", "import", "kilim", ".", "Task", ";", "import", "erjang", ".", "EAtom", ";", "import", "erjang", ".", "EBinary", ";", "import", "erjang", ".", "ECons", ";", "import", "erjang", ".", "EHandle", ";", "import", "erjang", ".", "EInternalPID", ";", "import", "erjang", ".", "EInternalPort", ";", "import", "erjang", ".", "EObject", ";", "import", "erjang", ".", "EPID", ";", "import", "erjang", ".", "EPeer", ";", "import", "erjang", ".", "EPort", ";", "import", "erjang", ".", "EProc", ";", "import", "erjang", ".", "ERT", ";", "import", "erjang", ".", "ERef", ";", "import", "erjang", ".", "ESeq", ";", "import", "erjang", ".", "EString", ";", "import", "erjang", ".", "ETask", ";", "import", "erjang", ".", "ETuple", ";", "import", "erjang", ".", "ETuple2", ";", "import", "erjang", ".", "ETuple3", ";", "import", "erjang", ".", "ETuple4", ";", "import", "erjang", ".", "ErlangError", ";", "import", "erjang", ".", "ErlangException", ";", "import", "erjang", ".", "ErlangExit", ";", "import", "erjang", ".", "ErlangExitSignal", ";", "import", "erjang", ".", "NotImplemented", ";", "public", "abstract", "class", "EDriverTask", "extends", "ETask", "<", "EInternalPort", ">", "implements", "NIOHandler", "{", "static", "Logger", "log", "=", "Logger", ".", "getLogger", "(", "\"\"", ")", ";", "public", "abstract", "EObject", "getName", "(", ")", ";", "@", "Override", "public", "String", "toString", "(", ")", "{", "return", "\"\"", "+", "super", ".", "id", "+", "\">\"", ";", "}", "private", "static", "final", "EAtom", "am_name", "=", "EAtom", ".", "intern", "(", "\"name\"", ")", ";", "private", "static", "final", "EAtom", "am_data", "=", "EAtom", ".", "intern", "(", "\"data\"", ")", ";", "private", "static", "final", "EAtom", "am_connected", "=", "EAtom", ".", "intern", "(", "\"connected\"", ")", ";", "private", "static", "final", "EAtom", "am_closed", "=", "EAtom", ".", "intern", "(", "\"closed\"", ")", ";", "private", "final", "EInternalPort", "port", ";", "protected", "EPID", "owner", ";", "private", "final", "EDriverControl", "instance", ";", "public", "EPID", "owner", "(", ")", "{", "return", "owner", ";", "}", "public", "void", "owner", "(", "EInternalPID", "ipid", ")", "{", "this", ".", "owner", "=", "ipid", ";", "}", "private", "static", "ConcurrentHashMap", "<", "Integer", ",", "EDriverTask", ">", "all_ports", "=", "new", "ConcurrentHashMap", "<", "Integer", ",", "EDriverTask", ">", "(", ")", ";", "public", "EDriverTask", "(", "EPID", "owner", ",", "EDriverControl", "driver", ")", "{", "EDriver", "drv", "=", "driver", ".", "getDriver", "(", ")", ";", "if", "(", "drv", ".", "useDriverLevelLocking", "(", ")", "==", "true", ")", "{", "log", ".", "fine", "(", "\"\"", "+", "driver", ")", ";", "driver", "=", "new", "LockingDriverInstance", "(", "driver", ",", "drv", ".", "getLock", "(", ")", ")", ";", "}", "else", "{", "driver", "=", "new", "LockingDriverInstance", "(", "driver", ",", "new", "kilim", ".", "ReentrantLock", "(", ")", ")", ";", "}", "this", ".", "owner", "=", "owner", ";", "this", ".", "instance", "=", "driver", ";", "this", ".", "port", "=", "new", "EInternalPort", "(", "this", ")", ";", "driver", ".", "setTask", "(", "this", ")", ";", "all_ports", ".", "put", "(", "id", ",", "this", ")", ";", "}", "public", "void", "setupInstance", "(", ")", "{", "instance", ".", "setup", "(", ")", ";", "}", "@", "Override", "public", "EInternalPort", "self_handle", "(", ")", "{", "return", "port", ";", "}", "static", "enum", "Mode", "{", "STREAM", ",", "PACKET", ",", "LINE", "}", ";", "protected", "boolean", "send_binary_data", ";", "protected", "boolean", "is_out_only", ";", "protected", "boolean", "is_in_only", ";", "protected", "boolean", "send_eof", ";", "protected", "boolean", "hide", ";", "protected", "int", "port_out_fd", ";", "protected", "int", "port_in_fd", ";", "protected", "boolean", "send_exit_status", ";", "protected", "int", "packet", ";", "protected", "int", "line_length", ";", "protected", "Mode", "mode", "=", "Mode", ".", "STREAM", ";", "protected", "String", "[", "]", "cmd", ";", "protected", "String", "cwd", ";", "protected", "HashMap", "<", "String", ",", "String", ">", "env", ";", "private", "long", "abs_timeout", ";", "public", "EObject", "port_data", ";", "public", "static", "final", "int", "ERTS_PORT_SFLG_CONNECTED", "=", "1", "<<", "0", ";", "public", "static", "final", "int", "ERTS_PORT_SFLG_EXITING", "=", "1", "<<", "1", ";", "public", "static", "final", "int", "ERTS_PORT_SFLG_DISTRIBUTION", "=", "1", "<<", "2", ";", "public", "static", "final", "int", "ERTS_PORT_SFLG_BINARY_IO", "=", "1", "<<", "3", ";", "public", "static", "final", "int", "ERTS_PORT_SFLG_SOFT_EOF", "=", "1", "<<", "4", ";", "public", "static", "final", "int", "ERTS_PORT_SFLG_PORT_BUSY", "=", "1", "<<", "5", ";", "public", "static", "final", "int", "ERTS_PORT_SFLG_CLOSING", "=", "1", "<<", "6", ";", "public", "static", "final", "int", "ERTS_PORT_SFLG_SEND_CLOSED", "=", "1", "<<", "7", ";", "public", "static", "final", "int", "ERTS_PORT_SFLG_LINEBUF_IO", "=", "1", "<<", "8", ";", "public", "static", "final", "int", "ERTS_PORT_SFLG_IMMORTAL", "=", "1", "<<", "9", ";", "public", "static", "final", "int", "ERTS_PORT_SFLG_FREE", "=", "1", "<<", "10", ";", "public", "static", "final", "int", "ERTS_PORT_SFLG_FREE_SCHEDULED", "=", "1", "<<", "11", ";", "public", "static", "final", "int", "ERTS_PORT_SFLG_INITIALIZING", "=", "1", "<<", "12", ";", "public", "static", "final", "int", "ERTS_PORT_SFLG_PORT_SPECIFIC_LOCK", "=", "1", "<<", "13", ";", "public", "static", "final", "int", "ERTS_PORT_SFLG_INVALID", "=", "1", "<<", "14", ";", "public", "static", "final", "int", "ERTS_PORT_SFLG_DEBUG", "=", "1", "<<", "31", ";", "public", "int", "status", ";", "private", "EPeer", "peer", ";", "boolean", "stderr_to_stdout", ";", "private", "EPID", "reply_closed_to", ";", "protected", "void", "parseOptions", "(", "String", "[", "]", "cmd", ",", "EObject", "portSetting", ")", "{", "this", ".", "cmd", "=", "cmd", ";", "this", ".", "cwd", "=", "System", ".", "getProperty", "(", "\"user.dir\"", ")", ";", "this", ".", "env", "=", "new", "HashMap", "<", "String", ",", "String", ">", "(", "System", ".", "getenv", "(", ")", ")", ";", "this", ".", "packet", "=", "-", "1", ";", "this", ".", "line_length", "=", "-", "1", ";", "this", ".", "send_exit_status", "=", "false", ";", "this", ".", "stderr_to_stdout", "=", "false", ";", "this", ".", "port_in_fd", "=", "1", ";", "this", ".", "port_out_fd", "=", "2", ";", "this", ".", "hide", "=", "false", ";", "this", ".", "send_eof", "=", "false", ";", "this", ".", "is_in_only", "=", "false", ";", "this", ".", "is_out_only", "=", "false", ";", "this", ".", "send_binary_data", "=", "false", ";", "ECons", "settings", "=", "portSetting", ".", "testCons", "(", ")", ";", "if", "(", "settings", "==", "null", ")", "throw", "ERT", ".", "badarg", "(", ")", ";", "for", "(", ";", "settings", "!=", "null", "&&", "!", "settings", ".", "isNil", "(", ")", ";", "settings", "=", "settings", ".", "tail", "(", ")", ".", "testCons", "(", ")", ")", "{", "EObject", "val", "=", "settings", ".", "head", "(", ")", ";", "ETuple", "tup", ";", "if", "(", "(", "tup", "=", "val", ".", "testTuple", "(", ")", ")", "!=", "null", ")", "{", "ETuple2", "tup2", ";", "if", "(", "(", "tup2", "=", "ETuple2", ".", "cast", "(", "tup", ")", ")", "!=", "null", ")", "{", "if", "(", "tup2", ".", "elem1", "==", "am_args", ")", "{", "ESeq", "list", "=", "tup2", ".", "elem2", ".", "testSeq", "(", ")", ";", "EObject", "[", "]", "nargs", "=", "list", ".", "toArray", "(", ")", ";", "String", "[", "]", "new_cmd", "=", "new", "String", "[", "nargs", ".", "length", "+", "1", "]", ";", "new_cmd", "[", "0", "]", "=", "cmd", "[", "0", "]", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "nargs", ".", "length", ";", "i", "++", ")", "{", "new_cmd", "[", "i", "+", "1", "]", "=", "EString", ".", "make", "(", "nargs", "[", "i", "]", ")", ".", "stringValue", "(", ")", ";", "}", "cmd", "=", "new_cmd", ";", "}", "else", "if", "(", "tup2", ".", "elem1", "==", "am_arg0", ")", "{", "String", "[", "]", "new_cmd", "=", "new", "String", "[", "2", "]", ";", "new_cmd", "[", "0", "]", "=", "cmd", "[", "0", "]", ";", "new_cmd", "[", "1", "]", "=", "EString", ".", "make", "(", "tup2", ".", "elem2", ")", ".", "stringValue", "(", ")", ";", "}", "else", "if", "(", "tup2", ".", "elem1", "==", "am_packet", ")", "{", "packet", "=", "tup2", ".", "elem2", ".", "asInt", "(", ")", ";", "mode", "=", "Mode", ".", "PACKET", ";", "}", "else", "if", "(", "tup2", ".", "elem1", "==", "am_cd", ")", "{", "cwd", "=", "EString", ".", "make", "(", "tup2", ".", "elem2", ")", ".", "stringValue", "(", ")", ";", "}", "else", "if", "(", "tup2", ".", "elem1", "==", "am_env", ")", "{", "ESeq", "ee", ";", "if", "(", "(", "ee", "=", "tup2", ".", "elem2", ".", "testSeq", "(", ")", ")", "==", "null", ")", "{", "throw", "ERT", ".", "badarg", "(", ")", ";", "}", "EObject", "[", "]", "envs", "=", "ee", ".", "toArray", "(", ")", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "envs", ".", "length", ";", "i", "++", ")", "{", "ETuple2", "e", "=", "ETuple2", ".", "cast", "(", "envs", "[", "i", "]", ".", "testTuple", "(", ")", ")", ";", "if", "(", "e", ".", "elem2", "==", "ERT", ".", "FALSE", ")", "{", "env", ".", "remove", "(", "EString", ".", "make", "(", "e", ".", "elem1", ")", ".", "stringValue", "(", ")", ")", ";", "}", "else", "{", "env", ".", "put", "(", "EString", ".", "make", "(", "e", ".", "elem1", ")", ".", "stringValue", "(", ")", ",", "EString", ".", "make", "(", "e", ".", "elem2", ")", ".", "stringValue", "(", ")", ")", ";", "}", "}", "}", "else", "if", "(", "tup2", ".", "elem1", "==", "am_line", ")", "{", "line_length", "=", "tup2", ".", "elem2", ".", "asInt", "(", ")", ";", "mode", "=", "Mode", ".", "LINE", ";", "}", "else", "{", "throw", "ERT", ".", "badarg", "(", ")", ";", "}", "}", "}", "else", "if", "(", "val", "==", "am_stream", ")", "{", "mode", "=", "Mode", ".", "STREAM", ";", "}", "else", "if", "(", "val", "==", "am_use_stdio", ")", "{", "port_in_fd", "=", "1", ";", "port_out_fd", "=", "2", ";", "}", "else", "if", "(", "val", "==", "am_nouse_stdio", ")", "{", "port_in_fd", "=", "3", ";", "port_out_fd", "=", "4", ";", "}", "else", "if", "(", "val", "==", "am_hide", ")", "{", "hide", "=", "true", ";", "}", "else", "if", "(", "val", "==", "am_exit_status", ")", "{", "send_exit_status", "=", "true", ";", "}", "else", "if", "(", "val", "==", "EPort", ".", "am_stderr_to_stdout", ")", "{", "stderr_to_stdout", "=", "true", ";", "}", "else", "if", "(", "val", "==", "am_eof", ")", "{", "send_eof", "=", "true", ";", "}", "else", "if", "(", "val", "==", "am_in", ")", "{", "is_in_only", "=", "true", ";", "}", "else", "if", "(", "val", "==", "am_out", ")", "{", "is_out_only", "=", "true", ";", "}", "else", "if", "(", "val", "==", "am_binary", ")", "{", "send_binary_data", "=", "true", ";", "}", "}", "}", "@", "Override", "public", "Task", "start", "(", ")", "{", "Task", "result", "=", "super", ".", "start", "(", ")", ";", "this", ".", "pstate", "=", "STATE_RUNNING", ";", "return", "result", ";", "}", "@", "Override", "public", "void", "execute", "(", ")", "throws", "Pausable", "{", "try", "{", "EObject", "result", "=", "null", ";", "try", "{", "main_loop", "(", ")", ";", "result", "=", "am_normal", ";", "}", "catch", "(", "NotImplemented", "e", ")", "{", "log", ".", "log", "(", "Level", ".", "SEVERE", ",", "\"exiting", "\"", "+", "self_handle", "(", ")", ",", "e", ")", ";", "result", "=", "e", ".", "reason", "(", ")", ";", "}", "catch", "(", "ErlangException", "e", ")", "{", "result", "=", "e", ".", "reason", "(", ")", ";", "}", "catch", "(", "ErlangExitSignal", "e", ")", "{", "result", "=", "e", ".", "reason", "(", ")", ";", "}", "catch", "(", "Throwable", "e", ")", "{", "e", ".", "printStackTrace", "(", ")", ";", "ESeq", "erl_trace", "=", "ErlangError", ".", "decodeTrace", "(", "e", ".", "getStackTrace", "(", ")", ")", ";", "ETuple", "java_ex", "=", "ETuple", ".", "make", "(", "am_java_exception", ",", "EString", ".", "fromString", "(", "ERT", ".", "describe_exception", "(", "e", ")", ")", ")", ";", "result", "=", "ETuple", ".", "make", "(", "java_ex", ",", "erl_trace", ")", ";", "if", "(", "log", ".", "isLoggable", "(", "Level", ".", "FINER", ")", ")", "{", "log", ".", "finer", "(", "\"EXITING", "\"", "+", "result", ")", ";", "}", "}", "finally", "{", "this", ".", "pstate", "=", "STATE_DONE", ";", "}", "do_proc_termination", "(", "result", ")", ";", "}", "catch", "(", "ThreadDeath", "e", ")", "{", "throw", "e", ";", "}", "catch", "(", "Throwable", "e", ")", "{", "e", ".", "printStackTrace", "(", ")", ";", "}", "}", "protected", "void", "main_loop", "(", ")", "throws", "Exception", ",", "Pausable", "{", "List", "<", "ByteBuffer", ">", "out", "=", "new", "ArrayList", "<", "ByteBuffer", ">", "(", ")", ";", "EObject", "msg", ";", "next_message", ":", "while", "(", "true", ")", "{", "if", "(", "abs_timeout", "==", "0", ")", "{", "msg", "=", "mbox", ".", "get", "(", ")", ";", "}", "else", "{", "msg", "=", "null", ";", "long", "timeout", "=", "abs_timeout", "-", "System", ".", "currentTimeMillis", "(", ")", ";", "if", "(", "timeout", ">", "0", ")", "{", "msg", "=", "mbox", ".", "get", "(", "timeout", ")", ";", "}", "if", "(", "msg", "==", "null", ")", "{", "abs_timeout", "=", "0", ";", "this", ".", "instance", ".", "timeout", "(", ")", ";", "continue", "next_message", ";", "}", "}", "ETuple2", "t2", ";", "EPortControl", "ctrl", ";", "ETuple3", "t3", ";", "ETuple4", "t4", ";", "ETuple", "tup", ";", "if", "(", "(", "t2", "=", "ETuple2", ".", "cast", "(", "msg", ")", ")", "!=", "null", ")", "{", "EObject", "sender", "=", "t2", ".", "elem1", ";", "ETuple2", "cmd", ";", "if", "(", "(", "cmd", "=", "ETuple2", ".", "cast", "(", "t2", ".", "elem2", ")", ")", "!=", "null", ")", "{", "if", "(", "cmd", ".", "elem1", "==", "EPort", ".", "am_command", ")", "{", "if", "(", "cmd", ".", "elem2", ".", "collectIOList", "(", "out", ")", ")", "{", "EHandle", "caller", "=", "sender", ".", "testHandle", "(", ")", ";", "if", "(", "caller", "==", "null", ")", "{", "log", ".", "warning", "(", "\"\"", "+", "sender", ")", ";", "}", "if", "(", "out", ".", "size", "(", ")", "==", "0", ")", "{", "instance", ".", "outputv", "(", "caller", ",", "ERT", ".", "EMPTY_BYTEBUFFER_ARR", ")", ";", "}", "else", "{", "instance", ".", "outputv", "(", "caller", ",", "out", ".", "toArray", "(", "new", "ByteBuffer", "[", "out", ".", "size", "(", ")", "]", ")", ")", ";", "}", "}", "out", ".", "clear", "(", ")", ";", "continue", "next_message", ";", "}", "else", "if", "(", "cmd", ".", "elem1", "==", "EPort", ".", "am_connect", ")", "{", "EPID", "new_owner", ";", "if", "(", "(", "new_owner", "=", "cmd", ".", "elem2", ".", "testPID", "(", ")", ")", "==", "null", ")", "break", ";", "EPID", "old_owner", "=", "this", ".", "owner", ";", "this", ".", "owner", "=", "new_owner", ";", "old_owner", ".", "send", "(", "this", ".", "port", ",", "ETuple", ".", "make", "(", "this", ".", "self_handle", "(", ")", ",", "EPort", ".", "am_connected", ")", ")", ";", "continue", "next_message", ";", "}", "}", "else", "if", "(", "t2", ".", "elem2", "==", "am_close", ")", "{", "this", ".", "reply_closed_to", "=", "t2", ".", "elem1", ".", "testPID", "(", ")", ";", "return", ";", "}", "}", "else", "if", "(", "(", "ctrl", "=", "msg", ".", "testPortControl", "(", ")", ")", "!=", "null", ")", "{", "ctrl", ".", "execute", "(", ")", ";", "continue", "next_message", ";", "}", "else", "if", "(", "(", "t3", "=", "ETuple3", ".", "cast", "(", "msg", ")", ")", "!=", "null", ")", "{", "if", "(", "t3", ".", "elem1", "==", "ERT", ".", "am_EXIT", ")", "{", "return", ";", "}", "}", "else", "if", "(", "(", "tup", "=", "msg", ".", "testTuple", "(", ")", ")", "!=", "null", "&&", "tup", ".", "arity", "(", ")", "==", "5", ")", "{", "if", "(", "tup", ".", "elm", "(", "1", ")", "==", "ERT", ".", "am_DOWN", ")", "{", "ERef", "ref", "=", "tup", ".", "elm", "(", "2", ")", ".", "testReference", "(", ")", ";", "instance", ".", "processExit", "(", "ref", ")", ";", "}", "}", "break", ";", "}", "throw", "new", "ErlangError", "(", "ERT", ".", "am_badsig", ",", "msg", ")", ";", "}", "public", "EObject", "control", "(", "EProc", "caller", ",", "int", "op", ",", "ByteBuffer", "cmd2", ")", "throws", "Pausable", "{", "if", "(", "pstate", "==", "STATE_RUNNING", "||", "pstate", "==", "STATE_INIT", ")", "{", "}", "else", "{", "log", ".", "warning", "(", "\"port", "\"", "+", "this", ".", "self_handle", "(", ")", "+", "\"", "in", "state:", "\"", "+", "pstate", ")", ";", "throw", "ERT", ".", "badarg", "(", ")", ";", "}", "if", "(", "log", ".", "isLoggable", "(", "Level", ".", "FINE", ")", ")", "log", ".", "fine", "(", "\"ctrl:", "cmd=\"", "+", "op", "+", "\";", "arg=\"", "+", "EBinary", ".", "make", "(", "cmd2", ")", ")", ";", "while", "(", "mbox", ".", "hasMessage", "(", ")", ")", "{", "Task", ".", "yield", "(", ")", ";", "}", "long", "old_to", "=", "abs_timeout", ";", "ByteBuffer", "bb", "=", "instance", ".", "control", "(", "caller", ".", "self_handle", "(", ")", ",", "op", ",", "cmd2", ")", ";", "long", "new_to", "=", "abs_timeout", ";", "if", "(", "old_to", "!=", "new_to", ")", "{", "mbox", ".", "put", "(", "new", "EPortControl", "(", ")", "{", "@", "Override", "public", "void", "execute", "(", ")", "throws", "Pausable", ",", "IOException", "{", "}", "}", ")", ";", "}", "if", "(", "bb", "==", "null", "||", "bb", ".", "position", "(", ")", "==", "0", ")", "{", "return", "ERT", ".", "NIL", ";", "}", "else", "{", "bb", ".", "flip", "(", ")", ";", "return", "EString", ".", "make", "(", "bb", ".", "array", "(", ")", ",", "bb", ".", "arrayOffset", "(", ")", ",", "bb", ".", "remaining", "(", ")", ")", ";", "}", "}", "public", "static", "ByteBuffer", "flatten", "(", "ByteBuffer", "[", "]", "out", ")", "{", "if", "(", "out", ".", "length", "==", "0", ")", "{", "return", "ERT", ".", "EMPTY_BYTEBUFFER", ";", "}", "else", "if", "(", "out", ".", "length", "==", "1", ")", "{", "return", "out", "[", "0", "]", ";", "}", "else", "{", "long", "size", "=", "0", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "out", ".", "length", ";", "i", "++", ")", "{", "size", "+=", "out", "[", "i", "]", ".", "limit", "(", ")", ";", "}", "if", "(", "size", ">", "Integer", ".", "MAX_VALUE", ")", "throw", "new", "IllegalArgumentException", "(", "\"\"", "+", "size", ")", ";", "ByteBuffer", "res", "=", "ByteBuffer", ".", "allocate", "(", "(", "int", ")", "size", ")", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "out", ".", "length", ";", "i", "++", ")", "{", "res", ".", "put", "(", "out", "[", "i", "]", ")", ";", "}", "res", ".", "flip", "(", ")", ";", "return", "res", ";", "}", "}", "public", "EObject", "call", "(", "EProc", "caller", ",", "int", "op", ",", "EObject", "data", ")", "throws", "Pausable", "{", "if", "(", "pstate", "!=", "STATE_RUNNING", ")", "{", "throw", "ERT", ".", "badarg", "(", ")", ";", "}", "EObject", "result", "=", "instance", ".", "call", "(", "caller", ".", "self_handle", "(", ")", ",", "op", ",", "data", ")", ";", "if", "(", "result", "==", "null", ")", "{", "return", "ERT", ".", "NIL", ";", "}", "else", "{", "return", "result", ";", "}", "}", "public", "void", "command", "(", "final", "EHandle", "caller", ",", "final", "ByteBuffer", "[", "]", "out", ")", "throws", "Pausable", "{", "mbox", ".", "put", "(", "new", "EPortControl", "(", ")", "{", "@", "Override", "public", "void", "execute", "(", ")", "throws", "Pausable", ",", "IOException", "{", "instance", ".", "outputv", "(", "caller", ",", "out", ")", ";", "}", "}", ")", ";", "}", "public", "void", "close", "(", ")", "throws", "Pausable", "{", "mbox", ".", "put", "(", "new", "EPortControl", "(", ")", "{", "@", "Override", "public", "void", "execute", "(", ")", "throws", "Exception", ",", "Pausable", "{", "throw", "new", "ErlangExitSignal", "(", "am_normal", ")", ";", "}", "}", ")", ";", "}", "@", "Override", "protected", "void", "process_incoming_exit", "(", "EHandle", "from", ",", "EObject", "reason", ",", "boolean", "exitToSender", ")", "throws", "Pausable", "{", "mbox", ".", "put", "(", "ETuple", ".", "make", "(", "ERT", ".", "am_EXIT", ",", "from", ",", "reason", ")", ")", ";", "}", "@", "Override", "protected", "void", "do_proc_termination", "(", "EObject", "result", ")", "throws", "Pausable", "{", "if", "(", "this", ".", "reply_closed_to", "!=", "null", ")", "{", "this", ".", "reply_closed_to", ".", "send", "(", "self_handle", "(", ")", ",", "ETuple", ".", "make", "(", "self_handle", "(", ")", ",", "am_closed", ")", ")", ";", "}", "super", ".", "do_proc_termination", "(", "result", ")", ";", "if", "(", "result", "!=", "am_normal", ")", "{", "owner", ".", "send", "(", "self_handle", "(", ")", ",", "ETuple", ".", "make", "(", "ERT", ".", "am_EXIT", ",", "self_handle", "(", ")", ",", "result", ")", ")", ";", "}", "all_ports", ".", "remove", "(", "this", ".", "id", ")", ";", "EDriverControl", "i", "=", "instance", ";", "if", "(", "i", "!=", "null", ")", "i", ".", "stop", "(", "result", ")", ";", "}", "@", "Override", "public", "void", "ready", "(", "final", "SelectableChannel", "ch", ",", "final", "int", "readyOps", ")", "{", "mbox", ".", "putb", "(", "new", "EPortControl", "(", ")", "{", "@", "Override", "public", "void", "execute", "(", ")", "throws", "Pausable", "{", "if", "(", "(", "readyOps", "&", "EDriverInstance", ".", "ERL_DRV_READ", ")", "==", "EDriverInstance", ".", "ERL_DRV_READ", ")", "{", "instance", ".", "readyInput", "(", "ch", ")", ";", "}", "if", "(", "(", "readyOps", "&", "EDriverInstance", ".", "ERL_DRV_WRITE", ")", "==", "EDriverInstance", ".", "ERL_DRV_WRITE", ")", "{", "instance", ".", "readyOutput", "(", "ch", ")", ";", "}", "if", "(", "(", "readyOps", "&", "EDriverInstance", ".", "ERL_DRV_CONNECT", ")", "==", "EDriverInstance", ".", "ERL_DRV_CONNECT", ")", "{", "instance", ".", "readyConnect", "(", "ch", ")", ";", "}", "if", "(", "(", "readyOps", "&", "EDriverInstance", ".", "ERL_DRV_ACCEPT", ")", "==", "EDriverInstance", ".", "ERL_DRV_ACCEPT", ")", "{", "instance", ".", "readyAccept", "(", "ch", ")", ";", "}", "}", "}", ")", ";", "}", "@", "Override", "public", "void", "released", "(", "final", "SelectableChannel", "ch", ")", "{", "mbox", ".", "putb", "(", "new", "EPortControl", "(", ")", "{", "@", "Override", "public", "void", "execute", "(", ")", "throws", "Pausable", "{", "instance", ".", "stopSelect", "(", "ch", ")", ";", "}", "}", ")", ";", "}", "@", "Override", "public", "void", "exception", "(", "SelectableChannel", "ch", ",", "IOException", "e", ")", "{", "}", "public", "void", "set_timer", "(", "long", "howlong", ")", "{", "this", ".", "abs_timeout", "=", "System", ".", "currentTimeMillis", "(", ")", "+", "howlong", ";", "}", "public", "long", "read_timer", "(", ")", "{", "return", "this", ".", "abs_timeout", "-", "System", ".", "currentTimeMillis", "(", ")", ";", "}", "public", "void", "cancel_timer", "(", "EPort", "port2", ")", "{", "assert", "port2", "==", "this", ".", "port", ":", "\"\"", ";", "this", ".", "abs_timeout", "=", "0", ";", "}", "public", "void", "async_done", "(", "final", "EAsync", "job", ")", "{", "mbox", ".", "putb", "(", "new", "EPortControl", "(", ")", "{", "@", "Override", "public", "void", "execute", "(", ")", "throws", "Pausable", "{", "instance", ".", "readyAsync", "(", "job", ")", ";", "}", "}", ")", ";", "}", "public", "void", "output_from_driver", "(", "EObject", "out", ")", "throws", "Pausable", "{", "output_term_from_driver", "(", "new", "ETuple2", "(", "port", ",", "new", "ETuple2", "(", "am_data", ",", "out", ")", ")", ")", ";", "}", "public", "void", "output_from_driver_b", "(", "EObject", "out", ")", "{", "output_term_from_driver_b", "(", "new", "ETuple2", "(", "port", ",", "new", "ETuple2", "(", "am_data", ",", "out", ")", ")", ")", ";", "}", "public", "void", "output_term_from_driver", "(", "EObject", "out", ")", "throws", "Pausable", "{", "if", "(", "log", ".", "isLoggable", "(", "Level", ".", "FINE", ")", ")", "log", ".", "fine", "(", "\"\"", "+", "owner", "+", "\"", "!", "\"", "+", "out", ")", ";", "owner", ".", "send", "(", "port", ",", "out", ")", ";", "}", "public", "void", "output_term_from_driver_b", "(", "EObject", "out", ")", "{", "if", "(", "log", ".", "isLoggable", "(", "Level", ".", "FINE", ")", ")", "log", ".", "fine", "(", "\"\"", "+", "owner", "+", "\"", "!", "\"", "+", "out", ")", ";", "owner", ".", "sendb", "(", "out", ")", ";", "}", "public", "void", "eof_from_driver_b", "(", ")", "{", "output_term_from_driver_b", "(", "new", "ETuple2", "(", "port", ",", "am_eof", ")", ")", ";", "}", "public", "void", "eof_from_driver", "(", ")", "throws", "Pausable", "{", "output_term_from_driver", "(", "new", "ETuple2", "(", "port", ",", "am_eof", ")", ")", ";", "}", "public", "void", "exit_status_from_driver", "(", "int", "code", ")", "throws", "Pausable", "{", "output_term_from_driver", "(", "new", "ETuple2", "(", "port", ",", "ERT", ".", "box", "(", "code", ")", ")", ")", ";", "}", "public", "void", "exit_status_from_driver_b", "(", "int", "code", ")", "{", "output_term_from_driver_b", "(", "new", "ETuple2", "(", "port", ",", "ERT", ".", "box", "(", "code", ")", ")", ")", ";", "}", "public", "static", "ESeq", "all_ports", "(", ")", "{", "ESeq", "res", "=", "ERT", ".", "NIL", ";", "for", "(", "EDriverTask", "dt", ":", "all_ports", ".", "values", "(", ")", ")", "{", "if", "(", "dt", ".", "isDone", "(", ")", ")", "continue", ";", "res", "=", "res", ".", "cons", "(", "dt", ".", "self_handle", "(", ")", ")", ";", "}", "return", "res", ";", "}", "public", "EObject", "port_info", "(", "EAtom", "spec", ")", "{", "if", "(", "spec", "==", "am_connected", ")", "{", "return", "new", "ETuple2", "(", "am_connected", ",", "owner", ")", ";", "}", "if", "(", "spec", "==", "am_name", ")", "{", "return", "new", "ETuple2", "(", "am_name", ",", "getName", "(", ")", ")", ";", "}", "if", "(", "spec", "==", "EProc", ".", "am_links", ")", "{", "return", "new", "ETuple2", "(", "EProc", ".", "am_links", ",", "links", "(", ")", ")", ";", "}", "throw", "new", "NotImplemented", "(", "\"port_info(\"", "+", "spec", "+", "\")\"", ")", ";", "}", "public", "void", "exit", "(", "final", "EObject", "reason", ")", "{", "mbox", ".", "putb", "(", "new", "EPortControl", "(", ")", "{", "@", "Override", "public", "void", "execute", "(", ")", "throws", "Pausable", ",", "IOException", "{", "throw", "new", "ErlangExit", "(", "reason", ")", ";", "}", "}", ")", ";", "}", "public", "EPeer", "node", "(", ")", "{", "return", "this", ".", "peer", ";", "}", "public", "void", "node", "(", "EPeer", "peer", ")", "{", "this", ".", "peer", "=", "peer", ";", "this", ".", "status", "|=", "ERTS_PORT_SFLG_DISTRIBUTION", ";", "}", "public", "void", "outputv", "(", "EHandle", "sender", ",", "ByteBuffer", "[", "]", "ev", ")", "throws", "IOException", ",", "Pausable", "{", "this", ".", "command", "(", "sender", ",", "ev", ")", ";", "}", "public", "boolean", "send_binary_data", "(", ")", "{", "return", "send_binary_data", ";", "}", "}", "</s>" ]
7,729
[ "<s>", "package", "erjang", ".", "driver", ".", "js", ";", "import", "java", ".", "util", ".", "concurrent", ".", "locks", ".", "ReentrantLock", ";", "import", "erjang", ".", "EString", ";", "import", "erjang", ".", "driver", ".", "EDriver", ";", "import", "erjang", ".", "driver", ".", "EDriverControl", ";", "public", "class", "EJSDriver", "implements", "EDriver", "{", "private", "kilim", ".", "ReentrantLock", "lock", ";", "@", "Override", "public", "String", "driverName", "(", ")", "{", "return", "\"\"", ";", "}", "@", "Override", "public", "void", "finish", "(", ")", "{", "}", "@", "Override", "public", "ReentrantLock", "getLock", "(", ")", "{", "if", "(", "lock", "==", "null", ")", "{", "lock", "=", "new", "kilim", ".", "ReentrantLock", "(", ")", ";", "}", "return", "lock", ";", "}", "@", "Override", "public", "EDriverControl", "start", "(", "EString", "command", ")", "{", "return", "new", "EJSDriverInstance", "(", "this", ")", ";", "}", "@", "Override", "public", "boolean", "useDriverLevelLocking", "(", ")", "{", "return", "false", ";", "}", "}", "</s>" ]
7,730
[ "<s>", "package", "erjang", ".", "driver", ".", "js", ";", "import", "java", ".", "io", ".", "IOException", ";", "import", "java", ".", "nio", ".", "ByteBuffer", ";", "import", "kilim", ".", "Pausable", ";", "import", "org", ".", "mozilla", ".", "javascript", ".", "Context", ";", "import", "org", ".", "mozilla", ".", "javascript", ".", "ContextFactory", ";", "import", "org", ".", "mozilla", ".", "javascript", ".", "Script", ";", "import", "org", ".", "mozilla", ".", "javascript", ".", "ScriptableObject", ";", "import", "erjang", ".", "EAtom", ";", "import", "erjang", ".", "EBinary", ";", "import", "erjang", ".", "EHandle", ";", "import", "erjang", ".", "ERT", ";", "import", "erjang", ".", "ETuple", ";", "import", "erjang", ".", "driver", ".", "EAsync", ";", "import", "erjang", ".", "driver", ".", "EDriver", ";", "import", "erjang", ".", "driver", ".", "EDriverInstance", ";", "import", "erjang", ".", "driver", ".", "IO", ";", "public", "class", "EJSDriverInstance", "extends", "EDriverInstance", "{", "static", "final", "EAtom", "am_ok", "=", "ERT", ".", "am_ok", ";", "static", "final", "EAtom", "am_error", "=", "ERT", ".", "am_error", ";", "static", "final", "EAtom", "am_unknown_command", "=", "EAtom", ".", "intern", "(", "\"\"", ")", ";", "static", "ContextFactory", "cf_global", "=", "ContextFactory", ".", "getGlobal", "(", ")", ";", "static", "class", "EContext", "extends", "Context", "{", "public", "EContext", "(", ")", "{", "super", "(", "cf_global", ")", ";", "}", "}", "public", "EJSDriverInstance", "(", "EDriver", "driver", ")", "{", "super", "(", "driver", ")", ";", "}", "void", "send_ok_response", "(", "EBinary", "call_id", ")", "throws", "Pausable", "{", "driver_output_term", "(", "ETuple", ".", "make", "(", "call_id", ",", "am_ok", ")", ")", ";", "}", "void", "send_error_string_response", "(", "EBinary", "call_id", ",", "String", "msg", ")", "throws", "Pausable", "{", "driver_output_term", "(", "ETuple", ".", "make", "(", "call_id", ",", "am_error", ",", "EBinary", ".", "fromString", "(", "msg", ")", ")", ")", ";", "}", "void", "send_string_response", "(", "EBinary", "call_id", ",", "String", "result", ")", "throws", "Pausable", "{", "driver_output_term", "(", "ETuple", ".", "make", "(", "call_id", ",", "am_ok", ",", "EBinary", ".", "fromString", "(", "result", ")", ")", ")", ";", "}", "void", "unknown_command", "(", "EBinary", "call_id", ")", "throws", "Pausable", "{", "driver_output_term", "(", "ETuple", ".", "make", "(", "call_id", ",", "am_error", ",", "am_unknown_command", ")", ")", ";", "}", "short", "IJ", "=", "(", "'i'", "<<", "8", ")", "|", "'j'", ";", "short", "EJ", "=", "(", "'e'", "<<", "8", ")", "|", "'j'", ";", "short", "DJ", "=", "(", "'d'", "<<", "8", ")", "|", "'j'", ";", "short", "SD", "=", "(", "'s'", "<<", "8", ")", "|", "'d'", ";", "private", "VM", "vm", ";", "@", "Override", "protected", "void", "readyAsync", "(", "EAsync", "data", ")", "throws", "Pausable", "{", "data", ".", "ready", "(", ")", ";", "}", "@", "Override", "protected", "void", "output", "(", "EHandle", "caller", ",", "final", "ByteBuffer", "buf", ")", "throws", "IOException", ",", "Pausable", "{", "final", "int", "cmd", "=", "buf", ".", "getShort", "(", ")", ";", "final", "EBinary", "call_id", "=", "read_binary", "(", "buf", ")", ";", "if", "(", "cmd", "==", "IJ", ")", "{", "int", "heap_size", "=", "buf", ".", "getInt", "(", ")", ";", "vm", "=", "sm_initialize", "(", "heap_size", "*", "1024", "*", "1024", ")", ";", "send_ok_response", "(", "call_id", ")", ";", "}", "else", "{", "EAsync", "job", "=", "new", "EAsync", "(", ")", "{", "String", "err", ",", "resp", ";", "@", "Override", "public", "void", "async", "(", ")", "{", "if", "(", "cmd", "==", "EJ", ")", "{", "String", "filename", "=", "read_string", "(", "buf", ")", ";", "String", "code", "=", "read_string", "(", "buf", ")", ";", "String", "result", "=", "sm_eval", "(", "filename", ",", "code", ",", "true", ")", ";", "if", "(", "result", ".", "startsWith", "(", "\"{\\\"error\\\"\"", ")", ")", "{", "err", "=", "result", ";", "}", "else", "{", "resp", "=", "result", ";", "}", "}", "else", "if", "(", "cmd", "==", "DJ", ")", "{", "String", "filename", "=", "read_string", "(", "buf", ")", ";", "String", "code", "=", "read_string", "(", "buf", ")", ";", "String", "result", "=", "sm_eval", "(", "filename", ",", "code", ",", "false", ")", ";", "if", "(", "result", "!=", "null", ")", "{", "err", "=", "result", ";", "}", "}", "else", "if", "(", "cmd", "==", "SD", ")", "{", "vm", "=", "null", ";", "}", "}", "@", "Override", "public", "void", "ready", "(", ")", "throws", "Pausable", "{", "if", "(", "err", "!=", "null", ")", "{", "send_error_string_response", "(", "call_id", ",", "err", ")", ";", "}", "else", "if", "(", "resp", "!=", "null", ")", "{", "send_string_response", "(", "call_id", ",", "err", ")", ";", "}", "else", "{", "send_ok_response", "(", "call_id", ")", ";", "}", "}", "}", ";", "driver_async", "(", "job", ")", ";", "}", "}", "static", "class", "VM", "{", "EContext", "cx", ";", "ScriptableObject", "global", ";", "}", "private", "VM", "sm_initialize", "(", "int", "i", ")", "{", "VM", "vm", "=", "new", "VM", "(", ")", ";", "vm", ".", "cx", "=", "new", "EContext", "(", ")", ";", "cf_global", ".", "enterContext", "(", "vm", ".", "cx", ")", ";", "try", "{", "vm", ".", "global", "=", "vm", ".", "cx", ".", "initStandardObjects", "(", ")", ";", "return", "vm", ";", "}", "finally", "{", "Context", ".", "exit", "(", ")", ";", "}", "}", "private", "String", "sm_eval", "(", "String", "filename", ",", "String", "code", ",", "boolean", "handle_retval", ")", "{", "Context", "ctx", "=", "cf_global", ".", "enterContext", "(", "vm", ".", "cx", ")", ";", "try", "{", "Script", "scr", "=", "ctx", ".", "compileString", "(", "code", ",", "filename", ",", "1", ",", "null", ")", ";", "Object", "result", "=", "scr", ".", "exec", "(", "ctx", ",", "vm", ".", "global", ")", ";", "if", "(", "handle_retval", ")", "{", "if", "(", "result", "instanceof", "String", ")", "{", "return", "(", "String", ")", "result", ";", "}", "else", "if", "(", "result", "==", "Context", ".", "getUndefinedValue", "(", ")", ")", "{", "return", "\"\"", ";", "}", "else", "{", "return", "\"\"", ";", "}", "}", "else", "{", "return", "null", ";", "}", "}", "finally", "{", "Context", ".", "exit", "(", ")", ";", "}", "}", "private", "EBinary", "read_binary", "(", "ByteBuffer", "buf", ")", "{", "int", "str_len", "=", "buf", ".", "getInt", "(", ")", ";", "EBinary", "str", "=", "new", "EBinary", "(", "buf", ".", "array", "(", ")", ",", "buf", ".", "position", "(", ")", "+", "buf", ".", "arrayOffset", "(", ")", ",", "str_len", ")", ";", "buf", ".", "position", "(", "buf", ".", "position", "(", ")", "+", "str_len", ")", ";", "return", "str", ";", "}", "private", "String", "read_string", "(", "ByteBuffer", "buf", ")", "{", "int", "str_len", "=", "buf", ".", "getInt", "(", ")", ";", "byte", "[", "]", "data", "=", "new", "byte", "[", "str_len", "]", ";", "buf", ".", "get", "(", "data", ")", ";", "return", "new", "String", "(", "data", ",", "IO", ".", "UTF8", ")", ";", "}", "}", "</s>" ]
7,731
[ "<s>", "package", "erjang", ".", "driver", ".", "inet_gethost", ";", "import", "java", ".", "io", ".", "IOException", ";", "import", "java", ".", "net", ".", "Inet4Address", ";", "import", "java", ".", "net", ".", "Inet6Address", ";", "import", "java", ".", "net", ".", "InetAddress", ";", "import", "java", ".", "net", ".", "UnknownHostException", ";", "import", "java", ".", "nio", ".", "ByteBuffer", ";", "import", "java", ".", "nio", ".", "channels", ".", "SelectableChannel", ";", "import", "kilim", ".", "Pausable", ";", "import", "erjang", ".", "EHandle", ";", "import", "erjang", ".", "EString", ";", "import", "erjang", ".", "NotImplemented", ";", "import", "erjang", ".", "driver", ".", "EAsync", ";", "import", "erjang", ".", "driver", ".", "EDriver", ";", "import", "erjang", ".", "driver", ".", "EDriverInstance", ";", "import", "erjang", ".", "driver", ".", "IO", ";", "public", "class", "GetHostDriver", "extends", "EDriverInstance", "{", "public", "static", "final", "byte", "OP_GETHOSTBYNAME", "=", "1", ";", "public", "static", "final", "byte", "OP_GETHOSTBYADDR", "=", "2", ";", "public", "static", "final", "byte", "OP_CANCEL_REQUEST", "=", "3", ";", "public", "static", "final", "byte", "OP_CONTROL", "=", "4", ";", "public", "static", "final", "byte", "PROTO_IPV4", "=", "1", ";", "public", "static", "final", "byte", "PROTO_IPV6", "=", "2", ";", "public", "static", "final", "byte", "SETOPT_DEBUG_LEVEL", "=", "0", ";", "public", "static", "final", "byte", "UNIT_ERROR", "=", "0", ";", "public", "static", "final", "byte", "UNIT_IPV4", "=", "4", ";", "public", "static", "final", "byte", "UNIT_IPV6", "=", "16", ";", "private", "EString", "command", ";", "public", "GetHostDriver", "(", "EDriver", "driver", ",", "EString", "command", ")", "{", "super", "(", "driver", ")", ";", "this", ".", "command", "=", "command", ";", "}", "@", "Override", "protected", "void", "flush", "(", ")", "throws", "Pausable", "{", "}", "@", "Override", "protected", "void", "output", "(", "EHandle", "caller", ",", "ByteBuffer", "buf", ")", "throws", "IOException", ",", "Pausable", "{", "final", "int", "seq", "=", "buf", ".", "getInt", "(", ")", ";", "byte", "op", "=", "buf", ".", "get", "(", ")", ";", "EAsync", "eas", ";", "switch", "(", "op", ")", "{", "case", "OP_GETHOSTBYNAME", ":", "{", "eas", "=", "gethostbyname", "(", "buf", ",", "seq", ")", ";", "break", ";", "}", "case", "OP_GETHOSTBYADDR", ":", "{", "eas", "=", "gethostbyaddr", "(", "buf", ",", "seq", ")", ";", "break", ";", "}", "default", ":", "throw", "new", "NotImplemented", "(", "\"\"", "+", "seq", "+", "\";", "op=\"", "+", "op", ")", ";", "}", "driver_async", "(", "eas", ")", ";", "}", "private", "EAsync", "gethostbyname", "(", "ByteBuffer", "buf", ",", "final", "int", "seq", ")", "{", "final", "byte", "proto", "=", "buf", ".", "get", "(", ")", ";", "final", "String", "host", "=", "IO", ".", "getstr", "(", "buf", ",", "true", ")", ";", "return", "new", "EAsync", "(", ")", "{", "InetAddress", "[", "]", "addr", ";", "String", "[", "]", "names", ";", "private", "UnknownHostException", "err", ";", "InetAddress", "primary", ";", "@", "Override", "public", "void", "async", "(", ")", "{", "try", "{", "primary", "=", "InetAddress", ".", "getByName", "(", "host", ")", ";", "addr", "=", "InetAddress", ".", "getAllByName", "(", "host", ")", ";", "names", "=", "new", "String", "[", "addr", ".", "length", "]", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "addr", ".", "length", ";", "i", "++", ")", "{", "names", "[", "i", "]", "=", "addr", "[", "i", "]", ".", "getCanonicalHostName", "(", ")", ";", "}", "}", "catch", "(", "UnknownHostException", "e", ")", "{", "this", ".", "err", "=", "e", ";", "}", "}", "@", "Override", "public", "void", "ready", "(", ")", "throws", "Pausable", "{", "if", "(", "addr", "!=", "null", ")", "{", "byte", "[", "]", "[", "]", "bytes", "=", "new", "byte", "[", "addr", ".", "length", "]", "[", "]", ";", "int", "size", "=", "4", "+", "1", "+", "4", ";", "int", "first", "=", "-", "1", ";", "int", "acount", "=", "0", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "addr", ".", "length", ";", "i", "++", ")", "{", "if", "(", "(", "proto", "==", "PROTO_IPV4", "&&", "(", "addr", "[", "i", "]", "instanceof", "Inet4Address", ")", ")", "||", "(", "proto", "==", "PROTO_IPV6", "&&", "(", "addr", "[", "i", "]", "instanceof", "Inet6Address", ")", ")", ")", "{", "bytes", "[", "i", "]", "=", "addr", "[", "i", "]", ".", "getAddress", "(", ")", ";", "size", "+=", "bytes", "[", "i", "]", ".", "length", ";", "acount", "+=", "1", ";", "if", "(", "first", "==", "-", "1", ")", "first", "=", "i", ";", "if", "(", "host", ".", "equals", "(", "names", "[", "i", "]", ")", ")", "{", "first", "=", "i", ";", "}", "}", "}", "size", "+=", "4", ";", "size", "+=", "host", ".", "length", "(", ")", "+", "1", ";", "ByteBuffer", "rep", "=", "ByteBuffer", ".", "allocate", "(", "size", ")", ";", "rep", ".", "putInt", "(", "seq", ")", ";", "if", "(", "proto", "==", "PROTO_IPV4", ")", "{", "rep", ".", "put", "(", "UNIT_IPV4", ")", ";", "rep", ".", "putInt", "(", "acount", ")", ";", "if", "(", "acount", ">", "0", ")", "{", "rep", ".", "put", "(", "bytes", "[", "first", "]", ")", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "addr", ".", "length", ";", "i", "++", ")", "{", "if", "(", "i", "!=", "first", "&&", "bytes", "[", "i", "]", "!=", "null", ")", "{", "rep", ".", "put", "(", "bytes", "[", "i", "]", ")", ";", "}", "}", "}", "rep", ".", "putInt", "(", "1", ")", ";", "rep", ".", "put", "(", "host", ".", "getBytes", "(", "IO", ".", "ISO_LATIN_1", ")", ")", ";", "rep", ".", "put", "(", "(", "byte", ")", "0", ")", ";", "driver_output", "(", "rep", ")", ";", "return", ";", "}", "else", "if", "(", "proto", "==", "PROTO_IPV6", ")", "{", "rep", ".", "put", "(", "UNIT_IPV6", ")", ";", "rep", ".", "putInt", "(", "acount", ")", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "addr", ".", "length", ";", "i", "++", ")", "{", "if", "(", "bytes", "[", "i", "]", "!=", "null", ")", "{", "rep", ".", "put", "(", "bytes", "[", "i", "]", ")", ";", "}", "}", "rep", ".", "putInt", "(", "1", ")", ";", "rep", ".", "put", "(", "host", ".", "getBytes", "(", "IO", ".", "ISO_LATIN_1", ")", ")", ";", "rep", ".", "put", "(", "(", "byte", ")", "0", ")", ";", "driver_output", "(", "rep", ")", ";", "return", ";", "}", "}", "String", "message", "=", "\"unknown\"", ";", "if", "(", "err", "!=", "null", ")", "{", "message", "=", "err", ".", "getMessage", "(", ")", ";", "}", "byte", "[", "]", "msg", "=", "message", ".", "getBytes", "(", "IO", ".", "ISO_LATIN_1", ")", ";", "int", "len", "=", "4", "+", "1", "+", "msg", ".", "length", ";", "ByteBuffer", "rep", "=", "ByteBuffer", ".", "allocate", "(", "len", ")", ";", "rep", ".", "putInt", "(", "seq", ")", ";", "rep", ".", "put", "(", "UNIT_ERROR", ")", ";", "rep", ".", "put", "(", "msg", ")", ";", "dump_buffer", "(", "new", "ByteBuffer", "[", "]", "{", "rep", "}", ")", ";", "driver_output", "(", "rep", ")", ";", "}", "}", ";", "}", "private", "EAsync", "gethostbyaddr", "(", "ByteBuffer", "buf", ",", "final", "int", "seq", ")", "{", "final", "byte", "proto", "=", "buf", ".", "get", "(", ")", ";", "final", "byte", "[", "]", "host", "=", "new", "byte", "[", "proto", "==", "PROTO_IPV4", "?", "4", ":", "16", "]", ";", "buf", ".", "get", "(", "host", ")", ";", "return", "new", "EAsync", "(", ")", "{", "String", "name", ";", "private", "UnknownHostException", "err", ";", "InetAddress", "primary", ";", "InetAddress", "[", "]", "addr", ";", "@", "Override", "public", "void", "async", "(", ")", "{", "try", "{", "primary", "=", "InetAddress", ".", "getByAddress", "(", "host", ")", ";", "name", "=", "primary", ".", "getCanonicalHostName", "(", ")", ";", "addr", "=", "InetAddress", ".", "getAllByName", "(", "name", ")", ";", "}", "catch", "(", "UnknownHostException", "e", ")", "{", "this", ".", "err", "=", "e", ";", "}", "}", "@", "Override", "public", "void", "ready", "(", ")", "throws", "Pausable", "{", "if", "(", "addr", "!=", "null", ")", "{", "byte", "[", "]", "[", "]", "bytes", "=", "new", "byte", "[", "addr", ".", "length", "]", "[", "]", ";", "int", "size", "=", "4", "+", "1", "+", "4", ";", "int", "first", "=", "-", "1", ";", "int", "acount", "=", "0", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "addr", ".", "length", ";", "i", "++", ")", "{", "if", "(", "(", "proto", "==", "PROTO_IPV4", "&&", "(", "addr", "[", "i", "]", "instanceof", "Inet4Address", ")", ")", "||", "(", "proto", "==", "PROTO_IPV6", "&&", "(", "addr", "[", "i", "]", "instanceof", "Inet6Address", ")", ")", ")", "{", "bytes", "[", "i", "]", "=", "addr", "[", "i", "]", ".", "getAddress", "(", ")", ";", "size", "+=", "bytes", "[", "i", "]", ".", "length", ";", "acount", "+=", "1", ";", "if", "(", "first", "==", "-", "1", ")", "first", "=", "i", ";", "}", "}", "size", "+=", "4", ";", "size", "+=", "name", ".", "length", "(", ")", "+", "1", ";", "ByteBuffer", "rep", "=", "ByteBuffer", ".", "allocate", "(", "size", ")", ";", "rep", ".", "putInt", "(", "seq", ")", ";", "if", "(", "proto", "==", "PROTO_IPV4", ")", "{", "rep", ".", "put", "(", "UNIT_IPV4", ")", ";", "rep", ".", "putInt", "(", "acount", ")", ";", "if", "(", "acount", ">", "0", ")", "{", "rep", ".", "put", "(", "bytes", "[", "first", "]", ")", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "addr", ".", "length", ";", "i", "++", ")", "{", "if", "(", "i", "!=", "first", "&&", "bytes", "[", "i", "]", "!=", "null", ")", "{", "rep", ".", "put", "(", "bytes", "[", "i", "]", ")", ";", "}", "}", "}", "rep", ".", "putInt", "(", "1", ")", ";", "rep", ".", "put", "(", "name", ".", "getBytes", "(", "IO", ".", "ISO_LATIN_1", ")", ")", ";", "rep", ".", "put", "(", "(", "byte", ")", "0", ")", ";", "driver_output", "(", "rep", ")", ";", "return", ";", "}", "else", "if", "(", "proto", "==", "PROTO_IPV6", ")", "{", "rep", ".", "put", "(", "UNIT_IPV6", ")", ";", "rep", ".", "putInt", "(", "acount", ")", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "addr", ".", "length", ";", "i", "++", ")", "{", "if", "(", "bytes", "[", "i", "]", "!=", "null", ")", "{", "rep", ".", "put", "(", "bytes", "[", "i", "]", ")", ";", "}", "}", "rep", ".", "putInt", "(", "1", ")", ";", "rep", ".", "put", "(", "name", ".", "getBytes", "(", "IO", ".", "ISO_LATIN_1", ")", ")", ";", "rep", ".", "put", "(", "(", "byte", ")", "0", ")", ";", "driver_output", "(", "rep", ")", ";", "return", ";", "}", "}", "String", "message", "=", "\"unknown\"", ";", "if", "(", "err", "!=", "null", ")", "{", "message", "=", "err", ".", "getMessage", "(", ")", ";", "}", "byte", "[", "]", "msg", "=", "message", ".", "getBytes", "(", "IO", ".", "ISO_LATIN_1", ")", ";", "int", "len", "=", "4", "+", "1", "+", "msg", ".", "length", ";", "ByteBuffer", "rep", "=", "ByteBuffer", ".", "allocate", "(", "len", ")", ";", "rep", ".", "putInt", "(", "seq", ")", ";", "rep", ".", "put", "(", "UNIT_ERROR", ")", ";", "rep", ".", "put", "(", "msg", ")", ";", "dump_buffer", "(", "new", "ByteBuffer", "[", "]", "{", "rep", "}", ")", ";", "driver_output", "(", "rep", ")", ";", "}", "}", ";", "}", "@", "Override", "protected", "void", "readyAsync", "(", "EAsync", "data", ")", "throws", "Pausable", "{", "data", ".", "ready", "(", ")", ";", "}", "@", "Override", "protected", "void", "readyInput", "(", "SelectableChannel", "ch", ")", "throws", "Pausable", "{", "throw", "new", "erjang", ".", "NotImplemented", "(", ")", ";", "}", "@", "Override", "protected", "void", "readyOutput", "(", "SelectableChannel", "evt", ")", "throws", "Pausable", "{", "throw", "new", "erjang", ".", "NotImplemented", "(", ")", ";", "}", "@", "Override", "protected", "void", "timeout", "(", ")", "throws", "Pausable", "{", "throw", "new", "erjang", ".", "NotImplemented", "(", ")", ";", "}", "}", "</s>" ]
7,732
[ "<s>", "package", "erjang", ".", "driver", ".", "inet_gethost", ";", "import", "java", ".", "util", ".", "concurrent", ".", "locks", ".", "ReentrantLock", ";", "import", "erjang", ".", "EString", ";", "import", "erjang", ".", "driver", ".", "EDriver", ";", "import", "erjang", ".", "driver", ".", "EDriverControl", ";", "public", "class", "Driver", "implements", "EDriver", "{", "@", "Override", "public", "String", "driverName", "(", ")", "{", "return", "\"inet_gethost\"", ";", "}", "@", "Override", "public", "boolean", "useDriverLevelLocking", "(", ")", "{", "return", "false", ";", "}", "@", "Override", "public", "void", "finish", "(", ")", "{", "}", "@", "Override", "public", "ReentrantLock", "getLock", "(", ")", "{", "throw", "new", "erjang", ".", "NotImplemented", "(", ")", ";", "}", "@", "Override", "public", "EDriverControl", "start", "(", "EString", "command", ")", "{", "return", "new", "GetHostDriver", "(", "this", ",", "command", ")", ";", "}", "}", "</s>" ]
7,733
[ "<s>", "package", "erjang", ".", "driver", ";", "import", "java", ".", "util", ".", "concurrent", ".", "locks", ".", "ReentrantLock", ";", "import", "erjang", ".", "EString", ";", "public", "interface", "EDriver", "{", "EDriverControl", "start", "(", "EString", "command", ")", ";", "void", "finish", "(", ")", ";", "String", "driverName", "(", ")", ";", "boolean", "useDriverLevelLocking", "(", ")", ";", "ReentrantLock", "getLock", "(", ")", ";", "}", "</s>" ]
7,734
[ "<s>", "package", "erjang", ".", "driver", ";", "import", "java", ".", "io", ".", "IOException", ";", "import", "java", ".", "nio", ".", "channels", ".", "CancelledKeyException", ";", "import", "java", ".", "nio", ".", "channels", ".", "ClosedChannelException", ";", "import", "java", ".", "nio", ".", "channels", ".", "ClosedSelectorException", ";", "import", "java", ".", "nio", ".", "channels", ".", "SelectableChannel", ";", "import", "java", ".", "nio", ".", "channels", ".", "SelectionKey", ";", "import", "java", ".", "nio", ".", "channels", ".", "Selector", ";", "import", "java", ".", "util", ".", "Set", ";", "import", "java", ".", "util", ".", "concurrent", ".", "ArrayBlockingQueue", ";", "import", "java", ".", "util", ".", "logging", ".", "Level", ";", "import", "java", ".", "util", ".", "logging", ".", "Logger", ";", "import", "erjang", ".", "driver", ".", "NIOChannelInfo", ".", "Interest", ";", "public", "class", "NIOSelector", "extends", "Thread", "{", "static", "Logger", "log", "=", "Logger", ".", "getLogger", "(", "\"\"", ")", ";", "static", "final", "NIOSelector", "INSTANCE", "=", "new", "NIOSelector", "(", ")", ";", "private", "Selector", "selector", ";", "public", "NIOSelector", "(", ")", "{", "setDaemon", "(", "true", ")", ";", "try", "{", "selector", "=", "Selector", ".", "open", "(", ")", ";", "}", "catch", "(", "IOException", "e", ")", "{", "e", ".", "printStackTrace", "(", ")", ";", "}", "start", "(", ")", ";", "}", "static", "public", "SelectionKey", "interest", "(", "SelectableChannel", "ch", ")", "{", "return", "ch", ".", "keyFor", "(", "INSTANCE", ".", "selector", ")", ";", "}", "static", "enum", "SetOrClear", "{", "SET", ",", "CLEAR", ";", "}", "static", "class", "SelectMsg", "{", "SetOrClear", "set", ";", "NIOChannelInfo", ".", "Interest", "interest", ";", "}", "ArrayBlockingQueue", "<", "SelectMsg", ">", "mbox", "=", "new", "ArrayBlockingQueue", "<", "SelectMsg", ">", "(", "2", ")", ";", "@", "Override", "public", "void", "run", "(", ")", "{", "try", "{", "run0", "(", ")", ";", "}", "catch", "(", "Throwable", "e", ")", "{", "log", ".", "severe", "(", "\"\"", "+", "e", ".", "getMessage", "(", ")", ")", ";", "log", ".", "log", "(", "Level", ".", "FINE", ",", "\"details:", "\"", ",", "e", ")", ";", "}", "}", "public", "void", "run0", "(", ")", "{", "select_loop", ":", "while", "(", "true", ")", "{", "SelectMsg", "msg", ";", "msg_loop", ":", "while", "(", "(", "msg", "=", "mbox", ".", "poll", "(", ")", ")", "!=", "null", ")", "{", "if", "(", "msg", ".", "set", "==", "SetOrClear", ".", "SET", ")", "{", "process_add_interest_request", "(", "msg", ".", "interest", ")", ";", "}", "else", "{", "process_clear_interest_request", "(", "msg", ".", "interest", ")", ";", "try", "{", "selector", ".", "selectNow", "(", ")", ";", "}", "catch", "(", "IOException", "e", ")", "{", "e", ".", "printStackTrace", "(", ")", ";", "}", "}", "}", "int", "num", ";", "if", "(", "false", ")", "{", "log", ".", "fine", "(", "\"select", "loop\"", ")", ";", "for", "(", "SelectionKey", "key", ":", "selector", ".", "keys", "(", ")", ")", "{", "if", "(", "key", ".", "isValid", "(", ")", ")", "{", "SelectableChannel", "ch", "=", "key", ".", "channel", "(", ")", ";", "int", "interst", "=", "key", ".", "interestOps", "(", ")", ";", "if", "(", "log", ".", "isLoggable", "(", "Level", ".", "FINE", ")", ")", "log", ".", "fine", "(", "Integer", ".", "toBinaryString", "(", "interst", ")", "+", "\":\"", "+", "ch", ")", ";", "}", "}", "}", "try", "{", "num", "=", "selector", ".", "select", "(", "10000", ")", ";", "}", "catch", "(", "CancelledKeyException", "e", ")", "{", "}", "catch", "(", "ClosedSelectorException", "e", ")", "{", "e", ".", "printStackTrace", "(", ")", ";", "return", ";", "}", "catch", "(", "IOException", "e", ")", "{", "e", ".", "printStackTrace", "(", ")", ";", "}", "Set", "<", "SelectionKey", ">", "ready", "=", "selector", ".", "selectedKeys", "(", ")", ";", "for", "(", "SelectionKey", "key", ":", "ready", ")", "{", "NIOChannelInfo", "req", "=", "(", "NIOChannelInfo", ")", "key", ".", "attachment", "(", ")", ";", "if", "(", "req", "==", "null", ")", "{", "log", ".", "severe", "(", "\"\"", ")", ";", "}", "else", "{", "req", ".", "ready", "(", "key", ")", ";", "}", "}", "}", "}", "private", "void", "process_clear_interest_request", "(", "Interest", "interest", ")", "{", "SelectableChannel", "ch", "=", "interest", ".", "ch", ";", "SelectionKey", "key", "=", "ch", ".", "keyFor", "(", "selector", ")", ";", "NIOHandler", "handler", "=", "interest", ".", "handler", ";", "if", "(", "key", "==", "null", "||", "!", "key", ".", "isValid", "(", ")", ")", "{", "if", "(", "handler", "!=", "null", "&&", "interest", ".", "releaseNotify", ")", "{", "handler", ".", "released", "(", "ch", ")", ";", "}", "}", "else", "{", "NIOChannelInfo", "info", "=", "(", "NIOChannelInfo", ")", "key", ".", "attachment", "(", ")", ";", "if", "(", "info", "==", "null", ")", "{", "throw", "new", "InternalError", "(", ")", ";", "}", "info", ".", "clear_interest", "(", "interest", ")", ";", "if", "(", "info", ".", "updateInterestOpsFor", "(", "key", ")", "==", "0", ")", "{", "key", ".", "cancel", "(", ")", ";", "}", "}", "}", "private", "void", "process_add_interest_request", "(", "Interest", "interest", ")", "{", "SelectableChannel", "ch", "=", "interest", ".", "ch", ";", "SelectionKey", "key", "=", "ch", ".", "keyFor", "(", "selector", ")", ";", "NIOChannelInfo", "info", "=", "null", ";", "if", "(", "key", "!=", "null", "&&", "!", "key", ".", "isValid", "(", ")", ")", "{", "try", "{", "selector", ".", "selectNow", "(", ")", ";", "}", "catch", "(", "IOException", "e", ")", "{", "e", ".", "printStackTrace", "(", ")", ";", "}", "key", "=", "null", ";", "}", "if", "(", "key", "==", "null", "||", "!", "key", ".", "isValid", "(", ")", ")", "{", "try", "{", "key", "=", "ch", ".", "register", "(", "selector", ",", "interest", ".", "ops", ",", "info", "=", "new", "NIOChannelInfo", "(", "interest", ")", ")", ";", "}", "catch", "(", "ClosedChannelException", "e", ")", "{", "interest", ".", "handler", ".", "exception", "(", "ch", ",", "e", ")", ";", "}", "}", "else", "{", "info", "=", "(", "NIOChannelInfo", ")", "key", ".", "attachment", "(", ")", ";", "info", ".", "add", "(", "interest", ")", ";", "info", ".", "updateInterestOpsFor", "(", "key", ")", ";", "}", "}", "static", "public", "void", "setInterest", "(", "SelectableChannel", "ch", ",", "int", "op", ",", "NIOHandler", "handler", ")", "{", "INSTANCE", ".", "_addInterest", "(", "ch", ",", "op", ",", "handler", ")", ";", "}", "void", "_addInterest", "(", "SelectableChannel", "ch", ",", "int", "op", ",", "NIOHandler", "handler", ")", "{", "SelectMsg", "msg", "=", "new", "SelectMsg", "(", ")", ";", "msg", ".", "set", "=", "SetOrClear", ".", "SET", ";", "msg", ".", "interest", "=", "new", "NIOChannelInfo", ".", "Interest", "(", "ch", ",", "handler", ",", "op", ",", "false", ")", ";", "try", "{", "mbox", ".", "put", "(", "msg", ")", ";", "}", "catch", "(", "InterruptedException", "e", ")", "{", "e", ".", "printStackTrace", "(", ")", ";", "}", "selector", ".", "wakeup", "(", ")", ";", "}", "static", "public", "void", "clearInterest", "(", "SelectableChannel", "ch", ",", "int", "op", ",", "boolean", "releaseNotify", ",", "NIOHandler", "handler", ")", "{", "INSTANCE", ".", "_removeInterest", "(", "ch", ",", "op", ",", "releaseNotify", ",", "handler", ")", ";", "}", "void", "_removeInterest", "(", "SelectableChannel", "ch", ",", "int", "op", ",", "boolean", "releaseNotify", ",", "NIOHandler", "handler", ")", "{", "SelectMsg", "msg", "=", "new", "SelectMsg", "(", ")", ";", "msg", ".", "set", "=", "SetOrClear", ".", "CLEAR", ";", "msg", ".", "interest", "=", "new", "NIOChannelInfo", ".", "Interest", "(", "ch", ",", "handler", ",", "op", ",", "releaseNotify", ")", ";", "try", "{", "mbox", ".", "put", "(", "msg", ")", ";", "}", "catch", "(", "InterruptedException", "e", ")", "{", "e", ".", "printStackTrace", "(", ")", ";", "}", "selector", ".", "wakeup", "(", ")", ";", "}", "}", "</s>" ]
7,735
[ "<s>", "package", "erjang", ".", "driver", ".", "zlib", ";", "import", "java", ".", "util", ".", "concurrent", ".", "locks", ".", "ReentrantLock", ";", "import", "erjang", ".", "EString", ";", "import", "erjang", ".", "driver", ".", "EDriver", ";", "import", "erjang", ".", "driver", ".", "EDriverControl", ";", "public", "class", "Driver", "implements", "EDriver", "{", "@", "Override", "public", "String", "driverName", "(", ")", "{", "return", "\"zlib_drv\"", ";", "}", "@", "Override", "public", "boolean", "useDriverLevelLocking", "(", ")", "{", "return", "false", ";", "}", "@", "Override", "public", "void", "finish", "(", ")", "{", "}", "@", "Override", "public", "ReentrantLock", "getLock", "(", ")", "{", "throw", "new", "erjang", ".", "NotImplemented", "(", ")", ";", "}", "@", "Override", "public", "EDriverControl", "start", "(", "EString", "command", ")", "{", "return", "new", "ZLibDriver", "(", "this", ",", "command", ")", ";", "}", "}", "</s>" ]
7,736
[ "<s>", "package", "erjang", ".", "driver", ".", "zlib", ";", "import", "java", ".", "io", ".", "IOException", ";", "import", "java", ".", "net", ".", "Inet4Address", ";", "import", "java", ".", "net", ".", "Inet6Address", ";", "import", "java", ".", "net", ".", "InetAddress", ";", "import", "java", ".", "net", ".", "UnknownHostException", ";", "import", "java", ".", "nio", ".", "ByteBuffer", ";", "import", "java", ".", "nio", ".", "channels", ".", "SelectableChannel", ";", "import", "java", ".", "util", ".", "ArrayList", ";", "import", "com", ".", "jcraft", ".", "jzlib", ".", "ZStream", ";", "import", "com", ".", "jcraft", ".", "jzlib", ".", "ZStreamException", ";", "import", "kilim", ".", "Pausable", ";", "import", "kilim", ".", "Task", ";", "import", "erjang", ".", "EBinary", ";", "import", "erjang", ".", "EHandle", ";", "import", "erjang", ".", "EPID", ";", "import", "erjang", ".", "EString", ";", "import", "erjang", ".", "NotImplemented", ";", "import", "erjang", ".", "driver", ".", "EAsync", ";", "import", "erjang", ".", "driver", ".", "EDriver", ";", "import", "erjang", ".", "driver", ".", "EDriverInstance", ";", "import", "erjang", ".", "driver", ".", "IO", ";", "public", "class", "ZLibDriver", "extends", "EDriverInstance", "{", "public", "static", "final", "int", "Z_NO_FLUSH", "=", "0", ";", "public", "static", "final", "int", "Z_SYNC_FLUSH", "=", "2", ";", "public", "static", "final", "int", "Z_FULL_FLUSH", "=", "3", ";", "public", "static", "final", "int", "Z_FINISH", "=", "4", ";", "public", "static", "final", "int", "Z_NO_COMPRESSION", "=", "0", ";", "public", "static", "final", "int", "Z_BEST_SPEED", "=", "1", ";", "public", "static", "final", "int", "Z_BEST_COMPRESSION", "=", "9", ";", "public", "static", "final", "int", "Z_DEFAULT_COMPRESSION", "=", "(", "-", "1", ")", ";", "public", "static", "final", "int", "Z_FILTERED", "=", "1", ";", "public", "static", "final", "int", "Z_HUFFMAN_ONLY", "=", "2", ";", "public", "static", "final", "int", "Z_DEFAULT_STRATEGY", "=", "0", ";", "public", "static", "final", "int", "Z_DEFLATED", "=", "8", ";", "public", "static", "final", "int", "Z_NULL", "=", "0", ";", "public", "static", "final", "int", "MAX_WBITS", "=", "15", ";", "public", "static", "final", "int", "ID1", "=", "0x1f", ";", "public", "static", "final", "int", "ID2", "=", "0x8b", ";", "public", "static", "final", "int", "FTEXT", "=", "0x01", ";", "public", "static", "final", "int", "FHCRC", "=", "0x02", ";", "public", "static", "final", "int", "FEXTRA", "=", "0x04", ";", "public", "static", "final", "int", "FNAME", "=", "0x08", ";", "public", "static", "final", "int", "FCOMMENT", "=", "0x10", ";", "public", "static", "final", "int", "RESERVED", "=", "0xE0", ";", "public", "static", "final", "int", "OS_MDDOS", "=", "0", ";", "public", "static", "final", "int", "OS_AMIGA", "=", "1", ";", "public", "static", "final", "int", "OS_OPENVMS", "=", "2", ";", "public", "static", "final", "int", "OS_UNIX", "=", "3", ";", "public", "static", "final", "int", "OS_VMCMS", "=", "4", ";", "public", "static", "final", "int", "OS_ATARI", "=", "5", ";", "public", "static", "final", "int", "OS_OS2", "=", "6", ";", "public", "static", "final", "int", "OS_MAC", "=", "7", ";", "public", "static", "final", "int", "OS_ZSYS", "=", "8", ";", "public", "static", "final", "int", "OS_CPM", "=", "9", ";", "public", "static", "final", "int", "OS_TOP20", "=", "10", ";", "public", "static", "final", "int", "OS_NTFS", "=", "11", ";", "public", "static", "final", "int", "OS_QDOS", "=", "12", ";", "public", "static", "final", "int", "OS_ACORN", "=", "13", ";", "public", "static", "final", "int", "OS_UNKNOWN", "=", "255", ";", "public", "static", "final", "int", "DEFLATE_INIT", "=", "1", ";", "public", "static", "final", "int", "DEFLATE_INIT2", "=", "2", ";", "public", "static", "final", "int", "DEFLATE_SETDICT", "=", "3", ";", "public", "static", "final", "int", "DEFLATE_RESET", "=", "4", ";", "public", "static", "final", "int", "DEFLATE_END", "=", "5", ";", "public", "static", "final", "int", "DEFLATE_PARAMS", "=", "6", ";", "public", "static", "final", "int", "DEFLATE", "=", "7", ";", "public", "static", "final", "int", "INFLATE_INIT", "=", "8", ";", "public", "static", "final", "int", "INFLATE_INIT2", "=", "9", ";", "public", "static", "final", "int", "INFLATE_SETDICT", "=", "10", ";", "public", "static", "final", "int", "INFLATE_SYNC", "=", "11", ";", "public", "static", "final", "int", "INFLATE_RESET", "=", "12", ";", "public", "static", "final", "int", "INFLATE_END", "=", "13", ";", "public", "static", "final", "int", "INFLATE", "=", "14", ";", "public", "static", "final", "int", "CRC32_0", "=", "15", ";", "public", "static", "final", "int", "CRC32_1", "=", "16", ";", "public", "static", "final", "int", "CRC32_2", "=", "17", ";", "public", "static", "final", "int", "SET_BUFSZ", "=", "18", ";", "public", "static", "final", "int", "GET_BUFSZ", "=", "19", ";", "public", "static", "final", "int", "GET_QSIZE", "=", "20", ";", "public", "static", "final", "int", "ADLER32_1", "=", "21", ";", "public", "static", "final", "int", "ADLER32_2", "=", "22", ";", "public", "static", "final", "int", "CRC32_COMBINE", "=", "23", ";", "public", "static", "final", "int", "ADLER32_COMBINE", "=", "24", ";", "private", "ZStream", "inf", ";", "public", "ZLibDriver", "(", "EDriver", "driver", ",", "EString", "command", ")", "{", "super", "(", "driver", ")", ";", "}", "ArrayList", "<", "ByteBuffer", ">", "inbuf", "=", "new", "ArrayList", "<", "ByteBuffer", ">", "(", ")", ";", "@", "Override", "protected", "void", "output", "(", "EHandle", "caller", ",", "ByteBuffer", "buf", ")", "throws", "IOException", ",", "Pausable", "{", "inbuf", ".", "add", "(", "buf", ")", ";", "}", "@", "Override", "protected", "void", "outputv", "(", "EHandle", "caller", ",", "ByteBuffer", "[", "]", "buf", ")", "throws", "IOException", ",", "Pausable", "{", "for", "(", "int", "i", "=", "0", ";", "i", "<", "buf", ".", "length", ";", "i", "++", ")", "{", "inbuf", ".", "add", "(", "buf", "[", "i", "]", ")", ";", "}", "}", "void", "do_inflate", "(", "int", "flush_mode", ")", "throws", "Pausable", "{", "int", "err", "=", "ZStream", ".", "Z_OK", ";", "read_loop", ":", "for", "(", "int", "i", "=", "0", ";", "err", "==", "ZStream", ".", "Z_OK", "&&", "i", "<", "inbuf", ".", "size", "(", ")", ";", "i", "++", ")", "{", "ByteBuffer", "bb", "=", "inbuf", ".", "get", "(", "i", ")", ";", "inf", ".", "next_in", "=", "bb", ".", "array", "(", ")", ";", "inf", ".", "next_in_index", "=", "bb", ".", "arrayOffset", "(", ")", "+", "bb", ".", "position", "(", ")", ";", "inf", ".", "avail_in", "=", "bb", ".", "limit", "(", ")", ";", "int", "in_size", "=", "bb", ".", "remaining", "(", ")", ";", "do", "{", "ByteBuffer", "out", "=", "ByteBuffer", ".", "allocate", "(", "1024", ")", ";", "long", "read_before", "=", "inf", ".", "total_in", ";", "long", "wrote_before", "=", "inf", ".", "total_out", ";", "inf", ".", "next_out", "=", "out", ".", "array", "(", ")", ";", "inf", ".", "next_out_index", "=", "out", ".", "arrayOffset", "(", ")", "+", "out", ".", "position", "(", ")", ";", "inf", ".", "avail_out", "=", "out", ".", "capacity", "(", ")", ";", "err", "=", "inf", ".", "inflate", "(", "flush_mode", ")", ";", "if", "(", "err", "==", "ZStream", ".", "Z_OK", "||", "err", "==", "ZStream", ".", "Z_STREAM_END", ")", "{", "long", "read_after", "=", "inf", ".", "total_in", ";", "long", "wrote_after", "=", "inf", ".", "total_out", ";", "in_size", "-=", "(", "read_after", "-", "read_before", ")", ";", "int", "written", "=", "(", "int", ")", "(", "wrote_after", "-", "wrote_before", ")", ";", "out", ".", "position", "(", "written", ")", ";", "driver_output", "(", "out", ")", ";", "}", "}", "while", "(", "err", "==", "ZStream", ".", "Z_OK", "&&", "in_size", ">", "0", ")", ";", "}", "inbuf", ".", "clear", "(", ")", ";", "if", "(", "flush_mode", "==", "Z_FINISH", ")", "{", "inf", ".", "free", "(", ")", ";", "}", "}", "void", "do_deflate", "(", "int", "flush_mode", ")", "throws", "Pausable", "{", "int", "err", "=", "ZStream", ".", "Z_OK", ";", "read_loop", ":", "for", "(", "int", "i", "=", "0", ";", "err", "==", "ZStream", ".", "Z_OK", "&&", "i", "<", "inbuf", ".", "size", "(", ")", ";", "i", "++", ")", "{", "ByteBuffer", "bb", "=", "inbuf", ".", "get", "(", "i", ")", ";", "inf", ".", "next_in", "=", "bb", ".", "array", "(", ")", ";", "inf", ".", "next_in_index", "=", "bb", ".", "arrayOffset", "(", ")", "+", "bb", ".", "position", "(", ")", ";", "inf", ".", "avail_in", "=", "bb", ".", "limit", "(", ")", ";", "int", "in_size", "=", "bb", ".", "remaining", "(", ")", ";", "do", "{", "ByteBuffer", "out", "=", "ByteBuffer", ".", "allocate", "(", "1024", ")", ";", "long", "read_before", "=", "inf", ".", "total_in", ";", "long", "wrote_before", "=", "inf", ".", "total_out", ";", "inf", ".", "next_out", "=", "out", ".", "array", "(", ")", ";", "inf", ".", "next_out_index", "=", "out", ".", "arrayOffset", "(", ")", "+", "out", ".", "position", "(", ")", ";", "inf", ".", "avail_out", "=", "out", ".", "capacity", "(", ")", ";", "err", "=", "inf", ".", "deflate", "(", "flush_mode", ")", ";", "if", "(", "err", "==", "ZStream", ".", "Z_OK", "||", "err", "==", "ZStream", ".", "Z_STREAM_END", ")", "{", "long", "read_after", "=", "inf", ".", "total_in", ";", "long", "wrote_after", "=", "inf", ".", "total_out", ";", "in_size", "-=", "(", "read_after", "-", "read_before", ")", ";", "int", "written", "=", "(", "int", ")", "(", "wrote_after", "-", "wrote_before", ")", ";", "out", ".", "position", "(", "written", ")", ";", "driver_output", "(", "out", ")", ";", "}", "}", "while", "(", "err", "==", "ZStream", ".", "Z_OK", "&&", "in_size", ">", "0", ")", ";", "}", "inbuf", ".", "clear", "(", ")", ";", "if", "(", "flush_mode", "==", "Z_FINISH", ")", "{", "inf", ".", "free", "(", ")", ";", "}", "}", "@", "Override", "protected", "ByteBuffer", "control", "(", "EPID", "caller", ",", "int", "command", ",", "ByteBuffer", "cmd", ")", "throws", "Pausable", "{", "switch", "(", "command", ")", "{", "case", "INFLATE_INIT", ":", "{", "this", ".", "inf", "=", "new", "ZStream", "(", ")", ";", "this", ".", "inf", ".", "inflateInit", "(", "true", ")", ";", "return", "reply_ok", "(", ")", ";", "}", "case", "INFLATE_INIT2", ":", "{", "int", "ws", "=", "cmd", ".", "getInt", "(", ")", ";", "this", ".", "inf", "=", "new", "ZStream", "(", ")", ";", "this", ".", "inf", ".", "inflateInit", "(", "ws", ")", ";", "return", "reply_ok", "(", ")", ";", "}", "case", "DEFLATE_INIT2", ":", "{", "int", "level", "=", "cmd", ".", "getInt", "(", ")", ";", "int", "method", "=", "cmd", ".", "getInt", "(", ")", ";", "int", "bits", "=", "cmd", ".", "getInt", "(", ")", ";", "int", "memLevel", "=", "cmd", ".", "getInt", "(", ")", ";", "int", "strategy", "=", "cmd", ".", "getInt", "(", ")", ";", "this", ".", "inf", "=", "new", "ZStream", "(", ")", ";", "this", ".", "inf", ".", "deflateInit", "(", "level", ",", "method", ",", "bits", ",", "memLevel", ",", "strategy", ")", ";", "return", "reply_ok", "(", ")", ";", "}", "case", "INFLATE", ":", "{", "int", "flush_mode", "=", "cmd", ".", "getInt", "(", ")", ";", "do_inflate", "(", "flush_mode", ")", ";", "return", "reply_ok", "(", ")", ";", "}", "case", "INFLATE_END", ":", "{", "do_inflate", "(", "Z_FINISH", ")", ";", "return", "reply_ok", "(", ")", ";", "}", "case", "DEFLATE", ":", "{", "int", "flush_mode", "=", "cmd", ".", "getInt", "(", ")", ";", "do_deflate", "(", "flush_mode", ")", ";", "return", "reply_ok", "(", ")", ";", "}", "case", "DEFLATE_END", ":", "{", "do_deflate", "(", "Z_FINISH", ")", ";", "return", "reply_ok", "(", ")", ";", "}", "}", "throw", "new", "erjang", ".", "NotImplemented", "(", "\"command=\"", "+", "command", "+", "\";", "data=\"", "+", "EBinary", ".", "make", "(", "cmd", ")", ")", ";", "}", "private", "ByteBuffer", "reply_ok", "(", ")", "{", "ByteBuffer", "ok", "=", "ByteBuffer", ".", "allocate", "(", "3", ")", ";", "ok", ".", "put", "(", "(", "byte", ")", "0", ")", ";", "ok", ".", "put", "(", "(", "byte", ")", "'o'", ")", ";", "ok", ".", "put", "(", "(", "byte", ")", "'k'", ")", ";", "return", "ok", ";", "}", "@", "Override", "protected", "void", "readyAsync", "(", "EAsync", "data", ")", "throws", "Pausable", "{", "data", ".", "ready", "(", ")", ";", "}", "}", "</s>" ]
7,737
[ "<s>", "package", "erjang", ".", "driver", ";", "import", "java", ".", "io", ".", "ByteArrayOutputStream", ";", "import", "java", ".", "io", ".", "IOException", ";", "import", "java", ".", "io", ".", "InputStream", ";", "import", "java", ".", "io", ".", "OutputStream", ";", "import", "java", ".", "net", ".", "BindException", ";", "import", "java", ".", "net", ".", "ConnectException", ";", "import", "java", ".", "nio", ".", "ByteBuffer", ";", "import", "java", ".", "nio", ".", "channels", ".", "GatheringByteChannel", ";", "import", "java", ".", "nio", ".", "channels", ".", "WritableByteChannel", ";", "import", "java", ".", "nio", ".", "charset", ".", "Charset", ";", "import", "java", ".", "util", ".", "logging", ".", "Level", ";", "import", "java", ".", "util", ".", "zip", ".", "GZIPOutputStream", ";", "import", "erjang", ".", "EBinary", ";", "import", "erjang", ".", "ERT", ";", "import", "erjang", ".", "driver", ".", "efile", ".", "Posix", ";", "public", "class", "IO", "{", "public", "static", "final", "Charset", "ISO_LATIN_1", "=", "Charset", ".", "forName", "(", "\"ISO-8859-1\"", ")", ";", "public", "static", "final", "Charset", "UTF8", "=", "Charset", ".", "forName", "(", "\"UTF8\"", ")", ";", "static", "private", "class", "BARR", "extends", "ByteArrayOutputStream", "{", "ByteBuffer", "wrap", "(", ")", "{", "return", "ByteBuffer", ".", "wrap", "(", "super", ".", "buf", ",", "0", ",", "super", ".", "count", ")", ";", "}", "}", "public", "static", "void", "write", "(", "OutputStream", "out", ",", "ByteBuffer", "src", ")", "throws", "IOException", "{", "out", ".", "write", "(", "src", ".", "array", "(", ")", ",", "src", ".", "arrayOffset", "(", ")", "+", "src", ".", "position", "(", ")", ",", "src", ".", "remaining", "(", ")", ")", ";", "src", ".", "position", "(", "src", ".", "limit", "(", ")", ")", ";", "}", "public", "static", "long", "gzwrite", "(", "WritableByteChannel", "fd", ",", "ByteBuffer", "src", ")", "throws", "IOException", "{", "long", "result", "=", "src", ".", "remaining", "(", ")", ";", "BARR", "barr", "=", "new", "BARR", "(", ")", ";", "GZIPOutputStream", "go", "=", "new", "GZIPOutputStream", "(", "barr", ")", ";", "IO", ".", "write", "(", "go", ",", "src", ")", ";", "go", ".", "close", "(", ")", ";", "src", "=", "barr", ".", "wrap", "(", ")", ";", "writeFully", "(", "fd", ",", "src", ")", ";", "if", "(", "src", ".", "hasRemaining", "(", ")", ")", "{", "throw", "new", "Error", "(", "\"\"", ")", ";", "}", "return", "result", ";", "}", "public", "static", "long", "writeFully", "(", "WritableByteChannel", "fd", ",", "ByteBuffer", "src", ")", "throws", "IOException", "{", "long", "written", "=", "0", ";", "written", "+=", "fd", ".", "write", "(", "src", ")", ";", "if", "(", "src", ".", "hasRemaining", "(", ")", ")", "{", "while", "(", "src", ".", "hasRemaining", "(", ")", ")", "{", "Thread", ".", "yield", "(", ")", ";", "written", "+=", "fd", ".", "write", "(", "src", ")", ";", "}", "}", "return", "written", ";", "}", "public", "static", "int", "exception_to_posix_code", "(", "IOException", "e", ")", "{", "if", "(", "e", "instanceof", "java", ".", "nio", ".", "channels", ".", "ClosedChannelException", ")", "{", "return", "Posix", ".", "ENOTCONN", ";", "}", "if", "(", "\"Broken", "pipe\"", ".", "equals", "(", "e", ".", "getMessage", "(", ")", ")", "||", "\"\"", ".", "equals", "(", "e", ".", "getMessage", "(", ")", ")", ")", "{", "return", "Posix", ".", "ENOTCONN", ";", "}", "if", "(", "e", "instanceof", "ConnectException", ")", "{", "if", "(", "\"\"", ".", "equals", "(", "e", ".", "getMessage", "(", ")", ")", ")", "{", "return", "Posix", ".", "ECONNREFUSED", ";", "}", "}", "if", "(", "e", "instanceof", "BindException", ")", "{", "if", "(", "\"\"", ".", "equals", "(", "e", ".", "getMessage", "(", ")", ")", ")", "{", "return", "Posix", ".", "EADDRNOTAVAIL", ";", "}", "}", "if", "(", "e", "instanceof", "java", ".", "net", ".", "SocketException", ")", "{", "if", "(", "\"\"", ".", "equals", "(", "e", ".", "getMessage", "(", ")", ")", ")", "{", "return", "Posix", ".", "ENETUNREACH", ";", "}", "}", "ERT", ".", "log", ".", "warning", "(", "\"\"", "+", "e", ".", "getMessage", "(", ")", ")", ";", "ERT", ".", "log", ".", "log", "(", "Level", ".", "FINE", ",", "\"details:", "\"", ",", "e", ")", ";", "return", "Posix", ".", "EUNKNOWN", ";", "}", "public", "static", "long", "writev", "(", "GatheringByteChannel", "fd", ",", "ByteBuffer", "[", "]", "iov", ")", "throws", "IOException", "{", "int", "cnt", "=", "0", ";", "long", "written", "=", "0", ";", "while", "(", "cnt", "<", "iov", ".", "length", ")", "{", "int", "b", "=", "iov", ".", "length", "-", "cnt", ";", "if", "(", "iov", "[", "cnt", "]", ".", "hasRemaining", "(", ")", ")", "{", "if", "(", "b", "==", "1", ")", "{", "written", "+=", "fd", ".", "write", "(", "iov", "[", "cnt", "]", ")", ";", "}", "else", "{", "written", "+=", "fd", ".", "write", "(", "iov", ",", "cnt", ",", "b", ")", ";", "}", "}", "else", "{", "cnt", "++", ";", "}", "}", "return", "written", ";", "}", "public", "static", "String", "strcpy", "(", "ByteBuffer", "data", ")", "{", "int", "end_pos", ";", "for", "(", "end_pos", "=", "data", ".", "position", "(", ")", ";", "end_pos", "<", "data", ".", "limit", "(", ")", ";", "end_pos", "++", ")", "{", "if", "(", "data", ".", "get", "(", "end_pos", ")", "==", "0", ")", "{", "byte", "[", "]", "bb", "=", "data", ".", "array", "(", ")", ";", "int", "arr_off", "=", "data", ".", "arrayOffset", "(", ")", "+", "data", ".", "position", "(", ")", ";", "int", "len", "=", "end_pos", "-", "data", ".", "position", "(", ")", ";", "String", "result", "=", "new", "String", "(", "bb", ",", "arr_off", ",", "len", ",", "ISO_LATIN_1", ")", ";", "data", ".", "position", "(", "end_pos", "+", "1", ")", ";", "return", "result", ";", "}", "}", "throw", "ERT", ".", "badarg", "(", ")", ";", "}", "public", "static", "void", "putstr", "(", "ByteBuffer", "buf", ",", "String", "err", ",", "boolean", "term", ")", "{", "for", "(", "int", "i", "=", "0", ";", "i", "<", "err", ".", "length", "(", ")", ";", "i", "++", ")", "{", "buf", ".", "put", "(", "(", "byte", ")", "err", ".", "charAt", "(", "i", ")", ")", ";", "}", "if", "(", "term", ")", "{", "buf", ".", "put", "(", "(", "byte", ")", "0", ")", ";", "}", "}", "public", "static", "String", "getstr", "(", "ByteBuffer", "buf", ",", "boolean", "term", ")", "{", "if", "(", "term", ")", "{", "StringBuilder", "sb", "=", "new", "StringBuilder", "(", ")", ";", "byte", "b", ";", "while", "(", "(", "b", "=", "buf", ".", "get", "(", ")", ")", "!=", "0", ")", "{", "sb", ".", "append", "(", "(", "char", ")", "(", "0xff", "&", "b", ")", ")", ";", "}", "return", "sb", ".", "toString", "(", ")", ";", "}", "else", "{", "String", "str", "=", "new", "String", "(", "buf", ".", "array", "(", ")", ",", "buf", ".", "arrayOffset", "(", ")", "+", "buf", ".", "position", "(", ")", ",", "buf", ".", "remaining", "(", ")", ",", "ISO_LATIN_1", ")", ";", "buf", ".", "position", "(", "buf", ".", "limit", "(", ")", ")", ";", "return", "str", ";", "}", "}", "static", "private", "class", "BARR2", "extends", "ByteArrayOutputStream", "{", "EBinary", "asBinary", "(", ")", "{", "return", "new", "EBinary", "(", "super", ".", "buf", ",", "0", ",", "super", ".", "count", ")", ";", "}", "}", "public", "static", "EBinary", "istream2binary", "(", "InputStream", "in", ")", "throws", "IOException", "{", "BARR2", "out", "=", "new", "BARR2", "(", ")", ";", "byte", "[", "]", "buf", "=", "new", "byte", "[", "4", "*", "1024", "]", ";", "int", "read", ";", "while", "(", "(", "read", "=", "in", ".", "read", "(", "buf", ")", ")", ">", "0", ")", "{", "out", ".", "write", "(", "buf", ",", "0", ",", "read", ")", ";", "}", "return", "out", ".", "asBinary", "(", ")", ";", "}", "public", "static", "byte", "[", "]", "istream2bytearray", "(", "InputStream", "in", ")", "throws", "IOException", "{", "BARR2", "out", "=", "new", "BARR2", "(", ")", ";", "byte", "[", "]", "buf", "=", "new", "byte", "[", "4", "*", "1024", "]", ";", "int", "read", ";", "while", "(", "(", "read", "=", "in", ".", "read", "(", "buf", ")", ")", ">", "0", ")", "{", "out", ".", "write", "(", "buf", ",", "0", ",", "read", ")", ";", "}", "return", "out", ".", "toByteArray", "(", ")", ";", "}", "}", "</s>" ]
7,738
[ "<s>", "package", "erjang", ".", "driver", ";", "import", "kilim", ".", "Pausable", ";", "public", "interface", "EAsync", "{", "void", "async", "(", ")", ";", "void", "ready", "(", ")", "throws", "Pausable", ";", "}", "</s>" ]
7,739
[ "<s>", "package", "erjang", ".", "driver", ".", "ram_file", ";", "import", "java", ".", "util", ".", "concurrent", ".", "locks", ".", "ReentrantLock", ";", "import", "kilim", ".", "Lock", ";", "import", "erjang", ".", "EString", ";", "import", "erjang", ".", "driver", ".", "EDriver", ";", "import", "erjang", ".", "driver", ".", "EDriverControl", ";", "public", "class", "Driver", "implements", "EDriver", "{", "private", "kilim", ".", "ReentrantLock", "lock", ";", "@", "Override", "public", "String", "driverName", "(", ")", "{", "return", "\"ram_file_drv\"", ";", "}", "@", "Override", "public", "void", "finish", "(", ")", "{", "}", "@", "Override", "public", "EDriverControl", "start", "(", "EString", "command", ")", "{", "return", "new", "RamFile", "(", "command", ",", "this", ")", ";", "}", "@", "Override", "public", "boolean", "useDriverLevelLocking", "(", ")", "{", "return", "false", ";", "}", "@", "Override", "public", "ReentrantLock", "getLock", "(", ")", "{", "if", "(", "this", ".", "lock", "==", "null", ")", "{", "this", ".", "lock", "=", "new", "kilim", ".", "ReentrantLock", "(", ")", ";", "}", "return", "this", ".", "lock", ";", "}", "}", "</s>" ]
7,740
[ "<s>", "package", "erjang", ".", "driver", ".", "ram_file", ";", "import", "erjang", ".", "EHandle", ";", "import", "erjang", ".", "EObject", ";", "import", "erjang", ".", "EPID", ";", "import", "erjang", ".", "EString", ";", "import", "erjang", ".", "EBinary", ";", "import", "erjang", ".", "ERef", ";", "import", "erjang", ".", "NotImplemented", ";", "import", "erjang", ".", "driver", ".", "EDriverInstance", ";", "import", "erjang", ".", "driver", ".", "EAsync", ";", "import", "erjang", ".", "driver", ".", "IO", ";", "import", "erjang", ".", "driver", ".", "efile", ".", "Posix", ";", "import", "java", ".", "io", ".", "IOException", ";", "import", "java", ".", "io", ".", "ByteArrayOutputStream", ";", "import", "java", ".", "util", ".", "logging", ".", "Level", ";", "import", "java", ".", "util", ".", "zip", ".", "Inflater", ";", "import", "java", ".", "nio", ".", "ByteBuffer", ";", "import", "java", ".", "nio", ".", "channels", ".", "SelectableChannel", ";", "import", "kilim", ".", "Pausable", ";", "import", "static", "java", ".", "util", ".", "zip", ".", "GZIPInputStream", ".", "GZIP_MAGIC", ";", "import", "static", "erjang", ".", "driver", ".", "efile", ".", "EFile", ".", "FILE_OPEN", ";", "import", "static", "erjang", ".", "driver", ".", "efile", ".", "EFile", ".", "FILE_READ", ";", "import", "static", "erjang", ".", "driver", ".", "efile", ".", "EFile", ".", "FILE_LSEEK", ";", "import", "static", "erjang", ".", "driver", ".", "efile", ".", "EFile", ".", "FILE_WRITE", ";", "import", "static", "erjang", ".", "driver", ".", "efile", ".", "EFile", ".", "FILE_FSYNC", ";", "import", "static", "erjang", ".", "driver", ".", "efile", ".", "EFile", ".", "FILE_TRUNCATE", ";", "import", "static", "erjang", ".", "driver", ".", "efile", ".", "EFile", ".", "FILE_RESP_OK", ";", "import", "static", "erjang", ".", "driver", ".", "efile", ".", "EFile", ".", "FILE_RESP_ERROR", ";", "import", "static", "erjang", ".", "driver", ".", "efile", ".", "EFile", ".", "FILE_RESP_DATA", ";", "import", "static", "erjang", ".", "driver", ".", "efile", ".", "EFile", ".", "FILE_RESP_NUMBER", ";", "import", "static", "erjang", ".", "driver", ".", "efile", ".", "EFile", ".", "FILE_RESP_INFO", ";", "import", "static", "erjang", ".", "driver", ".", "efile", ".", "EFile", ".", "EFILE_MODE_READ", ";", "import", "static", "erjang", ".", "driver", ".", "efile", ".", "EFile", ".", "EFILE_MODE_WRITE", ";", "import", "static", "erjang", ".", "driver", ".", "efile", ".", "EFile", ".", "EFILE_MODE_READ_WRITE", ";", "public", "class", "RamFile", "extends", "EDriverInstance", "{", "public", "static", "final", "int", "FILE_PREAD", "=", "17", ";", "public", "static", "final", "int", "FILE_PWRITE", "=", "18", ";", "public", "static", "final", "int", "RAM_FILE_FDATASYNC", "=", "19", ";", "public", "static", "final", "int", "RAM_FILE_GET", "=", "30", ";", "public", "static", "final", "int", "RAM_FILE_SET", "=", "31", ";", "public", "static", "final", "int", "RAM_FILE_GET_CLOSE", "=", "32", ";", "public", "static", "final", "int", "RAM_FILE_COMPRESS", "=", "33", ";", "public", "static", "final", "int", "RAM_FILE_UNCOMPRESS", "=", "34", ";", "public", "static", "final", "int", "RAM_FILE_UUENCODE", "=", "35", ";", "public", "static", "final", "int", "RAM_FILE_UUDECODE", "=", "36", ";", "public", "static", "final", "int", "RAM_FILE_SIZE", "=", "37", ";", "public", "static", "final", "int", "RAM_FILE_ADVISE", "=", "38", ";", "private", "static", "final", "byte", "[", "]", "FILE_RESP_NUMBER_HEADER", "=", "new", "byte", "[", "]", "{", "FILE_RESP_NUMBER", "}", ";", "private", "ByteBuffer", "contents", ";", "private", "int", "flags", ";", "RamFile", "(", "EString", "command", ",", "Driver", "driver", ")", "{", "super", "(", "driver", ")", ";", "}", "@", "Override", "protected", "void", "outputv", "(", "EHandle", "caller", ",", "ByteBuffer", "[", "]", "ev", ")", "throws", "IOException", ",", "Pausable", "{", "if", "(", "ev", ".", "length", "==", "0", "||", "ev", "[", "0", "]", ".", "remaining", "(", ")", "==", "0", ")", "{", "reply_posix_error", "(", "Posix", ".", "EINVAL", ")", ";", "return", ";", "}", "byte", "command", "=", "ev", "[", "0", "]", ".", "get", "(", ")", ";", "switch", "(", "command", ")", "{", "default", ":", "ev", "[", "0", "]", ".", "position", "(", "ev", "[", "0", "]", ".", "position", "(", ")", "-", "1", ")", ";", "output", "(", "caller", ",", "flatten", "(", "ev", ")", ")", ";", "}", "}", "protected", "void", "output", "(", "EHandle", "caller", ",", "ByteBuffer", "data", ")", "throws", "IOException", ",", "Pausable", "{", "byte", "cmd", "=", "data", ".", "get", "(", ")", ";", "switch", "(", "cmd", ")", "{", "case", "FILE_OPEN", ":", "{", "if", "(", "data", ".", "remaining", "(", ")", "<", "4", ")", "{", "reply_posix_error", "(", "Posix", ".", "EINVAL", ")", ";", "return", ";", "}", "flags", "=", "data", ".", "getInt", "(", ")", ";", "try", "{", "contents", "=", "ByteBuffer", ".", "allocate", "(", "data", ".", "remaining", "(", ")", ")", ".", "put", "(", "data", ")", ";", "}", "catch", "(", "OutOfMemoryError", "e", ")", "{", "reply_posix_error", "(", "Posix", ".", "ENOMEM", ")", ";", "return", ";", "}", "reply_number", "(", "0", ")", ";", "}", "break", ";", "case", "RAM_FILE_UNCOMPRESS", ":", "{", "if", "(", "data", ".", "hasRemaining", "(", ")", ")", "{", "reply_posix_error", "(", "Posix", ".", "EINVAL", ")", ";", "return", ";", "}", "data", ".", "mark", "(", ")", ";", "boolean", "is_gzip", "=", "(", "data", ".", "remaining", "(", ")", ">=", "2", "&&", "data", ".", "getShort", "(", ")", "==", "GZIP_MAGIC", ")", ";", "data", ".", "reset", "(", ")", ";", "if", "(", "is_gzip", ")", "{", "final", "Inflater", "inflater", "=", "new", "Inflater", "(", "true", ")", ";", "inflater", ".", "setInput", "(", "contents", ".", "array", "(", ")", ",", "0", ",", "contents", ".", "limit", "(", ")", ")", ";", "byte", "[", "]", "buf", "=", "new", "byte", "[", "4096", "]", ";", "ByteArrayOutputStream", "baos", "=", "new", "ByteArrayOutputStream", "(", "contents", ".", "limit", "(", ")", ")", ";", "try", "{", "while", "(", "!", "inflater", ".", "finished", "(", ")", ")", "{", "int", "inflated", "=", "inflater", ".", "inflate", "(", "buf", ",", "0", ",", "buf", ".", "length", ")", ";", "baos", ".", "write", "(", "buf", ",", "0", ",", "inflated", ")", ";", "}", "}", "catch", "(", "Exception", "e", ")", "{", "log", ".", "severe", "(", "\"\"", "+", "e", ".", "getMessage", "(", ")", ")", ";", "log", ".", "log", "(", "Level", ".", "FINE", ",", "\"details:", "\"", ",", "e", ")", ";", "reply_posix_error", "(", "Posix", ".", "EINVAL", ")", ";", "return", ";", "}", "contents", "=", "ByteBuffer", ".", "wrap", "(", "baos", ".", "toByteArray", "(", ")", ")", ";", "}", "reply_number", "(", "contents", ".", "limit", "(", ")", ")", ";", "}", "break", ";", "case", "RAM_FILE_GET", ":", "{", "if", "(", "data", ".", "hasRemaining", "(", ")", ")", "{", "reply_posix_error", "(", "Posix", ".", "EINVAL", ")", ";", "return", ";", "}", "reply_buf", "(", "contents", ")", ";", "}", "break", ";", "default", ":", "throw", "new", "NotImplemented", "(", "\"\"", "+", "(", "(", "int", ")", "cmd", ")", "+", "\"", "\"", "+", "EBinary", ".", "make", "(", "data", ")", ")", ";", "}", "}", "public", "void", "reply_ok", "(", ")", "throws", "Pausable", "{", "ByteBuffer", "header", "=", "ByteBuffer", ".", "allocate", "(", "1", ")", ";", "header", ".", "put", "(", "FILE_RESP_OK", ")", ";", "driver_output2", "(", "header", ",", "null", ")", ";", "}", "public", "void", "reply_number", "(", "int", "val", ")", "throws", "Pausable", "{", "ByteBuffer", "reply", "=", "ByteBuffer", ".", "allocate", "(", "1", "+", "4", ")", ";", "reply", ".", "put", "(", "FILE_RESP_NUMBER", ")", ";", "reply", ".", "putInt", "(", "val", ")", ";", "driver_output2", "(", "reply", ",", "null", ")", ";", "}", "void", "reply_buf", "(", "ByteBuffer", "buf", ")", "throws", "Pausable", "{", "ByteBuffer", "header", "=", "ByteBuffer", ".", "allocate", "(", "1", "+", "4", ")", ";", "header", ".", "put", "(", "FILE_RESP_DATA", ")", ";", "header", ".", "putInt", "(", "buf", ".", "position", "(", ")", ")", ";", "driver_output2", "(", "header", ",", "buf", ")", ";", "}", "public", "void", "reply_Uint", "(", "int", "value", ")", "throws", "Pausable", "{", "ByteBuffer", "response", "=", "ByteBuffer", ".", "allocate", "(", "4", ")", ";", "response", ".", "putInt", "(", "value", ")", ";", "driver_output2", "(", "response", ",", "null", ")", ";", "}", "public", "void", "reply_posix_error", "(", "int", "posix_errno", ")", "throws", "Pausable", "{", "ByteBuffer", "response", "=", "ByteBuffer", ".", "allocate", "(", "256", ")", ";", "response", ".", "put", "(", "FILE_RESP_ERROR", ")", ";", "String", "err", "=", "Posix", ".", "errno_id", "(", "posix_errno", ")", ";", "IO", ".", "putstr", "(", "response", ",", "err", ",", "false", ")", ";", "driver_output2", "(", "response", ",", "null", ")", ";", "}", "@", "Override", "protected", "EObject", "call", "(", "EPID", "caller", ",", "int", "command", ",", "EObject", "data", ")", "throws", "Pausable", "{", "return", "null", ";", "}", "@", "Override", "protected", "void", "flush", "(", ")", "throws", "Pausable", "{", "}", "@", "Override", "public", "void", "processExit", "(", "ERef", "monitor", ")", "throws", "Pausable", "{", "}", "@", "Override", "protected", "void", "readyInput", "(", "SelectableChannel", "ch", ")", "throws", "Pausable", "{", "}", "@", "Override", "protected", "void", "readyOutput", "(", "SelectableChannel", "evt", ")", "throws", "Pausable", "{", "}", "@", "Override", "protected", "void", "timeout", "(", ")", "throws", "Pausable", "{", "}", "@", "Override", "protected", "void", "readyAsync", "(", "EAsync", "data", ")", "throws", "Pausable", "{", "}", "}", "</s>" ]
7,741
[ "<s>", "package", "erjang", ".", "driver", ";", "import", "java", ".", "io", ".", "IOException", ";", "import", "java", ".", "nio", ".", "channels", ".", "SelectableChannel", ";", "public", "interface", "NIOHandler", "{", "void", "exception", "(", "SelectableChannel", "ch", ",", "IOException", "e", ")", ";", "void", "ready", "(", "SelectableChannel", "ch", ",", "int", "readyOps", ")", ";", "void", "released", "(", "SelectableChannel", "ch", ")", ";", "}", "</s>" ]
7,742
[ "<s>", "package", "erjang", ".", "driver", ";", "import", "erjang", ".", "EObject", ";", "import", "erjang", ".", "EProc", ";", "import", "erjang", ".", "EString", ";", "public", "class", "ESpawnDriverTask", "extends", "EDriverTask", "{", "private", "final", "EString", "command", ";", "private", "final", "EObject", "portSetting", ";", "public", "EObject", "getName", "(", ")", "{", "return", "command", ";", "}", "public", "ESpawnDriverTask", "(", "EProc", "proc", ",", "EDriver", "driver", ",", "EString", "command", ",", "EObject", "portSetting", ")", "{", "super", "(", "proc", ".", "self_handle", "(", ")", ",", "driver", ".", "start", "(", "command", ")", ")", ";", "this", ".", "command", "=", "command", ";", "this", ".", "portSetting", "=", "portSetting", ";", "super", ".", "parseOptions", "(", "new", "String", "[", "]", "{", "command", ".", "stringValue", "(", ")", "}", ",", "portSetting", ")", ";", "}", "}", "</s>" ]
7,743
[ "<s>", "package", "erjang", ".", "driver", ";", "public", "enum", "SelectMode", "{", "SET", ",", "CLEAR", ";", "}", "</s>" ]
7,744
[ "<s>", "package", "erjang", ".", "driver", ";", "import", "java", ".", "io", ".", "IOException", ";", "import", "java", ".", "nio", ".", "ByteBuffer", ";", "import", "java", ".", "nio", ".", "channels", ".", "SelectableChannel", ";", "import", "kilim", ".", "Pausable", ";", "import", "erjang", ".", "EHandle", ";", "import", "erjang", ".", "EObject", ";", "import", "erjang", ".", "EPID", ";", "import", "erjang", ".", "ERef", ";", "public", "abstract", "class", "EDriverControl", "{", "abstract", "void", "setTask", "(", "EDriverTask", "task", ")", ";", "public", "void", "setup", "(", ")", "{", "}", "protected", "void", "stop", "(", "EObject", "reason", ")", "throws", "Pausable", "{", "}", "protected", "void", "timeout", "(", ")", "throws", "Pausable", "{", "}", "protected", "void", "outputv", "(", "EHandle", "caller", ",", "ByteBuffer", "[", "]", "bufv", ")", "throws", "IOException", ",", "Pausable", "{", "}", "protected", "ByteBuffer", "control", "(", "EPID", "pid", ",", "int", "op", ",", "ByteBuffer", "cmd2", ")", "throws", "Pausable", "{", "return", "null", ";", "}", "protected", "void", "readyInput", "(", "SelectableChannel", "ch", ")", "throws", "Pausable", "{", "}", "protected", "void", "readyOutput", "(", "SelectableChannel", "ch", ")", "throws", "Pausable", "{", "}", "public", "void", "readyConnect", "(", "SelectableChannel", "ch", ")", "throws", "Pausable", "{", "}", "public", "void", "readyAccept", "(", "SelectableChannel", "ch", ")", "throws", "Pausable", "{", "}", "protected", "void", "stopSelect", "(", "SelectableChannel", "ch", ")", "throws", "Pausable", "{", "}", "protected", "void", "readyAsync", "(", "EAsync", "job", ")", "throws", "Pausable", "{", "}", "protected", "EObject", "call", "(", "EPID", "caller", ",", "int", "op", ",", "EObject", "data", ")", "throws", "Pausable", "{", "return", "null", ";", "}", "public", "void", "processExit", "(", "ERef", "ref", ")", "throws", "Pausable", "{", "}", "public", "abstract", "EDriver", "getDriver", "(", ")", ";", "}", "</s>" ]
7,745
[ "<s>", "package", "erjang", ".", "driver", ";", "import", "kilim", ".", "Pausable", ";", "import", "erjang", ".", "EPseudoTerm", ";", "public", "abstract", "class", "EPortControl", "extends", "EPseudoTerm", "{", "public", "EPortControl", "testPortControl", "(", ")", "{", "return", "this", ";", "}", "@", "Override", "public", "int", "hashCode", "(", ")", "{", "return", "System", ".", "identityHashCode", "(", "this", ")", ";", "}", "public", "abstract", "void", "execute", "(", ")", "throws", "Exception", ",", "Pausable", ";", "}", "</s>" ]
7,746
[ "<s>", "package", "erjang", ".", "driver", ";", "import", "java", ".", "util", ".", "concurrent", ".", "locks", ".", "ReentrantLock", ";", "import", "erjang", ".", "EString", ";", "public", "class", "FDDriver", "implements", "EDriver", "{", "@", "Override", "public", "String", "driverName", "(", ")", "{", "throw", "new", "erjang", ".", "NotImplemented", "(", ")", ";", "}", "@", "Override", "public", "void", "finish", "(", ")", "{", "throw", "new", "erjang", ".", "NotImplemented", "(", ")", ";", "}", "@", "Override", "public", "EDriverControl", "start", "(", "EString", "command", ")", "{", "throw", "new", "erjang", ".", "NotImplemented", "(", ")", ";", "}", "@", "Override", "public", "boolean", "useDriverLevelLocking", "(", ")", "{", "return", "false", ";", "}", "@", "Override", "public", "ReentrantLock", "getLock", "(", ")", "{", "throw", "new", "erjang", ".", "NotImplemented", "(", ")", ";", "}", "}", "</s>" ]
7,747
[ "<s>", "package", "erjang", ".", "driver", ";", "import", "erjang", ".", "EObject", ";", "import", "erjang", ".", "EPort", ";", "import", "erjang", ".", "EProc", ";", "import", "erjang", ".", "ESmall", ";", "import", "erjang", ".", "EString", ";", "import", "erjang", ".", "ETask", ";", "public", "class", "EFDDriverTask", "extends", "EDriverTask", "{", "public", "EObject", "getName", "(", ")", "{", "return", "EString", ".", "fromString", "(", "\"fd\"", ")", ";", "}", "public", "EFDDriverTask", "(", "EProc", "owner", ",", "int", "in", ",", "int", "out", ",", "EObject", "portSetting", ")", "{", "super", "(", "owner", ".", "self_handle", "(", ")", ",", "new", "FDDriverInstance", "(", "in", ",", "out", ")", ")", ";", "super", ".", "parseOptions", "(", "new", "String", "[", "]", "{", "\"fd\"", "}", ",", "portSetting", ")", ";", "super", ".", "setupInstance", "(", ")", ";", "}", "}", "</s>" ]
7,748
[ "<s>", "package", "erjang", ".", "driver", ";", "import", "java", ".", "io", ".", "IOException", ";", "import", "java", ".", "io", ".", "InputStream", ";", "import", "java", ".", "io", ".", "OutputStream", ";", "import", "java", ".", "nio", ".", "ByteBuffer", ";", "import", "java", ".", "nio", ".", "ByteOrder", ";", "import", "java", ".", "nio", ".", "channels", ".", "SelectableChannel", ";", "import", "kilim", ".", "Pausable", ";", "import", "erjang", ".", "EBinary", ";", "import", "erjang", ".", "EHandle", ";", "import", "erjang", ".", "EObject", ";", "import", "erjang", ".", "EPID", ";", "import", "erjang", ".", "ERT", ";", "import", "erjang", ".", "ERef", ";", "import", "erjang", ".", "EString", ";", "import", "erjang", ".", "NotImplemented", ";", "public", "class", "FDDriverInstance", "extends", "EDriverInstance", "{", "public", "static", "final", "int", "CTRL_OP_GET_WINSIZE", "=", "100", ";", "private", "final", "int", "in", ";", "private", "final", "int", "out", ";", "InputStream", "ins", ";", "OutputStream", "outs", ";", "public", "FDDriverInstance", "(", "int", "in", ",", "int", "out", ")", "{", "super", "(", "new", "FDDriver", "(", ")", ")", ";", "this", ".", "in", "=", "in", ";", "this", ".", "out", "=", "out", ";", "if", "(", "in", "==", "0", ")", "{", "ins", "=", "ERT", ".", "getInputStream", "(", ")", ";", "}", "if", "(", "out", "==", "1", ")", "{", "outs", "=", "ERT", ".", "getOutputStream", "(", ")", ";", "}", "if", "(", "out", "==", "2", ")", "{", "outs", "=", "ERT", ".", "getErrorStream", "(", ")", ";", "}", "}", "@", "Override", "protected", "void", "readyAsync", "(", "EAsync", "data", ")", "throws", "Pausable", "{", "data", ".", "ready", "(", ")", ";", "}", "public", "void", "setup", "(", ")", "{", "if", "(", "ins", "!=", "null", ")", "{", "new", "Thread", "(", ")", "{", "{", "setDaemon", "(", "true", ")", ";", "start", "(", ")", ";", "setName", "(", "\"FD", "in=\"", "+", "in", ")", ";", "}", "void", "finish", "(", "final", "int", "howmany", ",", "final", "byte", "[", "]", "buffer", ")", "{", "final", "EDriverTask", "dt", "=", "FDDriverInstance", ".", "this", ".", "task", ";", "final", "byte", "[", "]", "ob", "=", "new", "byte", "[", "howmany", "]", ";", "System", ".", "arraycopy", "(", "buffer", ",", "0", ",", "ob", ",", "0", ",", "howmany", ")", ";", "ERT", ".", "run_async", "(", "new", "EAsync", "(", ")", "{", "@", "Override", "public", "void", "ready", "(", ")", "throws", "Pausable", "{", "if", "(", "task", ".", "send_binary_data", ")", "{", "EBinary", "out", "=", "new", "EBinary", "(", "ob", ")", ";", "task", ".", "output_from_driver", "(", "out", ")", ";", "}", "else", "{", "EString", "str", "=", "EString", ".", "make", "(", "ob", ")", ";", "task", ".", "output_from_driver", "(", "str", ")", ";", "}", "}", "@", "Override", "public", "void", "async", "(", ")", "{", "}", "}", ",", "dt", ")", ";", "}", "@", "Override", "public", "void", "run", "(", ")", "{", "byte", "[", "]", "buffer", "=", "new", "byte", "[", "1024", "]", ";", "while", "(", "true", ")", "{", "try", "{", "int", "howmany", ";", "howmany", "=", "ins", ".", "read", "(", "buffer", ")", ";", "if", "(", "howmany", "<", "0", ")", "{", "if", "(", "task", ".", "send_eof", ")", "{", "task", ".", "eof_from_driver_b", "(", ")", ";", "}", "return", ";", "}", "finish", "(", "howmany", ",", "buffer", ")", ";", "}", "catch", "(", "IOException", "e", ")", "{", "if", "(", "e", ".", "getMessage", "(", ")", ".", "equals", "(", "\"\"", ")", ")", "{", "}", "else", "{", "e", ".", "printStackTrace", "(", ")", ";", "}", "}", "}", "}", "}", ";", "}", "}", "@", "Override", "protected", "ByteBuffer", "control", "(", "EPID", "caller", ",", "int", "command", ",", "ByteBuffer", "out", ")", "throws", "Pausable", "{", "if", "(", "command", "==", "CTRL_OP_GET_WINSIZE", ")", "{", "ByteBuffer", "bb", "=", "ByteBuffer", ".", "allocate", "(", "8", ")", ";", "bb", ".", "order", "(", "ByteOrder", ".", "nativeOrder", "(", ")", ")", ";", "bb", ".", "putInt", "(", "80", ")", ";", "bb", ".", "putInt", "(", "25", ")", ";", "return", "bb", ";", "}", "else", "{", "throw", "ERT", ".", "badarg", "(", ")", ";", "}", "}", "@", "Override", "protected", "EObject", "call", "(", "EPID", "caller", ",", "int", "command", ",", "EObject", "data", ")", "throws", "Pausable", "{", "return", "null", ";", "}", "@", "Override", "protected", "void", "flush", "(", ")", "throws", "Pausable", "{", "}", "@", "Override", "protected", "void", "output", "(", "EHandle", "caller", ",", "ByteBuffer", "data", ")", "throws", "IOException", ",", "Pausable", "{", "if", "(", "outs", "!=", "null", ")", "{", "if", "(", "data", ".", "hasArray", "(", ")", ")", "{", "outs", ".", "write", "(", "data", ".", "array", "(", ")", ",", "data", ".", "arrayOffset", "(", ")", ",", "data", ".", "remaining", "(", ")", ")", ";", "}", "else", "{", "throw", "new", "NotImplemented", "(", ")", ";", "}", "}", "}", "@", "Override", "public", "void", "processExit", "(", "ERef", "monitor", ")", "throws", "Pausable", "{", "}", "@", "Override", "protected", "void", "readyInput", "(", "SelectableChannel", "ch", ")", "throws", "Pausable", "{", "}", "@", "Override", "protected", "void", "readyOutput", "(", "SelectableChannel", "evt", ")", "throws", "Pausable", "{", "}", "@", "Override", "protected", "void", "timeout", "(", ")", "throws", "Pausable", "{", "}", "}", "</s>" ]
7,749
[ "<s>", "package", "erjang", ".", "driver", ";", "import", "java", ".", "io", ".", "IOException", ";", "import", "java", ".", "nio", ".", "ByteBuffer", ";", "import", "java", ".", "nio", ".", "channels", ".", "SelectableChannel", ";", "import", "java", ".", "nio", ".", "channels", ".", "SelectionKey", ";", "import", "java", ".", "util", ".", "ArrayList", ";", "import", "java", ".", "util", ".", "concurrent", ".", "locks", ".", "Lock", ";", "import", "java", ".", "util", ".", "logging", ".", "Level", ";", "import", "java", ".", "util", ".", "logging", ".", "Logger", ";", "import", "kilim", ".", "Pausable", ";", "import", "kilim", ".", "ReentrantLock", ";", "import", "erjang", ".", "EAtom", ";", "import", "erjang", ".", "EBinList", ";", "import", "erjang", ".", "EBinary", ";", "import", "erjang", ".", "EHandle", ";", "import", "erjang", ".", "EInternalPort", ";", "import", "erjang", ".", "EObject", ";", "import", "erjang", ".", "EPID", ";", "import", "erjang", ".", "EPeer", ";", "import", "erjang", ".", "ERT", ";", "import", "erjang", ".", "ERef", ";", "import", "erjang", ".", "EString", ";", "import", "erjang", ".", "ETask", ";", "import", "erjang", ".", "ETuple", ";", "import", "erjang", ".", "ErlangException", ";", "import", "erjang", ".", "NotImplemented", ";", "import", "erjang", ".", "driver", ".", "efile", ".", "Posix", ";", "import", "erjang", ".", "m", ".", "erlang", ".", "ErlProc", ";", "public", "abstract", "class", "EDriverInstance", "extends", "EDriverControl", "{", "protected", "static", "Logger", "log", "=", "Logger", ".", "getLogger", "(", "\"\"", ")", ";", "EDriver", "driver", ";", "protected", "EDriverTask", "task", ";", "Lock", "pdl", ";", "public", "EDriverInstance", "(", "EDriver", "driver", ")", "{", "this", ".", "driver", "=", "driver", ";", "}", "public", "EDriver", "getDriver", "(", ")", "{", "return", "driver", ";", "}", "public", "EInternalPort", "port", "(", ")", "{", "return", "task", ".", "self_handle", "(", ")", ";", "}", "@", "Override", "void", "setTask", "(", "EDriverTask", "task", ")", "{", "this", ".", "task", "=", "task", ";", "}", "protected", "static", "final", "int", "ERL_DRV_READ", "=", "SelectionKey", ".", "OP_READ", ";", "protected", "static", "final", "int", "ERL_DRV_WRITE", "=", "SelectionKey", ".", "OP_WRITE", ";", "protected", "static", "final", "int", "ERL_DRV_ACCEPT", "=", "SelectionKey", ".", "OP_ACCEPT", ";", "protected", "static", "final", "int", "ERL_DRV_CONNECT", "=", "SelectionKey", ".", "OP_CONNECT", ";", "protected", "static", "final", "int", "ERL_DRV_USE", "=", "1", "<<", "5", ";", "static", "private", "final", "int", "ALL_OPS", "=", "ERL_DRV_READ", "|", "ERL_DRV_WRITE", "|", "ERL_DRV_ACCEPT", "|", "ERL_DRV_CONNECT", ";", "public", "void", "select", "(", "SelectableChannel", "ch", ",", "int", "mode", ",", "SelectMode", "onOff", ")", "{", "int", "selectOps", "=", "mode", "&", "ALL_OPS", ";", "if", "(", "onOff", "==", "SelectMode", ".", "SET", ")", "{", "NIOSelector", ".", "setInterest", "(", "ch", ",", "selectOps", ",", "task", ")", ";", "}", "else", "if", "(", "onOff", "==", "SelectMode", ".", "CLEAR", ")", "{", "boolean", "releaseNotify", "=", "(", "mode", "&", "ERL_DRV_USE", ")", "==", "ERL_DRV_USE", ";", "NIOSelector", ".", "clearInterest", "(", "ch", ",", "selectOps", ",", "releaseNotify", ",", "task", ")", ";", "}", "}", "protected", "void", "driver_exit", "(", "int", "i", ")", "{", "this", ".", "task", ".", "exit", "(", "i", "==", "0", "?", "ETask", ".", "am_normal", ":", "EAtom", ".", "intern", "(", "Posix", ".", "errno_id", "(", "i", ")", ")", ")", ";", "}", "protected", "void", "driver_async", "(", "EAsync", "job", ")", "{", "ERT", ".", "run_async", "(", "job", ",", "task", ")", ";", "}", "protected", "void", "driver_outputv", "(", "ByteBuffer", "hdr", ",", "ByteBuffer", "[", "]", "ev", ")", "throws", "Pausable", "{", "EObject", "resp", "=", "ERT", ".", "NIL", ";", "if", "(", "task", ".", "send_binary_data", ")", "{", "if", "(", "ev", ".", "length", ">", "0", ")", "{", "ev", "[", "ev", ".", "length", "-", "1", "]", ".", "flip", "(", ")", ";", "resp", "=", "EBinary", ".", "make", "(", "ev", "[", "ev", ".", "length", "-", "1", "]", ")", ";", "for", "(", "int", "i", "=", "ev", ".", "length", "-", "2", ";", "i", ">=", "0", ";", "i", "--", ")", "{", "ev", "[", "i", "]", ".", "flip", "(", ")", ";", "resp", "=", "resp", ".", "cons", "(", "EBinary", ".", "make", "(", "ev", "[", "i", "]", ")", ")", ";", "}", "}", "}", "else", "{", "throw", "new", "NotImplemented", "(", ")", ";", "}", "hdr", ".", "flip", "(", ")", ";", "EBinList", "res", "=", "new", "EBinList", "(", "hdr", ",", "resp", ")", ";", "task", ".", "output_from_driver", "(", "res", ")", ";", "}", "public", "void", "driver_output2", "(", "ByteBuffer", "header", ",", "ByteBuffer", "buf", ")", "throws", "Pausable", "{", "int", "status", "=", "task", ".", "status", ";", "if", "(", "(", "status", "&", "EDriverTask", ".", "ERTS_PORT_SFLG_CLOSING", ")", "!=", "0", ")", "{", "return", ";", "}", "header", ".", "flip", "(", ")", ";", "if", "(", "buf", "!=", "null", ")", "buf", ".", "flip", "(", ")", ";", "if", "(", "(", "status", "&", "EDriverTask", ".", "ERTS_PORT_SFLG_DISTRIBUTION", ")", "!=", "0", ")", "{", "task", ".", "node", "(", ")", ".", "net_message", "(", "task", ".", "self_handle", "(", ")", ",", "null", ",", "buf", ")", ";", "return", ";", "}", "if", "(", "(", "status", "&", "EDriverTask", ".", "ERTS_PORT_SFLG_LINEBUF_IO", ")", "!=", "0", ")", "{", "throw", "new", "NotImplemented", "(", ")", ";", "}", "EObject", "tail", "=", "null", ";", "if", "(", "buf", "==", "null", "||", "!", "buf", ".", "hasRemaining", "(", ")", ")", "{", "tail", "=", "ERT", ".", "NIL", ";", "}", "else", "if", "(", "task", ".", "send_binary_data", ")", "{", "tail", "=", "EBinary", ".", "make", "(", "buf", ")", ";", "}", "else", "{", "tail", "=", "EString", ".", "make", "(", "buf", ")", ";", "}", "EBinList", "out", "=", "new", "EBinList", "(", "header", ",", "tail", ")", ";", "task", ".", "output_from_driver", "(", "out", ")", ";", "}", "protected", "void", "driver_output", "(", "ByteBuffer", "buf", ")", "throws", "Pausable", "{", "int", "status", "=", "task", ".", "status", ";", "if", "(", "(", "status", "&", "EDriverTask", ".", "ERTS_PORT_SFLG_CLOSING", ")", "!=", "0", ")", "{", "return", ";", "}", "buf", ".", "flip", "(", ")", ";", "if", "(", "(", "status", "&", "EDriverTask", ".", "ERTS_PORT_SFLG_DISTRIBUTION", ")", "!=", "0", ")", "{", "task", ".", "node", "(", ")", ".", "net_message", "(", "task", ".", "self_handle", "(", ")", ",", "null", ",", "buf", ")", ";", "return", ";", "}", "if", "(", "(", "status", "&", "EDriverTask", ".", "ERTS_PORT_SFLG_LINEBUF_IO", ")", "!=", "0", ")", "{", "throw", "new", "NotImplemented", "(", ")", ";", "}", "EObject", "out", ";", "if", "(", "buf", "==", "null", "||", "!", "buf", ".", "hasRemaining", "(", ")", ")", "{", "out", "=", "ERT", ".", "NIL", ";", "}", "else", "if", "(", "task", ".", "send_binary_data", ")", "{", "out", "=", "EBinary", ".", "make", "(", "buf", ")", ";", "}", "else", "{", "out", "=", "EString", ".", "make", "(", "buf", ")", ";", "}", "task", ".", "output_from_driver", "(", "out", ")", ";", "}", "public", "void", "driver_output_term", "(", "EObject", "term", ")", "throws", "Pausable", "{", "task", ".", "output_term_from_driver", "(", "term", ")", ";", "}", "public", "void", "driver_send_term", "(", "EHandle", "caller", ",", "ETuple", "msg", ")", "throws", "Pausable", "{", "if", "(", "caller", "!=", "null", ")", "{", "caller", ".", "send", "(", "task", ".", "self_handle", "(", ")", ",", "msg", ")", ";", "}", "}", "protected", "void", "driver_output_binary", "(", "byte", "[", "]", "header", ",", "ByteBuffer", "binp", ")", "throws", "Pausable", "{", "EObject", "out", "=", "EBinary", ".", "make", "(", "binp", ")", ";", "if", "(", "header", ".", "length", ">", "0", ")", "{", "out", "=", "new", "EBinList", "(", "header", ",", "out", ")", ";", "}", "task", ".", "output_from_driver", "(", "out", ")", ";", "}", "protected", "void", "driver_cancel_timer", "(", ")", "{", "task", ".", "cancel_timer", "(", "port", "(", ")", ")", ";", "}", "protected", "void", "driver_set_timer", "(", "long", "howlong", ")", "{", "task", ".", "set_timer", "(", "howlong", ")", ";", "}", "protected", "long", "driver_read_timer", "(", ")", "{", "return", "task", ".", "read_timer", "(", ")", ";", "}", "protected", "Lock", "driver_pdl_create", "(", ")", "{", "if", "(", "pdl", "==", "null", ")", "{", "pdl", "=", "new", "ReentrantLock", "(", ")", ";", "}", "return", "pdl", ";", "}", "private", "ByteBuffer", "[", "]", "queue", "=", "null", ";", "private", "EPID", "caller", ";", "protected", "ByteBuffer", "[", "]", "driver_peekq", "(", ")", "{", "return", "queue", ";", "}", "protected", "EPID", "driver_caller", "(", ")", "{", "return", "this", ".", "caller", ";", "}", "protected", "boolean", "driver_demonitor_process", "(", "ERef", "monitor", ")", "throws", "Pausable", "{", "try", "{", "return", "ErlProc", ".", "demonitor", "(", "task", ",", "monitor", ",", "ERT", ".", "NIL", ")", "==", "ERT", ".", "TRUE", ";", "}", "catch", "(", "ErlangException", "e", ")", "{", "EDriverTask", ".", "log", ".", "log", "(", "Level", ".", "FINE", ",", "\"demonitor\"", ",", "e", ")", ";", "return", "false", ";", "}", "}", "protected", "EHandle", "driver_get_monitored_process", "(", "ERef", "monitor", ")", "{", "return", "task", ".", "get_monitored_process", "(", "monitor", ")", ";", "}", "protected", "ERef", "driver_monitor_process", "(", "EPID", "pid", ")", "throws", "Pausable", "{", "ERef", "ref", "=", "ERT", ".", "getLocalNode", "(", ")", ".", "createRef", "(", ")", ";", "if", "(", "!", "task", ".", "monitor", "(", "pid", ",", "pid", ",", "ref", ")", ")", "{", "port", "(", ")", ".", "send", "(", "port", "(", ")", ",", "ETuple", ".", "make", "(", "ERT", ".", "am_DOWN", ",", "ref", ",", "ErlProc", ".", "am_process", ",", "pid", ",", "ERT", ".", "am_noproc", ")", ")", ";", "}", "return", "ref", ";", "}", "protected", "int", "driver_sizeq", "(", ")", "{", "if", "(", "queue", "==", "null", ")", "return", "0", ";", "int", "size", "=", "0", ";", "int", "p", "=", "0", ";", "for", "(", "p", "=", "0", ";", "p", "<", "queue", ".", "length", ";", "p", "++", ")", "{", "if", "(", "queue", "[", "p", "]", "!=", "null", ")", "size", "+=", "queue", "[", "p", "]", ".", "remaining", "(", ")", ";", "}", "return", "size", ";", "}", "protected", "long", "driver_deq", "(", "long", "size", ")", "{", "ByteBuffer", "[", "]", "queue", "=", "this", ".", "queue", ";", "if", "(", "queue", "==", "null", ")", "return", "0", ";", "int", "p", "=", "0", ";", "for", "(", "p", "=", "0", ";", "p", "<", "queue", ".", "length", "&&", "queue", "[", "p", "]", "!=", "null", "&&", "!", "queue", "[", "p", "]", ".", "hasRemaining", "(", ")", ";", "p", "++", ")", "{", "}", "if", "(", "p", "==", "queue", ".", "length", ")", "return", "0", ";", "long", "res", "=", "0", ";", "for", "(", "int", "i", "=", "0", ";", "(", "p", "+", "i", ")", "<", "queue", ".", "length", ";", "i", "++", ")", "{", "queue", "[", "i", "]", "=", "queue", "[", "p", "+", "i", "]", ";", "if", "(", "queue", "[", "i", "]", "!=", "null", ")", "{", "res", "+=", "queue", "[", "i", "]", ".", "remaining", "(", ")", ";", "}", "}", "for", "(", "int", "i", "=", "p", ";", "i", "<", "queue", ".", "length", ";", "i", "++", ")", "{", "queue", "[", "i", "]", "=", "null", ";", "}", "return", "res", ";", "}", "protected", "void", "driver_enqv", "(", "ByteBuffer", "[", "]", "q", ")", "{", "if", "(", "queue", "==", "null", "||", "queue", "[", "0", "]", "==", "null", ")", "queue", "=", "q", ";", "else", "{", "ArrayList", "<", "ByteBuffer", ">", "bbs", "=", "new", "ArrayList", "<", "ByteBuffer", ">", "(", ")", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "queue", ".", "length", ";", "i", "++", ")", "{", "if", "(", "queue", "[", "i", "]", "!=", "null", "&&", "queue", "[", "i", "]", ".", "hasRemaining", "(", ")", ")", "bbs", ".", "add", "(", "queue", "[", "i", "]", ")", ";", "}", "for", "(", "int", "i", "=", "0", ";", "i", "<", "q", ".", "length", ";", "i", "++", ")", "{", "if", "(", "q", "[", "i", "]", "!=", "null", "&&", "q", "[", "i", "]", ".", "hasRemaining", "(", ")", ")", "bbs", ".", "add", "(", "q", "[", "i", "]", ")", ";", "}", "queue", "=", "bbs", ".", "toArray", "(", "new", "ByteBuffer", "[", "bbs", ".", "size", "(", ")", "]", ")", ";", "}", "}", "protected", "void", "stopSelect", "(", "SelectableChannel", "event", ")", "throws", "Pausable", "{", "}", "public", "static", "ByteBuffer", "flatten", "(", "ByteBuffer", "[", "]", "out", ")", "{", "return", "EDriverTask", ".", "flatten", "(", "out", ")", ";", "}", "protected", "void", "stop", "(", "EObject", "reason", ")", "throws", "Pausable", "{", "if", "(", "(", "task", ".", "status", "&", "EDriverTask", ".", "ERTS_PORT_SFLG_DISTRIBUTION", ")", "!=", "0", ")", "{", "EPeer", "node", "=", "task", ".", "node", "(", ")", ";", "if", "(", "node", "!=", "null", ")", "{", "node", ".", "node_going_down", "(", "port", "(", ")", ",", "reason", ")", ";", "}", "task", ".", "status", "&=", "~", "EDriverTask", ".", "ERTS_PORT_SFLG_DISTRIBUTION", ";", "}", "}", "protected", "abstract", "void", "output", "(", "EHandle", "caller", ",", "ByteBuffer", "buf", ")", "throws", "IOException", ",", "Pausable", ";", "protected", "void", "outputv", "(", "EHandle", "caller", ",", "ByteBuffer", "[", "]", "ev", ")", "throws", "IOException", ",", "Pausable", "{", "output", "(", "caller", ",", "flatten", "(", "ev", ")", ")", ";", "}", "protected", "void", "readyInput", "(", "SelectableChannel", "ch", ")", "throws", "Pausable", "{", "}", ";", "protected", "void", "readyOutput", "(", "SelectableChannel", "evt", ")", "throws", "Pausable", "{", "}", ";", "protected", "void", "readyAsync", "(", "EAsync", "data", ")", "throws", "Pausable", "{", "}", "protected", "ByteBuffer", "control", "(", "EPID", "pid", ",", "int", "command", ",", "ByteBuffer", "cmd", ")", "throws", "Pausable", "{", "throw", "ERT", ".", "badarg", "(", ")", ";", "}", "protected", "void", "timeout", "(", ")", "throws", "Pausable", "{", "}", ";", "protected", "void", "flush", "(", ")", "throws", "Pausable", "{", "}", ";", "protected", "EObject", "call", "(", "EPID", "caller", ",", "int", "command", ",", "EObject", "data", ")", "throws", "Pausable", "{", "throw", "ERT", ".", "badarg", "(", ")", ";", "}", "public", "void", "readyConnect", "(", "SelectableChannel", "evt", ")", "throws", "Pausable", "{", "}", "public", "void", "readyAccept", "(", "SelectableChannel", "ch", ")", "throws", "Pausable", "{", "}", "protected", "void", "set_busy_port", "(", "boolean", "b", ")", "{", "throw", "new", "erjang", ".", "NotImplemented", "(", ")", ";", "}", "public", "static", "void", "dump_buffer", "(", "ByteBuffer", "[", "]", "buffer", ")", "{", "dump_buffer", "(", "log", ",", "null", ",", "buffer", ")", ";", "}", "public", "static", "void", "dump_buffer", "(", "Logger", "log", ",", "String", "heading", ",", "ByteBuffer", "[", "]", "buffer", ")", "{", "dump_buffer", "(", "log", ",", "Level", ".", "FINEST", ",", "heading", ",", "buffer", ")", ";", "}", "public", "static", "void", "dump_buffer", "(", "Logger", "log", ",", "Level", "level", ",", "String", "heading", ",", "ByteBuffer", "[", "]", "buffer", ")", "{", "if", "(", "!", "log", ".", "isLoggable", "(", "level", ")", ")", "return", ";", "StringBuilder", "sb", "=", "new", "StringBuilder", "(", ")", ";", "if", "(", "heading", "!=", "null", ")", "{", "sb", ".", "append", "(", "heading", ")", ";", "sb", ".", "append", "(", "\"n\"", ")", ";", "}", "sb", ".", "append", "(", "\"", "vec[\"", "+", "buffer", ".", "length", "+", "\"]::", "n\"", ")", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "buffer", ".", "length", ";", "i", "++", ")", "{", "ByteBuffer", "evp", "=", "buffer", "[", "i", "]", ";", "int", "off", "=", "0", ";", "boolean", "did_print", "=", "false", ";", "for", "(", "int", "p", "=", "evp", ".", "position", "(", ")", ";", "p", "<", "evp", ".", "limit", "(", ")", ";", "p", "++", ")", "{", "if", "(", "(", "off", "%", "0x10", ")", "==", "0", "&&", "off", "!=", "0", ")", "sb", ".", "append", "(", "\"n\"", ")", ";", "if", "(", "(", "off", "%", "0x10", ")", "==", "0", ")", "sb", ".", "append", "(", "\"[\"", "+", "i", "+", "\"]", "0x\"", "+", "hex4", "(", "off", ")", "+", "\"", ":\"", ")", ";", "did_print", "=", "true", ";", "sb", ".", "append", "(", "\"", "\"", ")", ";", "byte", "ch", "=", "evp", ".", "get", "(", "p", ")", ";", "sb", ".", "append", "(", "hex2", "(", "ch", "&", "0xff", ")", ")", ";", "off", "+=", "1", ";", "}", "if", "(", "i", "<", "buffer", ".", "length", "-", "1", "&&", "did_print", ")", "sb", ".", "append", "(", "\"n\"", ")", ";", "}", "sb", ".", "append", "(", "\"---n\"", ")", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "buffer", ".", "length", ";", "i", "++", ")", "{", "ByteBuffer", "evp", "=", "buffer", "[", "i", "]", ";", "int", "off", "=", "0", ";", "boolean", "did_print", "=", "false", ";", "for", "(", "int", "p", "=", "evp", ".", "position", "(", ")", ";", "p", "<", "evp", ".", "limit", "(", ")", ";", "p", "++", ")", "{", "if", "(", "(", "off", "%", "0x10", ")", "==", "0", "&&", "off", "!=", "0", ")", "sb", ".", "append", "(", "\"n\"", ")", ";", "if", "(", "(", "off", "%", "0x10", ")", "==", "0", ")", "sb", ".", "append", "(", "\"[\"", "+", "i", "+", "\"]", "0x\"", "+", "hex4", "(", "off", ")", "+", "\"", ":", "\"", ")", ";", "did_print", "=", "true", ";", "byte", "ch", "=", "evp", ".", "get", "(", "p", ")", ";", "if", "(", "ch", ">=", "32", "&&", "ch", "<=", "127", ")", "{", "sb", ".", "append", "(", "(", "char", ")", "ch", ")", ";", "}", "else", "{", "sb", ".", "append", "(", "'.'", ")", ";", "}", "off", "+=", "1", ";", "}", "if", "(", "i", "<", "buffer", ".", "length", "-", "1", "&&", "did_print", ")", "sb", ".", "append", "(", "\"n\"", ")", ";", "}", "String", "msg", "=", "sb", ".", "toString", "(", ")", ";", "log", ".", "log", "(", "level", ",", "msg", ")", ";", "}", "public", "static", "String", "hex2", "(", "int", "i", ")", "{", "if", "(", "i", "<", "0x10", ")", "return", "\"0\"", "+", "Integer", ".", "toHexString", "(", "i", ")", ";", "return", "Integer", ".", "toHexString", "(", "i", ")", ";", "}", "public", "static", "String", "hex4", "(", "int", "i", ")", "{", "if", "(", "i", "<", "0x10", ")", "return", "\"000\"", "+", "Integer", ".", "toHexString", "(", "i", ")", ";", "if", "(", "i", "<", "0x100", ")", "return", "\"00\"", "+", "Integer", ".", "toHexString", "(", "i", ")", ";", "if", "(", "i", "<", "0x1000", ")", "return", "\"0\"", "+", "Integer", ".", "toHexString", "(", "i", ")", ";", "return", "Integer", ".", "toHexString", "(", "i", ")", ";", "}", "}", "</s>" ]
7,750
[ "<s>", "package", "erjang", ".", "driver", ";", "import", "java", ".", "util", ".", "HashMap", ";", "import", "erjang", ".", "ERT", ";", "import", "erjang", ".", "ESeq", ";", "import", "erjang", ".", "EString", ";", "public", "class", "Drivers", "{", "public", "static", "final", "HashMap", "<", "String", ",", "EDriver", ">", "drivers", "=", "new", "HashMap", "(", ")", ";", "public", "static", "synchronized", "void", "register", "(", "EDriver", "driver", ")", "{", "drivers", ".", "put", "(", "driver", ".", "driverName", "(", ")", ",", "driver", ")", ";", "}", "public", "static", "synchronized", "EDriver", "getDriver", "(", "String", "name", ")", "{", "EDriver", "res", "=", "drivers", ".", "get", "(", "name", ")", ";", "return", "res", ";", "}", "public", "static", "ESeq", "getLoaded", "(", ")", "{", "ESeq", "res", "=", "ERT", ".", "NIL", ";", "for", "(", "String", "driver", ":", "drivers", ".", "keySet", "(", ")", ")", "{", "res", "=", "res", ".", "cons", "(", "EString", ".", "fromString", "(", "driver", ")", ")", ";", "}", "return", "res", ";", "}", "}", "</s>" ]
7,751
[ "<s>", "package", "erjang", ".", "driver", ";", "import", "java", ".", "nio", ".", "channels", ".", "CancelledKeyException", ";", "import", "java", ".", "nio", ".", "channels", ".", "SelectableChannel", ";", "import", "java", ".", "nio", ".", "channels", ".", "SelectionKey", ";", "import", "java", ".", "util", ".", "HashMap", ";", "import", "java", ".", "util", ".", "Map", ";", "class", "NIOChannelInfo", "{", "static", "class", "Interest", "{", "SelectableChannel", "ch", ";", "NIOHandler", "handler", ";", "int", "ops", ";", "boolean", "releaseNotify", ";", "@", "Override", "public", "String", "toString", "(", ")", "{", "return", "\"{ch=\"", "+", "ch", "+", "\";", "ops=\"", "+", "Integer", ".", "toBinaryString", "(", "ops", ")", "+", "\";", "release=\"", "+", "releaseNotify", "+", "\"}\"", ";", "}", "public", "Interest", "(", "SelectableChannel", "ch", ",", "NIOHandler", "handler", ",", "int", "ops", ",", "boolean", "releaseNotify", ")", "{", "this", ".", "ch", "=", "ch", ";", "this", ".", "handler", "=", "handler", ";", "this", ".", "ops", "=", "ops", ";", "this", ".", "releaseNotify", "=", "releaseNotify", ";", "}", "public", "Interest", "combine", "(", "Interest", "old", ")", "{", "return", "new", "Interest", "(", "ch", ",", "handler", ",", "ops", "|", "old", ".", "ops", ",", "releaseNotify", "||", "old", ".", "releaseNotify", ")", ";", "}", "}", "public", "static", "final", "int", "ALL_OPS", "=", "SelectionKey", ".", "OP_ACCEPT", "|", "SelectionKey", ".", "OP_CONNECT", "|", "SelectionKey", ".", "OP_READ", "|", "SelectionKey", ".", "OP_WRITE", ";", "Map", "<", "NIOHandler", ",", "Interest", ">", "interest", "=", "new", "HashMap", "<", "NIOHandler", ",", "Interest", ">", "(", ")", ";", "public", "NIOChannelInfo", "(", "Interest", "interest", ")", "{", "add", "(", "interest", ")", ";", "}", "public", "void", "add", "(", "Interest", "ops", ")", "{", "Interest", "old", "=", "interest", ".", "get", "(", "ops", ".", "handler", ")", ";", "if", "(", "old", "==", "null", ")", "{", "interest", ".", "put", "(", "ops", ".", "handler", ",", "ops", ")", ";", "}", "else", "{", "interest", ".", "put", "(", "ops", ".", "handler", ",", "ops", ".", "combine", "(", "old", ")", ")", ";", "}", "}", "public", "void", "clear_interest", "(", "Interest", "req", ")", "{", "NIOHandler", "handler", "=", "req", ".", "handler", ";", "boolean", "releaseNotify", "=", "req", ".", "releaseNotify", ";", "SelectableChannel", "ch", "=", "req", ".", "ch", ";", "Interest", "old", "=", "interest", ".", "get", "(", "handler", ")", ";", "if", "(", "old", "==", "null", ")", "{", "if", "(", "releaseNotify", "&&", "handler", "!=", "null", ")", "{", "handler", ".", "released", "(", "ch", ")", ";", "}", "}", "else", "{", "old", ".", "releaseNotify", "|=", "releaseNotify", ";", "old", ".", "ops", "&=", "~", "req", ".", "ops", ";", "if", "(", "old", ".", "ops", "==", "0", "&&", "!", "old", ".", "releaseNotify", ")", "{", "interest", ".", "remove", "(", "handler", ")", ";", "}", "}", "}", "public", "int", "updateInterestOpsFor", "(", "SelectionKey", "key", ")", "{", "int", "ops", "=", "computeOps", "(", ")", ";", "key", ".", "interestOps", "(", "ops", ")", ";", "return", "ops", ";", "}", "private", "int", "computeOps", "(", ")", "{", "int", "ops", "=", "0", ";", "for", "(", "Interest", "i", ":", "interest", ".", "values", "(", ")", ")", "{", "ops", "|=", "i", ".", "ops", ";", "}", "return", "ops", ";", "}", "public", "void", "ready", "(", "SelectionKey", "key", ")", "{", "final", "SelectableChannel", "ch", "=", "key", ".", "channel", "(", ")", ";", "int", "readyOps", ";", "try", "{", "readyOps", "=", "key", ".", "readyOps", "(", ")", ";", "}", "catch", "(", "CancelledKeyException", "e", ")", "{", "return", ";", "}", "Interest", "[", "]", "ents", "=", "interest", ".", "values", "(", ")", ".", "toArray", "(", "new", "Interest", "[", "interest", ".", "size", "(", ")", "]", ")", ";", "for", "(", "Interest", "want", ":", "ents", ")", "{", "int", "gotOps", "=", "want", ".", "ops", "&", "readyOps", ";", "if", "(", "gotOps", "!=", "0", ")", "{", "NIOHandler", "handler", "=", "want", ".", "handler", ";", "if", "(", "handler", "!=", "null", ")", "{", "handler", ".", "ready", "(", "ch", ",", "gotOps", ")", ";", "}", "want", ".", "ops", "&=", "~", "gotOps", ";", "if", "(", "want", ".", "ops", "==", "0", "&&", "!", "want", ".", "releaseNotify", ")", "{", "interest", ".", "remove", "(", "handler", ")", ";", "}", "}", "}", "try", "{", "key", ".", "interestOps", "(", "computeOps", "(", ")", ")", ";", "if", "(", "interest", ".", "isEmpty", "(", ")", ")", "{", "key", ".", "cancel", "(", ")", ";", "}", "}", "catch", "(", "CancelledKeyException", "e", ")", "{", "}", "}", "public", "void", "cancelled", "(", ")", "{", "for", "(", "Interest", "i", ":", "interest", ".", "values", "(", ")", ")", "{", "if", "(", "i", ".", "releaseNotify", "&&", "i", ".", "handler", "!=", "null", ")", "{", "i", ".", "handler", ".", "released", "(", "i", ".", "ch", ")", ";", "}", "}", "interest", ".", "clear", "(", ")", ";", "}", "}", "</s>" ]
7,752
[ "<s>", "package", "erjang", ".", "driver", ";", "import", "java", ".", "io", ".", "IOException", ";", "import", "java", ".", "nio", ".", "ByteBuffer", ";", "import", "java", ".", "nio", ".", "channels", ".", "SelectableChannel", ";", "import", "java", ".", "util", ".", "concurrent", ".", "locks", ".", "ReentrantLock", ";", "import", "kilim", ".", "Lock", ";", "import", "kilim", ".", "Pausable", ";", "import", "kilim", ".", "Task", ";", "import", "erjang", ".", "EHandle", ";", "import", "erjang", ".", "EInternalPort", ";", "import", "erjang", ".", "EObject", ";", "import", "erjang", ".", "EPID", ";", "import", "erjang", ".", "ERef", ";", "class", "LockingDriverInstance", "extends", "EDriverControl", "{", "private", "final", "ReentrantLock", "lock", ";", "private", "final", "EDriverControl", "target", ";", "public", "LockingDriverInstance", "(", "EDriverControl", "target", ",", "ReentrantLock", "lock", ")", "{", "this", ".", "target", "=", "target", ";", "this", ".", "lock", "=", "lock", ";", "}", "@", "Override", "protected", "EObject", "call", "(", "EPID", "caller", ",", "int", "command", ",", "EObject", "data", ")", "throws", "Pausable", "{", "lock", ".", "lock", "(", ")", ";", "try", "{", "return", "target", ".", "call", "(", "caller", ",", "command", ",", "data", ")", ";", "}", "finally", "{", "lock", ".", "unlock", "(", ")", ";", "}", "}", "@", "Override", "protected", "ByteBuffer", "control", "(", "EPID", "pid", ",", "int", "command", ",", "ByteBuffer", "buf", ")", "throws", "Pausable", "{", "lock", ".", "lock", "(", ")", ";", "try", "{", "return", "target", ".", "control", "(", "pid", ",", "command", ",", "buf", ")", ";", "}", "finally", "{", "lock", ".", "unlock", "(", ")", ";", "}", "}", "@", "Override", "protected", "void", "outputv", "(", "EHandle", "caller", ",", "ByteBuffer", "[", "]", "ev", ")", "throws", "IOException", ",", "Pausable", "{", "lock", ".", "lock", "(", ")", ";", "try", "{", "target", ".", "outputv", "(", "caller", ",", "ev", ")", ";", "}", "finally", "{", "lock", ".", "unlock", "(", ")", ";", "}", "}", "@", "Override", "public", "void", "processExit", "(", "ERef", "monitor", ")", "throws", "Pausable", "{", "lock", ".", "lock", "(", ")", ";", "try", "{", "target", ".", "processExit", "(", "monitor", ")", ";", "}", "finally", "{", "lock", ".", "unlock", "(", ")", ";", "}", "}", "@", "Override", "protected", "void", "readyInput", "(", "SelectableChannel", "evt", ")", "throws", "Pausable", "{", "lock", ".", "lock", "(", ")", ";", "try", "{", "target", ".", "readyInput", "(", "evt", ")", ";", "}", "finally", "{", "lock", ".", "unlock", "(", ")", ";", "}", "}", "@", "Override", "protected", "void", "readyOutput", "(", "SelectableChannel", "evt", ")", "throws", "Pausable", "{", "lock", ".", "lock", "(", ")", ";", "try", "{", "target", ".", "readyOutput", "(", "evt", ")", ";", "}", "finally", "{", "lock", ".", "unlock", "(", ")", ";", "}", "}", "@", "Override", "protected", "void", "stop", "(", "EObject", "reason", ")", "throws", "Pausable", "{", "lock", ".", "lock", "(", ")", ";", "try", "{", "target", ".", "stop", "(", "reason", ")", ";", "}", "finally", "{", "lock", ".", "unlock", "(", ")", ";", "}", "}", "@", "Override", "protected", "void", "stopSelect", "(", "SelectableChannel", "ch", ")", "throws", "Pausable", "{", "lock", ".", "lock", "(", ")", ";", "try", "{", "target", ".", "stopSelect", "(", "ch", ")", ";", "}", "finally", "{", "lock", ".", "unlock", "(", ")", ";", "}", "}", "@", "Override", "protected", "void", "timeout", "(", ")", "throws", "Pausable", "{", "lock", ".", "lock", "(", ")", ";", "try", "{", "target", ".", "timeout", "(", ")", ";", "}", "finally", "{", "lock", ".", "unlock", "(", ")", ";", "}", "}", "@", "Override", "protected", "void", "readyAsync", "(", "EAsync", "data", ")", "throws", "Pausable", "{", "lock", ".", "lock", "(", ")", ";", "try", "{", "target", ".", "readyAsync", "(", "data", ")", ";", "}", "finally", "{", "lock", ".", "unlock", "(", ")", ";", "}", "}", "@", "Override", "public", "void", "readyAccept", "(", "SelectableChannel", "ch", ")", "throws", "Pausable", "{", "lock", ".", "lock", "(", ")", ";", "try", "{", "target", ".", "readyAccept", "(", "ch", ")", ";", "}", "finally", "{", "lock", ".", "unlock", "(", ")", ";", "}", "}", "@", "Override", "public", "void", "readyConnect", "(", "SelectableChannel", "evt", ")", "throws", "Pausable", "{", "lock", ".", "lock", "(", ")", ";", "try", "{", "target", ".", "readyConnect", "(", "evt", ")", ";", "}", "finally", "{", "lock", ".", "unlock", "(", ")", ";", "}", "}", "@", "Override", "void", "setTask", "(", "EDriverTask", "task", ")", "{", "target", ".", "setTask", "(", "task", ")", ";", "}", "@", "Override", "public", "EDriver", "getDriver", "(", ")", "{", "return", "target", ".", "getDriver", "(", ")", ";", "}", "@", "Override", "public", "void", "setup", "(", ")", "{", "target", ".", "setup", "(", ")", ";", "}", "}", "</s>" ]
7,753
[ "<s>", "package", "erjang", ".", "driver", ".", "tcp_inet", ";", "import", "java", ".", "io", ".", "ByteArrayOutputStream", ";", "import", "java", ".", "io", ".", "DataOutputStream", ";", "import", "java", ".", "io", ".", "IOException", ";", "import", "java", ".", "net", ".", "InetAddress", ";", "import", "java", ".", "net", ".", "InetSocketAddress", ";", "import", "java", ".", "net", ".", "UnknownHostException", ";", "import", "java", ".", "nio", ".", "ByteBuffer", ";", "import", "java", ".", "nio", ".", "ByteOrder", ";", "import", "java", ".", "nio", ".", "channels", ".", "CancelledKeyException", ";", "import", "java", ".", "nio", ".", "channels", ".", "ClosedChannelException", ";", "import", "java", ".", "nio", ".", "channels", ".", "GatheringByteChannel", ";", "import", "java", ".", "nio", ".", "channels", ".", "ReadableByteChannel", ";", "import", "java", ".", "nio", ".", "channels", ".", "SelectableChannel", ";", "import", "java", ".", "nio", ".", "channels", ".", "SelectionKey", ";", "import", "java", ".", "nio", ".", "channels", ".", "SocketChannel", ";", "import", "java", ".", "nio", ".", "charset", ".", "Charset", ";", "import", "java", ".", "util", ".", "ArrayList", ";", "import", "java", ".", "util", ".", "List", ";", "import", "java", ".", "util", ".", "PriorityQueue", ";", "import", "java", ".", "util", ".", "concurrent", ".", "atomic", ".", "AtomicInteger", ";", "import", "java", ".", "util", ".", "logging", ".", "Level", ";", "import", "java", ".", "util", ".", "logging", ".", "Logger", ";", "import", "kilim", ".", "Pausable", ";", "import", "kilim", ".", "RingQueue", ";", "import", "erjang", ".", "EAtom", ";", "import", "erjang", ".", "EBinList", ";", "import", "erjang", ".", "EBinary", ";", "import", "erjang", ".", "EHandle", ";", "import", "erjang", ".", "EInternalPID", ";", "import", "erjang", ".", "EInternalPort", ";", "import", "erjang", ".", "EObject", ";", "import", "erjang", ".", "EPID", ";", "import", "erjang", ".", "EPort", ";", "import", "erjang", ".", "ERT", ";", "import", "erjang", ".", "ERef", ";", "import", "erjang", ".", "EString", ";", "import", "erjang", ".", "ETuple", ";", "import", "erjang", ".", "ETuple2", ";", "import", "erjang", ".", "ErlangError", ";", "import", "erjang", ".", "NotImplemented", ";", "import", "erjang", ".", "driver", ".", "EAsync", ";", "import", "erjang", ".", "driver", ".", "EDriverInstance", ";", "import", "erjang", ".", "driver", ".", "EDriverTask", ";", "import", "erjang", ".", "driver", ".", "IO", ";", "import", "erjang", ".", "driver", ".", "NIOSelector", ";", "import", "erjang", ".", "driver", ".", "SelectMode", ";", "import", "erjang", ".", "driver", ".", "efile", ".", "Posix", ";", "import", "erjang", ".", "net", ".", "InetSocket", ";", "import", "erjang", ".", "net", ".", "Protocol", ";", "import", "erjang", ".", "net", ".", "ProtocolFamily", ";", "import", "erjang", ".", "net", ".", "ProtocolType", ";", "public", "class", "TCPINet", "extends", "EDriverInstance", "implements", "java", ".", "lang", ".", "Cloneable", "{", "static", "Logger", "log", "=", "Logger", ".", "getLogger", "(", "\"\"", ")", ";", "static", "Logger", "portlog", "=", "Logger", ".", "getLogger", "(", "\"erjang.port\"", ")", ";", "public", "class", "AsyncMultiOp", "{", "public", "AsyncOp", "op", ";", "public", "MultiTimerData", "timeout", ";", "public", "AsyncMultiOp", "next", ";", "}", "static", "class", "MultiTimerData", "implements", "Comparable", "<", "MultiTimerData", ">", "{", "public", "long", "when", ";", "public", "EPID", "caller", ";", "@", "Override", "public", "int", "compareTo", "(", "MultiTimerData", "o", ")", "{", "if", "(", "this", ".", "when", "<", "o", ".", "when", ")", "return", "-", "1", ";", "if", "(", "this", ".", "when", ">", "o", ".", "when", ")", "return", "1", ";", "return", "0", ";", "}", "}", "static", "class", "AsyncOp", "{", "public", "AsyncOp", "(", "short", "id", ",", "EPID", "caller", ",", "int", "req", ",", "int", "timeout", ",", "ERef", "monitor", ")", "{", "this", ".", "id", "=", "id", ";", "this", ".", "caller", "=", "caller", ";", "this", ".", "req", "=", "req", ";", "this", ".", "monitor", "=", "monitor", ";", "this", ".", "timeout", "=", "timeout", ";", "}", "final", "short", "id", ";", "final", "EPID", "caller", ";", "final", "int", "req", ";", "final", "ERef", "monitor", ";", "final", "public", "int", "timeout", ";", "}", "static", "enum", "SockType", "{", "SOCK_STREAM", ",", "SOCK_DGRAM", ",", "SOCK_SEQPACKET", ";", "}", "static", "enum", "ActiveType", "{", "PASSIVE", "(", "0", ")", ",", "ACTIVE", "(", "1", ")", ",", "ACTIVE_ONCE", "(", "2", ")", ";", "final", "int", "value", ";", "ActiveType", "(", "int", "val", ")", "{", "this", ".", "value", "=", "val", ";", "}", "public", "static", "ActiveType", "valueOf", "(", "int", "ival", ")", "{", "switch", "(", "ival", ")", "{", "case", "0", ":", "return", "PASSIVE", ";", "case", "1", ":", "return", "ACTIVE", ";", "case", "2", ":", "return", "ACTIVE_ONCE", ";", "}", "throw", "new", "erjang", ".", "NotImplemented", "(", ")", ";", "}", "}", "public", "static", "final", "byte", "INET_AF_INET", "=", "1", ";", "public", "static", "final", "byte", "INET_AF_INET6", "=", "2", ";", "public", "static", "final", "byte", "INET_AF_ANY", "=", "3", ";", "public", "static", "final", "byte", "INET_AF_LOOPBACK", "=", "4", ";", "public", "static", "final", "int", "INET_TYPE_STREAM", "=", "1", ";", "public", "static", "final", "int", "INET_TYPE_DGRAM", "=", "2", ";", "public", "static", "final", "int", "INET_TYPE_SEQPACKET", "=", "3", ";", "public", "static", "final", "int", "INET_MODE_LIST", "=", "0", ";", "public", "static", "final", "int", "INET_MODE_BINARY", "=", "1", ";", "public", "static", "final", "int", "INET_DELIVER_PORT", "=", "0", ";", "public", "static", "final", "int", "INET_DELIVER_TERM", "=", "1", ";", "public", "static", "final", "int", "INET_PASSIVE", "=", "0", ";", "public", "static", "final", "int", "INET_ACTIVE", "=", "1", ";", "public", "static", "final", "int", "INET_ONCE", "=", "2", ";", "public", "static", "final", "int", "INET_F_OPEN", "=", "0x0001", ";", "public", "static", "final", "int", "INET_F_BOUND", "=", "0x0002", ";", "public", "static", "final", "int", "INET_F_ACTIVE", "=", "0x0004", ";", "public", "static", "final", "int", "INET_F_LISTEN", "=", "0x0008", ";", "public", "static", "final", "int", "INET_F_CON", "=", "0x0010", ";", "public", "static", "final", "int", "INET_F_ACC", "=", "0x0020", ";", "public", "static", "final", "int", "INET_F_LST", "=", "0x0040", ";", "public", "static", "final", "int", "INET_F_BUSY", "=", "0x0080", ";", "public", "static", "final", "int", "INET_F_MULTI_CLIENT", "=", "0x0100", ";", "public", "static", "final", "int", "INET_REQ_OPEN", "=", "1", ";", "public", "static", "final", "int", "INET_REQ_CLOSE", "=", "2", ";", "public", "static", "final", "int", "INET_REQ_CONNECT", "=", "3", ";", "public", "static", "final", "int", "INET_REQ_PEER", "=", "4", ";", "public", "static", "final", "int", "INET_REQ_NAME", "=", "5", ";", "public", "static", "final", "int", "INET_REQ_BIND", "=", "6", ";", "public", "static", "final", "int", "INET_REQ_SETOPTS", "=", "7", ";", "public", "static", "final", "int", "INET_REQ_GETOPTS", "=", "8", ";", "public", "static", "final", "int", "INET_REQ_GETSTAT", "=", "11", ";", "public", "static", "final", "int", "INET_REQ_GETHOSTNAME", "=", "12", ";", "public", "static", "final", "int", "INET_REQ_FDOPEN", "=", "13", ";", "public", "static", "final", "int", "INET_REQ_GETFD", "=", "14", ";", "public", "static", "final", "int", "INET_REQ_GETTYPE", "=", "15", ";", "public", "static", "final", "int", "INET_REQ_GETSTATUS", "=", "16", ";", "public", "static", "final", "int", "INET_REQ_GETSERVBYNAME", "=", "17", ";", "public", "static", "final", "int", "INET_REQ_GETSERVBYPORT", "=", "18", ";", "public", "static", "final", "int", "INET_REQ_SETNAME", "=", "19", ";", "public", "static", "final", "int", "INET_REQ_SETPEER", "=", "20", ";", "public", "static", "final", "int", "INET_REQ_GETIFLIST", "=", "21", ";", "public", "static", "final", "int", "INET_REQ_IFGET", "=", "22", ";", "public", "static", "final", "int", "INET_REQ_IFSET", "=", "23", ";", "public", "static", "final", "int", "INET_REQ_SUBSCRIBE", "=", "24", ";", "public", "static", "final", "int", "TCP_REQ_ACCEPT", "=", "40", ";", "public", "static", "final", "int", "TCP_REQ_LISTEN", "=", "41", ";", "public", "static", "final", "int", "TCP_REQ_RECV", "=", "42", ";", "public", "static", "final", "int", "TCP_REQ_UNRECV", "=", "43", ";", "public", "static", "final", "int", "TCP_REQ_SHUTDOWN", "=", "44", ";", "public", "static", "final", "int", "TCP_REQ_MULTI_OP", "=", "45", ";", "public", "static", "final", "int", "PACKET_REQ_RECV", "=", "60", ";", "public", "static", "final", "int", "SCTP_REQ_LISTEN", "=", "61", ";", "public", "static", "final", "int", "SCTP_REQ_BINDX", "=", "62", ";", "public", "static", "final", "byte", "INET_SUBS_EMPTY_OUT_Q", "=", "1", ";", "public", "static", "final", "byte", "TCP_ADDF_DELAY_SEND", "=", "1", ";", "public", "static", "final", "byte", "TCP_ADDF_CLOSE_SENT", "=", "2", ";", "public", "static", "final", "byte", "TCP_ADDF_DELAYED_CLOSE_RECV", "=", "4", ";", "public", "static", "final", "byte", "TCP_ADDF_DELAYED_CLOSE_SEND", "=", "8", ";", "public", "static", "final", "byte", "INET_REP_ERROR", "=", "0", ";", "public", "static", "final", "byte", "INET_REP_OK", "=", "1", ";", "public", "static", "final", "byte", "INET_REP_SCTP", "=", "2", ";", "public", "static", "final", "int", "INET_STATE_CLOSED", "=", "0", ";", "public", "static", "final", "int", "INET_STATE_OPEN", "=", "(", "INET_F_OPEN", ")", ";", "public", "static", "final", "int", "INET_STATE_BOUND", "=", "(", "INET_STATE_OPEN", "|", "INET_F_BOUND", ")", ";", "public", "static", "final", "int", "INET_STATE_CONNECTED", "=", "(", "INET_STATE_BOUND", "|", "INET_F_ACTIVE", ")", ";", "public", "static", "final", "int", "TCP_STATE_CLOSED", "=", "INET_STATE_CLOSED", ";", "public", "static", "final", "int", "TCP_STATE_OPEN", "=", "(", "INET_F_OPEN", ")", ";", "public", "static", "final", "int", "TCP_STATE_BOUND", "=", "(", "TCP_STATE_OPEN", "|", "INET_F_BOUND", ")", ";", "public", "static", "final", "int", "TCP_STATE_CONNECTED", "=", "(", "TCP_STATE_BOUND", "|", "INET_F_ACTIVE", ")", ";", "public", "static", "final", "int", "TCP_STATE_LISTEN", "=", "(", "TCP_STATE_BOUND", "|", "INET_F_LISTEN", ")", ";", "public", "static", "final", "int", "TCP_STATE_CONNECTING", "=", "(", "TCP_STATE_BOUND", "|", "INET_F_CON", ")", ";", "public", "static", "final", "int", "TCP_STATE_ACCEPTING", "=", "(", "TCP_STATE_LISTEN", "|", "INET_F_ACC", ")", ";", "public", "static", "final", "int", "TCP_STATE_MULTI_ACCEPTING", "=", "(", "TCP_STATE_ACCEPTING", "|", "INET_F_MULTI_CLIENT", ")", ";", "public", "static", "final", "byte", "INET_OPT_REUSEADDR", "=", "0", ";", "public", "static", "final", "byte", "INET_OPT_KEEPALIVE", "=", "1", ";", "public", "static", "final", "byte", "INET_OPT_DONTROUTE", "=", "2", ";", "public", "static", "final", "byte", "INET_OPT_LINGER", "=", "3", ";", "public", "static", "final", "byte", "INET_OPT_BROADCAST", "=", "4", ";", "public", "static", "final", "byte", "INET_OPT_OOBINLINE", "=", "5", ";", "public", "static", "final", "byte", "INET_OPT_SNDBUF", "=", "6", ";", "public", "static", "final", "byte", "INET_OPT_RCVBUF", "=", "7", ";", "public", "static", "final", "byte", "INET_OPT_PRIORITY", "=", "8", ";", "public", "static", "final", "byte", "INET_OPT_TOS", "=", "9", ";", "public", "static", "final", "byte", "TCP_OPT_NODELAY", "=", "10", ";", "public", "static", "final", "byte", "UDP_OPT_MULTICAST_IF", "=", "11", ";", "public", "static", "final", "byte", "UDP_OPT_MULTICAST_TTL", "=", "12", ";", "public", "static", "final", "byte", "UDP_OPT_MULTICAST_LOOP", "=", "13", ";", "public", "static", "final", "byte", "UDP_OPT_ADD_MEMBERSHIP", "=", "14", ";", "public", "static", "final", "byte", "UDP_OPT_DROP_MEMBERSHIP", "=", "15", ";", "public", "static", "final", "byte", "INET_LOPT_BUFFER", "=", "20", ";", "public", "static", "final", "byte", "INET_LOPT_HEADER", "=", "21", ";", "public", "static", "final", "byte", "INET_LOPT_ACTIVE", "=", "22", ";", "public", "static", "final", "byte", "INET_LOPT_PACKET", "=", "23", ";", "public", "static", "final", "byte", "INET_LOPT_MODE", "=", "24", ";", "public", "static", "final", "byte", "INET_LOPT_DELIVER", "=", "25", ";", "public", "static", "final", "byte", "INET_LOPT_EXITONCLOSE", "=", "26", ";", "public", "static", "final", "byte", "INET_LOPT_TCP_HIWTRMRK", "=", "27", ";", "public", "static", "final", "byte", "INET_LOPT_TCP_LOWTRMRK", "=", "28", ";", "public", "static", "final", "byte", "INET_LOPT_BIT8", "=", "29", ";", "public", "static", "final", "byte", "INET_LOPT_TCP_SEND_TIMEOUT", "=", "30", ";", "public", "static", "final", "byte", "INET_LOPT_TCP_DELAY_SEND", "=", "31", ";", "public", "static", "final", "byte", "INET_LOPT_PACKET_SIZE", "=", "32", ";", "public", "static", "final", "byte", "INET_LOPT_READ_PACKETS", "=", "33", ";", "public", "static", "final", "byte", "INET_OPT_RAW", "=", "34", ";", "public", "static", "final", "byte", "INET_LOPT_TCP_SEND_TIMEOUT_CLOSE", "=", "35", ";", "public", "static", "final", "byte", "SCTP_OPT_RTOINFO", "=", "100", ";", "public", "static", "final", "byte", "SCTP_OPT_ASSOCINFO", "=", "101", ";", "public", "static", "final", "byte", "SCTP_OPT_INITMSG", "=", "102", ";", "public", "static", "final", "byte", "SCTP_OPT_AUTOCLOSE", "=", "103", ";", "public", "static", "final", "byte", "SCTP_OPT_NODELAY", "=", "104", ";", "public", "static", "final", "byte", "SCTP_OPT_DISABLE_FRAGMENTS", "=", "105", ";", "public", "static", "final", "byte", "SCTP_OPT_I_WANT_MAPPED_V4_ADDR", "=", "106", ";", "public", "static", "final", "byte", "SCTP_OPT_MAXSEG", "=", "107", ";", "public", "static", "final", "byte", "SCTP_OPT_SET_PEER_PRIMARY_ADDR", "=", "108", ";", "public", "static", "final", "byte", "SCTP_OPT_PRIMARY_ADDR", "=", "109", ";", "public", "static", "final", "byte", "SCTP_OPT_ADAPTATION_LAYER", "=", "110", ";", "public", "static", "final", "byte", "SCTP_OPT_PEER_ADDR_PARAMS", "=", "111", ";", "public", "static", "final", "byte", "SCTP_OPT_DEFAULT_SEND_PARAM", "=", "112", ";", "public", "static", "final", "byte", "SCTP_OPT_EVENTS", "=", "113", ";", "public", "static", "final", "byte", "SCTP_OPT_DELAYED_ACK_TIME", "=", "114", ";", "public", "static", "final", "byte", "SCTP_OPT_STATUS", "=", "115", ";", "public", "static", "final", "byte", "SCTP_OPT_GET_PEER_ADDR_INFO", "=", "116", ";", "public", "static", "final", "int", "INET_IFOPT_ADDR", "=", "1", ";", "public", "static", "final", "int", "INET_IFOPT_BROADADDR", "=", "2", ";", "public", "static", "final", "int", "INET_IFOPT_DSTADDR", "=", "3", ";", "public", "static", "final", "int", "INET_IFOPT_MTU", "=", "4", ";", "public", "static", "final", "int", "INET_IFOPT_NETMASK", "=", "5", ";", "public", "static", "final", "int", "INET_IFOPT_FLAGS", "=", "6", ";", "public", "static", "final", "int", "INET_IFOPT_HWADDR", "=", "7", ";", "public", "static", "final", "int", "INET_BIT8_CLEAR", "=", "0", ";", "public", "static", "final", "int", "INET_BIT8_SET", "=", "1", ";", "public", "static", "final", "int", "INET_BIT8_ON", "=", "2", ";", "public", "static", "final", "int", "INET_BIT8_OFF", "=", "3", ";", "public", "static", "final", "int", "INET_STAT_RECV_CNT", "=", "1", ";", "public", "static", "final", "int", "INET_STAT_RECV_MAX", "=", "2", ";", "public", "static", "final", "int", "INET_STAT_RECV_AVG", "=", "3", ";", "public", "static", "final", "int", "INET_STAT_RECV_DVI", "=", "4", ";", "public", "static", "final", "int", "INET_STAT_SEND_CNT", "=", "5", ";", "public", "static", "final", "int", "INET_STAT_SEND_MAX", "=", "6", ";", "public", "static", "final", "int", "INET_STAT_SEND_AVG", "=", "7", ";", "public", "static", "final", "int", "INET_STAT_SEND_PND", "=", "8", ";", "public", "static", "final", "int", "INET_STAT_RECV_OCT", "=", "9", ";", "public", "static", "final", "int", "INET_STAT_SEND_OCT", "=", "10", ";", "public", "static", "final", "int", "INET_IFF_UP", "=", "0x0001", ";", "public", "static", "final", "int", "INET_IFF_BROADCAST", "=", "0x0002", ";", "public", "static", "final", "int", "INET_IFF_LOOPBACK", "=", "0x0004", ";", "public", "static", "final", "int", "INET_IFF_POINTTOPOINT", "=", "0x0008", ";", "public", "static", "final", "int", "INET_IFF_RUNNING", "=", "0x0010", ";", "public", "static", "final", "int", "INET_IFF_MULTICAST", "=", "0x0020", ";", "public", "static", "final", "int", "INET_IFF_DOWN", "=", "0x0100", ";", "public", "static", "final", "int", "INET_IFF_NBROADCAST", "=", "0x0200", ";", "public", "static", "final", "int", "INET_IFF_NPOINTTOPOINT", "=", "0x0800", ";", "public", "static", "final", "int", "SCTP_FLAG_UNORDERED", "=", "(", "1", ")", ";", "public", "static", "final", "int", "SCTP_FLAG_ADDR_OVER", "=", "(", "2", ")", ";", "public", "static", "final", "int", "SCTP_FLAG_ABORT", "=", "(", "4", ")", ";", "public", "static", "final", "int", "SCTP_FLAG_EOF", "=", "(", "8", ")", ";", "public", "static", "final", "int", "SCTP_FLAG_SNDALL", "=", "(", "16", ")", ";", "public", "static", "final", "int", "SCTP_FLAG_HB_ENABLE", "=", "(", "1", ")", ";", "public", "static", "final", "int", "SCTP_FLAG_HB_DISABLE", "=", "(", "2", ")", ";", "public", "static", "final", "int", "SCTP_FLAG_HB_DEMAND", "=", "(", "4", ")", ";", "public", "static", "final", "int", "SCTP_FLAG_PMTUD_ENABLE", "=", "(", "8", ")", ";", "public", "static", "final", "int", "SCTP_FLAG_PMTUD_DISABLE", "=", "(", "16", ")", ";", "public", "static", "final", "int", "SCTP_FLAG_SACDELAY_ENABLE", "=", "(", "32", ")", ";", "public", "static", "final", "int", "SCTP_FLAG_SACDELAY_DISABLE", "=", "(", "64", ")", ";", "public", "static", "final", "int", "INET_DEF_BUFFER", "=", "1460", ";", "public", "static", "final", "int", "INET_MIN_BUFFER", "=", "1", ";", "public", "static", "final", "int", "INET_MAX_BUFFER", "=", "(", "1024", "*", "64", ")", ";", "public", "static", "final", "byte", "[", "]", "EXBADPORT", "=", "\"exbadport\"", ".", "getBytes", "(", "Charset", ".", "forName", "(", "\"ASCII\"", ")", ")", ";", "public", "static", "final", "byte", "[", "]", "EXBADSEQ", "=", "\"exbadseq\"", ".", "getBytes", "(", "Charset", ".", "forName", "(", "\"ASCII\"", ")", ")", ";", "public", "static", "final", "int", "INET_HIGH_WATERMARK", "=", "(", "1024", "*", "8", ")", ";", "public", "static", "final", "int", "INET_LOW_WATERMARK", "=", "(", "1024", "*", "4", ")", ";", "public", "static", "final", "int", "INET_INFINITY", "=", "0xffffffff", ";", "private", "static", "final", "EAtom", "am_inet_async", "=", "EAtom", ".", "intern", "(", "\"inet_async\"", ")", ";", "private", "static", "final", "EAtom", "am_inet_reply", "=", "EAtom", ".", "intern", "(", "\"inet_reply\"", ")", ";", "private", "static", "final", "int", "INVALID_EVENT", "=", "0xffff0000", ";", "private", "static", "final", "int", "SOL_SOCKET", "=", "0xffff", ";", "private", "static", "final", "EAtom", "am_closed", "=", "EAtom", ".", "intern", "(", "\"closed\"", ")", ";", "private", "static", "final", "EAtom", "am_empty_out_q", "=", "EAtom", ".", "intern", "(", "\"empty_out_q\"", ")", ";", "private", "static", "final", "EAtom", "am_tcp", "=", "EAtom", ".", "intern", "(", "\"tcp\"", ")", ";", "private", "static", "final", "EAtom", "am_tcp_closed", "=", "EAtom", ".", "intern", "(", "\"tcp_closed\"", ")", ";", "private", "static", "final", "EAtom", "am_timeout", "=", "EAtom", ".", "intern", "(", "\"timeout\"", ")", ";", "private", "static", "final", "EAtom", "am_tcp_error", "=", "EAtom", ".", "intern", "(", "\"tcp_error\"", ")", ";", "private", "static", "final", "byte", "[", "]", "NOPROC", "=", "new", "byte", "[", "]", "{", "'n'", ",", "'o'", ",", "'p'", ",", "'r'", ",", "'o'", ",", "'c'", "}", ";", "private", "static", "final", "PacketCallbacks", "<", "TCPINet", ">", "INET_CALLBACKS", "=", "new", "TCPINetCallbacks", "(", ")", ";", "private", "int", "state", "=", "INET_STATE_CLOSED", ";", "private", "InetSocket", "fd", ";", "private", "List", "<", "EHandle", ">", "empty_out_q_subs", "=", "new", "ArrayList", "<", "EHandle", ">", "(", "1", ")", ";", "private", "InetSocketAddress", "remote", ";", "ActiveType", "active", "=", "ActiveType", ".", "PASSIVE", ";", "private", "RingQueue", "<", "AsyncOp", ">", "opt", "=", "new", "RingQueue", "<", "AsyncOp", ">", "(", "1", ")", ";", "private", "boolean", "busy_on_send", ";", "private", "EHandle", "caller", ";", "private", "EHandle", "busy_caller", ";", "private", "int", "i_remain", ";", "private", "boolean", "send_timeout_close", ";", "private", "AsyncMultiOp", "multi_last", ";", "private", "AsyncMultiOp", "multi_first", ";", "private", "PriorityQueue", "<", "MultiTimerData", ">", "mtd_queue", ";", "private", "boolean", "prebound", ";", "private", "int", "event_mask", ";", "PacketParseType", "htype", "=", "PacketParseType", ".", "TCP_PB_RAW", ";", "private", "int", "hsz", ";", "private", "int", "mode", "=", "INET_MODE_LIST", ";", "private", "int", "deliver", "=", "INET_DELIVER_TERM", ";", "private", "int", "bufsz", "=", "1200", ";", "private", "boolean", "exitf", "=", "true", ";", "private", "int", "psize", ";", "private", "boolean", "bit8f", "=", "false", ";", "private", "boolean", "bit8", "=", "false", ";", "private", "int", "low", "=", "INET_LOW_WATERMARK", ";", "private", "int", "high", "=", "INET_HIGH_WATERMARK", ";", "private", "int", "send_timeout", "=", "INET_INFINITY", ";", "private", "int", "tcp_add_flags", ";", "private", "int", "read_packets", ";", "private", "Protocol", "protocol", ";", "private", "ProtocolType", "stype", ";", "private", "ProtocolFamily", "sfamily", ";", "private", "ByteBuffer", "i_buf", ";", "private", "int", "i_ptr_start", ";", "private", "IntCell", "http_state", "=", "new", "IntCell", "(", ")", ";", "private", "PacketCallbacks", "<", "TCPINet", ">", "packet_callbacks", "=", "INET_CALLBACKS", ";", "private", "int", "recv_cnt", ";", "private", "int", "recv_max", ";", "private", "double", "recv_avg", ";", "private", "double", "recv_dvi", ";", "private", "int", "send_cnt", ";", "private", "int", "send_max", ";", "private", "double", "send_avg", ";", "private", "long", "recv_oct", ";", "private", "long", "send_oct", ";", "public", "TCPINet", "(", "Protocol", "protocol", ",", "Driver", "driver", ")", "{", "super", "(", "driver", ")", ";", "this", ".", "protocol", "=", "protocol", ";", "this", ".", "bufsz", "=", "INET_DEF_BUFFER", ";", "}", "public", "TCPINet", "copy", "(", "EPID", "caller", ",", "InetSocket", "sock", ")", "{", "TCPINet", "copy", ";", "try", "{", "copy", "=", "(", "TCPINet", ")", "this", ".", "clone", "(", ")", ";", "}", "catch", "(", "CloneNotSupportedException", "e", ")", "{", "throw", "new", "InternalError", "(", "\"cannot", "clone\"", ")", ";", "}", "copy", ".", "fd", "=", "sock", ";", "copy", ".", "caller", "=", "caller", ";", "copy", ".", "opt", "=", "new", "RingQueue", "<", "AsyncOp", ">", "(", "2", ")", ";", "copy", ".", "empty_out_q_subs", "=", "new", "ArrayList", "<", "EHandle", ">", "(", ")", ";", "copy", ".", "active", "=", "ActiveType", ".", "PASSIVE", ";", "final", "EDriverTask", "this_task", "=", "port", "(", ")", ".", "task", "(", ")", ";", "EDriverTask", "driver", "=", "new", "EDriverTask", "(", "caller", ",", "copy", ")", "{", "public", "EObject", "getName", "(", ")", "{", "return", "this_task", ".", "getName", "(", ")", ";", "}", "}", ";", "EInternalPID", "caller_pid", "=", "caller", ".", "testInternalPID", "(", ")", ";", "if", "(", "caller_pid", "!=", "null", ")", "{", "caller_pid", ".", "task", "(", ")", ".", "link_oneway", "(", "driver", ".", "self_handle", "(", ")", ")", ";", "driver", ".", "link_oneway", "(", "caller_pid", ")", ";", "}", "ERT", ".", "run", "(", "driver", ")", ";", "return", "copy", ";", "}", "@", "Override", "protected", "void", "flush", "(", ")", "throws", "Pausable", "{", "throw", "new", "erjang", ".", "NotImplemented", "(", ")", ";", "}", "@", "Override", "protected", "void", "output", "(", "EHandle", "caller", ",", "ByteBuffer", "buf", ")", "throws", "IOException", ",", "Pausable", "{", "this", ".", "caller", "=", "caller", ";", "if", "(", "!", "is_connected", "(", ")", ")", "{", "inet_reply_error", "(", "Posix", ".", "ENOTCONN", ")", ";", "}", "else", "if", "(", "tcp_sendv", "(", "new", "ByteBuffer", "[", "]", "{", "buf", "}", ")", "==", "0", ")", "{", "inet_reply_ok", "(", "caller", ")", ";", "}", "throw", "new", "erjang", ".", "NotImplemented", "(", ")", ";", "}", "@", "Override", "protected", "void", "outputv", "(", "EHandle", "caller", ",", "ByteBuffer", "[", "]", "ev", ")", "throws", "IOException", ",", "Pausable", "{", "this", ".", "caller", "=", "caller", ";", "if", "(", "log", ".", "isLoggable", "(", "Level", ".", "FINEST", ")", ")", "{", "dump_buffer", "(", "log", ",", "\"\"", ",", "ev", ")", ";", "}", "if", "(", "!", "is_connected", "(", ")", ")", "{", "if", "(", "(", "tcp_add_flags", "&", "TCP_ADDF_DELAYED_CLOSE_SEND", ")", "!=", "0", ")", "{", "tcp_add_flags", "&=", "~", "TCP_ADDF_DELAYED_CLOSE_SEND", ";", "inet_reply_error", "(", "am_closed", ")", ";", "}", "else", "{", "inet_reply_error", "(", "Posix", ".", "ENOTCONN", ")", ";", "}", "}", "else", "if", "(", "tcp_sendv", "(", "ev", ")", "==", "0", ")", "{", "inet_reply_ok", "(", "caller", ")", ";", "}", "else", "{", "log", ".", "fine", "(", "\"bad", "output\"", ")", ";", "}", "}", "private", "int", "tcp_sendv", "(", "ByteBuffer", "[", "]", "ev", ")", "throws", "Pausable", "{", "int", "sz", ";", "EPort", "ix", "=", "port", "(", ")", ";", "long", "len", "=", "remaining", "(", "ev", ")", ";", "ByteBuffer", "hbuf", "=", "null", ";", "switch", "(", "htype", ")", "{", "case", "TCP_PB_1", ":", "hbuf", "=", "ByteBuffer", ".", "allocate", "(", "1", ")", ";", "hbuf", ".", "put", "(", "0", ",", "(", "byte", ")", "(", "len", "&", "0xff", ")", ")", ";", "break", ";", "case", "TCP_PB_2", ":", "hbuf", "=", "ByteBuffer", ".", "allocate", "(", "2", ")", ";", "hbuf", ".", "putShort", "(", "0", ",", "(", "short", ")", "(", "len", "&", "0xffff", ")", ")", ";", "break", ";", "case", "TCP_PB_4", ":", "hbuf", "=", "ByteBuffer", ".", "allocate", "(", "4", ")", ";", "hbuf", ".", "putInt", "(", "0", ",", "(", "int", ")", "len", ")", ";", "break", ";", "default", ":", "if", "(", "len", "==", "0", ")", "{", "return", "0", ";", "}", "}", "inet_output_count", "(", "len", "+", "(", "hbuf", "==", "null", "?", "0", ":", "hbuf", ".", "limit", "(", ")", ")", ")", ";", "if", "(", "hbuf", "!=", "null", ")", "{", "len", "+=", "hbuf", ".", "remaining", "(", ")", ";", "if", "(", "ev", ".", "length", ">", "0", "&&", "ev", "[", "0", "]", ".", "remaining", "(", ")", "==", "0", ")", "{", "ev", "[", "0", "]", "=", "hbuf", ";", "}", "else", "{", "ByteBuffer", "[", "]", "ev2", "=", "new", "ByteBuffer", "[", "ev", ".", "length", "+", "1", "]", ";", "ev2", "[", "0", "]", "=", "hbuf", ";", "System", ".", "arraycopy", "(", "ev", ",", "0", ",", "ev2", ",", "1", ",", "ev", ".", "length", ")", ";", "ev", "=", "ev2", ";", "}", "}", "if", "(", "(", "sz", "=", "driver_sizeq", "(", ")", ")", ">", "0", ")", "{", "driver_enqv", "(", "ev", ")", ";", "sock_select", "(", "ERL_DRV_WRITE", ",", "SelectMode", ".", "SET", ")", ";", "if", "(", "sz", "+", "len", ">=", "high", ")", "{", "state", "|=", "INET_F_BUSY", ";", "busy_caller", "=", "caller", ";", "set_busy_port", "(", "port", "(", ")", ",", "true", ")", ";", "if", "(", "this", ".", "send_timeout", "!=", "INET_INFINITY", ")", "{", "busy_on_send", "=", "true", ";", "driver_set_timer", "(", "send_timeout", ")", ";", "}", "return", "1", ";", "}", "}", "else", "{", "int", "vsize", "=", "ev", ".", "length", ";", "long", "n", ";", "if", "(", "(", "tcp_add_flags", "&", "TCP_ADDF_DELAY_SEND", ")", "!=", "0", ")", "{", "if", "(", "log", ".", "isLoggable", "(", "Level", ".", "FINE", ")", ")", "log", ".", "fine", "(", "\"\"", ")", ";", "n", "=", "0", ";", "}", "else", "{", "GatheringByteChannel", "gbc", "=", "(", "GatheringByteChannel", ")", "fd", ".", "channel", "(", ")", ";", "try", "{", "n", "=", "gbc", ".", "write", "(", "ev", ")", ";", "}", "catch", "(", "IOException", "e", ")", "{", "int", "sock_errno", "=", "IO", ".", "exception_to_posix_code", "(", "e", ")", ";", "if", "(", "(", "sock_errno", "!=", "Posix", ".", "EAGAIN", ")", "&&", "(", "sock_errno", "!=", "Posix", ".", "EINTR", ")", ")", "{", "tcp_send_error", "(", "sock_errno", ")", ";", "return", "sock_errno", ";", "}", "n", "=", "0", ";", "}", "}", "if", "(", "n", "==", "len", ")", "{", "assert", "empty_out_q_subs", ".", "isEmpty", "(", ")", ":", "\"\"", ";", "return", "0", ";", "}", "driver_enqv", "(", "ev", ")", ";", "sock_select", "(", "ERL_DRV_WRITE", "|", "0", ",", "SelectMode", ".", "SET", ")", ";", "}", "return", "0", ";", "}", "private", "void", "inet_output_count", "(", "long", "len", ")", "{", "this", ".", "send_oct", "+=", "len", ";", "this", ".", "send_cnt", "+=", "1", ";", "if", "(", "len", ">", "send_max", ")", "send_max", "=", "(", "int", ")", "len", ";", "}", "private", "long", "remaining", "(", "ByteBuffer", "[", "]", "ev", ")", "{", "long", "res", "=", "0", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "ev", ".", "length", ";", "i", "++", ")", "{", "if", "(", "ev", "[", "i", "]", "!=", "null", ")", "{", "res", "+=", "ev", "[", "i", "]", ".", "remaining", "(", ")", ";", "}", "}", "return", "res", ";", "}", "@", "Override", "public", "void", "processExit", "(", "ERef", "monitor", ")", "throws", "Pausable", "{", "EHandle", "who", "=", "driver_get_monitored_process", "(", "monitor", ")", ";", "int", "state", "=", "this", ".", "state", ";", "if", "(", "(", "state", "&", "TCP_STATE_MULTI_ACCEPTING", ")", "==", "TCP_STATE_MULTI_ACCEPTING", ")", "{", "AsyncMultiOp", "op", ";", "if", "(", "(", "op", "=", "remove_multi_op", "(", "who", ")", ")", "==", "null", ")", "{", "return", ";", "}", "if", "(", "op", ".", "timeout", "!=", "null", ")", "{", "remove_multi_timer", "(", "op", ".", "timeout", ")", ";", "}", "if", "(", "this", ".", "multi_first", "==", "null", ")", "{", "sock_select", "(", "ERL_DRV_ACCEPT", ",", "SelectMode", ".", "CLEAR", ")", ";", "this", ".", "state", "=", "TCP_STATE_LISTEN", ";", "}", "}", "else", "if", "(", "(", "state", "&", "TCP_STATE_ACCEPTING", ")", "==", "TCP_STATE_ACCEPTING", ")", "{", "deq_async", "(", ")", ";", "driver_cancel_timer", "(", ")", ";", "sock_select", "(", "ERL_DRV_ACCEPT", ",", "SelectMode", ".", "CLEAR", ")", ";", "this", ".", "state", "=", "TCP_STATE_LISTEN", ";", "}", "}", "private", "void", "sock_select", "(", "int", "ops", ",", "SelectMode", "onOff", ")", "{", "if", "(", "onOff", "==", "SelectMode", ".", "SET", ")", "{", "this", ".", "event_mask", "|=", "ops", ";", "}", "else", "{", "this", ".", "event_mask", "&=", "~", "ops", ";", "}", "if", "(", "log", ".", "isLoggable", "(", "Level", ".", "FINE", ")", ")", "log", ".", "fine", "(", "\"sock_select", "\"", "+", "this", "+", "\"", "ops=\"", "+", "Integer", ".", "toBinaryString", "(", "ops", ")", "+", "\";", "mode=\"", "+", "onOff", ")", ";", "super", ".", "select", "(", "this", ".", "fd", ".", "channel", "(", ")", ",", "ops", ",", "onOff", ")", ";", "}", "private", "void", "remove_multi_timer", "(", "MultiTimerData", "p", ")", "{", "boolean", "is_first", "=", "mtd_queue", ".", "peek", "(", ")", "==", "p", ";", "mtd_queue", ".", "remove", "(", "p", ")", ";", "if", "(", "is_first", ")", "{", "driver_cancel_timer", "(", ")", ";", "MultiTimerData", "first", "=", "mtd_queue", ".", "peek", "(", ")", ";", "if", "(", "first", "!=", "null", ")", "{", "long", "timeout", "=", "relative_timeout", "(", "first", ".", "when", ")", ";", "driver_set_timer", "(", "timeout", ")", ";", "}", "}", "}", "private", "long", "relative_timeout", "(", "long", "abs_time", ")", "{", "long", "now", "=", "System", ".", "currentTimeMillis", "(", ")", ";", "if", "(", "abs_time", "<", "now", ")", "return", "0", ";", "else", "return", "abs_time", "-", "now", ";", "}", "@", "Override", "protected", "void", "readyAsync", "(", "EAsync", "data", ")", "throws", "Pausable", "{", "throw", "new", "erjang", ".", "NotImplemented", "(", ")", ";", "}", "@", "Override", "protected", "void", "readyInput", "(", "SelectableChannel", "ch", ")", "throws", "Pausable", "{", "if", "(", "fd", "==", "null", "||", "fd", ".", "channel", "(", ")", "==", "null", ")", "return", ";", "if", "(", "!", "is_open", "(", ")", ")", "return", ";", "if", "(", "ch", ".", "isOpen", "(", ")", ")", "select", "(", "ch", ",", "ERL_DRV_READ", ",", "SelectMode", ".", "SET", ")", ";", "if", "(", "log", ".", "isLoggable", "(", "Level", ".", "FINE", ")", ")", "log", ".", "fine", "(", "\"readyInput", "\"", "+", "this", "+", "\"", "@", "\"", "+", "ch", ")", ";", "if", "(", "is_connected", "(", ")", ")", "{", "int", "rcv", "=", "tcp_recv", "(", "0", ")", ";", "if", "(", "log", ".", "isLoggable", "(", "Level", ".", "FINE", ")", ")", "log", ".", "fine", "(", "\"\"", "+", "rcv", ")", ";", "}", "else", "{", "if", "(", "log", ".", "isLoggable", "(", "Level", ".", "FINE", ")", ")", "log", ".", "fine", "(", "\"\"", ")", ";", "}", "}", "private", "int", "tcp_recv", "(", "int", "request_len", ")", "throws", "Pausable", "{", "if", "(", "log", ".", "isLoggable", "(", "Level", ".", "FINER", ")", ")", "log", ".", "finer", "(", "\"\"", "+", "request_len", ")", ";", "int", "n", ",", "len", ",", "nread", ";", "if", "(", "i_buf", "==", "null", ")", "{", "if", "(", "log", ".", "isLoggable", "(", "Level", ".", "FINER", ")", ")", "log", ".", "finer", "(", "\"\"", ")", ";", "int", "sz", "=", "(", "request_len", ">", "0", ")", "?", "request_len", ":", "this", ".", "bufsz", ";", "try", "{", "i_buf", "=", "ByteBuffer", ".", "allocate", "(", "sz", ")", ";", "}", "catch", "(", "OutOfMemoryError", "e", ")", "{", "return", "-", "1", ";", "}", "i_ptr_start", "=", "0", ";", "nread", "=", "sz", ";", "if", "(", "request_len", ">", "0", ")", "{", "i_remain", "=", "request_len", ";", "}", "else", "{", "i_remain", "=", "0", ";", "}", "}", "else", "if", "(", "request_len", ">", "0", ")", "{", "n", "=", "i_buf", ".", "position", "(", ")", "-", "i_ptr_start", ";", "if", "(", "log", ".", "isLoggable", "(", "Level", ".", "FINER", ")", ")", "log", ".", "finer", "(", "\"\"", "+", "n", "+", "\"", "bytes\"", ")", ";", "if", "(", "n", ">=", "request_len", ")", "{", "return", "tcp_deliver", "(", "request_len", ")", ";", "}", "else", "if", "(", "tcp_expand_buffer", "(", "request_len", ")", "<", "0", ")", "{", "return", "tcp_recv_error", "(", "Posix", ".", "ENOMEM", ")", ";", "}", "else", "{", "i_remain", "=", "nread", "=", "request_len", "-", "n", ";", "}", "}", "else", "if", "(", "i_remain", "==", "0", ")", "{", "if", "(", "log", ".", "isLoggable", "(", "Level", ".", "FINER", ")", ")", "log", ".", "finer", "(", "\"\"", ")", ";", "int", "[", "]", "lenp", "=", "new", "int", "[", "1", "]", ";", "if", "(", "(", "nread", "=", "tcp_remain", "(", "lenp", ")", ")", "<", "0", ")", "{", "return", "tcp_recv_error", "(", "Posix", ".", "EMSGSIZE", ")", ";", "}", "else", "if", "(", "nread", "==", "0", ")", "{", "return", "tcp_deliver", "(", "lenp", "[", "0", "]", ")", ";", "}", "else", "if", "(", "lenp", "[", "0", "]", ">", "0", ")", "{", "i_remain", "=", "lenp", "[", "0", "]", ";", "}", "}", "else", "{", "if", "(", "log", ".", "isLoggable", "(", "Level", ".", "FINER", ")", ")", "log", ".", "finer", "(", "\"\"", "+", "i_remain", ")", ";", "nread", "=", "i_remain", ";", "}", "try", "{", "ReadableByteChannel", "rbc", "=", "(", "ReadableByteChannel", ")", "fd", ".", "channel", "(", ")", ";", "if", "(", "rbc", "instanceof", "SocketChannel", ")", "{", "SocketChannel", "sc", "=", "(", "SocketChannel", ")", "rbc", ";", "if", "(", "sc", ".", "isBlocking", "(", ")", ")", "{", "log", ".", "fine", "(", "\"\"", "+", "sc", ")", ";", "}", "}", "else", "{", "log", ".", "warning", "(", "\"\"", "+", "rbc", ")", ";", "}", "i_buf", ".", "limit", "(", "Math", ".", "min", "(", "i_buf", ".", "position", "(", ")", "+", "nread", ",", "i_buf", ".", "capacity", "(", ")", ")", ")", ";", "n", "=", "rbc", ".", "read", "(", "i_buf", ")", ";", "if", "(", "log", ".", "isLoggable", "(", "Level", ".", "FINER", ")", ")", "log", ".", "finer", "(", "\"did", "read", "\"", "+", "n", "+", "\"\"", "+", "i_buf", ".", "remaining", "(", ")", "+", "\")\"", ")", ";", "if", "(", "n", "==", "0", ")", "return", "0", ";", "}", "catch", "(", "ClosedChannelException", "e", ")", "{", "return", "tcp_recv_closed", "(", ")", ";", "}", "catch", "(", "IOException", "e", ")", "{", "int", "code", "=", "IO", ".", "exception_to_posix_code", "(", "e", ")", ";", "if", "(", "code", "==", "Posix", ".", "ENOTCONN", "||", "!", "fd", ".", "isOpen", "(", ")", ")", "return", "tcp_recv_closed", "(", ")", ";", "else", "return", "tcp_recv_error", "(", "IO", ".", "exception_to_posix_code", "(", "e", ")", ")", ";", "}", "if", "(", "n", "<", "0", ")", "{", "try", "{", "fd", ".", "channel", "(", ")", ".", "close", "(", ")", ";", "}", "catch", "(", "IOException", "e", ")", "{", "}", "return", "tcp_recv_closed", "(", ")", ";", "}", "if", "(", "i_remain", ">", "0", ")", "{", "i_remain", "-=", "n", ";", "if", "(", "i_remain", "==", "0", ")", "{", "return", "tcp_deliver", "(", "i_buf", ".", "position", "(", ")", "-", "i_ptr_start", ")", ";", "}", "}", "else", "{", "int", "[", "]", "lenp", "=", "new", "int", "[", "1", "]", ";", "nread", "=", "tcp_remain", "(", "lenp", ")", ";", "if", "(", "(", "nread", ")", "<", "0", ")", "{", "return", "tcp_recv_error", "(", "Posix", ".", "EMSGSIZE", ")", ";", "}", "else", "if", "(", "nread", "==", "0", ")", "{", "return", "tcp_deliver", "(", "lenp", "[", "0", "]", ")", ";", "}", "else", "if", "(", "lenp", "[", "0", "]", ">", "0", ")", "{", "i_remain", "=", "lenp", "[", "0", "]", ";", "}", "}", "return", "0", ";", "}", "private", "int", "tcp_recv_closed", "(", ")", "throws", "Pausable", "{", "if", "(", "is_busy", "(", ")", ")", "{", "caller", "=", "busy_caller", ";", "tcp_clear_output", "(", ")", ";", "if", "(", "busy_on_send", ")", "{", "driver_cancel_timer", "(", ")", ";", "busy_on_send", "=", "false", ";", "}", "state", "&=", "~", "INET_F_BUSY", ";", "set_busy_port", "(", "false", ")", ";", "inet_reply_error", "(", "am_closed", ")", ";", "}", "if", "(", "active", "==", "ActiveType", ".", "PASSIVE", ")", "{", "driver_cancel_timer", "(", ")", ";", "tcp_clear_input", "(", ")", ";", "if", "(", "exitf", ")", "{", "tcp_clear_output", "(", ")", ";", "desc_close", "(", ")", ";", "}", "else", "{", "desc_close_read", "(", ")", ";", "}", "async_error_all", "(", "am_closed", ")", ";", "}", "else", "{", "tcp_clear_input", "(", ")", ";", "tcp_closed_message", "(", ")", ";", "if", "(", "exitf", ")", "{", "driver_exit", "(", "0", ")", ";", "}", "else", "{", "desc_close_read", "(", ")", ";", "}", "}", "return", "-", "1", ";", "}", "private", "void", "tcp_clear_output", "(", ")", "throws", "Pausable", "{", "int", "qsz", "=", "driver_sizeq", "(", ")", ";", "ByteBuffer", "[", "]", "q", "=", "driver_peekq", "(", ")", ";", "if", "(", "q", "!=", "null", ")", "{", "for", "(", "int", "i", "=", "0", ";", "i", "<", "q", ".", "length", ";", "i", "++", ")", "{", "if", "(", "q", "[", "i", "]", "!=", "null", ")", "{", "q", "[", "i", "]", ".", "position", "(", "q", "[", "i", "]", ".", "limit", "(", ")", ")", ";", "}", "}", "}", "driver_deq", "(", "qsz", ")", ";", "send_empty_out_q_msgs", "(", ")", ";", "}", "private", "int", "tcp_recv_error", "(", "int", "err", ")", "throws", "Pausable", "{", "if", "(", "err", "==", "Posix", ".", "EAGAIN", ")", "{", "return", "0", ";", "}", "if", "(", "is_busy", "(", ")", ")", "{", "caller", "=", "busy_caller", ";", "tcp_clear_output", "(", ")", ";", "if", "(", "busy_on_send", ")", "{", "driver_cancel_timer", "(", ")", ";", "busy_on_send", "=", "false", ";", "}", "state", "&=", "~", "INET_F_BUSY", ";", "set_busy_port", "(", "false", ")", ";", "inet_reply_error", "(", "am_closed", ")", ";", "}", "if", "(", "active", "==", "ActiveType", ".", "PASSIVE", ")", "{", "driver_cancel_timer", "(", ")", ";", "tcp_clear_input", "(", ")", ";", "if", "(", "exitf", ")", "{", "desc_close", "(", ")", ";", "}", "else", "{", "desc_close_read", "(", ")", ";", "}", "async_error_all", "(", "EAtom", ".", "intern", "(", "Posix", ".", "errno_id", "(", "err", ")", ")", ")", ";", "}", "else", "{", "tcp_clear_input", "(", ")", ";", "tcp_error_message", "(", "err", ")", ";", "tcp_closed_message", "(", ")", ";", "if", "(", "exitf", ")", "driver_exit", "(", "err", ")", ";", "else", "desc_close", "(", ")", ";", "}", "return", "-", "1", ";", "}", "private", "void", "tcp_error_message", "(", "int", "err", ")", "throws", "Pausable", "{", "ETuple", "spec", "=", "ETuple", ".", "make", "(", "am_tcp_error", ",", "port", "(", ")", ",", "EAtom", ".", "intern", "(", "Posix", ".", "errno_id", "(", "err", ")", ")", ")", ";", "driver_output_term", "(", "spec", ")", ";", "}", "@", "Override", "protected", "void", "readyOutput", "(", "SelectableChannel", "evt", ")", "throws", "Pausable", "{", "EInternalPort", "ix", "=", "port", "(", ")", ";", "if", "(", "is_connected", "(", ")", ")", "{", "ByteBuffer", "[", "]", "iov", ";", "if", "(", "(", "iov", "=", "driver_peekq", "(", ")", ")", "==", "null", ")", "{", "select", "(", "evt", ",", "ERL_DRV_WRITE", ",", "SelectMode", ".", "CLEAR", ")", ";", "send_empty_out_q_msgs", "(", ")", ";", "return", ";", "}", "GatheringByteChannel", "gbc", "=", "(", "GatheringByteChannel", ")", "fd", ".", "channel", "(", ")", ";", "long", "n", ";", "try", "{", "n", "=", "gbc", ".", "write", "(", "iov", ")", ";", "}", "catch", "(", "IOException", "e", ")", "{", "tcp_send_error", "(", "IO", ".", "exception_to_posix_code", "(", "e", ")", ")", ";", "return", ";", "}", "driver_deq", "(", "n", ")", ";", "int", "dsq", "=", "driver_sizeq", "(", ")", ";", "if", "(", "dsq", "!=", "0", ")", "{", "select", "(", "evt", ",", "ERL_DRV_WRITE", ",", "SelectMode", ".", "SET", ")", ";", "}", "if", "(", "dsq", "<=", "low", ")", "{", "if", "(", "is_busy", "(", ")", ")", "{", "this", ".", "caller", "=", "busy_caller", ";", "state", "&=", "~", "INET_F_BUSY", ";", "set_busy_port", "(", "port", "(", ")", ",", "false", ")", ";", "if", "(", "busy_on_send", ")", "{", "driver_cancel_timer", "(", ")", ";", "busy_on_send", "=", "false", ";", "}", "inet_reply_ok", "(", "caller", ")", ";", "}", "}", "}", "}", "private", "void", "set_busy_port", "(", "EInternalPort", "port", ",", "boolean", "on", ")", "{", "if", "(", "on", ")", "{", "task", ".", "status", "|=", "EDriverTask", ".", "ERTS_PORT_SFLG_PORT_BUSY", ";", "}", "else", "{", "task", ".", "status", "&=", "~", "EDriverTask", ".", "ERTS_PORT_SFLG_PORT_BUSY", ";", "}", "}", "private", "void", "inet_reply_ok", "(", "EHandle", "caller2", ")", "throws", "Pausable", "{", "ETuple", "msg", "=", "ETuple", ".", "make", "(", "am_inet_reply", ",", "port", "(", ")", ",", "ERT", ".", "am_ok", ")", ";", "EHandle", "caller", "=", "this", ".", "caller", ";", "this", ".", "caller", "=", "null", ";", "if", "(", "log", ".", "isLoggable", "(", "Level", ".", "FINER", ")", "&&", "caller", "!=", "null", ")", "{", "log", ".", "finer", "(", "\"sending", "to", "\"", "+", "caller", "+", "\"", "!", "\"", "+", "msg", ")", ";", "}", "driver_send_term", "(", "caller", ",", "msg", ")", ";", "}", "private", "void", "tcp_send_error", "(", "int", "err", ")", "throws", "Pausable", "{", "if", "(", "is_busy", "(", ")", ")", "{", "caller", "=", "busy_caller", ";", "tcp_clear_output", "(", ")", ";", "if", "(", "busy_on_send", ")", "{", "driver_cancel_timer", "(", ")", ";", "busy_on_send", "=", "false", ";", "}", "state", "&=", "~", "INET_F_BUSY", ";", "set_busy_port", "(", "false", ")", ";", "}", "if", "(", "active", "!=", "ActiveType", ".", "PASSIVE", ")", "{", "tcp_closed_message", "(", ")", ";", "inet_reply_error", "(", "am_closed", ")", ";", "if", "(", "exitf", ")", "{", "driver_exit", "(", "0", ")", ";", "}", "else", "{", "try", "{", "fd", ".", "close", "(", ")", ";", "}", "catch", "(", "IOException", "e", ")", "{", "}", "}", "}", "else", "{", "tcp_clear_output", "(", ")", ";", "tcp_clear_input", "(", ")", ";", "tcp_close_check", "(", ")", ";", "erl_inet_close", "(", ")", ";", "if", "(", "caller", "!=", "null", ")", "{", "inet_reply_error", "(", "am_closed", ")", ";", "}", "else", "{", "tcp_add_flags", "|=", "TCP_ADDF_DELAYED_CLOSE_SEND", ";", "}", "tcp_add_flags", "|=", "TCP_ADDF_DELAYED_CLOSE_RECV", ";", "}", "}", "private", "void", "tcp_close_check", "(", ")", "throws", "Pausable", "{", "if", "(", "state", "==", "TCP_STATE_ACCEPTING", ")", "{", "AsyncOp", "op", "=", "opt", ".", "peek", "(", ")", ";", "sock_select", "(", "ERL_DRV_ACCEPT", ",", "SelectMode", ".", "CLEAR", ")", ";", "state", "=", "TCP_STATE_LISTEN", ";", "if", "(", "op", "!=", "null", ")", "{", "driver_demonitor_process", "(", "op", ".", "monitor", ")", ";", "}", "async_error", "(", "am_closed", ")", ";", "}", "else", "if", "(", "(", "state", "&", "TCP_STATE_MULTI_ACCEPTING", ")", "==", "TCP_STATE_MULTI_ACCEPTING", ")", "{", "throw", "new", "NotImplemented", "(", ")", ";", "}", "else", "if", "(", "(", "state", "&", "TCP_STATE_CONNECTING", ")", "==", "TCP_STATE_CONNECTING", ")", "{", "async_error", "(", "am_closed", ")", ";", "}", "else", "if", "(", "(", "state", "&", "TCP_STATE_CONNECTED", ")", "==", "TCP_STATE_CONNECTED", ")", "{", "async_error_all", "(", "am_closed", ")", ";", "}", "}", "private", "void", "async_error_all", "(", "EAtom", "reason", ")", "throws", "Pausable", "{", "for", "(", "AsyncOp", "op", "=", "deq_async", "(", ")", ";", "op", "!=", "null", ";", "op", "=", "deq_async", "(", ")", ")", "{", "send_async_error", "(", "op", ".", "id", ",", "op", ".", "caller", ",", "reason", ")", ";", "}", "}", "private", "void", "send_empty_out_q_msgs", "(", ")", "throws", "Pausable", "{", "if", "(", "empty_out_q_subs", ".", "isEmpty", "(", ")", ")", "return", ";", "ETuple2", "msg", "=", "new", "ETuple2", "(", "am_empty_out_q", ",", "port", "(", ")", ")", ";", "for", "(", "EHandle", "h", ":", "empty_out_q_subs", ")", "{", "h", ".", "send", "(", "port", "(", ")", ",", "msg", ")", ";", "}", "}", "@", "Override", "public", "void", "readyAccept", "(", "SelectableChannel", "ch", ")", "throws", "Pausable", "{", "if", "(", "log", ".", "isLoggable", "(", "Level", ".", "FINE", ")", ")", "log", ".", "fine", "(", "\"readyAccept", "\"", "+", "this", ")", ";", "if", "(", "state", "==", "TCP_STATE_ACCEPTING", ")", "{", "InetSocket", "sock", ";", "try", "{", "sock", "=", "fd", ".", "accept", "(", ")", ";", "}", "catch", "(", "IOException", "e", ")", "{", "sock", "=", "null", ";", "}", "sock_select", "(", "ERL_DRV_ACCEPT", ",", "SelectMode", ".", "CLEAR", ")", ";", "state", "=", "TCP_STATE_LISTEN", ";", "AsyncOp", "peek", "=", "opt", ".", "peek", "(", ")", ";", "if", "(", "peek", "!=", "null", ")", "{", "driver_demonitor_process", "(", "peek", ".", "monitor", ")", ";", "}", "driver_cancel_timer", "(", ")", ";", "if", "(", "sock", "==", "null", ")", "{", "}", "else", "{", "if", "(", "peek", "==", "null", ")", "{", "sock_close", "(", "fd", ".", "channel", "(", ")", ")", ";", "async_error", "(", "Posix", ".", "EINVAL", ")", ";", "return", ";", "}", "TCPINet", "accept_desc", "=", "this", ".", "copy", "(", "peek", ".", "caller", ",", "sock", ")", ";", "accept_desc", ".", "state", "=", "TCP_STATE_CONNECTED", ";", "try", "{", "sock", ".", "setNonBlocking", "(", ")", ";", "}", "catch", "(", "IOException", "e", ")", "{", "e", ".", "printStackTrace", "(", ")", ";", "}", "async_ok_port", "(", "peek", ".", "caller", ",", "accept_desc", ".", "port", "(", ")", ")", ";", "}", "}", "else", "if", "(", "state", "==", "TCP_STATE_MULTI_ACCEPTING", ")", "{", "while", "(", "state", "==", "TCP_STATE_MULTI_ACCEPTING", ")", "{", "int", "err", "=", "0", ";", "InetSocket", "sock", ";", "try", "{", "sock", "=", "fd", ".", "accept", "(", ")", ";", "if", "(", "sock", "==", "null", ")", "{", "sock_select", "(", "ERL_DRV_ACCEPT", ",", "SelectMode", ".", "SET", ")", ";", "return", ";", "}", "}", "catch", "(", "IOException", "e", ")", "{", "sock", "=", "null", ";", "err", "=", "IO", ".", "exception_to_posix_code", "(", "e", ")", ";", "}", "AsyncMultiOp", "multi", "=", "deq_multi_op", "(", ")", ";", "if", "(", "multi", "==", "null", ")", "{", "return", ";", "}", "if", "(", "this", ".", "multi_first", "==", "null", ")", "{", "sock_select", "(", "ERL_DRV_ACCEPT", ",", "SelectMode", ".", "CLEAR", ")", ";", "state", "=", "TCP_STATE_LISTEN", ";", "}", "if", "(", "multi", ".", "timeout", "!=", "null", ")", "{", "remove_multi_timer", "(", "multi", ".", "timeout", ")", ";", "}", "driver_demonitor_process", "(", "multi", ".", "op", ".", "monitor", ")", ";", "if", "(", "sock", "==", "null", ")", "{", "send_async_error", "(", "multi", ".", "op", ".", "id", ",", "multi", ".", "op", ".", "caller", ",", "EAtom", ".", "intern", "(", "Posix", ".", "errno_id", "(", "err", ")", ".", "toLowerCase", "(", ")", ")", ")", ";", "}", "else", "{", "TCPINet", "accept_desc", "=", "this", ".", "copy", "(", "multi", ".", "op", ".", "caller", ",", "sock", ")", ";", "accept_desc", ".", "state", "=", "TCP_STATE_CONNECTED", ";", "try", "{", "sock", ".", "setNonBlocking", "(", ")", ";", "}", "catch", "(", "IOException", "e", ")", "{", "e", ".", "printStackTrace", "(", ")", ";", "}", "send_async_ok_port", "(", "multi", ".", "op", ".", "id", ",", "multi", ".", "op", ".", "caller", ",", "accept_desc", ".", "port", "(", ")", ")", ";", "}", "}", "}", "}", "@", "Override", "public", "void", "readyConnect", "(", "SelectableChannel", "evt", ")", "throws", "Pausable", "{", "if", "(", "log", ".", "isLoggable", "(", "Level", ".", "FINE", ")", ")", "log", ".", "fine", "(", "\"\"", "+", "this", ")", ";", "if", "(", "state", "==", "TCP_STATE_CONNECTING", ")", "{", "sock_select", "(", "ERL_DRV_CONNECT", ",", "SelectMode", ".", "CLEAR", ")", ";", "driver_cancel_timer", "(", ")", ";", "try", "{", "if", "(", "!", "fd", ".", "finishConnect", "(", ")", ")", "{", "async_error", "(", "Posix", ".", "EIO", ")", ";", "return", ";", "}", "else", "{", "state", "=", "TCP_STATE_CONNECTED", ";", "}", "}", "catch", "(", "IOException", "e", ")", "{", "async_error", "(", "IO", ".", "exception_to_posix_code", "(", "e", ")", ")", ";", "return", ";", "}", "if", "(", "active", "!=", "ActiveType", ".", "PASSIVE", ")", "{", "sock_select", "(", "ERL_DRV_READ", ",", "SelectMode", ".", "SET", ")", ";", "}", "async_ok", "(", ")", ";", "}", "else", "{", "sock_select", "(", "ERL_DRV_CONNECT", ",", "SelectMode", ".", "CLEAR", ")", ";", "}", "}", "private", "boolean", "async_error", "(", "int", "eio", ")", "throws", "Pausable", "{", "return", "async_error", "(", "EAtom", ".", "intern", "(", "Posix", ".", "errno_id", "(", "eio", ")", ".", "toLowerCase", "(", ")", ")", ")", ";", "}", "@", "Override", "protected", "void", "timeout", "(", ")", "throws", "Pausable", "{", "if", "(", "log", ".", "isLoggable", "(", "Level", ".", "FINE", ")", ")", "{", "log", ".", "fine", "(", "\"timeout", "\"", "+", "this", ")", ";", "}", "if", "(", "(", "state", "&", "INET_F_MULTI_CLIENT", ")", "!=", "0", ")", "{", "fire_multi_timers", "(", ")", ";", "}", "else", "if", "(", "(", "state", "&", "TCP_STATE_CONNECTED", ")", "==", "TCP_STATE_CONNECTED", ")", "{", "if", "(", "busy_on_send", ")", "{", "assert", "is_busy", "(", ")", ";", "caller", "=", "busy_caller", ";", "state", "&=", "~", "INET_F_BUSY", ";", "busy_on_send", "=", "false", ";", "set_busy_port", "(", "false", ")", ";", "inet_reply_error", "(", "ERT", ".", "am_timeout", ")", ";", "if", "(", "send_timeout_close", ")", "{", "erl_inet_close", "(", ")", ";", "}", "}", "else", "{", "assert", "active", "!=", "ActiveType", ".", "PASSIVE", ";", "sock_select", "(", "ERL_DRV_READ", "|", "ERL_DRV_WRITE", ",", "SelectMode", ".", "CLEAR", ")", ";", "i_remain", "=", "0", ";", "async_error", "(", "ERT", ".", "am_timeout", ")", ";", "}", "}", "else", "if", "(", "(", "state", "&", "TCP_STATE_CONNECTING", ")", "==", "TCP_STATE_CONNECTING", ")", "{", "erl_inet_close", "(", ")", ";", "async_error", "(", "ERT", ".", "am_timeout", ")", ";", "}", "else", "if", "(", "(", "state", "&", "TCP_STATE_ACCEPTING", ")", "==", "TCP_STATE_ACCEPTING", ")", "{", "AsyncOp", "this_op", "=", "opt", ".", "peek", "(", ")", ";", "sock_select", "(", "ERL_DRV_ACCEPT", ",", "SelectMode", ".", "CLEAR", ")", ";", "if", "(", "this_op", "!=", "null", ")", "{", "driver_demonitor_process", "(", "this_op", ".", "monitor", ")", ";", "}", "state", "=", "TCP_STATE_LISTEN", ";", "async_error", "(", "ERT", ".", "am_timeout", ")", ";", "}", "}", "private", "boolean", "is_busy", "(", ")", "{", "return", "(", "state", "&", "INET_F_BUSY", ")", "==", "INET_F_BUSY", ";", "}", "private", "void", "fire_multi_timers", "(", ")", "throws", "Pausable", "{", "long", "next_timeout", "=", "0", ";", "if", "(", "this", ".", "mtd_queue", "==", "null", "||", "this", ".", "mtd_queue", ".", "isEmpty", "(", ")", ")", "{", "throw", "new", "InternalError", "(", ")", ";", "}", "do", "{", "MultiTimerData", "save", "=", "mtd_queue", ".", "remove", "(", ")", ";", "tcp_inet_multi_timeout", "(", "save", ".", "caller", ")", ";", "if", "(", "mtd_queue", ".", "isEmpty", "(", ")", ")", "return", ";", "next_timeout", "=", "mtd_queue", ".", "peek", "(", ")", ".", "when", ";", "}", "while", "(", "next_timeout", "==", "0", ")", ";", "driver_set_timer", "(", "next_timeout", ")", ";", "}", "private", "void", "tcp_inet_multi_timeout", "(", "EPID", "caller", ")", "throws", "Pausable", "{", "AsyncMultiOp", "multi", ";", "if", "(", "(", "multi", "=", "remove_multi_op", "(", "caller", ")", ")", "==", "null", ")", "{", "return", ";", "}", "driver_demonitor_process", "(", "multi", ".", "op", ".", "monitor", ")", ";", "if", "(", "multi_first", "==", "null", ")", "{", "sock_select", "(", "ERL_DRV_ACCEPT", ",", "SelectMode", ".", "CLEAR", ")", ";", "this", ".", "state", "=", "TCP_STATE_LISTEN", ";", "}", "send_async_error", "(", "multi", ".", "op", ".", "id", ",", "caller", ",", "am_timeout", ")", ";", "}", "private", "boolean", "async_error", "(", "EAtom", "reason", ")", "throws", "Pausable", "{", "AsyncOp", "op", "=", "deq_async", "(", ")", ";", "if", "(", "op", "==", "null", ")", "{", "return", "false", ";", "}", "return", "send_async_error", "(", "op", ".", "id", ",", "op", ".", "caller", ",", "reason", ")", ";", "}", "private", "void", "erl_inet_close", "(", ")", "{", "free_subscribers", "(", "empty_out_q_subs", ")", ";", "if", "(", "!", "prebound", "&&", "(", "(", "state", "&", "INET_F_OPEN", ")", "==", "INET_F_OPEN", ")", ")", "{", "desc_close", "(", ")", ";", "state", "=", "INET_STATE_CLOSED", ";", "}", "else", "if", "(", "prebound", "&&", "(", "fd", "!=", "null", ")", ")", "{", "sock_select", "(", "ERL_DRV_READ", "|", "ERL_DRV_WRITE", ",", "SelectMode", ".", "CLEAR", ")", ";", "event_mask", "=", "0", ";", "}", "}", "private", "void", "desc_close", "(", ")", "{", "sock_select", "(", "ERL_DRV_USE", ",", "SelectMode", ".", "CLEAR", ")", ";", "fd", "=", "null", ";", "event_mask", "=", "0", ";", "}", "@", "Override", "protected", "void", "stopSelect", "(", "SelectableChannel", "ch", ")", "throws", "Pausable", "{", "sock_close", "(", "ch", ")", ";", "}", "@", "Override", "protected", "void", "stop", "(", "EObject", "reason", ")", "throws", "Pausable", "{", "super", ".", "stop", "(", "reason", ")", ";", "tcp_close_check", "(", ")", ";", "InetSocket", "ff", "=", "fd", ";", "if", "(", "ff", "!=", "null", ")", "{", "SelectableChannel", "ch", "=", "ff", ".", "channel", "(", ")", ";", "if", "(", "ch", "!=", "null", ")", "{", "sock_close", "(", "ch", ")", ";", "}", "}", "}", "private", "void", "sock_close", "(", "SelectableChannel", "ch", ")", "{", "try", "{", "ch", ".", "close", "(", ")", ";", "}", "catch", "(", "IOException", "e", ")", "{", "if", "(", "log", ".", "isLoggable", "(", "Level", ".", "WARNING", ")", ")", "log", ".", "log", "(", "Level", ".", "WARNING", ",", "\"\"", ",", "e", ")", ";", "}", "}", "private", "void", "free_subscribers", "(", "List", "<", "EHandle", ">", "emptyOutQSubs", ")", "{", "emptyOutQSubs", ".", "clear", "(", ")", ";", "}", "@", "Override", "protected", "ByteBuffer", "control", "(", "EPID", "caller", ",", "int", "command", ",", "ByteBuffer", "buf", ")", "throws", "Pausable", "{", "switch", "(", "command", ")", "{", "case", "INET_REQ_OPEN", ":", "return", "inet_open", "(", "buf", ")", ";", "case", "INET_REQ_PEER", ":", "return", "inet_peer", "(", "buf", ")", ";", "case", "INET_REQ_SUBSCRIBE", ":", "return", "inet_subscribe", "(", "caller", ",", "buf", ")", ";", "case", "INET_REQ_BIND", ":", "return", "inet_bind", "(", "buf", ")", ";", "case", "INET_REQ_NAME", ":", "return", "inet_name", "(", "buf", ")", ";", "case", "TCP_REQ_LISTEN", ":", "return", "tcp_listen", "(", "buf", ")", ";", "case", "TCP_REQ_ACCEPT", ":", "return", "tcp_accept", "(", "caller", ",", "buf", ")", ";", "case", "TCP_REQ_RECV", ":", "return", "tcp_recv", "(", "caller", ",", "buf", ")", ";", "case", "INET_REQ_CONNECT", ":", "return", "inet_connect", "(", "caller", ",", "buf", ")", ";", "case", "INET_REQ_GETOPTS", ":", "return", "inet_get_opts", "(", "buf", ")", ";", "case", "INET_REQ_SETOPTS", ":", "switch", "(", "inet_set_opts", "(", "buf", ")", ")", "{", "case", "-", "1", ":", "return", "ctl_error", "(", "Posix", ".", "EINVAL", ")", ";", "case", "0", ":", "return", "ctl_reply", "(", "INET_REP_OK", ",", "new", "byte", "[", "0", "]", ")", ";", "default", ":", "tcp_deliver", "(", "0", ")", ";", "return", "ctl_reply", "(", "INET_REP_OK", ",", "new", "byte", "[", "0", "]", ")", ";", "}", "case", "INET_REQ_GETSTAT", ":", "return", "inet_getstat", "(", "buf", ")", ";", "}", "throw", "new", "erjang", ".", "NotImplemented", "(", "\"\"", "+", "command", "+", "\")\"", ")", ";", "}", "private", "ByteBuffer", "inet_getstat", "(", "ByteBuffer", "buf", ")", "{", "int", "outsize", "=", "1", "+", "(", "buf", ".", "remaining", "(", ")", "+", "2", ")", "*", "5", ";", "ByteBuffer", "dst", "=", "ByteBuffer", ".", "allocate", "(", "outsize", ")", ";", "dst", ".", "put", "(", "INET_REP_OK", ")", ";", "while", "(", "buf", ".", "hasRemaining", "(", ")", ")", "{", "byte", "op", "=", "buf", ".", "get", "(", ")", ";", "dst", ".", "put", "(", "op", ")", ";", "int", "val", ";", "switch", "(", "op", ")", "{", "case", "INET_STAT_RECV_CNT", ":", "val", "=", "this", ".", "recv_cnt", ";", "break", ";", "case", "INET_STAT_RECV_MAX", ":", "val", "=", "this", ".", "recv_max", ";", "break", ";", "case", "INET_STAT_RECV_AVG", ":", "val", "=", "(", "int", ")", "this", ".", "recv_avg", ";", "break", ";", "case", "INET_STAT_RECV_DVI", ":", "val", "=", "(", "int", ")", "Math", ".", "abs", "(", "this", ".", "recv_dvi", ")", ";", "break", ";", "case", "INET_STAT_SEND_CNT", ":", "val", "=", "this", ".", "send_cnt", ";", "break", ";", "case", "INET_STAT_SEND_MAX", ":", "val", "=", "this", ".", "send_max", ";", "break", ";", "case", "INET_STAT_SEND_AVG", ":", "val", "=", "(", "int", ")", "this", ".", "send_avg", ";", "break", ";", "case", "INET_STAT_SEND_PND", ":", "val", "=", "driver_sizeq", "(", ")", ";", "break", ";", "case", "INET_STAT_RECV_OCT", ":", "dst", ".", "putLong", "(", "this", ".", "recv_oct", ")", ";", "continue", ";", "case", "INET_STAT_SEND_OCT", ":", "dst", ".", "putLong", "(", "this", ".", "send_oct", ")", ";", "continue", ";", "default", ":", "return", "ctl_error", "(", "Posix", ".", "EINVAL", ")", ";", "}", "dst", ".", "putInt", "(", "val", ")", ";", "}", "return", "dst", ";", "}", "private", "ByteBuffer", "inet_peer", "(", "ByteBuffer", "buf", ")", "{", "if", "(", "(", "state", "&", "INET_F_ACTIVE", ")", "==", "0", ")", "{", "log", ".", "fine", "(", "\"\"", ")", ";", "return", "ctl_error", "(", "Posix", ".", "ENOTCONN", ")", ";", "}", "InetSocketAddress", "addr", "=", "fd", ".", "getRemoteAddress", "(", ")", ";", "InetAddress", "a", "=", "addr", ".", "getAddress", "(", ")", ";", "if", "(", "log", ".", "isLoggable", "(", "Level", ".", "FINE", ")", ")", "log", ".", "fine", "(", "\"peer", "->", "\"", "+", "addr", ")", ";", "byte", "[", "]", "bytes", "=", "a", ".", "getAddress", "(", ")", ";", "int", "port", "=", "addr", ".", "getPort", "(", ")", ";", "byte", "[", "]", "data", "=", "new", "byte", "[", "1", "+", "2", "+", "bytes", ".", "length", "]", ";", "data", "[", "0", "]", "=", "(", "byte", ")", "sfamily", ".", "code", ";", "data", "[", "1", "]", "=", "(", "byte", ")", "(", "(", "port", ">>", "8", ")", "&", "0xff", ")", ";", "data", "[", "2", "]", "=", "(", "byte", ")", "(", "port", "&", "0xff", ")", ";", "System", ".", "arraycopy", "(", "bytes", ",", "0", ",", "data", ",", "3", ",", "bytes", ".", "length", ")", ";", "return", "ctl_reply", "(", "INET_REP_OK", ",", "data", ")", ";", "}", "private", "ByteBuffer", "tcp_recv", "(", "EPID", "caller2", ",", "ByteBuffer", "buf", ")", "throws", "Pausable", "{", "if", "(", "!", "is_connected", "(", ")", ")", "{", "if", "(", "(", "tcp_add_flags", "&", "TCP_ADDF_DELAYED_CLOSE_RECV", ")", "!=", "0", ")", "{", "tcp_add_flags", "&=", "~", "(", "TCP_ADDF_DELAYED_CLOSE_RECV", "|", "TCP_ADDF_DELAYED_CLOSE_SEND", ")", ";", "return", "ctl_reply", "(", "INET_REP_ERROR", ",", "\"closed\"", ")", ";", "}", "else", "{", "return", "ctl_error", "(", "Posix", ".", "ENOTCONN", ")", ";", "}", "}", "if", "(", "active", "!=", "ActiveType", ".", "PASSIVE", "||", "buf", ".", "remaining", "(", ")", "!=", "8", ")", "{", "return", "ctl_error", "(", "Posix", ".", "EINVAL", ")", ";", "}", "int", "timeout", "=", "buf", ".", "getInt", "(", ")", ";", "int", "n", "=", "buf", ".", "getInt", "(", ")", ";", "if", "(", "htype", "!=", "PacketParseType", ".", "TCP_PB_RAW", "&&", "n", "!=", "0", ")", "return", "ctl_error", "(", "Posix", ".", "EINVAL", ")", ";", "if", "(", "n", ">", "0x4000000", ")", "return", "ctl_error", "(", "Posix", ".", "ENOMEM", ")", ";", "ByteBuffer", "tbuf", "=", "ByteBuffer", ".", "allocate", "(", "2", ")", ";", "if", "(", "enq_async", "(", "caller2", ",", "tbuf", ",", "TCP_REQ_RECV", ")", "<", "0", ")", "return", "ctl_error", "(", "Posix", ".", "EALREADY", ")", ";", "if", "(", "log", ".", "isLoggable", "(", "Level", ".", "FINER", ")", ")", "log", ".", "finer", "(", "\"enq", "\"", "+", "caller2", "+", "\"::\"", "+", "tbuf", ".", "getShort", "(", "0", ")", "+", "\";", "timeout=\"", "+", "timeout", ")", ";", "int", "rep", ";", "if", "(", "(", "rep", "=", "tcp_recv", "(", "n", ")", ")", "==", "0", ")", "{", "if", "(", "timeout", "==", "0", ")", "{", "async_error", "(", "am_timeout", ")", ";", "}", "else", "{", "if", "(", "timeout", "!=", "INET_INFINITY", ")", "{", "driver_set_timer", "(", "timeout", ")", ";", "}", "sock_select", "(", "ERL_DRV_READ", ",", "SelectMode", ".", "SET", ")", ";", "}", "}", "else", "{", "if", "(", "log", ".", "isLoggable", "(", "Level", ".", "FINER", ")", ")", "log", ".", "finer", "(", "\"\"", "+", "rep", ")", ";", "}", "return", "ctl_reply", "(", "INET_REP_OK", ",", "tbuf", ".", "array", "(", ")", ")", ";", "}", "private", "ByteBuffer", "inet_get_opts", "(", "ByteBuffer", "buf", ")", "{", "ByteArrayOutputStream", "barr", "=", "new", "ByteArrayOutputStream", "(", ")", ";", "DataOutputStream", "ptr", "=", "new", "DataOutputStream", "(", "barr", ")", ";", "try", "{", "barr", ".", "write", "(", "INET_REP_OK", ")", ";", "while", "(", "buf", ".", "hasRemaining", "(", ")", ")", "{", "byte", "opt", "=", "buf", ".", "get", "(", ")", ";", "switch", "(", "opt", ")", "{", "case", "INET_LOPT_BUFFER", ":", "ptr", ".", "write", "(", "opt", ")", ";", "ptr", ".", "writeInt", "(", "bufsz", ")", ";", "continue", ";", "case", "INET_LOPT_HEADER", ":", "ptr", ".", "write", "(", "opt", ")", ";", "ptr", ".", "writeInt", "(", "hsz", ")", ";", "continue", ";", "case", "INET_LOPT_MODE", ":", "ptr", ".", "write", "(", "opt", ")", ";", "ptr", ".", "writeInt", "(", "mode", ")", ";", "continue", ";", "case", "INET_LOPT_DELIVER", ":", "ptr", ".", "write", "(", "opt", ")", ";", "ptr", ".", "writeInt", "(", "deliver", ")", ";", "continue", ";", "case", "INET_LOPT_ACTIVE", ":", "ptr", ".", "write", "(", "opt", ")", ";", "ptr", ".", "writeInt", "(", "active", "==", "ActiveType", ".", "PASSIVE", "?", "0", ":", "active", "==", "ActiveType", ".", "ACTIVE", "?", "1", ":", "2", ")", ";", "continue", ";", "case", "INET_LOPT_PACKET", ":", "ptr", ".", "write", "(", "opt", ")", ";", "ptr", ".", "writeInt", "(", "htype", ".", "code", ")", ";", "continue", ";", "case", "INET_LOPT_PACKET_SIZE", ":", "ptr", ".", "write", "(", "opt", ")", ";", "ptr", ".", "writeInt", "(", "psize", ")", ";", "continue", ";", "case", "INET_LOPT_EXITONCLOSE", ":", "ptr", ".", "write", "(", "opt", ")", ";", "ptr", ".", "writeInt", "(", "exitf", "?", "1", ":", "0", ")", ";", "continue", ";", "case", "INET_LOPT_BIT8", ":", "ptr", ".", "write", "(", "opt", ")", ";", "ptr", ".", "writeInt", "(", "bit8f", "?", "(", "bit8", "?", "1", ":", "0", ")", ":", "INET_BIT8_OFF", ")", ";", "continue", ";", "case", "INET_LOPT_TCP_HIWTRMRK", ":", "if", "(", "stype", "==", "ProtocolType", ".", "STREAM", ")", "{", "ptr", ".", "write", "(", "opt", ")", ";", "ptr", ".", "writeInt", "(", "high", ")", ";", "}", "continue", ";", "case", "INET_LOPT_TCP_LOWTRMRK", ":", "if", "(", "stype", "==", "ProtocolType", ".", "STREAM", ")", "{", "ptr", ".", "write", "(", "opt", ")", ";", "ptr", ".", "writeInt", "(", "low", ")", ";", "}", "continue", ";", "case", "INET_LOPT_TCP_SEND_TIMEOUT", ":", "if", "(", "stype", "==", "ProtocolType", ".", "STREAM", ")", "{", "ptr", ".", "write", "(", "opt", ")", ";", "ptr", ".", "writeInt", "(", "send_timeout", ")", ";", "}", "continue", ";", "case", "INET_LOPT_TCP_SEND_TIMEOUT_CLOSE", ":", "if", "(", "stype", "==", "ProtocolType", ".", "STREAM", ")", "{", "ptr", ".", "write", "(", "opt", ")", ";", "ptr", ".", "writeInt", "(", "send_timeout_close", "?", "1", ":", "0", ")", ";", "}", "continue", ";", "case", "INET_LOPT_TCP_DELAY_SEND", ":", "if", "(", "stype", "==", "ProtocolType", ".", "STREAM", ")", "{", "ptr", ".", "write", "(", "opt", ")", ";", "ptr", ".", "writeInt", "(", "(", "(", "tcp_add_flags", "&", "TCP_ADDF_DELAY_SEND", ")", "!=", "0", ")", "?", "1", ":", "0", ")", ";", "}", "continue", ";", "case", "INET_LOPT_READ_PACKETS", ":", "if", "(", "stype", "==", "ProtocolType", ".", "STREAM", ")", "{", "ptr", ".", "write", "(", "opt", ")", ";", "ptr", ".", "writeInt", "(", "read_packets", ")", ";", "}", "continue", ";", "case", "INET_OPT_RAW", ":", "continue", ";", "case", "INET_OPT_PRIORITY", ":", "ptr", ".", "write", "(", "opt", ")", ";", "ptr", ".", "writeInt", "(", "0", ")", ";", "continue", ";", "case", "INET_OPT_TOS", ":", "ptr", ".", "write", "(", "opt", ")", ";", "ptr", ".", "writeInt", "(", "0", ")", ";", "continue", ";", "case", "INET_OPT_REUSEADDR", ":", "try", "{", "boolean", "val", "=", "fd", ".", "getReuseAddress", "(", ")", ";", "ptr", ".", "write", "(", "opt", ")", ";", "ptr", ".", "writeInt", "(", "val", "?", "1", ":", "0", ")", ";", "continue", ";", "}", "catch", "(", "IOException", "e", ")", "{", "continue", ";", "}", "case", "INET_OPT_KEEPALIVE", ":", "try", "{", "boolean", "val", "=", "fd", ".", "getKeepAlive", "(", ")", ";", "ptr", ".", "write", "(", "opt", ")", ";", "ptr", ".", "writeInt", "(", "val", "?", "1", ":", "0", ")", ";", "continue", ";", "}", "catch", "(", "IOException", "e", ")", "{", "continue", ";", "}", "case", "INET_OPT_SNDBUF", ":", "try", "{", "int", "val", "=", "fd", ".", "getSendBufferSize", "(", ")", ";", "ptr", ".", "write", "(", "opt", ")", ";", "ptr", ".", "writeInt", "(", "val", ")", ";", "continue", ";", "}", "catch", "(", "IOException", "e", ")", "{", "continue", ";", "}", "case", "INET_OPT_RCVBUF", ":", "try", "{", "int", "val", "=", "fd", ".", "getReceiveBufferSize", "(", ")", ";", "ptr", ".", "write", "(", "opt", ")", ";", "ptr", ".", "writeInt", "(", "val", ")", ";", "continue", ";", "}", "catch", "(", "IOException", "e", ")", "{", "continue", ";", "}", "case", "TCP_OPT_NODELAY", ":", "try", "{", "boolean", "val", "=", "fd", ".", "getNoDelay", "(", ")", ";", "ptr", ".", "write", "(", "opt", ")", ";", "ptr", ".", "writeInt", "(", "val", "?", "1", ":", "0", ")", ";", "continue", ";", "}", "catch", "(", "IOException", "e", ")", "{", "continue", ";", "}", "default", ":", "throw", "new", "NotImplemented", "(", "\"getopt", "\"", "+", "(", "(", "int", ")", "opt", ")", ")", ";", "}", "}", "ptr", ".", "close", "(", ")", ";", "byte", "[", "]", "b", "=", "barr", ".", "toByteArray", "(", ")", ";", "ByteBuffer", "res", "=", "ByteBuffer", ".", "wrap", "(", "b", ")", ";", "res", ".", "position", "(", "b", ".", "length", ")", ";", "return", "res", ";", "}", "catch", "(", "IOException", "e", ")", "{", "e", ".", "printStackTrace", "(", ")", ";", "return", "ctl_error", "(", "IO", ".", "exception_to_posix_code", "(", "e", ")", ")", ";", "}", "}", "private", "ByteBuffer", "tcp_accept", "(", "EPID", "caller", ",", "ByteBuffer", "buf", ")", "throws", "Pausable", "{", "if", "(", "(", "state", "!=", "TCP_STATE_LISTEN", "&&", "state", "!=", "TCP_STATE_ACCEPTING", "&&", "state", "!=", "TCP_STATE_MULTI_ACCEPTING", ")", "||", "buf", ".", "remaining", "(", ")", "!=", "4", ")", "{", "return", "ctl_error", "(", "Posix", ".", "EINVAL", ")", ";", "}", "int", "timeout", "=", "buf", ".", "getInt", "(", ")", ";", "switch", "(", "state", ")", "{", "case", "TCP_STATE_ACCEPTING", ":", "{", "long", "time_left", ";", "MultiTimerData", "mtd", "=", "null", ",", "omtd", "=", "null", ";", "ERef", "monitor", ";", "if", "(", "(", "monitor", "=", "driver_monitor_process", "(", "caller", ")", ")", "==", "null", ")", "{", "return", "ctl_xerror", "(", "NOPROC", ")", ";", "}", "AsyncOp", "op", "=", "deq_async_w_tmo", "(", ")", ";", "if", "(", "op", ".", "timeout", "!=", "INET_INFINITY", ")", "{", "time_left", "=", "driver_read_timer", "(", ")", ";", "driver_cancel_timer", "(", ")", ";", "if", "(", "time_left", "<=", "0", ")", "{", "time_left", "=", "1", ";", "}", "omtd", "=", "add_multi_timer", "(", "op", ".", "caller", ",", "time_left", ")", ";", "}", "enq_old_multi_op", "(", "op", ",", "omtd", ")", ";", "if", "(", "timeout", "!=", "INET_INFINITY", ")", "{", "mtd", "=", "add_multi_timer", "(", "caller", ",", "timeout", ")", ";", "}", "short", "id", "=", "enq_multi_op", "(", "TCP_REQ_ACCEPT", ",", "caller", ",", "mtd", ",", "monitor", ")", ";", "byte", "[", "]", "data", "=", "new", "byte", "[", "2", "]", ";", "data", "[", "0", "]", "=", "(", "byte", ")", "(", "id", ">>>", "8", ")", ";", "data", "[", "1", "]", "=", "(", "byte", ")", "(", "id", "&", "0xff", ")", ";", "state", "=", "TCP_STATE_MULTI_ACCEPTING", ";", "return", "ctl_reply", "(", "INET_REP_OK", ",", "data", ")", ";", "}", "case", "TCP_STATE_MULTI_ACCEPTING", ":", "{", "MultiTimerData", "mtd", "=", "null", ",", "omtd", "=", "null", ";", "ERef", "monitor", ";", "if", "(", "(", "monitor", "=", "driver_monitor_process", "(", "caller", ")", ")", "==", "null", ")", "{", "return", "ctl_xerror", "(", "NOPROC", ")", ";", "}", "if", "(", "timeout", "!=", "INET_INFINITY", ")", "{", "mtd", "=", "add_multi_timer", "(", "caller", ",", "timeout", ")", ";", "}", "short", "id", "=", "enq_multi_op", "(", "TCP_REQ_ACCEPT", ",", "caller", ",", "mtd", ",", "monitor", ")", ";", "byte", "[", "]", "data", "=", "new", "byte", "[", "2", "]", ";", "data", "[", "0", "]", "=", "(", "byte", ")", "(", "id", ">>>", "8", ")", ";", "data", "[", "1", "]", "=", "(", "byte", ")", "(", "id", "&", "0xff", ")", ";", "return", "ctl_reply", "(", "INET_REP_OK", ",", "data", ")", ";", "}", "case", "TCP_STATE_LISTEN", ":", "ByteBuffer", "reply", "=", "ByteBuffer", ".", "allocate", "(", "2", ")", ";", "InetSocket", "sock", ";", "try", "{", "sock", "=", "fd", ".", "accept", "(", ")", ";", "}", "catch", "(", "IOException", "e", ")", "{", "return", "ctl_error", "(", "IO", ".", "exception_to_posix_code", "(", "e", ")", ")", ";", "}", "if", "(", "sock", "==", "null", ")", "{", "ERef", "monitor", "=", "driver_monitor_process", "(", "caller", ")", ";", "if", "(", "monitor", "==", "null", ")", "{", "return", "ctl_xerror", "(", "NOPROC", ")", ";", "}", "enq_async_w_tmo", "(", "caller", ",", "reply", ",", "TCP_REQ_ACCEPT", ",", "timeout", ",", "monitor", ")", ";", "state", "=", "TCP_STATE_ACCEPTING", ";", "sock_select", "(", "ERL_DRV_ACCEPT", ",", "SelectMode", ".", "SET", ")", ";", "if", "(", "timeout", "!=", "INET_INFINITY", ")", "{", "driver_set_timer", "(", "timeout", ")", ";", "}", "}", "else", "{", "try", "{", "sock", ".", "setNonBlocking", "(", ")", ";", "}", "catch", "(", "IOException", "e", ")", "{", "return", "ctl_error", "(", "IO", ".", "exception_to_posix_code", "(", "e", ")", ")", ";", "}", "TCPINet", "accept_desc", "=", "this", ".", "copy", "(", "caller", ",", "sock", ")", ";", "accept_desc", ".", "state", "=", "TCP_STATE_CONNECTED", ";", "enq_async", "(", "caller", ",", "reply", ",", "TCP_REQ_ACCEPT", ")", ";", "async_ok_port", "(", "caller", ",", "accept_desc", ".", "port", "(", ")", ")", ";", "}", "return", "ctl_reply", "(", "INET_REP_OK", ",", "reply", ".", "array", "(", ")", ")", ";", "default", ":", "throw", "new", "InternalError", "(", ")", ";", "}", "}", "private", "MultiTimerData", "add_multi_timer", "(", "EPID", "caller", ",", "long", "timeout", ")", "{", "MultiTimerData", "mtd", "=", "new", "MultiTimerData", "(", ")", ";", "mtd", ".", "when", "=", "System", ".", "currentTimeMillis", "(", ")", "+", "timeout", ";", "mtd", ".", "caller", "=", "caller", ";", "if", "(", "this", ".", "mtd_queue", "==", "null", ")", "{", "this", ".", "mtd_queue", "=", "new", "PriorityQueue", "<", "MultiTimerData", ">", "(", ")", ";", "}", "this", ".", "mtd_queue", ".", "add", "(", "mtd", ")", ";", "if", "(", "this", ".", "mtd_queue", ".", "peek", "(", ")", "==", "mtd", ")", "{", "if", "(", "this", ".", "mtd_queue", ".", "size", "(", ")", ">", "1", ")", "{", "driver_cancel_timer", "(", ")", ";", "}", "driver_set_timer", "(", "timeout", ")", ";", "}", "return", "mtd", ";", "}", "private", "AsyncMultiOp", "remove_multi_op", "(", "EHandle", "caller", ")", "{", "AsyncMultiOp", "opp", ",", "slap", "=", "null", ";", "for", "(", "opp", "=", "multi_first", ";", "opp", "!=", "null", "&&", "opp", ".", "op", ".", "caller", "!=", "caller", ";", "slap", "=", "opp", ",", "opp", "=", "opp", ".", "next", ")", "{", "}", "if", "(", "opp", "==", "null", ")", "{", "return", "null", ";", "}", "if", "(", "slap", "==", "null", ")", "{", "multi_first", "=", "opp", ".", "next", ";", "}", "else", "{", "slap", ".", "next", "=", "opp", ".", "next", ";", "}", "if", "(", "multi_last", "==", "opp", ")", "{", "multi_last", "=", "slap", ";", "}", "opp", ".", "next", "=", "null", ";", "return", "opp", ";", "}", "private", "short", "enq_multi_op", "(", "int", "req", ",", "EPID", "caller", ",", "MultiTimerData", "timeout", ",", "ERef", "monitor", ")", "{", "short", "id", "=", "(", "short", ")", "(", "aid", ".", "incrementAndGet", "(", ")", "&", "0xffff", ")", ";", "AsyncOp", "op", "=", "new", "AsyncOp", "(", "id", ",", "caller", ",", "req", ",", "-", "1", ",", "monitor", ")", ";", "enq_old_multi_op", "(", "op", ",", "timeout", ")", ";", "return", "id", ";", "}", "AsyncMultiOp", "deq_multi_op", "(", ")", "{", "AsyncMultiOp", "first", "=", "multi_first", ";", "if", "(", "first", "==", "null", ")", "{", "return", "null", ";", "}", "multi_first", "=", "first", ".", "next", ";", "if", "(", "multi_first", "==", "null", ")", "{", "multi_last", "=", "null", ";", "}", "first", ".", "next", "=", "null", ";", "return", "first", ";", "}", "private", "void", "enq_old_multi_op", "(", "AsyncOp", "op", ",", "MultiTimerData", "timeout", ")", "{", "AsyncMultiOp", "opp", "=", "new", "AsyncMultiOp", "(", ")", ";", "opp", ".", "op", "=", "op", ";", "opp", ".", "timeout", "=", "timeout", ";", "if", "(", "this", ".", "multi_first", "==", "null", ")", "{", "multi_first", "=", "opp", ";", "}", "else", "{", "multi_last", ".", "next", "=", "opp", ";", "}", "multi_last", "=", "opp", ";", "}", "private", "boolean", "async_ok_port", "(", "EPID", "caller", ",", "EInternalPort", "port2", ")", "throws", "Pausable", "{", "AsyncOp", "op", "=", "deq_async", "(", ")", ";", "if", "(", "op", "==", "null", ")", "{", "return", "false", ";", "}", "return", "send_async_ok_port", "(", "op", ".", "id", ",", "caller", ",", "port2", ")", ";", "}", "private", "ByteBuffer", "inet_name", "(", "ByteBuffer", "buf", ")", "{", "if", "(", "!", "is_bound", "(", ")", ")", "{", "return", "ctl_error", "(", "Posix", ".", "EINVAL", ")", ";", "}", "InetSocketAddress", "addr", "=", "(", "InetSocketAddress", ")", "fd", ".", "getLocalSocketAddress", "(", ")", ";", "int", "port", "=", "addr", ".", "getPort", "(", ")", ";", "byte", "[", "]", "ip", "=", "addr", ".", "getAddress", "(", ")", ".", "getAddress", "(", ")", ";", "ByteBuffer", "out", "=", "ByteBuffer", ".", "allocate", "(", "4", "+", "ip", ".", "length", ")", ";", "out", ".", "put", "(", "INET_REP_OK", ")", ";", "out", ".", "put", "(", "encode_proto_family", "(", "this", ".", "sfamily", ")", ")", ";", "out", ".", "putShort", "(", "(", "short", ")", "port", ")", ";", "out", ".", "put", "(", "ip", ")", ";", "return", "out", ";", "}", "private", "ByteBuffer", "tcp_listen", "(", "ByteBuffer", "buf", ")", "{", "if", "(", "state", "==", "TCP_STATE_CLOSED", "||", "!", "is_open", "(", ")", ")", "{", "return", "ctl_xerror", "(", "EXBADPORT", ")", ";", "}", "else", "if", "(", "!", "is_bound", "(", ")", ")", "{", "return", "ctl_xerror", "(", "EXBADSEQ", ")", ";", "}", "else", "if", "(", "buf", ".", "remaining", "(", ")", "!=", "2", ")", "{", "return", "ctl_error", "(", "Posix", ".", "EINVAL", ")", ";", "}", "int", "backlog", "=", "buf", ".", "getShort", "(", ")", "&", "0xffff", ";", "try", "{", "this", ".", "fd", ".", "listen", "(", "backlog", ")", ";", "}", "catch", "(", "IOException", "e", ")", "{", "return", "ctl_error", "(", "IO", ".", "exception_to_posix_code", "(", "e", ")", ")", ";", "}", "state", "=", "TCP_STATE_LISTEN", ";", "return", "ctl_reply", "(", "INET_REP_OK", ")", ";", "}", "private", "int", "inet_set_opts", "(", "ByteBuffer", "buf", ")", "throws", "Pausable", "{", "PacketParseType", "old_htype", "=", "this", ".", "htype", ";", "ActiveType", "old_active", "=", "this", ".", "active", ";", "boolean", "propagate", "=", "false", ";", "int", "res", "=", "0", ";", "while", "(", "buf", ".", "remaining", "(", ")", ">=", "5", ")", "{", "byte", "opt", "=", "buf", ".", "get", "(", ")", ";", "int", "ival", "=", "buf", ".", "getInt", "(", ")", ";", "switch", "(", "opt", ")", "{", "case", "INET_LOPT_HEADER", ":", "this", ".", "hsz", "=", "ival", ";", "continue", ";", "case", "INET_LOPT_MODE", ":", "this", ".", "mode", "=", "ival", ";", "continue", ";", "case", "INET_LOPT_DELIVER", ":", "this", ".", "deliver", "=", "ival", ";", "continue", ";", "case", "INET_LOPT_BUFFER", ":", "if", "(", "ival", ">", "INET_MAX_BUFFER", ")", "ival", "=", "INET_MAX_BUFFER", ";", "else", "if", "(", "ival", "<", "INET_MIN_BUFFER", ")", "ival", "=", "INET_MIN_BUFFER", ";", "this", ".", "bufsz", "=", "ival", ";", "continue", ";", "case", "INET_LOPT_ACTIVE", ":", "this", ".", "active", "=", "ActiveType", ".", "valueOf", "(", "ival", ")", ";", "if", "(", "(", "stype", "==", "ProtocolType", ".", "STREAM", ")", "&&", "(", "active", "!=", "ActiveType", ".", "PASSIVE", ")", "&&", "(", "state", "==", "INET_STATE_CLOSED", ")", ")", "{", "tcp_closed_message", "(", ")", ";", "if", "(", "this", ".", "exitf", ")", "{", "driver_exit", "(", "0", ")", ";", "return", "0", ";", "}", "else", "{", "desc_close_read", "(", ")", ";", "}", "}", "res", "=", "1", ";", "continue", ";", "case", "INET_LOPT_PACKET", ":", "this", ".", "htype", "=", "PacketParseType", ".", "valueOf", "(", "ival", ")", ";", "continue", ";", "case", "INET_LOPT_PACKET_SIZE", ":", "this", ".", "psize", "=", "(", "int", ")", "ival", ";", "continue", ";", "case", "INET_LOPT_EXITONCLOSE", ":", "log", ".", "fine", "(", "\"\"", "+", "(", "ival", "!=", "0", ")", "+", "\"", "on", "\"", "+", "this", ")", ";", "this", ".", "exitf", "=", "(", "ival", "==", "0", ")", "?", "false", ":", "true", ";", "continue", ";", "case", "INET_LOPT_BIT8", ":", "switch", "(", "ival", ")", "{", "case", "INET_BIT8_ON", ":", "this", ".", "bit8f", "=", "true", ";", "this", ".", "bit8", "=", "false", ";", "break", ";", "case", "INET_BIT8_OFF", ":", "this", ".", "bit8f", "=", "false", ";", "this", ".", "bit8", "=", "false", ";", "break", ";", "case", "INET_BIT8_CLEAR", ":", "this", ".", "bit8f", "=", "true", ";", "this", ".", "bit8", "=", "false", ";", "break", ";", "case", "INET_BIT8_SET", ":", "this", ".", "bit8f", "=", "true", ";", "this", ".", "bit8", "=", "true", ";", "break", ";", "}", "continue", ";", "case", "INET_LOPT_TCP_HIWTRMRK", ":", "if", "(", "this", ".", "stype", "==", "ProtocolType", ".", "STREAM", ")", "{", "if", "(", "ival", "<", "0", ")", "ival", "=", "0", ";", "else", "if", "(", "ival", ">", "INET_MAX_BUFFER", "*", "2", ")", "ival", "=", "INET_MAX_BUFFER", "*", "2", ";", "if", "(", "this", ".", "low", ">", "ival", ")", "this", ".", "low", "=", "ival", ";", "this", ".", "high", "=", "ival", ";", "}", "continue", ";", "case", "INET_LOPT_TCP_LOWTRMRK", ":", "if", "(", "this", ".", "stype", "==", "ProtocolType", ".", "STREAM", ")", "{", "if", "(", "ival", "<", "0", ")", "ival", "=", "0", ";", "else", "if", "(", "ival", ">", "INET_MAX_BUFFER", ")", "ival", "=", "INET_MAX_BUFFER", ";", "if", "(", "this", ".", "high", "<", "ival", ")", "this", ".", "high", "=", "ival", ";", "this", ".", "high", "=", "ival", ";", "}", "continue", ";", "case", "INET_LOPT_TCP_SEND_TIMEOUT", ":", "if", "(", "this", ".", "stype", "==", "ProtocolType", ".", "STREAM", ")", "{", "this", ".", "send_timeout", "=", "ival", ";", "}", "continue", ";", "case", "INET_LOPT_TCP_SEND_TIMEOUT_CLOSE", ":", "if", "(", "this", ".", "stype", "==", "ProtocolType", ".", "STREAM", ")", "{", "this", ".", "send_timeout_close", "=", "ival", "==", "0", "?", "false", ":", "true", ";", "}", "continue", ";", "case", "INET_LOPT_TCP_DELAY_SEND", ":", "if", "(", "this", ".", "stype", "==", "ProtocolType", ".", "STREAM", ")", "{", "if", "(", "ival", "!=", "0", ")", "this", ".", "tcp_add_flags", "|=", "TCP_ADDF_DELAY_SEND", ";", "else", "this", ".", "tcp_add_flags", "&=", "~", "TCP_ADDF_DELAY_SEND", ";", "}", "continue", ";", "case", "INET_LOPT_READ_PACKETS", ":", "if", "(", "this", ".", "stype", "==", "ProtocolType", ".", "STREAM", ")", "{", "if", "(", "ival", "<=", "0", ")", "return", "-", "1", ";", "this", ".", "read_packets", "=", "ival", ";", "}", "continue", ";", "case", "INET_OPT_REUSEADDR", ":", "try", "{", "fd", ".", "setReuseAddress", "(", "ival", "!=", "0", ")", ";", "}", "catch", "(", "IOException", "e", ")", "{", "if", "(", "propagate", ")", "return", "-", "1", ";", "}", "continue", ";", "case", "INET_OPT_KEEPALIVE", ":", "try", "{", "fd", ".", "setKeepAlive", "(", "ival", "!=", "0", ")", ";", "}", "catch", "(", "IOException", "e", ")", "{", "if", "(", "propagate", ")", "return", "-", "1", ";", "}", "break", ";", "case", "INET_OPT_DONTROUTE", ":", "continue", ";", "case", "INET_OPT_BROADCAST", ":", "try", "{", "fd", ".", "setBroadcast", "(", "ival", "!=", "0", ")", ";", "}", "catch", "(", "IOException", "e", ")", "{", "if", "(", "propagate", ")", "return", "-", "1", ";", "}", "continue", ";", "case", "INET_OPT_OOBINLINE", ":", "try", "{", "fd", ".", "setOOBInline", "(", "ival", "!=", "0", ")", ";", "}", "catch", "(", "IOException", "e", ")", "{", "if", "(", "propagate", ")", "return", "-", "1", ";", "}", "continue", ";", "case", "INET_OPT_SNDBUF", ":", "try", "{", "fd", ".", "setSendBufferSize", "(", "ival", ")", ";", "}", "catch", "(", "IOException", "e", ")", "{", "if", "(", "propagate", ")", "return", "-", "1", ";", "}", "continue", ";", "case", "INET_OPT_RCVBUF", ":", "try", "{", "fd", ".", "setReceiveBufferSize", "(", "ival", ")", ";", "if", "(", "ival", ">", "this", ".", "bufsz", ")", "{", "this", ".", "bufsz", "=", "ival", ";", "}", "}", "catch", "(", "IOException", "e", ")", "{", "if", "(", "propagate", ")", "return", "-", "1", ";", "}", "continue", ";", "case", "INET_OPT_LINGER", ":", "if", "(", "buf", ".", "remaining", "(", ")", "<", "4", ")", "return", "-", "1", ";", "int", "linger", "=", "buf", ".", "getInt", "(", ")", ";", "try", "{", "fd", ".", "setLinger", "(", "ival", "!=", "0", ",", "linger", ")", ";", "}", "catch", "(", "IOException", "e", ")", "{", "if", "(", "propagate", ")", "return", "-", "1", ";", "}", "continue", ";", "case", "INET_OPT_PRIORITY", ":", "continue", ";", "case", "INET_OPT_TOS", ":", "try", "{", "fd", ".", "setTrafficClass", "(", "ival", ")", ";", "}", "catch", "(", "IOException", "e", ")", "{", "if", "(", "propagate", ")", "return", "-", "1", ";", "}", "continue", ";", "case", "TCP_OPT_NODELAY", ":", "try", "{", "fd", ".", "setTcpNoDelay", "(", "ival", "!=", "0", ")", ";", "}", "catch", "(", "IOException", "e", ")", "{", "if", "(", "propagate", ")", "return", "-", "1", ";", "}", "continue", ";", "default", ":", "return", "-", "1", ";", "}", "}", "if", "(", "(", "(", "stype", "==", "ProtocolType", ".", "STREAM", ")", "&&", "is_connected", "(", ")", ")", "||", "(", "(", "stype", "==", "ProtocolType", ".", "DGRAM", ")", "&&", "is_open", "(", ")", ")", ")", "{", "if", "(", "active", "!=", "old_active", ")", "sock_select", "(", "ERL_DRV_READ", ",", "active", "==", "ActiveType", ".", "PASSIVE", "?", "SelectMode", ".", "CLEAR", ":", "SelectMode", ".", "SET", ")", ";", "if", "(", "(", "stype", "==", "ProtocolType", ".", "STREAM", ")", "&&", "active", "!=", "ActiveType", ".", "PASSIVE", ")", "{", "if", "(", "old_active", "==", "ActiveType", ".", "PASSIVE", "||", "(", "htype", "!=", "old_htype", ")", ")", "{", "return", "1", ";", "}", "return", "0", ";", "}", "}", "return", "0", ";", "}", "private", "byte", "[", "]", "int_to_ip", "(", "int", "ival", ")", "{", "return", "new", "byte", "[", "]", "{", "(", "byte", ")", "(", "(", "ival", ">>>", "24", ")", "&", "0xff", ")", ",", "(", "byte", ")", "(", "(", "ival", ">>>", "16", ")", "&", "0xff", ")", ",", "(", "byte", ")", "(", "(", "ival", ">>>", "8", ")", "&", "0xff", ")", ",", "(", "byte", ")", "(", "(", "ival", ")", "&", "0xff", ")", ",", "}", ";", "}", "private", "void", "desc_close_read", "(", ")", "{", "sock_select", "(", "ERL_DRV_READ", "|", "ERL_DRV_USE", ",", "SelectMode", ".", "CLEAR", ")", ";", "}", "private", "void", "tcp_closed_message", "(", ")", "throws", "Pausable", "{", "if", "(", "(", "tcp_add_flags", "&", "TCP_ADDF_CLOSE_SENT", ")", "==", "0", ")", "{", "tcp_add_flags", "|=", "TCP_ADDF_CLOSE_SENT", ";", "driver_output_term", "(", "new", "ETuple2", "(", "am_tcp_closed", ",", "port", "(", ")", ")", ")", ";", "}", "}", "private", "int", "tcp_deliver", "(", "int", "len", ")", "throws", "Pausable", "{", "if", "(", "log", ".", "isLoggable", "(", "Level", ".", "FINER", ")", ")", "log", ".", "finer", "(", "\"tcp_deliver", "\"", "+", "i_ptr_start", "+", "\":\"", "+", "len", ")", ";", "int", "count", "=", "0", ";", "int", "n", ";", "int", "[", "]", "lenp", "=", "new", "int", "[", "]", "{", "len", "}", ";", "if", "(", "len", "==", "0", ")", "{", "if", "(", "i_buf", "==", "null", "||", "i_remain", ">", "0", ")", "{", "return", "count", ";", "}", "n", "=", "tcp_remain", "(", "lenp", ")", ";", "len", "=", "lenp", "[", "0", "]", ";", "if", "(", "n", "!=", "0", ")", "{", "if", "(", "n", "<", "0", ")", "{", "if", "(", "log", ".", "isLoggable", "(", "Level", ".", "WARNING", ")", ")", "log", ".", "warning", "(", "\"\"", "+", "n", ")", ";", "return", "n", ";", "}", "if", "(", "len", ">", "0", ")", "i_remain", "=", "len", ";", "return", "count", ";", "}", "}", "while", "(", "len", ">", "0", ")", "{", "if", "(", "log", ".", "isLoggable", "(", "Level", ".", "FINER", ")", ")", "log", ".", "finer", "(", "\"deliver.2\"", ")", ";", "int", "code", "=", "0", ";", "inet_input_count", "(", "len", ")", ";", "if", "(", "len", "*", "4", ">=", "i_buf", ".", "capacity", "(", ")", "*", "3", ")", "{", "if", "(", "log", ".", "isLoggable", "(", "Level", ".", "FINER", ")", ")", "log", ".", "finer", "(", "\"deliver.2.1\"", ")", ";", "if", "(", "i_ptr_start", "+", "len", "==", "i_buf", ".", "position", "(", ")", ")", "{", "code", "=", "tcp_reply_data", "(", "i_buf", ".", "array", "(", ")", ",", "i_buf", ".", "arrayOffset", "(", ")", "+", "i_ptr_start", ",", "len", ")", ";", "if", "(", "code", ">=", "0", ")", "tcp_clear_input", "(", ")", ";", "}", "else", "{", "ByteBuffer", "bin", "=", "ByteBuffer", ".", "allocate", "(", "i_buf", ".", "capacity", "(", ")", ")", ";", "bin", ".", "put", "(", "i_buf", ".", "array", "(", ")", ",", "i_buf", ".", "arrayOffset", "(", ")", "+", "i_ptr_start", "+", "len", ",", "i_buf", ".", "position", "(", ")", "-", "len", "-", "i_ptr_start", ")", ";", "code", "=", "tcp_reply_data", "(", "i_buf", ".", "array", "(", ")", ",", "i_buf", ".", "arrayOffset", "(", ")", "+", "i_ptr_start", ",", "len", ")", ";", "if", "(", "code", ">=", "0", ")", "{", "i_buf", "=", "bin", ";", "i_ptr_start", "=", "0", ";", "i_remain", "=", "0", ";", "}", "}", "}", "else", "{", "if", "(", "log", ".", "isLoggable", "(", "Level", ".", "FINER", ")", ")", "log", ".", "finer", "(", "\"deliver.2.2\"", ")", ";", "boolean", "share_ok", "=", "i_ptr_start", "+", "len", "==", "i_buf", ".", "position", "(", ")", ";", "if", "(", "share_ok", ")", "{", "code", "=", "tcp_reply_data", "(", "i_buf", ".", "array", "(", ")", ",", "i_buf", ".", "arrayOffset", "(", ")", "+", "i_ptr_start", ",", "len", ")", ";", "if", "(", "code", ">=", "0", ")", "tcp_clear_input", "(", ")", ";", "}", "else", "{", "byte", "[", "]", "data", "=", "new", "byte", "[", "len", "]", ";", "System", ".", "arraycopy", "(", "i_buf", ".", "array", "(", ")", ",", "i_buf", ".", "arrayOffset", "(", ")", "+", "i_ptr_start", ",", "data", ",", "0", ",", "len", ")", ";", "code", "=", "tcp_reply_data", "(", "data", ",", "0", ",", "len", ")", ";", "if", "(", "code", ">=", "0", ")", "{", "i_ptr_start", "+=", "len", ";", "i_remain", "=", "0", ";", "}", "}", "}", "if", "(", "code", "<", "0", ")", "{", "if", "(", "log", ".", "isLoggable", "(", "Level", ".", "WARNING", ")", ")", "log", ".", "warning", "(", "\"\"", "+", "code", ")", ";", "return", "code", ";", "}", "count", "++", ";", "len", "=", "0", ";", "if", "(", "active", "==", "ActiveType", ".", "PASSIVE", ")", "{", "driver_cancel_timer", "(", ")", ";", "sock_select", "(", "ERL_DRV_READ", "|", "0", ",", "SelectMode", ".", "CLEAR", ")", ";", "if", "(", "i_buf", "!=", "null", ")", "{", "tcp_restart_input", "(", ")", ";", "}", "}", "else", "if", "(", "i_buf", "!=", "null", ")", "{", "lenp", "[", "0", "]", "=", "len", ";", "n", "=", "tcp_remain", "(", "lenp", ")", ";", "len", "=", "lenp", "[", "0", "]", ";", "if", "(", "n", "!=", "0", ")", "{", "if", "(", "n", "<", "0", ")", "return", "n", ";", "tcp_restart_input", "(", ")", ";", "if", "(", "len", ">", "0", ")", "i_remain", "=", "len", ";", "len", "=", "0", ";", "}", "}", "}", "return", "count", ";", "}", "private", "void", "inet_input_count", "(", "int", "len", ")", "{", "recv_cnt", "+=", "1", ";", "recv_oct", "+=", "len", ";", "double", "avg", "=", "recv_avg", ";", "double", "dvi", "=", "recv_dvi", ";", "recv_avg", "=", "avg", "+", "(", "len", "-", "avg", ")", "/", "recv_cnt", ";", "if", "(", "len", ">", "recv_max", ")", "recv_max", "=", "len", ";", "}", "private", "void", "tcp_restart_input", "(", ")", "{", "if", "(", "i_ptr_start", "!=", "0", ")", "{", "int", "n", "=", "i_buf", ".", "position", "(", ")", "-", "i_ptr_start", ";", "System", ".", "arraycopy", "(", "i_buf", ".", "array", "(", ")", ",", "i_buf", ".", "arrayOffset", "(", ")", "+", "i_ptr_start", ",", "i_buf", ".", "array", "(", ")", ",", "i_buf", ".", "arrayOffset", "(", ")", ",", "n", ")", ";", "i_ptr_start", "=", "0", ";", "i_buf", ".", "position", "(", "n", ")", ";", "}", "}", "private", "int", "tcp_reply_data", "(", "byte", "[", "]", "ib", ",", "int", "start", ",", "int", "len", ")", "throws", "Pausable", "{", "if", "(", "log", ".", "isLoggable", "(", "Level", ".", "FINER", ")", ")", "log", ".", "finer", "(", "\"\"", "+", "len", ")", ";", "ByteBuffer", "out", "=", "ByteBuffer", ".", "wrap", "(", "ib", ",", "start", ",", "len", ")", ";", "Packet", ".", "get_body", "(", "htype", ",", "out", ")", ";", "start", "=", "out", ".", "position", "(", ")", ";", "int", "bodylen", "=", "out", ".", "remaining", "(", ")", ";", "scanbit8", "(", "out", ")", ";", "out", "=", "out", ".", "slice", "(", ")", ";", "out", ".", "position", "(", "out", ".", "limit", "(", ")", ")", ";", "int", "code", ";", "if", "(", "deliver", "==", "INET_DELIVER_PORT", ")", "{", "code", "=", "inet_port_data", "(", "out", ")", ";", "}", "else", "if", "(", "(", "code", "=", "Packet", ".", "parse", "(", "htype", ",", "ib", ",", "start", ",", "len", ",", "http_state", ",", "packet_callbacks", ",", "this", ")", ")", "==", "0", ")", "{", "if", "(", "active", "==", "ActiveType", ".", "PASSIVE", ")", "{", "return", "inet_async_data", "(", "0", ",", "out", ")", ";", "}", "else", "{", "code", "=", "tcp_message", "(", "out", ")", ";", "}", "}", "if", "(", "code", "<", "0", ")", "return", "code", ";", "if", "(", "active", "==", "ActiveType", ".", "ACTIVE_ONCE", ")", "{", "active", "=", "ActiveType", ".", "PASSIVE", ";", "}", "return", "code", ";", "}", "private", "int", "tcp_message", "(", "ByteBuffer", "out", ")", "throws", "Pausable", "{", "int", "hsz", "=", "this", ".", "hsz", ";", "EObject", "msg", ";", "EObject", "data", ";", "if", "(", "mode", "==", "INET_MODE_LIST", ")", "{", "out", ".", "flip", "(", ")", ";", "data", "=", "EString", ".", "make", "(", "out", ")", ";", "}", "else", "{", "out", ".", "position", "(", "hsz", ")", ";", "ByteBuffer", "tail", "=", "out", ".", "slice", "(", ")", ";", "out", ".", "flip", "(", ")", ";", "ByteBuffer", "header", "=", "out", ";", "data", "=", "new", "EBinList", "(", "header", ",", "EBinary", ".", "make", "(", "tail", ")", ")", ";", "}", "msg", "=", "ETuple", ".", "make", "(", "am_tcp", ",", "port", "(", ")", ",", "data", ")", ";", "driver_output_term", "(", "msg", ")", ";", "return", "0", ";", "}", "private", "int", "inet_async_data", "(", "int", "i", ",", "ByteBuffer", "out", ")", "{", "AsyncOp", "op", "=", "deq_async", "(", ")", ";", "if", "(", "op", "==", "null", ")", "return", "-", "1", ";", "if", "(", "log", ".", "isLoggable", "(", "Level", ".", "FINER", ")", ")", "log", ".", "finer", "(", "\"deq", "\"", "+", "op", ".", "caller", "+", "\"::\"", "+", "op", ".", "id", ")", ";", "EObject", "data", ";", "if", "(", "mode", "==", "INET_MODE_LIST", ")", "{", "out", ".", "flip", "(", ")", ";", "data", "=", "EString", ".", "make", "(", "out", ")", ";", "}", "else", "{", "out", ".", "position", "(", "hsz", ")", ";", "ByteBuffer", "tail", "=", "out", ".", "slice", "(", ")", ";", "out", ".", "flip", "(", ")", ";", "data", "=", "EBinary", ".", "make", "(", "tail", ")", ";", "}", "ETuple", "res", "=", "ETuple", ".", "make", "(", "am_inet_async", ",", "port", "(", ")", ",", "ERT", ".", "box", "(", "op", ".", "id", ")", ",", "new", "ETuple2", "(", "ERT", ".", "am_ok", ",", "data", ")", ")", ";", "if", "(", "log", ".", "isLoggable", "(", "Level", ".", "FINER", ")", ")", "{", "log", ".", "finer", "(", "\"sending", "to", "\"", "+", "op", ".", "caller", "+", "\"", "!", "\"", "+", "res", ")", ";", "}", "op", ".", "caller", ".", "sendb", "(", "res", ")", ";", "return", "0", ";", "}", "private", "int", "inet_port_data", "(", "ByteBuffer", "out", ")", "throws", "Pausable", "{", "int", "hsz", "=", "this", ".", "hsz", ";", "if", "(", "mode", "==", "INET_MODE_LIST", "||", "(", "hsz", ">", "out", ".", "remaining", "(", ")", ")", ")", "{", "driver_output", "(", "out", ")", ";", "return", "0", ";", "}", "else", "if", "(", "hsz", ">", "0", ")", "{", "out", ".", "limit", "(", "out", ".", "position", "(", ")", ")", ";", "out", ".", "position", "(", "hsz", ")", ";", "ByteBuffer", "tail", "=", "out", ".", "slice", "(", ")", ";", "tail", ".", "position", "(", "tail", ".", "limit", "(", ")", ")", ";", "out", ".", "limit", "(", "hsz", ")", ";", "driver_output2", "(", "out", ",", "tail", ")", ";", "return", "0", ";", "}", "else", "{", "driver_output", "(", "out", ")", ";", "return", "0", ";", "}", "}", "private", "int", "tcp_reply_binary_data", "(", "byte", "[", "]", "ib", ",", "int", "start", ",", "int", "len", ")", "throws", "Pausable", "{", "ByteBuffer", "out", "=", "ByteBuffer", ".", "wrap", "(", "ib", ",", "start", ",", "len", ")", ";", "Packet", ".", "get_body", "(", "htype", ",", "out", ")", ";", "start", "=", "out", ".", "position", "(", ")", ";", "int", "bodylen", "=", "out", ".", "remaining", "(", ")", ";", "scanbit8", "(", "out", ")", ";", "int", "code", ";", "if", "(", "deliver", "==", "INET_DELIVER_PORT", ")", "{", "code", "=", "inet_port_binary_data", "(", "out", ")", ";", "}", "else", "if", "(", "(", "code", "=", "Packet", ".", "parse", "(", "htype", ",", "ib", ",", "start", ",", "len", ",", "http_state", ",", "packet_callbacks", ",", "this", ")", ")", "==", "0", ")", "{", "if", "(", "active", "==", "ActiveType", ".", "PASSIVE", ")", "{", "return", "inet_async_binary_data", "(", "0", ",", "out", ")", ";", "}", "else", "{", "code", "=", "tcp_binary_message", "(", "out", ")", ";", "}", "}", "if", "(", "code", "<", "0", ")", "return", "code", ";", "if", "(", "active", "==", "ActiveType", ".", "ACTIVE_ONCE", ")", "{", "active", "=", "ActiveType", ".", "PASSIVE", ";", "}", "return", "code", ";", "}", "private", "int", "tcp_binary_message", "(", "ByteBuffer", "out", ")", "{", "throw", "new", "erjang", ".", "NotImplemented", "(", ")", ";", "}", "private", "int", "inet_async_binary_data", "(", "int", "i", ",", "ByteBuffer", "out", ")", "{", "throw", "new", "erjang", ".", "NotImplemented", "(", ")", ";", "}", "private", "int", "inet_port_binary_data", "(", "ByteBuffer", "out", ")", "{", "throw", "new", "erjang", ".", "NotImplemented", "(", ")", ";", "}", "private", "void", "scanbit8", "(", "ByteBuffer", "out", ")", "{", "if", "(", "!", "bit8f", "||", "bit8", ")", "return", ";", "char", "c", "=", "0", ";", "int", "rem", "=", "out", ".", "remaining", "(", ")", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "rem", ";", "i", "++", ")", "{", "c", "|=", "out", ".", "get", "(", "i", ")", ";", "}", "bit8", "=", "(", "(", "c", "&", "0x80", ")", "!=", "0", ")", ";", "}", "private", "void", "tcp_clear_input", "(", ")", "{", "i_buf", "=", "null", ";", "i_ptr_start", "=", "0", ";", "i_remain", "=", "0", ";", "}", "private", "int", "tcp_expand_buffer", "(", "int", "len", ")", "{", "int", "used", "=", "i_ptr_start", ";", "int", "ulen", "=", "used", "+", "len", ";", "if", "(", "i_buf", ".", "limit", "(", ")", ">=", "ulen", ")", "{", "return", "0", ";", "}", "else", "if", "(", "i_buf", ".", "capacity", "(", ")", ">=", "ulen", ")", "{", "i_buf", ".", "limit", "(", "ulen", ")", ";", "return", "0", ";", "}", "try", "{", "ByteBuffer", "bin", "=", "ByteBuffer", ".", "allocate", "(", "ulen", ")", ";", "i_buf", ".", "flip", "(", ")", ";", "bin", ".", "put", "(", "i_buf", ")", ";", "i_buf", "=", "bin", ";", "return", "0", ";", "}", "catch", "(", "OutOfMemoryError", "e", ")", "{", "return", "-", "1", ";", "}", "}", "private", "final", "int", "i_ptr", "(", ")", "{", "return", "i_buf", ".", "position", "(", ")", ";", "}", "private", "final", "int", "i_bufsz", "(", ")", "{", "return", "i_buf", ".", "limit", "(", ")", ";", "}", "private", "final", "void", "i_bufsz", "(", "int", "pos", ")", "{", "i_buf", ".", "limit", "(", "pos", ")", ";", "}", "private", "final", "int", "i_buf_origsz", "(", ")", "{", "return", "i_buf", ".", "capacity", "(", ")", ";", "}", "private", "int", "tcp_push_buffer", "(", "byte", "[", "]", "data", ",", "int", "off", ",", "int", "len", ")", "{", "if", "(", "i_buf", "==", "null", ")", "{", "i_buf", "=", "ByteBuffer", ".", "allocate", "(", "len", ")", ";", "i_buf", ".", "put", "(", "data", ",", "off", ",", "len", ")", ";", "i_ptr_start", "=", "0", ";", "}", "else", "{", "int", "sz_before", "=", "i_ptr_start", ";", "int", "sz_filled", "=", "i_buf", ".", "position", "(", ")", "-", "i_ptr_start", ";", "if", "(", "len", "<=", "sz_before", ")", "{", "i_buf", ".", "position", "(", "sz_before", "-", "len", ")", ";", "i_buf", ".", "put", "(", "data", ",", "off", ",", "len", ")", ";", "i_ptr_start", "-=", "len", ";", "}", "else", "{", "ByteBuffer", "bin", "=", "ByteBuffer", ".", "allocate", "(", "len", "+", "i_buf", ".", "limit", "(", ")", ")", ";", "bin", ".", "put", "(", "data", ",", "off", ",", "len", ")", ";", "i_buf", ".", "position", "(", "i_ptr_start", ")", ";", "i_buf", ".", "limit", "(", "sz_filled", ")", ";", "bin", ".", "put", "(", "i_buf", ".", "array", "(", ")", ",", "i_buf", ".", "arrayOffset", "(", ")", "+", "i_ptr_start", ",", "sz_filled", ")", ";", "i_buf", "=", "bin", ";", "i_ptr_start", "=", "0", ";", "}", "}", "i_remain", "=", "0", ";", "return", "0", ";", "}", "private", "int", "tcp_remain", "(", "int", "[", "]", "lenp", ")", "{", "int", "nfill", "=", "i_buf", ".", "position", "(", ")", ";", "int", "nsz", "=", "i_buf", ".", "remaining", "(", ")", ";", "int", "n", "=", "nfill", "-", "i_ptr_start", ";", "int", "tlen", ";", "tlen", "=", "Packet", ".", "get_length", "(", "htype", ",", "i_buf", ".", "array", "(", ")", ",", "i_buf", ".", "arrayOffset", "(", ")", "+", "i_ptr_start", ",", "n", ",", "this", ".", "psize", ",", "i_bufsz", "(", ")", ",", "http_state", ")", ";", "if", "(", "tlen", ">", "0", ")", "{", "if", "(", "tlen", "<=", "n", ")", "{", "lenp", "[", "0", "]", "=", "tlen", ";", "return", "0", ";", "}", "else", "{", "if", "(", "tcp_expand_buffer", "(", "tlen", ")", "<", "0", ")", "{", "return", "-", "1", ";", "}", "lenp", "[", "0", "]", "=", "(", "tlen", "-", "n", ")", ";", "return", "lenp", "[", "0", "]", ";", "}", "}", "else", "if", "(", "tlen", "==", "0", ")", "{", "lenp", "[", "0", "]", "=", "0", ";", "if", "(", "nsz", "==", "0", ")", "{", "if", "(", "nfill", "==", "n", ")", "{", "return", "-", "1", ";", "}", "else", "{", "return", "nfill", "-", "n", ";", "}", "}", "else", "{", "return", "nsz", ";", "}", "}", "return", "-", "1", ";", "}", "private", "ByteBuffer", "inet_open", "(", "ByteBuffer", "cmd", ")", "{", "if", "(", "cmd", ".", "remaining", "(", ")", "==", "1", ")", "{", "byte", "family", "=", "cmd", ".", "get", "(", ")", ";", "if", "(", "family", "==", "INET_AF_INET", "||", "family", "==", "INET_AF_INET6", ")", "{", "return", "inet_ctl_open", "(", "decode_proto_family", "(", "family", ")", ",", "ProtocolType", ".", "STREAM", ")", ";", "}", "}", "return", "ctl_error", "(", "Posix", ".", "EINVAL", ")", ";", "}", "private", "ByteBuffer", "inet_connect", "(", "EPID", "caller", ",", "ByteBuffer", "cmd", ")", "throws", "Pausable", "{", "if", "(", "!", "is_open", "(", ")", ")", "{", "return", "ctl_xerror", "(", "EXBADPORT", ")", ";", "}", "else", "if", "(", "is_connected", "(", ")", ")", "{", "return", "ctl_error", "(", "Posix", ".", "EISCONN", ")", ";", "}", "else", "if", "(", "!", "is_bound", "(", ")", ")", "{", "return", "ctl_xerror", "(", "EXBADSEQ", ")", ";", "}", "else", "if", "(", "is_connecting", "(", ")", ")", "{", "return", "ctl_error", "(", "Posix", ".", "EINVAL", ")", ";", "}", "int", "timeout", "=", "cmd", ".", "getInt", "(", ")", ";", "remote", "=", "inet_set_address", "(", "sfamily", ",", "cmd", ")", ";", "if", "(", "remote", "==", "null", ")", "{", "return", "ctl_error", "(", "Posix", ".", "EINVAL", ")", ";", "}", "try", "{", "short", "aid", ";", "ByteBuffer", "reply", "=", "ByteBuffer", ".", "allocate", "(", "3", ")", ";", "reply", ".", "put", "(", "INET_REP_OK", ")", ";", "if", "(", "this", ".", "fd", ".", "connect", "(", "remote", ")", ")", "{", "state", "=", "TCP_STATE_CONNECTED", ";", "if", "(", "active", "!=", "ActiveType", ".", "PASSIVE", ")", "sock_select", "(", "ERL_DRV_READ", ",", "SelectMode", ".", "SET", ")", ";", "aid", "=", "enq_async", "(", "caller", ",", "reply", ",", "INET_REQ_CONNECT", ")", ";", "async_ok", "(", ")", ";", "}", "else", "{", "state", "=", "TCP_STATE_CONNECTING", ";", "if", "(", "timeout", "!=", "INET_INFINITY", ")", "driver_set_timer", "(", "timeout", ")", ";", "sock_select", "(", "ERL_DRV_CONNECT", ",", "SelectMode", ".", "SET", ")", ";", "aid", "=", "enq_async", "(", "caller", ",", "reply", ",", "INET_REQ_CONNECT", ")", ";", "}", "return", "reply", ";", "}", "catch", "(", "IOException", "e", ")", "{", "e", ".", "printStackTrace", "(", ")", ";", "return", "ctl_error", "(", "IO", ".", "exception_to_posix_code", "(", "e", ")", ")", ";", "}", "}", "private", "ByteBuffer", "inet_bind", "(", "ByteBuffer", "cmd", ")", "{", "if", "(", "cmd", ".", "remaining", "(", ")", "<", "2", ")", "return", "ctl_error", "(", "Posix", ".", "EINVAL", ")", ";", "if", "(", "state", "!=", "INET_STATE_OPEN", ")", "return", "ctl_xerror", "(", "EXBADSEQ", ")", ";", "InetSocketAddress", "addr", "=", "inet_set_address", "(", "sfamily", ",", "cmd", ")", ";", "if", "(", "addr", "==", "null", ")", "return", "ctl_error", "(", "Posix", ".", "EINVAL", ")", ";", "try", "{", "fd", ".", "bind", "(", "addr", ")", ";", "}", "catch", "(", "IOException", "e1", ")", "{", "e1", ".", "printStackTrace", "(", ")", ";", "return", "ctl_error", "(", "IO", ".", "exception_to_posix_code", "(", "e1", ")", ")", ";", "}", "state", "=", "INET_STATE_BOUND", ";", "int", "port", "=", "addr", ".", "getPort", "(", ")", ";", "if", "(", "port", "==", "0", ")", "{", "port", "=", "fd", ".", "getLocalPort", "(", ")", ";", "}", "ByteBuffer", "reply", "=", "ByteBuffer", ".", "allocate", "(", "3", ")", ";", "reply", ".", "order", "(", "ByteOrder", ".", "nativeOrder", "(", ")", ")", ";", "reply", ".", "put", "(", "INET_REP_OK", ")", ";", "reply", ".", "putShort", "(", "(", "short", ")", "(", "port", "&", "0xFFFF", ")", ")", ";", "return", "reply", ";", "}", "private", "boolean", "async_ok", "(", ")", "throws", "Pausable", "{", "AsyncOp", "op", "=", "deq_async", "(", ")", ";", "if", "(", "op", "==", "null", ")", "{", "return", "false", ";", "}", "return", "send_async_ok", "(", "op", ".", "id", ",", "op", ".", "caller", ")", ";", "}", "AsyncOp", "deq_async", "(", ")", "{", "return", "deq_async_w_tmo", "(", ")", ";", "}", "private", "AsyncOp", "deq_async_w_tmo", "(", ")", "{", "if", "(", "opt", ".", "size", "(", ")", "==", "0", ")", "return", "null", ";", "return", "opt", ".", "get", "(", ")", ";", "}", "private", "boolean", "inet_reply_error", "(", "EObject", "reason", ")", "throws", "Pausable", "{", "EHandle", "caller", "=", "this", ".", "caller", ";", "this", ".", "caller", "=", "null", ";", "ETuple", "msg", "=", "ETuple", ".", "make", "(", "am_inet_reply", ",", "port", "(", ")", ",", "new", "ETuple2", "(", "ERT", ".", "am_error", ",", "reason", ")", ")", ";", "if", "(", "portlog", ".", "isLoggable", "(", "Level", ".", "FINER", ")", ")", "{", "portlog", ".", "finer", "(", "\"sending", "to", "\"", "+", "caller", "+", "\"", "!", "\"", "+", "msg", ")", ";", "}", "driver_send_term", "(", "caller", ",", "msg", ")", ";", "return", "true", ";", "}", "private", "boolean", "inet_reply_error", "(", "int", "reason", ")", "throws", "Pausable", "{", "return", "inet_reply_error", "(", "EAtom", ".", "intern", "(", "Posix", ".", "errno_id", "(", "reason", ")", ")", ")", ";", "}", "private", "boolean", "send_async_error", "(", "short", "id", ",", "EPID", "caller", ",", "EObject", "reason", ")", "throws", "Pausable", "{", "ETuple", "msg", "=", "ETuple", ".", "make", "(", "am_inet_async", ",", "port", "(", ")", ",", "ERT", ".", "box", "(", "id", ")", ",", "new", "ETuple2", "(", "ERT", ".", "am_error", ",", "reason", ")", ")", ";", "if", "(", "portlog", ".", "isLoggable", "(", "Level", ".", "FINER", ")", ")", "{", "portlog", ".", "finer", "(", "\"sending", "to", "\"", "+", "caller", "+", "\"", "!", "\"", "+", "msg", ")", ";", "}", "caller", ".", "send", "(", "port", "(", ")", ",", "msg", ")", ";", "return", "true", ";", "}", "private", "boolean", "send_async_ok", "(", "int", "id", ",", "EPID", "caller", ")", "throws", "Pausable", "{", "ETuple", "msg", "=", "ETuple", ".", "make", "(", "am_inet_async", ",", "port", "(", ")", ",", "ERT", ".", "box", "(", "id", ")", ",", "ERT", ".", "am_ok", ")", ";", "if", "(", "portlog", ".", "isLoggable", "(", "Level", ".", "FINER", ")", ")", "{", "portlog", ".", "finer", "(", "\"sending", "to", "\"", "+", "caller", "+", "\"", "!", "\"", "+", "msg", ")", ";", "}", "caller", ".", "send", "(", "port", "(", ")", ",", "msg", ")", ";", "return", "true", ";", "}", "private", "boolean", "send_async_ok_port", "(", "int", "id", ",", "EPID", "caller", ",", "EPort", "port2", ")", "throws", "Pausable", "{", "ETuple", "msg", "=", "ETuple", ".", "make", "(", "am_inet_async", ",", "port", "(", ")", ",", "ERT", ".", "box", "(", "id", ")", ",", "new", "ETuple2", "(", "ERT", ".", "am_ok", ",", "port2", ")", ")", ";", "if", "(", "portlog", ".", "isLoggable", "(", "Level", ".", "FINER", ")", ")", "{", "log", ".", "finer", "(", "\"sending", "to", "\"", "+", "caller", "+", "\"", "!", "\"", "+", "msg", ")", ";", "}", "caller", ".", "send", "(", "port", "(", ")", ",", "msg", ")", ";", "return", "true", ";", "}", "private", "short", "enq_async", "(", "EPID", "caller", ",", "ByteBuffer", "reply", ",", "int", "req", ")", "{", "return", "enq_async_w_tmo", "(", "caller", ",", "reply", ",", "req", ",", "INET_INFINITY", ",", "(", "ERef", ")", "null", ")", ";", "}", "static", "AtomicInteger", "aid", "=", "new", "AtomicInteger", "(", "0", ")", ";", "private", "short", "enq_async_w_tmo", "(", "EPID", "caller", ",", "ByteBuffer", "reply", ",", "int", "req", ",", "int", "timeout", ",", "ERef", "monitor", ")", "{", "short", "id", "=", "(", "short", ")", "(", "aid", ".", "incrementAndGet", "(", ")", "&", "0x7fff", ")", ";", "AsyncOp", "op", "=", "new", "AsyncOp", "(", "id", ",", "caller", ",", "req", ",", "timeout", ",", "monitor", ")", ";", "if", "(", "reply", "!=", "null", ")", "{", "reply", ".", "putShort", "(", "op", ".", "id", ")", ";", "}", "opt", ".", "put", "(", "op", ")", ";", "return", "op", ".", "id", ";", "}", "private", "InetSocketAddress", "inet_set_address", "(", "ProtocolFamily", "sfamily2", ",", "ByteBuffer", "cmd", ")", "{", "int", "port", "=", "cmd", ".", "getShort", "(", ")", "&", "0xffff", ";", "byte", "[", "]", "bytes", ";", "if", "(", "sfamily2", "==", "ProtocolFamily", ".", "INET", ")", "{", "bytes", "=", "new", "byte", "[", "4", "]", ";", "}", "else", "if", "(", "sfamily2", "==", "ProtocolFamily", ".", "INET6", ")", "{", "bytes", "=", "new", "byte", "[", "16", "]", ";", "}", "else", "{", "return", "null", ";", "}", "InetAddress", "addr", ";", "try", "{", "if", "(", "cmd", ".", "remaining", "(", ")", "==", "0", ")", "{", "addr", "=", "InetAddress", ".", "getLocalHost", "(", ")", ";", "}", "else", "{", "cmd", ".", "get", "(", "bytes", ")", ";", "addr", "=", "InetAddress", ".", "getByAddress", "(", "bytes", ")", ";", "}", "}", "catch", "(", "UnknownHostException", "e", ")", "{", "return", "null", ";", "}", "InetSocketAddress", "res", "=", "new", "InetSocketAddress", "(", "addr", ",", "port", ")", ";", "return", "res", ";", "}", "private", "boolean", "is_connecting", "(", ")", "{", "return", "(", "state", "&", "INET_F_CON", ")", "==", "INET_F_CON", ";", "}", "private", "boolean", "is_bound", "(", ")", "{", "return", "(", "state", "&", "INET_F_BOUND", ")", "==", "INET_F_BOUND", ";", "}", "private", "boolean", "is_connected", "(", ")", "{", "return", "(", "state", "&", "INET_STATE_CONNECTED", ")", "==", "INET_STATE_CONNECTED", ";", "}", "private", "boolean", "is_open", "(", ")", "{", "return", "(", "state", "&", "INET_F_OPEN", ")", "==", "INET_F_OPEN", ";", "}", "private", "ByteBuffer", "inet_subscribe", "(", "EPID", "caller", ",", "ByteBuffer", "cmd", ")", "{", "ByteBuffer", "reply", "=", "ByteBuffer", ".", "allocate", "(", "1", "+", "cmd", ".", "remaining", "(", ")", "*", "5", ")", ";", "reply", ".", "put", "(", "INET_REP_OK", ")", ";", "while", "(", "cmd", ".", "hasRemaining", "(", ")", ")", "{", "byte", "op", "=", "cmd", ".", "get", "(", ")", ";", "if", "(", "op", "==", "INET_SUBS_EMPTY_OUT_Q", ")", "{", "reply", ".", "put", "(", "INET_SUBS_EMPTY_OUT_Q", ")", ";", "int", "val", "=", "driver_sizeq", "(", ")", ";", "if", "(", "val", ">", "0", ")", "{", "save_subscriber", "(", "empty_out_q_subs", ",", "caller", ")", ";", "}", "reply", ".", "putInt", "(", "val", ")", ";", "}", "else", "{", "throw", "new", "ErlangError", "(", "EAtom", ".", "intern", "(", "\"einval\"", ")", ")", ";", "}", "}", "return", "reply", ";", "}", "private", "boolean", "save_subscriber", "(", "List", "<", "EHandle", ">", "subs", ",", "EPID", "pid", ")", "{", "subs", ".", "add", "(", "pid", ")", ";", "return", "true", ";", "}", "private", "ByteBuffer", "inet_ctl_open", "(", "ProtocolFamily", "domain", ",", "ProtocolType", "type", ")", "{", "if", "(", "state", "!=", "INET_STATE_CLOSED", ")", "{", "return", "ctl_xerror", "(", "EXBADSEQ", ")", ";", "}", "try", "{", "this", ".", "fd", "=", "InetSocket", ".", "open", "(", "domain", ",", "type", ",", "protocol", ")", ";", "fd", ".", "configureBlocking", "(", "false", ")", ";", "}", "catch", "(", "IOException", "e", ")", "{", "int", "code", "=", "IO", ".", "exception_to_posix_code", "(", "e", ")", ";", "return", "ctl_error", "(", "code", ")", ";", "}", "this", ".", "state", "=", "INET_STATE_OPEN", ";", "this", ".", "stype", "=", "type", ";", "this", ".", "sfamily", "=", "domain", ";", "return", "ctl_reply", "(", "INET_REP_OK", ")", ";", "}", "private", "ProtocolFamily", "decode_proto_family", "(", "byte", "domain", ")", "{", "switch", "(", "domain", ")", "{", "case", "INET_AF_INET", ":", "return", "ProtocolFamily", ".", "INET", ";", "case", "INET_AF_INET6", ":", "return", "ProtocolFamily", ".", "INET6", ";", "case", "INET_AF_ANY", ":", "return", "ProtocolFamily", ".", "ANY", ";", "case", "INET_AF_LOOPBACK", ":", "return", "ProtocolFamily", ".", "LOOPBACK", ";", "default", ":", "throw", "new", "NotImplemented", "(", ")", ";", "}", "}", "private", "byte", "encode_proto_family", "(", "ProtocolFamily", "domain", ")", "{", "switch", "(", "domain", ")", "{", "case", "INET", ":", "return", "INET_AF_INET", ";", "case", "INET6", ":", "return", "INET_AF_INET6", ";", "case", "ANY", ":", "return", "INET_AF_ANY", ";", "case", "LOOPBACK", ":", "return", "INET_AF_LOOPBACK", ";", "default", ":", "throw", "new", "NotImplemented", "(", ")", ";", "}", "}", "private", "ByteBuffer", "ctl_reply", "(", "int", "code", ")", "{", "ByteBuffer", "buf", "=", "ByteBuffer", ".", "allocate", "(", "1", ")", ";", "buf", ".", "put", "(", "(", "byte", ")", "code", ")", ";", "return", "buf", ";", "}", "private", "ByteBuffer", "ctl_xerror", "(", "byte", "[", "]", "exbadseq2", ")", "{", "return", "ctl_reply", "(", "INET_REP_ERROR", ",", "exbadseq2", ")", ";", "}", "private", "ByteBuffer", "ctl_reply", "(", "int", "code", ",", "byte", "[", "]", "data", ")", "{", "ByteBuffer", "buf", "=", "ByteBuffer", ".", "allocate", "(", "1", "+", "data", ".", "length", ")", ";", "buf", ".", "put", "(", "(", "byte", ")", "code", ")", ";", "buf", ".", "put", "(", "data", ")", ";", "return", "buf", ";", "}", "private", "ByteBuffer", "ctl_reply", "(", "int", "code", ",", "String", "data", ")", "{", "ByteBuffer", "buf", "=", "ByteBuffer", ".", "allocate", "(", "1", "+", "data", ".", "length", "(", ")", ")", ";", "buf", ".", "put", "(", "(", "byte", ")", "code", ")", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "data", ".", "length", "(", ")", ";", "i", "++", ")", "{", "buf", ".", "put", "(", "(", "byte", ")", "data", ".", "charAt", "(", "i", ")", ")", ";", "}", "return", "buf", ";", "}", "private", "ByteBuffer", "ctl_error", "(", "int", "err", ")", "{", "String", "id", "=", "Posix", ".", "errno_id", "(", "err", ")", ";", "return", "ctl_reply", "(", "INET_REP_ERROR", ",", "id", ")", ";", "}", "void", "state", "(", "StringBuffer", "sb", ")", "{", "if", "(", "(", "state", "&", "TCP_STATE_ACCEPTING", ")", "!=", "0", ")", "sb", ".", "append", "(", "\"Ac\"", ")", ";", "if", "(", "(", "state", "&", "TCP_STATE_BOUND", ")", "!=", "0", ")", "sb", ".", "append", "(", "\"Bo\"", ")", ";", "if", "(", "(", "state", "&", "TCP_STATE_CLOSED", ")", "!=", "0", ")", "sb", ".", "append", "(", "\"Clo\"", ")", ";", "if", "(", "(", "state", "&", "TCP_STATE_CONNECTED", ")", "!=", "0", ")", "sb", ".", "append", "(", "\"Con\"", ")", ";", "if", "(", "(", "state", "&", "TCP_STATE_CONNECTING", ")", "!=", "0", ")", "sb", ".", "append", "(", "\"Cog\"", ")", ";", "if", "(", "(", "state", "&", "TCP_STATE_LISTEN", ")", "!=", "0", ")", "sb", ".", "append", "(", "\"Li\"", ")", ";", "if", "(", "(", "state", "&", "TCP_STATE_MULTI_ACCEPTING", ")", "!=", "0", ")", "sb", ".", "append", "(", "\"Mu\"", ")", ";", "if", "(", "(", "state", "&", "TCP_STATE_OPEN", ")", "!=", "0", ")", "sb", ".", "append", "(", "\"Op\"", ")", ";", "}", "@", "Override", "public", "String", "toString", "(", ")", "{", "StringBuffer", "sb", "=", "new", "StringBuffer", "(", "\"TCPIP@\"", ")", ";", "sb", ".", "append", "(", "System", ".", "identityHashCode", "(", "this", ")", ")", ";", "sb", ".", "append", "(", "'['", ")", ";", "sb", ".", "append", "(", "\"sock=\"", ")", ".", "append", "(", "fd", ")", ";", "sb", ".", "append", "(", "\";", "state=\"", ")", ";", "state", "(", "sb", ")", ";", "sb", ".", "append", "(", "\";", "active=\"", ")", ".", "append", "(", "active", ")", ";", "sb", ".", "append", "(", "\";", "deliver=\"", ")", ".", "append", "(", "deliver", ")", ";", "sb", ".", "append", "(", "\";", "select=\"", ")", ".", "append", "(", "Integer", ".", "toBinaryString", "(", "event_mask", ")", ")", ";", "if", "(", "fd", "!=", "null", "&&", "fd", ".", "channel", "(", ")", "!=", "null", ")", "{", "SelectionKey", "sk", "=", "NIOSelector", ".", "interest", "(", "fd", ".", "channel", "(", ")", ")", ";", "if", "(", "sk", "==", "null", ")", "{", "sb", ".", "append", "(", "\";", "nointrest\"", ")", ";", "}", "else", "if", "(", "!", "sk", ".", "isValid", "(", ")", ")", "{", "sb", ".", "append", "(", "\";", "cancelled\"", ")", ";", "}", "else", "{", "try", "{", "sb", ".", "append", "(", "\";", "ready=\"", "+", "Integer", ".", "toBinaryString", "(", "sk", ".", "readyOps", "(", ")", ")", ")", ";", "sb", ".", "append", "(", "\";", "interest=\"", "+", "Integer", ".", "toBinaryString", "(", "sk", ".", "interestOps", "(", ")", ")", ")", ";", "}", "catch", "(", "CancelledKeyException", "e", ")", "{", "sb", ".", "append", "(", "\";", "cancelled\"", ")", ";", "}", "}", "}", "sb", ".", "append", "(", "']'", ")", ";", "return", "sb", ".", "toString", "(", ")", ";", "}", "}", "</s>" ]
7,754
[ "<s>", "package", "erjang", ".", "driver", ".", "tcp_inet", ";", "class", "PacketHttpURI", "{", "static", "enum", "URIType", "{", "URI_STAR", ",", "URI_STRING", ",", "URI_ABS_PATH", ",", "URI_SCHEME", ",", "URI_HTTP", ",", "URI_HTTPS", "}", ";", "URIType", "type", ";", "public", "byte", "[", "]", "s1_data", ";", "public", "int", "s1_ptr", ";", "public", "int", "s1_len", ";", "public", "byte", "[", "]", "s2_data", ";", "public", "int", "s2_ptr", ";", "public", "int", "s2_len", ";", "public", "int", "port", ";", "}", "</s>" ]
7,755
[ "<s>", "package", "erjang", ".", "driver", ".", "tcp_inet", ";", "import", "java", ".", "nio", ".", "ByteBuffer", ";", "import", "kilim", ".", "Pausable", ";", "import", "erjang", ".", "EAtom", ";", "import", "erjang", ".", "NotImplemented", ";", "import", "erjang", ".", "driver", ".", "IO", ";", "import", "erjang", ".", "driver", ".", "tcp_inet", ".", "PacketHttpURI", ".", "URIType", ";", "public", "class", "Packet", "{", "private", "static", "final", "int", "HTTP_HDR_HASH_SIZE", "=", "53", ";", "private", "static", "final", "int", "HTTP_METH_HASH_SIZE", "=", "13", ";", "private", "static", "final", "int", "HTTP_MAX_NAME_LEN", "=", "20", ";", "public", "static", "void", "get_body", "(", "PacketParseType", "htype", ",", "ByteBuffer", "out", ")", "{", "switch", "(", "htype", ")", "{", "case", "TCP_PB_1", ":", "out", ".", "position", "(", "out", ".", "position", "(", ")", "+", "1", ")", ";", "break", ";", "case", "TCP_PB_2", ":", "out", ".", "position", "(", "out", ".", "position", "(", ")", "+", "2", ")", ";", "break", ";", "case", "TCP_PB_4", ":", "out", ".", "position", "(", "out", ".", "position", "(", ")", "+", "4", ")", ";", "break", ";", "case", "TCP_PB_FCGI", ":", "out", ".", "limit", "(", "out", ".", "limit", "(", ")", "-", "(", "0xff", "&", "out", ".", "get", "(", "6", ")", ")", ")", ";", "break", ";", "default", ":", ";", "}", "}", "public", "static", "<", "T", ">", "int", "parse", "(", "PacketParseType", "htype", ",", "byte", "[", "]", "data", ",", "int", "buf", ",", "int", "len", ",", "IntCell", "statep", ",", "PacketCallbacks", "<", "T", ">", "pcb", ",", "T", "arg", ")", "throws", "Pausable", "{", "switch", "(", "htype", ")", "{", "case", "TCP_PB_HTTP", ":", "case", "TCP_PB_HTTPH", ":", "case", "TCP_PB_HTTP_BIN", ":", "case", "TCP_PB_HTTPH_BIN", ":", "if", "(", "parse_http", "(", "data", ",", "buf", ",", "len", ",", "statep", ",", "pcb", ",", "arg", ")", "<", "0", ")", "pcb", ".", "http_error", "(", "arg", ",", "data", ",", "buf", ",", "len", ")", ";", "return", "1", ";", "case", "TCP_PB_SSL_TLS", ":", "return", "parse_ssl", "(", "data", ",", "buf", ",", "len", ",", "pcb", ",", "arg", ")", ";", "default", ":", "}", "return", "0", ";", "}", "public", "static", "<", "T", ">", "int", "parse_http", "(", "byte", "[", "]", "data", ",", "int", "buf", ",", "int", "len", ",", "IntCell", "statep", ",", "PacketCallbacks", "<", "T", ">", "pcb", ",", "T", "arg", ")", "throws", "Pausable", "{", "int", "ptr", "=", "buf", ";", "int", "p0", ";", "int", "n", "=", "len", ";", "if", "(", "(", "n", ">=", "2", ")", "&&", "(", "data", "[", "buf", "+", "n", "-", "2", "]", "==", "'\\r'", ")", ")", "n", "-=", "2", ";", "else", "if", "(", "(", "n", ">=", "1", ")", "&&", "(", "data", "[", "buf", "+", "n", "-", "1", "]", "==", "'\\n'", ")", ")", "n", "-=", "1", ";", "if", "(", "statep", ".", "get", "(", ")", "==", "0", ")", "{", "if", "(", "n", ">=", "5", "&&", "(", "strncmp", "(", "data", ",", "buf", ",", "\"HTTP/\"", ",", "5", ")", "==", "0", ")", ")", "{", "int", "major", "=", "0", ";", "int", "minor", "=", "0", ";", "int", "status", "=", "0", ";", "ptr", "+=", "5", ";", "n", "-=", "5", ";", "p0", "=", "ptr", ";", "while", "(", "n", "!=", "0", "&&", "isdigit", "(", "data", ",", "ptr", ")", ")", "{", "major", "=", "10", "*", "major", "+", "(", "data", "[", "ptr", "]", "-", "'0'", ")", ";", "ptr", "++", ";", "n", "--", ";", "}", "if", "(", "ptr", "==", "p0", "||", "n", "==", "0", "||", "(", "data", "[", "ptr", "]", "!=", "'.'", ")", ")", "return", "-", "1", ";", "ptr", "++", ";", "n", "--", ";", "p0", "=", "ptr", ";", "while", "(", "n", "!=", "0", "&&", "isdigit", "(", "(", "int", ")", "data", "[", "ptr", "]", ")", ")", "{", "minor", "=", "10", "*", "minor", "+", "(", "data", "[", "ptr", "]", "-", "'0'", ")", ";", "ptr", "++", ";", "n", "--", ";", "}", "if", "(", "ptr", "==", "p0", ")", "return", "-", "1", ";", "p0", "=", "ptr", ";", "while", "(", "n", "!=", "0", "&&", "SP", "(", "data", ",", "ptr", ")", ")", "{", "ptr", "++", ";", "n", "--", ";", "}", "if", "(", "ptr", "==", "p0", ")", "return", "-", "1", ";", "while", "(", "n", "!=", "0", "&&", "isdigit", "(", "(", "int", ")", "data", "[", "ptr", "]", ")", ")", "{", "status", "=", "10", "*", "status", "+", "(", "data", "[", "ptr", "]", "-", "'0'", ")", ";", "ptr", "++", ";", "n", "--", ";", "}", "p0", "=", "ptr", ";", "while", "(", "n", "!=", "0", "&&", "SP", "(", "data", ",", "ptr", ")", ")", "{", "ptr", "++", ";", "n", "--", ";", "}", "if", "(", "ptr", "==", "p0", ")", "return", "-", "1", ";", "statep", ".", "set", "(", "~", "0", ")", ";", "return", "pcb", ".", "http_response", "(", "arg", ",", "major", ",", "minor", ",", "status", ",", "data", ",", "ptr", ",", "n", ")", ";", "}", "else", "{", "HTTPAtom", "meth", ";", "int", "meth_ptr", "=", "buf", ";", "int", "meth_len", ";", "PacketHttpURI", "uri", ";", "int", "uri_ptr", ";", "int", "uri_len", ";", "int", "major", "=", "0", ";", "int", "minor", "=", "0", ";", "int", "h", "=", "0", ";", "while", "(", "n", "!=", "0", "&&", "!", "is_tspecial", "(", "data", "[", "ptr", "]", ")", ")", "{", "h", "=", "hash_update", "(", "h", ",", "data", "[", "ptr", "]", ")", ";", "ptr", "++", ";", "n", "--", ";", "}", "meth_len", "=", "ptr", "-", "meth_ptr", ";", "if", "(", "n", "==", "0", "||", "meth_len", "==", "0", "||", "!", "SP", "(", "data", ",", "ptr", ")", ")", "return", "-", "1", ";", "meth", "=", "http_hash_lookup", "(", "data", ",", "meth_ptr", ",", "meth_len", ",", "h", ",", "http_meth_hash", ")", ";", "while", "(", "n", "!=", "0", "&&", "SP", "(", "data", ",", "ptr", ")", ")", "{", "ptr", "++", ";", "n", "--", ";", "}", "uri_ptr", "=", "ptr", ";", "while", "(", "n", "!=", "0", "&&", "!", "SP", "(", "data", ",", "ptr", ")", ")", "{", "ptr", "++", ";", "n", "--", ";", "}", "if", "(", "(", "uri_len", "=", "(", "ptr", "-", "uri_ptr", ")", ")", "==", "0", ")", "return", "-", "1", ";", "while", "(", "n", "!=", "0", "&&", "SP", "(", "data", ",", "ptr", ")", ")", "{", "ptr", "++", ";", "n", "--", ";", "}", "if", "(", "n", "==", "0", ")", "{", "statep", ".", "set", "(", "~", "0", ")", ";", "uri", "=", "http_parse_uri", "(", "data", ",", "uri_ptr", ",", "uri_len", ")", ";", "return", "pcb", ".", "http_request", "(", "arg", ",", "meth", ",", "data", ",", "meth_ptr", ",", "meth_len", ",", "uri", ",", "0", ",", "9", ")", ";", "}", "if", "(", "n", "<", "8", ")", "return", "-", "1", ";", "if", "(", "strncmp", "(", "data", ",", "ptr", ",", "\"HTTP/\"", ",", "5", ")", "!=", "0", ")", "return", "-", "1", ";", "ptr", "+=", "5", ";", "n", "-=", "5", ";", "p0", "=", "ptr", ";", "while", "(", "n", "!=", "0", "&&", "isdigit", "(", "(", "int", ")", "data", "[", "ptr", "]", ")", ")", "{", "major", "=", "10", "*", "major", "+", "(", "data", "[", "ptr", "]", "-", "'0'", ")", ";", "ptr", "++", ";", "n", "--", ";", "}", "if", "(", "ptr", "==", "p0", "||", "n", "==", "0", "||", "(", "data", "[", "ptr", "]", "!=", "'.'", ")", ")", "return", "-", "1", ";", "ptr", "++", ";", "n", "--", ";", "p0", "=", "ptr", ";", "while", "(", "n", "!=", "0", "&&", "isdigit", "(", "(", "int", ")", "data", "[", "ptr", "]", ")", ")", "{", "minor", "=", "10", "*", "minor", "+", "(", "data", "[", "ptr", "]", "-", "'0'", ")", ";", "ptr", "++", ";", "n", "--", ";", "}", "if", "(", "ptr", "==", "p0", ")", "return", "-", "1", ";", "statep", ".", "set", "(", "~", "0", ")", ";", "uri", "=", "http_parse_uri", "(", "data", ",", "uri_ptr", ",", "uri_len", ")", ";", "return", "pcb", ".", "http_request", "(", "arg", ",", "meth", ",", "data", ",", "meth_ptr", ",", "meth_len", ",", "uri", ",", "major", ",", "minor", ")", ";", "}", "}", "else", "{", "int", "up", "=", "1", ";", "HTTPAtom", "name", ";", "byte", "[", "]", "name_buf", "=", "new", "byte", "[", "HTTP_MAX_NAME_LEN", "]", ";", "int", "name_ptr", "=", "0", ";", "int", "name_len", ";", "int", "h", ";", "if", "(", "n", "==", "0", ")", "{", "statep", ".", "set", "(", "0", ")", ";", "return", "pcb", ".", "http_eoh", "(", "arg", ")", ";", "}", "h", "=", "0", ";", "name_len", "=", "0", ";", "while", "(", "!", "is_tspecial", "(", "data", "[", "ptr", "]", ")", ")", "{", "if", "(", "name_len", "<", "HTTP_MAX_NAME_LEN", ")", "{", "byte", "c", "=", "data", "[", "ptr", "]", ";", "if", "(", "up", "!=", "0", ")", "{", "if", "(", "islower", "(", "c", ")", ")", "{", "c", "=", "toupper", "(", "c", ")", ";", "}", "up", "=", "0", ";", "}", "else", "{", "if", "(", "isupper", "(", "c", ")", ")", "c", "=", "tolower", "(", "c", ")", ";", "else", "if", "(", "c", "==", "'-'", ")", "up", "=", "1", ";", "}", "name_buf", "[", "name_len", "]", "=", "c", ";", "h", "=", "hash_update", "(", "h", ",", "c", ")", ";", "}", "name_len", "++", ";", "ptr", "++", ";", "if", "(", "--", "n", "==", "0", ")", "return", "-", "1", ";", "}", "while", "(", "n", "!=", "0", "&&", "SP", "(", "data", ",", "ptr", ")", ")", "{", "ptr", "++", ";", "n", "--", ";", "}", "if", "(", "data", "[", "ptr", "]", "!=", "':'", ")", "{", "return", "-", "1", ";", "}", "if", "(", "name_len", "<=", "HTTP_MAX_NAME_LEN", ")", "{", "name", "=", "http_hash_lookup", "(", "name_buf", ",", "0", ",", "name_len", ",", "h", ",", "http_hdr_hash", ")", ";", "}", "else", "{", "name_ptr", "=", "buf", ";", "name", "=", "null", ";", "}", "ptr", "++", ";", "n", "--", ";", "while", "(", "n", "!=", "0", "&&", "SP", "(", "data", ",", "ptr", ")", ")", "{", "ptr", "++", ";", "n", "--", ";", "}", "return", "pcb", ".", "http_header", "(", "arg", ",", "name", ",", "name_buf", ",", "name_ptr", ",", "name_len", ",", "data", ",", "ptr", ",", "n", ")", ";", "}", "}", "private", "static", "byte", "tolower", "(", "byte", "c", ")", "{", "return", "(", "byte", ")", "Character", ".", "toLowerCase", "(", "c", ")", ";", "}", "private", "static", "boolean", "isupper", "(", "byte", "c", ")", "{", "return", "Character", ".", "isUpperCase", "(", "c", ")", ";", "}", "private", "static", "byte", "toupper", "(", "byte", "c", ")", "{", "return", "(", "byte", ")", "Character", ".", "toUpperCase", "(", "c", ")", ";", "}", "private", "static", "boolean", "islower", "(", "byte", "c", ")", "{", "return", "Character", ".", "isLowerCase", "(", "c", ")", ";", "}", "private", "static", "HTTPAtom", "http_hash_lookup", "(", "byte", "[", "]", "data", ",", "int", "ptr", ",", "int", "len", ",", "int", "h", ",", "HTTPAtom", "[", "]", "hash", ")", "{", "int", "ix", "=", "Math", ".", "abs", "(", "h", ")", "%", "hash", ".", "length", ";", "for", "(", "HTTPAtom", "entry", "=", "hash", "[", "ix", "]", ";", "entry", "!=", "null", ";", "entry", "=", "entry", ".", "next", ")", "{", "if", "(", "h", "==", "entry", ".", "h", "&&", "len", "==", "entry", ".", "len", "&&", "strncmp", "(", "data", ",", "ptr", ",", "entry", ".", "name", ",", "0", ",", "len", ")", "==", "0", ")", "{", "return", "entry", ";", "}", "}", "return", "null", ";", "}", "private", "static", "int", "strncmp", "(", "byte", "[", "]", "data", ",", "int", "ptr", ",", "byte", "[", "]", "string", ",", "int", "string_ptr", ",", "int", "i", ")", "{", "for", "(", "int", "p", "=", "0", ";", "p", "<", "i", ";", "p", "++", ")", "{", "int", "val", "=", "string", "[", "string_ptr", "+", "p", "]", "-", "data", "[", "ptr", "+", "p", "]", ";", "if", "(", "val", "!=", "0", ")", "return", "val", ";", "}", "return", "0", ";", "}", "private", "static", "int", "strncmp", "(", "byte", "[", "]", "data", ",", "int", "ptr", ",", "String", "string", ",", "int", "i", ")", "{", "for", "(", "int", "p", "=", "0", ";", "p", "<", "i", ";", "p", "++", ")", "{", "int", "val", "=", "string", ".", "charAt", "(", "p", ")", "-", "data", "[", "ptr", "+", "p", "]", ";", "if", "(", "val", "!=", "0", ")", "return", "val", ";", "}", "return", "0", ";", "}", "private", "static", "PacketHttpURI", "http_parse_uri", "(", "byte", "[", "]", "data", ",", "int", "uri_ptr", ",", "int", "uri_len", ")", "{", "PacketHttpURI", "uri", "=", "new", "PacketHttpURI", "(", ")", ";", "if", "(", "(", "uri_len", "==", "1", ")", "&&", "(", "data", "[", "uri_ptr", "+", "0", "]", "==", "'*'", ")", ")", "uri", ".", "type", "=", "URIType", ".", "URI_STAR", ";", "else", "if", "(", "(", "uri_len", "<=", "1", ")", "||", "(", "data", "[", "uri_ptr", "+", "0", "]", "==", "'/'", ")", ")", "{", "uri", ".", "type", "=", "URIType", ".", "URI_ABS_PATH", ";", "uri", ".", "s1_data", "=", "data", ";", "uri", ".", "s1_ptr", "=", "uri_ptr", ";", "uri", ".", "s1_len", "=", "uri_len", ";", "}", "else", "if", "(", "(", "uri_len", ">=", "7", ")", "&&", "(", "STRNCASECMP", "(", "data", ",", "uri_ptr", ",", "\"http://\"", ",", "7", ")", "==", "0", ")", ")", "{", "uri_len", "-=", "7", ";", "uri_ptr", "+=", "7", ";", "uri", ".", "type", "=", "URIType", ".", "URI_HTTP", ";", "http_parse_absoluteURI", "(", "uri", ",", "data", ",", "uri_ptr", ",", "uri_len", ")", ";", "}", "else", "if", "(", "(", "uri_len", ">=", "8", ")", "&&", "(", "STRNCASECMP", "(", "data", ",", "uri_ptr", ",", "\"https://\"", ",", "8", ")", "==", "0", ")", ")", "{", "uri_len", "-=", "8", ";", "uri_ptr", "+=", "8", ";", "uri", ".", "type", "=", "URIType", ".", "URI_HTTPS", ";", "http_parse_absoluteURI", "(", "uri", ",", "data", ",", "uri_ptr", ",", "uri_len", ")", ";", "}", "else", "{", "int", "ptr", ";", "if", "(", "(", "ptr", "=", "memchr", "(", "data", ",", "uri_ptr", ",", "':'", ",", "uri_len", ")", ")", "==", "-", "1", ")", "{", "uri", ".", "type", "=", "URIType", ".", "URI_STRING", ";", "uri", ".", "s1_ptr", "=", "uri_ptr", ";", "uri", ".", "s1_len", "=", "uri_len", ";", "}", "else", "{", "int", "slen", "=", "ptr", "-", "uri_ptr", ";", "uri", ".", "type", "=", "URIType", ".", "URI_SCHEME", ";", "uri", ".", "s1_ptr", "=", "uri_ptr", ";", "uri", ".", "s1_len", "=", "slen", ";", "uri", ".", "s2_data", "=", "data", ";", "uri", ".", "s2_ptr", "=", "uri_ptr", "+", "(", "slen", "+", "1", ")", ";", "uri", ".", "s2_len", "=", "uri_len", "-", "(", "slen", "+", "1", ")", ";", "}", "}", "return", "uri", ";", "}", "static", "final", "byte", "[", "]", "SLASH", "=", "new", "byte", "[", "]", "{", "'/'", "}", ";", "private", "static", "void", "http_parse_absoluteURI", "(", "PacketHttpURI", "uri", ",", "byte", "[", "]", "data", ",", "int", "uri_ptr", ",", "int", "uri_len", ")", "{", "int", "p", ";", "if", "(", "(", "p", "=", "memchr", "(", "data", ",", "uri_ptr", ",", "'/'", ",", "uri_len", ")", ")", "==", "-", "1", ")", "{", "uri", ".", "s2_data", "=", "SLASH", ";", "uri", ".", "s2_ptr", "=", "0", ";", "uri", ".", "s2_len", "=", "1", ";", "}", "else", "{", "int", "n", "=", "(", "p", "-", "uri_ptr", ")", ";", "uri", ".", "s2_data", "=", "data", ";", "uri", ".", "s2_ptr", "=", "p", ";", "uri", ".", "s2_len", "=", "uri_len", "-", "n", ";", "uri_len", "=", "n", ";", "}", "uri", ".", "s1_data", "=", "data", ";", "uri", ".", "s1_ptr", "=", "uri_ptr", ";", "uri", ".", "port", "=", "0", ";", "if", "(", "(", "p", "=", "memchr", "(", "data", ",", "uri_ptr", ",", "':'", ",", "uri_len", ")", ")", "==", "-", "1", ")", "{", "uri", ".", "s1_len", "=", "uri_len", ";", "}", "else", "{", "int", "n", "=", "(", "p", "-", "uri_ptr", ")", ";", "int", "port", "=", "0", ";", "uri", ".", "s1_len", "=", "n", ";", "n", "=", "uri_len", "-", "(", "n", "+", "1", ")", ";", "p", "++", ";", "while", "(", "n", "!=", "0", "&&", "isdigit", "(", "data", "[", "p", "]", ")", ")", "{", "port", "=", "port", "*", "10", "+", "(", "data", "[", "p", "]", "-", "'0'", ")", ";", "n", "--", ";", "p", "++", ";", "}", "if", "(", "n", "==", "0", "&&", "port", "!=", "0", ")", "uri", ".", "port", "=", "port", ";", "}", "}", "private", "static", "int", "STRNCASECMP", "(", "byte", "[", "]", "data", ",", "int", "s1", ",", "String", "s2", ",", "int", "n", ")", "{", "int", "i", ";", "for", "(", "i", "=", "0", ";", "i", "<", "n", "-", "1", "&&", "data", "[", "s1", "+", "i", "]", "!=", "0", "&&", "i", "<", "s2", ".", "length", "(", ")", "&&", "toupper", "(", "data", "[", "s1", "+", "i", "]", ")", "==", "toupper", "(", "(", "byte", ")", "s2", ".", "charAt", "(", "i", ")", ")", ";", "++", "i", ")", ";", "return", "(", "toupper", "(", "data", "[", "s1", "+", "i", "]", ")", "-", "toupper", "(", "(", "byte", ")", "s2", ".", "charAt", "(", "i", ")", ")", ")", ";", "}", "static", "class", "HTTPAtom", "{", "private", "final", "HTTPAtom", "next", ";", "private", "final", "int", "h", ";", "private", "final", "byte", "[", "]", "name", ";", "private", "final", "int", "len", ";", "final", "EAtom", "atom", ";", "final", "int", "index", ";", "public", "HTTPAtom", "(", "String", "am", ",", "int", "index", ",", "HTTPAtom", "[", "]", "hash", ")", "{", "this", ".", "index", "=", "index", ";", "this", ".", "atom", "=", "EAtom", ".", "intern", "(", "am", ")", ";", "this", ".", "name", "=", "am", ".", "getBytes", "(", "IO", ".", "ISO_LATIN_1", ")", ";", "int", "ptr", "=", "0", ",", "len", "=", "0", ",", "h", "=", "0", ";", "while", "(", "ptr", "!=", "name", ".", "length", ")", "{", "h", "=", "hash_update", "(", "h", ",", "name", "[", "ptr", "]", ")", ";", "ptr", "++", ";", "len", "++", ";", "}", "int", "ix", "=", "h", "%", "hash", ".", "length", ";", "this", ".", "len", "=", "len", ";", "this", ".", "h", "=", "h", ";", "this", ".", "next", "=", "hash", "[", "ix", "]", ";", "hash", "[", "ix", "]", "=", "this", ";", "}", "}", "static", "boolean", "[", "]", "tspecial", "=", "new", "boolean", "[", "128", "]", ";", "static", "HTTPAtom", "[", "]", "http_hdr_hash", "=", "new", "HTTPAtom", "[", "HTTP_HDR_HASH_SIZE", "]", ";", "static", "HTTPAtom", "[", "]", "http_meth_hash", "=", "new", "HTTPAtom", "[", "HTTP_METH_HASH_SIZE", "]", ";", "static", "String", "http_hdr_strings", "[", "]", "=", "{", "\"\"", ",", "\"Connection\"", ",", "\"Date\"", ",", "\"Pragma\"", ",", "\"\"", ",", "\"Upgrade\"", ",", "\"Via\"", ",", "\"Accept\"", ",", "\"\"", ",", "\"\"", ",", "\"\"", ",", "\"\"", ",", "\"From\"", ",", "\"Host\"", ",", "\"\"", ",", "\"If-Match\"", ",", "\"\"", ",", "\"If-Range\"", ",", "\"\"", ",", "\"Max-Forwards\"", ",", "\"\"", ",", "\"Range\"", ",", "\"Referer\"", ",", "\"User-Agent\"", ",", "\"Age\"", ",", "\"Location\"", ",", "\"\"", ",", "\"Public\"", ",", "\"Retry-After\"", ",", "\"Server\"", ",", "\"Vary\"", ",", "\"Warning\"", ",", "\"\"", ",", "\"Allow\"", ",", "\"Content-Base\"", ",", "\"\"", ",", "\"\"", ",", "\"\"", ",", "\"\"", ",", "\"Content-Md5\"", ",", "\"\"", ",", "\"Content-Type\"", ",", "\"Etag\"", ",", "\"Expires\"", ",", "\"\"", ",", "\"\"", ",", "\"Set-Cookie\"", ",", "\"Set-Cookie2\"", ",", "\"\"", ",", "\"Cookie\"", ",", "\"Keep-Alive\"", ",", "\"\"", ",", "null", "}", ";", "static", "String", "http_meth_strings", "[", "]", "=", "{", "\"OPTIONS\"", ",", "\"GET\"", ",", "\"HEAD\"", ",", "\"POST\"", ",", "\"PUT\"", ",", "\"DELETE\"", ",", "\"TRACE\"", ",", "null", "}", ";", "static", "{", "int", "i", ";", "for", "(", "i", "=", "0", ";", "i", "<", "33", ";", "i", "++", ")", "tspecial", "[", "i", "]", "=", "true", ";", "String", "specials", "=", "\"\"", ";", "for", "(", "i", "=", "0", ";", "i", "<", "specials", ".", "length", "(", ")", ";", "i", "++", ")", "{", "char", "val", "=", "specials", ".", "charAt", "(", "i", ")", ";", "tspecial", "[", "val", "]", "=", "true", ";", "}", "for", "(", "i", "=", "0", ";", "i", "<", "HTTP_HDR_HASH_SIZE", ";", "i", "++", ")", "http_hdr_hash", "[", "i", "]", "=", "null", ";", "for", "(", "i", "=", "0", ";", "http_hdr_strings", "[", "i", "]", "!=", "null", ";", "i", "++", ")", "{", "assert", "(", "http_hdr_strings", "[", "i", "]", ".", "length", "(", ")", "<=", "HTTP_MAX_NAME_LEN", ")", ";", "new", "HTTPAtom", "(", "http_hdr_strings", "[", "i", "]", ",", "i", ",", "http_hdr_hash", ")", ";", "}", "for", "(", "i", "=", "0", ";", "i", "<", "HTTP_METH_HASH_SIZE", ";", "i", "++", ")", "http_hdr_hash", "[", "i", "]", "=", "null", ";", "for", "(", "i", "=", "0", ";", "http_meth_strings", "[", "i", "]", "!=", "null", ";", "i", "++", ")", "{", "new", "HTTPAtom", "(", "http_meth_strings", "[", "i", "]", ",", "i", ",", "http_meth_hash", ")", ";", "}", "}", "private", "static", "boolean", "is_tspecial", "(", "byte", "x", ")", "{", "if", "(", "x", "<", "0", ")", "return", "false", ";", "return", "tspecial", "[", "x", "]", ";", "}", "static", "final", "int", "hash_update", "(", "int", "h", ",", "int", "c", ")", "{", "c", "&=", "0xff", ";", "int", "__g", ";", "(", "h", ")", "=", "(", "(", "h", ")", "<<", "4", ")", "+", "(", "c", ")", ";", "if", "(", "(", "__g", "=", "(", "h", ")", "&", "0xf0000000", ")", "!=", "0", ")", "{", "(", "h", ")", "^=", "(", "__g", ">>>", "24", ")", ";", "(", "h", ")", "^=", "__g", ";", "}", "return", "h", ";", "}", "private", "static", "boolean", "isdigit", "(", "byte", "[", "]", "data", ",", "int", "ptr", ")", "{", "byte", "ch", "=", "data", "[", "ptr", "]", ";", "return", "(", "ch", ">=", "'0'", "&&", "ch", "<=", "'9'", ")", ";", "}", "private", "static", "boolean", "isdigit", "(", "int", "data", ")", "{", "return", "(", "data", ">=", "'0'", "&&", "data", "<=", "'9'", ")", ";", "}", "public", "static", "<", "T", ">", "int", "parse_ssl", "(", "byte", "[", "]", "buf", ",", "int", "start", ",", "int", "len", ",", "PacketCallbacks", "<", "T", ">", "pcb", ",", "T", "arg", ")", "{", "throw", "new", "NotImplemented", "(", ")", ";", "}", "public", "static", "int", "get_length", "(", "PacketParseType", "htype", ",", "byte", "[", "]", "data", ",", "int", "ptr", ",", "int", "n", ",", "int", "max_plen", ",", "int", "trunc_len", ",", "IntCell", "statep", ")", "{", "int", "hlen", ",", "plen", ";", "switch", "(", "htype", ")", "{", "case", "TCP_PB_RAW", ":", "if", "(", "n", "==", "0", ")", "return", "0", ";", "else", "return", "n", ";", "case", "TCP_PB_1", ":", "hlen", "=", "1", ";", "if", "(", "n", "<", "hlen", ")", "return", "0", ";", "plen", "=", "data", "[", "ptr", "]", "&", "0xff", ";", "break", ";", "case", "TCP_PB_2", ":", "hlen", "=", "2", ";", "if", "(", "n", "<", "hlen", ")", "return", "0", ";", "plen", "=", "(", "(", "data", "[", "ptr", "]", "&", "0xff", ")", "<<", "8", ")", "|", "(", "data", "[", "ptr", "+", "1", "]", "&", "0xff", ")", ";", "break", ";", "case", "TCP_PB_4", ":", "hlen", "=", "4", ";", "if", "(", "n", "<", "hlen", ")", "return", "0", ";", "plen", "=", "(", "(", "data", "[", "ptr", "]", "&", "0xff", ")", "<<", "24", ")", "|", "(", "(", "data", "[", "ptr", "+", "1", "]", "&", "0xff", ")", "<<", "16", ")", "|", "(", "(", "data", "[", "ptr", "+", "2", "]", "&", "0xff", ")", "<<", "8", ")", "|", "(", "data", "[", "ptr", "+", "3", "]", "&", "0xff", ")", ";", "break", ";", "case", "TCP_PB_LINE_LF", ":", "{", "int", "ptr2", ";", "if", "(", "(", "ptr2", "=", "memchr", "(", "data", ",", "ptr", ",", "'\\n'", ",", "n", ")", ")", "==", "-", "1", ")", "{", "if", "(", "n", ">=", "trunc_len", "&&", "trunc_len", "!=", "0", ")", "{", "return", "trunc_len", ";", "}", "return", "0", ";", "}", "int", "len", "=", "(", "ptr2", "-", "ptr", ")", "+", "1", ";", "if", "(", "len", ">", "trunc_len", "&&", "trunc_len", "!=", "0", ")", "{", "return", "trunc_len", ";", "}", "return", "len", ";", "}", "case", "TCP_PB_HTTPH", ":", "case", "TCP_PB_HTTPH_BIN", ":", "statep", ".", "set", "(", "~", "0", ")", ";", "case", "TCP_PB_HTTP", ":", "case", "TCP_PB_HTTP_BIN", ":", "plen", "=", "n", ";", "if", "(", "(", "(", "plen", "==", "1", ")", "&&", "NL", "(", "data", ",", "ptr", ")", ")", "||", "(", "(", "plen", "==", "2", ")", "&&", "CRNL", "(", "data", ",", "ptr", ")", ")", ")", "return", "plen", ";", "else", "{", "int", "ptr1", "=", "ptr", ";", "int", "len", "=", "plen", ";", "while", "(", "true", ")", "{", "int", "ptr2", "=", "memchr", "(", "data", ",", "ptr1", ",", "'\\n'", ",", "len", ")", ";", "if", "(", "ptr2", "==", "-", "1", ")", "{", "if", "(", "n", ">=", "trunc_len", "&&", "trunc_len", "!=", "0", ")", "{", "plen", "=", "trunc_len", ";", "return", "plen", ";", "}", "return", "0", ";", "}", "else", "{", "plen", "=", "(", "ptr2", "-", "ptr", ")", "+", "1", ";", "if", "(", "statep", ".", "get", "(", ")", "==", "0", ")", "return", "plen", ";", "if", "(", "plen", "<", "n", ")", "{", "if", "(", "SP", "(", "data", ",", "ptr2", "+", "1", ")", "&&", "plen", ">", "2", ")", "{", "ptr1", "=", "ptr2", "+", "1", ";", "len", "=", "n", "-", "plen", ";", "}", "else", "return", "plen", ";", "}", "else", "return", "0", ";", "}", "}", "}", "default", ":", "throw", "new", "NotImplemented", "(", "\"\"", "+", "htype", ")", ";", "}", "int", "tlen", "=", "hlen", "+", "plen", ";", "if", "(", "(", "max_plen", "!=", "0", "&&", "plen", ">", "max_plen", ")", "||", "tlen", "<", "hlen", ")", "{", "return", "-", "1", ";", "}", "return", "tlen", ";", "}", "private", "static", "boolean", "SP", "(", "byte", "[", "]", "data", ",", "int", "ptr", ")", "{", "return", "data", "[", "ptr", "]", "==", "'", "'", "||", "data", "[", "ptr", "]", "==", "'\\t'", ";", "}", "private", "static", "boolean", "CRNL", "(", "byte", "[", "]", "data", ",", "int", "ptr", ")", "{", "return", "data", "[", "ptr", "]", "==", "'\\r'", "&&", "data", "[", "ptr", "+", "1", "]", "==", "'\\n'", ";", "}", "private", "static", "boolean", "NL", "(", "byte", "[", "]", "data", ",", "int", "ptr", ")", "{", "return", "data", "[", "ptr", "]", "==", "'\\n'", ";", "}", "private", "static", "int", "memchr", "(", "byte", "[", "]", "data", ",", "int", "offset", ",", "char", "c", ",", "int", "n", ")", "{", "for", "(", "int", "i", "=", "0", ";", "i", "<", "n", ";", "i", "++", ")", "{", "if", "(", "data", "[", "offset", "+", "i", "]", "==", "c", ")", "return", "offset", "+", "i", ";", "}", "return", "-", "1", ";", "}", "}", "</s>" ]
7,756
[ "<s>", "package", "erjang", ".", "driver", ".", "tcp_inet", ";", "import", "kilim", ".", "Pausable", ";", "public", "abstract", "class", "PacketCallbacks", "<", "T", ">", "{", "abstract", "int", "http_error", "(", "T", "src", ",", "byte", "[", "]", "data", ",", "int", "pos", ",", "int", "len", ")", "throws", "Pausable", ";", "abstract", "int", "http_response", "(", "T", "arg", ",", "int", "major", ",", "int", "minor", ",", "int", "status", ",", "byte", "[", "]", "data", ",", "int", "ptr", ",", "int", "n", ")", "throws", "Pausable", ";", "abstract", "int", "http_request", "(", "T", "arg", ",", "Packet", ".", "HTTPAtom", "method", ",", "byte", "[", "]", "data", ",", "int", "meth_ptr", ",", "int", "meth_len", ",", "PacketHttpURI", "uri", ",", "int", "major", ",", "int", "minor", ")", "throws", "Pausable", ";", "abstract", "int", "http_header", "(", "T", "arg", ",", "Packet", ".", "HTTPAtom", "name", ",", "byte", "[", "]", "name_buf", ",", "int", "name_ptr", ",", "int", "name_len", ",", "byte", "[", "]", "val_buf", ",", "int", "val_ptr", ",", "int", "val_len", ")", "throws", "Pausable", ";", "abstract", "int", "http_eoh", "(", "T", "arg", ")", "throws", "Pausable", ";", "}", "</s>" ]
7,757
[ "<s>", "package", "erjang", ".", "driver", ".", "tcp_inet", ";", "import", "kilim", ".", "Pausable", ";", "import", "erjang", ".", "EAtom", ";", "import", "erjang", ".", "EBinary", ";", "import", "erjang", ".", "EObject", ";", "import", "erjang", ".", "ERT", ";", "import", "erjang", ".", "EString", ";", "import", "erjang", ".", "ETuple", ";", "import", "erjang", ".", "ETuple2", ";", "import", "erjang", ".", "driver", ".", "tcp_inet", ".", "Packet", ".", "HTTPAtom", ";", "import", "erjang", ".", "driver", ".", "tcp_inet", ".", "TCPINet", ".", "ActiveType", ";", "import", "erjang", ".", "driver", ".", "tcp_inet", ".", "TCPINet", ".", "AsyncOp", ";", "public", "class", "TCPINetCallbacks", "extends", "PacketCallbacks", "<", "TCPINet", ">", "{", "private", "static", "final", "EAtom", "am_http_request", "=", "EAtom", ".", "intern", "(", "\"http_request\"", ")", ";", "private", "static", "final", "EAtom", "am_inet_async", "=", "EAtom", ".", "intern", "(", "\"inet_async\"", ")", ";", "private", "static", "final", "EAtom", "am_http", "=", "EAtom", ".", "intern", "(", "\"http\"", ")", ";", "private", "static", "final", "EAtom", "am_star", "=", "EAtom", ".", "intern", "(", "\"*\"", ")", ";", "private", "static", "final", "EAtom", "am_abs_path", "=", "EAtom", ".", "intern", "(", "\"abs_path\"", ")", ";", "private", "static", "final", "EAtom", "am_https", "=", "EAtom", ".", "intern", "(", "\"https\"", ")", ";", "private", "static", "final", "EAtom", "am_absoluteURI", "=", "EAtom", ".", "intern", "(", "\"absoluteURI\"", ")", ";", "private", "static", "final", "EAtom", "am_scheme", "=", "EAtom", ".", "intern", "(", "\"scheme\"", ")", ";", "private", "static", "final", "EAtom", "am_http_header", "=", "EAtom", ".", "intern", "(", "\"http_header\"", ")", ";", "private", "static", "final", "EAtom", "am_http_eoh", "=", "EAtom", ".", "intern", "(", "\"http_eoh\"", ")", ";", "private", "static", "final", "EAtom", "am_http_error", "=", "EAtom", ".", "intern", "(", "\"http_error\"", ")", ";", "@", "Override", "int", "http_eoh", "(", "TCPINet", "desc", ")", "throws", "Pausable", "{", "return", "send_http", "(", "desc", ",", "am_http_eoh", ")", ";", "}", "@", "Override", "int", "http_error", "(", "TCPINet", "desc", ",", "byte", "[", "]", "data", ",", "int", "pos", ",", "int", "len", ")", "throws", "Pausable", "{", "EObject", "line", "=", "load_string", "(", "desc", ",", "data", ",", "pos", ",", "len", ")", ";", "ETuple2", "req", "=", "new", "ETuple2", "(", "am_http_error", ",", "line", ")", ";", "if", "(", "desc", ".", "active", "==", "ActiveType", ".", "PASSIVE", ")", "{", "AsyncOp", "op", "=", "desc", ".", "deq_async", "(", ")", ";", "if", "(", "op", "==", "null", ")", "{", "return", "-", "1", ";", "}", "ETuple2", "ok", "=", "new", "ETuple2", "(", "ERT", ".", "am_error", ",", "req", ")", ";", "ETuple", "msg", "=", "ETuple", ".", "make", "(", "am_inet_async", ",", "desc", ".", "port", "(", ")", ",", "ERT", ".", "box", "(", "op", ".", "id", ")", ",", "ok", ")", ";", "desc", ".", "driver_send_term", "(", "op", ".", "caller", ",", "msg", ")", ";", "}", "else", "{", "ETuple", "http", "=", "ETuple", ".", "make", "(", "am_http", ",", "desc", ".", "port", "(", ")", ",", "req", ")", ";", "desc", ".", "driver_output_term", "(", "http", ")", ";", "}", "return", "0", ";", "}", "@", "Override", "int", "http_header", "(", "TCPINet", "desc", ",", "HTTPAtom", "name", ",", "byte", "[", "]", "nameBuf", ",", "int", "namePtr", ",", "int", "nameLen", ",", "byte", "[", "]", "valBuf", ",", "int", "valPtr", ",", "int", "valLen", ")", "throws", "Pausable", "{", "EObject", "bit", "=", "(", "name", "==", "null", ")", "?", "ERT", ".", "box", "(", "0", ")", ":", "ERT", ".", "box", "(", "name", ".", "index", "+", "1", ")", ";", "EObject", "nam", "=", "(", "name", "==", "null", ")", "?", "load_string", "(", "desc", ",", "nameBuf", ",", "namePtr", ",", "nameLen", ")", ":", "name", ".", "atom", ";", "EObject", "value", "=", "load_string", "(", "desc", ",", "valBuf", ",", "valPtr", ",", "valLen", ")", ";", "ETuple", "req", "=", "ETuple", ".", "make", "(", "am_http_header", ",", "bit", ",", "nam", ",", "ERT", ".", "am_undefined", ",", "value", ")", ";", "return", "send_http", "(", "desc", ",", "req", ")", ";", "}", "@", "Override", "int", "http_request", "(", "TCPINet", "desc", ",", "HTTPAtom", "method", ",", "byte", "[", "]", "data", ",", "int", "meth_ptr", ",", "int", "meth_len", ",", "PacketHttpURI", "uri", ",", "int", "major", ",", "int", "minor", ")", "throws", "Pausable", "{", "EObject", "meth", "=", "(", "method", "==", "null", ")", "?", "load_string", "(", "desc", ",", "data", ",", "meth_ptr", ",", "meth_len", ")", ":", "method", ".", "atom", ";", "ETuple", "version", "=", "new", "ETuple2", "(", "ERT", ".", "box", "(", "major", ")", ",", "ERT", ".", "box", "(", "minor", ")", ")", ";", "ETuple", "req", "=", "ETuple", ".", "make", "(", "am_http_request", ",", "meth", ",", "load_uri", "(", "desc", ",", "uri", ")", ",", "version", ")", ";", "return", "send_http", "(", "desc", ",", "req", ")", ";", "}", "private", "int", "send_http", "(", "TCPINet", "desc", ",", "EObject", "req", ")", "throws", "Pausable", "{", "if", "(", "desc", ".", "active", "==", "ActiveType", ".", "PASSIVE", ")", "{", "AsyncOp", "op", "=", "desc", ".", "deq_async", "(", ")", ";", "if", "(", "op", "==", "null", ")", "{", "return", "-", "1", ";", "}", "ETuple2", "ok", "=", "new", "ETuple2", "(", "ERT", ".", "am_ok", ",", "req", ")", ";", "ETuple", "msg", "=", "ETuple", ".", "make", "(", "am_inet_async", ",", "desc", ".", "port", "(", ")", ",", "ERT", ".", "box", "(", "op", ".", "id", ")", ",", "ok", ")", ";", "desc", ".", "driver_send_term", "(", "op", ".", "caller", ",", "msg", ")", ";", "}", "else", "{", "ETuple", "http", "=", "ETuple", ".", "make", "(", "am_http", ",", "desc", ".", "port", "(", ")", ",", "req", ")", ";", "desc", ".", "driver_output_term", "(", "http", ")", ";", "}", "return", "0", ";", "}", "private", "EObject", "load_uri", "(", "TCPINet", "desc", ",", "PacketHttpURI", "uri", ")", "{", "EAtom", "scheme", "=", "null", ";", "switch", "(", "uri", ".", "type", ")", "{", "case", "URI_STAR", ":", "return", "(", "EAtom", ")", "am_star", ";", "case", "URI_ABS_PATH", ":", "return", "new", "ETuple2", "(", "am_abs_path", ",", "load_string", "(", "desc", ",", "uri", ".", "s1_data", ",", "uri", ".", "s1_ptr", ",", "uri", ".", "s1_len", ")", ")", ";", "case", "URI_HTTPS", ":", "scheme", "=", "am_https", ";", "case", "URI_HTTP", ":", "if", "(", "scheme", "==", "null", ")", "{", "scheme", "=", "am_http", ";", "}", "return", "ETuple", ".", "make", "(", "am_absoluteURI", ",", "scheme", ",", "load_string", "(", "desc", ",", "uri", ".", "s1_data", ",", "uri", ".", "s1_ptr", ",", "uri", ".", "s1_len", ")", ",", "(", "uri", ".", "port", "==", "0", "?", "ERT", ".", "am_undefined", ":", "ERT", ".", "box", "(", "uri", ".", "port", ")", ")", ",", "load_string", "(", "desc", ",", "uri", ".", "s2_data", ",", "uri", ".", "s2_ptr", ",", "uri", ".", "s2_len", ")", ")", ";", "case", "URI_STRING", ":", "return", "load_string", "(", "desc", ",", "uri", ".", "s1_data", ",", "uri", ".", "s1_ptr", ",", "uri", ".", "s1_len", ")", ";", "case", "URI_SCHEME", ":", "return", "ETuple", ".", "make", "(", "am_scheme", ",", "load_string", "(", "desc", ",", "uri", ".", "s1_data", ",", "uri", ".", "s1_ptr", ",", "uri", ".", "s1_len", ")", ",", "load_string", "(", "desc", ",", "uri", ".", "s2_data", ",", "uri", ".", "s2_ptr", ",", "uri", ".", "s2_len", ")", ")", ";", "}", "throw", "new", "InternalError", "(", "\"\"", ")", ";", "}", "private", "EObject", "load_string", "(", "TCPINet", "desc", ",", "byte", "[", "]", "data", ",", "int", "data_off", ",", "int", "data_len", ")", "{", "switch", "(", "desc", ".", "htype", ")", "{", "case", "TCP_PB_HTTPH_BIN", ":", "case", "TCP_PB_HTTP_BIN", ":", "return", "EBinary", ".", "make", "(", "data", ",", "data_off", ",", "data_len", ",", "0", ")", ";", "default", ":", "return", "EString", ".", "make", "(", "data", ",", "data_off", ",", "data_len", ")", ";", "}", "}", "@", "Override", "int", "http_response", "(", "TCPINet", "arg", ",", "int", "major", ",", "int", "minor", ",", "int", "status", ",", "byte", "[", "]", "data", ",", "int", "off", ",", "int", "len", ")", "{", "throw", "new", "erjang", ".", "NotImplemented", "(", ")", ";", "}", "}", "</s>" ]
7,758
[ "<s>", "package", "erjang", ".", "driver", ".", "tcp_inet", ";", "public", "final", "class", "IntCell", "{", "int", "value", ";", "int", "get", "(", ")", "{", "return", "value", ";", "}", "void", "set", "(", "int", "val", ")", "{", "value", "=", "val", ";", "}", "}", "</s>" ]
7,759
[ "<s>", "package", "erjang", ".", "driver", ".", "tcp_inet", ";", "import", "java", ".", "util", ".", "concurrent", ".", "locks", ".", "ReentrantLock", ";", "import", "erjang", ".", "EString", ";", "import", "erjang", ".", "driver", ".", "EDriver", ";", "import", "erjang", ".", "driver", ".", "EDriverControl", ";", "import", "erjang", ".", "net", ".", "Protocol", ";", "public", "class", "Driver", "implements", "EDriver", "{", "@", "Override", "public", "String", "driverName", "(", ")", "{", "return", "\"tcp_inet\"", ";", "}", "@", "Override", "public", "void", "finish", "(", ")", "{", "}", "@", "Override", "public", "EDriverControl", "start", "(", "EString", "command", ")", "{", "TCPINet", "inst", "=", "new", "TCPINet", "(", "Protocol", ".", "TCP", ",", "this", ")", ";", "return", "inst", ";", "}", "@", "Override", "public", "boolean", "useDriverLevelLocking", "(", ")", "{", "return", "false", ";", "}", "@", "Override", "public", "ReentrantLock", "getLock", "(", ")", "{", "throw", "new", "erjang", ".", "NotImplemented", "(", ")", ";", "}", "}", "</s>" ]
7,760
[ "<s>", "package", "erjang", ".", "driver", ".", "tcp_inet", ";", "public", "enum", "PacketParseType", "{", "TCP_PB_RAW", "(", "0", ")", ",", "TCP_PB_1", "(", "1", ")", ",", "TCP_PB_2", "(", "2", ")", ",", "TCP_PB_4", "(", "3", ")", ",", "TCP_PB_ASN1", "(", "4", ")", ",", "TCP_PB_RM", "(", "5", ")", ",", "TCP_PB_CDR", "(", "6", ")", ",", "TCP_PB_FCGI", "(", "7", ")", ",", "TCP_PB_LINE_LF", "(", "8", ")", ",", "TCP_PB_TPKT", "(", "9", ")", ",", "TCP_PB_HTTP", "(", "10", ")", ",", "TCP_PB_HTTPH", "(", "11", ")", ",", "TCP_PB_SSL_TLS", "(", "12", ")", ",", "TCP_PB_HTTP_BIN", "(", "13", ")", ",", "TCP_PB_HTTPH_BIN", "(", "14", ")", ";", "public", "final", "int", "code", ";", "private", "PacketParseType", "(", "int", "code", ")", "{", "this", ".", "code", "=", "code", ";", "}", "public", "static", "PacketParseType", "valueOf", "(", "int", "ival", ")", "{", "switch", "(", "ival", ")", "{", "case", "0", ":", "return", "TCP_PB_RAW", ";", "case", "1", ":", "return", "TCP_PB_1", ";", "case", "2", ":", "return", "TCP_PB_2", ";", "case", "3", ":", "return", "TCP_PB_4", ";", "case", "4", ":", "return", "TCP_PB_ASN1", ";", "case", "5", ":", "return", "TCP_PB_RM", ";", "case", "6", ":", "return", "TCP_PB_CDR", ";", "case", "7", ":", "return", "TCP_PB_FCGI", ";", "case", "8", ":", "return", "TCP_PB_LINE_LF", ";", "case", "9", ":", "return", "TCP_PB_TPKT", ";", "case", "10", ":", "return", "TCP_PB_HTTP", ";", "case", "11", ":", "return", "TCP_PB_HTTPH", ";", "case", "12", ":", "return", "TCP_PB_SSL_TLS", ";", "case", "13", ":", "return", "TCP_PB_HTTP_BIN", ";", "case", "14", ":", "return", "TCP_PB_HTTPH_BIN", ";", "default", ":", "throw", "new", "IllegalArgumentException", "(", ")", ";", "}", "}", "}", "</s>" ]
7,761
[ "<s>", "package", "erjang", ".", "driver", ".", "efile", ";", "import", "java", ".", "util", ".", "concurrent", ".", "locks", ".", "ReentrantLock", ";", "import", "kilim", ".", "Lock", ";", "import", "erjang", ".", "EString", ";", "import", "erjang", ".", "NotImplemented", ";", "import", "erjang", ".", "driver", ".", "EDriver", ";", "import", "erjang", ".", "driver", ".", "EDriverControl", ";", "public", "class", "Driver", "implements", "EDriver", "{", "private", "Lock", "lock", ";", "@", "Override", "public", "String", "driverName", "(", ")", "{", "return", "\"efile\"", ";", "}", "@", "Override", "public", "void", "finish", "(", ")", "{", "}", "@", "Override", "public", "EDriverControl", "start", "(", "EString", "command", ")", "{", "return", "new", "EFile", "(", "command", ",", "this", ")", ";", "}", "@", "Override", "public", "boolean", "useDriverLevelLocking", "(", ")", "{", "return", "false", ";", "}", "@", "Override", "public", "ReentrantLock", "getLock", "(", ")", "{", "throw", "new", "NotImplemented", "(", ")", ";", "}", "}", "</s>" ]
7,762
[ "<s>", "package", "erjang", ".", "driver", ".", "efile", ";", "import", "java", ".", "io", ".", "File", ";", "import", "java", ".", "io", ".", "IOException", ";", "import", "java", ".", "io", ".", "InputStream", ";", "import", "java", ".", "net", ".", "URL", ";", "import", "java", ".", "nio", ".", "ByteBuffer", ";", "import", "java", ".", "nio", ".", "ByteOrder", ";", "import", "java", ".", "util", ".", "Calendar", ";", "import", "java", ".", "util", ".", "Enumeration", ";", "import", "java", ".", "util", ".", "GregorianCalendar", ";", "import", "java", ".", "util", ".", "HashSet", ";", "import", "java", ".", "util", ".", "Set", ";", "import", "java", ".", "util", ".", "zip", ".", "ZipEntry", ";", "import", "java", ".", "util", ".", "zip", ".", "ZipFile", ";", "import", "kilim", ".", "Pausable", ";", "import", "erjang", ".", "EBinary", ";", "import", "erjang", ".", "driver", ".", "IO", ";", "public", "class", "ClassPathResource", "{", "public", "static", "boolean", "isResource", "(", "String", "fileName", ")", "{", "return", "fileName", ".", "startsWith", "(", "EFile", ".", "RESOURCE_PREFIX", ")", ";", "}", "public", "static", "String", "getResourceName", "(", "String", "fileName", ")", "{", "if", "(", "!", "isResource", "(", "fileName", ")", ")", "return", "fileName", ";", "fileName", "=", "fileName", ".", "substring", "(", "EFile", ".", "RESOURCE_PREFIX", ".", "length", "(", ")", ")", ";", "if", "(", "fileName", ".", "startsWith", "(", "File", ".", "separator", ")", "||", "fileName", ".", "startsWith", "(", "\"/\"", ")", ")", "{", "fileName", "=", "fileName", ".", "substring", "(", "1", ")", ";", "}", "return", "fileName", ";", "}", "public", "static", "EBinary", "read_file", "(", "String", "name", ")", "{", "if", "(", "!", "name", ".", "startsWith", "(", "EFile", ".", "RESOURCE_PREFIX", ")", ")", "return", "null", ";", "String", "fileName", "=", "getResourceName", "(", "name", ")", ";", "InputStream", "resource", "=", "ClassPathResource", ".", "class", ".", "getClassLoader", "(", ")", ".", "getResourceAsStream", "(", "fileName", ")", ";", "if", "(", "resource", "==", "null", ")", "{", "resource", "=", "Thread", ".", "currentThread", "(", ")", ".", "getContextClassLoader", "(", ")", ".", "getResourceAsStream", "(", "fileName", ")", ";", "}", "if", "(", "resource", "==", "null", ")", "{", "return", "null", ";", "}", "else", "{", "EBinary", "bin", "=", "null", ";", "try", "{", "bin", "=", "IO", ".", "istream2binary", "(", "resource", ")", ";", "return", "bin", ";", "}", "catch", "(", "IOException", "e", ")", "{", "return", "null", ";", "}", "finally", "{", "try", "{", "resource", ".", "close", "(", ")", ";", "}", "catch", "(", "IOException", "e", ")", "{", "}", "}", "}", "}", "public", "static", "void", "listdir", "(", "EFile", "eFile", ",", "String", "path", ")", "throws", "Pausable", "{", "String", "[", "]", "dir", ";", "try", "{", "dir", "=", "list", "(", "path", ")", ";", "}", "catch", "(", "IOException", "e", ")", "{", "eFile", ".", "reply_posix_error", "(", "IO", ".", "exception_to_posix_code", "(", "e", ")", ")", ";", "return", ";", "}", "eFile", ".", "reply_list_directory", "(", "dir", ")", ";", "}", "static", "String", "[", "]", "list", "(", "String", "path", ")", "throws", "IOException", "{", "Enumeration", "<", "URL", ">", "out", "=", "ClassPathResource", ".", "class", ".", "getClassLoader", "(", ")", ".", "getResources", "(", "path", ")", ";", "Set", "<", "String", ">", "res", "=", "new", "HashSet", "<", "String", ">", "(", ")", ";", "while", "(", "out", ".", "hasMoreElements", "(", ")", ")", "{", "URL", "u", "=", "out", ".", "nextElement", "(", ")", ";", "list", "(", "res", ",", "u", ")", ";", "}", "return", "res", ".", "toArray", "(", "new", "String", "[", "res", ".", "size", "(", ")", "]", ")", ";", "}", "static", "void", "list", "(", "Set", "<", "String", ">", "res", ",", "URL", "url", ")", "throws", "IOException", "{", "if", "(", "url", ".", "getProtocol", "(", ")", ".", "equals", "(", "\"jar\"", ")", ")", "{", "listJarURL", "(", "res", ",", "url", ")", ";", "}", "if", "(", "url", ".", "getProtocol", "(", ")", ".", "equals", "(", "\"file\"", ")", ")", "{", "File", "file", "=", "new", "File", "(", "url", ".", "getFile", "(", ")", ")", ";", "for", "(", "String", "elm", ":", "file", ".", "list", "(", ")", ")", "{", "res", ".", "add", "(", "elm", ")", ";", "}", "}", "else", "{", "return", ";", "}", "}", "private", "static", "void", "listJarURL", "(", "Set", "<", "String", ">", "res", ",", "URL", "url", ")", "throws", "IOException", "{", "String", "path", "=", "url", ".", "getPath", "(", ")", ";", "int", "bang", "=", "path", ".", "indexOf", "(", "'!'", ")", ";", "String", "jar", "=", "path", ".", "substring", "(", "\"file:\"", ".", "length", "(", ")", ",", "bang", ")", ";", "String", "elm", "=", "path", ".", "substring", "(", "bang", "+", "2", ")", ";", "ZipFile", "z", "=", "new", "ZipFile", "(", "jar", ")", ";", "Enumeration", "<", "?", "extends", "ZipEntry", ">", "ents", "=", "z", ".", "entries", "(", ")", ";", "while", "(", "ents", ".", "hasMoreElements", "(", ")", ")", "{", "ZipEntry", "ent", "=", "ents", ".", "nextElement", "(", ")", ";", "if", "(", "ent", ".", "getName", "(", ")", ".", "startsWith", "(", "elm", ")", ")", "{", "add", "(", "res", ",", "elm", ",", "ent", ".", "getName", "(", ")", ")", ";", "}", "}", "z", ".", "close", "(", ")", ";", "}", "private", "static", "void", "add", "(", "Set", "<", "String", ">", "res", ",", "String", "elm", ",", "String", "name", ")", "{", "String", "rest", "=", "name", ".", "substring", "(", "elm", ".", "length", "(", ")", "+", "1", ")", ";", "int", "idx", ";", "if", "(", "(", "idx", "=", "rest", ".", "indexOf", "(", "'/'", ")", ")", "!=", "-", "1", ")", "{", "res", ".", "add", "(", "rest", ".", "substring", "(", "0", ",", "idx", ")", ")", ";", "}", "else", "if", "(", "rest", ".", "length", "(", ")", "!=", "0", ")", "{", "res", ".", "add", "(", "rest", ")", ";", "}", "}", "public", "static", "void", "fstat", "(", "EFile", "efile", ",", "String", "file_name", ")", "throws", "Pausable", "{", "try", "{", "ZipEntry", "ent", ";", "ent", "=", "get_entry", "(", "file_name", "+", "\"/\"", ")", ";", "if", "(", "ent", "==", "null", ")", "{", "ent", "=", "get_entry", "(", "file_name", ")", ";", "if", "(", "ent", "==", "null", ")", "{", "efile", ".", "reply_posix_error", "(", "Posix", ".", "ENOENT", ")", ";", "return", ";", "}", "}", "long", "file_size", "=", "ent", ".", "getSize", "(", ")", ";", "int", "file_type", "=", "ent", ".", "isDirectory", "(", ")", "?", "EFile", ".", "FT_DIRECTORY", ":", "EFile", ".", "FT_REGULAR", ";", "final", "int", "RESULT_SIZE", "=", "(", "1", "+", "(", "29", "*", "4", ")", ")", ";", "ByteBuffer", "res", "=", "ByteBuffer", ".", "allocate", "(", "RESULT_SIZE", ")", ";", "res", ".", "order", "(", "ByteOrder", ".", "BIG_ENDIAN", ")", ";", "res", ".", "put", "(", "EFile", ".", "FILE_RESP_INFO", ")", ";", "res", ".", "putLong", "(", "file_size", ")", ";", "res", ".", "putInt", "(", "file_type", ")", ";", "put_time", "(", "res", ",", "ent", ".", "getTime", "(", ")", ")", ";", "put_time", "(", "res", ",", "ent", ".", "getTime", "(", ")", ")", ";", "put_time", "(", "res", ",", "ent", ".", "getTime", "(", ")", ")", ";", "res", ".", "putInt", "(", "0000400", ")", ";", "res", ".", "putInt", "(", "1", ")", ";", "res", ".", "putInt", "(", "0", ")", ";", "res", ".", "putInt", "(", "0", ")", ";", "res", ".", "putInt", "(", "file_name", ".", "hashCode", "(", ")", ")", ";", "res", ".", "putInt", "(", "0", ")", ";", "res", ".", "putInt", "(", "0", ")", ";", "res", ".", "putInt", "(", "EFile", ".", "FA_READ", ")", ";", "efile", ".", "driver_output2", "(", "res", ",", "null", ")", ";", "}", "catch", "(", "IOException", "e", ")", "{", "efile", ".", "reply_posix_error", "(", "IO", ".", "exception_to_posix_code", "(", "e", ")", ")", ";", "}", "}", "private", "static", "void", "put_time", "(", "ByteBuffer", "res", ",", "long", "time", ")", "{", "Calendar", "c", "=", "GregorianCalendar", ".", "getInstance", "(", ")", ";", "c", ".", "setTimeInMillis", "(", "time", ")", ";", "int", "year", "=", "c", ".", "get", "(", "Calendar", ".", "YEAR", ")", ";", "res", ".", "putInt", "(", "year", ")", ";", "int", "month", "=", "c", ".", "get", "(", "Calendar", ".", "MONTH", ")", "-", "Calendar", ".", "JANUARY", "+", "1", ";", "res", ".", "putInt", "(", "month", ")", ";", "int", "day_of_month", "=", "c", ".", "get", "(", "Calendar", ".", "DAY_OF_MONTH", ")", ";", "res", ".", "putInt", "(", "day_of_month", ")", ";", "int", "hour_of_day", "=", "c", ".", "get", "(", "Calendar", ".", "HOUR_OF_DAY", ")", ";", "res", ".", "putInt", "(", "hour_of_day", ")", ";", "int", "minute_of_hour", "=", "c", ".", "get", "(", "Calendar", ".", "MINUTE", ")", ";", "res", ".", "putInt", "(", "minute_of_hour", ")", ";", "int", "seconds", "=", "c", ".", "get", "(", "Calendar", ".", "SECOND", ")", ";", "res", ".", "putInt", "(", "seconds", ")", ";", "}", "static", "ZipEntry", "get_entry", "(", "String", "path", ")", "throws", "IOException", "{", "String", "fileName", "=", "getResourceName", "(", "path", ")", ";", "Enumeration", "<", "URL", ">", "out", "=", "ClassPathResource", ".", "class", ".", "getClassLoader", "(", ")", ".", "getResources", "(", "fileName", ")", ";", "while", "(", "out", ".", "hasMoreElements", "(", ")", ")", "{", "URL", "u", "=", "out", ".", "nextElement", "(", ")", ";", "ZipEntry", "result", "=", "get_entry", "(", "u", ")", ";", "if", "(", "result", "!=", "null", ")", "return", "result", ";", "}", "return", "null", ";", "}", "static", "ZipEntry", "get_entry", "(", "URL", "url", ")", "throws", "IOException", "{", "if", "(", "url", ".", "getProtocol", "(", ")", ".", "equals", "(", "\"jar\"", ")", ")", "{", "return", "get_jar_entry", "(", "url", ")", ";", "}", "else", "{", "return", "null", ";", "}", "}", "private", "static", "ZipEntry", "get_jar_entry", "(", "URL", "url", ")", "throws", "IOException", "{", "String", "path", "=", "url", ".", "getPath", "(", ")", ";", "int", "bang", "=", "path", ".", "indexOf", "(", "'!'", ")", ";", "String", "jar", "=", "path", ".", "substring", "(", "\"file:\"", ".", "length", "(", ")", ",", "bang", ")", ";", "String", "elm", "=", "path", ".", "substring", "(", "bang", "+", "2", ")", ";", "ZipFile", "z", "=", "new", "ZipFile", "(", "jar", ")", ";", "try", "{", "ZipEntry", "ze", "=", "z", ".", "getEntry", "(", "elm", ")", ";", "if", "(", "ze", "!=", "null", ")", "return", "ze", ";", "}", "finally", "{", "z", ".", "close", "(", ")", ";", "}", "return", "null", ";", "}", "}", "</s>" ]
7,763
[ "<s>", "package", "erjang", ".", "driver", ".", "efile", ";", "import", "java", ".", "io", ".", "File", ";", "import", "java", ".", "io", ".", "FileDescriptor", ";", "import", "java", ".", "io", ".", "FileInputStream", ";", "import", "java", ".", "io", ".", "FileNotFoundException", ";", "import", "java", ".", "io", ".", "FileOutputStream", ";", "import", "java", ".", "io", ".", "FilenameFilter", ";", "import", "java", ".", "io", ".", "IOException", ";", "import", "java", ".", "io", ".", "RandomAccessFile", ";", "import", "java", ".", "lang", ".", "reflect", ".", "Field", ";", "import", "java", ".", "nio", ".", "ByteBuffer", ";", "import", "java", ".", "nio", ".", "ByteOrder", ";", "import", "java", ".", "nio", ".", "channels", ".", "FileChannel", ";", "import", "java", ".", "nio", ".", "channels", ".", "SelectableChannel", ";", "import", "java", ".", "util", ".", "Calendar", ";", "import", "java", ".", "util", ".", "GregorianCalendar", ";", "import", "java", ".", "util", ".", "LinkedList", ";", "import", "java", ".", "util", ".", "Queue", ";", "import", "java", ".", "util", ".", "concurrent", ".", "locks", ".", "Lock", ";", "import", "java", ".", "util", ".", "logging", ".", "Level", ";", "import", "java", ".", "util", ".", "logging", ".", "Logger", ";", "import", "kilim", ".", "Pausable", ";", "import", "erjang", ".", "EBinList", ";", "import", "erjang", ".", "EBinary", ";", "import", "erjang", ".", "EHandle", ";", "import", "erjang", ".", "ERT", ";", "import", "erjang", ".", "ERef", ";", "import", "erjang", ".", "EString", ";", "import", "erjang", ".", "NotImplemented", ";", "import", "erjang", ".", "driver", ".", "EAsync", ";", "import", "erjang", ".", "driver", ".", "EDriverInstance", ";", "import", "erjang", ".", "driver", ".", "IO", ";", "public", "class", "EFile", "extends", "EDriverInstance", "{", "static", "Logger", "log", "=", "Logger", ".", "getLogger", "(", "\"\"", ")", ";", "public", "static", "final", "String", "RESOURCE_PREFIX", "=", "\"/~resource/\"", ";", "private", "static", "Field", "FileDescriptor_FD", ";", "static", "{", "try", "{", "FileDescriptor_FD", "=", "FileDescriptor", ".", "class", ".", "getDeclaredField", "(", "\"fd\"", ")", ";", "FileDescriptor_FD", ".", "setAccessible", "(", "true", ")", ";", "}", "catch", "(", "Exception", "e", ")", "{", "throw", "new", "RuntimeException", "(", "e", ")", ";", "}", "}", "private", "int", "getFDnumber", "(", "FileDescriptor", "fd", ")", "throws", "IllegalAccessException", "{", "int", "res", "=", "FileDescriptor_FD", ".", "getInt", "(", "fd", ")", ";", "if", "(", "res", "==", "-", "1", ")", "res", "=", "255", ";", "return", "res", ";", "}", "private", "FileChannel", "fd", ";", "private", "int", "flags", ";", "private", "TimerState", "timer_state", ";", "private", "FileAsync", "invoke", ";", "private", "Queue", "<", "FileAsync", ">", "cq", ";", "private", "int", "level", ";", "private", "Lock", "q_mtx", ";", "private", "int", "write_buffered", ";", "private", "int", "write_bufsize", ";", "public", "int", "posix_errno", ";", "public", "boolean", "write_error", ";", "private", "long", "write_delay", ";", "private", "ByteBuffer", "read_binp", ";", "protected", "File", "name", ";", "private", "final", "class", "WriteAsync", "extends", "FileAsync", "{", "Lock", "q_mtx", ";", "int", "size", ",", "free_size", ",", "reply_size", ";", "private", "WriteAsync", "(", "boolean", "reply", ",", "int", "reply_size", ")", "{", "EFile", "efile", "=", "EFile", ".", "this", ";", "super", ".", "command", "=", "FILE_WRITE", ";", "super", ".", "fd", "=", "efile", ".", "fd", ";", "super", ".", "flags", "=", "efile", ".", "flags", ";", "super", ".", "level", "=", "1", ";", "this", ".", "q_mtx", "=", "efile", ".", "q_mtx", ";", "this", ".", "size", "=", "efile", ".", "write_buffered", ";", "super", ".", "reply", "=", "reply", ";", "this", ".", "free_size", "=", "0", ";", "this", ".", "reply_size", "=", "reply_size", ";", "}", "@", "Override", "public", "void", "async", "(", ")", "{", "int", "size", ";", "boolean", "segment", "=", "again", "&&", "this", ".", "size", ">=", "2", "*", "FILE_SEGMENT_WRITE", ";", "if", "(", "segment", ")", "{", "size", "=", "FILE_SEGMENT_WRITE", ";", "}", "else", "{", "size", "=", "this", ".", "size", ";", "}", "q_mtx", ".", "lock", "(", ")", ";", "ByteBuffer", "[", "]", "iov0", "=", "driver_peekq", "(", ")", ";", "if", "(", "iov0", "!=", "null", ")", "{", "ByteBuffer", "[", "]", "iov", "=", "iov0", ".", "clone", "(", ")", ";", "q_mtx", ".", "unlock", "(", ")", ";", "long", "p", "=", "0", ";", "int", "iovcnt", "=", "0", ";", "while", "(", "p", "<", "size", "&&", "iovcnt", "<", "iov", ".", "length", ")", "{", "p", "+=", "iov", "[", "iovcnt", "++", "]", ".", "remaining", "(", ")", ";", "}", "if", "(", "iov", ".", "length", ">", "0", ")", "{", "assert", "iov", "[", "iovcnt", "-", "1", "]", ".", "limit", "(", ")", ">", "p", "-", "size", ";", "if", "(", "(", "flags", "&", "EFILE_COMPRESSED", ")", "==", "EFILE_COMPRESSED", ")", "{", "for", "(", "int", "i", "=", "0", ";", "i", "<", "iovcnt", ";", "i", "++", ")", "{", "try", "{", "free_size", "+=", "IO", ".", "gzwrite", "(", "fd", ",", "iov", "[", "i", "]", ")", ";", "super", ".", "result_ok", "=", "true", ";", "}", "catch", "(", "IOException", "e", ")", "{", "posix_errno", "=", "IO", ".", "exception_to_posix_code", "(", "e", ")", ";", "super", ".", "result_ok", "=", "false", ";", "}", "}", "}", "else", "{", "try", "{", "long", "written_bytes", "=", "IO", ".", "writev", "(", "fd", ",", "iov", ")", ";", "if", "(", "log", ".", "isLoggable", "(", "Level", ".", "FINER", ")", ")", "{", "log", ".", "finer", "(", "\"\"", "+", "EFile", ".", "this", "+", "\"", "::", "wrote", "\"", "+", "written_bytes", ")", ";", "}", "free_size", "+=", "written_bytes", ";", "result_ok", "=", "true", ";", "}", "catch", "(", "IOException", "e", ")", "{", "posix_errno", "=", "IO", ".", "exception_to_posix_code", "(", "e", ")", ";", "super", ".", "result_ok", "=", "false", ";", "}", "}", "}", "else", "if", "(", "iov", ".", "length", "==", "0", ")", "{", "result_ok", "=", "true", ";", "}", "}", "else", "{", "q_mtx", ".", "unlock", "(", ")", ";", "posix_errno", "=", "Posix", ".", "EINVAL", ";", "result_ok", "=", "false", ";", "}", "if", "(", "!", "result_ok", ")", "{", "again", "=", "false", ";", "}", "else", "if", "(", "!", "segment", ")", "{", "again", "=", "false", ";", "}", "}", "@", "Override", "public", "void", "ready", "(", ")", "throws", "Pausable", "{", "if", "(", "reply", ")", "{", "if", "(", "!", "result_ok", ")", "{", "reply_posix_error", "(", "posix_errno", ")", ";", "}", "else", "{", "reply_Uint", "(", "reply_size", ")", ";", "}", "}", "else", "{", "if", "(", "!", "result_ok", ")", "{", "EFile", ".", "this", ".", "write_error", "=", "true", ";", "EFile", ".", "this", ".", "posix_errno", "=", "posix_errno", ";", "}", "}", "}", "@", "Override", "public", "void", "deq_free_size", "(", ")", "{", "driver_deq", "(", "free_size", ")", ";", "}", "}", "public", "enum", "TimerState", "{", "IDLE", ",", "AGAIN", ",", "WRITE", "}", "public", "static", "class", "Time", "{", "short", "year", ";", "short", "month", ";", "short", "day", ";", "short", "hour", ";", "short", "minute", ";", "short", "second", ";", "}", "public", "static", "class", "Info", "{", "int", "size_low", ";", "int", "size_high", ";", "int", "type", ";", "int", "access", ";", "int", "mode", ";", "int", "links", ";", "int", "major_device", ";", "int", "minor_device", ";", "int", "inode", ";", "int", "uid", ";", "int", "gid", ";", "Time", "accessTime", ";", "Time", "modifyTime", ";", "Time", "cTime", ";", "}", "public", "static", "final", "int", "EFILE_MODE_READ", "=", "1", ";", "public", "static", "final", "int", "EFILE_MODE_WRITE", "=", "2", ";", "public", "static", "final", "int", "EFILE_MODE_READ_WRITE", "=", "3", ";", "public", "static", "final", "int", "EFILE_MODE_APPEND", "=", "4", ";", "public", "static", "final", "int", "EFILE_COMPRESSED", "=", "8", ";", "public", "static", "final", "int", "EFILE_NO_TRUNCATE", "=", "16", ";", "public", "static", "final", "int", "EFILE_SEEK_SET", "=", "0", ";", "public", "static", "final", "int", "EFILE_SEEK_CUR", "=", "1", ";", "public", "static", "final", "int", "EFILE_SEEK_END", "=", "2", ";", "public", "static", "final", "int", "FT_DEVICE", "=", "1", ";", "public", "static", "final", "int", "FT_DIRECTORY", "=", "2", ";", "public", "static", "final", "int", "FT_REGULAR", "=", "3", ";", "public", "static", "final", "int", "FT_SYMLINK", "=", "4", ";", "public", "static", "final", "int", "FT_OTHER", "=", "5", ";", "public", "static", "final", "int", "FA_NONE", "=", "0", ";", "public", "static", "final", "int", "FA_WRITE", "=", "1", ";", "public", "static", "final", "int", "FA_READ", "=", "2", ";", "public", "static", "final", "int", "FA_EXECUTE", "=", "4", ";", "public", "static", "final", "int", "FILE_OPEN", "=", "1", ";", "public", "static", "final", "int", "FILE_READ", "=", "2", ";", "public", "static", "final", "int", "FILE_LSEEK", "=", "3", ";", "public", "static", "final", "int", "FILE_WRITE", "=", "4", ";", "public", "static", "final", "int", "FILE_FSTAT", "=", "5", ";", "public", "static", "final", "int", "FILE_PWD", "=", "6", ";", "public", "static", "final", "int", "FILE_READDIR", "=", "7", ";", "public", "static", "final", "int", "FILE_CHDIR", "=", "8", ";", "public", "static", "final", "int", "FILE_FSYNC", "=", "9", ";", "public", "static", "final", "int", "FILE_MKDIR", "=", "10", ";", "public", "static", "final", "int", "FILE_DELETE", "=", "11", ";", "public", "static", "final", "int", "FILE_RENAME", "=", "12", ";", "public", "static", "final", "int", "FILE_RMDIR", "=", "13", ";", "public", "static", "final", "int", "FILE_TRUNCATE", "=", "14", ";", "public", "static", "final", "int", "FILE_READ_FILE", "=", "15", ";", "public", "static", "final", "int", "FILE_WRITE_INFO", "=", "16", ";", "public", "static", "final", "int", "FILE_LSTAT", "=", "19", ";", "public", "static", "final", "int", "FILE_READLINK", "=", "20", ";", "public", "static", "final", "int", "FILE_LINK", "=", "21", ";", "public", "static", "final", "int", "FILE_SYMLINK", "=", "22", ";", "public", "static", "final", "int", "FILE_CLOSE", "=", "23", ";", "public", "static", "final", "int", "FILE_PWRITEV", "=", "24", ";", "public", "static", "final", "int", "FILE_PREADV", "=", "25", ";", "public", "static", "final", "int", "FILE_SETOPT", "=", "26", ";", "public", "static", "final", "int", "FILE_IPREAD", "=", "27", ";", "public", "static", "final", "int", "FILE_ALTNAME", "=", "28", ";", "public", "static", "final", "int", "FILE_READ_LINE", "=", "29", ";", "public", "static", "final", "int", "FILE_FDATASYNC", "=", "30", ";", "public", "static", "final", "int", "FILE_FADVISE", "=", "31", ";", "public", "static", "final", "byte", "FILE_RESP_OK", "=", "0", ";", "private", "static", "final", "byte", "[", "]", "FILE_RESP_OK_HEADER", "=", "new", "byte", "[", "]", "{", "FILE_RESP_OK", "}", ";", "public", "static", "final", "byte", "FILE_RESP_ERROR", "=", "1", ";", "public", "static", "final", "byte", "FILE_RESP_DATA", "=", "2", ";", "public", "static", "final", "byte", "FILE_RESP_NUMBER", "=", "3", ";", "public", "static", "final", "byte", "FILE_RESP_INFO", "=", "4", ";", "public", "static", "final", "byte", "FILE_RESP_NUMERR", "=", "5", ";", "public", "static", "final", "byte", "FILE_RESP_LDATA", "=", "6", ";", "public", "static", "final", "byte", "FILE_RESP_N2DATA", "=", "7", ";", "public", "static", "final", "byte", "FILE_RESP_EOF", "=", "8", ";", "public", "static", "final", "byte", "FILE_RESP_FNAME", "=", "9", ";", "public", "static", "final", "byte", "FILE_RESP_ALL_DATA", "=", "10", ";", "private", "static", "final", "byte", "[", "]", "FILE_RESP_ALL_DATA_HEADER", "=", "new", "byte", "[", "]", "{", "FILE_RESP_ALL_DATA", "}", ";", "public", "static", "final", "int", "FILE_OPT_DELAYED_WRITE", "=", "0", ";", "public", "static", "final", "int", "FILE_OPT_READ_AHEAD", "=", "1", ";", "public", "static", "final", "int", "IPREAD_S32BU_P32BU", "=", "0", ";", "public", "static", "final", "int", "POSIX_FADV_NORMAL", "=", "0", ";", "public", "static", "final", "int", "POSIX_FADV_RANDOM", "=", "1", ";", "public", "static", "final", "int", "POSIX_FADV_SEQUENTIAL", "=", "2", ";", "public", "static", "final", "int", "POSIX_FADV_WILLNEED", "=", "3", ";", "public", "static", "final", "int", "POSIX_FADV_DONTNEED", "=", "4", ";", "public", "static", "final", "int", "POSIX_FADV_NOREUSE", "=", "5", ";", "public", "static", "final", "int", "FILE_SEGMENT_READ", "=", "(", "256", "*", "1024", ")", ";", "public", "static", "final", "int", "FILE_SEGMENT_WRITE", "=", "(", "256", "*", "1024", ")", ";", "public", "static", "final", "int", "FILE_TYPE_DEVICE", "=", "0", ";", "public", "static", "final", "int", "FILE_TYPE_DIRECTORY", "=", "2", ";", "public", "static", "final", "int", "FILE_TYPE_REGULAR", "=", "3", ";", "public", "static", "final", "int", "FILE_TYPE_SYMLINK", "=", "4", ";", "public", "static", "final", "int", "FILE_ACCESS_NONE", "=", "0", ";", "public", "static", "final", "int", "FILE_ACCESS_WRITE", "=", "1", ";", "public", "static", "final", "int", "FILE_ACCESS_READ", "=", "2", ";", "public", "static", "final", "int", "FILE_ACCESS_READ_WRITE", "=", "3", ";", "private", "static", "final", "int", "THREAD_SHORT_CIRCUIT", ";", "static", "{", "String", "buf", "=", "System", ".", "getenv", "(", "\"\"", ")", ";", "if", "(", "buf", "==", "null", ")", "{", "THREAD_SHORT_CIRCUIT", "=", "0", ";", "}", "else", "{", "THREAD_SHORT_CIRCUIT", "=", "Integer", ".", "parseInt", "(", "buf", ")", ";", "}", "}", "public", "EFile", "(", "EString", "command", ",", "Driver", "driver", ")", "{", "super", "(", "driver", ")", ";", "this", ".", "fd", "=", "(", "FileChannel", ")", "null", ";", "this", ".", "flags", "=", "0", ";", "this", ".", "invoke", "=", "null", ";", "this", ".", "cq", "=", "new", "LinkedList", "<", "FileAsync", ">", "(", ")", ";", "this", ".", "timer_state", "=", "TimerState", ".", "IDLE", ";", "this", ".", "read_binp", "=", "(", "ByteBuffer", ")", "null", ";", "this", ".", "write_delay", "=", "0L", ";", "this", ".", "write_bufsize", "=", "0", ";", "this", ".", "q_mtx", "=", "driver_pdl_create", "(", ")", ";", "this", ".", "write_buffered", "=", "0", ";", "}", "public", "void", "reply_Uint", "(", "int", "value", ")", "throws", "Pausable", "{", "if", "(", "isUnicodeDriverInterface", "(", ")", ")", "{", "ByteBuffer", "response", "=", "ByteBuffer", ".", "allocate", "(", "9", ")", ";", "response", ".", "put", "(", "FILE_RESP_NUMBER", ")", ";", "response", ".", "putLong", "(", "value", ")", ";", "driver_output2", "(", "response", ",", "null", ")", ";", "}", "else", "{", "ByteBuffer", "response", "=", "ByteBuffer", ".", "allocate", "(", "4", ")", ";", "response", ".", "putInt", "(", "value", ")", ";", "driver_output2", "(", "response", ",", "null", ")", ";", "}", "}", "public", "void", "reply_Uint_error", "(", "int", "value", ",", "int", "posix_error", ")", "throws", "Pausable", "{", "ByteBuffer", "response", "=", "ByteBuffer", ".", "allocate", "(", "256", ")", ";", "String", "err", "=", "Posix", ".", "errno_id", "(", "posix_error", ")", ";", "response", ".", "putInt", "(", "value", ")", ";", "IO", ".", "putstr", "(", "response", ",", "err", ",", "false", ")", ";", "driver_output2", "(", "response", ",", "null", ")", ";", "}", "public", "void", "reply_posix_error", "(", "int", "posix_errno", ")", "throws", "Pausable", "{", "ByteBuffer", "response", "=", "ByteBuffer", ".", "allocate", "(", "256", ")", ";", "response", ".", "put", "(", "FILE_RESP_ERROR", ")", ";", "String", "err", "=", "Posix", ".", "errno_id", "(", "posix_errno", ")", ";", "IO", ".", "putstr", "(", "response", ",", "err", ",", "false", ")", ";", "driver_output2", "(", "response", ",", "null", ")", ";", "}", "@", "Override", "protected", "void", "flush", "(", ")", "throws", "Pausable", "{", "int", "r", "=", "flush_write", "(", "null", ")", ";", "assert", "(", "r", "==", "0", ")", ";", "cq_execute", "(", ")", ";", "}", "private", "abstract", "class", "SimpleFileAsync", "extends", "FileAsync", "{", "protected", "final", "File", "file", ";", "protected", "final", "String", "name", ";", "{", "level", "=", "2", ";", "reply", "=", "true", ";", "}", "public", "SimpleFileAsync", "(", "byte", "command", ",", "String", "path", ")", "{", "this", ".", "command", "=", "command", ";", "this", ".", "name", "=", "path", ";", "this", ".", "file", "=", "ERT", ".", "newFile", "(", "path", ")", ";", "}", "@", "Override", "public", "final", "void", "async", "(", ")", "{", "try", "{", "this", ".", "result_ok", "=", "false", ";", "run", "(", ")", ";", "}", "catch", "(", "OutOfMemoryError", "e", ")", "{", "posix_errno", "=", "Posix", ".", "ENOMEM", ";", "}", "catch", "(", "SecurityException", "e", ")", "{", "posix_errno", "=", "Posix", ".", "EPERM", ";", "}", "catch", "(", "Throwable", "e", ")", "{", "e", ".", "printStackTrace", "(", ")", ";", "posix_errno", "=", "Posix", ".", "EUNKNOWN", ";", "}", "}", "protected", "abstract", "void", "run", "(", ")", ";", "public", "void", "ready", "(", ")", "throws", "Pausable", "{", "reply", "(", "EFile", ".", "this", ")", ";", "}", "}", "@", "Override", "protected", "void", "outputv", "(", "EHandle", "caller", ",", "ByteBuffer", "[", "]", "ev", ")", "throws", "Pausable", "{", "if", "(", "ev", ".", "length", "==", "0", "||", "ev", "[", "0", "]", ".", "remaining", "(", ")", "==", "0", ")", "{", "reply_posix_error", "(", "Posix", ".", "EINVAL", ")", ";", "return", ";", "}", "byte", "command", "=", "ev", "[", "0", "]", ".", "get", "(", ")", ";", "switch", "(", "command", ")", "{", "case", "FILE_PREADV", ":", "{", "ByteBuffer", "evin", "=", "flatten", "(", "ev", ")", ";", "evin", ".", "getInt", "(", ")", ";", "final", "int", "n", "=", "evin", ".", "getInt", "(", ")", ";", "final", "long", "[", "]", "offsets", "=", "new", "long", "[", "n", "]", ";", "final", "ByteBuffer", "[", "]", "res_ev", "=", "new", "ByteBuffer", "[", "n", "+", "1", "]", ";", "for", "(", "int", "i", "=", "1", ";", "i", "<", "n", "+", "1", ";", "i", "++", ")", "{", "offsets", "[", "i", "-", "1", "]", "=", "evin", ".", "getLong", "(", ")", ";", "int", "len", "=", "(", "int", ")", "(", "evin", ".", "getLong", "(", ")", "&", "0x7fffffff", ")", ";", "res_ev", "[", "i", "]", "=", "ByteBuffer", ".", "allocate", "(", "len", ")", ";", "if", "(", "log", ".", "isLoggable", "(", "Level", ".", "FINER", ")", ")", "{", "log", ".", "finer", "(", "EFile", ".", "this", "+", "\"", "::", "pread", "\"", "+", "len", "+", "\"", "@", "\"", "+", "offsets", "[", "i", "-", "1", "]", ")", ";", "}", "}", "res_ev", "[", "0", "]", "=", "ByteBuffer", ".", "allocate", "(", "4", "+", "4", "+", "8", "*", "n", ")", ";", "res_ev", "[", "0", "]", ".", "putInt", "(", "0", ")", ";", "res_ev", "[", "0", "]", ".", "putInt", "(", "n", ")", ";", "if", "(", "n", "==", "0", ")", "{", "reply_ev", "(", "FILE_RESP_LDATA", ",", "offsets", ",", "res_ev", ")", ";", "}", "else", "{", "cq_enq", "(", "new", "FileAsync", "(", ")", "{", "int", "cnt", ";", "{", "this", ".", "level", "=", "1", ";", "this", ".", "fd", "=", "EFile", ".", "this", ".", "fd", ";", "this", ".", "cnt", "=", "0", ";", "this", ".", "result_ok", "=", "true", ";", "}", "@", "Override", "public", "void", "async", "(", ")", "{", "for", "(", "int", "i", "=", "cnt", ";", "i", "<", "n", ";", "i", "++", ")", "{", "ByteBuffer", "res", "=", "res_ev", "[", "i", "+", "1", "]", ";", "long", "pos", "=", "offsets", "[", "i", "]", "+", "res", ".", "position", "(", ")", ";", "int", "rem", "=", "res", ".", "remaining", "(", ")", ";", "if", "(", "rem", ">", "0", ")", "{", "int", "bytes_read", ";", "try", "{", "fd", ".", "position", "(", "pos", ")", ";", "bytes_read", "=", "fd", ".", "read", "(", "res", ")", ";", "if", "(", "log", ".", "isLoggable", "(", "Level", ".", "FINER", ")", ")", "{", "log", ".", "finer", "(", "EFile", ".", "this", "+", "\"\"", "+", "bytes_read", "+", "\"@\"", "+", "pos", "+", "\"", "into", "res[\"", "+", "i", "+", "\"];", "missing=\"", "+", "res", ".", "remaining", "(", ")", ")", ";", "}", "}", "catch", "(", "IOException", "e", ")", "{", "result_ok", "=", "false", ";", "this", ".", "posix_errno", "=", "IO", ".", "exception_to_posix_code", "(", "e", ")", ";", "this", ".", "again", "=", "false", ";", "return", ";", "}", "if", "(", "bytes_read", ">=", "0", "&&", "res", ".", "hasRemaining", "(", ")", ")", "{", "this", ".", "again", "=", "true", ";", "return", ";", "}", "res_ev", "[", "0", "]", ".", "putLong", "(", "res", ".", "position", "(", ")", ")", ";", "cnt", "+=", "1", ";", "}", "}", "this", ".", "again", "=", "false", ";", "}", "@", "Override", "public", "void", "ready", "(", ")", "throws", "Pausable", "{", "if", "(", "!", "result_ok", ")", "{", "reply_posix_error", "(", "posix_errno", ")", ";", "}", "else", "{", "reply_ev", "(", "FILE_RESP_LDATA", ",", "offsets", ",", "res_ev", ")", ";", "}", "}", "}", ")", ";", "}", "}", "break", ";", "case", "FILE_CLOSE", ":", "{", "if", "(", "ev", ".", "length", ">", "1", "&&", "ev", "[", "0", "]", ".", "hasRemaining", "(", ")", ")", "{", "reply_posix_error", "(", "Posix", ".", "EINVAL", ")", ";", "return", ";", "}", "ByteBuffer", "last", "=", "ev", "[", "ev", ".", "length", "-", "1", "]", ";", "if", "(", "last", ".", "hasRemaining", "(", ")", ")", "{", "reply_posix_error", "(", "Posix", ".", "EINVAL", ")", ";", "return", ";", "}", "if", "(", "log", ".", "isLoggable", "(", "Level", ".", "FINE", ")", ")", "log", ".", "fine", "(", "\"\"", "+", "this", "+", "\"", "::", "close\"", ")", ";", "FileAsync", "d", "=", "new", "FileAsync", "(", ")", "{", "{", "this", ".", "fd", "=", "EFile", ".", "this", ".", "fd", ";", "}", "public", "void", "async", "(", ")", "{", "try", "{", "fd", ".", "close", "(", ")", ";", "result_ok", "=", "true", ";", "}", "catch", "(", "IOException", "e", ")", "{", "result_ok", "=", "false", ";", "posix_errno", "=", "IO", ".", "exception_to_posix_code", "(", "e", ")", ";", "}", "}", "@", "Override", "public", "void", "ready", "(", ")", "throws", "Pausable", "{", "if", "(", "result_ok", ")", "{", "reply_ok", "(", ")", ";", "}", "else", "{", "reply_posix_error", "(", "posix_errno", ")", ";", "}", "}", "}", ";", "cq_enq", "(", "d", ")", ";", "break", ";", "}", "case", "FILE_READ", ":", "{", "int", "[", "]", "errp", "=", "new", "int", "[", "1", "]", ";", "if", "(", "flush_write_check_error", "(", "errp", ")", "<", "0", ")", "{", "reply_posix_error", "(", "errp", "[", "0", "]", ")", ";", "return", ";", "}", "if", "(", "ev", ".", "length", ">", "1", "&&", "ev", "[", "0", "]", ".", "hasRemaining", "(", ")", ")", "{", "reply_posix_error", "(", "Posix", ".", "EINVAL", ")", ";", "return", ";", "}", "ByteBuffer", "last", "=", "ev", "[", "ev", ".", "length", "-", "1", "]", ";", "if", "(", "last", ".", "remaining", "(", ")", "!=", "8", ")", "{", "reply_posix_error", "(", "Posix", ".", "EINVAL", ")", ";", "return", ";", "}", "final", "long", "size", "=", "last", ".", "getLong", "(", ")", ";", "if", "(", "size", ">", "Integer", ".", "MAX_VALUE", "||", "size", "<", "0", ")", "{", "reply_posix_error", "(", "Posix", ".", "ENOMEM", ")", ";", "return", ";", "}", "FileAsync", "d", "=", "new", "FileAsync", "(", ")", "{", "private", "ByteBuffer", "binp", "=", "null", ";", "{", "super", ".", "level", "=", "2", ";", "super", ".", "again", "=", "true", ";", "this", ".", "fd", "=", "EFile", ".", "this", ".", "fd", ";", "}", "@", "Override", "public", "void", "async", "(", ")", "{", "if", "(", "binp", "==", "null", ")", "{", "try", "{", "binp", "=", "ByteBuffer", ".", "allocate", "(", "(", "int", ")", "size", ")", ";", "}", "catch", "(", "OutOfMemoryError", "e", ")", "{", "result_ok", "=", "false", ";", "posix_errno", "=", "Posix", ".", "ENOMEM", ";", "return", ";", "}", "}", "if", "(", "binp", "!=", "null", "&&", "binp", ".", "hasRemaining", "(", ")", ")", "{", "try", "{", "int", "want", "=", "binp", ".", "remaining", "(", ")", ";", "int", "bytes", "=", "fd", ".", "read", "(", "binp", ")", ";", "if", "(", "log", ".", "isLoggable", "(", "Level", ".", "FINER", ")", ")", "{", "log", ".", "finer", "(", "EFile", ".", "this", "+", "\"::", "did", "read", "\"", "+", "bytes", "+", "\"", "bytes", "of", "\"", "+", "want", ")", ";", "}", "if", "(", "bytes", "==", "-", "1", ")", "{", "result_ok", "=", "true", ";", "again", "=", "false", ";", "return", ";", "}", "if", "(", "binp", ".", "hasRemaining", "(", ")", ")", "{", "again", "=", "true", ";", "return", ";", "}", "else", "{", "result_ok", "=", "true", ";", "}", "}", "catch", "(", "IOException", "e", ")", "{", "result_ok", "=", "false", ";", "posix_errno", "=", "IO", ".", "exception_to_posix_code", "(", "e", ")", ";", "}", "}", "again", "=", "false", ";", "}", "@", "Override", "public", "void", "ready", "(", ")", "throws", "Pausable", "{", "if", "(", "!", "result_ok", ")", "{", "reply_posix_error", "(", "posix_errno", ")", ";", "return", ";", "}", "reply_buf", "(", "binp", ")", ";", "binp", ".", "flip", "(", ")", ";", "}", "}", ";", "cq_enq", "(", "d", ")", ";", "break", ";", "}", "case", "FILE_READ_FILE", ":", "{", "if", "(", "ev", ".", "length", ">", "1", "&&", "ev", "[", "0", "]", ".", "hasRemaining", "(", ")", ")", "{", "reply_posix_error", "(", "Posix", ".", "EINVAL", ")", ";", "return", ";", "}", "ByteBuffer", "last", "=", "ev", "[", "ev", ".", "length", "-", "1", "]", ";", "final", "String", "name", "=", "IO", ".", "getstr", "(", "last", ",", "false", ")", ";", "if", "(", "name", ".", "length", "(", ")", "==", "0", ")", "{", "reply_posix_error", "(", "Posix", ".", "ENOENT", ")", ";", "return", ";", "}", "if", "(", "ClassPathResource", ".", "isResource", "(", "name", ")", ")", "{", "EBinary", "data", "=", "ClassPathResource", ".", "read_file", "(", "name", ")", ";", "if", "(", "data", "==", "null", ")", "{", "reply_posix_error", "(", "Posix", ".", "ENOENT", ")", ";", "}", "else", "{", "task", ".", "output_from_driver", "(", "new", "EBinList", "(", "FILE_RESP_OK_HEADER", ",", "data", ")", ")", ";", "}", "return", ";", "}", "FileAsync", "d", "=", "new", "FileAsync", "(", ")", "{", "private", "ByteBuffer", "binp", "=", "null", ";", "private", "long", "size", "=", "0", ";", "{", "super", ".", "level", "=", "2", ";", "super", ".", "again", "=", "true", ";", "}", "@", "Override", "public", "void", "async", "(", ")", "{", "if", "(", "binp", "==", "null", ")", "{", "File", "file", "=", "ERT", ".", "newFile", "(", "name", ")", ";", "try", "{", "this", ".", "fd", "=", "new", "FileInputStream", "(", "file", ")", ".", "getChannel", "(", ")", ";", "}", "catch", "(", "FileNotFoundException", "e", ")", "{", "this", ".", "again", "=", "false", ";", "result_ok", "=", "false", ";", "posix_errno", "=", "fileNotFound_to_posixErrno", "(", "file", ",", "EFILE_MODE_READ", ")", ";", "this", ".", "again", "=", "false", ";", "return", ";", "}", "this", ".", "size", "=", "file", ".", "length", "(", ")", ";", "if", "(", "size", ">", "Integer", ".", "MAX_VALUE", "||", "size", "<", "0", ")", "{", "result_ok", "=", "false", ";", "posix_errno", "=", "Posix", ".", "ENOMEM", ";", "}", "else", "{", "try", "{", "binp", "=", "ByteBuffer", ".", "allocate", "(", "(", "int", ")", "size", ")", ";", "}", "catch", "(", "OutOfMemoryError", "e", ")", "{", "result_ok", "=", "false", ";", "posix_errno", "=", "Posix", ".", "ENOMEM", ";", "}", "}", "}", "if", "(", "binp", "!=", "null", "&&", "binp", ".", "hasRemaining", "(", ")", ")", "{", "try", "{", "int", "bytes", "=", "fd", ".", "read", "(", "binp", ")", ";", "if", "(", "bytes", "==", "-", "1", "&&", "binp", ".", "hasRemaining", "(", ")", ")", "{", "result_ok", "=", "false", ";", "posix_errno", "=", "Posix", ".", "EIO", ";", "}", "if", "(", "binp", ".", "hasRemaining", "(", ")", ")", "{", "again", "=", "true", ";", "return", ";", "}", "else", "{", "result_ok", "=", "true", ";", "}", "}", "catch", "(", "IOException", "e", ")", "{", "result_ok", "=", "false", ";", "posix_errno", "=", "IO", ".", "exception_to_posix_code", "(", "e", ")", ";", "}", "}", "try", "{", "fd", ".", "close", "(", ")", ";", "}", "catch", "(", "IOException", "e", ")", "{", "result_ok", "=", "false", ";", "posix_errno", "=", "IO", ".", "exception_to_posix_code", "(", "e", ")", ";", "}", "again", "=", "false", ";", "}", "@", "Override", "public", "void", "ready", "(", ")", "throws", "Pausable", "{", "if", "(", "!", "result_ok", ")", "{", "reply_posix_error", "(", "posix_errno", ")", ";", "return", ";", "}", "binp", ".", "flip", "(", ")", ";", "driver_output_binary", "(", "isUnicodeDriverInterface", "(", ")", "?", "FILE_RESP_ALL_DATA_HEADER", ":", "FILE_RESP_OK_HEADER", ",", "binp", ")", ";", "}", "}", ";", "cq_enq", "(", "d", ")", ";", "break", ";", "}", "case", "FILE_PWRITEV", ":", "{", "int", "[", "]", "errp", "=", "new", "int", "[", "1", "]", ";", "if", "(", "lseek_flush_read", "(", "errp", ")", "<", "0", ")", "{", "reply_posix_error", "(", "errp", "[", "0", "]", ")", ";", "return", ";", "}", "if", "(", "flush_write_check_error", "(", "errp", ")", "<", "0", ")", "{", "reply_posix_error", "(", "errp", "[", "0", "]", ")", ";", "return", ";", "}", "final", "int", "n", "=", "ev", "[", "0", "]", ".", "getInt", "(", ")", ";", "if", "(", "n", "==", "0", ")", "{", "if", "(", "ev", ".", "length", ">", "1", "||", "ev", "[", "0", "]", ".", "hasRemaining", "(", ")", ")", "{", "reply_posix_error", "(", "Posix", ".", "EINVAL", ")", ";", "}", "else", "{", "reply_Uint", "(", "0", ")", ";", "}", "return", ";", "}", "if", "(", "ev", "[", "0", "]", ".", "remaining", "(", ")", "!=", "(", "8", "*", "2", "*", "n", ")", ")", "{", "reply_posix_error", "(", "Posix", ".", "EINVAL", ")", ";", "return", ";", "}", "final", "long", "[", "]", "offsets", "=", "new", "long", "[", "n", "]", ";", "final", "long", "[", "]", "sizes", "=", "new", "long", "[", "n", "]", ";", "long", "total", "=", "0", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "n", ";", "i", "++", ")", "{", "offsets", "[", "i", "]", "=", "ev", "[", "0", "]", ".", "getLong", "(", ")", ";", "sizes", "[", "i", "]", "=", "ev", "[", "0", "]", ".", "getLong", "(", ")", ";", "total", "+=", "sizes", "[", "i", "]", ";", "}", "if", "(", "total", "==", "0", ")", "{", "reply_Uint", "(", "0", ")", ";", "return", ";", "}", "q_mtx", ".", "lock", "(", ")", ";", "try", "{", "driver_enqv", "(", "ev", ")", ";", "}", "finally", "{", "q_mtx", ".", "unlock", "(", ")", ";", "}", "FileAsync", "d", "=", "new", "FileAsync", "(", ")", "{", "int", "cnt", "=", "0", ";", "{", "this", ".", "level", "=", "1", ";", "this", ".", "fd", "=", "EFile", ".", "this", ".", "fd", ";", "}", "@", "Override", "public", "void", "async", "(", ")", "{", "q_mtx", ".", "lock", "(", ")", ";", "ByteBuffer", "[", "]", "iov0", "=", "driver_peekq", "(", ")", ";", "if", "(", "iov0", "!=", "null", ")", "{", "ByteBuffer", "[", "]", "iov", "=", "iov0", ".", "clone", "(", ")", ";", "q_mtx", ".", "unlock", "(", ")", ";", "int", "ip", "=", "0", ";", "while", "(", "cnt", "<", "offsets", ".", "length", "&&", "ip", "<", "iov", ".", "length", ")", "{", "if", "(", "sizes", "[", "cnt", "]", "==", "0", ")", "{", "cnt", "+=", "1", ";", "continue", ";", "}", "if", "(", "!", "iov", "[", "ip", "]", ".", "hasRemaining", "(", ")", ")", "{", "ip", "++", ";", "continue", ";", "}", "ByteBuffer", "o", "=", "iov", "[", "ip", "]", ";", "if", "(", "o", ".", "remaining", "(", ")", ">", "sizes", "[", "cnt", "]", ")", "{", "o", "=", "o", ".", "slice", "(", ")", ";", "o", ".", "limit", "(", "(", "int", ")", "sizes", "[", "cnt", "]", ")", ";", "}", "int", "bytes", ";", "try", "{", "fd", ".", "position", "(", "offsets", "[", "cnt", "]", ")", ";", "bytes", "=", "fd", ".", "write", "(", "o", ")", ";", "if", "(", "log", ".", "isLoggable", "(", "Level", ".", "FINE", ")", ")", "{", "log", ".", "fine", "(", "\"\"", "+", "EFile", ".", "this", "+", "\"", "::", "wrote", "\"", "+", "bytes", ")", ";", "}", "}", "catch", "(", "IOException", "e", ")", "{", "EFile", ".", "this", ".", "posix_errno", "=", "IO", ".", "exception_to_posix_code", "(", "e", ")", ";", "this", ".", "result_ok", "=", "false", ";", "return", ";", "}", "offsets", "[", "cnt", "]", "+=", "bytes", ";", "sizes", "[", "cnt", "]", "-=", "bytes", ";", "if", "(", "o", ".", "hasRemaining", "(", ")", ")", "{", "this", ".", "again", "=", "true", ";", "return", ";", "}", "if", "(", "sizes", "[", "cnt", "]", "==", "0", ")", "{", "cnt", "+=", "1", ";", "}", "}", "if", "(", "cnt", "!=", "n", ")", "{", "this", ".", "result_ok", "=", "false", ";", "EFile", ".", "this", ".", "posix_errno", "=", "Posix", ".", "EINVAL", ";", "this", ".", "again", "=", "false", ";", "}", "else", "{", "this", ".", "again", "=", "false", ";", "this", ".", "result_ok", "=", "true", ";", "}", "}", "}", "@", "Override", "public", "void", "ready", "(", ")", "throws", "Pausable", "{", "if", "(", "!", "result_ok", ")", "{", "reply_Uint_error", "(", "cnt", ",", "EFile", ".", "this", ".", "posix_errno", ")", ";", "}", "else", "{", "reply_Uint", "(", "n", ")", ";", "}", "}", "}", ";", "cq_enq", "(", "d", ")", ";", "break", ";", "}", "case", "FILE_WRITE", ":", "{", "int", "[", "]", "errp", ";", "int", "reply_size", "=", "0", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "ev", ".", "length", ";", "i", "++", ")", "{", "reply_size", "+=", "ev", "[", "i", "]", ".", "remaining", "(", ")", ";", "if", "(", "log", ".", "isLoggable", "(", "Level", ".", "FINER", ")", ")", "log", ".", "finer", "(", "\"\"", "+", "this", "+", "\"", "::", "write", "\"", "+", "ev", "[", "i", "]", ".", "remaining", "(", ")", ")", ";", "}", "q_mtx", ".", "lock", "(", ")", ";", "driver_enqv", "(", "ev", ")", ";", "write_buffered", "+=", "reply_size", ";", "if", "(", "write_buffered", "<", "write_bufsize", ")", "{", "q_mtx", ".", "unlock", "(", ")", ";", "reply_Uint", "(", "reply_size", ")", ";", "if", "(", "timer_state", "==", "TimerState", ".", "IDLE", ")", "{", "timer_state", "=", "TimerState", ".", "WRITE", ";", "driver_set_timer", "(", "write_delay", ")", ";", "}", "}", "else", "if", "(", "async_write", "(", "errp", "=", "new", "int", "[", "1", "]", ",", "true", ",", "reply_size", ")", "!=", "0", ")", "{", "reply_posix_error", "(", "errp", "[", "0", "]", ")", ";", "q_mtx", ".", "unlock", "(", ")", ";", "}", "else", "{", "q_mtx", ".", "unlock", "(", ")", ";", "}", "break", ";", "}", "default", ":", "ev", "[", "0", "]", ".", "position", "(", "ev", "[", "0", "]", ".", "position", "(", ")", "-", "1", ")", ";", "output", "(", "caller", ",", "flatten", "(", "ev", ")", ")", ";", "}", "cq_execute", "(", ")", ";", "}", "private", "int", "flush_write_check_error", "(", "int", "[", "]", "errp", ")", "{", "int", "r", ";", "if", "(", "(", "r", "=", "flush_write", "(", "errp", ")", ")", "!=", "0", ")", "{", "check_write_error", "(", "null", ")", ";", "return", "r", ";", "}", "else", "{", "return", "check_write_error", "(", "errp", ")", ";", "}", "}", "private", "int", "check_write_error", "(", "int", "[", "]", "errp", ")", "{", "if", "(", "write_error", ")", "{", "if", "(", "errp", "!=", "null", ")", "{", "errp", "[", "0", "]", "=", "this", ".", "posix_errno", ";", "}", "return", "-", "1", ";", "}", "return", "0", ";", "}", "void", "flush_read", "(", ")", "{", "this", ".", "read_binp", "=", "null", ";", "}", "private", "int", "lseek_flush_read", "(", "int", "[", "]", "errp", ")", "{", "int", "r", "=", "0", ";", "int", "read_size", "=", "(", "read_binp", "==", "null", "?", "0", ":", "read_binp", ".", "remaining", "(", ")", ")", ";", "flush_read", "(", ")", ";", "if", "(", "read_size", "!=", "0", ")", "{", "if", "(", "(", "r", "=", "async_lseek", "(", "errp", ",", "false", ",", "-", "read_size", ",", "EFILE_SEEK_CUR", ")", ")", "<", "0", ")", "{", "return", "r", ";", "}", "}", "return", "r", ";", "}", "private", "int", "async_lseek", "(", "int", "[", "]", "errp", ",", "final", "boolean", "do_reply", ",", "final", "long", "off", ",", "final", "int", "whence", ")", "{", "try", "{", "FileAsync", "d", "=", "new", "FileAsync", "(", ")", "{", "{", "this", ".", "reply", "=", "do_reply", ";", "this", ".", "level", "=", "1", ";", "this", ".", "fd", "=", "EFile", ".", "this", ".", "fd", ";", "}", "long", "out_pos", ";", "@", "Override", "public", "void", "async", "(", ")", "{", "if", "(", "(", "flags", "&", "EFILE_COMPRESSED", ")", "!=", "0", ")", "{", "this", ".", "result_ok", "=", "false", ";", "this", ".", "posix_errno", "=", "Posix", ".", "EINVAL", ";", "}", "try", "{", "switch", "(", "whence", ")", "{", "case", "EFILE_SEEK_SET", ":", "out_pos", "=", "off", ";", "break", ";", "case", "EFILE_SEEK_CUR", ":", "long", "cur", "=", "fd", ".", "position", "(", ")", ";", "out_pos", "=", "cur", "+", "off", ";", "break", ";", "case", "EFILE_SEEK_END", ":", "cur", "=", "fd", ".", "size", "(", ")", ";", "out_pos", "=", "cur", "-", "off", ";", "break", ";", "default", ":", "this", ".", "result_ok", "=", "false", ";", "this", ".", "posix_errno", "=", "Posix", ".", "EINVAL", ";", "return", ";", "}", "fd", ".", "position", "(", "out_pos", ")", ";", "if", "(", "log", ".", "isLoggable", "(", "Level", ".", "FINE", ")", ")", "{", "log", ".", "fine", "(", "\"\"", "+", "EFile", ".", "this", "+", "\"", "::", "seek", "\"", "+", "out_pos", ")", ";", "}", "}", "catch", "(", "IOException", "e", ")", "{", "this", ".", "result_ok", "=", "false", ";", "this", ".", "posix_errno", "=", "IO", ".", "exception_to_posix_code", "(", "e", ")", ";", "}", "this", ".", "result_ok", "=", "true", ";", "}", "@", "Override", "public", "void", "ready", "(", ")", "throws", "Pausable", "{", "if", "(", "reply", ")", "{", "if", "(", "result_ok", ")", "{", "EFile", ".", "this", ".", "fd", "=", "fd", ";", "ByteBuffer", "response", "=", "ByteBuffer", ".", "allocate", "(", "9", ")", ";", "response", ".", "put", "(", "FILE_RESP_NUMBER", ")", ";", "response", ".", "putLong", "(", "out_pos", ")", ";", "driver_output2", "(", "response", ",", "null", ")", ";", "}", "else", "{", "reply_posix_error", "(", "posix_errno", ")", ";", "}", "}", "}", "}", ";", "cq_enq", "(", "d", ")", ";", "}", "catch", "(", "OutOfMemoryError", "e", ")", "{", "if", "(", "errp", "!=", "null", ")", "{", "errp", "[", "0", "]", "=", "Posix", ".", "ENOMEM", ";", "}", "return", "-", "1", ";", "}", "return", "0", ";", "}", "private", "void", "reply_ev", "(", "byte", "response", ",", "long", "[", "]", "offsets", ",", "ByteBuffer", "[", "]", "res_ev", ")", "throws", "Pausable", "{", "ByteBuffer", "tmp", "=", "ByteBuffer", ".", "allocate", "(", "1", ")", ";", "tmp", ".", "put", "(", "response", ")", ";", "driver_outputv", "(", "tmp", ",", "res_ev", ")", ";", "}", "static", "FilenameFilter", "READDIR_FILTER", "=", "new", "FilenameFilter", "(", ")", "{", "@", "Override", "public", "boolean", "accept", "(", "File", "dir", ",", "String", "name", ")", "{", "return", "!", "\".\"", ".", "equals", "(", "name", ")", "&&", "!", "\"..\"", ".", "equals", "(", "name", ")", ";", "}", "}", ";", "@", "Override", "protected", "void", "output", "(", "EHandle", "caller", ",", "ByteBuffer", "buf", ")", "throws", "Pausable", "{", "FileAsync", "d", ";", "final", "byte", "cmd", "=", "buf", ".", "get", "(", ")", ";", "switch", "(", "cmd", ")", "{", "case", "FILE_TRUNCATE", ":", "{", "d", "=", "new", "FileAsync", "(", ")", "{", "{", "level", "=", "2", ";", "fd", "=", "EFile", ".", "this", ".", "fd", ";", "command", "=", "FILE_TRUNCATE", ";", "}", "@", "Override", "public", "void", "async", "(", ")", "{", "again", "=", "false", ";", "try", "{", "long", "pos", "=", "fd", ".", "position", "(", ")", ";", "fd", ".", "truncate", "(", "pos", ")", ";", "result_ok", "=", "true", ";", "}", "catch", "(", "IOException", "e", ")", "{", "result_ok", "=", "false", ";", "posix_errno", "=", "IO", ".", "exception_to_posix_code", "(", "e", ")", ";", "}", "}", "@", "Override", "public", "void", "ready", "(", ")", "throws", "Pausable", "{", "reply", "(", "EFile", ".", "this", ")", ";", "}", "}", ";", "}", "break", ";", "case", "FILE_FDATASYNC", ":", "case", "FILE_FSYNC", ":", "{", "d", "=", "new", "FileAsync", "(", ")", "{", "{", "level", "=", "2", ";", "fd", "=", "EFile", ".", "this", ".", "fd", ";", "command", "=", "cmd", ";", "}", "@", "Override", "public", "void", "async", "(", ")", "{", "again", "=", "false", ";", "try", "{", "fd", ".", "force", "(", "true", ")", ";", "result_ok", "=", "true", ";", "}", "catch", "(", "IOException", "e", ")", "{", "result_ok", "=", "false", ";", "posix_errno", "=", "IO", ".", "exception_to_posix_code", "(", "e", ")", ";", "}", "}", "@", "Override", "public", "void", "ready", "(", ")", "throws", "Pausable", "{", "reply", "(", "EFile", ".", "this", ")", ";", "}", "}", ";", "}", "break", ";", "case", "FILE_MKDIR", ":", "{", "d", "=", "new", "SimpleFileAsync", "(", "cmd", ",", "IO", ".", "strcpy", "(", "buf", ")", ")", "{", "public", "void", "run", "(", ")", "{", "result_ok", "=", "file", ".", "mkdir", "(", ")", ";", "if", "(", "!", "result_ok", ")", "{", "if", "(", "name", ".", "length", "(", ")", "==", "0", ")", "{", "posix_errno", "=", "Posix", ".", "ENOENT", ";", "}", "else", "if", "(", "file", ".", "exists", "(", ")", ")", "{", "posix_errno", "=", "Posix", ".", "EEXIST", ";", "}", "else", "{", "posix_errno", "=", "Posix", ".", "EUNKNOWN", ";", "}", "}", "}", "}", ";", "break", ";", "}", "case", "FILE_RMDIR", ":", "{", "d", "=", "new", "SimpleFileAsync", "(", "cmd", ",", "IO", ".", "strcpy", "(", "buf", ")", ")", "{", "public", "void", "run", "(", ")", "{", "result_ok", "=", "file", ".", "isDirectory", "(", ")", "&&", "file", ".", "delete", "(", ")", ";", "if", "(", "!", "result_ok", ")", "{", "if", "(", "!", "file", ".", "exists", "(", ")", ")", "{", "posix_errno", "=", "Posix", ".", "ENOENT", ";", "}", "else", "if", "(", "Posix", ".", "isCWD", "(", "name", ",", "file", ")", ")", "{", "posix_errno", "=", "Posix", ".", "EINVAL", ";", "}", "else", "if", "(", "file", ".", "exists", "(", ")", ")", "{", "posix_errno", "=", "Posix", ".", "EEXIST", ";", "}", "else", "{", "posix_errno", "=", "Posix", ".", "EUNKNOWN", ";", "}", "}", "}", "}", ";", "break", ";", "}", "case", "FILE_CHDIR", ":", "{", "d", "=", "new", "SimpleFileAsync", "(", "cmd", ",", "IO", ".", "strcpy", "(", "buf", ")", ")", "{", "public", "void", "run", "(", ")", "{", "result_ok", "=", "file", ".", "isDirectory", "(", ")", ";", "if", "(", "!", "result_ok", ")", "{", "if", "(", "!", "file", ".", "exists", "(", ")", ")", "{", "posix_errno", "=", "Posix", ".", "ENOENT", ";", "}", "else", "if", "(", "!", "file", ".", "isDirectory", "(", ")", ")", "{", "posix_errno", "=", "Posix", ".", "EEXIST", ";", "}", "else", "{", "posix_errno", "=", "Posix", ".", "EUNKNOWN", ";", "}", "}", "else", "{", "try", "{", "System", ".", "setProperty", "(", "\"user.dir\"", ",", "file", ".", "getCanonicalPath", "(", ")", ")", ";", "}", "catch", "(", "IOException", "e", ")", "{", "posix_errno", "=", "Posix", ".", "EUNKNOWN", ";", "}", "}", "}", "}", ";", "break", ";", "}", "case", "FILE_DELETE", ":", "{", "d", "=", "new", "SimpleFileAsync", "(", "cmd", ",", "IO", ".", "strcpy", "(", "buf", ")", ")", "{", "public", "void", "run", "(", ")", "{", "result_ok", "=", "file", ".", "isFile", "(", ")", "&&", "file", ".", "delete", "(", ")", ";", "if", "(", "!", "result_ok", ")", "{", "if", "(", "!", "file", ".", "exists", "(", ")", ")", "{", "posix_errno", "=", "Posix", ".", "ENOENT", ";", "}", "else", "if", "(", "file", ".", "isDirectory", "(", ")", ")", "{", "posix_errno", "=", "Posix", ".", "EEXIST", ";", "}", "else", "{", "posix_errno", "=", "Posix", ".", "EUNKNOWN", ";", "}", "}", "}", "}", ";", "break", ";", "}", "case", "FILE_PWD", ":", "{", "d", "=", "new", "FileAsync", "(", ")", "{", "private", "String", "pwd", ";", "{", "this", ".", "command", "=", "FILE_PWD", ";", "super", ".", "level", "=", "2", ";", "}", "@", "Override", "public", "void", "async", "(", ")", "{", "File", "pwd", "=", "Posix", ".", "getCWD", "(", ")", ";", "if", "(", "pwd", ".", "exists", "(", ")", "&&", "pwd", ".", "isDirectory", "(", ")", ")", "{", "this", ".", "pwd", "=", "pwd", ".", "getAbsolutePath", "(", ")", ";", "result_ok", "=", "true", ";", "}", "else", "{", "result_ok", "=", "false", ";", "posix_errno", "=", "Posix", ".", "ENOENT", ";", "}", "again", "=", "false", ";", "}", "@", "Override", "public", "void", "ready", "(", ")", "throws", "Pausable", "{", "if", "(", "!", "result_ok", ")", "{", "reply_posix_error", "(", "posix_errno", ")", ";", "}", "else", "{", "ByteBuffer", "reply", "=", "null", ";", "ByteBuffer", "data", "=", "null", ";", "if", "(", "isUnicodeDriverInterface", "(", ")", ")", "{", "reply", "=", "ByteBuffer", ".", "allocate", "(", "1", ")", ";", "data", "=", "ByteBuffer", ".", "allocate", "(", "pwd", ".", "length", "(", ")", ")", ";", "reply", ".", "put", "(", "FILE_RESP_FNAME", ")", ";", "IO", ".", "putstr", "(", "data", ",", "pwd", ",", "false", ")", ";", "}", "else", "{", "reply", "=", "ByteBuffer", ".", "allocate", "(", "1", "+", "pwd", ".", "length", "(", ")", ")", ";", "reply", ".", "put", "(", "FILE_RESP_OK", ")", ";", "IO", ".", "putstr", "(", "reply", ",", "pwd", ",", "false", ")", ";", "}", "driver_output2", "(", "reply", ",", "data", ")", ";", "}", "}", "}", ";", "break", ";", "}", "case", "FILE_LSEEK", ":", "{", "final", "long", "off", "=", "buf", ".", "getLong", "(", ")", ";", "final", "int", "whence", "=", "buf", ".", "getInt", "(", ")", ";", "async_lseek", "(", "null", ",", "true", ",", "off", ",", "whence", ")", ";", "return", ";", "}", "case", "FILE_OPEN", ":", "{", "final", "int", "mode", "=", "buf", ".", "getInt", "(", ")", ";", "final", "String", "file_name", "=", "IO", ".", "strcpy", "(", "buf", ")", ";", "d", "=", "new", "SimpleFileAsync", "(", "cmd", ",", "file_name", ")", "{", "int", "res_fd", "=", "1234", ";", "public", "void", "run", "(", ")", "{", "boolean", "compressed", "=", "(", "mode", "&", "EFILE_COMPRESSED", ")", ">", "0", ";", "if", "(", "compressed", "&&", "log", ".", "isLoggable", "(", "Level", ".", "FINE", ")", ")", "{", "log", ".", "fine", "(", "\"\"", "+", "file_name", ")", ";", "}", "boolean", "append", "=", "(", "mode", "&", "EFILE_MODE_APPEND", ")", ">", "0", ";", "if", "(", "(", "mode", "&", "~", "(", "EFILE_MODE_APPEND", "|", "EFILE_MODE_READ_WRITE", ")", ")", ">", "0", ")", "{", "log", ".", "warning", "(", "\"\"", ")", ";", "throw", "new", "NotImplemented", "(", ")", ";", "}", "try", "{", "if", "(", "compressed", ")", "{", "if", "(", "(", "mode", "&", "EFILE_MODE_READ_WRITE", ")", "==", "EFILE_MODE_READ_WRITE", "&&", "append", ")", "{", "posix_errno", "=", "Posix", ".", "EINVAL", ";", "return", ";", "}", "log", ".", "warning", "(", "\"\"", ")", ";", "throw", "new", "NotImplemented", "(", ")", ";", "}", "else", "{", "switch", "(", "mode", "&", "EFILE_MODE_READ_WRITE", ")", "{", "case", "EFILE_MODE_READ", ":", "{", "FileInputStream", "fo", "=", "new", "FileInputStream", "(", "file", ")", ";", "fd", "=", "fo", ".", "getChannel", "(", ")", ";", "res_fd", "=", "getFDnumber", "(", "fo", ".", "getFD", "(", ")", ")", ";", "break", ";", "}", "case", "EFILE_MODE_WRITE", ":", "{", "FileOutputStream", "fo", "=", "new", "FileOutputStream", "(", "file", ")", ";", "fd", "=", "fo", ".", "getChannel", "(", ")", ";", "res_fd", "=", "getFDnumber", "(", "fo", ".", "getFD", "(", ")", ")", ";", "break", ";", "}", "case", "EFILE_MODE_READ_WRITE", ":", "{", "RandomAccessFile", "rafff", ";", "fd", "=", "(", "rafff", "=", "new", "RandomAccessFile", "(", "file", ",", "\"rw\"", ")", ")", ".", "getChannel", "(", ")", ";", "res_fd", "=", "getFDnumber", "(", "rafff", ".", "getFD", "(", ")", ")", ";", "break", ";", "}", "default", ":", "throw", "new", "NotImplemented", "(", ")", ";", "}", "EFile", ".", "this", ".", "name", "=", "file", ";", "result_ok", "=", "true", ";", "}", "}", "catch", "(", "FileNotFoundException", "fnfe", ")", "{", "posix_errno", "=", "fileNotFound_to_posixErrno", "(", "file", ",", "mode", ")", ";", "}", "catch", "(", "IOException", "e", ")", "{", "log", ".", "log", "(", "Level", ".", "WARNING", ",", "\"\"", ",", "e", ")", ";", "posix_errno", "=", "fileNotFound_to_posixErrno", "(", "file", ",", "mode", ")", ";", "}", "catch", "(", "IllegalAccessException", "e", ")", "{", "log", ".", "log", "(", "Level", ".", "WARNING", ",", "\"\"", ",", "e", ")", ";", "posix_errno", "=", "fileNotFound_to_posixErrno", "(", "file", ",", "mode", ")", ";", "}", "}", "@", "Override", "public", "void", "ready", "(", ")", "throws", "Pausable", "{", "if", "(", "result_ok", ")", "{", "EFile", ".", "this", ".", "fd", "=", "fd", ";", "reply_Uint", "(", "res_fd", ")", ";", "}", "else", "{", "reply_posix_error", "(", "posix_errno", ")", ";", "}", "}", "}", ";", "}", "break", ";", "case", "FILE_FSTAT", ":", "case", "FILE_LSTAT", ":", "{", "final", "String", "file_name", "=", "IO", ".", "strcpy", "(", "buf", ")", ";", "final", "File", "file", "=", "ERT", ".", "newFile", "(", "file_name", ")", ";", "if", "(", "ClassPathResource", ".", "isResource", "(", "file_name", ")", ")", "{", "ClassPathResource", ".", "fstat", "(", "this", ",", "file_name", ")", ";", "return", ";", "}", "d", "=", "new", "FileAsync", "(", ")", "{", "long", "file_size", ";", "int", "file_type", ";", "long", "file_access_time", ";", "long", "file_modify_time", ";", "long", "file_create_time", ";", "int", "file_access", ";", "int", "file_mode", ";", "@", "Override", "public", "void", "async", "(", ")", "{", "if", "(", "!", "file", ".", "exists", "(", ")", ")", "{", "result_ok", "=", "false", ";", "posix_errno", "=", "Posix", ".", "ENOENT", ";", "return", ";", "}", "file_size", "=", "file", ".", "length", "(", ")", ";", "if", "(", "file", ".", "isDirectory", "(", ")", ")", "{", "file_type", "=", "FT_DIRECTORY", ";", "}", "else", "if", "(", "file", ".", "isFile", "(", ")", ")", "{", "file_type", "=", "FT_REGULAR", ";", "}", "else", "{", "file_type", "=", "FT_OTHER", ";", "}", "file_access_time", "=", "file_create_time", "=", "file_modify_time", "=", "file", ".", "lastModified", "(", ")", ";", "file_mode", "|=", "file", ".", "canExecute", "(", ")", "?", "0000100", ":", "0", ";", "file_mode", "|=", "file", ".", "canWrite", "(", ")", "?", "0000200", ":", "0", ";", "file_mode", "|=", "file", ".", "canRead", "(", ")", "?", "0000400", ":", "0", ";", "file_access", "|=", "file", ".", "canRead", "(", ")", "?", "FA_READ", ":", "0", ";", "file_access", "|=", "file", ".", "canWrite", "(", ")", "?", "FA_WRITE", ":", "0", ";", "result_ok", "=", "true", ";", "}", "@", "Override", "public", "void", "ready", "(", ")", "throws", "Pausable", "{", "if", "(", "!", "this", ".", "result_ok", ")", "{", "reply_posix_error", "(", "posix_errno", ")", ";", "return", ";", "}", "final", "int", "RESULT_SIZE", "=", "(", "1", "+", "(", "29", "*", "4", ")", ")", ";", "ByteBuffer", "res", "=", "ByteBuffer", ".", "allocate", "(", "RESULT_SIZE", ")", ";", "res", ".", "order", "(", "ByteOrder", ".", "BIG_ENDIAN", ")", ";", "res", ".", "put", "(", "FILE_RESP_INFO", ")", ";", "res", ".", "putLong", "(", "file_size", ")", ";", "res", ".", "putInt", "(", "file_type", ")", ";", "put_time", "(", "res", ",", "file_access_time", ")", ";", "put_time", "(", "res", ",", "file_modify_time", ")", ";", "put_time", "(", "res", ",", "file_create_time", ")", ";", "res", ".", "putInt", "(", "file_mode", ")", ";", "res", ".", "putInt", "(", "1", ")", ";", "res", ".", "putInt", "(", "0", ")", ";", "res", ".", "putInt", "(", "0", ")", ";", "res", ".", "putInt", "(", "file_name", ".", "hashCode", "(", ")", ")", ";", "res", ".", "putInt", "(", "0", ")", ";", "res", ".", "putInt", "(", "0", ")", ";", "res", ".", "putInt", "(", "file_access", ")", ";", "driver_output2", "(", "res", ",", "null", ")", ";", "}", "private", "void", "put_time", "(", "ByteBuffer", "res", ",", "long", "time", ")", "{", "Calendar", "c", "=", "GregorianCalendar", ".", "getInstance", "(", ")", ";", "c", ".", "setTimeInMillis", "(", "time", ")", ";", "int", "year", "=", "c", ".", "get", "(", "Calendar", ".", "YEAR", ")", ";", "res", ".", "putInt", "(", "year", ")", ";", "int", "month", "=", "c", ".", "get", "(", "Calendar", ".", "MONTH", ")", "-", "Calendar", ".", "JANUARY", "+", "1", ";", "res", ".", "putInt", "(", "month", ")", ";", "int", "day_of_month", "=", "c", ".", "get", "(", "Calendar", ".", "DAY_OF_MONTH", ")", ";", "res", ".", "putInt", "(", "day_of_month", ")", ";", "int", "hour_of_day", "=", "c", ".", "get", "(", "Calendar", ".", "HOUR_OF_DAY", ")", ";", "res", ".", "putInt", "(", "hour_of_day", ")", ";", "int", "minute_of_hour", "=", "c", ".", "get", "(", "Calendar", ".", "MINUTE", ")", ";", "res", ".", "putInt", "(", "minute_of_hour", ")", ";", "int", "seconds", "=", "c", ".", "get", "(", "Calendar", ".", "SECOND", ")", ";", "res", ".", "putInt", "(", "seconds", ")", ";", "}", "}", ";", "break", ";", "}", "case", "FILE_READDIR", ":", "{", "final", "String", "dir_name", "=", "IO", ".", "strcpy", "(", "buf", ")", ";", "if", "(", "dir_name", ".", "startsWith", "(", "RESOURCE_PREFIX", ")", ")", "{", "ClassPathResource", ".", "listdir", "(", "this", ",", "dir_name", ".", "substring", "(", "RESOURCE_PREFIX", ".", "length", "(", ")", ")", ")", ";", "return", ";", "}", "final", "File", "dir", "=", "ERT", ".", "newFile", "(", "dir_name", ")", ";", "d", "=", "new", "FileAsync", "(", ")", "{", "{", "super", ".", "level", "=", "2", ";", "}", "String", "[", "]", "files", ";", "@", "Override", "public", "void", "async", "(", ")", "{", "if", "(", "!", "dir", ".", "exists", "(", ")", ")", "{", "this", ".", "posix_errno", "=", "Posix", ".", "ENOENT", ";", "this", ".", "result_ok", "=", "false", ";", "return", ";", "}", "if", "(", "!", "dir", ".", "isDirectory", "(", ")", ")", "{", "this", ".", "posix_errno", "=", "Posix", ".", "EINVAL", ";", "this", ".", "result_ok", "=", "false", ";", "return", ";", "}", "try", "{", "files", "=", "dir", ".", "list", "(", "READDIR_FILTER", ")", ";", "this", ".", "result_ok", "=", "true", ";", "}", "catch", "(", "SecurityException", "e", ")", "{", "this", ".", "posix_errno", "=", "Posix", ".", "EPERM", ";", "this", ".", "result_ok", "=", "false", ";", "return", ";", "}", "}", "@", "Override", "public", "void", "ready", "(", ")", "throws", "Pausable", "{", "if", "(", "!", "this", ".", "result_ok", ")", "{", "reply_posix_error", "(", "posix_errno", ")", ";", "return", ";", "}", "reply_list_directory", "(", "files", ")", ";", "}", "}", ";", "break", ";", "}", "case", "FILE_RENAME", ":", "{", "final", "String", "from_name", "=", "IO", ".", "getstr", "(", "buf", ",", "true", ")", ";", "final", "File", "to_name", "=", "ERT", ".", "newFile", "(", "IO", ".", "getstr", "(", "buf", ",", "true", ")", ")", ";", "if", "(", "log", ".", "isLoggable", "(", "Level", ".", "FINE", ")", ")", "log", ".", "fine", "(", "\"\"", "+", "this", "+", "\"rename", "\"", "+", "from_name", "+", "\"", "->", "\"", "+", "to_name", ")", ";", "d", "=", "new", "SimpleFileAsync", "(", "cmd", ",", "from_name", ")", "{", "public", "void", "run", "(", ")", "{", "this", ".", "result_ok", "=", "file", ".", "renameTo", "(", "to_name", ")", ";", "if", "(", "!", "result_ok", ")", "{", "if", "(", "!", "file", ".", "exists", "(", ")", ")", "{", "posix_errno", "=", "Posix", ".", "ENOENT", ";", "}", "else", "if", "(", "to_name", ".", "exists", "(", ")", ")", "{", "posix_errno", "=", "Posix", ".", "EEXIST", ";", "}", "else", "{", "posix_errno", "=", "Posix", ".", "EUNKNOWN", ";", "}", "}", "}", "}", ";", "break", ";", "}", "case", "FILE_FADVISE", ":", "{", "reply_ok", "(", ")", ";", "return", ";", "}", "case", "FILE_SETOPT", ":", "{", "reply_ok", "(", ")", ";", "return", ";", "}", "default", ":", "log", ".", "warning", "(", "\"\"", "+", "(", "(", "int", ")", "cmd", ")", "+", "\"", "\"", "+", "EBinary", ".", "make", "(", "buf", ")", ")", ";", "throw", "new", "NotImplemented", "(", "\"\"", "+", "(", "(", "int", ")", "cmd", ")", "+", "\"", "\"", "+", "EBinary", ".", "make", "(", "buf", ")", ")", ";", "}", "if", "(", "d", "!=", "null", ")", "{", "cq_enq", "(", "d", ")", ";", "}", "}", "@", "Override", "public", "void", "processExit", "(", "ERef", "monitor", ")", "throws", "Pausable", "{", "}", "@", "Override", "protected", "void", "readyAsync", "(", "EAsync", "data", ")", "throws", "Pausable", "{", "FileAsync", "d", "=", "(", "FileAsync", ")", "data", ";", "if", "(", "try_again", "(", "d", ")", ")", "return", ";", "d", ".", "ready", "(", ")", ";", "if", "(", "write_buffered", "!=", "0", "&&", "timer_state", "==", "TimerState", ".", "IDLE", ")", "{", "timer_state", "=", "TimerState", ".", "WRITE", ";", "driver_set_timer", "(", "write_delay", ")", ";", "}", "cq_execute", "(", ")", ";", "}", "private", "boolean", "try_again", "(", "FileAsync", "d", ")", "{", "if", "(", "!", "d", ".", "again", ")", "{", "return", "false", ";", "}", "d", ".", "deq_free_size", "(", ")", ";", "if", "(", "timer_state", "!=", "TimerState", ".", "IDLE", ")", "{", "driver_cancel_timer", "(", ")", ";", "}", "timer_state", "=", "TimerState", ".", "AGAIN", ";", "invoke", "=", "d", ";", "driver_set_timer", "(", "0", ")", ";", "return", "true", ";", "}", "@", "Override", "protected", "void", "readyInput", "(", "SelectableChannel", "ch", ")", "throws", "Pausable", "{", "throw", "new", "InternalError", "(", "\"\"", ")", ";", "}", "@", "Override", "protected", "void", "readyOutput", "(", "SelectableChannel", "evt", ")", "throws", "Pausable", "{", "throw", "new", "InternalError", "(", "\"\"", ")", ";", "}", "@", "Override", "protected", "void", "timeout", "(", ")", "throws", "Pausable", "{", "TimerState", "timer_state", "=", "this", ".", "timer_state", ";", "this", ".", "timer_state", "=", "TimerState", ".", "IDLE", ";", "switch", "(", "timer_state", ")", "{", "case", "IDLE", ":", "assert", "(", "false", ")", ":", "\"\"", ";", "return", ";", "case", "AGAIN", ":", "assert", "(", "invoke", "!=", "null", ")", ";", "driver_async", "(", "invoke", ")", ";", "break", ";", "case", "WRITE", ":", "int", "r", "=", "flush_write", "(", "null", ")", ";", "assert", "(", "r", "==", "0", ")", ";", "cq_execute", "(", ")", ";", "}", "}", "private", "int", "flush_write", "(", "int", "[", "]", "errp", ")", "{", "int", "result", ";", "q_mtx", ".", "lock", "(", ")", ";", "try", "{", "if", "(", "this", ".", "write_buffered", ">", "0", ")", "{", "result", "=", "async_write", "(", "null", ",", "false", ",", "0", ")", ";", "}", "else", "{", "result", "=", "0", ";", "}", "}", "finally", "{", "q_mtx", ".", "unlock", "(", ")", ";", "}", "return", "result", ";", "}", "private", "int", "async_write", "(", "int", "[", "]", "errp", ",", "boolean", "reply", ",", "int", "reply_size", ")", "{", "try", "{", "FileAsync", "cmd", "=", "new", "WriteAsync", "(", "reply", ",", "reply_size", ")", ";", "cq_enq", "(", "cmd", ")", ";", "write_buffered", "=", "0", ";", "return", "0", ";", "}", "catch", "(", "OutOfMemoryError", "e", ")", "{", "if", "(", "errp", "==", "null", ")", "{", "throw", "e", ";", "}", "if", "(", "errp", "!=", "null", ")", "errp", "[", "0", "]", "=", "Posix", ".", "ENOMEM", ";", "return", "-", "1", ";", "}", "}", "private", "void", "cq_enq", "(", "FileAsync", "d", ")", "{", "cq", ".", "add", "(", "d", ")", ";", "}", "private", "FileAsync", "cq_deq", "(", ")", "{", "return", "cq", ".", "poll", "(", ")", ";", "}", "private", "void", "cq_execute", "(", ")", "throws", "Pausable", "{", "if", "(", "timer_state", "==", "TimerState", ".", "AGAIN", ")", "return", ";", "FileAsync", "d", ";", "if", "(", "(", "d", "=", "cq_deq", "(", ")", ")", "==", "null", ")", "return", ";", "d", ".", "again", "=", "false", ";", "if", "(", "THREAD_SHORT_CIRCUIT", ">=", "level", ")", "{", "d", ".", "async", "(", ")", ";", "this", ".", "readyAsync", "(", "d", ")", ";", "}", "else", "{", "driver_async", "(", "d", ")", ";", "}", "}", "void", "reply_buf", "(", "ByteBuffer", "buf", ")", "throws", "Pausable", "{", "ByteBuffer", "header", "=", "ByteBuffer", ".", "allocate", "(", "1", "+", "4", "+", "4", ")", ";", "header", ".", "put", "(", "FILE_RESP_DATA", ")", ";", "header", ".", "putLong", "(", "buf", ".", "position", "(", ")", ")", ";", "driver_output2", "(", "header", ",", "buf", ")", ";", "}", "void", "reply_eof", "(", ")", "throws", "Pausable", "{", "ByteBuffer", "header", "=", "ByteBuffer", ".", "allocate", "(", "1", ")", ";", "header", ".", "put", "(", "FILE_RESP_EOF", ")", ";", "driver_output2", "(", "header", ",", "null", ")", ";", "}", "public", "void", "reply_ok", "(", ")", "throws", "Pausable", "{", "ByteBuffer", "header", "=", "ByteBuffer", ".", "allocate", "(", "1", ")", ";", "header", ".", "put", "(", "FILE_RESP_OK", ")", ";", "driver_output2", "(", "header", ",", "null", ")", ";", "}", "protected", "static", "int", "fileNotFound_to_posixErrno", "(", "File", "file", ",", "int", "mode", ")", "{", "if", "(", "!", "file", ".", "exists", "(", ")", "||", "!", "file", ".", "isFile", "(", ")", ")", "return", "Posix", ".", "ENOENT", ";", "else", "if", "(", "(", "mode", "&", "EFILE_MODE_READ", ")", ">", "0", "&&", "!", "file", ".", "canRead", "(", ")", ")", "return", "Posix", ".", "EPERM", ";", "else", "if", "(", "(", "mode", "&", "EFILE_MODE_WRITE", ")", ">", "0", "&&", "!", "file", ".", "canWrite", "(", ")", ")", "return", "Posix", ".", "EPERM", ";", "else", "return", "Posix", ".", "EUNKNOWN", ";", "}", "@", "Override", "public", "String", "toString", "(", ")", "{", "String", "pos", ";", "try", "{", "pos", "=", "(", "fd", "==", "null", "?", "\"?\"", ":", "\"0x\"", "+", "Long", ".", "toHexString", "(", "fd", ".", "position", "(", ")", ")", ")", ";", "}", "catch", "(", "IOException", "e", ")", "{", "pos", "=", "\"?\"", ";", "}", "return", "\"EFile[name=\\\"\"", "+", "name", "+", "\"\\\";pos=\"", "+", "pos", "+", "\"]\"", ";", "}", "void", "reply_list_directory", "(", "String", "[", "]", "files", ")", "throws", "Pausable", "{", "for", "(", "int", "i", "=", "0", ";", "i", "<", "files", ".", "length", ";", "i", "++", ")", "{", "if", "(", "isUnicodeDriverInterface", "(", ")", ")", "{", "ByteBuffer", "reply", "=", "ByteBuffer", ".", "allocate", "(", "1", ")", ";", "reply", ".", "put", "(", "FILE_RESP_FNAME", ")", ";", "ByteBuffer", "data", "=", "ByteBuffer", ".", "allocate", "(", "files", "[", "i", "]", ".", "length", "(", ")", ")", ";", "data", ".", "limit", "(", "data", ".", "capacity", "(", ")", ")", ";", "data", ".", "position", "(", "0", ")", ";", "IO", ".", "putstr", "(", "data", ",", "files", "[", "i", "]", ",", "false", ")", ";", "driver_output2", "(", "reply", ",", "data", ")", ";", "}", "else", "{", "ByteBuffer", "resbuf", "=", "ByteBuffer", ".", "allocate", "(", "files", "[", "i", "]", ".", "length", "(", ")", "+", "1", ")", ";", "resbuf", ".", "put", "(", "FILE_RESP_OK", ")", ";", "resbuf", ".", "limit", "(", "resbuf", ".", "capacity", "(", ")", ")", ";", "resbuf", ".", "position", "(", "1", ")", ";", "IO", ".", "putstr", "(", "resbuf", ",", "files", "[", "i", "]", ",", "false", ")", ";", "driver_output2", "(", "resbuf", ",", "null", ")", ";", "}", "}", "ByteBuffer", "resbuf", "=", "ByteBuffer", ".", "allocate", "(", "1", ")", ";", "resbuf", ".", "put", "(", "isUnicodeDriverInterface", "(", ")", "?", "FILE_RESP_FNAME", ":", "FILE_RESP_OK", ")", ";", "driver_output2", "(", "resbuf", ",", "null", ")", ";", "}", "private", "static", "boolean", "isUnicodeDriverInterface", "(", ")", "{", "return", "ERT", ".", "runtime_info", ".", "unicodeDriverInterface", ";", "}", "}", "</s>" ]
7,764
[ "<s>", "package", "erjang", ".", "driver", ".", "efile", ";", "import", "java", ".", "io", ".", "File", ";", "import", "erjang", ".", "EObject", ";", "public", "class", "Posix", "{", "public", "static", "final", "int", "EINVAL", "=", "0", ";", "public", "static", "final", "int", "ENOMEM", "=", "1", ";", "public", "static", "final", "int", "EEXIST", "=", "2", ";", "public", "static", "final", "int", "ENOENT", "=", "3", ";", "public", "static", "final", "int", "EPERM", "=", "4", ";", "public", "static", "final", "int", "EISCONN", "=", "5", ";", "public", "static", "final", "int", "EUNKNOWN", "=", "6", ";", "public", "static", "final", "int", "ENETUNREACH", "=", "7", ";", "public", "static", "final", "int", "EADDRNOTAVAIL", "=", "8", ";", "public", "static", "final", "int", "EIO", "=", "9", ";", "public", "static", "final", "int", "EOPNOTSUPP", "=", "10", ";", "public", "static", "final", "int", "ECONNREFUSED", "=", "11", ";", "public", "static", "final", "int", "EMSGSIZE", "=", "12", ";", "public", "static", "final", "int", "ENOTCONN", "=", "13", ";", "public", "static", "final", "int", "EINTR", "=", "14", ";", "public", "static", "final", "int", "EAGAIN", "=", "15", ";", "public", "static", "final", "int", "EALREADY", "=", "16", ";", "private", "static", "final", "String", "[", "]", "err_id", "=", "{", "\"einval\"", ",", "\"enomem\"", ",", "\"eexist\"", ",", "\"enoent\"", ",", "\"eperm\"", ",", "\"eisconn\"", ",", "\"eunknown\"", ",", "\"enetunreach\"", ",", "\"\"", ",", "\"eio\"", ",", "\"eopnotsupp\"", ",", "\"econnrefused\"", ",", "\"emsgsize\"", ",", "\"enotconn\"", ",", "\"eintr\"", ",", "\"eagain\"", ",", "\"ealready\"", ",", "}", ";", "public", "static", "String", "errno_id", "(", "int", "posixErrno", ")", "{", "if", "(", "posixErrno", ">=", "err_id", ".", "length", "||", "posixErrno", "<", "0", ")", "return", "\"\"", ";", "else", "return", "err_id", "[", "posixErrno", "]", ";", "}", "static", "File", "CWD", "=", "new", "File", "(", "\".\"", ")", ";", "public", "static", "boolean", "isCWD", "(", "String", "name", ",", "File", "file", ")", "{", "if", "(", "name", ".", "equals", "(", "\".\"", ")", ")", "return", "true", ";", "if", "(", "file", ".", "isAbsolute", "(", ")", ")", "{", "if", "(", "file", ".", "equals", "(", "getCWD", "(", ")", ")", ")", "return", "true", ";", "}", "else", "{", "if", "(", "file", ".", "getAbsoluteFile", "(", ")", ".", "equals", "(", "getCWD", "(", ")", ")", ")", "return", "true", ";", "}", "return", "false", ";", "}", "public", "static", "File", "getCWD", "(", ")", "{", "return", "new", "File", "(", "System", ".", "getProperty", "(", "\"user.dir\"", ")", ")", ".", "getAbsoluteFile", "(", ")", ";", "}", "}", "</s>" ]
7,765
[ "<s>", "package", "erjang", ".", "driver", ".", "efile", ";", "import", "java", ".", "nio", ".", "channels", ".", "FileChannel", ";", "import", "kilim", ".", "Pausable", ";", "import", "erjang", ".", "driver", ".", "EAsync", ";", "public", "abstract", "class", "FileAsync", "implements", "EAsync", "{", "public", "int", "command", ";", "public", "boolean", "again", ";", "protected", "FileChannel", "fd", ";", "protected", "int", "level", ";", "protected", "int", "flags", ";", "protected", "boolean", "reply", ";", "protected", "int", "posix_errno", ";", "protected", "boolean", "result_ok", ";", "public", "abstract", "void", "async", "(", ")", ";", "@", "Override", "public", "abstract", "void", "ready", "(", ")", "throws", "Pausable", ";", "public", "void", "deq_free_size", "(", ")", "{", "}", "protected", "void", "reply", "(", "EFile", "efile", ")", "throws", "Pausable", "{", "if", "(", "result_ok", ")", "{", "efile", ".", "reply_ok", "(", ")", ";", "}", "else", "{", "efile", ".", "reply_posix_error", "(", "posix_errno", ")", ";", "}", "}", "}", "</s>" ]
7,766
[ "<s>", "package", "erjang", ".", "driver", ";", "import", "java", ".", "util", ".", "concurrent", ".", "locks", ".", "ReentrantLock", ";", "import", "erjang", ".", "EString", ";", "import", "erjang", ".", "ETuple2", ";", "public", "class", "ExecDriver", "implements", "EDriver", "{", "public", "ExecDriver", "(", "ETuple2", "name", ")", "{", "}", "@", "Override", "public", "String", "driverName", "(", ")", "{", "throw", "new", "erjang", ".", "NotImplemented", "(", ")", ";", "}", "@", "Override", "public", "void", "finish", "(", ")", "{", "throw", "new", "erjang", ".", "NotImplemented", "(", ")", ";", "}", "@", "Override", "public", "EDriverControl", "start", "(", "EString", "command", ")", "{", "throw", "new", "erjang", ".", "NotImplemented", "(", ")", ";", "}", "@", "Override", "public", "boolean", "useDriverLevelLocking", "(", ")", "{", "return", "false", ";", "}", "@", "Override", "public", "ReentrantLock", "getLock", "(", ")", "{", "throw", "new", "erjang", ".", "NotImplemented", "(", ")", ";", "}", "}", "</s>" ]
7,767
[ "<s>", "package", "erjang", ".", "driver", ";", "import", "java", ".", "io", ".", "DataInputStream", ";", "import", "java", ".", "io", ".", "DataOutputStream", ";", "import", "java", ".", "io", ".", "File", ";", "import", "java", ".", "io", ".", "IOException", ";", "import", "java", ".", "io", ".", "InterruptedIOException", ";", "import", "java", ".", "nio", ".", "ByteBuffer", ";", "import", "java", ".", "nio", ".", "channels", ".", "SelectableChannel", ";", "import", "java", ".", "util", ".", "ArrayList", ";", "import", "java", ".", "util", ".", "Collections", ";", "import", "java", ".", "util", ".", "HashMap", ";", "import", "java", ".", "util", ".", "List", ";", "import", "java", ".", "util", ".", "Map", ";", "import", "kilim", ".", "Pausable", ";", "import", "kilim", ".", "Task", ";", "import", "erjang", ".", "EAtom", ";", "import", "erjang", ".", "EBinary", ";", "import", "erjang", ".", "ECons", ";", "import", "erjang", ".", "EHandle", ";", "import", "erjang", ".", "EObject", ";", "import", "erjang", ".", "EPID", ";", "import", "erjang", ".", "ERT", ";", "import", "erjang", ".", "ERef", ";", "import", "erjang", ".", "ESeq", ";", "import", "erjang", ".", "EString", ";", "import", "erjang", ".", "ETuple2", ";", "import", "erjang", ".", "ErlangError", ";", "import", "erjang", ".", "NotImplemented", ";", "import", "erjang", ".", "driver", ".", "EDriverTask", ".", "Mode", ";", "import", "erjang", ".", "m", ".", "erlang", ".", "ErlPort", ";", "public", "class", "ExecDriverInstance", "extends", "EDriverInstance", "{", "private", "ETuple2", "name", ";", "private", "Process", "process", ";", "private", "DataOutputStream", "out", ";", "private", "DataInputStream", "in", ";", "private", "DataInputStream", "err", ";", "protected", "Thread", "stdin_thread", ";", "protected", "Thread", "stderr_thread", ";", "private", "boolean", "is_closing", ";", "public", "ExecDriverInstance", "(", "ETuple2", "name", ")", "{", "super", "(", "new", "ExecDriver", "(", "name", ")", ")", ";", "this", ".", "name", "=", "name", ";", "}", "@", "Override", "public", "void", "setup", "(", ")", "{", "HashMap", "<", "String", ",", "String", ">", "env", "=", "task", ".", "env", ";", "String", "[", "]", "cmd", "=", "task", ".", "cmd", ";", "String", "cwd", "=", "task", ".", "cwd", ";", "String", "[", "]", "envp", "=", "new", "String", "[", "env", ".", "size", "(", ")", "]", ";", "int", "pos", "=", "0", ";", "for", "(", "Map", ".", "Entry", "<", "String", ",", "String", ">", "e", ":", "env", ".", "entrySet", "(", ")", ")", "{", "envp", "[", "pos", "++", "]", "=", "e", ".", "getKey", "(", ")", "+", "\"=\"", "+", "e", ".", "getValue", "(", ")", ";", "}", "try", "{", "this", ".", "process", "=", "Runtime", ".", "getRuntime", "(", ")", ".", "exec", "(", "cmd", ",", "envp", ",", "ERT", ".", "newFile", "(", "cwd", ")", ")", ";", "}", "catch", "(", "IOException", "e1", ")", "{", "throw", "new", "ErlangError", "(", "e1", ")", ";", "}", "List", "<", "String", ">", "al", "=", "new", "ArrayList", "<", "String", ">", "(", ")", ";", "Collections", ".", "addAll", "(", "al", ",", "cmd", ")", ";", "this", ".", "out", "=", "new", "DataOutputStream", "(", "this", ".", "process", ".", "getOutputStream", "(", ")", ")", ";", "this", ".", "in", "=", "new", "DataInputStream", "(", "this", ".", "process", ".", "getInputStream", "(", ")", ")", ";", "this", ".", "err", "=", "new", "DataInputStream", "(", "this", ".", "process", ".", "getErrorStream", "(", ")", ")", ";", "if", "(", "!", "task", ".", "is_out_only", ")", "{", "start_input_reader", "(", "in", ",", "true", ")", ";", "if", "(", "task", ".", "stderr_to_stdout", ")", "{", "start_input_reader", "(", "err", ",", "false", ")", ";", "}", "}", "}", "synchronized", "void", "do_close", "(", ")", "{", "this", ".", "is_closing", "=", "true", ";", "Thread", "th", "=", "stderr_thread", ";", "if", "(", "th", "!=", "null", ")", "{", "th", ".", "interrupt", "(", ")", ";", "}", "th", "=", "stdin_thread", ";", "if", "(", "th", "!=", "null", ")", "{", "th", ".", "interrupt", "(", ")", ";", "}", "Process", "p", "=", "this", ".", "process", ";", "if", "(", "p", "!=", "null", ")", "{", "p", ".", "destroy", "(", ")", ";", "}", "}", "synchronized", "boolean", "is_closing", "(", ")", "{", "return", "this", ".", "is_closing", ";", "}", "private", "void", "start_input_reader", "(", "final", "DataInputStream", "stream", ",", "final", "boolean", "is_stdin", ")", "{", "new", "Thread", "(", ")", "{", "{", "setDaemon", "(", "true", ")", ";", "start", "(", ")", ";", "}", "public", "void", "run", "(", ")", "{", "if", "(", "is_stdin", ")", "{", "stdin_thread", "=", "Thread", ".", "currentThread", "(", ")", ";", "try", "{", "boolean", "cont", "=", "false", ";", "do", "{", "try", "{", "cont", "=", "do_read", "(", ")", ";", "}", "catch", "(", "InterruptedIOException", "e", ")", "{", "cont", "=", "!", "is_closing", "(", ")", ";", "}", "catch", "(", "IOException", "e", ")", "{", "cont", "=", "false", ";", "}", "}", "while", "(", "cont", ")", ";", "}", "finally", "{", "stdin_thread", "=", "null", ";", "if", "(", "task", ".", "send_eof", ")", "{", "task", ".", "eof_from_driver_b", "(", ")", ";", "}", "if", "(", "task", ".", "send_exit_status", ")", "{", "int", "code", ";", "while", "(", "true", ")", "{", "try", "{", "code", "=", "process", ".", "waitFor", "(", ")", ";", "break", ";", "}", "catch", "(", "InterruptedException", "e", ")", "{", "continue", ";", "}", "}", "task", ".", "exit_status_from_driver_b", "(", "code", ")", ";", "}", "}", "}", "else", "{", "stderr_thread", "=", "Thread", ".", "currentThread", "(", ")", ";", "try", "{", "boolean", "cont", "=", "false", ";", "do", "{", "try", "{", "cont", "=", "do_read", "(", ")", ";", "}", "catch", "(", "InterruptedIOException", "e", ")", "{", "cont", "=", "!", "is_closing", "(", ")", ";", "}", "catch", "(", "IOException", "e", ")", "{", "cont", "=", "false", ";", "}", "}", "while", "(", "cont", ")", ";", "}", "finally", "{", "stderr_thread", "=", "null", ";", "}", "}", "}", "private", "boolean", "do_read", "(", ")", "throws", "IOException", "{", "byte", "[", "]", "data", ";", "int", "nbytes", ";", "if", "(", "task", ".", "mode", "==", "Mode", ".", "STREAM", ")", "{", "data", "=", "new", "byte", "[", "Math", ".", "max", "(", "stream", ".", "available", "(", ")", ",", "512", ")", "]", ";", "try", "{", "nbytes", "=", "stream", ".", "read", "(", "data", ")", ";", "}", "catch", "(", "IOException", "e", ")", "{", "nbytes", "=", "0", ";", "}", "}", "else", "if", "(", "task", ".", "mode", "==", "Mode", ".", "PACKET", ")", "{", "switch", "(", "task", ".", "packet", ")", "{", "case", "1", ":", "nbytes", "=", "stream", ".", "read", "(", ")", ";", "break", ";", "case", "2", ":", "nbytes", "=", "stream", ".", "readUnsignedShort", "(", ")", ";", "break", ";", "case", "4", ":", "nbytes", "=", "stream", ".", "readInt", "(", ")", "&", "0x7fffffff", ";", "break", ";", "default", ":", "throw", "new", "InternalError", "(", ")", ";", "}", "if", "(", "nbytes", "<=", "0", ")", "{", "return", "false", ";", "}", "data", "=", "new", "byte", "[", "nbytes", "]", ";", "try", "{", "stream", ".", "readFully", "(", "data", ")", ";", "}", "catch", "(", "IOException", "e", ")", "{", "nbytes", "=", "0", ";", "}", "}", "else", "{", "throw", "new", "NotImplemented", "(", "\"mode=\"", "+", "task", ".", "mode", ")", ";", "}", "if", "(", "nbytes", "<=", "0", ")", "{", "return", "false", ";", "}", "if", "(", "task", ".", "send_binary_data", ")", "{", "task", ".", "output_from_driver_b", "(", "new", "EBinary", "(", "data", ",", "0", ",", "nbytes", ")", ")", ";", "}", "else", "{", "task", ".", "output_from_driver_b", "(", "EString", ".", "make", "(", "data", ",", "0", ",", "nbytes", ")", ")", ";", "}", "return", "true", ";", "}", "}", ";", "}", "@", "Override", "protected", "EObject", "call", "(", "EPID", "pid", ",", "int", "command", ",", "EObject", "data", ")", "throws", "Pausable", "{", "throw", "ERT", ".", "badarg", "(", "ERT", ".", "box", "(", "command", ")", ",", "data", ")", ";", "}", "@", "Override", "protected", "void", "flush", "(", ")", "throws", "Pausable", "{", "}", "@", "Override", "protected", "void", "stop", "(", "EObject", "reason", ")", "throws", "Pausable", "{", "this", ".", "do_close", "(", ")", ";", "}", "@", "Override", "protected", "void", "output", "(", "EHandle", "caller", ",", "ByteBuffer", "buf", ")", "throws", "IOException", ",", "Pausable", "{", "byte", "[", "]", "data", "=", "buf", ".", "array", "(", ")", ";", "int", "data_off", "=", "buf", ".", "position", "(", ")", "+", "buf", ".", "arrayOffset", "(", ")", ";", "int", "data_len", "=", "buf", ".", "remaining", "(", ")", ";", "switch", "(", "task", ".", "mode", ")", "{", "case", "STREAM", ":", "this", ".", "out", ".", "write", "(", "data", ",", "data_off", ",", "data_len", ")", ";", "this", ".", "out", ".", "flush", "(", ")", ";", "return", ";", "case", "PACKET", ":", "switch", "(", "task", ".", "packet", ")", "{", "case", "1", ":", "for", "(", "int", "off", "=", "0", ";", "off", "<", "data_len", ";", "off", "+=", "256", ")", "{", "int", "rest", "=", "Math", ".", "min", "(", "256", ",", "data_len", "-", "off", ")", ";", "out", ".", "writeByte", "(", "rest", ")", ";", "out", ".", "write", "(", "data", ",", "data_off", "+", "off", ",", "rest", ")", ";", "}", "this", ".", "out", ".", "flush", "(", ")", ";", "return", ";", "case", "2", ":", "for", "(", "int", "off", "=", "0", ";", "off", "<", "data_len", ";", "off", "+=", "(", "1", "<<", "16", ")", ")", "{", "int", "rest", "=", "Math", ".", "min", "(", "(", "1", "<<", "16", ")", ",", "data_len", "-", "off", ")", ";", "out", ".", "writeShort", "(", "rest", ")", ";", "out", ".", "write", "(", "data", ",", "data_off", "+", "off", ",", "rest", ")", ";", "}", "this", ".", "out", ".", "flush", "(", ")", ";", "return", ";", "case", "4", ":", "out", ".", "writeInt", "(", "data_len", ")", ";", "out", ".", "write", "(", "data", ",", "data_off", ",", "data_len", ")", ";", "this", ".", "out", ".", "flush", "(", ")", ";", "return", ";", "default", ":", "throw", "new", "Error", "(", "\"\"", ")", ";", "}", "case", "LINE", ":", "throw", "new", "NotImplemented", "(", ")", ";", "}", "this", ".", "out", ".", "flush", "(", ")", ";", "}", "@", "Override", "public", "void", "processExit", "(", "ERef", "monitor", ")", "throws", "Pausable", "{", "}", "@", "Override", "protected", "void", "readyAsync", "(", "EAsync", "data", ")", "throws", "Pausable", "{", "}", "@", "Override", "protected", "void", "readyInput", "(", "SelectableChannel", "ch", ")", "throws", "Pausable", "{", "}", "@", "Override", "protected", "void", "readyOutput", "(", "SelectableChannel", "evt", ")", "throws", "Pausable", "{", "}", "@", "Override", "protected", "void", "timeout", "(", ")", "throws", "Pausable", "{", "}", "}", "</s>" ]
7,768
[ "<s>", "package", "erjang", ".", "driver", ";", "import", "java", ".", "io", ".", "DataInputStream", ";", "import", "java", ".", "io", ".", "DataOutputStream", ";", "import", "java", ".", "io", ".", "File", ";", "import", "java", ".", "io", ".", "IOException", ";", "import", "java", ".", "io", ".", "InputStream", ";", "import", "java", ".", "nio", ".", "ByteBuffer", ";", "import", "java", ".", "util", ".", "ArrayList", ";", "import", "java", ".", "util", ".", "Collections", ";", "import", "java", ".", "util", ".", "List", ";", "import", "java", ".", "util", ".", "Map", ";", "import", "kilim", ".", "Pausable", ";", "import", "kilim", ".", "Task", ";", "import", "erjang", ".", "EAtom", ";", "import", "erjang", ".", "EBinList", ";", "import", "erjang", ".", "EBinary", ";", "import", "erjang", ".", "EBitString", ";", "import", "erjang", ".", "ECons", ";", "import", "erjang", ".", "EHandle", ";", "import", "erjang", ".", "EObject", ";", "import", "erjang", ".", "EPort", ";", "import", "erjang", ".", "EProc", ";", "import", "erjang", ".", "ERT", ";", "import", "erjang", ".", "ESeq", ";", "import", "erjang", ".", "EString", ";", "import", "erjang", ".", "ETask", ";", "import", "erjang", ".", "ETuple2", ";", "import", "erjang", ".", "ErlangError", ";", "import", "erjang", ".", "NotImplemented", ";", "import", "erjang", ".", "m", ".", "erlang", ".", "ErlPort", ";", "public", "class", "EExecDriverTask", "extends", "EDriverTask", "{", "private", "Process", "process", ";", "private", "DataOutputStream", "out", ";", "private", "InputStream", "in", ";", "private", "DataInputStream", "err", ";", "private", "ETuple2", "name", ";", "private", "EObject", "command", ";", "public", "EObject", "getName", "(", ")", "{", "return", "command", ";", "}", "public", "EExecDriverTask", "(", "EProc", "owner", ",", "ETuple2", "name", ",", "EObject", "command", ",", "EObject", "portSetting", ")", "{", "super", "(", "owner", ".", "self_handle", "(", ")", ",", "new", "ExecDriverInstance", "(", "name", ")", ")", ";", "this", ".", "command", "=", "command", ";", "ESeq", "es", "=", "name", ".", "elem2", ".", "testString", "(", ")", ";", "if", "(", "es", "==", "null", ")", "{", "ECons", "cons", ";", "EAtom", "am", ";", "if", "(", "(", "cons", "=", "name", ".", "elem2", ".", "testCons", "(", ")", ")", "!=", "null", ")", "{", "es", "=", "EString", ".", "make", "(", "cons", ")", ";", "}", "else", "if", "(", "(", "am", "=", "name", ".", "elem2", ".", "testAtom", "(", ")", ")", "!=", "null", ")", "{", "es", "=", "EString", ".", "fromString", "(", "am", ".", "getName", "(", ")", ")", ";", "}", "else", "{", "throw", "ERT", ".", "badarg", "(", "name", ",", "portSetting", ")", ";", "}", "}", "String", "full_cmd", "=", "es", ".", "stringValue", "(", ")", ";", "String", "[", "]", "cmd", ";", "if", "(", "name", ".", "elem1", "==", "ErlPort", ".", "am_spawn", ")", "{", "cmd", "=", "full_cmd", ".", "split", "(", "\"", "+\"", ")", ";", "}", "else", "{", "cmd", "=", "new", "String", "[", "]", "{", "full_cmd", "}", ";", "}", "parseOptions", "(", "cmd", ",", "portSetting", ")", ";", "File", "f", "=", "ERT", ".", "newFile", "(", "cmd", "[", "0", "]", ")", ";", "if", "(", "f", ".", "exists", "(", ")", "&&", "f", ".", "canExecute", "(", ")", ")", "{", "}", "else", "if", "(", "f", ".", "isAbsolute", "(", ")", ")", "{", "throw", "new", "ErlangError", "(", "EAtom", ".", "intern", "(", "\"enoent\"", ")", ")", ";", "}", "else", "{", "String", "cmd_path", "=", "env", ".", "get", "(", "\"PATH\"", ")", ";", "if", "(", "cmd_path", "!=", "null", ")", "{", "for", "(", "String", "elm", ":", "cmd_path", ".", "split", "(", "File", ".", "pathSeparator", ")", ")", "{", "File", "dir", "=", "ERT", ".", "newFile", "(", "elm", ")", ";", "f", "=", "new", "File", "(", "dir", ",", "cmd", "[", "0", "]", ")", ";", "if", "(", "f", ".", "exists", "(", ")", ")", "{", "cmd", "[", "0", "]", "=", "f", ".", "getAbsolutePath", "(", ")", ";", "break", ";", "}", "else", "{", "f", "=", "null", ";", "}", "}", "}", "}", "if", "(", "f", "==", "null", ")", "{", "throw", "new", "ErlangError", "(", "EAtom", ".", "intern", "(", "\"enoent\"", ")", ")", ";", "}", "if", "(", "!", "f", ".", "canExecute", "(", ")", ")", "{", "throw", "new", "ErlangError", "(", "EAtom", ".", "intern", "(", "\"eaccess\"", ")", ")", ";", "}", "super", ".", "setupInstance", "(", ")", ";", "}", "@", "Override", "public", "String", "toString", "(", ")", "{", "return", "String", ".", "valueOf", "(", "name", ")", "+", "\"::\"", "+", "super", ".", "toString", "(", ")", ";", "}", "}", "</s>" ]
7,769
[ "<s>", "package", "erjang", ";", "import", "kilim", ".", "Pausable", ";", "public", "class", "EExternalPID", "extends", "EPID", "{", "private", "int", "id", ";", "private", "int", "serial", ";", "private", "int", "creation", ";", "public", "EExternalPID", "(", "EPeer", "peer", ",", "int", "id", ",", "int", "serial", ",", "int", "creation", ")", "{", "super", "(", "peer", ")", ";", "this", ".", "id", "=", "id", ";", "this", ".", "serial", "=", "serial", ";", "this", ".", "creation", "=", "creation", ";", "}", "protected", "int", "serial", "(", ")", "{", "return", "serial", ";", "}", "protected", "int", "id", "(", ")", "{", "return", "id", ";", "}", "protected", "int", "creation", "(", ")", "{", "return", "creation", ";", "}", "EPeer", "peer", "(", ")", "{", "return", "(", "EPeer", ")", "this", ".", "node", ";", "}", "public", "boolean", "exists", "(", ")", "{", "return", "true", ";", "}", "@", "Override", "public", "boolean", "is_alive", "(", ")", "{", "throw", "new", "erjang", ".", "NotImplemented", "(", ")", ";", "}", "@", "Override", "public", "EObject", "process_info", "(", ")", "{", "throw", "new", "erjang", ".", "NotImplemented", "(", ")", ";", "}", "@", "Override", "public", "EObject", "process_info", "(", "EObject", "spec", ")", "{", "throw", "new", "erjang", ".", "NotImplemented", "(", ")", ";", "}", "@", "Override", "public", "void", "set_group_leader", "(", "EPID", "gl", ")", "{", "throw", "new", "erjang", ".", "NotImplemented", "(", ")", ";", "}", "@", "Override", "public", "void", "exit_signal", "(", "EHandle", "from_pid", ",", "EObject", "reason", ",", "boolean", "exitToSender", ")", "throws", "Pausable", "{", "peer", "(", ")", ".", "dsig_exit", "(", "from_pid", ",", "this", ",", "reason", ")", ";", "}", "@", "Override", "public", "boolean", "add_monitor", "(", "EHandle", "from_pid", ",", "ERef", "ref", ")", "throws", "Pausable", "{", "peer", "(", ")", ".", "dsig_monitor", "(", "from_pid", ",", "this", ",", "ref", ")", ";", "return", "true", ";", "}", "@", "Override", "public", "boolean", "link_oneway", "(", "EHandle", "other", ")", "throws", "Pausable", "{", "peer", "(", ")", ".", "dsig_link", "(", "other", ",", "this", ")", ";", "return", "true", ";", "}", "@", "Override", "public", "void", "unlink_oneway", "(", "EHandle", "other", ")", "throws", "Pausable", "{", "peer", "(", ")", ".", "dsig_unlink", "(", "other", ",", "this", ")", ";", "}", "@", "Override", "public", "void", "remove_monitor", "(", "EHandle", "sender", ",", "ERef", "ref", ",", "boolean", "flush", ")", "throws", "Pausable", "{", "peer", "(", ")", ".", "dsig_demonitor", "(", "sender", ",", "ref", ",", "this", ")", ";", "}", "@", "Override", "public", "int", "send", "(", "EHandle", "sender", ",", "EObject", "msg", ")", "throws", "Pausable", "{", "return", "peer", "(", ")", ".", "dsig_send", "(", "sender", ",", "this", ",", "msg", ")", ";", "}", "@", "Override", "public", "void", "send_monitor_exit", "(", "EHandle", "from", ",", "ERef", "ref", ",", "EObject", "reason", ")", "throws", "Pausable", "{", "peer", "(", ")", ".", "dsig_send_monitor_exit", "(", "from", ",", "this", ",", "ref", ",", "reason", ")", ";", "}", "@", "Override", "public", "void", "sendb", "(", "EObject", "msg", ")", "{", "throw", "new", "erjang", ".", "NotImplemented", "(", ")", ";", "}", "}", "</s>" ]
7,770
[ "<s>", "package", "erjang", ";", "import", "java", ".", "nio", ".", "ByteBuffer", ";", "public", "class", "IOListBuilder", "{", "byte", "[", "]", "data", "=", "new", "byte", "[", "10", "]", ";", "int", "pos", "=", "10", ";", "int", "len", "=", "0", ";", "ByteBuffer", "toByteBuffer", "(", ")", "{", "return", "ByteBuffer", ".", "wrap", "(", "data", ",", "pos", ",", "len", ")", ";", "}", "void", "prepend", "(", "byte", "value", ")", "{", "if", "(", "pos", "==", "0", ")", "{", "byte", "[", "]", "new_data", "=", "new", "byte", "[", "len", "*", "2", "]", ";", "System", ".", "arraycopy", "(", "data", ",", "0", ",", "new_data", ",", "len", ",", "len", ")", ";", "data", "=", "new_data", ";", "pos", "=", "len", ";", "}", "data", "[", "--", "pos", "]", "=", "value", ";", "len", "+=", "1", ";", "}", "}", "</s>" ]
7,771
[ "<s>", "package", "erjang", ";", "import", "java", ".", "io", ".", "File", ";", "import", "java", ".", "io", ".", "IOException", ";", "import", "java", ".", "io", ".", "InputStream", ";", "import", "java", ".", "io", ".", "OutputStream", ";", "import", "java", ".", "io", ".", "PrintStream", ";", "import", "java", ".", "io", ".", "PrintWriter", ";", "import", "java", ".", "io", ".", "StringWriter", ";", "import", "java", ".", "lang", ".", "reflect", ".", "Method", ";", "import", "java", ".", "math", ".", "BigInteger", ";", "import", "java", ".", "nio", ".", "ByteBuffer", ";", "import", "java", ".", "util", ".", "Map", ";", "import", "java", ".", "util", ".", "concurrent", ".", "ConcurrentHashMap", ";", "import", "java", ".", "util", ".", "logging", ".", "Level", ";", "import", "java", ".", "util", ".", "logging", ".", "Logger", ";", "import", "kilim", ".", "Pausable", ";", "import", "kilim", ".", "Task", ";", "import", "erjang", ".", "driver", ".", "Drivers", ";", "import", "erjang", ".", "driver", ".", "EAsync", ";", "import", "erjang", ".", "driver", ".", "EDriver", ";", "import", "erjang", ".", "driver", ".", "EDriverTask", ";", "import", "erjang", ".", "driver", ".", "efile", ".", "Posix", ";", "import", "erjang", ".", "m", ".", "java", ".", "JavaObject", ";", "@", "Module", "(", "value", "=", "\"erlang\"", ")", "public", "class", "ERT", "{", "public", "static", "Logger", "log", "=", "Logger", ".", "getLogger", "(", "\"erjang\"", ")", ";", "static", "Logger", "ipclog", "=", "Logger", ".", "getLogger", "(", "\"erjang.ipc\"", ")", ";", "public", "static", "EAtom", "am_badsig", "=", "EAtom", ".", "intern", "(", "\"badsig\"", ")", ";", "public", "static", "EObject", "raise", "(", "EObject", "trace", ",", "EObject", "value", ")", "throws", "ErlangException", "{", "log", ".", "warning", "(", "\"raise", "\"", "+", "trace", ")", ";", "if", "(", "trace", "instanceof", "ErlangException", ".", "ExceptionAsObject", ")", "{", "ErlangException", "etrace", "=", "(", "(", "ErlangException", ".", "ExceptionAsObject", ")", "trace", ")", ".", "getException", "(", ")", ";", "EAtom", "clazz", "=", "etrace", ".", "getExClass", "(", ")", ";", "ESeq", "traz", "=", "etrace", ".", "getLazyTrace", "(", ")", ";", "throw", "new", "ErlangRaise", "(", "clazz", ",", "value", ",", "traz", ")", ";", "}", "else", "if", "(", "trace", "==", "am_exit", "||", "trace", "==", "am_error", "||", "trace", "==", "am_throw", ")", "{", "log", ".", "warning", "(", "\"\"", ")", ";", "}", "Throwable", "error", "=", "new", "Throwable", "(", "\"\"", "+", "value", "+", "\",", "\"", "+", "trace", "+", "\")\"", ")", ";", "log", ".", "log", "(", "Level", ".", "WARNING", ",", "\"\"", "+", "value", "+", "\",", "\"", "+", "trace", "+", "\")\"", ",", "error", ")", ";", "return", "am_badarg", ";", "}", "public", "static", "final", "EAtom", "am_badarg", "=", "EAtom", ".", "intern", "(", "\"badarg\"", ")", ";", "public", "static", "final", "EAtom", "am_notsup", "=", "EAtom", ".", "intern", "(", "\"notsup\"", ")", ";", "public", "static", "final", "EAtom", "AM_BADMATCH", "=", "EAtom", ".", "intern", "(", "\"badmatch\"", ")", ";", "public", "static", "final", "EAtom", "AM_BADARITH", "=", "EAtom", ".", "intern", "(", "\"badarith\"", ")", ";", "public", "static", "final", "EAtom", "am_module", "=", "EAtom", ".", "intern", "(", "\"module\"", ")", ";", "public", "static", "ECons", "cons", "(", "EObject", "h", ",", "EObject", "t", ")", "{", "return", "t", ".", "cons", "(", "h", ")", ";", "}", "public", "static", "ErlangError", "badarg", "(", ")", "{", "throw", "new", "ErlangError", "(", "am_badarg", ")", ";", "}", "public", "static", "ErlangError", "notsup", "(", ")", "{", "throw", "new", "ErlangError", "(", "am_notsup", ")", ";", "}", "public", "static", "ErlangError", "badarg", "(", "EObject", "...", "args", ")", "{", "throw", "new", "ErlangError", "(", "am_badarg", ",", "args", ")", ";", "}", "public", "static", "ErlangError", "badarg", "(", "EObject", "o1", ",", "EObject", "o2", ")", "throws", "ErlangError", "{", "throw", "new", "ErlangError", "(", "am_badarg", ",", "NIL", ".", "cons", "(", "o2", ")", ".", "cons", "(", "o1", ")", ")", ";", "}", "public", "static", "ErlangError", "badarith", "(", "EObject", "...", "args", ")", "{", "throw", "new", "ErlangError", "(", "AM_BADARITH", ",", "args", ")", ";", "}", "public", "static", "ErlangError", "badarith", "(", "EObject", "o1", ",", "EObject", "o2", ")", "throws", "ErlangError", "{", "throw", "new", "ErlangError", "(", "AM_BADARITH", ",", "NIL", ".", "cons", "(", "o2", ")", ".", "cons", "(", "o1", ")", ")", ";", "}", "public", "static", "ErlangError", "badarith", "(", "int", "o1", ",", "EObject", "o2", ")", "{", "throw", "new", "ErlangError", "(", "AM_BADARITH", ",", "NIL", ".", "cons", "(", "o2", ")", ".", "cons", "(", "o1", ")", ")", ";", "}", "public", "static", "ErlangError", "badarith", "(", "EObject", "o1", ",", "int", "o2", ")", "{", "throw", "new", "ErlangError", "(", "AM_BADARITH", ",", "NIL", ".", "cons", "(", "o2", ")", ".", "cons", "(", "o1", ")", ")", ";", "}", "public", "static", "ErlangError", "badarith", "(", "double", "o1", ",", "EObject", "o2", ")", "{", "throw", "new", "ErlangError", "(", "AM_BADARITH", ",", "NIL", ".", "cons", "(", "o2", ")", ".", "cons", "(", "o1", ")", ")", ";", "}", "public", "static", "ErlangError", "badarith", "(", "EObject", "o1", ",", "double", "o2", ")", "{", "throw", "new", "ErlangError", "(", "AM_BADARITH", ",", "NIL", ".", "cons", "(", "o2", ")", ".", "cons", "(", "o1", ")", ")", ";", "}", "public", "static", "ErlangError", "badarith", "(", "BigInteger", "o1", ",", "EObject", "o2", ")", "{", "throw", "new", "ErlangError", "(", "AM_BADARITH", ",", "NIL", ".", "cons", "(", "o2", ")", ".", "cons", "(", "o1", ")", ")", ";", "}", "public", "static", "final", "EAtom", "TRUE", "=", "EAtom", ".", "intern", "(", "\"true\"", ")", ";", "public", "static", "final", "EAtom", "FALSE", "=", "EAtom", ".", "intern", "(", "\"false\"", ")", ";", "public", "static", "boolean", "eq", "(", "EObject", "o1", ",", "EObject", "o2", ")", "{", "return", "o1", "==", "null", "?", "o2", "==", "null", ":", "o1", ".", "equals", "(", "o2", ")", ";", "}", "public", "static", "boolean", "eq", "(", "EAtom", "o1", ",", "EAtom", "o2", ")", "{", "return", "o1", "==", "o2", ";", "}", "public", "static", "EAtom", "as_atom_or_null", "(", "EObject", "o", ")", "{", "return", "o", "==", "null", "?", "null", ":", "o", ".", "testAtom", "(", ")", ";", "}", "public", "static", "ECons", "as_nonempty_list_or_null", "(", "EObject", "o", ")", "{", "return", "o", "==", "null", "?", "null", ":", "o", ".", "testNonEmptyList", "(", ")", ";", "}", "public", "static", "ENil", "as_nil_or_null", "(", "EObject", "o", ")", "{", "return", "o", "==", "null", "?", "ERT", ".", "NIL", ":", "o", ".", "testNil", "(", ")", ";", "}", "public", "static", "EDouble", "as_float_or_null", "(", "EObject", "o", ")", "{", "return", "o", "==", "null", "?", "null", ":", "o", ".", "testFloat", "(", ")", ";", "}", "public", "static", "EPID", "loopkup_pid", "(", "ESeq", "name", ")", "{", "throw", "new", "NotImplemented", "(", ")", ";", "}", "static", "private", "final", "Method", "definer", ";", "static", "{", "try", "{", "definer", "=", "ClassLoader", ".", "class", ".", "getDeclaredMethod", "(", "\"defineClass\"", ",", "new", "Class", "[", "]", "{", "String", ".", "class", ",", "byte", "[", "]", ".", "class", ",", "int", ".", "class", ",", "int", ".", "class", "}", ")", ";", "definer", ".", "setAccessible", "(", "true", ")", ";", "}", "catch", "(", "Exception", "e", ")", "{", "throw", "new", "ErlangError", "(", "e", ")", ";", "}", "}", "@", "SuppressWarnings", "(", "\"unchecked\"", ")", "public", "static", "<", "T", ">", "Class", "<", "?", "extends", "T", ">", "defineClass", "(", "ClassLoader", "classLoader", ",", "String", "name", ",", "byte", "[", "]", "data", ")", "{", "Class", "<", "?", "extends", "T", ">", "res", ";", "try", "{", "res", "=", "(", "Class", "<", "?", "extends", "T", ">", ")", "definer", ".", "invoke", "(", "classLoader", ",", "name", ".", "replace", "(", "'/'", ",", "'.'", ")", ",", "data", ",", "0", ",", "data", ".", "length", ")", ";", "}", "catch", "(", "Exception", "e", ")", "{", "throw", "new", "RuntimeException", "(", "e", ")", ";", "}", "if", "(", "!", "name", ".", "equals", "(", "res", ".", "getName", "(", ")", ")", ")", "{", "throw", "new", "Error", "(", ")", ";", "}", "return", "res", ";", "}", "public", "static", "ESmall", "box", "(", "int", "v", ")", "{", "return", "ESmall", ".", "make", "(", "v", ")", ";", "}", "public", "static", "EInteger", "box2", "(", "long", "longVal", ")", "{", "int", "intVal", "=", "(", "int", ")", "longVal", ";", "if", "(", "longVal", "==", "(", "long", ")", "intVal", ")", "{", "return", "ESmall", ".", "make", "(", "intVal", ")", ";", "}", "else", "{", "return", "new", "EBig", "(", "longVal", ")", ";", "}", "}", "public", "static", "EInteger", "box", "(", "long", "longVal", ")", "{", "int", "intVal", "=", "(", "int", ")", "longVal", ";", "if", "(", "intVal", "==", "longVal", ")", "{", "return", "ESmall", ".", "make", "(", "intVal", ")", ";", "}", "else", "{", "return", "new", "EBig", "(", "longVal", ")", ";", "}", "}", "public", "static", "EDouble", "box", "(", "double", "doubleVal", ")", "{", "return", "new", "EDouble", "(", "doubleVal", ")", ";", "}", "static", "BigInteger", "INT_MIN_AS_BIG", "=", "BigInteger", ".", "valueOf", "(", "Integer", ".", "MIN_VALUE", ")", ";", "static", "BigInteger", "INT_MAX_AS_BIG", "=", "BigInteger", ".", "valueOf", "(", "Integer", ".", "MAX_VALUE", ")", ";", "private", "static", "final", "ENode", "localNode", "=", "new", "ENode", "(", ")", ";", "public", "static", "EInteger", "box", "(", "BigInteger", "res", ")", "{", "if", "(", "res", ".", "compareTo", "(", "INT_MIN_AS_BIG", ")", "<", "0", ")", "return", "new", "EBig", "(", "res", ")", ";", "if", "(", "res", ".", "compareTo", "(", "INT_MAX_AS_BIG", ")", ">", "0", ")", "return", "new", "EBig", "(", "res", ")", ";", "return", "ESmall", ".", "make", "(", "res", ".", "intValue", "(", ")", ")", ";", "}", "public", "static", "EAtom", "box", "(", "boolean", "bool", ")", "{", "return", "bool", "?", "TRUE", ":", "FALSE", ";", "}", "public", "static", "EAtom", "guard", "(", "boolean", "bool", ")", "{", "return", "bool", "?", "TRUE", ":", "FALSE", ";", "}", "public", "static", "final", "ENil", "NIL", "=", "new", "ENil", "(", ")", ";", "public", "static", "final", "EAtom", "am_EXIT", "=", "EAtom", ".", "intern", "(", "\"EXIT\"", ")", ";", "public", "static", "final", "EAtom", "IGNORED", "=", "EAtom", ".", "intern", "(", "\"ignored\"", ")", ";", "private", "static", "final", "EAtom", "am_badmatch", "=", "EAtom", ".", "intern", "(", "\"badmatch\"", ")", ";", "private", "static", "final", "EAtom", "am_case_clause", "=", "EAtom", ".", "intern", "(", "\"case_clause\"", ")", ";", "public", "static", "final", "EAtom", "am_undefined", "=", "EAtom", ".", "intern", "(", "\"undefined\"", ")", ";", "public", "static", "final", "EObject", "am_receive_clause", "=", "EAtom", ".", "intern", "(", "\"\"", ")", ";", "public", "static", "final", "EObject", "AM_NOT_IMPLEMENTED", "=", "EAtom", ".", "intern", "(", "\"\"", ")", ";", "public", "static", "final", "EAtom", "AM_TIMEOUT", "=", "EAtom", ".", "intern", "(", "\"timeout\"", ")", ";", "public", "static", "final", "EAtom", "am_try_case_clause", "=", "EAtom", ".", "intern", "(", "\"\"", ")", ";", "public", "static", "final", "EAtom", "am_if_clause", "=", "EAtom", ".", "intern", "(", "\"if_clause\"", ")", ";", "public", "static", "final", "EBinary", "EMPTY_BINARY", "=", "new", "EBinary", "(", "new", "byte", "[", "0", "]", ")", ";", "public", "static", "final", "ByteBuffer", "[", "]", "EMPTY_BYTEBUFFER_ARR", "=", "new", "ByteBuffer", "[", "0", "]", ";", "public", "static", "final", "ByteBuffer", "EMPTY_BYTEBUFFER", "=", "ByteBuffer", ".", "allocate", "(", "0", ")", ";", "public", "static", "final", "EAtom", "am_infinity", "=", "EAtom", ".", "intern", "(", "\"infinity\"", ")", ";", "public", "static", "final", "EAtom", "am_noproc", "=", "EAtom", ".", "intern", "(", "\"noproc\"", ")", ";", "public", "static", "final", "EAtom", "am_error", "=", "EAtom", ".", "intern", "(", "\"error\"", ")", ";", "public", "static", "final", "EAtom", "am_exit", "=", "EAtom", ".", "intern", "(", "\"exit\"", ")", ";", "public", "static", "final", "EAtom", "am_throw", "=", "EAtom", ".", "intern", "(", "\"throw\"", ")", ";", "public", "static", "final", "EAtom", "am_badfile", "=", "EAtom", ".", "intern", "(", "\"badfile\"", ")", ";", "public", "static", "final", "EAtom", "am_value", "=", "EAtom", ".", "intern", "(", "\"value\"", ")", ";", "public", "static", "final", "EAtom", "am_timeout", "=", "EAtom", ".", "intern", "(", "\"timeout\"", ")", ";", "public", "static", "final", "EAtom", "am_function_clause", "=", "EAtom", ".", "intern", "(", "\"\"", ")", ";", "public", "static", "final", "EAtom", "am_ok", "=", "EAtom", ".", "intern", "(", "\"ok\"", ")", ";", "public", "static", "final", "EAtom", "am_noconnect", "=", "EAtom", ".", "intern", "(", "\"noconnect\"", ")", ";", "public", "static", "final", "EAtom", "am_latin1", "=", "EAtom", ".", "intern", "(", "\"latin1\"", ")", ";", "public", "static", "final", "EAtom", "am_utf8", "=", "EAtom", ".", "intern", "(", "\"utf8\"", ")", ";", "public", "static", "final", "EAtom", "am_unicode", "=", "EAtom", ".", "intern", "(", "\"unicode\"", ")", ";", "private", "static", "final", "EAtom", "am_init", "=", "EAtom", ".", "intern", "(", "\"init\"", ")", ";", "private", "static", "final", "EAtom", "am_stop", "=", "EAtom", ".", "intern", "(", "\"stop\"", ")", ";", "protected", "static", "final", "EAtom", "am_new", "=", "EAtom", ".", "intern", "(", "\"new\"", ")", ";", "public", "static", "EBitStringBuilder", "bs_init", "(", "int", "size", ",", "int", "flags", ")", "{", "if", "(", "size", "<", "0", ")", "throw", "ERT", ".", "badarg", "(", ")", ";", "return", "new", "EBitStringBuilder", "(", "size", ",", "flags", ")", ";", "}", "public", "static", "EBitStringBuilder", "bs_initBits", "(", "int", "size", ",", "int", "flags", ")", "{", "if", "(", "size", "<", "0", ")", "throw", "ERT", ".", "badarg", "(", ")", ";", "return", "new", "EBitStringBuilder", "(", "size", "/", "8", ",", "size", "%", "8", ",", "flags", ")", ";", "}", "public", "static", "String", "describe_exception", "(", "Throwable", "e", ")", "{", "StringWriter", "sw", "=", "new", "StringWriter", "(", ")", ";", "PrintWriter", "pw", "=", "new", "PrintWriter", "(", "sw", ")", ";", "e", ".", "printStackTrace", "(", "pw", ")", ";", "pw", ".", "close", "(", ")", ";", "return", "sw", ".", "toString", "(", ")", ";", "}", "public", "static", "void", "test_fun", "(", "EObject", "orig", ",", "EFun", "fun", ")", "{", "if", "(", "fun", "==", "null", ")", "{", "if", "(", "(", "orig", ".", "testFunction", "(", ")", ")", "!=", "null", ")", "{", "throw", "new", "ErlangError", "(", "new", "ETuple2", "(", "am_badarity", ",", "new", "ETuple2", "(", "orig", ",", "NIL", ")", ")", ")", ";", "}", "else", "{", "throw", "new", "ErlangError", "(", "am_badfun", ",", "orig", ")", ";", "}", "}", "}", "static", "EInteger", "max_send_time", "=", "ERT", ".", "box", "(", "4294967295L", ")", ";", "static", "ESmall", "zero", "=", "ERT", ".", "box", "(", "0", ")", ";", "public", "static", "final", "boolean", "gt", "(", "EInteger", "v1", ",", "EInteger", "v2", ")", "{", "return", "v1", ".", "erlangCompareTo", "(", "v2", ")", ">", "0", ";", "}", "public", "static", "final", "boolean", "lt", "(", "EInteger", "v1", ",", "EInteger", "v2", ")", "{", "return", "v1", ".", "erlangCompareTo", "(", "v2", ")", "<", "0", ";", "}", "@", "BIF", "public", "static", "EObject", "cancel_timer", "(", "EObject", "ref", ")", "{", "ERef", "timer_ref", "=", "ref", ".", "testReference", "(", ")", ";", "if", "(", "timer_ref", "==", "null", ")", "throw", "ERT", ".", "badarg", "(", ")", ";", "long", "time_left", "=", "ETimerTask", ".", "cancel", "(", "timer_ref", ")", ";", "if", "(", "time_left", ">", "0", ")", "{", "return", "ERT", ".", "box", "(", "time_left", ")", ";", "}", "else", "{", "return", "ERT", ".", "FALSE", ";", "}", "}", "@", "BIF", "public", "static", "EObject", "read_timer", "(", "EObject", "ref", ")", "{", "ERef", "timer_ref", "=", "ref", ".", "testReference", "(", ")", ";", "if", "(", "timer_ref", "==", "null", ")", "throw", "ERT", ".", "badarg", "(", ")", ";", "long", "time_left", "=", "ETimerTask", ".", "read_timer", "(", "timer_ref", ")", ";", "if", "(", "time_left", ">", "0", ")", "{", "return", "ERT", ".", "box", "(", "time_left", ")", ";", "}", "else", "{", "return", "ERT", ".", "FALSE", ";", "}", "}", "@", "BIF", "public", "static", "EObject", "send_after", "(", "final", "EProc", "proc", ",", "EObject", "time", ",", "final", "EObject", "rcv", ",", "final", "EObject", "msg", ")", "{", "EInteger", "when", "=", "time", ".", "testInteger", "(", ")", ";", "final", "EInternalPID", "rcv_pid", "=", "rcv", ".", "testInternalPID", "(", ")", ";", "EAtom", "rcv_atom", "=", "rcv", ".", "testAtom", "(", ")", ";", "if", "(", "when", "==", "null", "||", "gt", "(", "when", ",", "max_send_time", ")", "||", "lt", "(", "when", ",", "zero", ")", "||", "(", "rcv_pid", "==", "null", "&&", "rcv_atom", "==", "null", ")", ")", "{", "throw", "ERT", ".", "badarg", "(", "time", ",", "rcv", ",", "msg", ")", ";", "}", "ETimerTask", "send_task", "=", "new", "ETimerTask", "(", "rcv_pid", ")", "{", "@", "Override", "public", "void", "on_timeout", "(", ")", "throws", "Pausable", "{", "EHandle", "p", ";", "if", "(", "(", "p", "=", "rcv", ".", "testHandle", "(", ")", ")", "!=", "null", ")", "{", "p", ".", "send", "(", "proc", ".", "self_handle", "(", ")", ",", "msg", ")", ";", "return", ";", "}", "p", "=", "register", ".", "get", "(", "rcv", ")", ";", "if", "(", "p", "!=", "null", ")", "{", "p", ".", "send", "(", "proc", ".", "self_handle", "(", ")", ",", "msg", ")", ";", "}", "}", "}", ";", "send_task", ".", "schedule", "(", "when", ".", "longValue", "(", ")", ")", ";", "return", "send_task", ".", "ref", ";", "}", "@", "BIF", "public", "static", "EObject", "start_timer", "(", "EObject", "time", ",", "final", "EObject", "rcv", ",", "final", "EObject", "msg", ")", "{", "EInteger", "when", "=", "time", ".", "testInteger", "(", ")", ";", "final", "EInternalPID", "rcv_pid", "=", "rcv", ".", "testInternalPID", "(", ")", ";", "EAtom", "rcv_atom", "=", "rcv", ".", "testAtom", "(", ")", ";", "if", "(", "when", "==", "null", "||", "gt", "(", "when", ",", "max_send_time", ")", "||", "lt", "(", "when", ",", "zero", ")", "||", "(", "rcv_pid", "==", "null", "&&", "rcv_atom", "==", "null", ")", ")", "{", "throw", "ERT", ".", "badarg", "(", "time", ",", "rcv", ",", "msg", ")", ";", "}", "ETimerTask", "send_task", "=", "new", "ETimerTask", "(", "rcv_pid", ")", "{", "@", "Override", "public", "void", "on_timeout", "(", ")", "throws", "Pausable", "{", "ETuple3", "timeout_msg", "=", "new", "ETuple3", "(", ")", ";", "timeout_msg", ".", "elem1", "=", "am_timeout", ";", "timeout_msg", ".", "elem2", "=", "this", ".", "ref", ";", "timeout_msg", ".", "elem3", "=", "msg", ";", "EHandle", "p", ";", "if", "(", "(", "p", "=", "rcv", ".", "testHandle", "(", ")", ")", "!=", "null", ")", "{", "p", ".", "sendb", "(", "timeout_msg", ")", ";", "return", ";", "}", "p", "=", "register", ".", "get", "(", "rcv", ")", ";", "if", "(", "p", "!=", "null", ")", "{", "p", ".", "sendb", "(", "timeout_msg", ")", ";", "}", "}", "}", ";", "send_task", ".", "schedule", "(", "when", ".", "longValue", "(", ")", ")", ";", "return", "send_task", ".", "ref", ";", "}", "@", "Import", "(", "module", "=", "\"erlang\"", ",", "fun", "=", "\"dsend\"", ",", "arity", "=", "2", ")", "static", "EFun", "erlang__dsend__2", ";", "@", "Import", "(", "module", "=", "\"erlang\"", ",", "fun", "=", "\"dsend\"", ",", "arity", "=", "3", ")", "static", "EFun", "erlang__dsend__3", ";", "@", "BIF", "(", "name", "=", "\"!\"", ")", "public", "static", "EObject", "send", "(", "EProc", "proc", ",", "EObject", "pid", ",", "EObject", "msg", ")", "throws", "Pausable", "{", "proc", ".", "check_exit", "(", ")", ";", "EHandle", "p", ";", "EAtom", "reg_name", ";", "if", "(", "(", "p", "=", "pid", ".", "testHandle", "(", ")", ")", "!=", "null", ")", "{", "send_to_handle", "(", "proc", ",", "p", ",", "msg", ")", ";", "}", "else", "if", "(", "(", "reg_name", "=", "pid", ".", "testAtom", "(", ")", ")", "!=", "null", ")", "{", "send_to_locally_registered", "(", "proc", ",", "reg_name", ",", "msg", ")", ";", "}", "else", "{", "ETuple", "t", ";", "EAtom", "node_name", ";", "if", "(", "(", "t", "=", "pid", ".", "testTuple", "(", ")", ")", "!=", "null", "&&", "t", ".", "arity", "(", ")", "==", "2", "&&", "(", "reg_name", "=", "t", ".", "elm", "(", "1", ")", ".", "testAtom", "(", ")", ")", "!=", "null", "&&", "(", "node_name", "=", "t", ".", "elm", "(", "2", ")", ".", "testAtom", "(", ")", ")", "!=", "null", ")", "{", "send_to_remote", "(", "proc", ",", "t", ",", "node_name", ",", "reg_name", ",", "msg", ",", "null", ")", ";", "}", "else", "{", "ipclog", ".", "info", "(", "\"\"", "+", "pid", "+", "\"", "failed.\"", ")", ";", "throw", "badarg", "(", "pid", ",", "msg", ")", ";", "}", "}", "return", "msg", ";", "}", "@", "BIF", "public", "static", "EObject", "send", "(", "EProc", "proc", ",", "final", "EObject", "pid", ",", "final", "EObject", "msg", ",", "EObject", "options", ")", "throws", "Pausable", "{", "proc", ".", "check_exit", "(", ")", ";", "EHandle", "handle", ";", "EAtom", "reg_name", ";", "if", "(", "(", "handle", "=", "pid", ".", "testHandle", "(", ")", ")", "!=", "null", ")", "{", "send_to_handle", "(", "proc", ",", "handle", ",", "msg", ")", ";", "return", "am_ok", ";", "}", "else", "if", "(", "(", "reg_name", "=", "pid", ".", "testAtom", "(", ")", ")", "!=", "null", ")", "{", "boolean", "ok", "=", "send_to_locally_registered", "(", "proc", ",", "reg_name", ",", "msg", ")", ";", "if", "(", "ok", ")", "return", "am_ok", ";", "else", "throw", "badarg", "(", "pid", ",", "msg", ")", ";", "}", "else", "{", "ETuple", "t", ";", "EAtom", "node_name", ";", "if", "(", "(", "t", "=", "pid", ".", "testTuple", "(", ")", ")", "!=", "null", "&&", "t", ".", "arity", "(", ")", "==", "2", "&&", "(", "reg_name", "=", "t", ".", "elm", "(", "1", ")", ".", "testAtom", "(", ")", ")", "!=", "null", "&&", "(", "node_name", "=", "t", ".", "elm", "(", "2", ")", ".", "testAtom", "(", ")", ")", "!=", "null", ")", "{", "return", "send_to_remote", "(", "proc", ",", "t", ",", "node_name", ",", "reg_name", ",", "msg", ",", "options", ")", ";", "}", "else", "{", "ipclog", ".", "info", "(", "\"\"", "+", "pid", "+", "\"", "failed.\"", ")", ";", "throw", "badarg", "(", "pid", ",", "msg", ")", ";", "}", "}", "}", "private", "static", "EObject", "send_to_remote", "(", "EProc", "proc", ",", "ETuple", "dest", ",", "EAtom", "node_name", ",", "EAtom", "reg_name", ",", "EObject", "msg", ",", "EObject", "options", ")", "throws", "Pausable", "{", "if", "(", "node_name", "==", "getLocalNode", "(", ")", ".", "node", ")", "{", "send_to_locally_registered", "(", "proc", ",", "reg_name", ",", "msg", ")", ";", "return", "am_ok", ";", "}", "else", "{", "if", "(", "ipclog", ".", "isLoggable", "(", "Level", ".", "FINE", ")", ")", "{", "ipclog", ".", "fine", "(", "\"sending", "msg", "\"", "+", "dest", "+", "\"", "!", "\"", "+", "msg", ")", ";", "}", "EAbstractNode", "node", "=", "EPeer", ".", "get", "(", "node_name", ")", ";", "if", "(", "node", "==", "null", ")", "{", "EObject", "[", "]", "args", "=", "(", "options", "!=", "null", "?", "new", "EObject", "[", "]", "{", "dest", ",", "msg", ",", "options", "}", ":", "new", "EObject", "[", "]", "{", "dest", ",", "msg", "}", ")", ";", "return", "erlang__dsend__3", ".", "invoke", "(", "proc", ",", "args", ")", ";", "}", "else", "{", "node", ".", "dsig_reg_send", "(", "proc", ".", "self_handle", "(", ")", ",", "reg_name", ",", "msg", ")", ";", "return", "am_ok", ";", "}", "}", "}", "private", "static", "boolean", "send_to_locally_registered", "(", "EProc", "proc", ",", "EAtom", "name", ",", "EObject", "msg", ")", "throws", "Pausable", "{", "EHandle", "handle", ";", "if", "(", "(", "handle", "=", "register", ".", "get", "(", "name", ")", ")", "!=", "null", ")", "{", "send_to_handle", "(", "proc", ",", "handle", ",", "msg", ")", ";", "return", "true", ";", "}", "else", "return", "false", ";", "}", "private", "static", "void", "send_to_handle", "(", "EProc", "proc", ",", "EHandle", "handle", ",", "EObject", "msg", ")", "throws", "Pausable", "{", "proc", ".", "reds", "+=", "handle", ".", "send", "(", "proc", ".", "self_handle", "(", ")", ",", "msg", ")", ";", "if", "(", "proc", ".", "reds", ">", "1000", ")", "{", "proc", ".", "reds", "=", "0", ";", "Task", ".", "yield", "(", ")", ";", "}", "}", "public", "static", "ENode", "getLocalNode", "(", ")", "{", "return", "localNode", ";", "}", "static", "EAtom", "am_undef", "=", "EAtom", ".", "intern", "(", "\"undef\"", ")", ";", "public", "static", "ErlangException", "undef", "(", "FunID", "fun", ",", "EObject", "...", "args", ")", "{", "throw", "new", "ErlangError", "(", "am_undef", ",", "args", ")", ";", "}", "public", "static", "EFun", "resolve_fun", "(", "EObject", "mod", ",", "EObject", "fun", ",", "int", "arity", ")", "{", "EAtom", "f", "=", "fun", ".", "testAtom", "(", ")", ";", "if", "(", "f", "==", "null", ")", "{", "throw", "ERT", ".", "badarg", "(", "mod", ",", "fun", ",", "ESmall", ".", "make", "(", "arity", ")", ")", ";", "}", "JavaObject", "jo", ";", "if", "(", "(", "jo", "=", "mod", ".", "testJavaObject", "(", ")", ")", "!=", "null", ")", "{", "return", "jo", ".", "resolve_fun", "(", "f", ",", "arity", ")", ";", "}", "EAtom", "m", "=", "mod", ".", "testAtom", "(", ")", ";", "if", "(", "m", "==", "null", ")", "{", "final", "ETuple", "tup", ";", "EAtom", "pmod", ";", "if", "(", "(", "tup", "=", "mod", ".", "testTuple", "(", ")", ")", "!=", "null", "&&", "tup", ".", "arity", "(", ")", ">", "0", "&&", "(", "pmod", "=", "tup", ".", "elm", "(", "1", ")", ".", "testAtom", "(", ")", ")", "!=", "null", ")", "{", "final", "EFun", "pfun", "=", "EModuleManager", ".", "resolve", "(", "new", "FunID", "(", "pmod", ",", "f", ",", "arity", "+", "1", ")", ")", ";", "return", "EFun", ".", "get_fun_with_handler", "(", "pmod", ".", "toString", "(", ")", ",", "f", ".", "toString", "(", ")", ",", "arity", ",", "new", "EFunHandler", "(", ")", "{", "@", "Override", "public", "EObject", "invoke", "(", "EProc", "proc", ",", "EObject", "[", "]", "args", ")", "throws", "Pausable", "{", "EObject", "[", "]", "real_args", "=", "new", "EObject", "[", "args", ".", "length", "+", "1", "]", ";", "System", ".", "arraycopy", "(", "args", ",", "0", ",", "real_args", ",", "0", ",", "args", ".", "length", ")", ";", "real_args", "[", "args", ".", "length", "]", "=", "tup", ";", "return", "pfun", ".", "invoke", "(", "proc", ",", "real_args", ")", ";", "}", "}", ",", "ERT", ".", "class", ".", "getClassLoader", "(", ")", ")", ";", "}", "throw", "ERT", ".", "badarg", "(", "mod", ",", "fun", ",", "ESmall", ".", "make", "(", "arity", ")", ")", ";", "}", "EFun", "efun", "=", "EModuleManager", ".", "resolve", "(", "new", "FunID", "(", "m", ",", "f", ",", "arity", ")", ")", ";", "return", "efun", ";", "}", "public", "static", "EObject", "apply_list", "(", "EProc", "proc", ",", "EObject", "mod", ",", "EObject", "fun", ",", "ESeq", "seq", ",", "int", "len", ")", "throws", "Pausable", "{", "EAtom", "f", "=", "fun", ".", "testAtom", "(", ")", ";", "ESeq", "a", "=", "seq", ".", "testSeq", "(", ")", ";", "if", "(", "f", "==", "null", "||", "a", "==", "null", ")", "throw", "ERT", ".", "badarg", "(", "mod", ",", "fun", ",", "seq", ")", ";", "EFun", "efun", "=", "resolve_fun", "(", "mod", ",", "fun", ",", "len", ")", ";", "return", "efun", ".", "apply", "(", "proc", ",", "a", ")", ";", "}", "public", "static", "EObject", "apply_list_last", "(", "EProc", "proc", ",", "EObject", "mod", ",", "EObject", "fun", ",", "ESeq", "seq", ",", "int", "len", ")", "throws", "Pausable", "{", "EAtom", "f", "=", "fun", ".", "testAtom", "(", ")", ";", "ESeq", "a", "=", "seq", ".", "testSeq", "(", ")", ";", "if", "(", "f", "==", "null", "||", "a", "==", "null", ")", "throw", "ERT", ".", "badarg", "(", "mod", ",", "fun", ",", "seq", ")", ";", "EFun", "found", "=", "resolve_fun", "(", "mod", ",", "fun", ",", "len", ")", ";", "if", "(", "len", ">", "9", ")", "{", "return", "found", ".", "invoke", "(", "proc", ",", "a", ".", "toArray", "(", ")", ")", ";", "}", "proc", ".", "tail", "=", "found", ";", "a", "=", "a", ".", "reverse", "(", ")", ";", "switch", "(", "len", ")", "{", "default", ":", "throw", "new", "NotImplemented", "(", ")", ";", "case", "9", ":", "proc", ".", "arg8", "=", "a", ".", "head", "(", ")", ";", "a", "=", "a", ".", "tail", "(", ")", ";", "case", "8", ":", "proc", ".", "arg7", "=", "a", ".", "head", "(", ")", ";", "a", "=", "a", ".", "tail", "(", ")", ";", "case", "7", ":", "proc", ".", "arg6", "=", "a", ".", "head", "(", ")", ";", "a", "=", "a", ".", "tail", "(", ")", ";", "case", "6", ":", "proc", ".", "arg5", "=", "a", ".", "head", "(", ")", ";", "a", "=", "a", ".", "tail", "(", ")", ";", "case", "5", ":", "proc", ".", "arg4", "=", "a", ".", "head", "(", ")", ";", "a", "=", "a", ".", "tail", "(", ")", ";", "case", "4", ":", "proc", ".", "arg3", "=", "a", ".", "head", "(", ")", ";", "a", "=", "a", ".", "tail", "(", ")", ";", "case", "3", ":", "proc", ".", "arg2", "=", "a", ".", "head", "(", ")", ";", "a", "=", "a", ".", "tail", "(", ")", ";", "case", "2", ":", "proc", ".", "arg1", "=", "a", ".", "head", "(", ")", ";", "a", "=", "a", ".", "tail", "(", ")", ";", "case", "1", ":", "proc", ".", "arg0", "=", "a", ".", "head", "(", ")", ";", "a", "=", "a", ".", "tail", "(", ")", ";", "case", "0", ":", "}", "return", "EProc", ".", "TAIL_MARKER", ";", "}", "static", "Map", "<", "EAtom", ",", "EHandle", ">", "register", "=", "new", "ConcurrentHashMap", "<", "EAtom", ",", "EHandle", ">", "(", ")", ";", "public", "static", "void", "register", "(", "EAtom", "aname", ",", "EHandle", "handle", ")", "{", "register", ".", "put", "(", "aname", ",", "handle", ")", ";", "handle", ".", "setName", "(", "aname", ")", ";", "}", "public", "static", "boolean", "unregister", "(", "EAtom", "aname", ")", "{", "EHandle", "val", "=", "register", ".", "remove", "(", "aname", ")", ";", "if", "(", "val", "!=", "null", ")", "{", "val", ".", "setName", "(", "null", ")", ";", "return", "true", ";", "}", "else", "{", "return", "false", ";", "}", "}", "public", "static", "EObject", "whereis", "(", "EObject", "regname", ")", "{", "EObject", "result", "=", "register", ".", "get", "(", "regname", ")", ";", "if", "(", "result", "==", "null", ")", "{", "return", "am_undefined", ";", "}", "else", "{", "return", "result", ";", "}", "}", "public", "static", "EObject", "badmatch", "(", "EObject", "val", ")", "{", "throw", "new", "ErlangError", "(", "new", "ETuple2", "(", "am_badmatch", ",", "val", ")", ")", ";", "}", "public", "static", "void", "paranoiaCheck", "(", "final", "EObject", "e", ",", "String", "details", ")", "{", "if", "(", "e", "==", "null", ")", "throw", "new", "Error", "(", "\"\"", "+", "details", ")", ";", "}", "public", "static", "EObject", "decode_exception2", "(", "final", "ErlangException", "e", ")", "{", "return", "e", ".", "getCatchValue", "(", ")", ";", "}", "public", "static", "ETuple3", "decode_exception3", "(", "final", "ErlangException", "e", ")", "{", "return", "e", ".", "getTryValue", "(", ")", ";", "}", "public", "static", "EObject", "case_end", "(", "EObject", "val", ")", "{", "throw", "new", "ErlangError", "(", "ETuple", ".", "make", "(", "am_case_clause", ",", "val", ")", ")", ";", "}", "public", "static", "EObject", "if_end", "(", ")", "{", "throw", "new", "ErlangError", "(", "am_if_clause", ")", ";", "}", "public", "static", "EObject", "try_case_end", "(", "EObject", "val", ")", "{", "throw", "new", "ErlangError", "(", "ETuple", ".", "make", "(", "am_try_case_clause", ",", "val", ")", ")", ";", "}", "static", "kilim", ".", "Scheduler", "scheduler", "=", "new", "kilim", ".", "Scheduler", "(", "threadPoolSize", "(", ")", ")", ";", "static", "kilim", ".", "Scheduler", "async_scheduler", "=", "new", "kilim", ".", "Scheduler", "(", "asyncThreadPoolSize", "(", ")", ")", ";", "public", "static", "EAtom", "am_io", "=", "EAtom", ".", "intern", "(", "\"io\"", ")", ";", "public", "static", "EAtom", "am_attributes", "=", "EAtom", ".", "intern", "(", "\"attributes\"", ")", ";", "public", "static", "EAtom", "am_exports", "=", "EAtom", ".", "intern", "(", "\"exports\"", ")", ";", "public", "static", "EAtom", "am_badfun", "=", "EAtom", ".", "intern", "(", "\"badfun\"", ")", ";", "public", "static", "EAtom", "am_badarity", "=", "EAtom", ".", "intern", "(", "\"badarity\"", ")", ";", "public", "static", "EAtom", "am_name", "=", "EAtom", ".", "intern", "(", "\"name\"", ")", ";", "public", "static", "EAtom", "am_arity", "=", "EAtom", ".", "intern", "(", "\"arity\"", ")", ";", "public", "static", "EAtom", "am_env", "=", "EAtom", ".", "intern", "(", "\"env\"", ")", ";", "public", "static", "EAtom", "am_index", "=", "EAtom", ".", "intern", "(", "\"index\"", ")", ";", "public", "static", "EAtom", "am_new_index", "=", "EAtom", ".", "intern", "(", "\"new_index\"", ")", ";", "public", "static", "EAtom", "am_new_uniq", "=", "EAtom", ".", "intern", "(", "\"new_uniq\"", ")", ";", "public", "static", "EAtom", "am_uniq", "=", "EAtom", ".", "intern", "(", "\"uniq\"", ")", ";", "public", "static", "EAtom", "am_pid", "=", "EAtom", ".", "intern", "(", "\"pid\"", ")", ";", "public", "static", "EAtom", "am_type", "=", "EAtom", ".", "intern", "(", "\"type\"", ")", ";", "public", "static", "EAtom", "am_local", "=", "EAtom", ".", "intern", "(", "\"local\"", ")", ";", "public", "static", "EAtom", "am_external", "=", "EAtom", ".", "intern", "(", "\"external\"", ")", ";", "public", "static", "EAtom", "am_DOWN", "=", "EAtom", ".", "intern", "(", "\"DOWN\"", ")", ";", "public", "static", "EAtom", "am_killed", "=", "EAtom", ".", "intern", "(", "\"killed\"", ")", ";", "public", "static", "void", "run", "(", "Task", "task", ")", "{", "task", ".", "setScheduler", "(", "scheduler", ")", ";", "task", ".", "start", "(", ")", ";", "}", "public", "static", "void", "run_async", "(", "Task", "task", ")", "{", "task", ".", "setScheduler", "(", "async_scheduler", ")", ";", "task", ".", "start", "(", ")", ";", "}", "public", "static", "EObject", "loop_rec", "(", "EProc", "proc", ")", "{", "int", "idx", "=", "proc", ".", "midx", ";", "proc", ".", "in_receive", "=", "true", ";", "EObject", "msg", "=", "proc", ".", "mbox", ".", "peek", "(", "idx", ")", ";", "if", "(", "ipclog", ".", "isLoggable", "(", "Level", ".", "FINE", ")", ")", "ipclog", ".", "fine", "(", "\"\"", "+", "idx", "+", "\"", "message=\"", "+", "msg", ")", ";", "return", "msg", ";", "}", "public", "static", "void", "remove_message", "(", "EProc", "proc", ")", "{", "proc", ".", "mbox", ".", "remove", "(", "proc", ".", "midx", ")", ";", "proc", ".", "midx", "=", "0", ";", "proc", ".", "in_receive", "=", "false", ";", "}", "public", "static", "void", "loop_rec_end", "(", "EProc", "proc", ")", "{", "proc", ".", "midx", "+=", "1", ";", "}", "public", "static", "boolean", "wait_timeout", "(", "EProc", "proc", ",", "EObject", "howlong", ")", "throws", "Pausable", "{", "try", "{", "proc", ".", "check_exit", "(", ")", ";", "if", "(", "ipclog", ".", "isLoggable", "(", "Level", ".", "FINE", ")", ")", "ipclog", ".", "fine", "(", "\"WAIT|", "\"", "+", "proc", "+", "\"\"", "+", "howlong", "+", "\"", "ms\"", ")", ";", "if", "(", "howlong", "==", "am_infinity", ")", "{", "proc", ".", "mbox", ".", "untilHasMessages", "(", "proc", ".", "midx", "+", "1", ")", ";", "proc", ".", "check_exit", "(", ")", ";", "if", "(", "ipclog", ".", "isLoggable", "(", "Level", ".", "FINE", ")", ")", "ipclog", ".", "fine", "(", "\"WAIT|", "\"", "+", "proc", "+", "\"\"", ")", ";", "return", "true", ";", "}", "else", "{", "long", "now", "=", "System", ".", "currentTimeMillis", "(", ")", ";", "if", "(", "proc", ".", "midx", "==", "0", ")", "{", "proc", ".", "timeout_start", "=", "now", ";", "}", "EInteger", "ei", ";", "if", "(", "(", "ei", "=", "howlong", ".", "testInteger", "(", ")", ")", "==", "null", ")", "throw", "new", "ErlangError", "(", "EAtom", ".", "intern", "(", "\"\"", ")", ")", ";", "long", "end", "=", "proc", ".", "timeout_start", "+", "ei", ".", "longValue", "(", ")", ";", "long", "left", "=", "end", "-", "now", ";", "if", "(", "left", "<", "0", ")", "{", "return", "false", ";", "}", "if", "(", "!", "proc", ".", "in_receive", ")", "{", "Task", ".", "sleep", "(", "left", ")", ";", "return", "false", ";", "}", "else", "{", "if", "(", "ipclog", ".", "isLoggable", "(", "Level", ".", "FINE", ")", ")", "ipclog", ".", "fine", "(", "\"WAIT|", "\"", "+", "proc", "+", "\"\"", "+", "left", "+", "\"ms", "for", "msg", "#\"", "+", "(", "proc", ".", "midx", "+", "1", ")", ")", ";", "boolean", "res", "=", "proc", ".", "mbox", ".", "untilHasMessages", "(", "proc", ".", "midx", "+", "1", ",", "left", ")", ";", "proc", ".", "check_exit", "(", ")", ";", "if", "(", "ipclog", ".", "isLoggable", "(", "Level", ".", "FINE", ")", ")", "ipclog", ".", "fine", "(", "\"WAIT|", "\"", "+", "proc", "+", "\"", "wakes", "up", "\"", "+", "(", "res", "?", "\"on", "message\"", ":", "\"\"", ")", ")", ";", "return", "res", ";", "}", "}", "}", "finally", "{", "proc", ".", "in_receive", "=", "false", ";", "}", "}", "public", "static", "void", "wait", "(", "EProc", "proc", ")", "throws", "Pausable", "{", "try", "{", "int", "idx", "=", "proc", ".", "midx", "+", "1", ";", "if", "(", "ipclog", ".", "isLoggable", "(", "Level", ".", "FINE", ")", ")", "ipclog", ".", "fine", "(", "\"WAIT|", "\"", "+", "proc", "+", "\"", "waits", "for", "\"", "+", "idx", "+", "\"", "messages\"", ")", ";", "proc", ".", "mbox", ".", "untilHasMessages", "(", "idx", ")", ";", "if", "(", "ipclog", ".", "isLoggable", "(", "Level", ".", "FINE", ")", ")", "ipclog", ".", "fine", "(", "\"WAIT|", "\"", "+", "proc", "+", "\"\"", "+", "(", "idx", ")", ")", ";", "}", "finally", "{", "proc", ".", "in_receive", "=", "false", ";", "}", "}", "public", "static", "void", "timeout", "(", "EProc", "proc", ")", "{", "if", "(", "ipclog", ".", "isLoggable", "(", "Level", ".", "FINE", ")", ")", "ipclog", ".", "fine", "(", "\"WAIT|", "\"", "+", "proc", "+", "\"", "timed", "out\"", ")", ";", "proc", ".", "midx", "=", "0", ";", "proc", ".", "timeout_start", "=", "0L", ";", "proc", ".", "in_receive", "=", "false", ";", "}", "public", "static", "int", "unboxToInt", "(", "EInteger", "i", ")", "{", "return", "i", ".", "intValue", "(", ")", ";", "}", "public", "static", "int", "unboxToInt", "(", "EObject", "i", ")", "{", "ESmall", "ii", ";", "if", "(", "(", "ii", "=", "i", ".", "testSmall", "(", ")", ")", "==", "null", ")", "throw", "ERT", ".", "badarg", "(", "i", ")", ";", "return", "ii", ".", "value", ";", "}", "public", "static", "int", "unboxToInt", "(", "ENumber", "i", ")", "{", "return", "i", ".", "intValue", "(", ")", ";", "}", "public", "static", "double", "unboxToDouble", "(", "EInteger", "i", ")", "{", "return", "i", ".", "doubleValue", "(", ")", ";", "}", "public", "static", "double", "unboxToDouble", "(", "ENumber", "i", ")", "{", "return", "i", ".", "doubleValue", "(", ")", ";", "}", "public", "static", "double", "unboxToDouble", "(", "EObject", "i", ")", "{", "ENumber", "num", ";", "if", "(", "(", "num", "=", "i", ".", "testNumber", "(", ")", ")", "==", "null", ")", "throw", "ERT", ".", "badarg", "(", "i", ")", ";", "return", "num", ".", "doubleValue", "(", ")", ";", "}", "public", "static", "double", "unboxToDouble", "(", "int", "i", ")", "{", "return", "i", ";", "}", "public", "static", "Boolean", "asBoolean", "(", "EObject", "obj", ")", "{", "if", "(", "obj", "==", "ERT", ".", "TRUE", ")", "return", "true", ";", "if", "(", "obj", "==", "ERT", ".", "FALSE", ")", "return", "false", ";", "return", "null", ";", "}", "public", "static", "void", "check_exit", "(", "EProc", "p", ")", "{", "p", ".", "check_exit", "(", ")", ";", "}", "public", "static", "EObject", "func_info", "(", "EAtom", "mod", ",", "EAtom", "fun", ",", "int", "arity", ")", "{", "throw", "new", "ErlangError", "(", "am_function_clause", ")", ";", "}", "public", "static", "EObject", "func_info", "(", "EAtom", "mod", ",", "EAtom", "fun", ",", "ESeq", "args", ")", "{", "throw", "new", "ErlangError", "(", "am_function_clause", ",", "args", ")", ";", "}", "static", "void", "load_module", "(", "EAtom", "module", ")", "throws", "IOException", "{", "EModuleLoader", ".", "find_and_load_module", "(", "module", ".", "getName", "(", ")", ")", ";", "}", "public", "static", "void", "load_module", "(", "EAtom", "module", ",", "EBinary", "bin", ")", "throws", "IOException", "{", "EModuleLoader", ".", "load_module", "(", "module", ".", "getName", "(", ")", ",", "bin", ")", ";", "}", "public", "static", "EDriver", "find_driver", "(", "EString", "command", ")", "{", "String", "name", "=", "command", ".", "stringValue", "(", ")", ";", "int", "idx", "=", "name", ".", "indexOf", "(", "'", "'", ")", ";", "if", "(", "idx", "!=", "-", "1", ")", "{", "name", "=", "name", ".", "substring", "(", "0", ",", "idx", ")", ";", "}", "return", "Drivers", ".", "getDriver", "(", "name", ")", ";", "}", "public", "static", "void", "run_async", "(", "final", "EAsync", "job", ",", "final", "EDriverTask", "dt", ")", "{", "run_async", "(", "new", "Task", "(", ")", "{", "@", "Override", "public", "void", "execute", "(", ")", "throws", "Pausable", ",", "Exception", "{", "job", ".", "async", "(", ")", ";", "dt", ".", "async_done", "(", "job", ")", ";", "}", "}", ")", ";", "}", "public", "static", "int", "threadPoolSize", "(", ")", "{", "String", "threads", "=", "ErjangConfig", ".", "getString", "(", "\"\"", ")", ";", "if", "(", "threads", "!=", "null", ")", "return", "Integer", ".", "parseInt", "(", "threads", ")", ";", "else", "return", "Runtime", ".", "getRuntime", "(", ")", ".", "availableProcessors", "(", ")", ";", "}", "public", "static", "int", "asyncThreadPoolSize", "(", ")", "{", "String", "threads", "=", "ErjangConfig", ".", "getString", "(", "\"\"", ")", ";", "if", "(", "threads", "!=", "null", ")", "return", "Integer", ".", "parseInt", "(", "threads", ")", ";", "else", "return", "20", ";", "}", "public", "static", "ESeq", "registered", "(", ")", "{", "ESeq", "res", "=", "ERT", ".", "NIL", ";", "for", "(", "EAtom", "reg", ":", "register", ".", "keySet", "(", ")", ")", "{", "res", "=", "res", ".", "cons", "(", "reg", ")", ";", "}", "return", "res", ";", "}", "public", "static", "void", "shutdown", "(", ")", "{", "EObject", "init_proc", "=", "whereis", "(", "am_init", ")", ";", "ETuple", "tup", "=", "ETuple", ".", "make", "(", "am_stop", ",", "am_stop", ")", ";", "EPID", "init_pid", ";", "if", "(", "(", "init_pid", "=", "init_proc", ".", "testPID", "(", ")", ")", "!=", "null", ")", "{", "init_pid", ".", "sendb", "(", "tup", ")", ";", "}", "}", "static", "void", "shutdownSchedulers", "(", ")", "{", "scheduler", ".", "shutdown", "(", ")", ";", "async_scheduler", ".", "shutdown", "(", ")", ";", "}", "static", "protected", "volatile", "InputStream", "in", "=", "System", ".", "in", ";", "static", "protected", "volatile", "PrintStream", "out", "=", "System", ".", "out", ";", "static", "protected", "volatile", "PrintStream", "err", "=", "System", ".", "err", ";", "public", "static", "void", "set_stdio", "(", "InputStream", "in", ",", "PrintStream", "out", ",", "PrintStream", "err", ")", "{", "ERT", ".", "in", "=", "(", "in", "!=", "null", "?", "in", ":", "new", "NullInputStream", "(", ")", ")", ";", "ERT", ".", "out", "=", "(", "out", "!=", "null", "?", "out", ":", "new", "PrintStream", "(", "new", "NullOutputStream", "(", ")", ")", ")", ";", "ERT", ".", "err", "=", "(", "err", "!=", "null", "?", "err", ":", "new", "PrintStream", "(", "new", "NullOutputStream", "(", ")", ")", ")", ";", "}", "public", "static", "void", "set_stdio", "(", "InputStream", "in", ",", "OutputStream", "out", ",", "OutputStream", "err", ")", "{", "ERT", ".", "in", "=", "(", "in", "!=", "null", "?", "in", ":", "new", "NullInputStream", "(", ")", ")", ";", "ERT", ".", "out", "=", "(", "out", "!=", "null", "?", "new", "PrintStream", "(", "out", ")", ":", "new", "PrintStream", "(", "new", "NullOutputStream", "(", ")", ")", ")", ";", "ERT", ".", "err", "=", "(", "err", "!=", "null", "?", "new", "PrintStream", "(", "err", ")", ":", "new", "PrintStream", "(", "new", "NullOutputStream", "(", ")", ")", ")", ";", "}", "public", "static", "void", "setInputStream", "(", "InputStream", "in", ")", "{", "ERT", ".", "in", "=", "(", "in", "!=", "null", "?", "in", ":", "new", "NullInputStream", "(", ")", ")", ";", "}", "public", "static", "InputStream", "getInputStream", "(", ")", "{", "return", "in", ";", "}", "public", "static", "void", "setOutputStream", "(", "PrintStream", "out", ")", "{", "ERT", ".", "out", "=", "(", "out", "!=", "null", "?", "out", ":", "new", "PrintStream", "(", "new", "NullOutputStream", "(", ")", ")", ")", ";", "}", "public", "static", "void", "setOutputStream", "(", "OutputStream", "out", ")", "{", "ERT", ".", "out", "=", "(", "out", "!=", "null", "?", "new", "PrintStream", "(", "out", ")", ":", "new", "PrintStream", "(", "new", "NullOutputStream", "(", ")", ")", ")", ";", "}", "public", "static", "PrintStream", "getOutputStream", "(", ")", "{", "return", "out", ";", "}", "public", "static", "void", "setErrorStream", "(", "PrintStream", "err", ")", "{", "ERT", ".", "err", "=", "(", "err", "!=", "null", "?", "err", ":", "new", "PrintStream", "(", "new", "NullOutputStream", "(", ")", ")", ")", ";", "}", "public", "static", "void", "setErrorStream", "(", "OutputStream", "err", ")", "{", "ERT", ".", "err", "=", "(", "err", "!=", "null", "?", "new", "PrintStream", "(", "err", ")", ":", "new", "PrintStream", "(", "new", "NullOutputStream", "(", ")", ")", ")", ";", "}", "public", "static", "PrintStream", "getErrorStream", "(", ")", "{", "return", "err", ";", "}", "public", "static", "File", "newFile", "(", "String", "file_name", ")", "{", "File", "file", "=", "new", "File", "(", "file_name", ")", ";", "if", "(", "file", ".", "isAbsolute", "(", ")", ")", "return", "file", ";", "return", "new", "File", "(", "Posix", ".", "getCWD", "(", ")", ",", "file_name", ")", ";", "}", "public", "static", "void", "debug", "(", "String", "text", ")", "{", "log", ".", "fine", "(", "text", ")", ";", "}", "public", "static", "void", "debug", "(", "boolean", "condition", ",", "String", "text", ")", "{", "if", "(", "condition", ")", "{", "debug", "(", "text", ")", ";", "}", "}", "static", "class", "NullInputStream", "extends", "InputStream", "{", "@", "Override", "public", "int", "read", "(", ")", "throws", "IOException", "{", "return", "-", "1", ";", "}", "}", "static", "class", "NullOutputStream", "extends", "OutputStream", "{", "@", "Override", "public", "void", "write", "(", "int", "arg0", ")", "throws", "IOException", "{", "}", "@", "Override", "public", "void", "write", "(", "byte", "[", "]", "b", ")", "throws", "IOException", "{", "}", "@", "Override", "public", "void", "write", "(", "byte", "[", "]", "b", ",", "int", "off", ",", "int", "len", ")", "throws", "IOException", "{", "}", "}", "public", "static", "RuntimeInfo", "runtime_info", "=", "null", ";", "public", "static", "void", "setRuntimeInfo", "(", "RuntimeInfo", "info", ")", "{", "runtime_info", "=", "info", ";", "if", "(", "runtime_info", "!=", "null", ")", "{", "System", ".", "setProperty", "(", "\"erjang.path\"", ",", "runtime_info", ".", "erl_bootstrap_ebindir", ")", ";", "}", "}", "}", "</s>" ]
7,772
[ "<s>", "package", "erjang", ".", "m", ".", "os", ";", "import", "java", ".", "lang", ".", "management", ".", "ManagementFactory", ";", "import", "java", ".", "lang", ".", "management", ".", "RuntimeMXBean", ";", "import", "java", ".", "util", ".", "regex", ".", "Matcher", ";", "import", "java", ".", "util", ".", "regex", ".", "Pattern", ";", "import", "java", ".", "util", ".", "Map", ";", "import", "erjang", ".", "BIF", ";", "import", "erjang", ".", "EAtom", ";", "import", "erjang", ".", "ENative", ";", "import", "erjang", ".", "EObject", ";", "import", "erjang", ".", "ERT", ";", "import", "erjang", ".", "EString", ";", "import", "erjang", ".", "ETuple2", ";", "import", "erjang", ".", "ETuple3", ";", "import", "erjang", ".", "ECons", ";", "import", "erjang", ".", "NotImplemented", ";", "public", "class", "Native", "extends", "ENative", "{", "private", "static", "final", "EAtom", "am_unix", "=", "EAtom", ".", "intern", "(", "\"unix\"", ")", ";", "private", "static", "final", "EAtom", "am_win32", "=", "EAtom", ".", "intern", "(", "\"win32\"", ")", ";", "private", "static", "final", "EAtom", "am_darwin", "=", "EAtom", ".", "intern", "(", "\"darwin\"", ")", ";", "private", "static", "final", "EAtom", "am_linux", "=", "EAtom", ".", "intern", "(", "\"linux\"", ")", ";", "private", "static", "final", "EAtom", "am_sunos", "=", "EAtom", ".", "intern", "(", "\"sunos\"", ")", ";", "private", "static", "final", "EAtom", "am_windows", "=", "EAtom", ".", "intern", "(", "\"windows\"", ")", ";", "private", "static", "final", "EAtom", "am_nt", "=", "EAtom", ".", "intern", "(", "\"nt\"", ")", ";", "private", "static", "final", "ETuple2", "OS_TYPE_MACOS", "=", "new", "ETuple2", "(", "am_unix", ",", "am_darwin", ")", ";", "private", "static", "final", "ETuple2", "OS_TYPE_LINUX", "=", "new", "ETuple2", "(", "am_unix", ",", "am_linux", ")", ";", "private", "static", "final", "ETuple2", "OS_TYPE_SUNOS", "=", "new", "ETuple2", "(", "am_unix", ",", "am_sunos", ")", ";", "private", "static", "final", "ETuple2", "OS_TYPE_WINDOWS", "=", "new", "ETuple2", "(", "am_win32", ",", "am_windows", ")", ";", "private", "static", "final", "ETuple2", "OS_TYPE_WINNT", "=", "new", "ETuple2", "(", "am_win32", ",", "am_nt", ")", ";", "@", "BIF", "public", "static", "EObject", "getenv", "(", "EObject", "o", ")", "{", "EString", "str", "=", "o", ".", "testString", "(", ")", ";", "if", "(", "str", "==", "null", ")", "throw", "ERT", ".", "badarg", "(", "o", ")", ";", "String", "value", "=", "System", ".", "getenv", "(", "str", ".", "stringValue", "(", ")", ")", ";", "if", "(", "value", "==", "null", ")", "{", "return", "ERT", ".", "FALSE", ";", "}", "else", "{", "return", "EString", ".", "fromString", "(", "value", ")", ";", "}", "}", "@", "BIF", "public", "static", "EObject", "getenv", "(", ")", "{", "Map", "<", "String", ",", "String", ">", "env", "=", "System", ".", "getenv", "(", ")", ";", "ECons", "res", "=", "ERT", ".", "NIL", ";", "for", "(", "Map", ".", "Entry", "<", "String", ",", "String", ">", "entry", ":", "env", ".", "entrySet", "(", ")", ")", "{", "String", "s", "=", "entry", ".", "getKey", "(", ")", "+", "\"=\"", "+", "entry", ".", "getValue", "(", ")", ";", "res", "=", "res", ".", "cons", "(", "EString", ".", "fromString", "(", "s", ")", ")", ";", "}", "return", "res", ";", "}", "@", "BIF", "public", "static", "ETuple2", "type", "(", ")", "{", "String", "osname", "=", "System", ".", "getProperty", "(", "\"os.name\"", ")", ";", "if", "(", "\"Mac", "OS\"", ".", "equals", "(", "osname", ")", "||", "\"Mac", "OS", "X\"", ".", "equals", "(", "osname", ")", ")", "return", "OS_TYPE_MACOS", ";", "if", "(", "\"Linux\"", ".", "equals", "(", "osname", ")", ")", "return", "OS_TYPE_LINUX", ";", "if", "(", "\"Solaris\"", ".", "equals", "(", "osname", ")", "||", "\"SunOS\"", ".", "equals", "(", "osname", ")", ")", "return", "OS_TYPE_SUNOS", ";", "if", "(", "\"Windows", "95\"", ".", "equals", "(", "osname", ")", "||", "\"Windows", "98\"", ".", "equals", "(", "osname", ")", "||", "\"Windows", "Me\"", ".", "equals", "(", "osname", ")", ")", "return", "OS_TYPE_WINDOWS", ";", "if", "(", "\"Windows", "NT\"", ".", "equals", "(", "osname", ")", "||", "\"Windows", "2000\"", ".", "equals", "(", "osname", ")", "||", "\"Windows", "XP\"", ".", "equals", "(", "osname", ")", ")", "return", "OS_TYPE_WINNT", ";", "return", "OS_TYPE_MACOS", ";", "}", "@", "BIF", "public", "static", "EObject", "getpid", "(", ")", "{", "RuntimeMXBean", "rtb", "=", "ManagementFactory", ".", "getRuntimeMXBean", "(", ")", ";", "String", "processName", "=", "rtb", ".", "getName", "(", ")", ";", "Integer", "pid", "=", "tryPattern1", "(", "processName", ")", ";", "if", "(", "pid", "==", "null", ")", "{", "throw", "new", "NotImplemented", "(", ")", ";", "}", "return", "EString", ".", "fromString", "(", "String", ".", "valueOf", "(", "pid", ")", ")", ";", "}", "private", "static", "Integer", "tryPattern1", "(", "String", "processName", ")", "{", "Integer", "result", "=", "null", ";", "Pattern", "pattern", "=", "Pattern", ".", "compile", "(", "\"\"", ",", "Pattern", ".", "CASE_INSENSITIVE", ")", ";", "Matcher", "matcher", "=", "pattern", ".", "matcher", "(", "processName", ")", ";", "if", "(", "matcher", ".", "matches", "(", ")", ")", "{", "result", "=", "new", "Integer", "(", "Integer", ".", "parseInt", "(", "matcher", ".", "group", "(", "1", ")", ")", ")", ";", "}", "return", "result", ";", "}", "@", "BIF", "static", "public", "ETuple3", "timestamp", "(", ")", "{", "long", "now", "=", "erjang", ".", "m", ".", "erlang", ".", "ErlBif", ".", "now_raw_micros", "(", ")", ";", "int", "micros", "=", "(", "int", ")", "(", "now", "%", "1000000", ")", ";", "now", "/=", "1000000", ";", "int", "secs", "=", "(", "int", ")", "(", "now", "%", "1000000", ")", ";", "now", "/=", "1000000", ";", "int", "megas", "=", "(", "int", ")", "now", ";", "ETuple3", "res", "=", "new", "ETuple3", "(", ")", ";", "res", ".", "elem1", "=", "ERT", ".", "box", "(", "megas", ")", ";", "res", ".", "elem2", "=", "ERT", ".", "box", "(", "secs", ")", ";", "res", ".", "elem3", "=", "ERT", ".", "box", "(", "micros", ")", ";", "return", "res", ";", "}", "}", "</s>" ]
7,773
[ "<s>", "package", "erjang", ".", "m", ".", "java", ";", "import", "java", ".", "lang", ".", "reflect", ".", "Field", ";", "import", "java", ".", "lang", ".", "reflect", ".", "Method", ";", "import", "kilim", ".", "Pausable", ";", "import", "erjang", ".", "BIF", ";", "import", "erjang", ".", "EAtom", ";", "import", "erjang", ".", "EFun", ";", "import", "erjang", ".", "ENative", ";", "import", "erjang", ".", "EObject", ";", "import", "erjang", ".", "EProc", ";", "import", "erjang", ".", "ERT", ";", "import", "erjang", ".", "ESeq", ";", "import", "erjang", ".", "EString", ";", "import", "erjang", ".", "ErlangError", ";", "public", "class", "Native", "extends", "ENative", "{", "@", "BIF", "static", "EObject", "get_static", "(", "EProc", "self", ",", "EObject", "clzz", ",", "EObject", "member", ")", "{", "EAtom", "clz_am", "=", "clzz", ".", "testAtom", "(", ")", ";", "EAtom", "mem_am", "=", "member", ".", "testAtom", "(", ")", ";", "if", "(", "clz_am", "==", "null", "||", "mem_am", "==", "null", ")", "throw", "ERT", ".", "badarg", "(", "clzz", ",", "member", ")", ";", "try", "{", "Class", "<", "?", ">", "c", "=", "Class", ".", "forName", "(", "clz_am", ".", "getName", "(", ")", ")", ";", "Field", "f", "=", "c", ".", "getField", "(", "mem_am", ".", "getName", "(", ")", ")", ";", "if", "(", "java", ".", "lang", ".", "reflect", ".", "Modifier", ".", "isStatic", "(", "f", ".", "getModifiers", "(", ")", ")", ")", "{", "return", "JavaObject", ".", "box", "(", "self", ",", "f", ".", "get", "(", "null", ")", ")", ";", "}", "else", "{", "throw", "new", "ErlangError", "(", "EString", ".", "fromString", "(", "\"\"", ")", ",", "clzz", ",", "member", ")", ";", "}", "}", "catch", "(", "Exception", "e", ")", "{", "throw", "new", "ErlangError", "(", "EString", ".", "fromString", "(", "e", ".", "getMessage", "(", ")", ")", ",", "clzz", ",", "member", ")", ";", "}", "}", "@", "BIF", "static", "EObject", "call", "(", "EProc", "self", ",", "EObject", "obj", ",", "EObject", "member", ",", "EObject", "typez", ",", "EObject", "argz", ")", "{", "EAtom", "mem_am", "=", "member", ".", "testAtom", "(", ")", ";", "ESeq", "type_seq", "=", "typez", ".", "testSeq", "(", ")", ";", "ESeq", "arg_seq", "=", "argz", ".", "testSeq", "(", ")", ";", "Object", "receiver", "=", "JavaObject", ".", "unbox", "(", "self", ",", "Object", ".", "class", ",", "obj", ")", ";", "if", "(", "mem_am", "==", "null", "||", "type_seq", "==", "null", "||", "arg_seq", "==", "null", "||", "type_seq", ".", "length", "(", ")", "!=", "arg_seq", ".", "length", "(", ")", "||", "receiver", "==", "null", ")", "throw", "ERT", ".", "badarg", "(", "obj", ",", "member", ",", "typez", ",", "argz", ")", ";", "try", "{", "Class", "<", "?", ">", "c", "=", "receiver", ".", "getClass", "(", ")", ";", "Class", "<", "?", ">", "[", "]", "arg_types", "=", "new", "Class", "<", "?", ">", "[", "type_seq", ".", "length", "(", ")", "]", ";", "EObject", "[", "]", "at", "=", "type_seq", ".", "toArray", "(", ")", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "at", ".", "length", ";", "i", "++", ")", "{", "EAtom", "am", "=", "at", "[", "i", "]", ".", "testAtom", "(", ")", ";", "if", "(", "am", "==", "null", ")", "{", "throw", "ERT", ".", "badarg", "(", "obj", ",", "member", ",", "typez", ",", "argz", ")", ";", "}", "arg_types", "[", "i", "]", "=", "Class", ".", "forName", "(", "am", ".", "getName", "(", ")", ")", ";", "}", "Method", "m", "=", "c", ".", "getMethod", "(", "mem_am", ".", "getName", "(", ")", ",", "arg_types", ")", ";", "Object", "res", "=", "m", ".", "invoke", "(", "receiver", ",", "JavaObject", ".", "convert_args", "(", "self", ",", "arg_types", ",", "arg_seq", ")", ")", ";", "if", "(", "m", ".", "getReturnType", "(", ")", "==", "Void", ".", "TYPE", ")", "{", "return", "ERT", ".", "am_ok", ";", "}", "return", "JavaObject", ".", "box", "(", "self", ",", "res", ")", ";", "}", "catch", "(", "Exception", "e", ")", "{", "throw", "new", "ErlangError", "(", "EString", ".", "fromString", "(", "e", ".", "getMessage", "(", ")", ")", ",", "obj", ",", "member", ",", "typez", ",", "argz", ")", ";", "}", "finally", "{", "}", "}", "@", "BIF", "public", "static", "EObject", "run", "(", "EProc", "proc", ",", "EObject", "fun", ")", "throws", "Pausable", "{", "EFun", "f", "=", "fun", ".", "testFunction2", "(", "0", ")", ";", "if", "(", "f", "==", "null", ")", "{", "throw", "ERT", ".", "badarg", "(", "fun", ")", ";", "}", "return", "f", ".", "invoke", "(", "proc", ",", "new", "EObject", "[", "0", "]", ")", ";", "}", "}", "</s>" ]
7,774
[ "<s>", "package", "erjang", ".", "m", ".", "java", ";", "import", "java", ".", "lang", ".", "reflect", ".", "Array", ";", "import", "java", ".", "lang", ".", "reflect", ".", "Constructor", ";", "import", "java", ".", "lang", ".", "reflect", ".", "InvocationHandler", ";", "import", "java", ".", "lang", ".", "reflect", ".", "InvocationTargetException", ";", "import", "java", ".", "lang", ".", "reflect", ".", "Method", ";", "import", "java", ".", "lang", ".", "reflect", ".", "Modifier", ";", "import", "java", ".", "math", ".", "BigInteger", ";", "import", "java", ".", "util", ".", "HashMap", ";", "import", "java", ".", "util", ".", "Iterator", ";", "import", "java", ".", "util", ".", "Map", ";", "import", "junit", ".", "extensions", ".", "TestDecorator", ";", "import", "kilim", ".", "Mailbox", ";", "import", "kilim", ".", "Pausable", ";", "import", "erjang", ".", "EAtom", ";", "import", "erjang", ".", "EBinary", ";", "import", "erjang", ".", "EBitString", ";", "import", "erjang", ".", "ECons", ";", "import", "erjang", ".", "EDouble", ";", "import", "erjang", ".", "EFun", ";", "import", "erjang", ".", "EFunHandler", ";", "import", "erjang", ".", "EInteger", ";", "import", "erjang", ".", "EList", ";", "import", "erjang", ".", "ENil", ";", "import", "erjang", ".", "ENumber", ";", "import", "erjang", ".", "EObject", ";", "import", "erjang", ".", "EProc", ";", "import", "erjang", ".", "EPseudoTerm", ";", "import", "erjang", ".", "ERT", ";", "import", "erjang", ".", "ESeq", ";", "import", "erjang", ".", "ESmall", ";", "import", "erjang", ".", "EString", ";", "import", "erjang", ".", "ETuple", ";", "import", "erjang", ".", "ETuple2", ";", "import", "erjang", ".", "ErlangError", ";", "import", "erjang", ".", "ErlangException", ";", "import", "erjang", ".", "driver", ".", "IO", ";", "import", "erjang", ".", "m", ".", "erlang", ".", "ErlProc", ";", "public", "class", "JavaObject", "extends", "EPseudoTerm", "{", "public", "JavaObject", "testJavaObject", "(", ")", "{", "return", "this", ";", "}", "static", "final", "EAtom", "am_none", "=", "EAtom", ".", "intern", "(", "\"none\"", ")", ";", "static", "final", "EAtom", "am_java_object", "=", "EAtom", ".", "intern", "(", "\"java_object\"", ")", ";", "static", "final", "EAtom", "am_badaccess", "=", "EAtom", ".", "intern", "(", "\"badaccess\"", ")", ";", "static", "final", "EAtom", "am_badfun", "=", "EAtom", ".", "intern", "(", "\"badfun\"", ")", ";", "static", "final", "EAtom", "am_null_pointer_exception", "=", "EAtom", ".", "intern", "(", "\"\"", ")", ";", "protected", "static", "final", "EAtom", "am_erlang", "=", "EAtom", ".", "intern", "(", "\"erlang\"", ")", ";", "protected", "static", "final", "EAtom", "am_apply", "=", "EAtom", ".", "intern", "(", "\"apply\"", ")", ";", "final", "Object", "real_object", ";", "final", "EProc", "owner", ";", "public", "Object", "realObject", "(", ")", "{", "return", "real_object", ";", "}", "@", "Override", "public", "int", "hashCode", "(", ")", "{", "return", "real_object", ".", "hashCode", "(", ")", ";", "}", "@", "Override", "public", "EBinary", "testBinary", "(", ")", "{", "if", "(", "real_object", "instanceof", "byte", "[", "]", ")", "{", "return", "new", "EBinary", "(", "(", "byte", "[", "]", ")", "real_object", ")", ";", "}", "if", "(", "real_object", "instanceof", "String", ")", "{", "return", "new", "EBinary", "(", "(", "(", "String", ")", "real_object", ")", ".", "getBytes", "(", "IO", ".", "UTF8", ")", ")", ";", "}", "return", "null", ";", "}", "@", "Override", "public", "EBitString", "testBitString", "(", ")", "{", "EBinary", "bi", ";", "if", "(", "(", "bi", "=", "testBinary", "(", ")", ")", "!=", "null", ")", "{", "return", "bi", ";", "}", "if", "(", "testCons", "(", ")", "==", "null", "&&", "testNumber", "(", ")", "==", "null", "&&", "testTuple", "(", ")", "==", "null", "&&", "testAtom", "(", ")", "==", "null", "&&", "testHandle", "(", ")", "==", "null", ")", "return", "EBinary", ".", "EMPTY", ";", "return", "null", ";", "}", "@", "Override", "public", "ENil", "testNil", "(", ")", "{", "if", "(", "real_object", "==", "null", ")", "return", "ERT", ".", "NIL", ";", "if", "(", "testSeq", "(", ")", "==", "ERT", ".", "NIL", ")", "return", "ERT", ".", "NIL", ";", "return", "null", ";", "}", "@", "Override", "public", "EFun", "testFunction", "(", ")", "{", "EFun", "fun", ";", "if", "(", "(", "fun", "=", "testFunction2", "(", "0", ")", ")", "!=", "null", ")", "{", "return", "fun", ";", "}", "if", "(", "(", "fun", "=", "testFunction2", "(", "1", ")", ")", "!=", "null", ")", "{", "return", "fun", ";", "}", "return", "null", ";", "}", "@", "Override", "public", "EFun", "testFunction2", "(", "int", "nargs", ")", "{", "if", "(", "(", "nargs", "==", "0", ")", "&&", "(", "real_object", "instanceof", "Runnable", ")", ")", "{", "final", "Runnable", "r", "=", "(", "Runnable", ")", "real_object", ";", "return", "EFun", ".", "get_fun_with_handler", "(", "\"\"", ",", "\"run\"", ",", "0", ",", "new", "EFunHandler", "(", ")", "{", "@", "Override", "public", "EObject", "invoke", "(", "EProc", "proc", ",", "EObject", "[", "]", "args", ")", "throws", "Pausable", "{", "if", "(", "proc", "!=", "owner", ")", "throw", "new", "ErlangError", "(", "ERT", ".", "am_badfun", ",", "args", ")", ";", "r", ".", "run", "(", ")", ";", "return", "ERT", ".", "am_ok", ";", "}", "}", ",", "getClass", "(", ")", ".", "getClassLoader", "(", ")", ")", ";", "}", "if", "(", "(", "nargs", "==", "1", ")", "&&", "(", "real_object", "instanceof", "java", ".", "util", ".", "Map", "<", "?", ",", "?", ">", ")", ")", "{", "final", "java", ".", "util", ".", "Map", "<", "?", ",", "?", ">", "r", "=", "(", "java", ".", "util", ".", "Map", "<", "?", ",", "?", ">", ")", "real_object", ";", "return", "EFun", ".", "get_fun_with_handler", "(", "\"\"", ",", "\"get\"", ",", "0", ",", "new", "EFunHandler", "(", ")", "{", "@", "Override", "public", "EObject", "invoke", "(", "EProc", "self", ",", "EObject", "[", "]", "args", ")", "throws", "Pausable", "{", "if", "(", "self", "!=", "owner", ")", "throw", "new", "ErlangError", "(", "ERT", ".", "am_badfun", ",", "args", ")", ";", "Object", "key", "=", "JavaObject", ".", "unbox", "(", "self", ",", "Object", ".", "class", ",", "args", "[", "0", "]", ")", ";", "if", "(", "r", ".", "containsKey", "(", "key", ")", ")", "{", "return", "new", "ETuple2", "(", "args", "[", "0", "]", ",", "JavaObject", ".", "box", "(", "self", ",", "r", ".", "get", "(", "key", ")", ")", ")", ";", "}", "else", "{", "return", "am_none", ";", "}", "}", "}", ",", "getClass", "(", ")", ".", "getClassLoader", "(", ")", ")", ";", "}", "return", "null", ";", "}", "@", "Override", "public", "ECons", "testCons", "(", ")", "{", "return", "testSeq", "(", ")", ";", "}", "@", "Override", "public", "ECons", "testNonEmptyList", "(", ")", "{", "ESeq", "seq", "=", "testSeq", "(", ")", ";", "if", "(", "seq", "==", "null", "||", "seq", ".", "isNil", "(", ")", ")", "return", "null", ";", "return", "seq", ";", "}", "@", "Override", "public", "EAtom", "testBoolean", "(", ")", "{", "if", "(", "real_object", "==", "Boolean", ".", "TRUE", ")", "return", "ERT", ".", "TRUE", ";", "if", "(", "real_object", "==", "Boolean", ".", "FALSE", ")", "return", "ERT", ".", "FALSE", ";", "return", "null", ";", "}", "@", "Override", "public", "EString", "testString", "(", ")", "{", "if", "(", "real_object", "instanceof", "String", ")", "{", "return", "EString", ".", "fromString", "(", "(", "String", ")", "real_object", ")", ";", "}", "ESeq", "seq", ";", "if", "(", "(", "seq", "=", "testSeq", "(", ")", ")", "!=", "null", ")", "{", "return", "seq", ".", "testString", "(", ")", ";", "}", "return", "null", ";", "}", "@", "Override", "public", "EAtom", "testAtom", "(", ")", "{", "if", "(", "real_object", "instanceof", "String", ")", "{", "String", "s", "=", "(", "String", ")", "real_object", ";", "return", "EAtom", ".", "existing_atom", "(", "s", ")", ";", "}", "if", "(", "real_object", "instanceof", "Class", ")", "{", "return", "EAtom", ".", "intern", "(", "(", "(", "Class", ")", "real_object", ")", ".", "getName", "(", ")", ")", ";", "}", "return", "null", ";", "}", "@", "SuppressWarnings", "(", "\"unchecked\"", ")", "@", "Override", "public", "ESeq", "testSeq", "(", ")", "{", "if", "(", "real_object", "instanceof", "CharSequence", ")", "{", "return", "JavaCharSeq", ".", "box", "(", "owner", ",", "(", "CharSequence", ")", "real_object", ",", "0", ")", ";", "}", "if", "(", "real_object", "instanceof", "Iterable", "<", "?", ">", ")", "{", "Iterable", "<", "?", ">", "it", "=", "(", "Iterable", "<", "?", ">", ")", "real_object", ";", "return", "JavaIterator", ".", "box", "(", "owner", ",", "it", ".", "iterator", "(", ")", ")", ";", "}", "if", "(", "real_object", "instanceof", "Iterator", "<", "?", ">", ")", "{", "return", "JavaIterator", ".", "box", "(", "owner", ",", "(", "(", "Iterator", "<", "?", ">", ")", "real_object", ")", ")", ";", "}", "if", "(", "real_object", "instanceof", "Map", "<", "?", ",", "?", ">", ")", "{", "return", "JavaMapIterator", ".", "box", "(", "owner", ",", "(", "(", "Map", ")", "real_object", ")", ".", "entrySet", "(", ")", ".", "iterator", "(", ")", ")", ";", "}", "if", "(", "real_object", "!=", "null", "&&", "real_object", ".", "getClass", "(", ")", ".", "isArray", "(", ")", ")", "{", "return", "JavaArray", ".", "box", "(", "owner", ",", "real_object", ",", "0", ")", ";", "}", "return", "null", ";", "}", "@", "Override", "public", "ESmall", "testSmall", "(", ")", "{", "EInteger", "iv", ";", "if", "(", "(", "iv", "=", "testInteger", "(", ")", ")", "!=", "null", ")", "{", "return", "iv", ".", "testSmall", "(", ")", ";", "}", "return", "null", ";", "}", "@", "Override", "public", "ENumber", "testNumber", "(", ")", "{", "EInteger", "i", ";", "if", "(", "(", "i", "=", "testInteger", "(", ")", ")", "!=", "null", ")", "return", "i", ";", "EDouble", "d", ";", "if", "(", "(", "d", "=", "testFloat", "(", ")", ")", "!=", "null", ")", "return", "d", ";", "return", "null", ";", "}", "@", "Override", "public", "EInteger", "testInteger", "(", ")", "{", "if", "(", "real_object", "instanceof", "BigInteger", ")", "{", "return", "ERT", ".", "box", "(", "(", "(", "BigInteger", ")", "real_object", ")", ")", ";", "}", "if", "(", "real_object", "instanceof", "Integer", ")", "{", "return", "ERT", ".", "box", "(", "(", "(", "Integer", ")", "real_object", ")", ".", "intValue", "(", ")", ")", ";", "}", "if", "(", "real_object", "instanceof", "Short", ")", "{", "return", "ERT", ".", "box", "(", "(", "(", "Short", ")", "real_object", ")", ".", "shortValue", "(", ")", ")", ";", "}", "if", "(", "real_object", "instanceof", "Character", ")", "{", "return", "ERT", ".", "box", "(", "(", "(", "Character", ")", "real_object", ")", ".", "charValue", "(", ")", ")", ";", "}", "if", "(", "real_object", "instanceof", "Byte", ")", "{", "return", "ERT", ".", "box", "(", "(", "(", "Byte", ")", "real_object", ")", ".", "byteValue", "(", ")", ")", ";", "}", "if", "(", "real_object", "instanceof", "Long", ")", "{", "return", "ERT", ".", "box", "(", "(", "(", "Long", ")", "real_object", ")", ".", "longValue", "(", ")", ")", ";", "}", "return", "null", ";", "}", "@", "Override", "public", "EDouble", "testFloat", "(", ")", "{", "if", "(", "real_object", "instanceof", "Double", ")", "{", "return", "new", "EDouble", "(", "(", "(", "Double", ")", "real_object", ")", ".", "doubleValue", "(", ")", ")", ";", "}", "return", "null", ";", "}", "public", "JavaObject", "(", "EProc", "self", ",", "Object", "object", ")", "{", "real_object", "=", "object", ";", "owner", "=", "self", ";", "}", "public", "String", "toString", "(", ")", "{", "return", "String", ".", "valueOf", "(", "real_object", ")", ";", "}", ";", "public", "static", "EObject", "box", "(", "EProc", "self", ",", "Object", "object", ")", "{", "if", "(", "object", "instanceof", "EObject", ")", "{", "return", "(", "EObject", ")", "object", ";", "}", "return", "new", "JavaObject", "(", "self", ",", "object", ")", ";", "}", "public", "static", "Object", "[", "]", "convert_args", "(", "EProc", "self", ",", "Class", "<", "?", ">", "[", "]", "arg_types", ",", "ESeq", "arg_seq", ")", "throws", "IllegalArgumentException", "{", "Object", "[", "]", "out", "=", "new", "Object", "[", "arg_types", ".", "length", "]", ";", "ESeq", "as_iter", "=", "arg_seq", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "arg_types", ".", "length", ";", "i", "++", ")", "{", "out", "[", "i", "]", "=", "JavaObject", ".", "unbox", "(", "self", ",", "arg_types", "[", "i", "]", ",", "as_iter", ".", "head", "(", ")", ")", ";", "as_iter", "=", "as_iter", ".", "tail", "(", ")", ";", "}", "return", "out", ";", "}", "public", "static", "Object", "[", "]", "convert_args", "(", "EProc", "self", ",", "Class", "<", "?", ">", "[", "]", "arg_types", ",", "EObject", "[", "]", "args", ")", "throws", "IllegalArgumentException", "{", "Object", "[", "]", "out", "=", "new", "Object", "[", "arg_types", ".", "length", "]", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "arg_types", ".", "length", ";", "i", "++", ")", "{", "out", "[", "i", "]", "=", "JavaObject", ".", "unbox", "(", "self", ",", "arg_types", "[", "i", "]", ",", "args", "[", "i", "]", ")", ";", "}", "return", "out", ";", "}", "static", "Object", "unbox", "(", "final", "EProc", "self", ",", "Class", "<", "?", ">", "type", ",", "EObject", "val", ")", "throws", "IllegalArgumentException", "{", "if", "(", "val", "instanceof", "JavaObject", ")", "{", "JavaObject", "jo", "=", "(", "JavaObject", ")", "val", ";", "if", "(", "type", ".", "isInstance", "(", "jo", ".", "real_object", ")", ")", "{", "return", "jo", ".", "real_object", ";", "}", "else", "{", "throw", "new", "IllegalArgumentException", "(", "\"\"", "+", "val", ".", "getClass", "(", ")", ".", "getName", "(", ")", "+", "\"", "to", "\"", "+", "type", ")", ";", "}", "}", "if", "(", "type", "==", "Object", ".", "class", "||", "type", ".", "isInstance", "(", "val", ")", ")", "{", "return", "val", ";", "}", "if", "(", "type", "==", "Void", ".", "class", "||", "type", "==", "void", ".", "class", ")", "{", "return", "null", ";", "}", "if", "(", "type", ".", "isArray", "(", ")", ")", "{", "ESeq", "seq", ";", "if", "(", "(", "seq", "=", "val", ".", "testSeq", "(", ")", ")", "!=", "null", ")", "{", "int", "length", "=", "seq", ".", "length", "(", ")", ";", "Class", "<", "?", ">", "componentType", "=", "type", ".", "getComponentType", "(", ")", ";", "Object", "arr", "=", "Array", ".", "newInstance", "(", "componentType", ",", "length", ")", ";", "int", "index", "=", "0", ";", "while", "(", "!", "seq", ".", "isNil", "(", ")", ")", "{", "Object", "value", "=", "JavaObject", ".", "unbox", "(", "self", ",", "componentType", ",", "seq", ".", "head", "(", ")", ")", ";", "Array", ".", "set", "(", "arr", ",", "index", "++", ",", "value", ")", ";", "seq", "=", "seq", ".", "tail", "(", ")", ";", "}", "return", "arr", ";", "}", "ETuple", "tup", ";", "if", "(", "(", "tup", "=", "val", ".", "testTuple", "(", ")", ")", "!=", "null", ")", "{", "int", "length", "=", "tup", ".", "arity", "(", ")", ";", "Class", "<", "?", ">", "componentType", "=", "type", ".", "getComponentType", "(", ")", ";", "Object", "arr", "=", "Array", ".", "newInstance", "(", "componentType", ",", "length", ")", ";", "for", "(", "int", "index", "=", "0", ";", "index", "<", "length", ";", "index", "++", ")", "{", "Object", "value", "=", "JavaObject", ".", "unbox", "(", "self", ",", "componentType", ",", "tup", ".", "elm", "(", "index", "+", "1", ")", ")", ";", "Array", ".", "set", "(", "arr", ",", "index", ",", "value", ")", ";", "}", "return", "arr", ";", "}", "}", "Mapper", "mapper", "=", "type_mapper", ".", "get", "(", "type", ")", ";", "if", "(", "mapper", "!=", "null", ")", "{", "return", "mapper", ".", "map", "(", "val", ")", ";", "}", "final", "EFun", "ifun", ";", "if", "(", "type", ".", "isInterface", "(", ")", "&&", "(", "ifun", "=", "val", ".", "testFunction2", "(", "3", ")", ")", "!=", "null", ")", "{", "final", "ClassLoader", "loader", "=", "JavaObject", ".", "class", ".", "getClassLoader", "(", ")", ";", "return", "java", ".", "lang", ".", "reflect", ".", "Proxy", ".", "newProxyInstance", "(", "loader", ",", "new", "Class", "[", "]", "{", "type", "}", ",", "new", "InvocationHandler", "(", ")", "{", "@", "Override", "public", "Object", "invoke", "(", "Object", "proxy", ",", "final", "Method", "method", ",", "final", "Object", "[", "]", "args", ")", "throws", "Throwable", "{", "final", "Mailbox", "<", "Object", ">", "reply", "=", "new", "Mailbox", "<", "Object", ">", "(", "1", ")", ";", "EFun", "job", "=", "EFun", ".", "get_fun_with_handler", "(", "\"erlang\"", ",", "\"apply\"", ",", "0", ",", "new", "EFunHandler", "(", ")", "{", "@", "Override", "public", "EObject", "invoke", "(", "EProc", "proc", ",", "EObject", "[", "]", "_", ")", "throws", "Pausable", "{", "EObject", "aa", "=", "JavaObject", ".", "box", "(", "proc", ",", "args", ")", ";", "EObject", "at", "=", "JavaObject", ".", "box", "(", "proc", ",", "method", ".", "getParameterTypes", "(", ")", ")", ";", "EObject", "[", "]", "call_args", "=", "new", "EObject", "[", "]", "{", "EAtom", ".", "intern", "(", "method", ".", "getName", "(", ")", ")", ",", "at", ",", "aa", "}", ";", "EObject", "result", "=", "ifun", ".", "invoke", "(", "proc", ",", "call_args", ")", ";", "Object", "jresult", "=", "JavaObject", ".", "unbox", "(", "proc", ",", "method", ".", "getReturnType", "(", ")", ",", "result", ")", ";", "if", "(", "method", ".", "getReturnType", "(", ")", "==", "void", ".", "class", ")", "{", "reply", ".", "put", "(", "ERT", ".", "am_ok", ")", ";", "}", "else", "{", "reply", ".", "put", "(", "jresult", ")", ";", "}", "return", "ERT", ".", "am_ok", ";", "}", "}", ",", "loader", ")", ";", "EProc", "proc", "=", "new", "EProc", "(", "self", ".", "group_leader", "(", ")", ",", "am_erlang", ",", "am_apply", ",", "EList", ".", "make", "(", "job", ",", "ERT", ".", "NIL", ")", ")", ";", "ERT", ".", "run", "(", "proc", ")", ";", "return", "reply", ".", "getb", "(", ")", ";", "}", "}", ")", ";", "}", "throw", "new", "IllegalArgumentException", "(", "\"\"", "+", "val", ".", "getClass", "(", ")", ".", "getName", "(", ")", "+", "\"", "to", "\"", "+", "type", ")", ";", "}", "static", "Map", "<", "Class", "<", "?", ">", ",", "Mapper", ">", "type_mapper", "=", "new", "HashMap", "<", "Class", "<", "?", ">", ",", "Mapper", ">", "(", ")", ";", "interface", "Mapper", "{", "Object", "map", "(", "EObject", "val", ")", ";", "}", "static", "{", "Mapper", "string_mapper", "=", "new", "Mapper", "(", ")", "{", "public", "Object", "map", "(", "EObject", "val", ")", "{", "EString", "str", ";", "if", "(", "(", "str", "=", "val", ".", "testString", "(", ")", ")", "!=", "null", ")", "return", "str", ".", "stringValue", "(", ")", ";", "EAtom", "am", ";", "if", "(", "(", "am", "=", "val", ".", "testAtom", "(", ")", ")", "!=", "null", ")", "return", "am", ".", "getName", "(", ")", ";", "EBinary", "bi", ";", "if", "(", "(", "bi", "=", "val", ".", "testBinary", "(", ")", ")", "!=", "null", ")", "{", "return", "new", "String", "(", "bi", ".", "toByteArray", "(", ")", ",", "IO", ".", "UTF8", ")", ";", "}", "throw", "new", "IllegalArgumentException", "(", ")", ";", "}", "}", ";", "type_mapper", ".", "put", "(", "String", ".", "class", ",", "string_mapper", ")", ";", "type_mapper", ".", "put", "(", "CharSequence", ".", "class", ",", "string_mapper", ")", ";", "Mapper", "byte_mapper", "=", "new", "Mapper", "(", ")", "{", "public", "Object", "map", "(", "EObject", "val", ")", "{", "ESmall", "num", ";", "if", "(", "(", "num", "=", "val", ".", "testSmall", "(", ")", ")", "!=", "null", "&&", "num", ".", "value", ">=", "Byte", ".", "MIN_VALUE", "&&", "num", ".", "value", "<=", "255", ")", "{", "return", "new", "Byte", "(", "(", "byte", ")", "num", ".", "intValue", "(", ")", ")", ";", "}", "throw", "new", "IllegalArgumentException", "(", "\"\"", "+", "val", "+", "\"", "to", "byte\"", ")", ";", "}", "}", ";", "type_mapper", ".", "put", "(", "Byte", ".", "class", ",", "byte_mapper", ")", ";", "type_mapper", ".", "put", "(", "byte", ".", "class", ",", "byte_mapper", ")", ";", "Mapper", "short_mapper", "=", "new", "Mapper", "(", ")", "{", "public", "Object", "map", "(", "EObject", "val", ")", "{", "ESmall", "num", ";", "if", "(", "(", "num", "=", "val", ".", "testSmall", "(", ")", ")", "!=", "null", "&&", "num", ".", "value", ">=", "Short", ".", "MIN_VALUE", "&&", "num", ".", "value", "<=", "Short", ".", "MAX_VALUE", ")", "{", "return", "new", "Short", "(", "(", "byte", ")", "num", ".", "intValue", "(", ")", ")", ";", "}", "throw", "new", "IllegalArgumentException", "(", "\"\"", "+", "val", "+", "\"", "to", "short\"", ")", ";", "}", "}", ";", "type_mapper", ".", "put", "(", "Short", ".", "class", ",", "short_mapper", ")", ";", "type_mapper", ".", "put", "(", "short", ".", "class", ",", "short_mapper", ")", ";", "Mapper", "int_mapper", "=", "new", "Mapper", "(", ")", "{", "public", "Object", "map", "(", "EObject", "val", ")", "{", "ESmall", "num", ";", "if", "(", "(", "num", "=", "val", ".", "testSmall", "(", ")", ")", "!=", "null", ")", "{", "return", "new", "Integer", "(", "num", ".", "intValue", "(", ")", ")", ";", "}", "throw", "new", "IllegalArgumentException", "(", "\"\"", "+", "val", "+", "\"", "to", "int\"", ")", ";", "}", "}", ";", "type_mapper", ".", "put", "(", "Integer", ".", "class", ",", "int_mapper", ")", ";", "type_mapper", ".", "put", "(", "int", ".", "class", ",", "int_mapper", ")", ";", "Mapper", "long_mapper", "=", "new", "Mapper", "(", ")", "{", "public", "Object", "map", "(", "EObject", "val", ")", "{", "EInteger", "num", ";", "if", "(", "(", "num", "=", "val", ".", "testInteger", "(", ")", ")", "!=", "null", ")", "{", "return", "new", "Long", "(", "num", ".", "longValue", "(", ")", ")", ";", "}", "throw", "new", "IllegalArgumentException", "(", "\"\"", "+", "val", "+", "\"", "to", "long\"", ")", ";", "}", "}", ";", "type_mapper", ".", "put", "(", "Long", ".", "class", ",", "long_mapper", ")", ";", "type_mapper", ".", "put", "(", "long", ".", "class", ",", "long_mapper", ")", ";", "Mapper", "double_mapper", "=", "new", "Mapper", "(", ")", "{", "public", "Object", "map", "(", "EObject", "val", ")", "{", "ENumber", "num", ";", "if", "(", "(", "num", "=", "val", ".", "testNumber", "(", ")", ")", "!=", "null", ")", "{", "return", "new", "Double", "(", "num", ".", "doubleValue", "(", ")", ")", ";", "}", "throw", "new", "IllegalArgumentException", "(", "\"\"", "+", "val", "+", "\"", "to", "double\"", ")", ";", "}", "}", ";", "type_mapper", ".", "put", "(", "Double", ".", "class", ",", "double_mapper", ")", ";", "type_mapper", ".", "put", "(", "double", ".", "class", ",", "double_mapper", ")", ";", "Mapper", "float_mapper", "=", "new", "Mapper", "(", ")", "{", "public", "Object", "map", "(", "EObject", "val", ")", "{", "ENumber", "num", ";", "if", "(", "(", "num", "=", "val", ".", "testNumber", "(", ")", ")", "!=", "null", ")", "{", "return", "new", "Float", "(", "num", ".", "doubleValue", "(", ")", ")", ";", "}", "throw", "new", "IllegalArgumentException", "(", "\"\"", "+", "val", "+", "\"", "to", "float\"", ")", ";", "}", "}", ";", "type_mapper", ".", "put", "(", "Float", ".", "class", ",", "float_mapper", ")", ";", "type_mapper", ".", "put", "(", "float", ".", "class", ",", "float_mapper", ")", ";", "Mapper", "bool_mapper", "=", "new", "Mapper", "(", ")", "{", "public", "Object", "map", "(", "EObject", "val", ")", "{", "EAtom", "bool", ";", "if", "(", "(", "bool", "=", "val", ".", "testBoolean", "(", ")", ")", "!=", "null", ")", "{", "if", "(", "bool", "==", "ERT", ".", "TRUE", ")", "return", "Boolean", ".", "TRUE", ";", "if", "(", "bool", "==", "ERT", ".", "FALSE", ")", "return", "Boolean", ".", "FALSE", ";", "}", "throw", "new", "IllegalArgumentException", "(", ")", ";", "}", "}", ";", "type_mapper", ".", "put", "(", "boolean", ".", "class", ",", "bool_mapper", ")", ";", "type_mapper", ".", "put", "(", "Boolean", ".", "class", ",", "bool_mapper", ")", ";", "}", "public", "EFun", "resolve_fun", "(", "final", "EAtom", "f", ",", "final", "int", "arity", ")", "{", "return", "EFun", ".", "get_fun_with_handler", "(", "\"\"", ",", "f", ".", "toString", "(", ")", ",", "arity", ",", "new", "EFunHandler", "(", ")", "{", "@", "Override", "public", "EObject", "invoke", "(", "EProc", "proc", ",", "EObject", "[", "]", "args", ")", "throws", "Pausable", "{", "if", "(", "real_object", "==", "null", ")", "{", "throw", "new", "ErlangError", "(", "am_null_pointer_exception", ")", ";", "}", "Method", "[", "]", "methods", "=", "real_object", ".", "getClass", "(", ")", ".", "getMethods", "(", ")", ";", "return", "choose_and_invoke_method", "(", "proc", ",", "real_object", ",", "f", ",", "args", ",", "methods", ",", "false", ")", ";", "}", "}", ",", "JavaObject", ".", "class", ".", "getClassLoader", "(", ")", ")", ";", "}", "public", "static", "EObject", "choose_and_invoke_method", "(", "EProc", "self", ",", "Object", "target", ",", "final", "EAtom", "method_name", ",", "EObject", "[", "]", "args", ",", "Method", "[", "]", "methods", ",", "boolean", "static_only", ")", "{", "for", "(", "int", "i", "=", "0", ";", "i", "<", "methods", ".", "length", ";", "i", "++", ")", "{", "Method", "m", "=", "methods", "[", "i", "]", ";", "int", "modifier", "=", "m", ".", "getModifiers", "(", ")", ";", "boolean", "is_static", "=", "(", "Modifier", ".", "STATIC", "&", "modifier", ")", "==", "Modifier", ".", "STATIC", ";", "if", "(", "is_static", "!=", "static_only", ")", "continue", ";", "if", "(", "!", "m", ".", "getName", "(", ")", ".", "equals", "(", "method_name", ".", "getName", "(", ")", ")", ")", "continue", ";", "Class", "<", "?", ">", "[", "]", "pt", "=", "m", ".", "getParameterTypes", "(", ")", ";", "if", "(", "pt", ".", "length", "!=", "args", ".", "length", ")", "continue", ";", "Object", "[", "]", "a", ";", "try", "{", "a", "=", "convert_args", "(", "self", ",", "pt", ",", "args", ")", ";", "}", "catch", "(", "IllegalArgumentException", "e", ")", "{", "continue", ";", "}", "Object", "result", ";", "try", "{", "result", "=", "m", ".", "invoke", "(", "target", ",", "a", ")", ";", "}", "catch", "(", "IllegalArgumentException", "e", ")", "{", "throw", "ERT", ".", "badarg", "(", "args", ")", ";", "}", "catch", "(", "IllegalAccessException", "e", ")", "{", "throw", "new", "ErlangError", "(", "am_badaccess", ",", "args", ")", ";", "}", "catch", "(", "InvocationTargetException", "e", ")", "{", "Throwable", "te", "=", "e", ".", "getTargetException", "(", ")", ";", "if", "(", "te", "instanceof", "ErlangException", ")", "{", "throw", "(", "ErlangException", ")", "te", ";", "}", "else", "{", "ETuple", "reason", "=", "ETuple", ".", "make", "(", "EAtom", ".", "intern", "(", "te", ".", "getClass", "(", ")", ".", "getName", "(", ")", ")", ",", "EString", ".", "fromString", "(", "te", ".", "getMessage", "(", ")", ")", ")", ";", "throw", "new", "ErlangError", "(", "reason", ",", "args", ")", ";", "}", "}", "if", "(", "m", ".", "getReturnType", "(", ")", "==", "Void", ".", "TYPE", ")", "{", "return", "ERT", ".", "am_ok", ";", "}", "return", "JavaObject", ".", "box", "(", "self", ",", "result", ")", ";", "}", "throw", "new", "ErlangError", "(", "am_badfun", ",", "args", ")", ";", "}", "public", "static", "EObject", "choose_and_invoke_constructor", "(", "EProc", "self", ",", "EObject", "[", "]", "args", ",", "Constructor", "<", "?", ">", "[", "]", "cons", ")", "{", "for", "(", "int", "i", "=", "0", ";", "i", "<", "cons", ".", "length", ";", "i", "++", ")", "{", "Constructor", "<", "?", ">", "m", "=", "cons", "[", "i", "]", ";", "Class", "<", "?", ">", "[", "]", "pt", "=", "m", ".", "getParameterTypes", "(", ")", ";", "if", "(", "pt", ".", "length", "!=", "args", ".", "length", ")", "continue", ";", "Object", "[", "]", "a", ";", "try", "{", "a", "=", "convert_args", "(", "self", ",", "pt", ",", "args", ")", ";", "}", "catch", "(", "IllegalArgumentException", "e", ")", "{", "continue", ";", "}", "Object", "result", ";", "try", "{", "result", "=", "m", ".", "newInstance", "(", "a", ")", ";", "}", "catch", "(", "InstantiationException", "e", ")", "{", "throw", "ERT", ".", "badarg", "(", "args", ")", ";", "}", "catch", "(", "IllegalArgumentException", "e", ")", "{", "throw", "ERT", ".", "badarg", "(", "args", ")", ";", "}", "catch", "(", "IllegalAccessException", "e", ")", "{", "throw", "new", "ErlangError", "(", "am_badaccess", ",", "args", ")", ";", "}", "catch", "(", "InvocationTargetException", "e", ")", "{", "Throwable", "te", "=", "e", ".", "getTargetException", "(", ")", ";", "if", "(", "te", "instanceof", "ErlangException", ")", "{", "throw", "(", "ErlangException", ")", "te", ";", "}", "else", "{", "ETuple", "reason", "=", "ETuple", ".", "make", "(", "EAtom", ".", "intern", "(", "te", ".", "getClass", "(", ")", ".", "getName", "(", ")", ")", ",", "EString", ".", "fromString", "(", "te", ".", "getMessage", "(", ")", ")", ")", ";", "throw", "new", "ErlangError", "(", "reason", ",", "args", ")", ";", "}", "}", "return", "JavaObject", ".", "box", "(", "self", ",", "result", ")", ";", "}", "throw", "new", "ErlangError", "(", "am_badfun", ",", "args", ")", ";", "}", "}", "</s>" ]
7,775
[ "<s>", "package", "erjang", ".", "m", ".", "java", ";", "import", "java", ".", "lang", ".", "reflect", ".", "Array", ";", "import", "erjang", ".", "EList", ";", "import", "erjang", ".", "EObject", ";", "import", "erjang", ".", "EProc", ";", "import", "erjang", ".", "ERT", ";", "import", "erjang", ".", "ESeq", ";", "class", "JavaArray", "extends", "ESeq", "{", "private", "final", "int", "idx", ";", "private", "final", "Object", "arr", ";", "private", "EProc", "self", ";", "static", "ESeq", "box", "(", "EProc", "self", ",", "Object", "arr", ",", "int", "idx", ")", "{", "if", "(", "Array", ".", "getLength", "(", "arr", ")", "==", "idx", ")", "return", "ERT", ".", "NIL", ";", "return", "new", "JavaArray", "(", "self", ",", "arr", ",", "idx", ")", ";", "}", "private", "JavaArray", "(", "EProc", "self", ",", "Object", "arr", ",", "int", "idx", ")", "{", "this", ".", "arr", "=", "arr", ";", "this", ".", "idx", "=", "idx", ";", "this", ".", "self", "=", "self", ";", "}", "@", "Override", "public", "ESeq", "cons", "(", "EObject", "h", ")", "{", "return", "new", "EList", "(", "h", ",", "this", ")", ";", "}", "@", "Override", "public", "ESeq", "tail", "(", ")", "{", "return", "box", "(", "self", ",", "arr", ",", "idx", "+", "1", ")", ";", "}", "@", "Override", "public", "EObject", "head", "(", ")", "{", "return", "JavaObject", ".", "box", "(", "self", ",", "Array", ".", "get", "(", "arr", ",", "idx", ")", ")", ";", "}", "}", "</s>" ]
7,776
[ "<s>", "package", "erjang", ".", "m", ".", "java", ";", "import", "java", ".", "util", ".", "Iterator", ";", "import", "java", ".", "util", ".", "Map", ";", "import", "java", ".", "util", ".", "Map", ".", "Entry", ";", "import", "erjang", ".", "ECons", ";", "import", "erjang", ".", "EList", ";", "import", "erjang", ".", "ENil", ";", "import", "erjang", ".", "EObject", ";", "import", "erjang", ".", "EProc", ";", "import", "erjang", ".", "ERT", ";", "import", "erjang", ".", "ESeq", ";", "import", "erjang", ".", "ETuple2", ";", "class", "JavaMapIterator", "extends", "ESeq", "{", "final", "Iterator", "<", "Entry", ">", "rest", ";", "final", "Entry", "<", "?", ",", "?", ">", "ent", ";", "private", "EProc", "self", ";", "@", "Override", "public", "ECons", "testNonEmptyList", "(", ")", "{", "return", "this", ";", "}", "@", "Override", "public", "boolean", "isNil", "(", ")", "{", "return", "false", ";", "}", "@", "Override", "public", "ENil", "testNil", "(", ")", "{", "return", "null", ";", "}", "@", "SuppressWarnings", "(", "\"unchecked\"", ")", "static", "ESeq", "box", "(", "EProc", "self", ",", "Iterator", "<", "Map", ".", "Entry", ">", "iterator", ")", "{", "if", "(", "iterator", ".", "hasNext", "(", ")", ")", "return", "new", "JavaMapIterator", "(", "self", ",", "iterator", ")", ";", "return", "ERT", ".", "NIL", ";", "}", "@", "SuppressWarnings", "(", "\"unchecked\"", ")", "private", "JavaMapIterator", "(", "EProc", "self", ",", "Iterator", "<", "Map", ".", "Entry", ">", "it", ")", "{", "ent", "=", "it", ".", "next", "(", ")", ";", "this", ".", "rest", "=", "it", ";", "this", ".", "self", "=", "self", ";", "}", "@", "Override", "public", "ESeq", "cons", "(", "EObject", "h", ")", "{", "return", "new", "EList", "(", "h", ",", "this", ")", ";", "}", "@", "Override", "public", "ESeq", "tail", "(", ")", "{", "ESeq", "tail", "=", "box", "(", "self", ",", "rest", ")", ";", "return", "tail", ";", "}", "@", "Override", "public", "EObject", "head", "(", ")", "{", "return", "new", "ETuple2", "(", "JavaObject", ".", "box", "(", "self", ",", "ent", ".", "getKey", "(", ")", ")", ",", "JavaObject", ".", "box", "(", "self", ",", "ent", ".", "getValue", "(", ")", ")", ")", ";", "}", "@", "Override", "public", "int", "hashCode", "(", ")", "{", "return", "rest", ".", "hashCode", "(", ")", ";", "}", "}", "</s>" ]
7,777
[ "<s>", "package", "erjang", ".", "m", ".", "java", ";", "import", "java", ".", "util", ".", "Iterator", ";", "import", "erjang", ".", "EList", ";", "import", "erjang", ".", "EObject", ";", "import", "erjang", ".", "EProc", ";", "import", "erjang", ".", "ERT", ";", "import", "erjang", ".", "ESeq", ";", "class", "JavaIterator", "extends", "ESeq", "{", "Iterator", "<", "?", ">", "rest", ";", "Object", "head", ";", "private", "EProc", "self", ";", "static", "ESeq", "box", "(", "EProc", "self", ",", "Iterator", "<", "?", ">", "it", ")", "{", "if", "(", "it", ".", "hasNext", "(", ")", ")", "return", "new", "JavaIterator", "(", "self", ",", "it", ")", ";", "return", "ERT", ".", "NIL", ";", "}", "private", "JavaIterator", "(", "EProc", "self", ",", "Iterator", "<", "?", ">", "it", ")", "{", "this", ".", "head", "=", "it", ".", "next", "(", ")", ";", "this", ".", "rest", "=", "it", ";", "this", ".", "self", "=", "self", ";", "}", "@", "Override", "public", "ESeq", "cons", "(", "EObject", "h", ")", "{", "return", "new", "EList", "(", "h", ",", "this", ")", ";", "}", "@", "Override", "public", "ESeq", "tail", "(", ")", "{", "return", "box", "(", "self", ",", "rest", ")", ";", "}", "@", "Override", "public", "EObject", "head", "(", ")", "{", "return", "JavaObject", ".", "box", "(", "self", ",", "head", ")", ";", "}", "@", "Override", "public", "int", "hashCode", "(", ")", "{", "return", "head", ".", "hashCode", "(", ")", "+", "rest", ".", "hashCode", "(", ")", ";", "}", "}", "</s>" ]
7,778
[ "<s>", "package", "erjang", ".", "m", ".", "java", ";", "import", "erjang", ".", "ECons", ";", "import", "erjang", ".", "EList", ";", "import", "erjang", ".", "EObject", ";", "import", "erjang", ".", "EProc", ";", "import", "erjang", ".", "ERT", ";", "import", "erjang", ".", "ESeq", ";", "import", "erjang", ".", "ESmall", ";", "import", "erjang", ".", "EString", ";", "import", "erjang", ".", "EStringList", ";", "class", "JavaCharSeq", "extends", "ESeq", "{", "private", "final", "CharSequence", "seq", ";", "private", "final", "int", "pos", ";", "private", "EProc", "self", ";", "public", "ECons", "testNonEmptyList", "(", ")", "{", "if", "(", "seq", ".", "length", "(", ")", "==", "pos", ")", "return", "null", ";", "return", "this", ";", "}", "@", "Override", "public", "EString", "testString", "(", ")", "{", "return", "EString", ".", "make", "(", "seq", ",", "pos", ",", "seq", ".", "length", "(", ")", ")", ";", "}", "static", "ESeq", "box", "(", "EProc", "self", ",", "CharSequence", "cs", ",", "int", "pos", ")", "{", "if", "(", "cs", ".", "length", "(", ")", "==", "pos", ")", "return", "ERT", ".", "NIL", ";", "return", "new", "JavaCharSeq", "(", "self", ",", "cs", ",", "pos", ")", ";", "}", "private", "JavaCharSeq", "(", "EProc", "self", ",", "CharSequence", "cs", ",", "int", "pos", ")", "{", "this", ".", "seq", "=", "cs", ";", "this", ".", "pos", "=", "pos", ";", "this", ".", "self", "=", "self", ";", "}", "@", "Override", "public", "ESeq", "cons", "(", "EObject", "h", ")", "{", "ESmall", "s", ";", "if", "(", "(", "s", "=", "h", ".", "testSmall", "(", ")", ")", "!=", "null", ")", "{", "if", "(", "(", "s", ".", "value", "&", "0xff", ")", "==", "s", ".", "value", ")", "{", "return", "new", "EStringList", "(", "(", "byte", ")", "s", ".", "value", ",", "this", ")", ";", "}", "}", "return", "new", "EList", "(", "h", ",", "this", ")", ";", "}", "@", "Override", "public", "ESeq", "tail", "(", ")", "{", "return", "box", "(", "self", ",", "seq", ",", "pos", "+", "1", ")", ";", "}", "@", "Override", "public", "EObject", "head", "(", ")", "{", "return", "ERT", ".", "box", "(", "seq", ".", "charAt", "(", "pos", ")", ")", ";", "}", "@", "Override", "public", "int", "hashCode", "(", ")", "{", "return", "seq", ".", "hashCode", "(", ")", ";", "}", "}", "</s>" ]
7,779
[ "<s>", "package", "erjang", ".", "m", ".", "prim_file", ";", "import", "java", ".", "util", ".", "ArrayList", ";", "import", "java", ".", "util", ".", "List", ";", "import", "erjang", ".", "BIF", ";", "import", "erjang", ".", "EBinary", ";", "import", "erjang", ".", "ENative", ";", "import", "erjang", ".", "EObject", ";", "import", "erjang", ".", "ERT", ";", "import", "erjang", ".", "ESeq", ";", "import", "erjang", ".", "EString", ";", "public", "class", "Native", "extends", "ENative", "{", "@", "BIF", "public", "static", "EObject", "internal_name2native", "(", "EObject", "arg", ")", "{", "if", "(", "arg", ".", "testAtom", "(", ")", "!=", "null", ")", "{", "throw", "ERT", ".", "badarg", "(", "arg", ")", ";", "}", "else", "if", "(", "arg", ".", "testBinary", "(", ")", "!=", "null", ")", "{", "EBinary", "bin", "=", "arg", ".", "testBinary", "(", ")", ";", "byte", "[", "]", "binbytes", "=", "bin", ".", "getByteArray", "(", ")", ";", "byte", "[", "]", "outbytes", "=", "new", "byte", "[", "binbytes", ".", "length", "+", "1", "]", ";", "System", ".", "arraycopy", "(", "binbytes", ",", "0", ",", "outbytes", ",", "0", ",", "binbytes", ".", "length", ")", ";", "outbytes", "[", "outbytes", ".", "length", "-", "1", "]", "=", "0x0", ";", "return", "new", "EBinary", "(", "outbytes", ")", ";", "}", "else", "{", "ESeq", "input", "=", "arg", ".", "testSeq", "(", ")", ";", "List", "<", "Byte", ">", "bytes", "=", "new", "ArrayList", "<", "Byte", ">", "(", ")", ";", "byte", "[", "]", "out", ";", "while", "(", "!", "input", ".", "isNil", "(", ")", ")", "{", "Integer", "el", "=", "input", ".", "head", "(", ")", ".", "testSmall", "(", ")", ".", "intValue", "(", ")", ";", "bytes", ".", "add", "(", "el", ".", "byteValue", "(", ")", ")", ";", "input", "=", "input", ".", "tail", "(", ")", ";", "}", "out", "=", "new", "byte", "[", "bytes", ".", "size", "(", ")", "+", "1", "]", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "bytes", ".", "size", "(", ")", ";", "++", "i", ")", "{", "out", "[", "i", "]", "=", "bytes", ".", "get", "(", "i", ")", ";", "}", "out", "[", "out", ".", "length", "-", "1", "]", "=", "0x0", ";", "return", "new", "EBinary", "(", "out", ")", ";", "}", "}", "@", "BIF", "public", "static", "EObject", "internal_native2name", "(", "EObject", "arg", ")", "{", "EBinary", "bin", "=", "arg", ".", "testBinary", "(", ")", ";", "byte", "[", "]", "binbytes", ";", "if", "(", "bin", "==", "null", ")", "{", "throw", "ERT", ".", "badarg", "(", "arg", ")", ";", "}", "binbytes", "=", "bin", ".", "getByteArray", "(", ")", ";", "String", "out", "=", "new", "String", "(", "binbytes", ")", ";", "return", "new", "EString", "(", "out", ")", ";", "}", "}", "</s>" ]
7,780
[ "<s>", "package", "erjang", ".", "m", ".", "net_kernel", ";", "import", "erjang", ".", "ENative", ";", "import", "erjang", ".", "BIF", ";", "import", "erjang", ".", "EObject", ";", "import", "erjang", ".", "EAtom", ";", "import", "erjang", ".", "EPID", ";", "import", "erjang", ".", "ERT", ";", "public", "class", "Native", "extends", "ENative", "{", "@", "BIF", "public", "static", "EAtom", "dflag_unicode_io", "(", "EObject", "pid0", ")", "{", "EPID", "pid", ";", "if", "(", "(", "pid", "=", "pid0", ".", "testPID", "(", ")", ")", "==", "null", ")", "throw", "ERT", ".", "badarg", "(", "pid0", ")", ";", "return", "ERT", ".", "TRUE", ";", "}", "}", "</s>" ]
7,781
[ "<s>", "package", "erjang", ".", "m", ".", "erl_ddll", ";", "import", "java", ".", "util", ".", "logging", ".", "Level", ";", "import", "erjang", ".", "BIF", ";", "import", "erjang", ".", "ENative", ";", "import", "erjang", ".", "EObject", ";", "import", "erjang", ".", "ERT", ";", "import", "erjang", ".", "EAtom", ";", "import", "erjang", ".", "ETuple2", ";", "import", "erjang", ".", "NotImplemented", ";", "import", "erjang", ".", "driver", ".", "Drivers", ";", "public", "class", "Native", "extends", "ENative", "{", "static", "EAtom", "am_crypto_drv", "=", "EAtom", ".", "intern", "(", "\"crypto_drv\"", ")", ";", "static", "EAtom", "am_ok", "=", "EAtom", ".", "intern", "(", "\"ok\"", ")", ";", "static", "EAtom", "am_loaded", "=", "EAtom", ".", "intern", "(", "\"loaded\"", ")", ";", "@", "BIF", "public", "static", "ETuple2", "loaded_drivers", "(", ")", "{", "return", "new", "ETuple2", "(", "ERT", ".", "am_ok", ",", "Drivers", ".", "getLoaded", "(", ")", ")", ";", "}", "@", "BIF", "public", "static", "EObject", "info", "(", "EObject", "driver", ",", "EObject", "what", ")", "{", "return", "ERT", ".", "am_undefined", ";", "}", "@", "BIF", "public", "static", "EObject", "try_load", "(", "EObject", "path", ",", "EObject", "driver", ",", "EObject", "options", ")", "{", "if", "(", "log", ".", "isLoggable", "(", "Level", ".", "FINE", ")", ")", "log", ".", "fine", "(", "\"\"", "+", "driver", ")", ";", "return", "new", "ETuple2", "(", "am_ok", ",", "am_loaded", ")", ";", "}", "@", "BIF", "public", "static", "EObject", "try_unload", "(", "EObject", "driver", ",", "EObject", "options", ")", "{", "throw", "new", "NotImplemented", "(", ")", ";", "}", "@", "BIF", "public", "static", "EObject", "format_error_int", "(", "EObject", "err", ")", "{", "throw", "new", "NotImplemented", "(", ")", ";", "}", "}", "</s>" ]
7,782
[ "<s>", "package", "erjang", ".", "m", ".", "re", ";", "import", "java", ".", "io", ".", "CharArrayWriter", ";", "import", "java", ".", "io", ".", "IOException", ";", "import", "java", ".", "io", ".", "StringWriter", ";", "import", "java", ".", "io", ".", "UnsupportedEncodingException", ";", "import", "java", ".", "nio", ".", "ByteBuffer", ";", "import", "java", ".", "nio", ".", "charset", ".", "Charset", ";", "import", "java", ".", "util", ".", "ArrayList", ";", "import", "java", ".", "util", ".", "List", ";", "import", "java", ".", "util", ".", "regex", ".", "MatchResult", ";", "import", "java", ".", "util", ".", "regex", ".", "Matcher", ";", "import", "java", ".", "util", ".", "regex", ".", "Pattern", ";", "import", "java", ".", "util", ".", "regex", ".", "PatternSyntaxException", ";", "import", "erjang", ".", "BIF", ";", "import", "erjang", ".", "CharCollector", ";", "import", "erjang", ".", "EAtom", ";", "import", "erjang", ".", "EBigString", ";", "import", "erjang", ".", "EBinary", ";", "import", "erjang", ".", "ENative", ";", "import", "erjang", ".", "EObject", ";", "import", "erjang", ".", "ERT", ";", "import", "erjang", ".", "ESeq", ";", "import", "erjang", ".", "ESmall", ";", "import", "erjang", ".", "EString", ";", "import", "erjang", ".", "ETuple", ";", "import", "erjang", ".", "ETuple2", ";", "import", "erjang", ".", "NotImplemented", ";", "import", "erjang", ".", "CharCollector", ".", "CollectingException", ";", "import", "erjang", ".", "CharCollector", ".", "InvalidElementException", ";", "import", "erjang", ".", "CharCollector", ".", "PartialDecodingException", ";", "public", "class", "Native", "extends", "ENative", "{", "private", "static", "final", "boolean", "INDEX_COMPATIBLE", "=", "true", ";", "public", "static", "EAtom", "am_nomatch", "=", "EAtom", ".", "intern", "(", "\"nomatch\"", ")", ";", "public", "static", "EAtom", "am_match", "=", "EAtom", ".", "intern", "(", "\"match\"", ")", ";", "public", "static", "EAtom", "am_latin1", "=", "EAtom", ".", "intern", "(", "\"latin1\"", ")", ";", "public", "static", "EAtom", "am_unicode", "=", "EAtom", ".", "intern", "(", "\"unicode\"", ")", ";", "public", "static", "EAtom", "am_anchored", "=", "EAtom", ".", "intern", "(", "\"anchored\"", ")", ";", "public", "static", "EAtom", "am_caseless", "=", "EAtom", ".", "intern", "(", "\"caseless\"", ")", ";", "public", "static", "EAtom", "am_dollar_endonly", "=", "EAtom", ".", "intern", "(", "\"\"", ")", ";", "public", "static", "EAtom", "am_dotall", "=", "EAtom", ".", "intern", "(", "\"dotall\"", ")", ";", "public", "static", "EAtom", "am_extended", "=", "EAtom", ".", "intern", "(", "\"extended\"", ")", ";", "public", "static", "EAtom", "am_firstline", "=", "EAtom", ".", "intern", "(", "\"firstline\"", ")", ";", "public", "static", "EAtom", "am_multiline", "=", "EAtom", ".", "intern", "(", "\"multiline\"", ")", ";", "public", "static", "EAtom", "am_no_auto_capture", "=", "EAtom", ".", "intern", "(", "\"\"", ")", ";", "public", "static", "EAtom", "am_dupnames", "=", "EAtom", ".", "intern", "(", "\"dupnames\"", ")", ";", "public", "static", "EAtom", "am_ungreedy", "=", "EAtom", ".", "intern", "(", "\"ungreedy\"", ")", ";", "public", "static", "EAtom", "am_newline", "=", "EAtom", ".", "intern", "(", "\"newline\"", ")", ";", "public", "static", "EAtom", "am_bsr_anycrlf", "=", "EAtom", ".", "intern", "(", "\"bsr_anycrlf\"", ")", ";", "public", "static", "EAtom", "am_bsr_unicode", "=", "EAtom", ".", "intern", "(", "\"bsr_unicode\"", ")", ";", "public", "static", "EAtom", "am_cr", "=", "EAtom", ".", "intern", "(", "\"cr\"", ")", ";", "public", "static", "EAtom", "am_lf", "=", "EAtom", ".", "intern", "(", "\"lf\"", ")", ";", "public", "static", "EAtom", "am_crlf", "=", "EAtom", ".", "intern", "(", "\"crlf\"", ")", ";", "public", "static", "EAtom", "am_anycrlf", "=", "EAtom", ".", "intern", "(", "\"anycrlf\"", ")", ";", "public", "static", "EAtom", "am_any", "=", "EAtom", ".", "intern", "(", "\"any\"", ")", ";", "public", "static", "EAtom", "am_global", "=", "EAtom", ".", "intern", "(", "\"global\"", ")", ";", "public", "static", "EAtom", "am_none", "=", "EAtom", ".", "intern", "(", "\"none\"", ")", ";", "public", "static", "EAtom", "am_index", "=", "EAtom", ".", "intern", "(", "\"index\"", ")", ";", "public", "static", "EAtom", "am_binary", "=", "EAtom", ".", "intern", "(", "\"binary\"", ")", ";", "public", "static", "EAtom", "am_list", "=", "EAtom", ".", "intern", "(", "\"list\"", ")", ";", "public", "static", "EAtom", "am_all", "=", "EAtom", ".", "intern", "(", "\"all\"", ")", ";", "public", "static", "EAtom", "am_first", "=", "EAtom", ".", "intern", "(", "\"first\"", ")", ";", "public", "static", "EAtom", "am_all_but_first", "=", "EAtom", ".", "intern", "(", "\"\"", ")", ";", "public", "static", "EAtom", "am_capture", "=", "EAtom", ".", "intern", "(", "\"capture\"", ")", ";", "public", "static", "EAtom", "am_offset", "=", "EAtom", ".", "intern", "(", "\"offset\"", ")", ";", "@", "BIF", "public", "static", "EObject", "run", "(", "EObject", "subject", ",", "EObject", "pattern", ")", "{", "return", "run", "(", "subject", ",", "pattern", ",", "ERT", ".", "NIL", ")", ";", "}", "@", "BIF", "static", "public", "EObject", "run", "(", "EObject", "subj", ",", "EObject", "re", ",", "EObject", "opts", ")", "{", "try", "{", "EObject", "res", "=", "run2", "(", "subj", ",", "re", ",", "opts", ")", ";", "return", "res", ";", "}", "catch", "(", "RuntimeException", "e", ")", "{", "e", ".", "printStackTrace", "(", ")", ";", "throw", "e", ";", "}", "}", "static", "public", "EObject", "run2", "(", "EObject", "subj", ",", "EObject", "re", ",", "EObject", "opts", ")", "{", "ECompiledRE", "regex", ";", "if", "(", "re", "instanceof", "ECompiledRE", ")", "{", "regex", "=", "(", "ECompiledRE", ")", "re", ";", "}", "else", "{", "ETuple2", "res", "=", "compile", "(", "re", ",", "opts", ")", ";", "EObject", "val", "=", "res", ".", "elem2", ";", "if", "(", "res", ".", "elem1", "==", "ERT", ".", "am_ok", "&&", "(", "val", "instanceof", "ECompiledRE", ")", ")", "{", "regex", "=", "(", "ECompiledRE", ")", "val", ";", "}", "else", "{", "return", "val", ";", "}", "}", "ESeq", "o", "=", "opts", ".", "testSeq", "(", ")", ";", "Options", "o2", "=", "new", "Options", "(", ")", ";", "if", "(", "!", "o2", ".", "init", "(", "o", ")", ")", "{", "throw", "ERT", ".", "badarg", "(", "subj", ",", "re", ",", "opts", ")", ";", "}", "String", "subject", "=", "regex", ".", "options", ".", "decode", "(", "subj", ")", ";", "if", "(", "subject", "==", "null", ")", "{", "throw", "ERT", ".", "badarg", "(", "subj", ",", "re", ",", "opts", ")", ";", "}", "if", "(", "o2", ".", "offset", ">", "subject", ".", "length", "(", ")", "||", "o2", ".", "offset", "<", "0", ")", "{", "throw", "ERT", ".", "badarg", "(", "subj", ",", "re", ",", "opts", ")", ";", "}", "Matcher", "matcher", "=", "regex", ".", "patt", ".", "matcher", "(", "subject", ".", "substring", "(", "o2", ".", "offset", ")", ")", ";", "if", "(", "o2", ".", "global", ")", "{", "throw", "new", "NotImplemented", "(", "\"\"", ")", ";", "}", "else", "{", "if", "(", "matcher", ".", "find", "(", ")", ")", "{", "if", "(", "o2", ".", "capture_spec", "==", "am_none", ")", "{", "return", "am_match", ";", "}", "MatchResult", "mr", "=", "matcher", ".", "toMatchResult", "(", ")", ";", "ESeq", "il", ";", "if", "(", "o2", ".", "capture_spec", "==", "am_all", ")", "{", "ESeq", "l", "=", "ERT", ".", "NIL", ";", "for", "(", "int", "i", "=", "mr", ".", "groupCount", "(", ")", ";", "i", ">=", "0", ";", "i", "--", ")", "{", "l", "=", "l", ".", "cons", "(", "capture", "(", "subject", ",", "mr", ",", "i", ",", "o2", ")", ")", ";", "}", "return", "new", "ETuple2", "(", "am_match", ",", "l", ")", ";", "}", "else", "if", "(", "o2", ".", "capture_spec", "==", "am_all_but_first", ")", "{", "ESeq", "l", "=", "ERT", ".", "NIL", ";", "for", "(", "int", "i", "=", "mr", ".", "groupCount", "(", ")", ";", "i", ">", "0", ";", "i", "--", ")", "{", "l", "=", "l", ".", "cons", "(", "capture", "(", "subject", ",", "mr", ",", "i", ",", "o2", ")", ")", ";", "}", "return", "new", "ETuple2", "(", "am_match", ",", "l", ")", ";", "}", "else", "if", "(", "o2", ".", "capture_spec", "==", "am_first", ")", "{", "EObject", "l", "=", "capture", "(", "subject", ",", "mr", ",", "0", ",", "o2", ")", ";", "return", "new", "ETuple2", "(", "am_match", ",", "l", ")", ";", "}", "else", "if", "(", "(", "il", "=", "o2", ".", "capture_spec", ".", "testSeq", "(", ")", ")", "!=", "null", ")", "{", "ESeq", "out", "=", "ERT", ".", "NIL", ";", "for", "(", ";", "!", "il", ".", "isNil", "(", ")", ";", "il", "=", "il", ".", "tail", "(", ")", ")", "{", "ESmall", "idx", "=", "il", ".", "head", "(", ")", ".", "testSmall", "(", ")", ";", "EObject", "val", "=", "capture", "(", "subject", ",", "mr", ",", "idx", ".", "value", ",", "o2", ")", ";", "out", "=", "out", ".", "cons", "(", "val", ")", ";", "}", "return", "new", "ETuple2", "(", "am_match", ",", "out", ")", ";", "}", "else", "{", "throw", "ERT", ".", "badarg", "(", "subj", ",", "re", ",", "opts", ")", ";", "}", "}", "else", "{", "return", "am_nomatch", ";", "}", "}", "}", "private", "static", "EObject", "capture", "(", "String", "subject", ",", "MatchResult", "mr", ",", "int", "group_index", ",", "Options", "opts", ")", "{", "int", "start", "=", "mr", ".", "start", "(", "group_index", ")", ";", "int", "end", "=", "mr", ".", "end", "(", "group_index", ")", ";", "if", "(", "opts", ".", "capture_type", "==", "am_index", ")", "{", "if", "(", "INDEX_COMPATIBLE", "&&", "opts", ".", "unicode", ")", "{", "try", "{", "int", "istart", "=", "subject", ".", "substring", "(", "0", ",", "start", ")", ".", "getBytes", "(", "\"UTF8\"", ")", ".", "length", ";", "int", "ilen", "=", "subject", ".", "substring", "(", "start", ",", "end", ")", ".", "getBytes", "(", "\"UTF8\"", ")", ".", "length", ";", "return", "new", "ETuple2", "(", "ERT", ".", "box", "(", "istart", ")", ",", "ERT", ".", "box", "(", "ilen", ")", ")", ";", "}", "catch", "(", "UnsupportedEncodingException", "e", ")", "{", "throw", "new", "InternalError", "(", ")", ";", "}", "}", "return", "new", "ETuple2", "(", "ERT", ".", "box", "(", "start", ")", ",", "ERT", ".", "box", "(", "end", "-", "start", ")", ")", ";", "}", "else", "if", "(", "opts", ".", "capture_type", "==", "am_list", ")", "{", "String", "sub", "=", "subject", ".", "substring", "(", "start", ",", "end", ")", ";", "EBigString", "ebs", "=", "EBigString", ".", "fromString", "(", "sub", ")", ";", "return", "erjang", ".", "m", ".", "unicode", ".", "Native", ".", "characters_to_list", "(", "ebs", ",", "opts", ".", "unicode", "?", "am_unicode", ":", "am_latin1", ")", ";", "}", "else", "if", "(", "opts", ".", "capture_type", "==", "am_binary", ")", "{", "String", "sub", "=", "subject", ".", "substring", "(", "start", ",", "end", ")", ";", "EBigString", "ebs", "=", "EBigString", ".", "fromString", "(", "sub", ")", ";", "return", "erjang", ".", "m", ".", "unicode", ".", "Native", ".", "characters_to_binary", "(", "ebs", ",", "opts", ".", "unicode", "?", "am_unicode", ":", "am_latin1", ")", ";", "}", "else", "{", "throw", "new", "InternalError", "(", "\"\"", "+", "opts", ".", "capture_type", ")", ";", "}", "}", "@", "BIF", "static", "public", "EObject", "compile", "(", "EObject", "obj1", ")", "{", "return", "compile", "(", "obj1", ",", "ERT", ".", "NIL", ")", ";", "}", "static", "class", "Options", "implements", "java", ".", "lang", ".", "Cloneable", "{", "public", "int", "offset", "=", "0", ";", "public", "EObject", "capture_type", "=", "am_index", ";", "public", "EObject", "capture_spec", "=", "am_all", ";", "public", "boolean", "global", ";", "boolean", "unicode", "=", "false", ";", "boolean", "newline_cr", "=", "false", ";", "boolean", "newline_lf", "=", "true", ";", "boolean", "newline_crlf", "=", "false", ";", "boolean", "newline_any", "=", "false", ";", "int", "flags", "=", "0", ";", "boolean", "anchored", "=", "true", ";", "Options", "re_init", "(", "ESeq", "opts", ")", "{", "Options", "out", ";", "try", "{", "out", "=", "(", "Options", ")", "this", ".", "clone", "(", ")", ";", "}", "catch", "(", "CloneNotSupportedException", "e", ")", "{", "throw", "new", "InternalError", "(", ")", ";", "}", "out", ".", "init", "(", "opts", ")", ";", "return", "out", ";", "}", "boolean", "init", "(", "ESeq", "opts", ")", "{", "if", "(", "opts", "==", "null", ")", "return", "true", ";", "for", "(", ";", "!", "opts", ".", "isNil", "(", ")", ";", "opts", "=", "opts", ".", "tail", "(", ")", ")", "{", "EObject", "opt", "=", "opts", ".", "head", "(", ")", ";", "ETuple", "tup", ";", "ESmall", "off", ";", "if", "(", "opt", "==", "am_unicode", ")", "{", "unicode", "=", "true", ";", "}", "else", "if", "(", "opt", "==", "am_anchored", ")", "{", "anchored", "=", "true", ";", "}", "else", "if", "(", "opt", "==", "am_global", ")", "{", "global", "=", "true", ";", "}", "else", "if", "(", "opt", "==", "am_caseless", ")", "{", "flags", "|=", "Pattern", ".", "CASE_INSENSITIVE", ";", "}", "else", "if", "(", "opt", "==", "am_dollar_endonly", ")", "{", "throw", "new", "NotImplemented", "(", "\"\"", "+", "opt", ")", ";", "}", "else", "if", "(", "opt", "==", "am_dotall", ")", "{", "flags", "|=", "Pattern", ".", "DOTALL", ";", "}", "else", "if", "(", "opt", "==", "am_extended", ")", "{", "flags", "|=", "Pattern", ".", "COMMENTS", ";", "}", "else", "if", "(", "opt", "==", "am_firstline", ")", "{", "throw", "new", "NotImplemented", "(", "\"\"", "+", "opt", ")", ";", "}", "else", "if", "(", "opt", "==", "am_multiline", ")", "{", "flags", "|=", "Pattern", ".", "MULTILINE", ";", "}", "else", "if", "(", "opt", "==", "am_no_auto_capture", ")", "{", "throw", "new", "NotImplemented", "(", "\"\"", "+", "opt", ")", ";", "}", "else", "if", "(", "opt", "==", "am_dupnames", ")", "{", "throw", "new", "NotImplemented", "(", "\"\"", "+", "opt", ")", ";", "}", "else", "if", "(", "opt", "==", "am_ungreedy", ")", "{", "throw", "new", "NotImplemented", "(", "\"\"", "+", "opt", ")", ";", "}", "else", "if", "(", "opt", "==", "am_bsr_anycrlf", ")", "{", "newline_cr", "=", "true", ";", "newline_crlf", "=", "true", ";", "newline_lf", "=", "true", ";", "newline_any", "=", "false", ";", "}", "else", "if", "(", "opt", "==", "am_bsr_unicode", ")", "{", "newline_any", "=", "true", ";", "}", "else", "if", "(", "(", "tup", "=", "opt", ".", "testTuple", "(", ")", ")", "!=", "null", "&&", "tup", ".", "arity", "(", ")", "==", "2", "&&", "tup", ".", "elm", "(", "1", ")", "==", "am_newline", ")", "{", "newline_cr", "=", "false", ";", "newline_crlf", "=", "false", ";", "newline_lf", "=", "false", ";", "newline_any", "=", "false", ";", "EObject", "val", "=", "tup", ".", "elm", "(", "2", ")", ";", "if", "(", "val", "==", "am_cr", ")", "{", "newline_cr", "=", "true", ";", "}", "else", "if", "(", "val", "==", "am_lf", ")", "{", "newline_lf", "=", "true", ";", "}", "else", "if", "(", "val", "==", "am_crlf", ")", "{", "newline_crlf", "=", "true", ";", "}", "else", "if", "(", "val", "==", "am_anycrlf", ")", "{", "newline_cr", "=", "true", ";", "newline_lf", "=", "true", ";", "newline_crlf", "=", "true", ";", "}", "else", "if", "(", "val", "==", "am_any", ")", "{", "newline_any", "=", "true", ";", "}", "else", "{", "return", "false", ";", "}", "}", "else", "if", "(", "tup", "!=", "null", "&&", "tup", ".", "arity", "(", ")", "==", "2", "&&", "tup", ".", "elm", "(", "1", ")", "==", "am_capture", ")", "{", "this", ".", "capture_spec", "=", "tup", ".", "elm", "(", "2", ")", ";", "this", ".", "capture_type", "=", "am_index", ";", "}", "else", "if", "(", "tup", "!=", "null", "&&", "tup", ".", "arity", "(", ")", "==", "3", "&&", "tup", ".", "elm", "(", "1", ")", "==", "am_capture", ")", "{", "this", ".", "capture_spec", "=", "tup", ".", "elm", "(", "2", ")", ";", "this", ".", "capture_type", "=", "tup", ".", "elm", "(", "3", ")", ";", "}", "else", "if", "(", "tup", "!=", "null", "&&", "tup", ".", "arity", "(", ")", "==", "2", "&&", "tup", ".", "elm", "(", "1", ")", "==", "am_offset", "&&", "(", "off", "=", "tup", ".", "elm", "(", "2", ")", ".", "testSmall", "(", ")", ")", "!=", "null", ")", "{", "this", ".", "offset", "=", "off", ".", "value", ";", "}", "else", "{", "return", "false", ";", "}", "}", "ESeq", "spec", ";", "if", "(", "capture_spec", "==", "am_all", "||", "capture_spec", "==", "am_all_but_first", "||", "capture_spec", "==", "am_first", "||", "capture_spec", "==", "am_none", ")", "{", "}", "else", "if", "(", "(", "spec", "=", "capture_spec", ".", "testSeq", "(", ")", ")", "!=", "null", ")", "{", "while", "(", "!", "spec", ".", "isNil", "(", ")", ")", "{", "EObject", "val", "=", "spec", ".", "head", "(", ")", ";", "if", "(", "val", ".", "testSmall", "(", ")", "==", "null", ")", "return", "false", ";", "spec", "=", "spec", ".", "tail", "(", ")", ";", "}", "}", "else", "{", "return", "false", ";", "}", "if", "(", "capture_type", "==", "am_index", "||", "capture_type", "==", "am_list", "||", "capture_type", "==", "am_binary", ")", "{", "}", "else", "{", "return", "false", ";", "}", "if", "(", "unicode", "==", "true", "&&", "(", "(", "flags", "&", "Pattern", ".", "CASE_INSENSITIVE", ")", "!=", "0", ")", ")", "{", "flags", "|=", "Pattern", ".", "UNICODE_CASE", ";", "}", "if", "(", "newline_any", "==", "true", ")", "{", "}", "else", "if", "(", "newline_lf", "==", "true", "&&", "newline_cr", "==", "false", "&&", "newline_crlf", "==", "false", ")", "{", "flags", "|=", "Pattern", ".", "UNIX_LINES", ";", "}", "else", "{", "throw", "new", "NotImplemented", "(", "\"\"", "+", "newline_lf", "+", "\";", "cr=\"", "+", "newline_cr", "+", "\";", "crlf=\"", "+", "newline_crlf", ")", ";", "}", "return", "true", ";", "}", "String", "decode", "(", "EObject", "io_or_char_list", ")", "{", "String", "pattern", ";", "if", "(", "unicode", ")", "{", "CharArrayWriter", "out", "=", "new", "CharArrayWriter", "(", ")", ";", "Charset", "spec", "=", "Charset", ".", "forName", "(", "\"UTF-16BE\"", ")", ";", "CharCollector", "cc", "=", "new", "CharCollector", "(", "spec", ",", "out", ")", ";", "try", "{", "io_or_char_list", ".", "collectCharList", "(", "cc", ")", ";", "cc", ".", "end", "(", ")", ";", "}", "catch", "(", "CollectingException", "e", ")", "{", "return", "null", ";", "}", "catch", "(", "InvalidElementException", "e", ")", "{", "return", "null", ";", "}", "catch", "(", "IOException", "e", ")", "{", "return", "null", ";", "}", "catch", "(", "PartialDecodingException", "e", ")", "{", "return", "null", ";", "}", "pattern", "=", "out", ".", "toString", "(", ")", ";", "}", "else", "{", "EBinary", "bin", ";", "if", "(", "(", "bin", "=", "io_or_char_list", ".", "testBinary", "(", ")", ")", "!=", "null", ")", "{", "return", "EString", ".", "make", "(", "bin", ")", ".", "stringValue", "(", ")", ";", "}", "EString", "str", ";", "if", "(", "(", "str", "=", "io_or_char_list", ".", "testString", "(", ")", ")", "!=", "null", ")", "{", "return", "str", ".", "stringValue", "(", ")", ";", "}", "List", "<", "ByteBuffer", ">", "bb", "=", "new", "ArrayList", "<", "ByteBuffer", ">", "(", ")", ";", "if", "(", "io_or_char_list", ".", "collectIOList", "(", "bb", ")", ")", "{", "StringWriter", "sw", "=", "new", "StringWriter", "(", ")", ";", "for", "(", "ByteBuffer", "b", ":", "bb", ")", "{", "char", "ch", ";", "while", "(", "b", ".", "hasRemaining", "(", ")", ")", "{", "ch", "=", "(", "char", ")", "b", ".", "get", "(", ")", ";", "sw", ".", "append", "(", "ch", ")", ";", "}", "}", "pattern", "=", "sw", ".", "toString", "(", ")", ";", "}", "else", "{", "return", "null", ";", "}", "}", "return", "pattern", ";", "}", "}", "@", "BIF", "static", "public", "ETuple2", "compile", "(", "EObject", "obj1", ",", "EObject", "obj2", ")", "{", "ESeq", "opts", "=", "obj2", ".", "testSeq", "(", ")", ";", "Options", "o", "=", "new", "Options", "(", ")", ";", "if", "(", "!", "o", ".", "init", "(", "opts", ")", ")", "{", "throw", "ERT", ".", "badarg", "(", "obj1", ",", "obj2", ")", ";", "}", "String", "pattern", "=", "o", ".", "decode", "(", "obj1", ")", ";", "try", "{", "Pattern", "c", "=", "Pattern", ".", "compile", "(", "pattern", ",", "o", ".", "flags", ")", ";", "return", "new", "ETuple2", "(", "ERT", ".", "am_ok", ",", "new", "ECompiledRE", "(", "o", ",", "c", ")", ")", ";", "}", "catch", "(", "PatternSyntaxException", "e", ")", "{", "return", "new", "ETuple2", "(", "ERT", ".", "am_error", ",", "new", "ETuple2", "(", "EString", ".", "fromString", "(", "e", ".", "getDescription", "(", ")", ")", ",", "ERT", ".", "box", "(", "e", ".", "getIndex", "(", ")", ")", ")", ")", ";", "}", "}", "}", "</s>" ]
7,783
[ "<s>", "package", "erjang", ".", "m", ".", "re", ";", "import", "java", ".", "util", ".", "regex", ".", "Pattern", ";", "import", "erjang", ".", "EAtom", ";", "import", "erjang", ".", "EBinary", ";", "import", "erjang", ".", "EBitString", ";", "import", "erjang", ".", "EPseudoTerm", ";", "import", "erjang", ".", "ETuple", ";", "import", "erjang", ".", "ETuple2", ";", "import", "erjang", ".", "m", ".", "re", ".", "Native", ".", "Options", ";", "public", "class", "ECompiledRE", "extends", "EPseudoTerm", "{", "final", "Pattern", "patt", ";", "final", "Options", "options", ";", "ECompiledRE", "(", "Options", "options", ",", "Pattern", "patt", ")", "{", "this", ".", "options", "=", "options", ";", "this", ".", "patt", "=", "patt", ";", "}", "@", "Override", "public", "ETuple", "testTuple", "(", ")", "{", "return", "new", "ETuple2", "(", "EAtom", ".", "intern", "(", "\"re_pattern\"", ")", ",", "EBinary", ".", "EMPTY", ")", ";", "}", "@", "Override", "public", "EBinary", "testBinary", "(", ")", "{", "return", "null", ";", "}", "@", "Override", "public", "EBitString", "testBitString", "(", ")", "{", "return", "null", ";", "}", "@", "Override", "public", "int", "hashCode", "(", ")", "{", "return", "patt", ".", "hashCode", "(", ")", ";", "}", "}", "</s>" ]
7,784
[ "<s>", "package", "erjang", ".", "m", ".", "unicode", ";", "import", "erjang", ".", "EBigString", ";", "import", "erjang", ".", "ENative", ";", "import", "erjang", ".", "BIF", ";", "import", "erjang", ".", "EObject", ";", "import", "erjang", ".", "EAtom", ";", "import", "erjang", ".", "ESeq", ";", "import", "erjang", ".", "ETuple", ";", "import", "erjang", ".", "EBinary", ";", "import", "erjang", ".", "ERT", ";", "import", "erjang", ".", "NotImplemented", ";", "import", "erjang", ".", "CharCollector", ";", "import", "java", ".", "io", ".", "CharArrayWriter", ";", "import", "java", ".", "io", ".", "IOException", ";", "import", "java", ".", "nio", ".", "charset", ".", "Charset", ";", "public", "class", "Native", "extends", "ENative", "{", "public", "static", "EAtom", "LATIN1_ATOM", "=", "EAtom", ".", "intern", "(", "\"latin1\"", ")", ";", "public", "static", "EAtom", "UNICODE_ATOM", "=", "EAtom", ".", "intern", "(", "\"unicode\"", ")", ";", "public", "static", "EAtom", "UTF8_ATOM", "=", "EAtom", ".", "intern", "(", "\"utf8\"", ")", ";", "public", "static", "EAtom", "UTF16_ATOM", "=", "EAtom", ".", "intern", "(", "\"utf16\"", ")", ";", "public", "static", "EAtom", "UTF32_ATOM", "=", "EAtom", ".", "intern", "(", "\"utf32\"", ")", ";", "public", "static", "EAtom", "LITTLE_ATOM", "=", "EAtom", ".", "intern", "(", "\"little\"", ")", ";", "public", "static", "EAtom", "BIG_ATOM", "=", "EAtom", ".", "intern", "(", "\"big\"", ")", ";", "public", "static", "EAtom", "ERROR_ATOM", "=", "EAtom", ".", "intern", "(", "\"error\"", ")", ";", "public", "static", "EAtom", "INCOMPLETE_ATOM", "=", "EAtom", ".", "intern", "(", "\"incomplete\"", ")", ";", "@", "BIF", "public", "static", "EObject", "characters_to_binary", "(", "EObject", "charlist", ",", "EObject", "encodingSpec", ")", "{", "return", "characters_to", "(", "charlist", ",", "encodingSpec", ",", "CHAR_ARRAY_TO_BINARY_CONVERTER", ")", ";", "}", "@", "BIF", "public", "static", "EObject", "characters_to_list", "(", "EObject", "charlist", ",", "EObject", "encodingSpec", ")", "{", "return", "characters_to", "(", "charlist", ",", "encodingSpec", ",", "CHAR_ARRAY_TO_LIST_CONVERTER", ")", ";", "}", "@", "BIF", "public", "static", "EObject", "characters_to_list", "(", "EObject", "charlist", ")", "{", "return", "characters_to", "(", "charlist", ",", "UNICODE_ATOM", ",", "CHAR_ARRAY_TO_LIST_CONVERTER", ")", ";", "}", "public", "static", "EObject", "characters_to", "(", "EObject", "charlist", ",", "EObject", "encodingSpec", ",", "CharArrayConverter", "output_converter", ")", "{", "Charset", "encoding", "=", "encodingSpecToCharset", "(", "encodingSpec", ")", ";", "if", "(", "encoding", "==", "null", ")", "throw", "ERT", ".", "badarg", "(", "charlist", ",", "encodingSpec", ")", ";", "CharArrayWriter", "out", "=", "new", "CharArrayWriter", "(", ")", ";", "CharCollector", "collector", "=", "new", "CharCollector", "(", "encoding", ",", "out", ")", ";", "try", "{", "charlist", ".", "collectCharList", "(", "collector", ")", ";", "}", "catch", "(", "CharCollector", ".", "InvalidElementException", "e", ")", "{", "throw", "ERT", ".", "badarg", "(", "charlist", ",", "encodingSpec", ")", ";", "}", "catch", "(", "CharCollector", ".", "CollectingException", "e", ")", "{", "EObject", "data", "=", "output_converter", ".", "convert", "(", "out", ")", ";", "return", "ETuple", ".", "make", "(", "ERROR_ATOM", ",", "data", ",", "e", ".", "restOfInput", ")", ";", "}", "catch", "(", "IOException", "e", ")", "{", "throw", "new", "Error", "(", "e", ")", ";", "}", "try", "{", "collector", ".", "end", "(", ")", ";", "}", "catch", "(", "CharCollector", ".", "PartialDecodingException", "e", ")", "{", "EObject", "data", "=", "output_converter", ".", "convert", "(", "out", ")", ";", "return", "ETuple", ".", "make", "(", "INCOMPLETE_ATOM", ",", "data", ")", ";", "}", "catch", "(", "IOException", "e", ")", "{", "throw", "new", "Error", "(", "e", ")", ";", "}", "return", "output_converter", ".", "convert", "(", "out", ")", ";", "}", "public", "static", "Charset", "encodingSpecToCharset", "(", "EObject", "encoding", ")", "{", "EAtom", "ea", ";", "ETuple", "et", ";", "if", "(", "(", "ea", "=", "encoding", ".", "testAtom", "(", ")", ")", "!=", "null", ")", "{", "if", "(", "ea", ".", "equals", "(", "LATIN1_ATOM", ")", ")", "return", "Charset", ".", "forName", "(", "\"ISO-8859-1\"", ")", ";", "else", "if", "(", "ea", ".", "equals", "(", "UNICODE_ATOM", ")", "||", "ea", ".", "equals", "(", "UTF8_ATOM", ")", ")", "return", "Charset", ".", "forName", "(", "\"UTF-8\"", ")", ";", "else", "if", "(", "ea", ".", "equals", "(", "UTF16_ATOM", ")", ")", "return", "Charset", ".", "forName", "(", "\"UTF-16BE\"", ")", ";", "}", "else", "if", "(", "(", "et", "=", "encoding", ".", "testTuple", "(", ")", ")", "!=", "null", ")", "{", "EAtom", "ea2", ";", "if", "(", "(", "ea", "=", "et", ".", "elm", "(", "1", ")", ".", "testAtom", "(", ")", ")", "!=", "null", "&&", "(", "ea2", "=", "et", ".", "elm", "(", "21", ")", ".", "testAtom", "(", ")", ")", "!=", "null", ")", "{", "if", "(", "ea", ".", "equals", "(", "UTF16_ATOM", ")", ")", "{", "if", "(", "ea2", ".", "equals", "(", "LITTLE_ATOM", ")", ")", "return", "Charset", ".", "forName", "(", "\"UTF-16LE\"", ")", ";", "if", "(", "ea2", ".", "equals", "(", "BIG_ATOM", ")", ")", "return", "Charset", ".", "forName", "(", "\"UTF-16BE\"", ")", ";", "}", "else", "if", "(", "ea", ".", "equals", "(", "UTF32_ATOM", ")", ")", "{", "throw", "new", "NotImplemented", "(", ")", ";", "}", "}", "}", "return", "null", ";", "}", "static", "abstract", "class", "CharArrayConverter", "{", "EObject", "convert", "(", "CharArrayWriter", "caw", ")", "{", "return", "convert", "(", "caw", ".", "toCharArray", "(", ")", ")", ";", "}", "abstract", "EObject", "convert", "(", "char", "[", "]", "chars", ")", ";", "}", "final", "static", "CharArrayConverter", "CHAR_ARRAY_TO_BINARY_CONVERTER", "=", "new", "CharArrayConverter", "(", ")", "{", "EObject", "convert", "(", "char", "[", "]", "chars", ")", "{", "String", "s", "=", "new", "String", "(", "chars", ")", ";", "try", "{", "return", "new", "EBinary", "(", "s", ".", "getBytes", "(", "\"UTF-8\"", ")", ")", ";", "}", "catch", "(", "java", ".", "io", ".", "UnsupportedEncodingException", "e", ")", "{", "throw", "new", "Error", "(", "e", ")", ";", "}", "}", "}", ";", "final", "static", "CharArrayConverter", "CHAR_ARRAY_TO_LIST_CONVERTER", "=", "new", "CharArrayConverter", "(", ")", "{", "EObject", "convert", "(", "char", "[", "]", "chars", ")", "{", "return", "EBigString", ".", "make", "(", "chars", ",", "0", ",", "chars", ".", "length", ")", ";", "}", "}", ";", "@", "BIF", "public", "static", "EObject", "bin_is_7bit", "(", "EObject", "o1", ")", "{", "EBinary", "bin", ";", "if", "(", "(", "bin", "=", "o1", ".", "testBinary", "(", ")", ")", "!=", "null", ")", "{", "return", "ERT", ".", "box", "(", "bin", ".", "is_7bit", "(", ")", ")", ";", "}", "return", "ERT", ".", "FALSE", ";", "}", "}", "</s>" ]
7,785
[ "<s>", "package", "erjang", ".", "m", ".", "rpc", ";", "import", "kilim", ".", "Pausable", ";", "import", "erjang", ".", "BIF", ";", "import", "erjang", ".", "ENative", ";", "import", "erjang", ".", "EObject", ";", "import", "erjang", ".", "EPID", ";", "import", "erjang", ".", "EProc", ";", "import", "erjang", ".", "ERT", ";", "import", "erjang", ".", "ETuple", ";", "import", "erjang", ".", "ErlangException", ";", "import", "erjang", ".", "m", ".", "erlang", ".", "ErlBif", ";", "import", "erjang", ".", "m", ".", "erlang", ".", "ErlProc", ";", "public", "class", "Native", "extends", "ENative", "{", "static", "MBox", "started_mbox", "=", "new", "MBox", "(", ")", ";", "private", "static", "EPID", "local_group_leader", ";", "@", "BIF", "static", "public", "EObject", "erjang_started", "(", "EProc", "self", ")", "throws", "Pausable", "{", "local_group_leader", "=", "self", ".", "group_leader", "(", ")", ";", "started_mbox", ".", "put", "(", "ERT", ".", "am_ok", ")", ";", "return", "ERT", ".", "am_ok", ";", "}", "public", "static", "void", "wait_for_started", "(", "long", "timeout", ")", "{", "started_mbox", ".", "get_b", "(", "timeout", ")", ";", "}", "public", "static", "EPID", "get_local_group_leader", "(", ")", "{", "return", "local_group_leader", ";", "}", "@", "BIF", "static", "public", "EObject", "call_from_java", "(", "EProc", "self", ",", "EObject", "m", ",", "EObject", "f", ",", "EObject", "args", ",", "EObject", "mbox", ")", "throws", "Pausable", "{", "if", "(", "mbox", "instanceof", "MBox", ")", "{", "MBox", "embox", "=", "(", "MBox", ")", "mbox", ";", "try", "{", "EObject", "res", "=", "ErlBif", ".", "apply", "(", "self", ",", "m", ",", "f", ",", "args", ")", ";", "embox", ".", "put", "(", "ETuple", ".", "make", "(", "ERT", ".", "am_ok", ",", "res", ")", ")", ";", "return", "res", ";", "}", "catch", "(", "ErlangException", "e", ")", "{", "embox", ".", "put", "(", "ETuple", ".", "make", "(", "ERT", ".", "am_error", ",", "e", ".", "getCatchValue", "(", ")", ")", ")", ";", "return", "ERT", ".", "am_undefined", ";", "}", "}", "else", "{", "throw", "ERT", ".", "badarg", "(", ")", ";", "}", "}", "}", "</s>" ]
7,786
[ "<s>", "package", "erjang", ".", "m", ".", "rpc", ";", "import", "kilim", ".", "Mailbox", ";", "import", "kilim", ".", "Pausable", ";", "import", "erjang", ".", "EObject", ";", "import", "erjang", ".", "EPseudoTerm", ";", "public", "class", "MBox", "extends", "EPseudoTerm", "{", "Mailbox", "<", "EObject", ">", "mbox", ";", "public", "MBox", "(", ")", "{", "this", ".", "mbox", "=", "new", "Mailbox", "<", "EObject", ">", "(", ")", ";", "}", "public", "void", "put", "(", "EObject", "value", ")", "throws", "Pausable", "{", "mbox", ".", "put", "(", "value", ")", ";", "}", "public", "EObject", "get_b", "(", ")", "{", "return", "mbox", ".", "getb", "(", ")", ";", "}", "public", "EObject", "get_b", "(", "long", "timeout", ")", "{", "return", "mbox", ".", "getb", "(", "timeout", ")", ";", "}", "@", "Override", "public", "int", "hashCode", "(", ")", "{", "return", "System", ".", "identityHashCode", "(", "this", ")", ";", "}", "}", "</s>" ]
7,787
[ "<s>", "package", "erjang", ".", "m", ".", "error_logger", ";", "import", "erjang", ".", "BIF", ";", "import", "erjang", ".", "EAtom", ";", "import", "erjang", ".", "ENative", ";", "public", "class", "Native", "extends", "ENative", "{", "private", "static", "final", "EAtom", "am_error", "=", "EAtom", ".", "intern", "(", "\"error\"", ")", ";", "private", "static", "final", "EAtom", "am_warning", "=", "EAtom", ".", "intern", "(", "\"warning\"", ")", ";", "private", "static", "final", "EAtom", "am_info", "=", "EAtom", ".", "intern", "(", "\"info\"", ")", ";", "@", "BIF", "public", "static", "EAtom", "warning_map", "(", ")", "{", "return", "am_error", ";", "}", "}", "</s>" ]
7,788
[ "<s>", "package", "erjang", ".", "m", ".", "binary", ";", "import", "erjang", ".", "*", ";", "import", "erjang", ".", "m", ".", "erlang", ".", "ErlBif", ";", "import", "erjang", ".", "m", ".", "erlang", ".", "ErlConvert", ";", "public", "class", "Native", "extends", "ENative", "{", "@", "BIF", "public", "static", "EInteger", "at", "(", "EObject", "subject", ",", "EObject", "pos", ")", "{", "throw", "new", "NotImplemented", "(", ")", ";", "}", "protected", "static", "EString", "do_bin_to_list", "(", "EObject", "subject", ",", "EObject", "pos", ",", "EObject", "len", ")", "{", "if", "(", "subject", "==", "null", ")", "throw", "ERT", ".", "badarg", "(", "subject", ")", ";", "EBinary", "bin", "=", "subject", ".", "testBinary", "(", ")", ";", "if", "(", "bin", "==", "null", ")", "throw", "ERT", ".", "badarg", "(", "subject", ")", ";", "if", "(", "!", "bin", ".", "isBinary", "(", ")", ")", "throw", "ERT", ".", "badarg", "(", "subject", ")", ";", "if", "(", "pos", ".", "testSmall", "(", ")", "==", "null", ")", "throw", "ERT", ".", "badarg", "(", "pos", ")", ";", "if", "(", "len", ".", "testSmall", "(", ")", "==", "null", ")", "throw", "ERT", ".", "badarg", "(", "len", ")", ";", "ESmall", "start", "=", "new", "ESmall", "(", "pos", ".", "asInt", "(", ")", "+", "1", ")", ";", "ESmall", "stop", "=", "new", "ESmall", "(", "(", "len", ".", "asInt", "(", ")", "==", "-", "1", ")", "?", "bin", ".", "byteSize", "(", ")", ":", "len", ".", "asInt", "(", ")", "+", "pos", ".", "asInt", "(", ")", ")", ";", "return", "ErlConvert", ".", "binary_to_list", "(", "subject", ",", "start", ",", "stop", ")", ";", "}", "@", "BIF", "public", "static", "EString", "bin_to_list", "(", "EObject", "subject", ")", "{", "return", "do_bin_to_list", "(", "subject", ",", "new", "ESmall", "(", "0", ")", ",", "new", "ESmall", "(", "-", "1", ")", ")", ";", "}", "@", "BIF", "public", "static", "EString", "bin_to_list", "(", "EObject", "subject", ",", "EObject", "poslen", ")", "{", "if", "(", "poslen", "==", "null", ")", "throw", "ERT", ".", "badarg", "(", "poslen", ")", ";", "ETuple", "tuple", "=", "poslen", ".", "testTuple", "(", ")", ";", "if", "(", "tuple", "==", "null", ")", "throw", "ERT", ".", "badarg", "(", "poslen", ")", ";", "ETuple2", "tuple2", "=", "ETuple2", ".", "cast", "(", "tuple", ")", ";", "if", "(", "tuple2", "==", "null", ")", "throw", "ERT", ".", "badarg", "(", "poslen", ")", ";", "if", "(", "tuple2", ".", "elem1", ".", "testSmall", "(", ")", "==", "null", ")", "throw", "ERT", ".", "badarg", "(", "tuple2", ".", "elem1", ")", ";", "if", "(", "tuple2", ".", "elem2", ".", "testSmall", "(", ")", "==", "null", ")", "throw", "ERT", ".", "badarg", "(", "tuple2", ".", "elem2", ")", ";", "return", "do_bin_to_list", "(", "subject", ",", "new", "ESmall", "(", "tuple2", ".", "elem1", ".", "asInt", "(", ")", ")", ",", "new", "ESmall", "(", "tuple2", ".", "elem2", ".", "asInt", "(", ")", ")", ")", ";", "}", "@", "BIF", "public", "static", "EString", "bin_to_list", "(", "EObject", "subject", ",", "EObject", "pos", ",", "EObject", "len", ")", "{", "return", "do_bin_to_list", "(", "subject", ",", "pos", ",", "len", ")", ";", "}", "@", "BIF", "public", "static", "ETuple", "compile_pattern", "(", "EObject", "pattern", ")", "{", "throw", "new", "NotImplemented", "(", ")", ";", "}", "@", "BIF", "public", "static", "EBinary", "copy", "(", "EObject", "subject", ")", "{", "throw", "new", "NotImplemented", "(", ")", ";", "}", "@", "BIF", "public", "static", "EBinary", "copy", "(", "EObject", "subject", ",", "EObject", "n", ")", "{", "throw", "new", "NotImplemented", "(", ")", ";", "}", "@", "BIF", "public", "static", "EInteger", "decode_unsigned", "(", "EObject", "subject", ")", "{", "throw", "new", "NotImplemented", "(", ")", ";", "}", "@", "BIF", "public", "static", "EInteger", "decode_unsigned", "(", "EObject", "subject", ",", "EObject", "endianess", ")", "{", "throw", "new", "NotImplemented", "(", ")", ";", "}", "@", "BIF", "public", "static", "EBinary", "encode_unsigned", "(", "EObject", "unsigned", ")", "{", "throw", "new", "NotImplemented", "(", ")", ";", "}", "@", "BIF", "public", "static", "EBinary", "encode_unsigned", "(", "EObject", "unsigned", ",", "EObject", "endianess", ")", "{", "throw", "new", "NotImplemented", "(", ")", ";", "}", "@", "BIF", "public", "static", "EInteger", "first", "(", "EObject", "subject", ")", "{", "throw", "new", "NotImplemented", "(", ")", ";", "}", "@", "BIF", "public", "static", "EInteger", "last", "(", "EObject", "subject", ")", "{", "throw", "new", "NotImplemented", "(", ")", ";", "}", "@", "BIF", "public", "static", "EBinary", "list_to_bin", "(", "EObject", "byteList", ")", "{", "return", "ErlBif", ".", "list_to_binary", "(", "byteList", ")", ";", "}", "@", "BIF", "public", "static", "EInteger", "longest_common_prefix", "(", "EObject", "binaries", ")", "{", "throw", "new", "NotImplemented", "(", ")", ";", "}", "@", "BIF", "public", "static", "EInteger", "longest_common_suffix", "(", "EObject", "binaries", ")", "{", "throw", "new", "NotImplemented", "(", ")", ";", "}", "@", "BIF", "public", "static", "EObject", "match", "(", "EObject", "subject", ",", "EObject", "pattern", ")", "{", "throw", "new", "NotImplemented", "(", ")", ";", "}", "@", "BIF", "public", "static", "EObject", "match", "(", "EObject", "subject", ",", "EObject", "pattern", ",", "EObject", "options", ")", "{", "throw", "new", "NotImplemented", "(", ")", ";", "}", "@", "BIF", "public", "static", "EObject", "matches", "(", "EObject", "subject", ",", "EObject", "pattern", ")", "{", "throw", "new", "NotImplemented", "(", ")", ";", "}", "@", "BIF", "public", "static", "EObject", "matches", "(", "EObject", "subject", ",", "EObject", "pattern", ",", "EObject", "options", ")", "{", "throw", "new", "NotImplemented", "(", ")", ";", "}", "@", "BIF", "public", "static", "EBinary", "part", "(", "EObject", "subject", ",", "EObject", "poslen", ")", "{", "throw", "new", "NotImplemented", "(", ")", ";", "}", "@", "BIF", "public", "static", "EBinary", "part", "(", "EObject", "subject", ",", "EObject", "pos", ",", "EObject", "len", ")", "{", "throw", "new", "NotImplemented", "(", ")", ";", "}", "@", "BIF", "public", "static", "EInteger", "referenced_byte_size", "(", "EObject", "subject", ")", "{", "throw", "new", "NotImplemented", "(", ")", ";", "}", "}", "</s>" ]
7,789
[ "<s>", "package", "erjang", ".", "m", ".", "zlib", ";", "import", "java", ".", "io", ".", "ByteArrayOutputStream", ";", "import", "java", ".", "io", ".", "IOException", ";", "import", "java", ".", "util", ".", "zip", ".", "Deflater", ";", "import", "java", ".", "util", ".", "zip", ".", "DeflaterOutputStream", ";", "import", "erjang", ".", "BIF", ";", "import", "erjang", ".", "EBinary", ";", "import", "erjang", ".", "ENative", ";", "import", "erjang", ".", "EObject", ";", "import", "erjang", ".", "ERT", ";", "public", "class", "Native", "extends", "ENative", "{", "@", "BIF", "public", "static", "EBinary", "compress", "(", "EObject", "bin", ")", "{", "EBinary", "b", "=", "bin", ".", "testBinary", "(", ")", ";", "if", "(", "b", "==", "null", ")", "{", "throw", "ERT", ".", "badarg", "(", "bin", ")", ";", "}", "Deflater", "defl", "=", "new", "Deflater", "(", ")", ";", "BARR", "bos", "=", "new", "BARR", "(", ")", ";", "DeflaterOutputStream", "dos", "=", "new", "DeflaterOutputStream", "(", "bos", ",", "defl", ")", ";", "try", "{", "b", ".", "writeTo", "(", "dos", ")", ";", "dos", ".", "close", "(", ")", ";", "}", "catch", "(", "IOException", "e", ")", "{", "throw", "new", "InternalError", "(", "\"\"", ")", ";", "}", "return", "bos", ".", "asBinary", "(", ")", ";", "}", "static", "private", "class", "BARR", "extends", "ByteArrayOutputStream", "{", "EBinary", "asBinary", "(", ")", "{", "return", "new", "EBinary", "(", "super", ".", "buf", ",", "0", ",", "super", ".", "count", ")", ";", "}", "}", "}", "</s>" ]
7,790
[ "<s>", "package", "erjang", ".", "m", ".", "crypto", ";", "import", "java", ".", "math", ".", "BigInteger", ";", "import", "java", ".", "nio", ".", "ByteBuffer", ";", "import", "java", ".", "security", ".", "MessageDigest", ";", "import", "java", ".", "security", ".", "NoSuchAlgorithmException", ";", "import", "java", ".", "security", ".", "SecureRandom", ";", "import", "java", ".", "util", ".", "logging", ".", "Level", ";", "import", "erjang", ".", "BIF", ";", "import", "erjang", ".", "EBinary", ";", "import", "erjang", ".", "ENative", ";", "import", "erjang", ".", "EObject", ";", "import", "erjang", ".", "ERT", ";", "public", "class", "Native", "extends", "ENative", "{", "int", "get_int32", "(", "EBinary", "bin", ")", "{", "return", "bin", ".", "intBitsAt", "(", "0", ",", "32", ")", ";", "}", "static", "SecureRandom", "rand", ";", "static", "{", "try", "{", "rand", "=", "SecureRandom", ".", "getInstance", "(", "\"SHA1PRNG\"", ")", ";", "}", "catch", "(", "NoSuchAlgorithmException", "e", ")", "{", "e", ".", "printStackTrace", "(", ")", ";", "}", "}", "@", "BIF", "public", "static", "EObject", "sha", "(", "EObject", "data", ")", "{", "EBinary", "bin", "=", "data", ".", "testBinary", "(", ")", ";", "if", "(", "bin", "==", "null", ")", "throw", "ERT", ".", "badarg", "(", "data", ")", ";", "MessageDigest", "sha", ";", "try", "{", "sha", "=", "MessageDigest", ".", "getInstance", "(", "\"SHA\"", ")", ";", "}", "catch", "(", "NoSuchAlgorithmException", "e", ")", "{", "throw", "ERT", ".", "badarg", "(", "data", ")", ";", "}", "sha", ".", "digest", "(", "bin", ".", "getByteArray", "(", ")", ")", ";", "byte", "[", "]", "res", "=", "sha", ".", "digest", "(", ")", ";", "return", "EBinary", ".", "make", "(", "res", ")", ";", "}", "@", "BIF", "public", "static", "EObject", "md5", "(", "EObject", "data", ")", "{", "EBinary", "bin", "=", "data", ".", "testBinary", "(", ")", ";", "if", "(", "bin", "==", "null", ")", "throw", "ERT", ".", "badarg", "(", "data", ")", ";", "MessageDigest", "md5", ";", "try", "{", "md5", "=", "MessageDigest", ".", "getInstance", "(", "\"MD5\"", ")", ";", "}", "catch", "(", "NoSuchAlgorithmException", "e", ")", "{", "throw", "ERT", ".", "badarg", "(", "data", ")", ";", "}", "md5", ".", "digest", "(", "bin", ".", "getByteArray", "(", ")", ")", ";", "byte", "[", "]", "res", "=", "md5", ".", "digest", "(", ")", ";", "return", "EBinary", ".", "make", "(", "res", ")", ";", "}", "@", "BIF", "public", "static", "EObject", "rand_uniform_nif", "(", "EObject", "from", ",", "EObject", "to", ")", "{", "EBinary", "fb", "=", "from", ".", "testBinary", "(", ")", ";", "EBinary", "tb", "=", "to", ".", "testBinary", "(", ")", ";", "if", "(", "fb", "==", "null", "||", "tb", "==", "null", ")", "{", "throw", "ERT", ".", "badarg", "(", "from", ",", "to", ")", ";", "}", "BigInteger", "fi", "=", "mp2big", "(", "fb", ")", ";", "BigInteger", "ti", "=", "mp2big", "(", "tb", ")", ";", "if", "(", "log", ".", "isLoggable", "(", "Level", ".", "FINE", ")", ")", "log", ".", "fine", "(", "\"\"", "+", "fb", "+", "\",", "\"", "+", "tb", "+", "\")\"", ")", ";", "BigInteger", "interval", "=", "ti", ".", "subtract", "(", "fi", ")", ".", "subtract", "(", "BigInteger", ".", "ONE", ")", ";", "BigInteger", "base_value", "=", "new", "BigInteger", "(", "interval", ".", "bitLength", "(", ")", ",", "rand", ")", ";", "BigInteger", "result", ";", "while", "(", "interval", ".", "compareTo", "(", "base_value", ")", "==", "1", ")", "{", "base_value", "=", "new", "BigInteger", "(", "interval", ".", "bitLength", "(", ")", ",", "rand", ")", ";", "}", "result", "=", "fi", ".", "add", "(", "base_value", ")", ";", "if", "(", "log", ".", "isLoggable", "(", "Level", ".", "FINE", ")", ")", "log", ".", "fine", "(", "\"\"", "+", "fi", "+", "\",", "\"", "+", "ti", "+", "\")", "->", "\"", "+", "result", ")", ";", "EBinary", "res", "=", "big2mp", "(", "result", ")", ";", "return", "res", ";", "}", "private", "static", "EBinary", "big2mp", "(", "BigInteger", "result", ")", "{", "byte", "[", "]", "bytes", "=", "result", ".", "toByteArray", "(", ")", ";", "ByteBuffer", "out", "=", "ByteBuffer", ".", "allocate", "(", "4", "+", "bytes", ".", "length", ")", ";", "out", ".", "putInt", "(", "bytes", ".", "length", ")", ";", "out", ".", "put", "(", "bytes", ")", ";", "out", ".", "position", "(", "0", ")", ";", "EBinary", "res", "=", "EBinary", ".", "make", "(", "out", ")", ";", "return", "res", ";", "}", "private", "static", "BigInteger", "mp2big", "(", "EBinary", "bin", ")", "{", "ByteBuffer", "bb", "=", "bin", ".", "toByteBuffer", "(", ")", ";", "int", "len", "=", "bb", ".", "getInt", "(", ")", ";", "byte", "[", "]", "data", "=", "new", "byte", "[", "len", "]", ";", "bb", ".", "get", "(", "data", ")", ";", "return", "new", "BigInteger", "(", "data", ")", ";", "}", "}", "</s>" ]
7,791
[ "<s>", "package", "erjang", ".", "m", ".", "math", ";", "import", "erjang", ".", "BIF", ";", "import", "erjang", ".", "EDouble", ";", "import", "erjang", ".", "ENative", ";", "import", "erjang", ".", "ENumber", ";", "import", "erjang", ".", "EObject", ";", "import", "erjang", ".", "ERT", ";", "public", "class", "Native", "extends", "ENative", "{", "@", "BIF", "public", "static", "ENumber", "sin", "(", "EObject", "val", ")", "{", "ENumber", "num", ";", "if", "(", "(", "num", "=", "val", ".", "testNumber", "(", ")", ")", "!=", "null", ")", "{", "return", "new", "EDouble", "(", "Math", ".", "sin", "(", "num", ".", "doubleValue", "(", ")", ")", ")", ";", "}", "throw", "ERT", ".", "badarg", "(", "val", ")", ";", "}", "@", "BIF", "public", "static", "ENumber", "cos", "(", "EObject", "val", ")", "{", "ENumber", "num", ";", "if", "(", "(", "num", "=", "val", ".", "testNumber", "(", ")", ")", "!=", "null", ")", "{", "return", "new", "EDouble", "(", "Math", ".", "cos", "(", "num", ".", "doubleValue", "(", ")", ")", ")", ";", "}", "throw", "ERT", ".", "badarg", "(", "val", ")", ";", "}", "@", "BIF", "public", "static", "ENumber", "tan", "(", "EObject", "val", ")", "{", "ENumber", "num", ";", "if", "(", "(", "num", "=", "val", ".", "testNumber", "(", ")", ")", "!=", "null", ")", "{", "return", "boxIfValid", "(", "Math", ".", "tan", "(", "num", ".", "doubleValue", "(", ")", ")", ",", "val", ")", ";", "}", "throw", "ERT", ".", "badarg", "(", "val", ")", ";", "}", "@", "BIF", "public", "static", "ENumber", "asin", "(", "EObject", "val", ")", "{", "ENumber", "num", ";", "if", "(", "(", "num", "=", "val", ".", "testNumber", "(", ")", ")", "!=", "null", ")", "{", "return", "boxIfValid", "(", "Math", ".", "asin", "(", "num", ".", "doubleValue", "(", ")", ")", ",", "val", ")", ";", "}", "throw", "ERT", ".", "badarg", "(", "val", ")", ";", "}", "@", "BIF", "public", "static", "ENumber", "acos", "(", "EObject", "val", ")", "{", "ENumber", "num", ";", "if", "(", "(", "num", "=", "val", ".", "testNumber", "(", ")", ")", "!=", "null", ")", "{", "return", "boxIfValid", "(", "Math", ".", "acos", "(", "num", ".", "doubleValue", "(", ")", ")", ",", "val", ")", ";", "}", "throw", "ERT", ".", "badarg", "(", "val", ")", ";", "}", "@", "BIF", "public", "static", "EDouble", "atan", "(", "EObject", "val", ")", "{", "ENumber", "num", ";", "if", "(", "(", "num", "=", "val", ".", "testNumber", "(", ")", ")", "!=", "null", ")", "{", "return", "boxIfValid", "(", "Math", ".", "atan", "(", "num", ".", "doubleValue", "(", ")", ")", ",", "val", ")", ";", "}", "throw", "ERT", ".", "badarg", "(", "val", ")", ";", "}", "@", "BIF", "public", "static", "EDouble", "sinh", "(", "EObject", "val", ")", "{", "ENumber", "num", ";", "if", "(", "(", "num", "=", "val", ".", "testNumber", "(", ")", ")", "!=", "null", ")", "{", "return", "boxIfValid", "(", "Math", ".", "sinh", "(", "num", ".", "doubleValue", "(", ")", ")", ",", "val", ")", ";", "}", "throw", "ERT", ".", "badarg", "(", "val", ")", ";", "}", "@", "BIF", "public", "static", "EDouble", "cosh", "(", "EObject", "val", ")", "{", "ENumber", "num", ";", "if", "(", "(", "num", "=", "val", ".", "testNumber", "(", ")", ")", "!=", "null", ")", "{", "return", "boxIfValid", "(", "Math", ".", "cosh", "(", "num", ".", "doubleValue", "(", ")", ")", ",", "val", ")", ";", "}", "throw", "ERT", ".", "badarg", "(", "val", ")", ";", "}", "@", "BIF", "public", "static", "EDouble", "tanh", "(", "EObject", "val", ")", "{", "ENumber", "num", ";", "if", "(", "(", "num", "=", "val", ".", "testNumber", "(", ")", ")", "!=", "null", ")", "{", "return", "boxIfValid", "(", "Math", ".", "tanh", "(", "num", ".", "doubleValue", "(", ")", ")", ",", "val", ")", ";", "}", "throw", "ERT", ".", "badarg", "(", "val", ")", ";", "}", "@", "BIF", "public", "static", "EDouble", "exp", "(", "EObject", "val", ")", "{", "ENumber", "num", ";", "if", "(", "(", "num", "=", "val", ".", "testNumber", "(", ")", ")", "!=", "null", ")", "{", "return", "boxIfValid", "(", "Math", ".", "exp", "(", "num", ".", "doubleValue", "(", ")", ")", ",", "val", ")", ";", "}", "throw", "ERT", ".", "badarg", "(", "val", ")", ";", "}", "@", "BIF", "public", "static", "EDouble", "log", "(", "EObject", "val", ")", "{", "ENumber", "num", ";", "if", "(", "(", "num", "=", "val", ".", "testNumber", "(", ")", ")", "!=", "null", ")", "{", "return", "boxIfValid", "(", "Math", ".", "log", "(", "num", ".", "doubleValue", "(", ")", ")", ",", "val", ")", ";", "}", "throw", "ERT", ".", "badarg", "(", "val", ")", ";", "}", "@", "BIF", "public", "static", "ENumber", "log10", "(", "EObject", "val", ")", "{", "ENumber", "num", ";", "if", "(", "(", "num", "=", "val", ".", "testNumber", "(", ")", ")", "!=", "null", ")", "{", "return", "boxIfValid", "(", "Math", ".", "log10", "(", "num", ".", "doubleValue", "(", ")", ")", ",", "val", ")", ";", "}", "throw", "ERT", ".", "badarg", "(", "val", ")", ";", "}", "@", "BIF", "public", "static", "EDouble", "atan2", "(", "EObject", "val1", ",", "EObject", "val2", ")", "{", "ENumber", "num1", ",", "num2", ";", "if", "(", "(", "num1", "=", "val1", ".", "testNumber", "(", ")", ")", "!=", "null", "&&", "(", "num2", "=", "val2", ".", "testNumber", "(", ")", ")", "!=", "null", ")", "{", "return", "new", "EDouble", "(", "Math", ".", "atan2", "(", "num1", ".", "doubleValue", "(", ")", ",", "num2", ".", "doubleValue", "(", ")", ")", ")", ";", "}", "throw", "ERT", ".", "badarg", "(", "val1", ",", "val2", ")", ";", "}", "@", "BIF", "public", "static", "EDouble", "pi", "(", ")", "{", "return", "new", "EDouble", "(", "Math", ".", "PI", ")", ";", "}", "@", "BIF", "public", "static", "EDouble", "sqrt", "(", "EDouble", "val", ")", "{", "return", "boxIfValid", "(", "Math", ".", "sqrt", "(", "val", ".", "value", ")", ",", "val", ")", ";", "}", "@", "BIF", "public", "static", "EDouble", "sqrt", "(", "EObject", "val", ")", "{", "ENumber", "num", ";", "if", "(", "(", "num", "=", "val", ".", "testNumber", "(", ")", ")", "!=", "null", ")", "{", "return", "boxIfValid", "(", "Math", ".", "sqrt", "(", "num", ".", "doubleValue", "(", ")", ")", ",", "val", ")", ";", "}", "throw", "ERT", ".", "badarg", "(", "val", ")", ";", "}", "public", "static", "EDouble", "boxIfValid", "(", "double", "value", ",", "EObject", "arg", ")", "{", "if", "(", "Double", ".", "isNaN", "(", "value", ")", "||", "Double", ".", "isInfinite", "(", "value", ")", ")", "throw", "ERT", ".", "badarg", "(", "arg", ")", ";", "else", "return", "new", "EDouble", "(", "value", ")", ";", "}", "}", "</s>" ]
7,792
[ "<s>", "package", "erjang", ".", "m", ".", "ets", ";", "import", "java", ".", "util", ".", "Map", ";", "import", "java", ".", "util", ".", "Map", ".", "Entry", ";", "import", "com", ".", "trifork", ".", "clj_ds", ".", "IMapEntry", ";", "import", "com", ".", "trifork", ".", "clj_ds", ".", "IPersistentMap", ";", "import", "com", ".", "trifork", ".", "clj_ds", ".", "ISeq", ";", "import", "com", ".", "trifork", ".", "clj_ds", ".", "PersistentHashMap", ";", "import", "com", ".", "trifork", ".", "clj_ds", ".", "PersistentTreeMap", ";", "import", "erjang", ".", "EAtom", ";", "import", "erjang", ".", "ECons", ";", "import", "erjang", ".", "EInteger", ";", "import", "erjang", ".", "EInternalPID", ";", "import", "erjang", ".", "EList", ";", "import", "erjang", ".", "ENumber", ";", "import", "erjang", ".", "EObject", ";", "import", "erjang", ".", "EPID", ";", "import", "erjang", ".", "EProc", ";", "import", "erjang", ".", "EPseudoTerm", ";", "import", "erjang", ".", "ERT", ";", "import", "erjang", ".", "ESeq", ";", "import", "erjang", ".", "ESmall", ";", "import", "erjang", ".", "ETuple", ";", "import", "erjang", ".", "ETuple2", ";", "import", "erjang", ".", "NotImplemented", ";", "import", "erjang", ".", "m", ".", "erlang", ".", "ErlBif", ";", "public", "class", "ETableSet", "extends", "ETable", "{", "private", "boolean", "ordered", ";", "ETableSet", "(", "EProc", "owner", ",", "EAtom", "type", ",", "EInteger", "tid", ",", "EAtom", "aname", ",", "EAtom", "access", ",", "int", "keypos", ",", "boolean", "write_concurrency", ",", "boolean", "is_named", ",", "EInternalPID", "heirPID", ",", "EObject", "heirData", ")", "{", "super", "(", "owner", ",", "type", ",", "tid", ",", "aname", ",", "access", ",", "keypos", ",", "is_named", ",", "heirPID", ",", "heirData", ",", "type", "==", "Native", ".", "am_set", "?", "PersistentHashMap", ".", "EMPTY", ":", "new", "PersistentTreeMap", "(", "null", ",", "EObject", ".", "ERLANG_ORDERING", ")", ")", ";", "this", ".", "ordered", "=", "type", "!=", "Native", ".", "am_set", ";", "}", "@", "Override", "int", "size", "(", ")", "{", "return", "deref", "(", ")", ".", "count", "(", ")", ";", "}", "@", "Override", "protected", "void", "insert_one", "(", "final", "ETuple", "value", ")", "{", "in_tx", "(", "new", "WithMap", "<", "Object", ">", "(", ")", "{", "@", "Override", "protected", "Object", "run", "(", "IPersistentMap", "map", ")", "{", "EObject", "key", "=", "get_key", "(", "value", ")", ";", "IPersistentMap", "new_map", "=", "map", ".", "assoc", "(", "key", ",", "value", ")", ";", "set", "(", "new_map", ")", ";", "return", "null", ";", "}", "}", ")", ";", "}", "@", "Override", "protected", "void", "insert_many", "(", "final", "ESeq", "values", ")", "{", "in_tx", "(", "new", "WithMap", "<", "Object", ">", "(", ")", "{", "@", "Override", "protected", "Object", "run", "(", "IPersistentMap", "map", ")", "{", "for", "(", "ESeq", "seq", "=", "values", ";", "!", "seq", ".", "isNil", "(", ")", ";", "seq", "=", "seq", ".", "tail", "(", ")", ")", "{", "ETuple", "value", "=", "seq", ".", "head", "(", ")", ".", "testTuple", "(", ")", ";", "if", "(", "value", "==", "null", ")", "throw", "ERT", ".", "badarg", "(", "values", ")", ";", "map", "=", "map", ".", "assoc", "(", "get_key", "(", "value", ")", ",", "value", ")", ";", "}", "set", "(", "map", ")", ";", "return", "null", ";", "}", "}", ")", ";", "}", "@", "Override", "protected", "ESeq", "lookup", "(", "EObject", "key", ")", "{", "ESeq", "res", "=", "ERT", ".", "NIL", ";", "EObject", "val", "=", "(", "EObject", ")", "deref", "(", ")", ".", "valAt", "(", "key", ")", ";", "if", "(", "val", "!=", "null", ")", "{", "return", "res", ".", "cons", "(", "val", ")", ";", "}", "else", "{", "return", "res", ";", "}", "}", "@", "Override", "protected", "EAtom", "member", "(", "EObject", "key", ")", "{", "EObject", "val", "=", "(", "EObject", ")", "deref", "(", ")", ".", "valAt", "(", "key", ")", ";", "if", "(", "val", "!=", "null", ")", "{", "return", "ERT", ".", "TRUE", ";", "}", "else", "{", "return", "ERT", ".", "FALSE", ";", "}", "}", "@", "Override", "public", "ESeq", "slot", "(", ")", "{", "IPersistentMap", "map", "=", "deref", "(", ")", ";", "if", "(", "map", ".", "count", "(", ")", "==", "0", ")", "return", "ERT", ".", "NIL", ";", "ISeq", "seq", "=", "map", ".", "seq", "(", ")", ";", "return", "new", "ELSeq", "(", "seq", ")", ";", "}", "static", "class", "ELSeq", "extends", "ESeq", "{", "private", "ISeq", "seq", ";", "ELSeq", "(", "ISeq", "s", ")", "{", "this", ".", "seq", "=", "s", ";", "}", "@", "Override", "public", "ESeq", "cons", "(", "EObject", "h", ")", "{", "return", "new", "EList", "(", "h", ",", "this", ")", ";", "}", "@", "Override", "public", "ESeq", "tail", "(", ")", "{", "ISeq", "next", "=", "seq", ".", "next", "(", ")", ";", "if", "(", "next", "==", "null", ")", "return", "ERT", ".", "NIL", ";", "return", "new", "ELSeq", "(", "next", ")", ";", "}", "@", "Override", "public", "EObject", "head", "(", ")", "{", "IMapEntry", "ent", "=", "(", "IMapEntry", ")", "seq", ".", "first", "(", ")", ";", "return", "(", "EObject", ")", "ent", ".", "getValue", "(", ")", ";", "}", "@", "Override", "public", "boolean", "isNil", "(", ")", "{", "return", "false", ";", "}", "@", "Override", "public", "ECons", "testNonEmptyList", "(", ")", "{", "return", "this", ";", "}", "}", "@", "Override", "protected", "EObject", "first", "(", ")", "{", "IPersistentMap", "map", "=", "deref", "(", ")", ";", "if", "(", "map", ".", "count", "(", ")", "==", "0", ")", "{", "return", "Native", ".", "am_$end_of_table", ";", "}", "else", "{", "ISeq", "entseq", "=", "map", ".", "seq", "(", ")", ";", "if", "(", "entseq", "==", "null", ")", "return", "Native", ".", "am_$end_of_table", ";", "IMapEntry", "ent", "=", "(", "IMapEntry", ")", "entseq", ".", "first", "(", ")", ";", "if", "(", "ent", "==", "null", ")", "return", "Native", ".", "am_$end_of_table", ";", "return", "(", "EObject", ")", "ent", ".", "getKey", "(", ")", ";", "}", "}", "@", "Override", "protected", "boolean", "insert_new_many", "(", "final", "ESeq", "values", ")", "{", "for", "(", "ESeq", "seq", "=", "values", ";", "!", "seq", ".", "isNil", "(", ")", ";", "seq", "=", "seq", ".", "tail", "(", ")", ")", "{", "ETuple", "value", "=", "seq", ".", "head", "(", ")", ".", "testTuple", "(", ")", ";", "if", "(", "value", "==", "null", ")", "throw", "ERT", ".", "badarg", "(", "values", ")", ";", "EObject", "key", "=", "get_key", "(", "value", ")", ";", "}", "return", "in_tx", "(", "new", "WithMap", "<", "Boolean", ">", "(", ")", "{", "@", "Override", "protected", "Boolean", "run", "(", "IPersistentMap", "map", ")", "{", "for", "(", "ESeq", "seq", "=", "values", ";", "!", "seq", ".", "isNil", "(", ")", ";", "seq", "=", "seq", ".", "tail", "(", ")", ")", "{", "ETuple", "value", "=", "seq", ".", "head", "(", ")", ".", "testTuple", "(", ")", ";", "EObject", "key", "=", "get_key", "(", "value", ")", ";", "if", "(", "map", ".", "containsKey", "(", "key", ")", ")", "{", "return", "false", ";", "}", "}", "for", "(", "ESeq", "seq", "=", "values", ";", "!", "seq", ".", "isNil", "(", ")", ";", "seq", "=", "seq", ".", "tail", "(", ")", ")", "{", "ETuple", "value", "=", "seq", ".", "head", "(", ")", ".", "testTuple", "(", ")", ";", "EObject", "key", "=", "get_key", "(", "value", ")", ";", "map", "=", "map", ".", "assoc", "(", "key", ",", "value", ")", ";", "}", "set", "(", "map", ")", ";", "return", "true", ";", "}", "}", ")", ";", "}", "@", "Override", "protected", "boolean", "insert_new_one", "(", "final", "ETuple", "value", ")", "{", "final", "EObject", "key", "=", "get_key", "(", "value", ")", ";", "if", "(", "!", "deref", "(", ")", ".", "containsKey", "(", "key", ")", ")", "{", "return", "in_tx", "(", "new", "WithMap", "<", "Boolean", ">", "(", ")", "{", "@", "Override", "protected", "Boolean", "run", "(", "IPersistentMap", "map", ")", "{", "if", "(", "!", "map", ".", "containsKey", "(", "key", ")", ")", "{", "set", "(", "map", ".", "assoc", "(", "key", ",", "value", ")", ")", ";", "return", "true", ";", "}", "return", "false", ";", "}", "}", ")", ";", "}", "else", "{", "return", "false", ";", "}", "}", "@", "Override", "public", "ESeq", "match", "(", "EPattern", "matcher", ")", "{", "IPersistentMap", "map", "=", "deref", "(", ")", ";", "ESeq", "res", "=", "ERT", ".", "NIL", ";", "EObject", "key", "=", "matcher", ".", "getKey", "(", "keypos1", ")", ";", "if", "(", "key", "==", "null", ")", "{", "res", "=", "matcher", ".", "match", "(", "res", ",", "(", "Map", "<", "EObject", ",", "ETuple", ">", ")", "map", ")", ";", "if", "(", "ordered", ")", "res", "=", "res", ".", "reverse", "(", ")", ";", "}", "else", "{", "ETuple", "candidate", "=", "(", "ETuple", ")", "map", ".", "valAt", "(", "key", ")", ";", "if", "(", "candidate", "!=", "null", ")", "{", "res", "=", "matcher", ".", "match", "(", "res", ",", "candidate", ")", ";", "}", "}", "return", "res", ";", "}", "@", "Override", "public", "ESeq", "match_object", "(", "EPattern", "matcher", ")", "{", "IPersistentMap", "map", "=", "deref", "(", ")", ";", "ESeq", "res", "=", "ERT", ".", "NIL", ";", "EObject", "key", "=", "matcher", ".", "getKey", "(", "keypos1", ")", ";", "if", "(", "key", "==", "null", ")", "{", "res", "=", "matcher", ".", "match_members", "(", "res", ",", "(", "Map", "<", "EObject", ",", "ETuple", ">", ")", "map", ")", ";", "if", "(", "ordered", ")", "res", "=", "res", ".", "reverse", "(", ")", ";", "}", "else", "{", "ETuple", "candidate", "=", "(", "ETuple", ")", "map", ".", "valAt", "(", "key", ")", ";", "if", "(", "candidate", "!=", "null", ")", "{", "res", "=", "matcher", ".", "match_members", "(", "res", ",", "candidate", ")", ";", "}", "}", "return", "res", ";", "}", "@", "Override", "protected", "void", "delete", "(", "final", "EObject", "key", ")", "{", "in_tx", "(", "new", "WithMap", "<", "Object", ">", "(", ")", "{", "@", "Override", "protected", "Object", "run", "(", "IPersistentMap", "map", ")", "{", "try", "{", "map", "=", "map", ".", "without", "(", "key", ")", ";", "}", "catch", "(", "Exception", "e", ")", "{", "throw", "new", "Error", "(", "e", ")", ";", "}", "set", "(", "map", ")", ";", "return", "null", ";", "}", "}", ")", ";", "}", "@", "Override", "protected", "void", "delete_object", "(", "final", "ETuple", "obj", ")", "{", "in_tx", "(", "new", "WithMap", "<", "Object", ">", "(", ")", "{", "@", "Override", "protected", "Object", "run", "(", "IPersistentMap", "map", ")", "{", "EObject", "key", "=", "get_key", "(", "obj", ")", ";", "IMapEntry", "candidateEntry", "=", "map", ".", "entryAt", "(", "key", ")", ";", "if", "(", "candidateEntry", "==", "null", ")", "return", "null", ";", "EObject", "candidate", "=", "(", "EObject", ")", "candidateEntry", ".", "val", "(", ")", ";", "if", "(", "candidate", "!=", "null", "&&", "obj", ".", "equalsExactly", "(", "candidate", ")", ")", "{", "try", "{", "map", "=", "map", ".", "without", "(", "key", ")", ";", "set", "(", "map", ")", ";", "}", "catch", "(", "Exception", "e", ")", "{", "throw", "new", "Error", "(", "e", ")", ";", "}", "}", "return", "null", ";", "}", "}", ")", ";", "}", "@", "Override", "public", "EObject", "select", "(", "final", "EMatchSpec", "matcher", ",", "int", "limit", ")", "{", "IPersistentMap", "map", "=", "deref", "(", ")", ";", "EObject", "key", "=", "matcher", ".", "getTupleKey", "(", "keypos1", ")", ";", "if", "(", "key", "==", "null", ")", "{", "ESetCont", "cont0", "=", "new", "ESetCont", "(", "matcher", ",", "map", ".", "seq", "(", ")", ",", "ordered", ",", "limit", ")", ";", "return", "cont0", ".", "select", "(", ")", ";", "}", "else", "{", "ETuple", "candidate", "=", "(", "ETuple", ")", "map", ".", "valAt", "(", "key", ")", ";", "if", "(", "candidate", "==", "null", ")", "return", "Native", ".", "am_$end_of_table", ";", "EObject", "res", ";", "if", "(", "(", "res", "=", "matcher", ".", "match", "(", "candidate", ")", ")", "!=", "null", ")", "{", "return", "new", "ETuple2", "(", "ERT", ".", "NIL", ".", "cons", "(", "res", ")", ",", "Native", ".", "am_$end_of_table", ")", ";", "}", "}", "return", "Native", ".", "am_$end_of_table", ";", "}", "static", "class", "ESetCont", "extends", "EPseudoTerm", "implements", "ISelectContinuation", "{", "private", "final", "ISeq", "ent", ";", "private", "final", "EMatchSpec", "matcher", ";", "private", "final", "boolean", "ordered", ";", "private", "final", "int", "limit", ";", "public", "ESetCont", "(", "EMatchSpec", "matcher", ",", "ISeq", "ent", ",", "boolean", "ordered", ",", "int", "limit", ")", "{", "this", ".", "matcher", "=", "matcher", ";", "this", ".", "ent", "=", "ent", ";", "this", ".", "ordered", "=", "ordered", ";", "this", ".", "limit", "=", "limit", ";", "}", "public", "EObject", "select", "(", ")", "{", "int", "count", "=", "0", ";", "ESeq", "vals", "=", "ERT", ".", "NIL", ";", "ISeq", "map_seq", "=", "this", ".", "ent", ";", "while", "(", "seq_has_more", "(", "map_seq", ")", "&&", "(", "limit", "<", "0", "||", "count", "<", "limit", ")", ")", "{", "IMapEntry", "mape", "=", "(", "IMapEntry", ")", "map_seq", ".", "first", "(", ")", ";", "map_seq", "=", "map_seq", ".", "next", "(", ")", ";", "ETuple", "candidate", "=", "(", "ETuple", ")", "mape", ".", "getValue", "(", ")", ";", "EObject", "res", ";", "if", "(", "(", "res", "=", "matcher", ".", "match", "(", "candidate", ")", ")", "!=", "null", ")", "{", "count", "+=", "1", ";", "vals", "=", "vals", ".", "cons", "(", "res", ")", ";", "}", "}", "if", "(", "ordered", ")", "vals", "=", "vals", ".", "reverse", "(", ")", ";", "if", "(", "vals", "==", "ERT", ".", "NIL", ")", "{", "return", "Native", ".", "am_$end_of_table", ";", "}", "else", "if", "(", "!", "seq_has_more", "(", "map_seq", ")", ")", "{", "return", "new", "ETuple2", "(", "vals", ",", "Native", ".", "am_$end_of_table", ")", ";", "}", "else", "{", "return", "new", "ETuple2", "(", "vals", ",", "new", "ESetCont", "(", "matcher", ",", "map_seq", ",", "ordered", ",", "limit", ")", ")", ";", "}", "}", "private", "boolean", "seq_has_more", "(", "ISeq", "ent", ")", "{", "return", "ent", "!=", "null", "&&", "ent", "!=", "ent", ".", "empty", "(", ")", ";", "}", "@", "Override", "public", "int", "hashCode", "(", ")", "{", "return", "System", ".", "identityHashCode", "(", "this", ")", ";", "}", "}", "@", "Override", "public", "EInteger", "select_delete", "(", "final", "EMatchSpec", "matcher", ")", "{", "int", "delete_count", "=", "in_tx", "(", "new", "WithMap", "<", "Integer", ">", "(", ")", "{", "@", "Override", "protected", "Integer", "run", "(", "IPersistentMap", "map", ")", "{", "EObject", "key", "=", "matcher", ".", "getTupleKey", "(", "keypos1", ")", ";", "int", "count", "=", "0", ";", "if", "(", "key", "==", "null", ")", "{", "for", "(", "Map", ".", "Entry", "<", "EObject", ",", "ETuple", ">", "ent", ":", "(", "(", "Map", "<", "EObject", ",", "ETuple", ">", ")", "map", ")", ".", "entrySet", "(", ")", ")", "{", "ETuple", "val", "=", "ent", ".", "getValue", "(", ")", ";", "if", "(", "matcher", ".", "matches", "(", "val", ")", ")", "{", "try", "{", "map", "=", "map", ".", "without", "(", "ent", ".", "getKey", "(", ")", ")", ";", "}", "catch", "(", "Exception", "e", ")", "{", "throw", "new", "RuntimeException", "(", "e", ")", ";", "}", "count", "+=", "1", ";", "}", "}", "}", "else", "{", "ETuple", "candidate", "=", "(", "ETuple", ")", "map", ".", "valAt", "(", "key", ")", ";", "if", "(", "candidate", "!=", "null", "&&", "matcher", ".", "matches", "(", "candidate", ")", ")", "{", "try", "{", "map", "=", "map", ".", "without", "(", "key", ")", ";", "}", "catch", "(", "Exception", "e", ")", "{", "throw", "new", "RuntimeException", "(", "e", ")", ";", "}", "count", "+=", "1", ";", "}", "}", "set", "(", "map", ")", ";", "return", "count", ";", "}", "}", ")", ";", "return", "ERT", ".", "box", "(", "delete_count", ")", ";", "}", "public", "EObject", "update_counter", "(", "final", "EObject", "key", ",", "final", "EObject", "upd", ")", "{", "return", "in_tx", "(", "new", "WithMap", "<", "EObject", ">", "(", ")", "{", "@", "Override", "protected", "EObject", "run", "(", "IPersistentMap", "map", ")", "{", "ETuple", "rec", "=", "(", "ETuple", ")", "map", ".", "valAt", "(", "key", ")", ";", "if", "(", "rec", "==", "null", ")", "return", "null", ";", "if", "(", "type", "==", "Native", ".", "am_set", ")", "{", "if", "(", "!", "key", ".", "equalsExactly", "(", "get_key", "(", "rec", ")", ")", ")", "{", "return", "null", ";", "}", "}", "EInteger", "incr", ";", "ETuple", "one", ";", "if", "(", "(", "incr", "=", "upd", ".", "testInteger", "(", ")", ")", "!=", "null", ")", "{", "int", "idx", "=", "keypos1", "+", "1", ";", "rec", "=", "update", "(", "rec", ",", "idx", ",", "incr", ")", ";", "if", "(", "rec", "==", "null", ")", "return", "null", ";", "map", "=", "map", ".", "assoc", "(", "get_key", "(", "rec", ")", ",", "rec", ")", ";", "set", "(", "map", ")", ";", "return", "rec", ".", "elm", "(", "idx", ")", ";", "}", "else", "if", "(", "(", "one", "=", "upd", ".", "testTuple", "(", ")", ")", "!=", "null", ")", "{", "if", "(", "one", ".", "arity", "(", ")", "==", "2", ")", "{", "ESmall", "eidx", "=", "one", ".", "elm", "(", "1", ")", ".", "testSmall", "(", ")", ";", "incr", "=", "one", ".", "elm", "(", "2", ")", ".", "testInteger", "(", ")", ";", "if", "(", "eidx", "==", "null", "||", "eidx", ".", "value", ">", "rec", ".", "arity", "(", ")", "||", "incr", "==", "null", ")", "return", "null", ";", "int", "idx", "=", "eidx", ".", "value", ";", "rec", "=", "update", "(", "rec", ",", "idx", ",", "incr", ")", ";", "if", "(", "rec", "==", "null", ")", "return", "null", ";", "map", "=", "map", ".", "assoc", "(", "get_key", "(", "rec", ")", ",", "rec", ")", ";", "set", "(", "map", ")", ";", "return", "rec", ".", "elm", "(", "idx", ")", ";", "}", "else", "if", "(", "one", ".", "arity", "(", ")", "==", "4", ")", "{", "ESmall", "eidx", "=", "one", ".", "elm", "(", "1", ")", ".", "testSmall", "(", ")", ";", "incr", "=", "one", ".", "elm", "(", "2", ")", ".", "testInteger", "(", ")", ";", "EInteger", "threshold", "=", "one", ".", "elm", "(", "3", ")", ".", "testInteger", "(", ")", ";", "EInteger", "setvalue", "=", "one", ".", "elm", "(", "4", ")", ".", "testInteger", "(", ")", ";", "if", "(", "eidx", "==", "null", "||", "eidx", ".", "value", ">", "rec", ".", "arity", "(", ")", "||", "incr", "==", "null", "||", "threshold", "==", "null", "||", "setvalue", "==", "null", ")", "return", "null", ";", "int", "idx", "=", "eidx", ".", "value", ";", "rec", "=", "update", "(", "rec", ",", "idx", ",", "incr", ",", "threshold", ",", "setvalue", ")", ";", "if", "(", "rec", "==", "null", ")", "return", "null", ";", "map", "=", "map", ".", "assoc", "(", "get_key", "(", "rec", ")", ",", "rec", ")", ";", "set", "(", "map", ")", ";", "return", "rec", ".", "elm", "(", "idx", ")", ";", "}", "else", "{", "return", "null", ";", "}", "}", "else", "{", "throw", "new", "NotImplemented", "(", ")", ";", "}", "}", "private", "ETuple", "update", "(", "ETuple", "rec", ",", "int", "idx", ",", "EInteger", "incr", ")", "{", "EInteger", "old", "=", "rec", ".", "elm", "(", "idx", ")", ".", "testInteger", "(", ")", ";", "if", "(", "old", "==", "null", ")", "return", "null", ";", "EObject", "val", "=", "old", ".", "add", "(", "incr", ")", ";", "rec", "=", "ErlBif", ".", "setelement", "(", "idx", ",", "rec", ",", "val", ")", ";", "return", "rec", ";", "}", "private", "ETuple", "update", "(", "ETuple", "rec", ",", "int", "idx", ",", "EInteger", "incr", ",", "EInteger", "threshold", ",", "EInteger", "setvalue", ")", "{", "EInteger", "old", "=", "rec", ".", "elm", "(", "idx", ")", ".", "testInteger", "(", ")", ";", "if", "(", "old", "==", "null", ")", "return", "null", ";", "ENumber", "val", "=", "old", ".", "add", "(", "incr", ")", ";", "if", "(", "incr", ".", "is_ge", "(", "ESmall", ".", "ZERO", ")", ")", "{", "if", "(", "threshold", ".", "is_lt", "(", "val", ")", ")", "{", "val", "=", "setvalue", ";", "}", "}", "else", "{", "if", "(", "val", ".", "is_lt", "(", "threshold", ")", ")", "{", "val", "=", "setvalue", ";", "}", "}", "rec", "=", "ErlBif", ".", "setelement", "(", "idx", ",", "rec", ",", "val", ")", ";", "return", "rec", ";", "}", "}", ")", ";", "}", "public", "EObject", "update_element", "(", "final", "EObject", "key", ",", "final", "ESeq", "upd", ")", "{", "return", "in_tx", "(", "new", "WithMap", "<", "EObject", ">", "(", ")", "{", "@", "Override", "protected", "EObject", "run", "(", "IPersistentMap", "map", ")", "{", "ETuple", "rec", "=", "(", "ETuple", ")", "map", ".", "valAt", "(", "key", ")", ";", "if", "(", "rec", "==", "null", ")", "return", "ERT", ".", "FALSE", ";", "if", "(", "type", "==", "Native", ".", "am_set", ")", "{", "if", "(", "!", "key", ".", "equalsExactly", "(", "get_key", "(", "rec", ")", ")", ")", "{", "return", "ERT", ".", "FALSE", ";", "}", "}", "ETuple", "rep", "=", "null", ";", "for", "(", "ESeq", "next", "=", "upd", ";", "!", "next", ".", "isNil", "(", ")", ";", "next", "=", "next", ".", "tail", "(", ")", ")", "{", "ETuple2", "update", "=", "ETuple2", ".", "cast", "(", "next", ".", "head", "(", ")", ")", ";", "if", "(", "update", "==", "null", ")", "return", "null", ";", "ESmall", "idx1", "=", "update", ".", "elem1", ".", "testSmall", "(", ")", ";", "if", "(", "idx1", "==", "null", "||", "idx1", ".", "value", "<", "1", "||", "idx1", ".", "value", ">", "rec", ".", "arity", "(", ")", "||", "idx1", ".", "value", "==", "keypos1", ")", "return", "null", ";", "if", "(", "rep", "==", "null", ")", "{", "rep", "=", "rec", ".", "setelement", "(", "idx1", ".", "value", ",", "update", ".", "elem2", ")", ";", "}", "else", "{", "rep", ".", "set", "(", "idx1", ".", "value", ",", "update", ".", "elem2", ")", ";", "}", "}", "if", "(", "rep", "!=", "null", ")", "{", "map", "=", "map", ".", "assoc", "(", "get_key", "(", "rec", ")", ",", "rep", ")", ";", "set", "(", "map", ")", ";", "}", "return", "ERT", ".", "TRUE", ";", "}", "}", ")", ";", "}", "}", "</s>" ]
7,793
[ "<s>", "package", "erjang", ".", "m", ".", "ets", ";", "import", "java", ".", "lang", ".", "reflect", ".", "InvocationTargetException", ";", "import", "java", ".", "lang", ".", "reflect", ".", "Method", ";", "import", "java", ".", "util", ".", "ArrayList", ";", "import", "java", ".", "util", ".", "Collections", ";", "import", "java", ".", "util", ".", "HashSet", ";", "import", "java", ".", "util", ".", "List", ";", "import", "java", ".", "util", ".", "Map", ";", "import", "java", ".", "util", ".", "Set", ";", "import", "java", ".", "util", ".", "TreeSet", ";", "import", "com", ".", "trifork", ".", "clj_ds", ".", "IPersistentCollection", ";", "import", "com", ".", "trifork", ".", "clj_ds", ".", "ISeq", ";", "import", "erjang", ".", "EAtom", ";", "import", "erjang", ".", "EBitString", ";", "import", "erjang", ".", "ECons", ";", "import", "erjang", ".", "EFun", ";", "import", "erjang", ".", "ENumber", ";", "import", "erjang", ".", "EObject", ";", "import", "erjang", ".", "EPID", ";", "import", "erjang", ".", "EPort", ";", "import", "erjang", ".", "EPseudoTerm", ";", "import", "erjang", ".", "ERT", ";", "import", "erjang", ".", "ERef", ";", "import", "erjang", ".", "ESeq", ";", "import", "erjang", ".", "ETuple", ";", "import", "erjang", ".", "ETuple3", ";", "import", "erjang", ".", "ErlangError", ";", "import", "erjang", ".", "ErlangException", ";", "import", "erjang", ".", "NotImplemented", ";", "import", "erjang", ".", "beam", ".", "BIFUtil", ";", "import", "erjang", ".", "beam", ".", "BuiltInFunction", ";", "public", "class", "EMatchSpec", "extends", "EPseudoTerm", "{", "static", "final", "EAtom", "am_set_seq_token", "=", "EAtom", ".", "intern", "(", "\"\"", ")", ";", "static", "final", "EAtom", "am_get_seq_token", "=", "EAtom", ".", "intern", "(", "\"\"", ")", ";", "static", "final", "EAtom", "am_message", "=", "EAtom", ".", "intern", "(", "\"message\"", ")", ";", "static", "final", "EAtom", "am_return_trace", "=", "EAtom", ".", "intern", "(", "\"return_trace\"", ")", ";", "static", "final", "EAtom", "am_exception_trace", "=", "EAtom", ".", "intern", "(", "\"\"", ")", ";", "static", "final", "EAtom", "am_process_dump", "=", "EAtom", ".", "intern", "(", "\"process_dump\"", ")", ";", "static", "final", "EAtom", "am_enable_trace", "=", "EAtom", ".", "intern", "(", "\"enable_trace\"", ")", ";", "static", "final", "EAtom", "am_disable_trace", "=", "EAtom", ".", "intern", "(", "\"\"", ")", ";", "static", "final", "EAtom", "am_trace", "=", "EAtom", ".", "intern", "(", "\"trace\"", ")", ";", "static", "final", "EAtom", "am_display", "=", "EAtom", ".", "intern", "(", "\"display\"", ")", ";", "static", "final", "EAtom", "am_caller", "=", "EAtom", ".", "intern", "(", "\"caller\"", ")", ";", "static", "final", "EAtom", "am_set_tcw", "=", "EAtom", ".", "intern", "(", "\"set_tcw\"", ")", ";", "static", "final", "EAtom", "am_silent", "=", "EAtom", ".", "intern", "(", "\"silent\"", ")", ";", "static", "final", "Set", "<", "EAtom", ">", "ActionFunctions", "=", "new", "HashSet", "<", "EAtom", ">", "(", ")", ";", "static", "{", "Collections", ".", "addAll", "(", "ActionFunctions", ",", "am_set_seq_token", ",", "am_get_seq_token", ",", "am_message", ",", "am_return_trace", ",", "am_exception_trace", ",", "am_process_dump", ",", "am_enable_trace", ",", "am_disable_trace", ",", "am_trace", ",", "am_display", ",", "am_caller", ",", "am_set_tcw", ",", "am_silent", ")", ";", "}", "static", "final", "EAtom", "am_is_atom", "=", "EAtom", ".", "intern", "(", "\"is_atom\"", ")", ";", "static", "final", "EAtom", "am_is_constant", "=", "EAtom", ".", "intern", "(", "\"is_constant\"", ")", ";", "static", "final", "EAtom", "am_is_float", "=", "EAtom", ".", "intern", "(", "\"is_float\"", ")", ";", "static", "final", "EAtom", "am_is_integer", "=", "EAtom", ".", "intern", "(", "\"is_integer\"", ")", ";", "static", "final", "EAtom", "am_is_list", "=", "EAtom", ".", "intern", "(", "\"is_list\"", ")", ";", "static", "final", "EAtom", "am_is_number", "=", "EAtom", ".", "intern", "(", "\"is_number\"", ")", ";", "static", "final", "EAtom", "am_is_pid", "=", "EAtom", ".", "intern", "(", "\"is_pid\"", ")", ";", "static", "final", "EAtom", "am_is_port", "=", "EAtom", ".", "intern", "(", "\"is_port\"", ")", ";", "static", "final", "EAtom", "am_is_reference", "=", "EAtom", ".", "intern", "(", "\"is_reference\"", ")", ";", "static", "final", "EAtom", "am_is_tuple", "=", "EAtom", ".", "intern", "(", "\"is_tuple\"", ")", ";", "static", "final", "EAtom", "am_is_binary", "=", "EAtom", ".", "intern", "(", "\"is_binary\"", ")", ";", "static", "final", "EAtom", "am_is_function", "=", "EAtom", ".", "intern", "(", "\"is_function\"", ")", ";", "static", "final", "EAtom", "am_is_record", "=", "EAtom", ".", "intern", "(", "\"is_record\"", ")", ";", "static", "final", "EAtom", "am_is_seq_trace", "=", "EAtom", ".", "intern", "(", "\"is_seq_trace\"", ")", ";", "static", "final", "EAtom", "am_and", "=", "EAtom", ".", "intern", "(", "\"and\"", ")", ";", "static", "final", "EAtom", "am_or", "=", "EAtom", ".", "intern", "(", "\"or\"", ")", ";", "static", "final", "EAtom", "am_not", "=", "EAtom", ".", "intern", "(", "\"not\"", ")", ";", "static", "final", "EAtom", "am_xor", "=", "EAtom", ".", "intern", "(", "\"xor\"", ")", ";", "static", "final", "EAtom", "am_andalso", "=", "EAtom", ".", "intern", "(", "\"andalso\"", ")", ";", "static", "final", "EAtom", "am_orelse", "=", "EAtom", ".", "intern", "(", "\"orelse\"", ")", ";", "static", "final", "Set", "<", "EAtom", ">", "BoolFunctions", "=", "new", "HashSet", "<", "EAtom", ">", "(", ")", ";", "static", "{", "Collections", ".", "addAll", "(", "BoolFunctions", ",", "am_is_atom", ",", "am_is_constant", ",", "am_is_float", ",", "am_is_integer", ",", "am_is_list", ",", "am_is_number", ",", "am_is_pid", ",", "am_is_port", ",", "am_is_reference", ",", "am_is_tuple", ",", "am_is_binary", ",", "am_is_function", ",", "am_is_record", ",", "am_is_seq_trace", ",", "am_and", ",", "am_or", ",", "am_not", ",", "am_xor", ",", "am_andalso", ",", "am_orelse", ")", ";", "}", "static", "final", "EAtom", "am_abs", "=", "EAtom", ".", "intern", "(", "\"abs\"", ")", ";", "static", "final", "EAtom", "am_element", "=", "EAtom", ".", "intern", "(", "\"element\"", ")", ";", "static", "final", "EAtom", "am_hd", "=", "EAtom", ".", "intern", "(", "\"hd\"", ")", ";", "static", "final", "EAtom", "am_length", "=", "EAtom", ".", "intern", "(", "\"length\"", ")", ";", "static", "final", "EAtom", "am_node", "=", "EAtom", ".", "intern", "(", "\"node\"", ")", ";", "static", "final", "EAtom", "am_round", "=", "EAtom", ".", "intern", "(", "\"round\"", ")", ";", "static", "final", "EAtom", "am_size", "=", "EAtom", ".", "intern", "(", "\"size\"", ")", ";", "static", "final", "EAtom", "am_tl", "=", "EAtom", ".", "intern", "(", "\"tl\"", ")", ";", "static", "final", "EAtom", "am_trunc", "=", "EAtom", ".", "intern", "(", "\"trunc\"", ")", ";", "static", "final", "EAtom", "am_PLUS", "=", "EAtom", ".", "intern", "(", "\"+\"", ")", ";", "static", "final", "EAtom", "am_MINUS", "=", "EAtom", ".", "intern", "(", "\"-\"", ")", ";", "static", "final", "EAtom", "am_ASTERISK", "=", "EAtom", ".", "intern", "(", "\"*\"", ")", ";", "static", "final", "EAtom", "am_div", "=", "EAtom", ".", "intern", "(", "\"div\"", ")", ";", "static", "final", "EAtom", "am_rem", "=", "EAtom", ".", "intern", "(", "\"rem\"", ")", ";", "static", "final", "EAtom", "am_band", "=", "EAtom", ".", "intern", "(", "\"band\"", ")", ";", "static", "final", "EAtom", "am_bor", "=", "EAtom", ".", "intern", "(", "\"bor\"", ")", ";", "static", "final", "EAtom", "am_bxor", "=", "EAtom", ".", "intern", "(", "\"bxor\"", ")", ";", "static", "final", "EAtom", "am_bnor", "=", "EAtom", ".", "intern", "(", "\"bnor\"", ")", ";", "static", "final", "EAtom", "am_bsl", "=", "EAtom", ".", "intern", "(", "\"bsl\"", ")", ";", "static", "final", "EAtom", "am_bsr", "=", "EAtom", ".", "intern", "(", "\"bsr\"", ")", ";", "static", "final", "EAtom", "am_GT", "=", "EAtom", ".", "intern", "(", "\">\"", ")", ";", "static", "final", "EAtom", "am_GE", "=", "EAtom", ".", "intern", "(", "\">=\"", ")", ";", "static", "final", "EAtom", "am_LT", "=", "EAtom", ".", "intern", "(", "\"<\"", ")", ";", "static", "final", "EAtom", "am_LE", "=", "EAtom", ".", "intern", "(", "\"=<\"", ")", ";", "static", "final", "EAtom", "am_EEQ", "=", "EAtom", ".", "intern", "(", "\"=:=\"", ")", ";", "static", "final", "EAtom", "am_EQ", "=", "EAtom", ".", "intern", "(", "\"==\"", ")", ";", "static", "final", "EAtom", "am_ENE", "=", "EAtom", ".", "intern", "(", "\"=/=\"", ")", ";", "static", "final", "EAtom", "am_NE", "=", "EAtom", ".", "intern", "(", "\"/=\"", ")", ";", "static", "final", "EAtom", "am_self", "=", "EAtom", ".", "intern", "(", "\"self\"", ")", ";", "static", "final", "EAtom", "am_get_tcw", "=", "EAtom", ".", "intern", "(", "\"get_tcw\"", ")", ";", "static", "final", "Set", "<", "EAtom", ">", "GuardFunctions", "=", "new", "HashSet", "<", "EAtom", ">", "(", ")", ";", "static", "{", "GuardFunctions", ".", "addAll", "(", "BoolFunctions", ")", ";", "Collections", ".", "addAll", "(", "GuardFunctions", ",", "am_abs", ",", "am_element", ",", "am_hd", ",", "am_length", ",", "am_node", ",", "am_round", ",", "am_size", ",", "am_tl", ",", "am_trunc", ",", "am_PLUS", ",", "am_MINUS", ",", "am_ASTERISK", ",", "am_div", ",", "am_rem", ",", "am_band", ",", "am_bor", ",", "am_bxor", ",", "am_bsl", ",", "am_bsr", ",", "am_GT", ",", "am_GE", ",", "am_LT", ",", "am_LE", ",", "am_EEQ", ",", "am_EQ", ",", "am_ENE", ",", "am_NE", ",", "am_self", ",", "am_get_tcw", ")", ";", "}", "private", "static", "final", "EAtom", "am_ANY", "=", "EAtom", ".", "intern", "(", "\"_\"", ")", ";", "private", "static", "final", "EAtom", "am_ALL_VARS", "=", "EAtom", ".", "intern", "(", "\"$$\"", ")", ";", "private", "static", "final", "EAtom", "am_ENTIRE_MATCH", "=", "EAtom", ".", "intern", "(", "\"$_\"", ")", ";", "private", "static", "final", "EAtom", "am_const", "=", "EAtom", ".", "intern", "(", "\"const\"", ")", ";", "static", "java", ".", "util", ".", "regex", ".", "Pattern", "MATCH_VAR", "=", "java", ".", "util", ".", "regex", ".", "Pattern", ".", "compile", "(", "\"^\\\\$([0-9]+)$\"", ")", ";", "static", "final", "boolean", "is_match_var", "(", "EAtom", "am", ")", "{", "String", "name", "=", "am", ".", "getName", "(", ")", ";", "return", "name", ".", "length", "(", ")", ">", "0", "&&", "name", ".", "charAt", "(", "0", ")", "==", "'$'", "&&", "MATCH_VAR", ".", "matcher", "(", "name", ")", ".", "matches", "(", ")", ";", "}", "static", "final", "boolean", "is_expr_match_var", "(", "EAtom", "am", ")", "{", "return", "am", "==", "am_ALL_VARS", "||", "am", "==", "am_ENTIRE_MATCH", "||", "is_match_var", "(", "am", ")", ";", "}", "private", "final", "MatchFunction", "[", "]", "funs", ";", "private", "ESeq", "spec", ";", "static", "abstract", "class", "Pattern", "extends", "ETermPattern", "{", "abstract", "boolean", "is_simple", "(", ")", ";", "}", "static", "class", "EqualsPattern", "extends", "Pattern", "{", "final", "EObject", "value", ";", "boolean", "is_simple", "(", ")", "{", "return", "true", ";", "}", "public", "EqualsPattern", "(", "EObject", "term", ")", "{", "this", ".", "value", "=", "term", ";", "}", "@", "Override", "public", "boolean", "match", "(", "ECons", "c", ",", "EMatchContext", "r", ")", "{", "return", "c", ".", "erlangEquals", "(", "value", ")", ";", "}", "@", "Override", "public", "boolean", "match", "(", "ETuple", "t", ",", "EMatchContext", "r", ")", "{", "return", "t", ".", "erlangEquals", "(", "value", ")", ";", "}", "public", "boolean", "match", "(", "EPID", "pid", ",", "EMatchContext", "r", ")", "{", "return", "pid", ".", "erlangEquals", "(", "value", ")", ";", "}", "public", "boolean", "match", "(", "ERef", "ref", ",", "EMatchContext", "r", ")", "{", "return", "ref", ".", "erlangEquals", "(", "value", ")", ";", "}", "public", "boolean", "match", "(", "EPort", "port", ",", "EMatchContext", "r", ")", "{", "return", "port", ".", "erlangEquals", "(", "value", ")", ";", "}", "public", "boolean", "match", "(", "EAtom", "am", ",", "EMatchContext", "r", ")", "{", "return", "am", ".", "erlangEquals", "(", "value", ")", ";", "}", "public", "boolean", "match", "(", "EFun", "fu", ",", "EMatchContext", "r", ")", "{", "return", "fu", ".", "erlangEquals", "(", "value", ")", ";", "}", "public", "boolean", "match", "(", "EBitString", "bits", ",", "EMatchContext", "r", ")", "{", "return", "bits", ".", "erlangEquals", "(", "value", ")", ";", "}", "public", "boolean", "match", "(", "ENumber", "num", ",", "EMatchContext", "r", ")", "{", "return", "num", ".", "erlangEquals", "(", "value", ")", ";", "}", "}", "static", "abstract", "class", "Expr", "{", "public", "static", "final", "Expr", "[", "]", "EMPTY_ARR", "=", "new", "Expr", "[", "0", "]", ";", "public", "abstract", "EObject", "eval", "(", "EMatchContext", "ctx", ")", ";", "}", "static", "class", "ActionCall", "extends", "Expr", "{", "EAtom", "action", ";", "Expr", "[", "]", "args", ";", "public", "ActionCall", "(", "ETuple", "t", ",", "ParseContext", "ctx", ")", "{", "assert", "(", "ActionFunctions", ".", "contains", "(", "t", ".", "elm", "(", "1", ")", ")", ")", ";", "action", "=", "t", ".", "elm", "(", "1", ")", ".", "testAtom", "(", ")", ";", "args", "=", "new", "Expr", "[", "t", ".", "arity", "(", ")", "-", "1", "]", ";", "for", "(", "int", "i", "=", "2", ";", "i", "<=", "t", ".", "arity", "(", ")", ";", "i", "++", ")", "{", "args", "[", "i", "-", "2", "]", "=", "parse_ActionTerm", "(", "t", ".", "elm", "(", "i", ")", ",", "ctx", ")", ";", "}", "}", "@", "Override", "public", "EObject", "eval", "(", "EMatchContext", "ctx", ")", "{", "EObject", "[", "]", "vals", "=", "new", "EObject", "[", "args", ".", "length", "]", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "vals", ".", "length", ";", "i", "++", ")", "{", "vals", "[", "i", "]", "=", "args", "[", "i", "]", ".", "eval", "(", "ctx", ")", ";", "}", "List", "<", "EObject", ">", "aa", "=", "new", "ArrayList", "<", "EObject", ">", "(", ")", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "vals", ".", "length", ";", "i", "++", ")", "{", "aa", ".", "add", "(", "vals", "[", "i", "]", ")", ";", "}", "throw", "new", "NotImplemented", "(", "\"ActionCall", "\"", "+", "action", "+", "\"", "\"", "+", "aa", ")", ";", "}", "}", "static", "class", "TupleConstruct", "extends", "Expr", "{", "final", "Expr", "[", "]", "elems", ";", "public", "TupleConstruct", "(", "ETuple", "innerT", ",", "ParseContext", "ctx", ")", "{", "elems", "=", "new", "Expr", "[", "innerT", ".", "arity", "(", ")", "]", ";", "for", "(", "int", "idx1", "=", "1", ";", "idx1", "<=", "innerT", ".", "arity", "(", ")", ";", "idx1", "++", ")", "{", "elems", "[", "idx1", "-", "1", "]", "=", "parse_ConditionExpression", "(", "innerT", ".", "elm", "(", "idx1", ")", ",", "ctx", ")", ";", "}", "}", "@", "Override", "public", "EObject", "eval", "(", "EMatchContext", "ctx", ")", "{", "ETuple", "res", "=", "ETuple", ".", "make", "(", "elems", ".", "length", ")", ";", "for", "(", "int", "idx0", "=", "0", ";", "idx0", "<", "elems", ".", "length", ";", "idx0", "++", ")", "{", "res", ".", "set", "(", "idx0", "+", "1", ",", "elems", "[", "idx0", "]", ".", "eval", "(", "ctx", ")", ")", ";", "}", "return", "res", ";", "}", "}", "static", "class", "ConsConstruct", "extends", "Expr", "{", "Expr", "head_expr", ",", "tail_expr", ";", "public", "ConsConstruct", "(", "ECons", "seq", ",", "ParseContext", "ctx", ")", "{", "head_expr", "=", "parse_ConditionExpression", "(", "seq", ".", "head", "(", ")", ",", "ctx", ")", ";", "tail_expr", "=", "parse_ConditionExpression", "(", "seq", ".", "tail", "(", ")", ",", "ctx", ")", ";", "}", "@", "Override", "public", "EObject", "eval", "(", "EMatchContext", "ctx", ")", "{", "EObject", "head", "=", "head_expr", ".", "eval", "(", "ctx", ")", ";", "EObject", "tail", "=", "tail_expr", ".", "eval", "(", "ctx", ")", ";", "return", "tail", ".", "cons", "(", "head", ")", ";", "}", "}", "static", "class", "ConstantExpr", "extends", "Expr", "{", "final", "EObject", "term", ";", "ConstantExpr", "(", "EObject", "term", ")", "{", "this", ".", "term", "=", "term", ";", "}", "@", "Override", "public", "EObject", "eval", "(", "EMatchContext", "ctx", ")", "{", "return", "term", ";", "}", "}", "static", "class", "MatchVarExpr", "extends", "Expr", "{", "final", "int", "var_name", ";", "static", "final", "int", "EXPR_ALL_VARS", "=", "-", "1", ";", "static", "final", "int", "EXPR_ENTIRE_MATCH", "=", "-", "2", ";", "MatchVarExpr", "(", "EAtom", "var", ",", "ParseContext", "ctx", ")", "{", "if", "(", "var", "==", "am_ALL_VARS", ")", "{", "var_name", "=", "EXPR_ALL_VARS", ";", "}", "else", "if", "(", "var", "==", "am_ENTIRE_MATCH", ")", "{", "var_name", "=", "EXPR_ENTIRE_MATCH", ";", "}", "else", "{", "int", "idx", "=", "Integer", ".", "parseInt", "(", "var", ".", "getName", "(", ")", ".", "substring", "(", "1", ")", ")", ";", "var_name", "=", "idx", ";", "if", "(", "var_name", ">", "100000000", "||", "var_name", "<", "0", ")", "{", "throw", "new", "IllegalArgumentException", "(", "\"given", "index", "\"", "+", "idx", "+", "\"\"", ")", ";", "}", "if", "(", "!", "ctx", ".", "isBound", "(", "var_name", ")", ")", "{", "throw", "new", "IllegalArgumentException", "(", "\"\"", "+", "idx", ")", ";", "}", "}", "}", "@", "Override", "public", "EObject", "eval", "(", "EMatchContext", "ctx", ")", "{", "if", "(", "var_name", "==", "EXPR_ENTIRE_MATCH", ")", "{", "return", "ctx", ".", "value", ";", "}", "else", "if", "(", "var_name", "==", "EXPR_ALL_VARS", ")", "{", "return", "ctx", ".", "makeList", "(", ")", ";", "}", "else", "{", "EObject", "value", "=", "ctx", ".", "vars", ".", "get", "(", "var_name", ")", ";", "if", "(", "value", "==", "null", ")", "throw", "new", "InternalError", "(", "\"Unbound", "$\"", "+", "var_name", ")", ";", "return", "value", ";", "}", "}", "}", "static", "class", "MatchFunction", "{", "private", "final", "Pattern", "head", ";", "private", "final", "GuardCall", "[", "]", "cond", ";", "private", "final", "Expr", "[", "]", "body", ";", "private", "final", "Integer", "[", "]", "nvars", ";", "public", "MatchFunction", "(", "Pattern", "head", ",", "GuardCall", "[", "]", "cond", ",", "Expr", "[", "]", "body", ",", "Integer", "[", "]", "nvars", ")", "{", "this", ".", "head", "=", "head", ";", "this", ".", "cond", "=", "cond", ";", "this", ".", "body", "=", "body", ";", "this", ".", "nvars", "=", "nvars", ";", "}", "EObject", "match", "(", "EObject", "value", ")", "{", "EMatchContext", "ctx", "=", "new", "EMatchContext", "(", "nvars", ",", "value", ")", ";", "if", "(", "!", "value", ".", "match", "(", "head", ",", "ctx", ")", ")", "{", "return", "null", ";", "}", "try", "{", "for", "(", "int", "i", "=", "0", ";", "i", "<", "cond", ".", "length", ";", "i", "++", ")", "{", "if", "(", "!", "cond", "[", "i", "]", ".", "test", "(", "ctx", ")", ")", "return", "null", ";", "}", "}", "catch", "(", "Exception", "e", ")", "{", "return", "null", ";", "}", "EObject", "out", "=", "value", ";", "try", "{", "for", "(", "int", "i", "=", "0", ";", "i", "<", "body", ".", "length", ";", "i", "++", ")", "{", "out", "=", "body", "[", "i", "]", ".", "eval", "(", "ctx", ")", ";", "}", "}", "catch", "(", "Exception", "e", ")", "{", "e", ".", "printStackTrace", "(", ")", ";", "out", "=", "ERT", ".", "am_EXIT", ";", "}", "return", "out", ";", "}", "}", "static", "class", "GuardCall", "extends", "Expr", "{", "EAtom", "guard", ";", "Expr", "[", "]", "args", ";", "private", "BuiltInFunction", "bif", ";", "public", "GuardCall", "(", "ETuple", "t", ",", "ParseContext", "ctx", ")", "{", "if", "(", "t", ".", "arity", "(", ")", "<", "1", "||", "!", "GuardFunctions", ".", "contains", "(", "t", ".", "elm", "(", "1", ")", ")", ")", "{", "throw", "ERT", ".", "badarg", "(", ")", ";", "}", "guard", "=", "t", ".", "elm", "(", "1", ")", ".", "testAtom", "(", ")", ";", "args", "=", "new", "Expr", "[", "t", ".", "arity", "(", ")", "-", "1", "]", ";", "for", "(", "int", "i", "=", "2", ";", "i", "<=", "t", ".", "arity", "(", ")", ";", "i", "++", ")", "{", "args", "[", "i", "-", "2", "]", "=", "parse_ConditionExpression", "(", "t", ".", "elm", "(", "i", ")", ",", "ctx", ")", ";", "}", "this", ".", "bif", "=", "BIFUtil", ".", "getMethod", "(", "\"erlang\"", ",", "guard", ".", "getName", "(", ")", ",", "args", ".", "length", ",", "true", ",", "false", ")", ";", "}", "public", "boolean", "test", "(", "EMatchContext", "ctx", ")", "{", "EObject", "[", "]", "vals", "=", "new", "EObject", "[", "args", ".", "length", "]", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "vals", ".", "length", ";", "i", "++", ")", "{", "vals", "[", "i", "]", "=", "args", "[", "i", "]", ".", "eval", "(", "ctx", ")", ";", "}", "if", "(", "bif", "!=", "null", ")", "{", "try", "{", "Method", "m", "=", "bif", ".", "javaMethod", ";", "if", "(", "bif", ".", "isVirtual", ")", "{", "Object", "[", "]", "vargs", "=", "new", "Object", "[", "vals", ".", "length", "-", "1", "]", ";", "System", ".", "arraycopy", "(", "vals", ",", "1", ",", "vargs", ",", "0", ",", "vals", ".", "length", "-", "1", ")", ";", "return", "m", ".", "invoke", "(", "vals", "[", "0", "]", ",", "(", "Object", "[", "]", ")", "vargs", ")", "==", "ERT", ".", "TRUE", ";", "}", "else", "{", "return", "m", ".", "invoke", "(", "null", ",", "(", "Object", "[", "]", ")", "vals", ")", "==", "ERT", ".", "TRUE", ";", "}", "}", "catch", "(", "ErlangException", "e", ")", "{", "throw", "e", ";", "}", "catch", "(", "IllegalArgumentException", "e", ")", "{", "e", ".", "printStackTrace", "(", ")", ";", "return", "false", ";", "}", "catch", "(", "IllegalAccessException", "e", ")", "{", "e", ".", "printStackTrace", "(", ")", ";", "return", "false", ";", "}", "catch", "(", "InvocationTargetException", "e", ")", "{", "e", ".", "printStackTrace", "(", ")", ";", "return", "false", ";", "}", "}", "else", "{", "List", "<", "EObject", ">", "aa", "=", "new", "ArrayList", "<", "EObject", ">", "(", ")", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "vals", ".", "length", ";", "i", "++", ")", "{", "aa", ".", "add", "(", "vals", "[", "i", "]", ")", ";", "}", "throw", "new", "NotImplemented", "(", "\"\"", "+", "guard", "+", "\"", "\"", "+", "aa", ")", ";", "}", "}", "public", "static", "final", "GuardCall", "[", "]", "EMPTY_ARR", "=", "new", "GuardCall", "[", "0", "]", ";", "@", "Override", "public", "EObject", "eval", "(", "EMatchContext", "ctx", ")", "{", "EObject", "[", "]", "vals", "=", "new", "EObject", "[", "args", ".", "length", "]", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "vals", ".", "length", ";", "i", "++", ")", "{", "vals", "[", "i", "]", "=", "args", "[", "i", "]", ".", "eval", "(", "ctx", ")", ";", "}", "if", "(", "bif", "!=", "null", ")", "{", "try", "{", "Method", "m", "=", "bif", ".", "javaMethod", ";", "if", "(", "bif", ".", "isVirtual", ")", "{", "Object", "[", "]", "vargs", "=", "new", "Object", "[", "vals", ".", "length", "-", "1", "]", ";", "System", ".", "arraycopy", "(", "vals", ",", "1", ",", "vargs", ",", "0", ",", "vals", ".", "length", "-", "1", ")", ";", "return", "(", "EObject", ")", "m", ".", "invoke", "(", "vals", "[", "0", "]", ",", "(", "Object", "[", "]", ")", "vargs", ")", ";", "}", "else", "{", "return", "(", "EObject", ")", "m", ".", "invoke", "(", "null", ",", "(", "Object", "[", "]", ")", "vals", ")", ";", "}", "}", "catch", "(", "ErlangException", "e", ")", "{", "throw", "e", ";", "}", "catch", "(", "IllegalArgumentException", "e", ")", "{", "e", ".", "printStackTrace", "(", ")", ";", "throw", "new", "ErlangError", "(", "e", ")", ";", "}", "catch", "(", "IllegalAccessException", "e", ")", "{", "e", ".", "printStackTrace", "(", ")", ";", "throw", "new", "ErlangError", "(", "e", ")", ";", "}", "catch", "(", "InvocationTargetException", "e", ")", "{", "e", ".", "printStackTrace", "(", ")", ";", "throw", "new", "ErlangError", "(", "e", ")", ";", "}", "}", "else", "{", "List", "<", "EObject", ">", "aa", "=", "new", "ArrayList", "<", "EObject", ">", "(", ")", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "vals", ".", "length", ";", "i", "++", ")", "{", "aa", ".", "add", "(", "vals", "[", "i", "]", ")", ";", "}", "throw", "new", "NotImplemented", "(", "\"\"", "+", "guard", "+", "\"", "\"", "+", "aa", ")", ";", "}", "}", "}", "enum", "ParseMode", "{", "HEAD", ",", "CONDITIONS", ",", "BODY", "}", "static", "class", "ParseContext", "{", "private", "Set", "<", "Integer", ">", "bound", "=", "new", "TreeSet", "<", "Integer", ">", "(", ")", ";", "private", "ParseMode", "mode", ";", "public", "boolean", "isBound", "(", "int", "idx0", ")", "{", "return", "bound", ".", "contains", "(", "idx0", ")", ";", "}", "public", "void", "bind", "(", "MatchVariable", "matchVariable", ",", "int", "idx0", ")", "{", "bound", ".", "add", "(", "idx0", ")", ";", "}", "public", "void", "setMode", "(", "ParseMode", "mode", ")", "{", "this", ".", "mode", "=", "mode", ";", "}", "public", "Integer", "[", "]", "getNumberVars", "(", ")", "{", "return", "bound", ".", "toArray", "(", "new", "Integer", "[", "bound", ".", "size", "(", ")", "]", ")", ";", "}", "}", "static", "MatchFunction", "parse_MatchFunction", "(", "EObject", "fspec", ")", "{", "ETuple3", "tup", "=", "ETuple3", ".", "cast", "(", "fspec", ")", ";", "if", "(", "tup", "==", "null", ")", "throw", "ERT", ".", "badarg", "(", "fspec", ")", ";", "ParseContext", "ctx", "=", "new", "ParseContext", "(", ")", ";", "ctx", ".", "setMode", "(", "ParseMode", ".", "HEAD", ")", ";", "Pattern", "head", "=", "parse_MatchHead", "(", "tup", ".", "elem1", ",", "ctx", ")", ";", "ctx", ".", "setMode", "(", "ParseMode", ".", "CONDITIONS", ")", ";", "GuardCall", "[", "]", "cond", "=", "parse_MatchConditions", "(", "tup", ".", "elem2", ".", "testSeq", "(", ")", ",", "ctx", ")", ";", "ctx", ".", "setMode", "(", "ParseMode", ".", "BODY", ")", ";", "Expr", "[", "]", "body", "=", "parse_MatchBody", "(", "tup", ".", "elem3", ".", "testSeq", "(", ")", ",", "ctx", ")", ";", "return", "new", "MatchFunction", "(", "head", ",", "cond", ",", "body", ",", "ctx", ".", "getNumberVars", "(", ")", ")", ";", "}", "private", "static", "Expr", "[", "]", "parse_MatchBody", "(", "ESeq", "actionTerms", ",", "ParseContext", "ctx", ")", "{", "if", "(", "actionTerms", "==", "null", ")", "throw", "ERT", ".", "badarg", "(", ")", ";", "if", "(", "actionTerms", "==", "ERT", ".", "NIL", ")", "{", "return", "Expr", ".", "EMPTY_ARR", ";", "}", "List", "<", "Expr", ">", "terms", "=", "new", "ArrayList", "<", "Expr", ">", "(", "actionTerms", ".", "length", "(", ")", ")", ";", "for", "(", "ESeq", "actions", "=", "actionTerms", ";", "!", "actions", ".", "isNil", "(", ")", ";", "actions", "=", "actions", ".", "tail", "(", ")", ")", "{", "EObject", "action", "=", "actions", ".", "head", "(", ")", ";", "terms", ".", "add", "(", "parse_ActionTerm", "(", "action", ",", "ctx", ")", ")", ";", "}", "return", "terms", ".", "toArray", "(", "new", "Expr", "[", "terms", ".", "size", "(", ")", "]", ")", ";", "}", "private", "static", "Expr", "parse_ActionTerm", "(", "EObject", "action", ",", "ParseContext", "ctx", ")", "{", "ETuple", "t", "=", "action", ".", "testTuple", "(", ")", ";", "if", "(", "t", "!=", "null", "&&", "t", ".", "arity", "(", ")", ">=", "1", "&&", "ActionFunctions", ".", "contains", "(", "t", ".", "elm", "(", "1", ")", ")", ")", "{", "return", "new", "ActionCall", "(", "t", ",", "ctx", ")", ";", "}", "else", "{", "return", "parse_ConditionExpression", "(", "action", ",", "ctx", ")", ";", "}", "}", "private", "static", "Expr", "parse_ConditionExpression", "(", "EObject", "expr", ",", "ParseContext", "ctx", ")", "{", "EAtom", "am", "=", "expr", ".", "testAtom", "(", ")", ";", "if", "(", "am", "!=", "null", "&&", "is_expr_match_var", "(", "am", ")", ")", "{", "return", "parse_ExprMatchVariable", "(", "am", ",", "ctx", ")", ";", "}", "ETuple", "t", "=", "expr", ".", "testTuple", "(", ")", ";", "if", "(", "t", "!=", "null", "&&", "t", ".", "arity", "(", ")", ">=", "1", "&&", "GuardFunctions", ".", "contains", "(", "t", ".", "elm", "(", "1", ")", ")", ")", "{", "return", "parse_MatchCondition", "(", "t", ",", "ctx", ")", ";", "}", "return", "parse_TermConstruct", "(", "expr", ",", "ctx", ")", ";", "}", "private", "static", "Expr", "parse_TermConstruct", "(", "EObject", "expr", ",", "ParseContext", "ctx", ")", "{", "ETuple", "t", "=", "expr", ".", "testTuple", "(", ")", ";", "if", "(", "t", "!=", "null", ")", "{", "if", "(", "t", ".", "arity", "(", ")", "==", "2", "&&", "t", ".", "elm", "(", "1", ")", "==", "am_const", ")", "{", "return", "new", "ConstantExpr", "(", "t", ".", "elm", "(", "2", ")", ")", ";", "}", "ETuple", "inner_t", ";", "if", "(", "t", ".", "arity", "(", ")", "==", "1", "&&", "(", "inner_t", "=", "t", ".", "elm", "(", "1", ")", ".", "testTuple", "(", ")", ")", "!=", "null", ")", "{", "return", "new", "TupleConstruct", "(", "inner_t", ",", "ctx", ")", ";", "}", "throw", "ERT", ".", "badarg", "(", ")", ";", "}", "ECons", "cons", "=", "expr", ".", "testCons", "(", ")", ";", "if", "(", "cons", "!=", "null", "&&", "!", "cons", ".", "isNil", "(", ")", ")", "{", "return", "new", "ConsConstruct", "(", "cons", ",", "ctx", ")", ";", "}", "return", "new", "ConstantExpr", "(", "expr", ")", ";", "}", "private", "static", "Expr", "parse_ExprMatchVariable", "(", "EAtom", "am", ",", "ParseContext", "ctx", ")", "{", "assert", "is_match_var", "(", "am", ")", ";", "return", "new", "MatchVarExpr", "(", "am", ",", "ctx", ")", ";", "}", "private", "static", "GuardCall", "[", "]", "parse_MatchConditions", "(", "ESeq", "conds", ",", "ParseContext", "ctx", ")", "{", "if", "(", "conds", "==", "null", ")", "throw", "ERT", ".", "badarg", "(", ")", ";", "if", "(", "conds", ".", "isNil", "(", ")", ")", "{", "return", "GuardCall", ".", "EMPTY_ARR", ";", "}", "List", "<", "GuardCall", ">", "res", "=", "new", "ArrayList", "<", "GuardCall", ">", "(", ")", ";", "while", "(", "!", "conds", ".", "isNil", "(", ")", ")", "{", "res", ".", "add", "(", "parse_MatchCondition", "(", "conds", ".", "head", "(", ")", ",", "ctx", ")", ")", ";", "conds", "=", "conds", ".", "tail", "(", ")", ";", "}", "return", "res", ".", "toArray", "(", "new", "GuardCall", "[", "res", ".", "size", "(", ")", "]", ")", ";", "}", "private", "static", "GuardCall", "parse_MatchCondition", "(", "EObject", "expr", ",", "ParseContext", "ctx", ")", "{", "ETuple", "t", "=", "expr", ".", "testTuple", "(", ")", ";", "if", "(", "t", "==", "null", "||", "t", ".", "arity", "(", ")", "<", "1", "||", "!", "GuardFunctions", ".", "contains", "(", "t", ".", "elm", "(", "1", ")", ")", ")", "{", "throw", "ERT", ".", "badarg", "(", "expr", ")", ";", "}", "return", "new", "GuardCall", "(", "t", ",", "ctx", ")", ";", "}", "private", "static", "Pattern", "parse_MatchHead", "(", "EObject", "head", ",", "ParseContext", "ctx", ")", "{", "Pattern", "p", "=", "compile_Match", "(", "head", ",", "ctx", ")", ";", "if", "(", "p", "!=", "null", ")", "return", "p", ";", "throw", "ERT", ".", "badarg", "(", "head", ")", ";", "}", "private", "static", "Pattern", "compile_Match", "(", "EObject", "head", ",", "ParseContext", "ctx", ")", "{", "EAtom", "am", ";", "ECons", "cons", ";", "ETuple", "tuple", ";", "if", "(", "head", "==", "am_ANY", ")", "{", "return", "(", "AnyPattern", ".", "INSTANCE", ")", ";", "}", "else", "if", "(", "(", "am", "=", "head", ".", "testAtom", "(", ")", ")", "!=", "null", "&&", "is_match_var", "(", "am", ")", ")", "{", "return", "(", "parse_MatchVariable", "(", "am", ",", "ctx", ")", ")", ";", "}", "else", "if", "(", "head", ".", "isNil", "(", ")", ")", "{", "return", "NilPattern", ".", "INSTANCE", ";", "}", "else", "if", "(", "(", "cons", "=", "head", ".", "testCons", "(", ")", ")", "!=", "null", ")", "{", "return", "(", "new", "ConsPattern", "(", "cons", ",", "ctx", ")", ")", ";", "}", "else", "if", "(", "(", "tuple", "=", "head", ".", "testTuple", "(", ")", ")", "!=", "null", ")", "{", "TuplePattern", "tp", "=", "new", "TuplePattern", "(", "tuple", ",", "ctx", ")", ";", "if", "(", "tp", ".", "is_simple", "(", ")", ")", "{", "return", "new", "EqualsPattern", "(", "tuple", ")", ";", "}", "else", "{", "return", "tp", ";", "}", "}", "return", "null", ";", "}", "static", "class", "TuplePattern", "extends", "Pattern", "{", "Pattern", "[", "]", "elems", ";", "boolean", "is_simple", "(", ")", "{", "for", "(", "int", "i", "=", "0", ";", "i", "<", "elems", ".", "length", ";", "i", "++", ")", "{", "if", "(", "!", "elems", "[", "i", "]", ".", "is_simple", "(", ")", ")", "{", "return", "false", ";", "}", "}", "return", "true", ";", "}", "public", "TuplePattern", "(", "ETuple", "tuple", ",", "ParseContext", "ctx", ")", "{", "elems", "=", "new", "Pattern", "[", "tuple", ".", "arity", "(", ")", "]", ";", "for", "(", "int", "idx1", "=", "1", ";", "idx1", "<=", "tuple", ".", "arity", "(", ")", ";", "idx1", "++", ")", "{", "elems", "[", "idx1", "-", "1", "]", "=", "parse_MatchHeadPart", "(", "tuple", ".", "elm", "(", "idx1", ")", ",", "ctx", ")", ";", "}", "}", "@", "Override", "public", "boolean", "match", "(", "ETuple", "t", ",", "EMatchContext", "r", ")", "{", "if", "(", "t", ".", "arity", "(", ")", "!=", "elems", ".", "length", ")", "return", "false", ";", "for", "(", "int", "idx0", "=", "0", ";", "idx0", "<", "elems", ".", "length", ";", "idx0", "++", ")", "{", "if", "(", "!", "t", ".", "elm", "(", "idx0", "+", "1", ")", ".", "match", "(", "elems", "[", "idx0", "]", ",", "r", ")", ")", "return", "false", ";", "}", "return", "true", ";", "}", "}", "static", "class", "NilPattern", "extends", "Pattern", "{", "static", "final", "NilPattern", "INSTANCE", "=", "new", "NilPattern", "(", ")", ";", "boolean", "is_simple", "(", ")", "{", "return", "true", ";", "}", "@", "Override", "public", "boolean", "match", "(", "ECons", "c", ",", "EMatchContext", "r", ")", "{", "return", "c", ".", "isNil", "(", ")", ";", "}", "}", "static", "class", "ConsPattern", "extends", "Pattern", "{", "Pattern", "head_p", ",", "tail_p", ";", "boolean", "is_simple", "(", ")", "{", "return", "head_p", ".", "is_simple", "(", ")", "&&", "tail_p", ".", "is_simple", "(", ")", ";", "}", "public", "ConsPattern", "(", "ECons", "cons", ",", "ParseContext", "ctx", ")", "{", "head_p", "=", "parse_MatchHeadPart", "(", "cons", ".", "head", "(", ")", ",", "ctx", ")", ";", "tail_p", "=", "parse_MatchHeadPart", "(", "cons", ".", "tail", "(", ")", ",", "ctx", ")", ";", "}", "@", "Override", "public", "boolean", "match", "(", "ECons", "c", ",", "EMatchContext", "r", ")", "{", "if", "(", "c", ".", "isNil", "(", ")", ")", "return", "false", ";", "return", "c", ".", "head", "(", ")", ".", "match", "(", "head_p", ",", "r", ")", "&&", "c", ".", "tail", "(", ")", ".", "match", "(", "tail_p", ",", "r", ")", ";", "}", "}", "private", "static", "Pattern", "parse_MatchHeadPart", "(", "EObject", "part", ",", "ParseContext", "ctx", ")", "{", "Pattern", "p", "=", "compile_Match", "(", "part", ",", "ctx", ")", ";", "if", "(", "p", "!=", "null", ")", "return", "p", ";", "return", "new", "EqualsPattern", "(", "part", ")", ";", "}", "private", "static", "Pattern", "parse_MatchVariable", "(", "EAtom", "am", ",", "ParseContext", "ctx", ")", "{", "return", "new", "MatchVariable", "(", "am", ",", "ctx", ")", ";", "}", "static", "class", "AnyPattern", "extends", "Pattern", "{", "static", "AnyPattern", "INSTANCE", "=", "new", "AnyPattern", "(", ")", ";", "boolean", "is_simple", "(", ")", "{", "return", "false", ";", "}", "public", "boolean", "match", "(", "ETuple", "t", ",", "EMatchContext", "r", ")", "{", "return", "true", ";", "}", "public", "boolean", "match", "(", "ENumber", "n", ",", "EMatchContext", "r", ")", "{", "return", "true", ";", "}", "public", "boolean", "match", "(", "EAtom", "a", ",", "EMatchContext", "r", ")", "{", "return", "true", ";", "}", "public", "boolean", "match", "(", "EFun", "a", ",", "EMatchContext", "r", ")", "{", "return", "true", ";", "}", "public", "boolean", "match", "(", "ERef", "a", ",", "EMatchContext", "r", ")", "{", "return", "true", ";", "}", "public", "boolean", "match", "(", "ECons", "c", ",", "EMatchContext", "r", ")", "{", "return", "true", ";", "}", "public", "boolean", "match", "(", "EPID", "p", ",", "EMatchContext", "r", ")", "{", "return", "true", ";", "}", "public", "boolean", "match", "(", "EPort", "p", ",", "EMatchContext", "r", ")", "{", "return", "true", ";", "}", "public", "boolean", "match", "(", "EBitString", "bs", ",", "EMatchContext", "r", ")", "{", "return", "true", ";", "}", "}", "static", "class", "MatchVariable", "extends", "Pattern", "{", "final", "boolean", "free", ";", "final", "Integer", "var_name", ";", "boolean", "is_simple", "(", ")", "{", "return", "false", ";", "}", "public", "MatchVariable", "(", "EAtom", "var", ",", "ParseContext", "ctx", ")", "{", "int", "name", "=", "Integer", ".", "parseInt", "(", "var", ".", "getName", "(", ")", ".", "substring", "(", "1", ")", ")", ";", "this", ".", "var_name", "=", "name", ";", "if", "(", "name", ">", "100000000", "||", "name", "<", "0", ")", "{", "throw", "new", "IllegalArgumentException", "(", "\"given", "index", "\"", "+", "name", "+", "\"\"", ")", ";", "}", "free", "=", "!", "ctx", ".", "isBound", "(", "name", ")", ";", "if", "(", "free", ")", "ctx", ".", "bind", "(", "this", ",", "name", ")", ";", "}", "public", "boolean", "match", "(", "ETuple", "t", ",", "EMatchContext", "r", ")", "{", "if", "(", "free", ")", "{", "r", ".", "vars", ".", "put", "(", "var_name", ",", "t", ")", ";", "return", "true", ";", "}", "else", "{", "return", "t", ".", "equalsExactly", "(", "r", ".", "vars", ".", "get", "(", "var_name", ")", ")", ";", "}", "}", "public", "boolean", "match", "(", "ENumber", "t", ",", "EMatchContext", "r", ")", "{", "if", "(", "free", ")", "{", "r", ".", "vars", ".", "put", "(", "var_name", ",", "t", ")", ";", "return", "true", ";", "}", "else", "{", "return", "t", ".", "equalsExactly", "(", "r", ".", "vars", ".", "get", "(", "var_name", ")", ")", ";", "}", "}", "public", "boolean", "match", "(", "EAtom", "t", ",", "EMatchContext", "r", ")", "{", "if", "(", "free", ")", "{", "r", ".", "vars", ".", "put", "(", "var_name", ",", "t", ")", ";", "return", "true", ";", "}", "else", "{", "return", "t", ".", "equalsExactly", "(", "r", ".", "vars", ".", "get", "(", "var_name", ")", ")", ";", "}", "}", "public", "boolean", "match", "(", "ERef", "ref", ",", "EMatchContext", "r", ")", "{", "if", "(", "free", ")", "{", "r", ".", "vars", ".", "put", "(", "var_name", ",", "ref", ")", ";", "return", "true", ";", "}", "else", "{", "return", "ref", ".", "equalsExactly", "(", "r", ".", "vars", ".", "get", "(", "var_name", ")", ")", ";", "}", "}", "public", "boolean", "match", "(", "EFun", "fu", ",", "EMatchContext", "r", ")", "{", "if", "(", "free", ")", "{", "r", ".", "vars", ".", "put", "(", "var_name", ",", "fu", ")", ";", "return", "true", ";", "}", "else", "{", "return", "fu", ".", "equalsExactly", "(", "r", ".", "vars", ".", "get", "(", "var_name", ")", ")", ";", "}", "}", "public", "boolean", "match", "(", "ECons", "t", ",", "EMatchContext", "r", ")", "{", "if", "(", "free", ")", "{", "r", ".", "vars", ".", "put", "(", "var_name", ",", "t", ")", ";", "return", "true", ";", "}", "else", "{", "return", "t", ".", "equalsExactly", "(", "r", ".", "vars", ".", "get", "(", "var_name", ")", ")", ";", "}", "}", "public", "boolean", "match", "(", "EPID", "t", ",", "EMatchContext", "r", ")", "{", "if", "(", "free", ")", "{", "r", ".", "vars", ".", "put", "(", "var_name", ",", "t", ")", ";", "return", "true", ";", "}", "else", "{", "return", "t", ".", "equalsExactly", "(", "r", ".", "vars", ".", "get", "(", "var_name", ")", ")", ";", "}", "}", "public", "boolean", "match", "(", "EPort", "t", ",", "EMatchContext", "r", ")", "{", "if", "(", "free", ")", "{", "r", ".", "vars", ".", "put", "(", "var_name", ",", "t", ")", ";", "return", "true", ";", "}", "else", "{", "return", "t", ".", "equalsExactly", "(", "r", ".", "vars", ".", "get", "(", "var_name", ")", ")", ";", "}", "}", "public", "boolean", "match", "(", "EBitString", "t", ",", "EMatchContext", "r", ")", "{", "if", "(", "free", ")", "{", "r", ".", "vars", ".", "put", "(", "var_name", ",", "t", ")", ";", "return", "true", ";", "}", "else", "{", "return", "t", ".", "equalsExactly", "(", "r", ".", "vars", ".", "get", "(", "var_name", ")", ")", ";", "}", "}", "}", "private", "EMatchSpec", "(", "MatchFunction", "[", "]", "funs", ",", "ESeq", "spec", ")", "{", "this", ".", "funs", "=", "funs", ";", "this", ".", "spec", "=", "spec", ";", "}", "@", "Override", "public", "String", "toString", "(", ")", "{", "return", "spec", ".", "toString", "(", ")", ";", "}", "public", "static", "EMatchSpec", "compile", "(", "ESeq", "spec", ")", "{", "ESeq", "full_spec", "=", "spec", ";", "List", "<", "MatchFunction", ">", "funs", "=", "new", "ArrayList", "<", "MatchFunction", ">", "(", ")", ";", "for", "(", ";", "!", "spec", ".", "isNil", "(", ")", ";", "spec", "=", "spec", ".", "tail", "(", ")", ")", "{", "funs", ".", "add", "(", "parse_MatchFunction", "(", "spec", ".", "head", "(", ")", ")", ")", ";", "}", "return", "new", "EMatchSpec", "(", "funs", ".", "toArray", "(", "new", "MatchFunction", "[", "funs", ".", "size", "(", ")", "]", ")", ",", "full_spec", ")", ";", "}", "static", "EObject", "KEY_ABSENT", "=", "new", "EKeyAbsent", "(", ")", ";", "public", "EObject", "getTupleKey", "(", "int", "keypos1", ")", "{", "if", "(", "this", ".", "funs", ".", "length", "==", "1", ")", "{", "if", "(", "funs", "[", "0", "]", ".", "head", "instanceof", "TuplePattern", ")", "{", "TuplePattern", "tp", "=", "(", "TuplePattern", ")", "funs", "[", "0", "]", ".", "head", ";", "if", "(", "tp", ".", "elems", ".", "length", "<", "keypos1", ")", "return", "KEY_ABSENT", ";", "if", "(", "tp", ".", "elems", "[", "keypos1", "-", "1", "]", "instanceof", "EqualsPattern", ")", "{", "EqualsPattern", "ep", "=", "(", "EqualsPattern", ")", "tp", ".", "elems", "[", "keypos1", "-", "1", "]", ";", "return", "ep", ".", "value", ";", "}", "}", "else", "if", "(", "funs", "[", "0", "]", ".", "head", "instanceof", "EqualsPattern", ")", "{", "EqualsPattern", "ep", "=", "(", "EqualsPattern", ")", "funs", "[", "0", "]", ".", "head", ";", "ETuple", "tup", ";", "if", "(", "(", "tup", "=", "ep", ".", "value", ".", "testTuple", "(", ")", ")", "!=", "null", "&&", "tup", ".", "arity", "(", ")", ">=", "keypos1", ")", "{", "return", "tup", ".", "elm", "(", "keypos1", ")", ";", "}", "}", "}", "return", "null", ";", "}", "public", "ESeq", "matching_keys", "(", "ESeq", "values", ",", "Map", "<", "EObject", ",", "ETuple", ">", "map", ")", "{", "for", "(", "Map", ".", "Entry", "<", "EObject", ",", "ETuple", ">", "ent", ":", "map", ".", "entrySet", "(", ")", ")", "{", "ETuple", "val", "=", "ent", ".", "getValue", "(", ")", ";", "if", "(", "matches", "(", "val", ")", ")", "{", "values", "=", "values", ".", "cons", "(", "ent", ".", "getKey", "(", ")", ")", ";", "}", "}", "return", "values", ";", "}", "public", "boolean", "matches", "(", "EObject", "candidate", ")", "{", "return", "match", "(", "candidate", ")", "==", "ERT", ".", "TRUE", ";", "}", "public", "EObject", "match", "(", "EObject", "candidate", ")", "{", "for", "(", "int", "i", "=", "0", ";", "i", "<", "funs", ".", "length", ";", "i", "++", ")", "{", "EObject", "val", "=", "funs", "[", "i", "]", ".", "match", "(", "candidate", ")", ";", "if", "(", "val", "!=", "null", ")", "{", "return", "val", ";", "}", "}", "return", "null", ";", "}", "public", "ESeq", "matching_values_bag", "(", "ESeq", "vals", ",", "Map", "<", "EObject", ",", "IPersistentCollection", ">", "map", ")", "{", "for", "(", "Map", ".", "Entry", "<", "EObject", ",", "IPersistentCollection", ">", "ent", ":", "map", ".", "entrySet", "(", ")", ")", "{", "IPersistentCollection", "values", "=", "ent", ".", "getValue", "(", ")", ";", "for", "(", "ISeq", "seq", "=", "values", ".", "seq", "(", ")", ";", "seq", "!=", "null", ";", "seq", "=", "seq", ".", "next", "(", ")", ")", "{", "ETuple", "val", "=", "(", "ETuple", ")", "seq", ".", "first", "(", ")", ";", "if", "(", "matches", "(", "val", ")", ")", "{", "vals", "=", "vals", ".", "cons", "(", "val", ")", ";", "}", "}", "}", "return", "vals", ";", "}", "public", "ESeq", "matching_values_coll", "(", "ESeq", "vals", ",", "ISeq", "seq", ")", "{", "for", "(", ";", "seq", "!=", "null", "&&", "!", "seq", ".", "equals", "(", "seq", ".", "empty", "(", ")", ")", ";", "seq", "=", "seq", ".", "next", "(", ")", ")", "{", "EObject", "val", "=", "(", "EObject", ")", "seq", ".", "first", "(", ")", ";", "if", "(", "matches", "(", "val", ")", ")", "{", "vals", "=", "vals", ".", "cons", "(", "val", ")", ";", "}", "}", "return", "vals", ";", "}", "@", "Override", "public", "int", "hashCode", "(", ")", "{", "return", "spec", ".", "hashCode", "(", ")", ";", "}", "}", "class", "EKeyAbsent", "extends", "EPseudoTerm", "{", "int", "compare_same", "(", "EObject", "rhs", ")", "{", "if", "(", "rhs", "==", "EMatchSpec", ".", "KEY_ABSENT", ")", "return", "0", ";", "return", "-", "1", ";", "}", "@", "Override", "public", "int", "hashCode", "(", ")", "{", "return", "1", ";", "}", "}", "</s>" ]
7,794
[ "<s>", "package", "erjang", ".", "m", ".", "ets", ";", "import", "java", ".", "util", ".", "Map", ";", "import", "java", ".", "util", ".", "concurrent", ".", "atomic", ".", "AtomicInteger", ";", "import", "com", ".", "trifork", ".", "clj_ds", ".", "IMapEntry", ";", "import", "com", ".", "trifork", ".", "clj_ds", ".", "IPersistentCollection", ";", "import", "com", ".", "trifork", ".", "clj_ds", ".", "IPersistentMap", ";", "import", "com", ".", "trifork", ".", "clj_ds", ".", "IPersistentSet", ";", "import", "com", ".", "trifork", ".", "clj_ds", ".", "ISeq", ";", "import", "com", ".", "trifork", ".", "clj_ds", ".", "PersistentHashSet", ";", "import", "com", ".", "trifork", ".", "clj_ds", ".", "PersistentHashMap", ";", "import", "com", ".", "trifork", ".", "clj_ds", ".", "Seqable", ";", "import", "erjang", ".", "EAtom", ";", "import", "erjang", ".", "ECons", ";", "import", "erjang", ".", "EInteger", ";", "import", "erjang", ".", "EInternalPID", ";", "import", "erjang", ".", "EList", ";", "import", "erjang", ".", "EObject", ";", "import", "erjang", ".", "EProc", ";", "import", "erjang", ".", "EPseudoTerm", ";", "import", "erjang", ".", "ERT", ";", "import", "erjang", ".", "ESeq", ";", "import", "erjang", ".", "ETuple", ";", "import", "erjang", ".", "ETuple2", ";", "import", "erjang", ".", "NotImplemented", ";", "public", "class", "ETableBag", "extends", "ETable", "{", "AtomicInteger", "sizeRef", ";", "ETableBag", "(", "EProc", "owner", ",", "EAtom", "type", ",", "EInteger", "tid", ",", "EAtom", "aname", ",", "EAtom", "access", ",", "int", "keypos", ",", "boolean", "writeConcurrency", ",", "boolean", "isNamed", ",", "EInternalPID", "heirPid", ",", "EObject", "heirData", ")", "{", "super", "(", "owner", ",", "type", ",", "tid", ",", "aname", ",", "access", ",", "keypos", ",", "isNamed", ",", "heirPid", ",", "heirData", ",", "PersistentHashMap", ".", "EMPTY", ")", ";", "try", "{", "sizeRef", "=", "new", "AtomicInteger", "(", "0", ")", ";", "}", "catch", "(", "Exception", "e", ")", "{", "throw", "new", "Error", "(", "e", ")", ";", "}", "}", "IPersistentCollection", "empty", "(", ")", "{", "return", "type", "==", "Native", ".", "am_bag", "?", "PersistentHashSet", ".", "EMPTY", ":", "PersistentBag", ".", "EMPTY", ";", "}", "@", "Override", "protected", "void", "insert_many", "(", "final", "ESeq", "values", ")", "{", "in_tx", "(", "new", "WithMap", "<", "Object", ">", "(", ")", "{", "@", "Override", "protected", "Object", "run", "(", "IPersistentMap", "map", ")", "{", "int", "count", "=", "0", ";", "for", "(", "ESeq", "seq", "=", "values", ";", "!", "seq", ".", "isNil", "(", ")", ";", "seq", "=", "seq", ".", "tail", "(", ")", ")", "{", "ETuple", "value", "=", "seq", ".", "head", "(", ")", ".", "testTuple", "(", ")", ";", "if", "(", "value", "==", "null", ")", "throw", "ERT", ".", "badarg", "(", "values", ")", ";", "EObject", "key", "=", "get_key", "(", "value", ")", ";", "IPersistentCollection", "c", "=", "(", "IPersistentCollection", ")", "map", ".", "valAt", "(", "key", ",", "empty", "(", ")", ")", ";", "int", "sizeBefore", "=", "c", ".", "count", "(", ")", ";", "c", "=", "c", ".", "cons", "(", "value", ")", ";", "int", "sizeAfter", "=", "c", ".", "count", "(", ")", ";", "map", "=", "map", ".", "assoc", "(", "key", ",", "c", ")", ";", "if", "(", "sizeAfter", ">", "sizeBefore", ")", "count", "+=", "1", ";", "}", "sizeRef", ".", "set", "(", "count", "+", "(", "Integer", ")", "sizeRef", ".", "get", "(", ")", ")", ";", "set", "(", "map", ")", ";", "return", "null", ";", "}", "}", ")", ";", "}", "@", "Override", "protected", "boolean", "insert_new_many", "(", "ESeq", "values", ")", "{", "throw", "new", "NotImplemented", "(", ")", ";", "}", "@", "Override", "protected", "boolean", "insert_new_one", "(", "ETuple", "value", ")", "{", "throw", "new", "NotImplemented", "(", ")", ";", "}", "@", "Override", "protected", "void", "insert_one", "(", "final", "ETuple", "value", ")", "{", "in_tx", "(", "new", "WithMap", "<", "Object", ">", "(", ")", "{", "@", "Override", "protected", "Object", "run", "(", "IPersistentMap", "map", ")", "{", "IPersistentCollection", "empty", "=", "empty", "(", ")", ";", "EObject", "key", "=", "get_key", "(", "value", ")", ";", "IPersistentCollection", "c", "=", "(", "IPersistentCollection", ")", "map", ".", "valAt", "(", "key", ",", "empty", ")", ";", "int", "sizeBefore", "=", "c", ".", "count", "(", ")", ";", "c", "=", "c", ".", "cons", "(", "value", ")", ";", "int", "sizeAfter", "=", "c", ".", "count", "(", ")", ";", "map", "=", "map", ".", "assoc", "(", "key", ",", "c", ")", ";", "set", "(", "map", ")", ";", "Integer", "cnt0", "=", "(", "Integer", ")", "sizeRef", ".", "get", "(", ")", ";", "if", "(", "sizeAfter", ">", "sizeBefore", ")", "sizeRef", ".", "set", "(", "1", "+", "(", "Integer", ")", "sizeRef", ".", "get", "(", ")", ")", ";", "return", "null", ";", "}", "}", ")", ";", "}", "@", "Override", "protected", "ESeq", "lookup", "(", "EObject", "key", ")", "{", "IPersistentMap", "ipm", "=", "deref", "(", ")", ";", "IPersistentCollection", "set", "=", "(", "IPersistentCollection", ")", "ipm", ".", "valAt", "(", "key", ")", ";", "ESeq", "res", "=", "ERT", ".", "NIL", ";", "if", "(", "set", "==", "null", ")", "return", "res", ";", "for", "(", "ISeq", "s", "=", "set", ".", "seq", "(", ")", ";", "s", "!=", "null", ";", "s", "=", "s", ".", "next", "(", ")", ")", "{", "res", "=", "res", ".", "cons", "(", "(", "EObject", ")", "s", ".", "first", "(", ")", ")", ";", "}", "return", "res", ".", "reverse", "(", ")", ";", "}", "@", "Override", "protected", "EAtom", "member", "(", "EObject", "key", ")", "{", "IPersistentMap", "ipm", "=", "deref", "(", ")", ";", "IPersistentCollection", "set", "=", "(", "IPersistentCollection", ")", "ipm", ".", "valAt", "(", "key", ")", ";", "if", "(", "set", "!=", "null", "&&", "set", ".", "count", "(", ")", "!=", "0", ")", "{", "return", "ERT", ".", "TRUE", ";", "}", "else", "{", "return", "ERT", ".", "FALSE", ";", "}", "}", "@", "Override", "protected", "EObject", "first", "(", ")", "{", "IPersistentMap", "map", "=", "deref", "(", ")", ";", "if", "(", "map", ".", "count", "(", ")", "==", "0", ")", "{", "return", "Native", ".", "am_$end_of_table", ";", "}", "else", "{", "ISeq", "entseq", "=", "map", ".", "seq", "(", ")", ";", "IMapEntry", "ent", "=", "(", "IMapEntry", ")", "entseq", ".", "first", "(", ")", ";", "return", "(", "EObject", ")", "ent", ".", "getKey", "(", ")", ";", "}", "}", "@", "Override", "int", "size", "(", ")", "{", "return", "sizeRef", ".", "get", "(", ")", ";", "}", "@", "Override", "public", "ESeq", "match", "(", "EPattern", "matcher", ")", "{", "EObject", "key", "=", "matcher", ".", "getKey", "(", "keypos1", ")", ";", "if", "(", "key", "==", "null", ")", "{", "ESeq", "res", "=", "ERT", ".", "NIL", ";", "IPersistentMap", "map", "=", "deref", "(", ")", ";", "for", "(", "ISeq", "entseq", "=", "map", ".", "seq", "(", ")", ";", "entseq", "!=", "null", ";", "entseq", "=", "entseq", ".", "next", "(", ")", ")", "{", "IMapEntry", "ent", "=", "(", "IMapEntry", ")", "entseq", ".", "first", "(", ")", ";", "if", "(", "ent", "==", "null", ")", "continue", ";", "Seqable", "coll", "=", "(", "Seqable", ")", "ent", ".", "getValue", "(", ")", ";", "res", "=", "matcher", ".", "match_vars", "(", "res", ",", "coll", ".", "seq", "(", ")", ")", ";", "}", "return", "res", ".", "reverse", "(", ")", ";", "}", "IPersistentMap", "map", "=", "deref", "(", ")", ";", "IPersistentCollection", "coll", "=", "(", "IPersistentCollection", ")", "map", ".", "valAt", "(", "key", ")", ";", "if", "(", "coll", "==", "null", ")", "return", "ERT", ".", "NIL", ";", "return", "matcher", ".", "match_vars", "(", "ERT", ".", "NIL", ",", "coll", ".", "seq", "(", ")", ")", ".", "reverse", "(", ")", ";", "}", "@", "Override", "public", "ESeq", "match_object", "(", "final", "EPattern", "matcher", ")", "{", "EObject", "key", "=", "matcher", ".", "getKey", "(", "keypos1", ")", ";", "if", "(", "key", "==", "null", ")", "{", "ESeq", "res", "=", "ERT", ".", "NIL", ";", "IPersistentMap", "map", "=", "deref", "(", ")", ";", "for", "(", "ISeq", "entseq", "=", "map", ".", "seq", "(", ")", ";", "entseq", "!=", "null", ";", "entseq", "=", "entseq", ".", "next", "(", ")", ")", "{", "IMapEntry", "ent", "=", "(", "IMapEntry", ")", "entseq", ".", "first", "(", ")", ";", "if", "(", "ent", "==", "null", ")", "break", ";", "Seqable", "coll", "=", "(", "Seqable", ")", "ent", ".", "getValue", "(", ")", ";", "res", "=", "matcher", ".", "match_members", "(", "res", ",", "coll", ".", "seq", "(", ")", ")", ";", "}", "return", "res", ".", "reverse", "(", ")", ";", "}", "IPersistentMap", "map", "=", "deref", "(", ")", ";", "IPersistentCollection", "coll", "=", "(", "IPersistentCollection", ")", "map", ".", "valAt", "(", "key", ")", ";", "if", "(", "coll", "==", "null", ")", "return", "ERT", ".", "NIL", ";", "return", "matcher", ".", "match_members", "(", "ERT", ".", "NIL", ",", "coll", ".", "seq", "(", ")", ")", ".", "reverse", "(", ")", ";", "}", "@", "Override", "protected", "void", "delete", "(", "final", "EObject", "key", ")", "{", "in_tx", "(", "new", "WithMap", "<", "Object", ">", "(", ")", "{", "@", "Override", "protected", "Object", "run", "(", "IPersistentMap", "map", ")", "{", "IPersistentCollection", "empty", "=", "empty", "(", ")", ";", "IPersistentCollection", "c", "=", "(", "IPersistentCollection", ")", "map", ".", "valAt", "(", "key", ",", "empty", ")", ";", "try", "{", "map", "=", "map", ".", "without", "(", "key", ")", ";", "}", "catch", "(", "Exception", "e", ")", "{", "throw", "new", "Error", "(", "e", ")", ";", "}", "set", "(", "map", ")", ";", "sizeRef", ".", "addAndGet", "(", "-", "c", ".", "count", "(", ")", ")", ";", "return", "null", ";", "}", "}", ")", ";", "}", "@", "Override", "protected", "void", "delete_object", "(", "final", "ETuple", "obj", ")", "{", "in_tx", "(", "new", "WithMap", "<", "Object", ">", "(", ")", "{", "@", "Override", "protected", "Object", "run", "(", "IPersistentMap", "map", ")", "{", "EObject", "key", "=", "get_key", "(", "obj", ")", ";", "IPersistentCollection", "empty", "=", "empty", "(", ")", ";", "IPersistentCollection", "c", "=", "(", "IPersistentCollection", ")", "map", ".", "valAt", "(", "key", ",", "empty", ")", ";", "if", "(", "c", "==", "null", "||", "c", ".", "count", "(", ")", "==", "0", ")", "return", "null", ";", "IPersistentCollection", "out", "=", "empty", "(", ")", ";", "int", "deleted", "=", "0", ";", "for", "(", "ISeq", "s", "=", "c", ".", "seq", "(", ")", ";", "s", "!=", "null", ";", "s", "=", "s", ".", "next", "(", ")", ")", "{", "EObject", "val", "=", "(", "EObject", ")", "s", ".", "first", "(", ")", ";", "if", "(", "val", "==", "null", ")", "break", ";", "if", "(", "!", "obj", ".", "equalsExactly", "(", "val", ")", ")", "{", "out", "=", "out", ".", "cons", "(", "val", ")", ";", "}", "else", "{", "deleted", "+=", "1", ";", "}", "}", "if", "(", "out", ".", "count", "(", ")", "==", "0", ")", "{", "try", "{", "map", "=", "map", ".", "without", "(", "key", ")", ";", "}", "catch", "(", "Exception", "e", ")", "{", "throw", "new", "Error", "(", "e", ")", ";", "}", "}", "else", "{", "map", "=", "map", ".", "assoc", "(", "key", ",", "out", ")", ";", "}", "set", "(", "map", ")", ";", "sizeRef", ".", "addAndGet", "(", "-", "deleted", ")", ";", "return", "null", ";", "}", "}", ")", ";", "}", "@", "Override", "public", "EObject", "select", "(", "final", "EMatchSpec", "matcher", ",", "int", "limit", ")", "{", "IPersistentMap", "map", "=", "deref", "(", ")", ";", "EObject", "key", "=", "matcher", ".", "getTupleKey", "(", "keypos1", ")", ";", "if", "(", "key", "==", "null", ")", "{", "EBagCont", "cont0", "=", "new", "EBagCont", "(", "matcher", ",", "map", ".", "seq", "(", ")", ",", "null", ",", "limit", ")", ";", "return", "cont0", ".", "select", "(", ")", ";", "}", "else", "{", "IPersistentCollection", "coll", "=", "(", "IPersistentCollection", ")", "map", ".", "valAt", "(", "key", ")", ";", "if", "(", "coll", "==", "null", ")", "{", "return", "Native", ".", "am_$end_of_table", ";", "}", "else", "{", "EBagCont", "cont0", "=", "new", "EBagCont", "(", "matcher", ",", "null", ",", "coll", ".", "seq", "(", ")", ",", "limit", ")", ";", "return", "cont0", ".", "select", "(", ")", ";", "}", "}", "}", "static", "class", "EBagCont", "extends", "EPseudoTerm", "implements", "ISelectContinuation", "{", "private", "final", "EMatchSpec", "matcher", ";", "private", "final", "ISeq", "map_ent", ";", "private", "final", "ISeq", "coll_ent", ";", "private", "final", "int", "limit", ";", "public", "EBagCont", "(", "EMatchSpec", "matcher", ",", "ISeq", "mapent", ",", "ISeq", "conent", ",", "int", "limit", ")", "{", "this", ".", "matcher", "=", "matcher", ";", "this", ".", "map_ent", "=", "mapent", ";", "this", ".", "coll_ent", "=", "conent", ";", "this", ".", "limit", "=", "limit", ";", "}", "public", "EObject", "select", "(", ")", "{", "int", "count", "=", "0", ";", "ESeq", "vals", "=", "ERT", ".", "NIL", ";", "ISeq", "map_seq", "=", "map_ent", ";", "ISeq", "coll_seq", "=", "coll_ent", ";", "while", "(", "(", "seq_has_more", "(", "map_seq", ")", "||", "seq_has_more", "(", "coll_seq", ")", ")", "&&", "(", "limit", "<", "0", "||", "count", "<", "limit", ")", ")", "{", "if", "(", "!", "seq_has_more", "(", "coll_seq", ")", ")", "{", "IMapEntry", "ent", "=", "(", "IMapEntry", ")", "map_seq", ".", "first", "(", ")", ";", "IPersistentCollection", "coll", "=", "(", "IPersistentCollection", ")", "ent", ".", "getValue", "(", ")", ";", "coll_seq", "=", "coll", ".", "seq", "(", ")", ";", "map_seq", "=", "map_seq", ".", "next", "(", ")", ";", "}", "assert", "seq_has_more", "(", "coll_seq", ")", ";", "ETuple", "candidate", "=", "(", "ETuple", ")", "coll_seq", ".", "first", "(", ")", ";", "coll_seq", "=", "coll_seq", ".", "next", "(", ")", ";", "EObject", "res", ";", "if", "(", "(", "res", "=", "matcher", ".", "match", "(", "candidate", ")", ")", "!=", "null", ")", "{", "count", "+=", "1", ";", "vals", "=", "vals", ".", "cons", "(", "res", ")", ";", "}", "}", "if", "(", "vals", "==", "ERT", ".", "NIL", ")", "{", "return", "Native", ".", "am_$end_of_table", ";", "}", "else", "if", "(", "!", "seq_has_more", "(", "map_seq", ")", "&&", "!", "seq_has_more", "(", "coll_seq", ")", ")", "{", "return", "new", "ETuple2", "(", "vals", ",", "Native", ".", "am_$end_of_table", ")", ";", "}", "else", "{", "return", "new", "ETuple2", "(", "vals", ",", "new", "EBagCont", "(", "matcher", ",", "map_seq", ",", "coll_seq", ",", "limit", ")", ")", ";", "}", "}", "private", "boolean", "seq_has_more", "(", "ISeq", "ent", ")", "{", "return", "ent", "!=", "null", "&&", "ent", "!=", "ent", ".", "empty", "(", ")", ";", "}", "@", "Override", "public", "int", "hashCode", "(", ")", "{", "return", "System", ".", "identityHashCode", "(", "this", ")", ";", "}", "}", "@", "Override", "protected", "EInteger", "select_delete", "(", "final", "EMatchSpec", "matcher", ")", "{", "int", "delete_count", "=", "in_tx", "(", "new", "WithMap", "<", "Integer", ">", "(", ")", "{", "@", "Override", "protected", "Integer", "run", "(", "IPersistentMap", "map", ")", "{", "ESeq", "vals", "=", "ERT", ".", "NIL", ";", "int", "initial_count", "=", "sizeRef", ".", "get", "(", ")", ";", "EObject", "key", "=", "matcher", ".", "getTupleKey", "(", "keypos1", ")", ";", "if", "(", "key", "==", "null", ")", "{", "vals", "=", "matcher", ".", "matching_values_bag", "(", "vals", ",", "(", "Map", "<", "EObject", ",", "IPersistentCollection", ">", ")", "map", ")", ";", "}", "else", "{", "IPersistentCollection", "coll", "=", "(", "IPersistentCollection", ")", "map", ".", "valAt", "(", "key", ")", ";", "if", "(", "coll", "!=", "null", ")", "{", "vals", "=", "matcher", ".", "matching_values_coll", "(", "vals", ",", "coll", ".", "seq", "(", ")", ")", ";", "}", "}", "int", "count", "=", "0", ";", "for", "(", ";", "!", "vals", ".", "isNil", "(", ")", ";", "vals", "=", "vals", ".", "tail", "(", ")", ")", "{", "try", "{", "ETuple", "val", "=", "(", "ETuple", ")", "vals", ".", "head", "(", ")", ";", "key", "=", "val", ".", "elm", "(", "keypos1", ")", ";", "IPersistentCollection", "coll", "=", "(", "IPersistentCollection", ")", "map", ".", "valAt", "(", "key", ")", ";", "if", "(", "coll", "instanceof", "IPersistentSet", ")", "{", "IPersistentSet", "set", "=", "(", "IPersistentSet", ")", "coll", ";", "set", "=", "set", ".", "disjoin", "(", "val", ")", ";", "if", "(", "set", "!=", "coll", ")", "{", "count", "+=", "1", ";", "if", "(", "set", ".", "count", "(", ")", "==", "0", ")", "{", "map", "=", "map", ".", "without", "(", "key", ")", ";", "}", "else", "{", "map", "=", "map", ".", "assoc", "(", "key", ",", "set", ")", ";", "}", "}", "}", "else", "if", "(", "coll", "instanceof", "IPersistentBag", ")", "{", "IPersistentBag", "bag", "=", "(", "IPersistentBag", ")", "coll", ";", "bag", "=", "bag", ".", "disjoin", "(", "val", ")", ";", "if", "(", "bag", "!=", "coll", ")", "{", "count", "+=", "1", ";", "if", "(", "bag", ".", "count", "(", ")", "==", "0", ")", "{", "map", "=", "map", ".", "without", "(", "key", ")", ";", "}", "else", "{", "map", "=", "map", ".", "assoc", "(", "key", ",", "bag", ")", ";", "}", "}", "}", "}", "catch", "(", "Exception", "e", ")", "{", "throw", "new", "Error", "(", "e", ")", ";", "}", "}", "set", "(", "map", ")", ";", "sizeRef", ".", "set", "(", "initial_count", "-", "count", ")", ";", "return", "count", ";", "}", "}", ")", ";", "return", "ERT", ".", "box", "(", "delete_count", ")", ";", "}", "protected", "void", "delete_all_objects", "(", ")", "{", "in_tx", "(", "new", "WithMap", "<", "Object", ">", "(", ")", "{", "@", "Override", "protected", "Object", "run", "(", "IPersistentMap", "map", ")", "{", "set", "(", "empty", ")", ";", "sizeRef", ".", "set", "(", "0", ")", ";", "return", "null", ";", "}", "}", ")", ";", "}", "@", "Override", "public", "ESeq", "slot", "(", ")", "{", "IPersistentMap", "map", "=", "deref", "(", ")", ";", "if", "(", "map", ".", "count", "(", ")", "==", "0", ")", "return", "ERT", ".", "NIL", ";", "return", "new", "ELSeq", "(", "map", ".", "seq", "(", ")", ")", ";", "}", "static", "class", "ELSeq", "extends", "ESeq", "{", "private", "final", "ISeq", "coll", ";", "private", "final", "ISeq", "map_seq", ";", "ELSeq", "(", "ISeq", "map", ")", "{", "IMapEntry", "collent", "=", "(", "IMapEntry", ")", "map", ".", "first", "(", ")", ";", "IPersistentCollection", "c", "=", "(", "IPersistentCollection", ")", "collent", ".", "getValue", "(", ")", ";", "while", "(", "c", ".", "count", "(", ")", "==", "0", ")", "{", "map", "=", "map", ".", "next", "(", ")", ";", "collent", "=", "(", "IMapEntry", ")", "map", ".", "first", "(", ")", ";", "c", "=", "(", "IPersistentCollection", ")", "collent", ".", "getValue", "(", ")", ";", "}", "coll", "=", "c", ".", "seq", "(", ")", ";", "map_seq", "=", "map", ".", "next", "(", ")", ";", "}", "ELSeq", "(", "ISeq", "coll", ",", "ISeq", "map_seq", ")", "{", "this", ".", "coll", "=", "coll", ";", "this", ".", "map_seq", "=", "map_seq", ";", "}", "@", "Override", "public", "ESeq", "cons", "(", "EObject", "h", ")", "{", "return", "new", "EList", "(", "h", ",", "this", ")", ";", "}", "@", "Override", "public", "ESeq", "tail", "(", ")", "{", "ISeq", "c2", "=", "coll", ".", "next", "(", ")", ";", "if", "(", "c2", "==", "null", ")", "{", "if", "(", "map_seq", "==", "null", "||", "map_seq", "==", "map_seq", ".", "empty", "(", ")", ")", "return", "ERT", ".", "NIL", ";", "return", "new", "ELSeq", "(", "map_seq", ")", ";", "}", "else", "{", "return", "new", "ELSeq", "(", "c2", ",", "map_seq", ")", ";", "}", "}", "@", "Override", "public", "EObject", "head", "(", ")", "{", "return", "(", "EObject", ")", "coll", ".", "first", "(", ")", ";", "}", "@", "Override", "public", "boolean", "isNil", "(", ")", "{", "return", "false", ";", "}", "@", "Override", "public", "ECons", "testNonEmptyList", "(", ")", "{", "return", "this", ";", "}", "}", "}", "</s>" ]
7,795
[ "<s>", "package", "erjang", ".", "m", ".", "ets", ";", "import", "java", ".", "util", ".", "Map", ";", "import", "java", ".", "util", ".", "concurrent", ".", "ConcurrentHashMap", ";", "import", "java", ".", "util", ".", "concurrent", ".", "atomic", ".", "AtomicLong", ";", "import", "java", ".", "util", ".", "logging", ".", "Level", ";", "import", "java", ".", "util", ".", "logging", ".", "Logger", ";", "import", "erjang", ".", "BIF", ";", "import", "erjang", ".", "EAtom", ";", "import", "erjang", ".", "EInteger", ";", "import", "erjang", ".", "EInternalPID", ";", "import", "erjang", ".", "ENative", ";", "import", "erjang", ".", "EObject", ";", "import", "erjang", ".", "EProc", ";", "import", "erjang", ".", "ERT", ";", "import", "erjang", ".", "ESeq", ";", "import", "erjang", ".", "ESmall", ";", "import", "erjang", ".", "ETuple", ";", "import", "erjang", ".", "ETuple2", ";", "import", "erjang", ".", "ETuple3", ";", "import", "erjang", ".", "ErlangError", ";", "import", "erjang", ".", "ErlangException", ";", "import", "erjang", ".", "NotImplemented", ";", "public", "class", "Native", "extends", "ENative", "{", "static", "Logger", "log", "=", "Logger", ".", "getLogger", "(", "\"\"", ")", ";", "public", "static", "final", "EAtom", "am_$end_of_table", "=", "EAtom", ".", "intern", "(", "\"\"", ")", ";", "public", "static", "final", "EAtom", "am_set", "=", "EAtom", ".", "intern", "(", "\"set\"", ")", ";", "public", "static", "final", "EAtom", "am_ordered_set", "=", "EAtom", ".", "intern", "(", "\"ordered_set\"", ")", ";", "public", "static", "final", "EAtom", "am_bag", "=", "EAtom", ".", "intern", "(", "\"bag\"", ")", ";", "public", "static", "final", "EAtom", "am_duplicate_bag", "=", "EAtom", ".", "intern", "(", "\"\"", ")", ";", "public", "static", "final", "EAtom", "am_public", "=", "EAtom", ".", "intern", "(", "\"public\"", ")", ";", "public", "static", "final", "EAtom", "am_private", "=", "EAtom", ".", "intern", "(", "\"private\"", ")", ";", "public", "static", "final", "EAtom", "am_protected", "=", "EAtom", ".", "intern", "(", "\"protected\"", ")", ";", "public", "static", "final", "EAtom", "am_owner", "=", "EAtom", ".", "intern", "(", "\"owner\"", ")", ";", "public", "static", "final", "EAtom", "am_heir", "=", "EAtom", ".", "intern", "(", "\"heir\"", ")", ";", "public", "static", "final", "EAtom", "am_keypos", "=", "EAtom", ".", "intern", "(", "\"keypos\"", ")", ";", "public", "static", "final", "EAtom", "am_name", "=", "EAtom", ".", "intern", "(", "\"name\"", ")", ";", "public", "static", "final", "EAtom", "am_size", "=", "EAtom", ".", "intern", "(", "\"size\"", ")", ";", "public", "static", "final", "EAtom", "am_memory", "=", "EAtom", ".", "intern", "(", "\"memory\"", ")", ";", "public", "static", "final", "EAtom", "am_node", "=", "EAtom", ".", "intern", "(", "\"node\"", ")", ";", "public", "static", "final", "EAtom", "am_named_table", "=", "EAtom", ".", "intern", "(", "\"named_table\"", ")", ";", "public", "static", "final", "EAtom", "am_write_concurrency", "=", "EAtom", ".", "intern", "(", "\"\"", ")", ";", "public", "static", "final", "EAtom", "am_type", "=", "EAtom", ".", "intern", "(", "\"type\"", ")", ";", "public", "static", "final", "EAtom", "am_none", "=", "EAtom", ".", "intern", "(", "\"none\"", ")", ";", "public", "static", "final", "EAtom", "am_protection", "=", "EAtom", ".", "intern", "(", "\"protection\"", ")", ";", "public", "static", "final", "EAtom", "am_fixed", "=", "EAtom", ".", "intern", "(", "\"fixed\"", ")", ";", "public", "static", "final", "EAtom", "am_safe_fixed", "=", "EAtom", ".", "intern", "(", "\"safe_fixed\"", ")", ";", "public", "static", "final", "EAtom", "am_stats", "=", "EAtom", ".", "intern", "(", "\"stats\"", ")", ";", "static", "AtomicLong", "next_tid", "=", "new", "AtomicLong", "(", "1", ")", ";", "static", "ConcurrentHashMap", "<", "EAtom", ",", "EInteger", ">", "name_to_tid", "=", "new", "ConcurrentHashMap", "<", "EAtom", ",", "EInteger", ">", "(", ")", ";", "static", "Map", "<", "EInteger", ",", "ETable", ">", "tid_to_table", "=", "new", "ConcurrentHashMap", "<", "EInteger", ",", "ETable", ">", "(", ")", ";", "@", "BIF", "(", "name", "=", "\"new\"", ")", "public", "static", "EObject", "new$", "(", "EProc", "self", ",", "EObject", "name", ",", "EObject", "options", ")", "{", "EAtom", "aname", "=", "name", ".", "testAtom", "(", ")", ";", "ESeq", "opts", "=", "options", ".", "testSeq", "(", ")", ";", "if", "(", "aname", "==", "null", "||", "opts", "==", "null", ")", "{", "throw", "ERT", ".", "badarg", "(", "name", ",", "options", ")", ";", "}", "EAtom", "type", "=", "am_set", ";", "EAtom", "access", "=", "am_protected", ";", "int", "keypos", "=", "1", ";", "boolean", "write_concurrency", "=", "false", ";", "EInternalPID", "heir_pid", "=", "null", ";", "EObject", "heir_data", "=", "null", ";", "boolean", "is_named", "=", "false", ";", "for", "(", ";", "!", "opts", ".", "isNil", "(", ")", ";", "opts", "=", "opts", ".", "tail", "(", ")", ")", "{", "EObject", "option", "=", "opts", ".", "head", "(", ")", ";", "EAtom", "atom", ";", "ETuple2", "t2", ";", "ETuple3", "t3", ";", "if", "(", "(", "atom", "=", "option", ".", "testAtom", "(", ")", ")", "!=", "null", ")", "{", "if", "(", "atom", "==", "am_bag", "||", "atom", "==", "am_duplicate_bag", "||", "atom", "==", "am_set", "||", "atom", "==", "am_ordered_set", ")", "{", "type", "=", "atom", ";", "continue", ";", "}", "else", "if", "(", "atom", "==", "am_public", "||", "atom", "==", "am_private", "||", "atom", "==", "am_protected", ")", "{", "access", "=", "atom", ";", "continue", ";", "}", "else", "if", "(", "atom", "==", "am_named_table", ")", "{", "is_named", "=", "true", ";", "continue", ";", "}", "}", "else", "if", "(", "(", "t2", "=", "ETuple2", ".", "cast", "(", "option", ")", ")", "!=", "null", ")", "{", "ESmall", "pos", ";", "if", "(", "t2", ".", "elem1", "==", "am_heir", "&&", "t2", ".", "elem2", "==", "am_none", ")", "{", "heir_data", "=", "null", ";", "heir_pid", "=", "null", ";", "continue", ";", "}", "else", "if", "(", "t2", ".", "elem1", "==", "am_keypos", "&&", "(", "(", "pos", "=", "t2", ".", "elem2", ".", "testSmall", "(", ")", ")", "!=", "null", ")", "&&", "pos", ".", "value", ">=", "1", ")", "{", "keypos", "=", "pos", ".", "value", ";", "continue", ";", "}", "else", "if", "(", "t2", ".", "elem1", "==", "am_write_concurrency", ")", "{", "write_concurrency", "=", "(", "t2", ".", "elem2", "==", "ERT", ".", "TRUE", ")", ";", "continue", ";", "}", "}", "else", "if", "(", "(", "t3", "=", "ETuple3", ".", "cast", "(", "option", ")", ")", "!=", "null", ")", "{", "if", "(", "t3", ".", "elem1", "==", "am_heir", "&&", "(", "(", "heir_pid", "=", "t3", ".", "elem2", ".", "testInternalPID", "(", ")", ")", "!=", "null", ")", ")", "{", "if", "(", "!", "heir_pid", ".", "is_alive", "(", ")", ")", "{", "heir_pid", "=", "null", ";", "}", "else", "{", "heir_data", "=", "t3", ".", "elem3", ";", "}", "continue", ";", "}", "}", "throw", "ERT", ".", "badarg", "(", "name", ",", "options", ")", ";", "}", "EInteger", "tid", "=", "ERT", ".", "box", "(", "next_tid", ".", "incrementAndGet", "(", ")", ")", ";", "ETable", "table", "=", "ETable", ".", "allocate", "(", "self", ",", "tid", ",", "aname", ",", "type", ",", "access", ",", "keypos", ",", "write_concurrency", ",", "is_named", ",", "heir_pid", ",", "heir_data", ")", ";", "tid_to_table", ".", "put", "(", "tid", ",", "table", ")", ";", "if", "(", "is_named", ")", "{", "Object", "existing", "=", "name_to_tid", ".", "putIfAbsent", "(", "aname", ",", "tid", ")", ";", "if", "(", "existing", "!=", "null", ")", "throw", "ERT", ".", "badarg", "(", "name", ",", "options", ")", ";", "return", "aname", ";", "}", "else", "{", "return", "tid", ";", "}", "}", "private", "static", "ETable", "resolve", "(", "EProc", "caller", ",", "EObject", "nameOrTid", ",", "boolean", "write_access", ")", "{", "EInteger", "tid", "=", "null", ";", "EAtom", "name", ";", "if", "(", "(", "name", "=", "nameOrTid", ".", "testAtom", "(", ")", ")", "!=", "null", ")", "{", "tid", "=", "name_to_tid", ".", "get", "(", "name", ")", ";", "}", "else", "if", "(", "(", "tid", "=", "nameOrTid", ".", "testInteger", "(", ")", ")", "!=", "null", ")", "{", "}", "else", "{", "return", "null", ";", "}", "if", "(", "tid", "==", "null", ")", "{", "return", "null", ";", "}", "ETable", "table", "=", "tid_to_table", ".", "get", "(", "tid", ")", ";", "if", "(", "table", "!=", "null", "&&", "table", ".", "allow_access", "(", "caller", ",", "write_access", ")", ")", "{", "return", "table", ";", "}", "else", "{", "return", "null", ";", "}", "}", "@", "BIF", "public", "static", "EObject", "insert", "(", "EProc", "proc", ",", "EObject", "tab", ",", "EObject", "oneOrMore", ")", "{", "ETable", "table", "=", "resolve", "(", "proc", ",", "tab", ",", "true", ")", ";", "ETuple", "one", "=", "oneOrMore", ".", "testTuple", "(", ")", ";", "ESeq", "more", "=", "oneOrMore", ".", "testSeq", "(", ")", ";", "if", "(", "table", "==", "null", "||", "(", "one", "==", "null", "&&", "more", "==", "null", ")", ")", "{", "throw", "ERT", ".", "badarg", "(", "tab", ",", "oneOrMore", ")", ";", "}", "if", "(", "one", "!=", "null", ")", "{", "table", ".", "insert_one", "(", "one", ")", ";", "}", "else", "{", "table", ".", "insert_many", "(", "more", ")", ";", "}", "return", "ERT", ".", "TRUE", ";", "}", "@", "BIF", "public", "static", "EObject", "delete", "(", "EProc", "proc", ",", "EObject", "tab", ",", "EObject", "key", ")", "{", "ETable", "table", "=", "resolve", "(", "proc", ",", "tab", ",", "true", ")", ";", "if", "(", "table", "==", "null", ")", "{", "throw", "ERT", ".", "badarg", "(", "tab", ",", "key", ")", ";", "}", "table", ".", "delete", "(", "key", ")", ";", "return", "ERT", ".", "TRUE", ";", "}", "@", "BIF", "public", "static", "EObject", "lookup_element", "(", "EProc", "proc", ",", "EObject", "tab", ",", "EObject", "key", ",", "EObject", "pos", ")", "{", "ESmall", "p", "=", "pos", ".", "testSmall", "(", ")", ";", "ETable", "table", "=", "resolve", "(", "proc", ",", "tab", ",", "false", ")", ";", "if", "(", "table", "==", "null", "||", "p", "==", "null", ")", "{", "throw", "ERT", ".", "badarg", "(", "tab", ",", "key", ",", "pos", ")", ";", "}", "ESeq", "ent", "=", "table", ".", "lookup", "(", "key", ")", ";", "if", "(", "ent", "==", "ERT", ".", "NIL", ")", "{", "throw", "ERT", ".", "badarg", "(", "tab", ",", "key", ",", "pos", ")", ";", "}", "if", "(", "table", ".", "type", "==", "am_set", "||", "table", ".", "type", "==", "am_ordered_set", ")", "{", "return", "get_elm", "(", "tab", ",", "key", ",", "p", ",", "ent", ")", ";", "}", "else", "{", "ESeq", "res", "=", "ERT", ".", "NIL", ";", "for", "(", ";", "!", "ent", ".", "isNil", "(", ")", ";", "ent", "=", "ent", ".", "tail", "(", ")", ")", "{", "res", "=", "res", ".", "cons", "(", "get_elm", "(", "tab", ",", "key", ",", "p", ",", "ent", ")", ")", ";", "}", "return", "res", ";", "}", "}", "private", "static", "EObject", "get_elm", "(", "EObject", "tab", ",", "EObject", "key", ",", "ESmall", "p", ",", "ESeq", "ent", ")", "{", "ETuple", "tup", "=", "ent", ".", "head", "(", ")", ".", "testTuple", "(", ")", ";", "if", "(", "tup", "==", "null", "||", "p", ".", "value", "<", "1", "||", "p", ".", "value", ">", "tup", ".", "arity", "(", ")", ")", "{", "throw", "ERT", ".", "badarg", "(", "tab", ",", "key", ",", "p", ")", ";", "}", "return", "tup", ".", "elm", "(", "p", ".", "value", ")", ";", "}", "@", "BIF", "public", "static", "ESeq", "lookup", "(", "EProc", "proc", ",", "EObject", "tab", ",", "EObject", "key", ")", "{", "ETable", "table", "=", "resolve", "(", "proc", ",", "tab", ",", "false", ")", ";", "if", "(", "table", "==", "null", ")", "{", "throw", "ERT", ".", "badarg", "(", "tab", ",", "key", ")", ";", "}", "return", "table", ".", "lookup", "(", "key", ")", ";", "}", "@", "BIF", "public", "static", "EObject", "insert_new", "(", "EProc", "proc", ",", "EObject", "tab", ",", "EObject", "oneOrMore", ")", "{", "ETable", "table", "=", "resolve", "(", "proc", ",", "tab", ",", "true", ")", ";", "ETuple", "one", "=", "oneOrMore", ".", "testTuple", "(", ")", ";", "ESeq", "more", "=", "oneOrMore", ".", "testSeq", "(", ")", ";", "if", "(", "table", "==", "null", "||", "(", "one", "==", "null", "&&", "more", "==", "null", ")", ")", "{", "throw", "ERT", ".", "badarg", "(", "tab", ",", "oneOrMore", ")", ";", "}", "boolean", "result", ";", "if", "(", "one", "!=", "null", ")", "{", "result", "=", "table", ".", "insert_new_one", "(", "one", ")", ";", "}", "else", "{", "result", "=", "table", ".", "insert_new_many", "(", "more", ")", ";", "}", "return", "ERT", ".", "box", "(", "result", ")", ";", "}", "@", "BIF", "public", "static", "EAtom", "delete", "(", "EProc", "caller", ",", "EObject", "nameOrTid", ")", "{", "ETable", "table", "=", "resolve", "(", "caller", ",", "nameOrTid", ",", "true", ")", ";", "if", "(", "table", "==", "null", ")", "{", "throw", "ERT", ".", "badarg", "(", "nameOrTid", ")", ";", "}", "table", ".", "delete", "(", ")", ";", "return", "ERT", ".", "TRUE", ";", "}", "@", "BIF", "static", "ESeq", "match", "(", "EProc", "caller", ",", "EObject", "nameOrTid", ",", "EObject", "spec", ")", "{", "try", "{", "ETable", "table", "=", "resolve", "(", "caller", ",", "nameOrTid", ",", "false", ")", ";", "if", "(", "table", "==", "null", ")", "throw", "ERT", ".", "badarg", "(", "nameOrTid", ",", "spec", ")", ";", "EPattern", "matcher", "=", "new", "EPattern", "(", "table", ".", "keypos1", ",", "spec", ")", ";", "return", "table", ".", "match", "(", "matcher", ")", ";", "}", "catch", "(", "ErlangException", "e", ")", "{", "e", ".", "printStackTrace", "(", ")", ";", "throw", "e", ";", "}", "}", "@", "BIF", "static", "EInteger", "select_delete", "(", "EProc", "caller", ",", "EObject", "nameOrTid", ",", "EObject", "spec", ")", "{", "ESeq", "lspec", "=", "spec", ".", "testSeq", "(", ")", ";", "ETable", "table", "=", "resolve", "(", "caller", ",", "nameOrTid", ",", "true", ")", ";", "if", "(", "lspec", "==", "null", "||", "table", "==", "null", ")", "throw", "ERT", ".", "badarg", "(", "nameOrTid", ",", "spec", ")", ";", "EMatchSpec", "matcher", "=", "EMatchSpec", ".", "compile", "(", "lspec", ")", ";", "return", "table", ".", "select_delete", "(", "matcher", ")", ";", "}", "@", "BIF", "static", "public", "EAtom", "delete_all_objects", "(", "EProc", "caller", ",", "EObject", "nameOrTid", ")", "{", "ETable", "table", "=", "resolve", "(", "caller", ",", "nameOrTid", ",", "true", ")", ";", "if", "(", "table", "==", "null", ")", "throw", "ERT", ".", "badarg", "(", "nameOrTid", ")", ";", "table", ".", "delete_all_objects", "(", ")", ";", "return", "ERT", ".", "TRUE", ";", "}", "@", "BIF", "static", "public", "EObject", "match_spec_compile", "(", "EObject", "spec", ")", "{", "ESeq", "lspec", "=", "spec", ".", "testSeq", "(", ")", ";", "if", "(", "lspec", "==", "null", ")", "throw", "ERT", ".", "badarg", "(", "spec", ")", ";", "EMatchSpec", "matcher", "=", "EMatchSpec", ".", "compile", "(", "lspec", ")", ";", "return", "matcher", ";", "}", "@", "BIF", "static", "public", "EObject", "is_compiled_ms", "(", "EObject", "spec", ")", "{", "return", "ERT", ".", "box", "(", "spec", "instanceof", "EMatchSpec", ")", ";", "}", "@", "BIF", "static", "public", "EObject", "prev", "(", "EObject", "obj", ",", "EObject", "obj2", ")", "{", "throw", "new", "NotImplemented", "(", ")", ";", "}", "@", "BIF", "public", "static", "EObject", "first", "(", "EProc", "proc", ",", "EObject", "tab", ")", "{", "ETable", "table", "=", "resolve", "(", "proc", ",", "tab", ",", "false", ")", ";", "if", "(", "table", "==", "null", ")", "{", "throw", "ERT", ".", "badarg", "(", "tab", ")", ";", "}", "return", "table", ".", "first", "(", ")", ";", "}", "@", "BIF", "static", "public", "EObject", "slot", "(", "EProc", "caller", ",", "EObject", "nameOrTid", ",", "EObject", "i", ")", "{", "ETable", "table", "=", "resolve", "(", "caller", ",", "nameOrTid", ",", "false", ")", ";", "ESmall", "pos", ";", "if", "(", "(", "pos", "=", "i", ".", "testSmall", "(", ")", ")", "==", "null", "||", "table", "==", "null", ")", "throw", "ERT", ".", "badarg", "(", "nameOrTid", ",", "i", ")", ";", "if", "(", "pos", ".", "value", "==", "0", ")", "{", "return", "table", ".", "slot", "(", ")", ";", "}", "else", "if", "(", "pos", ".", "value", "==", "1", ")", "{", "return", "am_$end_of_table", ";", "}", "else", "{", "throw", "ERT", ".", "badarg", "(", "nameOrTid", ",", "i", ")", ";", "}", "}", "@", "BIF", "static", "public", "ESeq", "all", "(", ")", "{", "ESeq", "res", "=", "ERT", ".", "NIL", ";", "for", "(", "ETable", "table", ":", "tid_to_table", ".", "values", "(", ")", ")", "{", "if", "(", "table", ".", "is_named", ")", "{", "res", "=", "res", ".", "cons", "(", "table", ".", "aname", ")", ";", "}", "else", "{", "res", "=", "res", ".", "cons", "(", "table", ".", "tid", ")", ";", "}", "}", "return", "res", ";", "}", "@", "BIF", "static", "public", "EObject", "last", "(", "EObject", "obj", ")", "{", "throw", "new", "NotImplemented", "(", ")", ";", "}", "@", "BIF", "static", "public", "EObject", "match_object", "(", "EProc", "caller", ",", "EObject", "nameOrTid", ",", "EObject", "spec", ")", "{", "ETable", "table", "=", "resolve", "(", "caller", ",", "nameOrTid", ",", "false", ")", ";", "if", "(", "(", "spec", ".", "testAtom", "(", ")", "==", "null", "&&", "spec", ".", "testTuple", "(", ")", "==", "null", ")", "||", "table", "==", "null", ")", "throw", "ERT", ".", "badarg", "(", "nameOrTid", ",", "spec", ")", ";", "EPattern", "matcher", ";", "try", "{", "matcher", "=", "new", "EPattern", "(", "table", ".", "keypos1", ",", "spec", ")", ";", "}", "catch", "(", "ErlangException", "e", ")", "{", "log", ".", "severe", "(", "\"\"", "+", "spec", "+", "\":", "\"", "+", "e", ".", "getMessage", "(", ")", ")", ";", "log", ".", "log", "(", "Level", ".", "FINE", ",", "\"details:", "\"", ",", "e", ")", ";", "throw", "ERT", ".", "badarg", "(", "nameOrTid", ",", "spec", ")", ";", "}", "return", "table", ".", "match_object", "(", "matcher", ")", ";", "}", "@", "BIF", "static", "public", "EObject", "next", "(", "EProc", "proc", ",", "EObject", "tab", ",", "EObject", "key", ")", "{", "ETable", "table", "=", "resolve", "(", "proc", ",", "tab", ",", "false", ")", ";", "if", "(", "table", "==", "null", ")", "{", "throw", "ERT", ".", "badarg", "(", "tab", ",", "key", ")", ";", "}", "return", "table", ".", "next", "(", "key", ")", ";", "}", "@", "BIF", "static", "public", "EObject", "safe_fixtable", "(", "EProc", "proc", ",", "EObject", "tab", ",", "EObject", "onOff", ")", "{", "ETable", "table", "=", "resolve", "(", "proc", ",", "tab", ",", "false", ")", ";", "if", "(", "table", "==", "null", "||", "(", "onOff", "!=", "ERT", ".", "TRUE", "&&", "onOff", "!=", "ERT", ".", "FALSE", ")", ")", "{", "throw", "ERT", ".", "badarg", "(", "tab", ",", "onOff", ")", ";", "}", "return", "ERT", ".", "TRUE", ";", "}", "@", "BIF", "static", "public", "EObject", "repair_continuation", "(", "EObject", "cont", ",", "EObject", "ms", ")", "{", "if", "(", "log", ".", "isLoggable", "(", "Level", ".", "FINE", ")", ")", "log", ".", "fine", "(", "\"repair", "cont=\"", "+", "cont", "+", "\";", "ms=\"", "+", "ms", ")", ";", "return", "cont", ";", "}", "@", "BIF", "static", "public", "EObject", "select", "(", "EObject", "obj1", ")", "{", "if", "(", "obj1", "==", "Native", ".", "am_$end_of_table", ")", "{", "return", "obj1", ";", "}", "if", "(", "obj1", "instanceof", "ISelectContinuation", ")", "{", "ISelectContinuation", "cont", "=", "(", "ISelectContinuation", ")", "obj1", ";", "return", "cont", ".", "select", "(", ")", ";", "}", "else", "{", "throw", "ERT", ".", "badarg", "(", "obj1", ")", ";", "}", "}", "@", "BIF", "static", "public", "ESmall", "select_count", "(", "EProc", "caller", ",", "EObject", "nameOrTid", ",", "EObject", "matchSpec", ")", "{", "ESeq", "res", "=", "select", "(", "caller", ",", "nameOrTid", ",", "matchSpec", ")", ";", "int", "result", "=", "0", ";", "while", "(", "!", "res", ".", "isNil", "(", ")", ")", "{", "if", "(", "res", ".", "head", "(", ")", "==", "ERT", ".", "TRUE", ")", "result", "+=", "1", ";", "res", "=", "res", ".", "tail", "(", ")", ";", "}", "return", "ERT", ".", "box", "(", "result", ")", ";", "}", "@", "BIF", "static", "public", "ESeq", "select", "(", "EProc", "caller", ",", "EObject", "nameOrTid", ",", "EObject", "matchSpec", ")", "{", "ETable", "table", "=", "resolve", "(", "caller", ",", "nameOrTid", ",", "false", ")", ";", "if", "(", "table", "==", "null", ")", "throw", "ERT", ".", "badarg", "(", "nameOrTid", ",", "matchSpec", ")", ";", "EMatchSpec", "spec", ";", "ESeq", "seq", ";", "if", "(", "(", "matchSpec", "instanceof", "EMatchSpec", ")", ")", "{", "spec", "=", "(", "EMatchSpec", ")", "matchSpec", ";", "}", "else", "if", "(", "(", "seq", "=", "matchSpec", ".", "testSeq", "(", ")", ")", "!=", "null", ")", "{", "try", "{", "spec", "=", "EMatchSpec", ".", "compile", "(", "seq", ")", ";", "}", "catch", "(", "ErlangError", "e", ")", "{", "if", "(", "e", ".", "reason", "(", ")", "==", "ERT", ".", "am_badarg", ")", "{", "throw", "ERT", ".", "badarg", "(", "nameOrTid", ",", "matchSpec", ")", ";", "}", "else", "{", "throw", "e", ";", "}", "}", "catch", "(", "IllegalArgumentException", "e", ")", "{", "e", ".", "printStackTrace", "(", ")", ";", "throw", "ERT", ".", "badarg", "(", "nameOrTid", ",", "matchSpec", ")", ";", "}", "}", "else", "{", "throw", "ERT", ".", "badarg", "(", "nameOrTid", ",", "matchSpec", ")", ";", "}", "EObject", "res", "=", "table", ".", "select", "(", "spec", ",", "-", "1", ")", ";", "ETuple2", "tup", ";", "if", "(", "res", "==", "am_$end_of_table", ")", "{", "return", "ERT", ".", "NIL", ";", "}", "else", "if", "(", "(", "tup", "=", "ETuple2", ".", "cast", "(", "res", ")", ")", "!=", "null", "&&", "(", "seq", "=", "tup", ".", "elem1", ".", "testSeq", "(", ")", ")", "!=", "null", ")", "{", "return", "seq", ";", "}", "else", "{", "throw", "new", "InternalError", "(", ")", ";", "}", "}", "@", "BIF", "static", "public", "EObject", "select", "(", "EProc", "caller", ",", "EObject", "nameOrTid", ",", "EObject", "matchSpec", ",", "EObject", "limit", ")", "{", "ETable", "table", "=", "resolve", "(", "caller", ",", "nameOrTid", ",", "false", ")", ";", "ESmall", "lim", "=", "limit", ".", "testSmall", "(", ")", ";", "if", "(", "table", "==", "null", "||", "lim", "==", "null", "||", "lim", ".", "value", "<", "1", ")", "throw", "ERT", ".", "badarg", "(", "nameOrTid", ",", "matchSpec", ",", "limit", ")", ";", "EMatchSpec", "spec", ";", "ESeq", "seq", ";", "if", "(", "(", "matchSpec", "instanceof", "EMatchSpec", ")", ")", "{", "spec", "=", "(", "EMatchSpec", ")", "matchSpec", ";", "}", "else", "if", "(", "(", "seq", "=", "matchSpec", ".", "testSeq", "(", ")", ")", "!=", "null", ")", "{", "try", "{", "spec", "=", "EMatchSpec", ".", "compile", "(", "seq", ")", ";", "}", "catch", "(", "ErlangError", "e", ")", "{", "if", "(", "e", ".", "reason", "(", ")", "==", "ERT", ".", "am_badarg", ")", "{", "throw", "ERT", ".", "badarg", "(", "nameOrTid", ",", "matchSpec", ",", "limit", ")", ";", "}", "else", "{", "throw", "e", ";", "}", "}", "}", "else", "{", "throw", "ERT", ".", "badarg", "(", "nameOrTid", ",", "matchSpec", ",", "limit", ")", ";", "}", "return", "table", ".", "select", "(", "spec", ",", "lim", ".", "value", ")", ";", "}", "@", "BIF", "static", "public", "EObject", "match_spec_run_r", "(", "EObject", "list", ",", "EObject", "matchSpec", ",", "EObject", "tail_arg", ")", "{", "ESeq", "res", "=", "tail_arg", ".", "testSeq", "(", ")", ";", "ESeq", "input", "=", "list", ".", "testSeq", "(", ")", ";", "if", "(", "res", "==", "null", "||", "input", "==", "null", ")", "throw", "ERT", ".", "badarg", "(", "list", ",", "matchSpec", ",", "tail_arg", ")", ";", "EMatchSpec", "spec", ";", "ESeq", "seq", ";", "if", "(", "(", "matchSpec", "instanceof", "EMatchSpec", ")", ")", "{", "spec", "=", "(", "EMatchSpec", ")", "matchSpec", ";", "}", "else", "if", "(", "(", "seq", "=", "matchSpec", ".", "testSeq", "(", ")", ")", "!=", "null", ")", "{", "try", "{", "spec", "=", "EMatchSpec", ".", "compile", "(", "seq", ")", ";", "}", "catch", "(", "ErlangError", "e", ")", "{", "if", "(", "e", ".", "reason", "(", ")", "==", "ERT", ".", "am_badarg", ")", "{", "throw", "ERT", ".", "badarg", "(", "list", ",", "matchSpec", ",", "tail_arg", ")", ";", "}", "else", "{", "throw", "e", ";", "}", "}", "}", "else", "{", "throw", "ERT", ".", "badarg", "(", "list", ",", "matchSpec", ",", "tail_arg", ")", ";", "}", "while", "(", "!", "input", ".", "isNil", "(", ")", ")", "{", "EObject", "candidate", "=", "input", ".", "head", "(", ")", ";", "EObject", "o", "=", "spec", ".", "match", "(", "candidate", ")", ";", "if", "(", "o", "!=", "null", ")", "{", "res", "=", "res", ".", "cons", "(", "o", ")", ";", "}", "input", "=", "input", ".", "tail", "(", ")", ";", "}", "return", "res", ";", "}", "@", "BIF", "static", "public", "EObject", "setopts", "(", "EProc", "proc", ",", "EObject", "tab", ",", "EObject", "opts", ")", "{", "ETable", "table", "=", "resolve", "(", "proc", ",", "tab", ",", "true", ")", ";", "if", "(", "table", "==", "null", "||", "table", ".", "owner_pid", "(", ")", "!=", "proc", ".", "self_handle", "(", ")", ")", "{", "throw", "ERT", ".", "badarg", "(", "tab", ",", "opts", ")", ";", "}", "ESeq", "seq", ";", "if", "(", "(", "seq", "=", "opts", ".", "testSeq", "(", ")", ")", "!=", "null", ")", "{", "while", "(", "!", "seq", ".", "isNil", "(", ")", ")", "{", "table", ".", "setopt", "(", "seq", ".", "head", "(", ")", ")", ";", "seq", "=", "seq", ".", "tail", "(", ")", ";", "}", "}", "else", "{", "table", ".", "setopt", "(", "opts", ")", ";", "}", "return", "ERT", ".", "TRUE", ";", "}", "@", "BIF", "static", "public", "EObject", "info", "(", "EProc", "proc", ",", "EObject", "nameOrTid", ")", "{", "ETable", "table", ";", "if", "(", "(", "table", "=", "get_table", "(", "nameOrTid", ")", ")", "==", "null", ")", "{", "return", "ERT", ".", "am_undefined", ";", "}", "return", "table", ".", "info", "(", ")", ";", "}", "@", "BIF", "static", "public", "EObject", "info", "(", "EProc", "proc", ",", "EObject", "nameOrTid", ",", "EObject", "item", ")", "{", "ETable", "table", ";", "if", "(", "(", "table", "=", "get_table", "(", "nameOrTid", ")", ")", "==", "null", ")", "{", "return", "ERT", ".", "am_undefined", ";", "}", "EObject", "info", "=", "table", ".", "info", "(", "item", ")", ";", "if", "(", "info", "==", "null", ")", "throw", "ERT", ".", "badarg", "(", "nameOrTid", ",", "item", ")", ";", "else", "return", "info", ";", "}", "private", "static", "ETable", "get_table", "(", "EObject", "nameOrTid", ")", "{", "ETable", "table", "=", "null", ";", "EInteger", "tid", ";", "EAtom", "name", ";", "if", "(", "(", "tid", "=", "nameOrTid", ".", "testInteger", "(", ")", ")", "!=", "null", ")", "{", "table", "=", "tid_to_table", ".", "get", "(", "tid", ")", ";", "}", "else", "if", "(", "(", "name", "=", "nameOrTid", ".", "testAtom", "(", ")", ")", "!=", "null", ")", "{", "tid", "=", "name_to_tid", ".", "get", "(", "name", ")", ";", "if", "(", "tid", "!=", "null", ")", "{", "table", "=", "tid_to_table", ".", "get", "(", "tid", ")", ";", "}", "}", "else", "{", "throw", "ERT", ".", "badarg", "(", "nameOrTid", ")", ";", "}", "return", "table", ";", "}", "@", "BIF", "static", "public", "EObject", "member", "(", "EProc", "proc", ",", "EObject", "tab", ",", "EObject", "key", ")", "{", "ETable", "table", "=", "resolve", "(", "proc", ",", "tab", ",", "false", ")", ";", "if", "(", "table", "==", "null", ")", "{", "throw", "ERT", ".", "badarg", "(", "tab", ",", "key", ")", ";", "}", "return", "table", ".", "member", "(", "key", ")", ";", "}", "@", "BIF", "static", "public", "EObject", "delete_object", "(", "EProc", "proc", ",", "EObject", "tab", ",", "EObject", "obj", ")", "{", "ETable", "table", "=", "resolve", "(", "proc", ",", "tab", ",", "true", ")", ";", "ETuple", "one", "=", "obj", ".", "testTuple", "(", ")", ";", "if", "(", "table", "==", "null", "||", "one", "==", "null", ")", "{", "throw", "ERT", ".", "badarg", "(", "tab", ",", "obj", ")", ";", "}", "table", ".", "delete_object", "(", "one", ")", ";", "return", "ERT", ".", "TRUE", ";", "}", "@", "BIF", "static", "public", "EObject", "update_counter", "(", "EProc", "proc", ",", "EObject", "tab", ",", "EObject", "key", ",", "EObject", "upd", ")", "{", "ETable", "table", "=", "resolve", "(", "proc", ",", "tab", ",", "true", ")", ";", "if", "(", "table", "==", "null", "||", "!", "(", "table", ".", "type", "==", "am_set", "||", "table", ".", "type", "==", "am_ordered_set", ")", ")", "{", "throw", "ERT", ".", "badarg", "(", "tab", ",", "key", ",", "upd", ")", ";", "}", "ETableSet", "ets", "=", "(", "ETableSet", ")", "table", ";", "EObject", "res", "=", "ets", ".", "update_counter", "(", "key", ",", "upd", ")", ";", "if", "(", "res", "==", "null", ")", "{", "throw", "ERT", ".", "badarg", "(", "tab", ",", "key", ",", "upd", ")", ";", "}", "return", "res", ";", "}", "@", "BIF", "static", "public", "EObject", "update_element", "(", "EProc", "proc", ",", "EObject", "tab", ",", "EObject", "key", ",", "EObject", "upd", ")", "{", "ETable", "table", "=", "resolve", "(", "proc", ",", "tab", ",", "true", ")", ";", "ETuple2", "t_upd", "=", "ETuple2", ".", "cast", "(", "upd", ")", ";", "ESeq", "s_upd", "=", "upd", ".", "testSeq", "(", ")", ";", "if", "(", "table", "==", "null", "||", "(", "t_upd", "==", "null", "&&", "s_upd", "==", "null", ")", "||", "!", "(", "table", ".", "type", "==", "am_set", "||", "table", ".", "type", "==", "am_ordered_set", ")", ")", "{", "throw", "ERT", ".", "badarg", "(", "tab", ",", "key", ",", "upd", ")", ";", "}", "if", "(", "s_upd", "==", "null", ")", "{", "s_upd", "=", "ERT", ".", "NIL", ".", "cons", "(", "t_upd", ")", ";", "}", "ETableSet", "ets", "=", "(", "ETableSet", ")", "table", ";", "EObject", "res", "=", "ets", ".", "update_element", "(", "key", ",", "s_upd", ")", ";", "if", "(", "res", "==", "null", ")", "{", "throw", "ERT", ".", "badarg", "(", "tab", ",", "key", ",", "upd", ")", ";", "}", "return", "res", ";", "}", "}", "</s>" ]
7,796
[ "<s>", "package", "erjang", ".", "m", ".", "ets", ";", "import", "java", ".", "util", ".", "HashMap", ";", "import", "erjang", ".", "EObject", ";", "import", "erjang", ".", "ERT", ";", "import", "erjang", ".", "ESeq", ";", "import", "erjang", ".", "ETuple", ";", "public", "class", "EMatchContext", "{", "final", "HashMap", "<", "Integer", ",", "EObject", ">", "vars", ";", "final", "EObject", "value", ";", "private", "final", "Integer", "[", "]", "varnames", ";", "EMatchContext", "(", "Integer", "[", "]", "varnames", ",", "EObject", "value", ")", "{", "this", ".", "varnames", "=", "varnames", ";", "this", ".", "vars", "=", "new", "HashMap", "<", "Integer", ",", "EObject", ">", "(", ")", ";", "this", ".", "value", "=", "value", ";", "}", "public", "ESeq", "makeList", "(", ")", "{", "ESeq", "res", "=", "ERT", ".", "NIL", ";", "for", "(", "int", "i", "=", "varnames", ".", "length", "-", "1", ";", "i", ">=", "0", ";", "i", "--", ")", "{", "res", "=", "res", ".", "cons", "(", "vars", ".", "get", "(", "varnames", "[", "i", "]", ")", ")", ";", "}", "return", "res", ";", "}", "public", "EObject", "makeTuple", "(", ")", "{", "ETuple", "res", "=", "ETuple", ".", "make", "(", "varnames", ".", "length", ")", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "varnames", ".", "length", ";", "i", "++", ")", "{", "res", ".", "set", "(", "i", "+", "1", ",", "vars", ".", "get", "(", "varnames", "[", "i", "]", ")", ")", ";", "}", "return", "res", ";", "}", "}", "</s>" ]
7,797
[ "<s>", "package", "erjang", ".", "m", ".", "ets", ";", "import", "java", ".", "lang", ".", "ref", ".", "WeakReference", ";", "import", "java", ".", "util", ".", "concurrent", ".", "Callable", ";", "import", "java", ".", "util", ".", "concurrent", ".", "atomic", ".", "AtomicReference", ";", "import", "kilim", ".", "Pausable", ";", "import", "com", ".", "trifork", ".", "clj_ds", ".", "APersistentMap", ";", "import", "com", ".", "trifork", ".", "clj_ds", ".", "IMapEntry", ";", "import", "com", ".", "trifork", ".", "clj_ds", ".", "IPersistentMap", ";", "import", "com", ".", "trifork", ".", "clj_ds", ".", "ISeq", ";", "import", "com", ".", "trifork", ".", "clj_ds", ".", "PersistentTreeMap", ";", "import", "erjang", ".", "EAtom", ";", "import", "erjang", ".", "EInteger", ";", "import", "erjang", ".", "EInternalPID", ";", "import", "erjang", ".", "EObject", ";", "import", "erjang", ".", "EProc", ";", "import", "erjang", ".", "ERT", ";", "import", "erjang", ".", "ESeq", ";", "import", "erjang", ".", "ETuple", ";", "import", "erjang", ".", "ETuple2", ";", "import", "erjang", ".", "ETuple3", ";", "import", "erjang", ".", "ErlangError", ";", "import", "erjang", ".", "ExitHook", ";", "import", "erjang", ".", "NotImplemented", ";", "abstract", "class", "ETable", "implements", "ExitHook", "{", "public", "static", "final", "EAtom", "am_stm", "=", "EAtom", ".", "intern", "(", "\"stm\"", ")", ";", "protected", "WeakReference", "<", "EProc", ">", "owner", ";", "protected", "EAtom", "access", ";", "protected", "final", "int", "keypos1", ";", "protected", "EInternalPID", "heirPID", ";", "protected", "EObject", "heirData", ";", "protected", "final", "EInteger", "tid", ";", "protected", "final", "EAtom", "aname", ";", "protected", "final", "boolean", "is_named", ";", "protected", "final", "EAtom", "type", ";", "protected", "final", "APersistentMap", "empty", ";", "private", "AtomicReference", "<", "IPersistentMap", "<", "EObject", ",", "Object", ">", ">", "mapRef", ";", "private", "boolean", "is_fixed", ";", "ETable", "(", "EProc", "owner", ",", "EAtom", "type", ",", "EInteger", "tid", ",", "EAtom", "aname", ",", "EAtom", "access", ",", "int", "keypos", ",", "boolean", "is_named", ",", "EInternalPID", "heir_pid", ",", "EObject", "heir_data", ",", "APersistentMap", "map", ")", "{", "this", ".", "type", "=", "type", ";", "this", ".", "is_named", "=", "is_named", ";", "this", ".", "owner", "=", "new", "WeakReference", "<", "EProc", ">", "(", "owner", ")", ";", "this", ".", "tid", "=", "tid", ";", "this", ".", "aname", "=", "aname", ";", "this", ".", "access", "=", "access", ";", "this", ".", "keypos1", "=", "keypos", ";", "this", ".", "heirPID", "=", "heir_pid", ";", "this", ".", "heirData", "=", "heir_data", ";", "try", "{", "this", ".", "mapRef", "=", "new", "AtomicReference", "<", "IPersistentMap", "<", "EObject", ",", "Object", ">", ">", "(", "map", ")", ";", "}", "catch", "(", "Exception", "e", ")", "{", "throw", "new", "ErlangError", "(", "am_stm", ")", ";", "}", "empty", "=", "map", ";", "owner", ".", "add_exit_hook", "(", "this", ")", ";", "}", "public", "static", "ETable", "allocate", "(", "EProc", "proc", ",", "EInteger", "tid", ",", "EAtom", "aname", ",", "EAtom", "type", ",", "EAtom", "access", ",", "int", "keypos", ",", "boolean", "write_concurrency", ",", "boolean", "is_named", ",", "EInternalPID", "heir_pid", ",", "EObject", "heir_data", ")", "{", "if", "(", "type", "==", "Native", ".", "am_set", "||", "type", "==", "Native", ".", "am_ordered_set", ")", "{", "return", "new", "ETableSet", "(", "proc", ",", "type", ",", "tid", ",", "aname", ",", "access", ",", "keypos", ",", "write_concurrency", ",", "is_named", ",", "heir_pid", ",", "heir_data", ")", ";", "}", "if", "(", "type", "==", "Native", ".", "am_bag", "||", "type", "==", "Native", ".", "am_duplicate_bag", ")", "{", "return", "new", "ETableBag", "(", "proc", ",", "type", ",", "tid", ",", "aname", ",", "access", ",", "keypos", ",", "write_concurrency", ",", "is_named", ",", "heir_pid", ",", "heir_data", ")", ";", "}", "throw", "new", "NotImplemented", "(", "\"ets", "type=\"", "+", "type", "+", "\";", "access=\"", "+", "access", "+", "\";", "keypos=\"", "+", "keypos", "+", "\"\"", "+", "write_concurrency", "+", "\";", "heir_pid=\"", "+", "heir_pid", ")", ";", "}", "public", "final", "boolean", "allow_access", "(", "EProc", "caller", ",", "boolean", "write_access", ")", "{", "if", "(", "access", "==", "Native", ".", "am_protected", ")", "{", "if", "(", "write_access", ")", "{", "return", "(", "caller", "==", "owner", ".", "get", "(", ")", ")", ";", "}", "else", "{", "return", "true", ";", "}", "}", "else", "if", "(", "access", "==", "Native", ".", "am_public", ")", "{", "return", "true", ";", "}", "else", "if", "(", "access", "==", "Native", ".", "am_private", ")", "{", "return", "(", "caller", "==", "owner", ".", "get", "(", ")", ")", ";", "}", "else", "{", "throw", "new", "InternalError", "(", "\"\"", ")", ";", "}", "}", "EInternalPID", "owner_pid", "(", ")", "{", "EProc", "o", "=", "owner", ".", "get", "(", ")", ";", "if", "(", "o", "==", "null", ")", "throw", "ERT", ".", "badarg", "(", ")", ";", "return", "o", ".", "self_handle", "(", ")", ";", "}", "ESeq", "info", "(", ")", "{", "ESeq", "rep", "=", "ERT", ".", "NIL", ";", "ETable", "table", "=", "this", ";", "rep", "=", "rep", ".", "cons", "(", "new", "ETuple2", "(", "Native", ".", "am_owner", ",", "table", ".", "owner_pid", "(", ")", ")", ")", ";", "rep", "=", "rep", ".", "cons", "(", "new", "ETuple2", "(", "Native", ".", "am_named_table", ",", "ERT", ".", "box", "(", "table", ".", "is_named", ")", ")", ")", ";", "rep", "=", "rep", ".", "cons", "(", "new", "ETuple2", "(", "Native", ".", "am_name", ",", "table", ".", "aname", ")", ")", ";", "if", "(", "table", ".", "heirPID", "!=", "null", ")", "rep", "=", "rep", ".", "cons", "(", "new", "ETuple2", "(", "Native", ".", "am_heir", ",", "table", ".", "heirPID", ")", ")", ";", "else", "rep", "=", "rep", ".", "cons", "(", "new", "ETuple2", "(", "Native", ".", "am_heir", ",", "Native", ".", "am_none", ")", ")", ";", "rep", "=", "rep", ".", "cons", "(", "new", "ETuple2", "(", "Native", ".", "am_size", ",", "ERT", ".", "box", "(", "table", ".", "size", "(", ")", ")", ")", ")", ";", "rep", "=", "rep", ".", "cons", "(", "new", "ETuple2", "(", "Native", ".", "am_node", ",", "ERT", ".", "getLocalNode", "(", ")", ".", "node", "(", ")", ")", ")", ";", "rep", "=", "rep", ".", "cons", "(", "new", "ETuple2", "(", "Native", ".", "am_type", ",", "table", ".", "type", ")", ")", ";", "rep", "=", "rep", ".", "cons", "(", "new", "ETuple2", "(", "Native", ".", "am_keypos", ",", "ERT", ".", "box", "(", "table", ".", "keypos1", ")", ")", ")", ";", "rep", "=", "rep", ".", "cons", "(", "new", "ETuple2", "(", "Native", ".", "am_protection", ",", "table", ".", "access", ")", ")", ";", "rep", "=", "rep", ".", "cons", "(", "new", "ETuple2", "(", "Native", ".", "am_fixed", ",", "ERT", ".", "box", "(", "is_fixed", ")", ")", ")", ";", "return", "rep", ";", "}", "public", "void", "on_exit", "(", "EInternalPID", "dyingPID", ")", "throws", "Pausable", "{", "if", "(", "dyingPID", "==", "owner_pid", "(", ")", ")", "{", "EInternalPID", "heirPID", "=", "this", ".", "heirPID", ";", "EProc", "new_owner", ";", "if", "(", "heirPID", "!=", "null", "&&", "heirPID", "!=", "dyingPID", "&&", "(", "new_owner", "=", "heirPID", ".", "task", "(", ")", ")", "!=", "null", ")", "{", "ETuple", "msg", "=", "ETuple", ".", "make", "(", "EAtom", ".", "intern", "(", "\"ETS-TRANSFER\"", ")", ",", "this", ".", "aname", ",", "dyingPID", ",", "this", ".", "heirData", "==", "null", "?", "ERT", ".", "NIL", ":", "this", ".", "heirData", ")", ";", "this", ".", "owner", "=", "new", "WeakReference", "<", "EProc", ">", "(", "new_owner", ")", ";", "new_owner", ".", "add_exit_hook", "(", "this", ")", ";", "heirPID", ".", "send", "(", "dyingPID", ",", "msg", ")", ";", "}", "else", "{", "delete", "(", ")", ";", "}", "}", "else", "{", "Native", ".", "log", ".", "warning", "(", "\"table", "\"", "+", "aname", "+", "\"", "(\"", "+", "tid", "+", "\"\"", "+", "dyingPID", ")", ";", "}", "}", "void", "delete", "(", ")", "{", "EInternalPID", "p", "=", "owner_pid", "(", ")", ";", "if", "(", "p", "!=", "null", ")", "p", ".", "remove_exit_hook", "(", "this", ")", ";", "Native", ".", "tid_to_table", ".", "remove", "(", "tid", ")", ";", "if", "(", "is_named", ")", "{", "Native", ".", "name_to_tid", ".", "remove", "(", "aname", ")", ";", "}", "}", "abstract", "int", "size", "(", ")", ";", "EObject", "get_key", "(", "ETuple", "value", ")", "{", "if", "(", "keypos1", ">", "value", ".", "arity", "(", ")", ")", "{", "throw", "ERT", ".", "badarg", "(", "ERT", ".", "NIL", ".", "cons", "(", "value", ")", ")", ";", "}", "return", "value", ".", "elm", "(", "keypos1", ")", ";", "}", "IPersistentMap", "deref", "(", ")", "{", "return", "(", "IPersistentMap", ")", "mapRef", ".", "get", "(", ")", ";", "}", "abstract", "class", "WithMap", "<", "T", ">", "implements", "Callable", "<", "T", ">", "{", "private", "IPersistentMap", "orig", ";", "@", "Override", "public", "final", "T", "call", "(", ")", "{", "return", "run", "(", "orig", "=", "(", "IPersistentMap", ")", "mapRef", ".", "get", "(", ")", ")", ";", "}", "protected", "abstract", "T", "run", "(", "IPersistentMap", "map", ")", ";", "protected", "void", "set", "(", "IPersistentMap", "map", ")", "{", "mapRef", ".", "compareAndSet", "(", "orig", ",", "map", ")", ";", "}", "}", "@", "SuppressWarnings", "(", "\"unchecked\"", ")", "<", "X", ">", "X", "in_tx", "(", "WithMap", "<", "X", ">", "run", ")", "{", "try", "{", "synchronized", "(", "ETable", ".", "this", ")", "{", "return", "run", ".", "call", "(", ")", ";", "}", "}", "catch", "(", "ErlangError", "e", ")", "{", "throw", "e", ";", "}", "catch", "(", "Exception", "e", ")", "{", "e", ".", "printStackTrace", "(", ")", ";", "throw", "new", "ErlangError", "(", "am_stm", ")", ";", "}", "}", "protected", "abstract", "void", "insert_one", "(", "ETuple", "value", ")", ";", "protected", "abstract", "void", "insert_many", "(", "ESeq", "values", ")", ";", "protected", "abstract", "boolean", "insert_new_one", "(", "ETuple", "value", ")", ";", "protected", "abstract", "boolean", "insert_new_many", "(", "ESeq", "values", ")", ";", "protected", "abstract", "ESeq", "lookup", "(", "EObject", "key", ")", ";", "protected", "abstract", "ESeq", "match", "(", "EPattern", "matcher", ")", ";", "protected", "abstract", "ESeq", "match_object", "(", "EPattern", "matcher", ")", ";", "protected", "abstract", "void", "delete", "(", "EObject", "key", ")", ";", "protected", "abstract", "EInteger", "select_delete", "(", "EMatchSpec", "matcher", ")", ";", "protected", "void", "delete_all_objects", "(", ")", "{", "in_tx", "(", "new", "WithMap", "<", "Object", ">", "(", ")", "{", "@", "Override", "protected", "Object", "run", "(", "IPersistentMap", "map", ")", "{", "set", "(", "empty", ")", ";", "return", "null", ";", "}", "}", ")", ";", "}", "protected", "abstract", "EObject", "first", "(", ")", ";", "protected", "EObject", "next", "(", "EObject", "from", ")", "{", "IPersistentMap", "map", "=", "deref", "(", ")", ";", "if", "(", "map", "instanceof", "PersistentTreeMap", ")", "{", "PersistentTreeMap", "ptm", "=", "(", "PersistentTreeMap", ")", "map", ";", "ISeq", "seq", "=", "ptm", ".", "seqFrom", "(", "from", ",", "true", ")", ";", "if", "(", "seq", "==", "null", ")", "return", "Native", ".", "am_$end_of_table", ";", "seq", "=", "seq", ".", "next", "(", ")", ";", "if", "(", "seq", "==", "null", ")", "return", "Native", ".", "am_$end_of_table", ";", "IMapEntry", "ent", "=", "(", "IMapEntry", ")", "seq", ".", "first", "(", ")", ";", "if", "(", "ent", "==", "null", ")", "return", "Native", ".", "am_$end_of_table", ";", "return", "(", "EObject", ")", "ent", ".", "getKey", "(", ")", ";", "}", "else", "{", "for", "(", "ISeq", "seq", "=", "map", ".", "seq", "(", ")", ";", "seq", "!=", "null", ";", "seq", "=", "seq", ".", "next", "(", ")", ")", "{", "IMapEntry", "ent", "=", "(", "IMapEntry", ")", "seq", ".", "first", "(", ")", ";", "if", "(", "ent", "==", "null", ")", "return", "Native", ".", "am_$end_of_table", ";", "EObject", "key", "=", "(", "EObject", ")", "ent", ".", "getKey", "(", ")", ";", "if", "(", "key", ".", "equalsExactly", "(", "from", ")", ")", "{", "seq", "=", "seq", ".", "next", "(", ")", ";", "if", "(", "seq", "==", "null", ")", "return", "Native", ".", "am_$end_of_table", ";", "ent", "=", "(", "IMapEntry", ")", "seq", ".", "first", "(", ")", ";", "if", "(", "ent", "==", "null", ")", "return", "Native", ".", "am_$end_of_table", ";", "return", "(", "EObject", ")", "ent", ".", "getKey", "(", ")", ";", "}", "}", "return", "Native", ".", "am_$end_of_table", ";", "}", "}", "protected", "abstract", "void", "delete_object", "(", "ETuple", "obj", ")", ";", "public", "abstract", "ESeq", "slot", "(", ")", ";", "public", "abstract", "EObject", "select", "(", "EMatchSpec", "spec", ",", "int", "i", ")", ";", "public", "EObject", "info", "(", "EObject", "item", ")", "{", "if", "(", "item", "==", "Native", ".", "am_owner", ")", "{", "return", "owner_pid", "(", ")", ";", "}", "else", "if", "(", "item", "==", "Native", ".", "am_named_table", ")", "{", "return", "ERT", ".", "box", "(", "aname", "!=", "null", ")", ";", "}", "else", "if", "(", "item", "==", "Native", ".", "am_name", ")", "{", "return", "aname", ";", "}", "else", "if", "(", "item", "==", "Native", ".", "am_heir", ")", "{", "if", "(", "heirPID", "==", "null", ")", "return", "Native", ".", "am_none", ";", "else", "return", "heirPID", ";", "}", "else", "if", "(", "item", "==", "Native", ".", "am_size", ")", "{", "return", "ERT", ".", "box", "(", "size", "(", ")", ")", ";", "}", "else", "if", "(", "item", "==", "Native", ".", "am_memory", ")", "{", "return", "ERT", ".", "box", "(", "10", "*", "size", "(", ")", ")", ";", "}", "else", "if", "(", "item", "==", "Native", ".", "am_node", ")", "{", "return", "ERT", ".", "getLocalNode", "(", ")", ".", "node", "(", ")", ";", "}", "else", "if", "(", "item", "==", "Native", ".", "am_type", ")", "{", "return", "type", ";", "}", "else", "if", "(", "item", "==", "Native", ".", "am_keypos", ")", "{", "return", "ERT", ".", "box", "(", "keypos1", ")", ";", "}", "else", "if", "(", "item", "==", "Native", ".", "am_protection", ")", "{", "return", "access", ";", "}", "else", "if", "(", "item", "==", "Native", ".", "am_fixed", ")", "{", "return", "ERT", ".", "box", "(", "is_fixed", ")", ";", "}", "else", "if", "(", "item", "==", "Native", ".", "am_stats", ")", "{", "return", "ETuple", ".", "make", "(", "ERT", ".", "box", "(", "256", ")", ",", "ERT", ".", "box", "(", "7", ")", ",", "ERT", ".", "box", "(", "1", ")", ",", "ERT", ".", "box", "(", "1", ")", ",", "ERT", ".", "box", "(", "1", ")", ",", "ERT", ".", "box", "(", "10", ")", ")", ";", "}", "else", "if", "(", "item", "==", "Native", ".", "am_safe_fixed", ")", "{", "throw", "new", "NotImplemented", "(", ")", ";", "}", "else", "{", "return", "null", ";", "}", "}", "public", "void", "setopt", "(", "EObject", "head", ")", "{", "ETuple3", "tup", "=", "ETuple3", ".", "cast", "(", "head", ")", ";", "if", "(", "tup", "!=", "null", ")", "{", "EInternalPID", "pid", ";", "if", "(", "tup", ".", "elem1", "==", "Native", ".", "am_heir", "&&", "(", "pid", "=", "tup", ".", "elem2", ".", "testInternalPID", "(", ")", ")", "!=", "null", ")", "{", "if", "(", "!", "pid", ".", "is_alive", "(", ")", ")", "{", "this", ".", "heirPID", "=", "null", ";", "this", ".", "heirData", "=", "ERT", ".", "NIL", ";", "return", ";", "}", "EInternalPID", "old", "=", "this", ".", "heirPID", ";", "this", ".", "heirData", "=", "tup", ".", "elem3", ";", "this", ".", "heirPID", "=", "pid", ";", "pid", ".", "add_exit_hook", "(", "this", ")", ";", "if", "(", "old", "!=", "null", ")", "{", "old", ".", "remove_exit_hook", "(", "this", ")", ";", "}", "return", ";", "}", "}", "ETuple2", "tup2", "=", "ETuple2", ".", "cast", "(", "head", ")", ";", "if", "(", "tup2", "!=", "null", ")", "{", "if", "(", "tup2", ".", "elem1", "==", "Native", ".", "am_protection", ")", "{", "EObject", "mode", "=", "tup2", ".", "elem2", ";", "if", "(", "mode", "==", "Native", ".", "am_private", "||", "mode", "==", "Native", ".", "am_public", "||", "mode", "==", "Native", ".", "am_protected", ")", "{", "this", ".", "access", "=", "(", "EAtom", ")", "mode", ";", "return", ";", "}", "}", "else", "if", "(", "tup2", ".", "elem1", "==", "Native", ".", "am_heir", "&&", "tup2", ".", "elem2", "==", "Native", ".", "am_none", ")", "{", "EInternalPID", "old", "=", "this", ".", "heirPID", ";", "this", ".", "heirPID", "=", "null", ";", "this", ".", "heirData", "=", "ERT", ".", "NIL", ";", "if", "(", "old", "!=", "null", ")", "{", "old", ".", "remove_exit_hook", "(", "this", ")", ";", "}", "}", "}", "throw", "ERT", ".", "badarg", "(", "tid", ",", "head", ")", ";", "}", "protected", "abstract", "EAtom", "member", "(", "EObject", "key", ")", ";", "}", "</s>" ]
7,798
[ "<s>", "package", "erjang", ".", "m", ".", "ets", ";", "import", "erjang", ".", "EObject", ";", "interface", "ISelectContinuation", "{", "EObject", "select", "(", ")", ";", "}", "</s>" ]
7,799
[ "<s>", "package", "erjang", ".", "m", ".", "ets", ";", "import", "java", ".", "util", ".", "Collection", ";", "import", "java", ".", "util", ".", "HashSet", ";", "import", "java", ".", "util", ".", "Map", ";", "import", "java", ".", "util", ".", "Set", ";", "import", "java", ".", "util", ".", "SortedSet", ";", "import", "java", ".", "util", ".", "TreeSet", ";", "import", "java", ".", "util", ".", "regex", ".", "Pattern", ";", "import", "com", ".", "trifork", ".", "clj_ds", ".", "ISeq", ";", "import", "erjang", ".", "EAtom", ";", "import", "erjang", ".", "EBitString", ";", "import", "erjang", ".", "ECons", ";", "import", "erjang", ".", "EFun", ";", "import", "erjang", ".", "EList", ";", "import", "erjang", ".", "ENumber", ";", "import", "erjang", ".", "EObject", ";", "import", "erjang", ".", "EPID", ";", "import", "erjang", ".", "EPort", ";", "import", "erjang", ".", "ERT", ";", "import", "erjang", ".", "ERef", ";", "import", "erjang", ".", "ESeq", ";", "import", "erjang", ".", "ETuple", ";", "public", "class", "EPattern", "{", "ETermPattern", "matcher", ";", "private", "final", "EObject", "spec", ";", "private", "Integer", "[", "]", "out_vars", ";", "private", "final", "int", "keyidx", ";", "@", "Override", "public", "String", "toString", "(", ")", "{", "return", "\"\"", "+", "keyidx", "+", "\";\"", "+", "spec", ".", "toString", "(", ")", "+", "\">\"", ";", "}", "public", "EPattern", "(", "int", "keyidx", ",", "EObject", "spec", ")", "{", "this", ".", "keyidx", "=", "keyidx", ";", "this", ".", "spec", "=", "spec", ";", "SortedSet", "<", "Integer", ">", "out", "=", "new", "TreeSet", "<", "Integer", ">", "(", ")", ";", "matcher", "=", "spec", ".", "compileMatch", "(", "out", ")", ";", "this", ".", "out_vars", "=", "out", ".", "toArray", "(", "new", "Integer", "[", "out", ".", "size", "(", ")", "]", ")", ";", "}", "ESeq", "match_members", "(", "ESeq", "out", ",", "Collection", "<", "ETuple", ">", "in", ")", "{", "for", "(", "EObject", "elm", ":", "in", ")", "{", "EMatchContext", "res", "=", "new", "EMatchContext", "(", "out_vars", ",", "elm", ")", ";", "if", "(", "elm", ".", "match", "(", "matcher", ",", "res", ")", ")", "{", "out", "=", "out", ".", "cons", "(", "elm", ")", ";", "}", "}", "return", "out", ";", "}", "ESeq", "match", "(", "ESeq", "out", ",", "Map", "<", "EObject", ",", "ETuple", ">", "in", ")", "{", "for", "(", "ETuple", "elm", ":", "in", ".", "values", "(", ")", ")", "{", "ETuple", "val", "=", "elm", ".", "testTuple", "(", ")", ";", "EMatchContext", "res", "=", "new", "EMatchContext", "(", "out_vars", ",", "val", ")", ";", "if", "(", "matcher", ".", "match", "(", "val", ",", "res", ")", ")", "{", "out", "=", "out", ".", "cons", "(", "res", ".", "makeList", "(", ")", ")", ";", "}", "}", "return", "out", ";", "}", "ESeq", "match_members", "(", "ESeq", "out", ",", "Map", "<", "EObject", ",", "ETuple", ">", "in", ")", "{", "for", "(", "ETuple", "elm", ":", "in", ".", "values", "(", ")", ")", "{", "EMatchContext", "res", "=", "new", "EMatchContext", "(", "out_vars", ",", "elm", ")", ";", "if", "(", "matcher", ".", "match", "(", "elm", ",", "res", ")", ")", "{", "out", "=", "out", ".", "cons", "(", "elm", ")", ";", "}", "}", "return", "out", ";", "}", "ESeq", "match_members", "(", "ESeq", "out", ",", "ISeq", "in", ")", "{", "while", "(", "in", "!=", "null", ")", "{", "ETuple", "elm", "=", "(", "ETuple", ")", "in", ".", "first", "(", ")", ";", "if", "(", "elm", "==", "null", ")", "break", ";", "EMatchContext", "res", "=", "new", "EMatchContext", "(", "out_vars", ",", "elm", ")", ";", "if", "(", "matcher", ".", "match", "(", "elm", ",", "res", ")", ")", "{", "out", "=", "out", ".", "cons", "(", "elm", ")", ";", "}", "in", "=", "in", ".", "next", "(", ")", ";", "}", "return", "out", ";", "}", "ESeq", "match_vars", "(", "ESeq", "out", ",", "ISeq", "in", ")", "{", "while", "(", "in", "!=", "null", ")", "{", "ETuple", "elm", "=", "(", "ETuple", ")", "in", ".", "first", "(", ")", ";", "if", "(", "elm", "==", "null", ")", "break", ";", "EMatchContext", "res", "=", "new", "EMatchContext", "(", "out_vars", ",", "elm", ")", ";", "if", "(", "matcher", ".", "match", "(", "elm", ",", "res", ")", ")", "{", "out", "=", "out", ".", "cons", "(", "res", ".", "makeList", "(", ")", ")", ";", "}", "in", "=", "in", ".", "next", "(", ")", ";", "}", "return", "out", ";", "}", "public", "static", "EPattern", "compile", "(", "int", "keyidx", ",", "ETuple", "spec", ")", "{", "return", "new", "EPattern", "(", "keyidx", ",", "spec", ")", ";", "}", "static", "class", "AnyPattern", "extends", "ETermPattern", "{", "public", "boolean", "match", "(", "ETuple", "t", ",", "EMatchContext", "r", ")", "{", "return", "true", ";", "}", "public", "boolean", "match", "(", "ENumber", "n", ",", "EMatchContext", "r", ")", "{", "return", "true", ";", "}", "public", "boolean", "match", "(", "EAtom", "a", ",", "EMatchContext", "r", ")", "{", "return", "true", ";", "}", "public", "boolean", "match", "(", "ECons", "c", ",", "EMatchContext", "r", ")", "{", "return", "true", ";", "}", "public", "boolean", "match", "(", "EPID", "p", ",", "EMatchContext", "r", ")", "{", "return", "true", ";", "}", "public", "boolean", "match", "(", "EPort", "p", ",", "EMatchContext", "r", ")", "{", "return", "true", ";", "}", "public", "boolean", "match", "(", "EBitString", "bs", ",", "EMatchContext", "r", ")", "{", "return", "true", ";", "}", "}", "static", "class", "VarPattern", "extends", "ETermPattern", "{", "private", "Integer", "name", ";", "private", "boolean", "free", ";", "public", "VarPattern", "(", "int", "idx1", ",", "Set", "<", "Integer", ">", "out", ")", "{", "this", ".", "name", "=", "idx1", ";", "if", "(", "this", ".", "free", "=", "!", "out", ".", "contains", "(", "this", ".", "name", ")", ")", "{", "out", ".", "add", "(", "this", ".", "name", ")", ";", "}", "}", "public", "boolean", "match", "(", "ETuple", "t", ",", "EMatchContext", "r", ")", "{", "if", "(", "free", ")", "{", "r", ".", "vars", ".", "put", "(", "name", ",", "t", ")", ";", "return", "true", ";", "}", "else", "{", "return", "t", ".", "equalsExactly", "(", "r", ".", "vars", ".", "get", "(", "name", ")", ")", ";", "}", "}", "public", "boolean", "match", "(", "ENumber", "t", ",", "EMatchContext", "r", ")", "{", "if", "(", "free", ")", "{", "r", ".", "vars", ".", "put", "(", "name", ",", "t", ")", ";", "return", "true", ";", "}", "else", "{", "return", "t", ".", "equalsExactly", "(", "r", ".", "vars", ".", "get", "(", "name", ")", ")", ";", "}", "}", "public", "boolean", "match", "(", "EAtom", "t", ",", "EMatchContext", "r", ")", "{", "if", "(", "free", ")", "{", "r", ".", "vars", ".", "put", "(", "name", ",", "t", ")", ";", "return", "true", ";", "}", "else", "{", "return", "t", ".", "equalsExactly", "(", "r", ".", "vars", ".", "get", "(", "name", ")", ")", ";", "}", "}", "public", "boolean", "match", "(", "EFun", "fu", ",", "EMatchContext", "r", ")", "{", "if", "(", "free", ")", "{", "r", ".", "vars", ".", "put", "(", "name", ",", "fu", ")", ";", "return", "true", ";", "}", "else", "{", "return", "fu", ".", "equalsExactly", "(", "r", ".", "vars", ".", "get", "(", "name", ")", ")", ";", "}", "}", "public", "boolean", "match", "(", "ERef", "fu", ",", "EMatchContext", "r", ")", "{", "if", "(", "free", ")", "{", "r", ".", "vars", ".", "put", "(", "name", ",", "fu", ")", ";", "return", "true", ";", "}", "else", "{", "return", "fu", ".", "equalsExactly", "(", "r", ".", "vars", ".", "get", "(", "name", ")", ")", ";", "}", "}", "public", "boolean", "match", "(", "ECons", "t", ",", "EMatchContext", "r", ")", "{", "if", "(", "free", ")", "{", "r", ".", "vars", ".", "put", "(", "name", ",", "t", ")", ";", "return", "true", ";", "}", "else", "{", "return", "t", ".", "equalsExactly", "(", "r", ".", "vars", ".", "get", "(", "name", ")", ")", ";", "}", "}", "public", "boolean", "match", "(", "EPID", "t", ",", "EMatchContext", "r", ")", "{", "if", "(", "free", ")", "{", "r", ".", "vars", ".", "put", "(", "name", ",", "t", ")", ";", "return", "true", ";", "}", "else", "{", "return", "t", ".", "equalsExactly", "(", "r", ".", "vars", ".", "get", "(", "name", ")", ")", ";", "}", "}", "public", "boolean", "match", "(", "EPort", "t", ",", "EMatchContext", "r", ")", "{", "if", "(", "free", ")", "{", "r", ".", "vars", ".", "put", "(", "name", ",", "t", ")", ";", "return", "true", ";", "}", "else", "{", "return", "t", ".", "equalsExactly", "(", "r", ".", "vars", ".", "get", "(", "name", ")", ")", ";", "}", "}", "public", "boolean", "match", "(", "EBitString", "t", ",", "EMatchContext", "r", ")", "{", "if", "(", "free", ")", "{", "r", ".", "vars", ".", "put", "(", "name", ",", "t", ")", ";", "return", "true", ";", "}", "else", "{", "return", "t", ".", "equalsExactly", "(", "r", ".", "vars", ".", "get", "(", "name", ")", ")", ";", "}", "}", "}", "static", "class", "TuplePattern", "extends", "ETermPattern", "{", "int", "arity", ";", "ETermPattern", "[", "]", "elems", ";", "public", "TuplePattern", "(", "ETuple", "tup", ",", "Set", "<", "Integer", ">", "out", ")", "{", "arity", "=", "tup", ".", "arity", "(", ")", ";", "elems", "=", "new", "ETermPattern", "[", "arity", "]", ";", "for", "(", "int", "idx1", "=", "1", ";", "idx1", "<=", "arity", ";", "idx1", "++", ")", "{", "elems", "[", "idx1", "-", "1", "]", "=", "tup", ".", "elm", "(", "idx1", ")", ".", "compileMatch", "(", "out", ")", ";", "}", "}", "public", "boolean", "match", "(", "EObject", "elm", ",", "EMatchContext", "res", ")", "{", "ETuple", "tup", ";", "if", "(", "(", "tup", "=", "elm", ".", "testTuple", "(", ")", ")", "==", "null", ")", "return", "false", ";", "return", "match", "(", "tup", ",", "res", ")", ";", "}", "public", "boolean", "match", "(", "ETuple", "t", ",", "EMatchContext", "r", ")", "{", "if", "(", "t", ".", "arity", "(", ")", "!=", "arity", ")", "return", "false", ";", "for", "(", "int", "idx1", "=", "1", ";", "idx1", "<", "elems", ".", "length", "+", "1", ";", "idx1", "++", ")", "{", "if", "(", "!", "t", ".", "elm", "(", "idx1", ")", ".", "match", "(", "elems", "[", "idx1", "-", "1", "]", ",", "r", ")", ")", "return", "false", ";", "}", "return", "true", ";", "}", "}", "static", "class", "NilPattern", "extends", "ETermPattern", "{", "@", "Override", "public", "boolean", "match", "(", "ECons", "c", ",", "EMatchContext", "r", ")", "{", "return", "c", ".", "isNil", "(", ")", ";", "}", "}", "static", "class", "ConsPattern", "extends", "ETermPattern", "{", "ETermPattern", "head", ",", "tail", ";", "public", "ConsPattern", "(", "ECons", "cons", ",", "Set", "<", "Integer", ">", "out", ")", "{", "head", "=", "cons", ".", "head", "(", ")", ".", "compileMatch", "(", "out", ")", ";", "tail", "=", "cons", ".", "tail", "(", ")", ".", "compileMatch", "(", "out", ")", ";", "}", "public", "boolean", "match", "(", "ECons", "c", ",", "EMatchContext", "r", ")", "{", "return", "(", "!", "c", ".", "isNil", "(", ")", ")", "&&", "c", ".", "head", "(", ")", ".", "match", "(", "head", ",", "r", ")", "&&", "c", ".", "tail", "(", ")", ".", "match", "(", "tail", ",", "r", ")", ";", "}", "}", "static", "class", "ValuePattern", "extends", "ETermPattern", "{", "final", "EObject", "value", ";", "public", "ValuePattern", "(", "EObject", "val", ")", "{", "this", ".", "value", "=", "val", ";", "}", "public", "boolean", "match", "(", "EPID", "pid", ",", "EMatchContext", "r", ")", "{", "return", "pid", ".", "equalsExactly", "(", "value", ")", ";", "}", "public", "boolean", "match", "(", "ERef", "ref", ",", "EMatchContext", "r", ")", "{", "return", "ref", ".", "equalsExactly", "(", "value", ")", ";", "}", "public", "boolean", "match", "(", "EPort", "port", ",", "EMatchContext", "r", ")", "{", "return", "port", ".", "equalsExactly", "(", "value", ")", ";", "}", "public", "boolean", "match", "(", "EAtom", "port", ",", "EMatchContext", "r", ")", "{", "return", "port", ".", "equalsExactly", "(", "value", ")", ";", "}", "public", "boolean", "match", "(", "EFun", "fu", ",", "EMatchContext", "r", ")", "{", "return", "fu", ".", "equalsExactly", "(", "value", ")", ";", "}", "public", "boolean", "match", "(", "EBitString", "port", ",", "EMatchContext", "r", ")", "{", "return", "port", ".", "equalsExactly", "(", "value", ")", ";", "}", "public", "boolean", "match", "(", "ENumber", "num", ",", "EMatchContext", "r", ")", "{", "return", "num", ".", "equalsExactly", "(", "value", ")", ";", "}", "public", "boolean", "match", "(", "ETuple", "t", ",", "EMatchContext", "r", ")", "{", "return", "t", ".", "equalsExactly", "(", "value", ")", ";", "}", "@", "Override", "public", "boolean", "match", "(", "ECons", "c", ",", "EMatchContext", "r", ")", "{", "return", "c", ".", "equalsExactly", "(", "value", ")", ";", "}", "}", "public", "static", "ETermPattern", "compilePattern", "(", "ETuple", "tup", ",", "Set", "<", "Integer", ">", "out", ")", "{", "TuplePattern", "tp", "=", "new", "TuplePattern", "(", "tup", ",", "out", ")", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "tp", ".", "elems", ".", "length", ";", "i", "++", ")", "{", "if", "(", "!", "(", "tp", ".", "elems", "[", "i", "]", "instanceof", "ValuePattern", ")", ")", "{", "return", "tp", ";", "}", "}", "return", "new", "ValuePattern", "(", "tup", ")", ";", "}", "public", "static", "ETermPattern", "compilePattern", "(", "EObject", "epid", ",", "Set", "<", "Integer", ">", "out", ")", "{", "return", "new", "ValuePattern", "(", "epid", ")", ";", "}", "public", "static", "ETermPattern", "compilePattern", "(", "ECons", "cons", ",", "Set", "<", "Integer", ">", "out", ")", "{", "if", "(", "cons", ".", "isNil", "(", ")", ")", "{", "return", "new", "NilPattern", "(", ")", ";", "}", "else", "{", "return", "new", "ConsPattern", "(", "cons", ",", "out", ")", ";", "}", "}", "static", "Pattern", "VAR", "=", "Pattern", ".", "compile", "(", "\"^\\\\$[0-9]+$\"", ")", ";", "static", "EAtom", "am_ANY", "=", "EAtom", ".", "intern", "(", "\"_\"", ")", ";", "public", "static", "ETermPattern", "compilePattern", "(", "EAtom", "am", ",", "Set", "<", "Integer", ">", "out", ")", "{", "String", "name", "=", "am", ".", "getName", "(", ")", ";", "if", "(", "VAR", ".", "matcher", "(", "name", ")", ".", "matches", "(", ")", ")", "{", "int", "idx1", "=", "Integer", ".", "parseInt", "(", "name", ".", "substring", "(", "1", ")", ")", ";", "return", "new", "VarPattern", "(", "idx1", ",", "out", ")", ";", "}", "else", "if", "(", "am", "==", "am_ANY", ")", "{", "return", "new", "AnyPattern", "(", ")", ";", "}", "else", "{", "return", "new", "ValuePattern", "(", "am", ")", ";", "}", "}", "public", "EObject", "getKey", "(", "int", "keypos1", ")", "{", "if", "(", "matcher", "instanceof", "TuplePattern", ")", "{", "TuplePattern", "tm", "=", "(", "TuplePattern", ")", "matcher", ";", "if", "(", "keypos1", "<", "1", "||", "keypos1", ">", "tm", ".", "elems", ".", "length", ")", "{", "return", "null", ";", "}", "ETermPattern", "m", "=", "tm", ".", "elems", "[", "keypos1", "-", "1", "]", ";", "if", "(", "m", "instanceof", "ValuePattern", ")", "{", "ValuePattern", "vm", "=", "(", "ValuePattern", ")", "m", ";", "return", "vm", ".", "value", ";", "}", "}", "else", "if", "(", "matcher", "instanceof", "ValuePattern", ")", "{", "ValuePattern", "vp", "=", "(", "ValuePattern", ")", "matcher", ";", "if", "(", "vp", ".", "value", "instanceof", "ETuple", ")", "{", "ETuple", "et", "=", "(", "ETuple", ")", "vp", ".", "value", ";", "if", "(", "keypos1", "<", "1", "||", "keypos1", ">", "et", ".", "arity", "(", ")", ")", "return", "null", ";", "return", "et", ".", "elm", "(", "keypos1", ")", ";", "}", "}", "return", "null", ";", "}", "ESeq", "match", "(", "ESeq", "out", ",", "ETuple", "val", ")", "{", "EMatchContext", "res", "=", "new", "EMatchContext", "(", "out_vars", ",", "val", ")", ";", "if", "(", "matcher", ".", "match", "(", "val", ",", "res", ")", ")", "{", "out", "=", "out", ".", "cons", "(", "res", ".", "makeList", "(", ")", ")", ";", "}", "return", "out", ";", "}", "ESeq", "match_members", "(", "ESeq", "out", ",", "ETuple", "val", ")", "{", "EMatchContext", "res", "=", "new", "EMatchContext", "(", "out_vars", ",", "val", ")", ";", "if", "(", "matcher", ".", "match", "(", "val", ",", "res", ")", ")", "{", "out", "=", "out", ".", "cons", "(", "val", ")", ";", "}", "return", "out", ";", "}", "boolean", "match", "(", "ETuple", "val", ")", "{", "EMatchContext", "res", "=", "new", "EMatchContext", "(", "out_vars", ",", "val", ")", ";", "return", "matcher", ".", "match", "(", "val", ",", "res", ")", ";", "}", "}", "</s>" ]