text
stringlengths 30
1.67M
|
|---|
<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 "<STR_LIT>" + file . getName ( ) ; } } </s>
|
<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 "<STR_LIT>" + file . getName ( ) ; } @ Override public int countTestCases ( ) { return <NUM_LIT: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>
|
<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 "<STR_LIT>" + file . getName ( ) + "<STR_LIT>" ; } } </s>
|
<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 ( "<STR_LIT>" ) ; 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 ( "<STR_LIT>" ) ; } catch ( NoSuchElementException t ) { } } public void testEInt ( ) throws Exception { EInteger num = ESmall . make ( <NUM_LIT> ) ; 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 ( "<STR_LIT>" ) ; } catch ( NoSuchElementException t ) { } } public void testSeqWithSingleNil ( ) throws Exception { ESeq seq = ESeq . fromArray ( new EObject [ ] { ERT . NIL } ) ; assertEquals ( <NUM_LIT: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 ( "<STR_LIT>" ) ; } catch ( NoSuchElementException t ) { } } public void testSeqWithTwoNils ( ) throws Exception { ESeq seq = ESeq . fromArray ( new EObject [ ] { ERT . NIL , ERT . NIL } ) ; assertEquals ( <NUM_LIT: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 ( "<STR_LIT>" ) ; } catch ( NoSuchElementException t ) { } } public void testSeqWithSingleObject ( ) throws Exception { EObject first = EString . fromString ( "<STR_LIT:Hello>" ) ; ESeq seq = ESeq . fromArray ( new EObject [ ] { first } ) ; assertEquals ( <NUM_LIT: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 ( "<STR_LIT>" ) ; } catch ( NoSuchElementException t ) { } } public void testSeqWithTwoObjects ( ) throws Exception { EObject first = EString . fromString ( "<STR_LIT:Hello>" ) ; EObject second = EString . fromString ( "<STR_LIT>" ) ; ESeq seq = ESeq . fromArray ( new EObject [ ] { first , second } ) ; assertEquals ( <NUM_LIT: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 ( "<STR_LIT>" ) ; } catch ( NoSuchElementException t ) { } } public void testSeqWithThreeObjects ( ) throws Exception { EObject first = EString . fromString ( "<STR_LIT:Hello>" ) ; EObject second = EString . fromString ( "<STR_LIT>" ) ; EObject third = ESmall . make ( <NUM_LIT> ) ; ESeq seq = ESeq . fromArray ( new EObject [ ] { first , second , third } ) ; assertEquals ( <NUM_LIT: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 ( "<STR_LIT>" ) ; } catch ( NoSuchElementException t ) { } } } </s>
|
<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 [ <NUM_LIT> ] ; public OutputCollectorThread ( InputStream in ) { this . in = in ; } @ Override public void run ( ) { try { int len ; while ( ( len = in . read ( buf ) ) > <NUM_LIT:0> ) { acc . write ( buf , <NUM_LIT:0> , len ) ; } } catch ( IOException ioe ) { System . err . println ( "<STR_LIT>" + ioe ) ; try { in . close ( ) ; } catch ( IOException ioe2 ) { } } } public byte [ ] getResult ( ) { return acc . toByteArray ( ) ; } } </s>
|
<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 = "<STR_LIT>" ; static final String ERL_NODE_NAME = "<STR_LIT>" ; static final String THIS_NODE_NAME = "<STR_LIT>" ; static final EObject POSITIVE_RESULT = ETuple . make ( EAtom . intern ( "<STR_LIT>" ) , EAtom . intern ( "<STR_LIT:true>" ) ) ; public TestCaseWithErlangNodeAccess ( String name ) { super ( name ) ; } @ Override public String toString ( ) { return "<STR_LIT>" + file . getName ( ) + "<STR_LIT>" ; } @ Override public int countTestCases ( ) { return <NUM_LIT: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 + "<STR_LIT>" ) ; TestUtil . erl_compile ( file . getAbsolutePath ( ) ) ; Process erl_process = TestUtil . startErlProcess ( ERL_NODE_NAME , hostName ) ; String [ ] rawOutputArray = new String [ <NUM_LIT:1> ] ; EObject output = do_run ( file , TestUtil . get_ej ( ) , ERL_NODE_NAME , hostName , rawOutputArray ) ; rawOutput = rawOutputArray [ <NUM_LIT: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 , "<STR_LIT>" , TestUtil . nodeNameSwitch ( hostName ) , THIS_NODE_NAME + "<STR_LIT:@>" + hostName , "<STR_LIT>" , erlNodeName , "<STR_LIT>" , TestUtil . TEST_BEAM_DIR , "<STR_LIT>" , TestUtil . TRIQ_HOME + File . separator + "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:false>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , moduleName , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" } ; byte [ ] bin = TestUtil . execGetBinaryOutput ( cmd ) ; outputDest [ <NUM_LIT:0> ] = EString . make ( bin , <NUM_LIT:0> , bin . length ) . stringValue ( ) ; return processOutput ( bin ) ; } } </s>
|
<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 ( "<STR_LIT>" ) ; static final String ERTS_VSN = ErjangConfig . getString ( "<STR_LIT>" ) ; static final String ERLC_PRG = OTP_HOME + File . separator + "<STR_LIT>" + File . separator + "<STR_LIT>" ; static final String ERL_PRG = OTP_HOME + File . separator + "<STR_LIT>" + File . separator + "<STR_LIT>" ; static final String EJ_PRG = "<STR_LIT>" ; static final String TEST_BEAM_DIR = "<STR_LIT>" ; static final String TRIQ_HOME = ErjangConfig . getString ( "<STR_LIT>" ) ; public static String get_ej ( ) { String ej = EJ_PRG ; if ( System . getProperty ( "<STR_LIT>" ) . startsWith ( "<STR_LIT>" ) ) { ej = "<STR_LIT>" ; } return ej ; } public static void erl_compile ( String fileName ) throws Exception { execGetOutput ( new String [ ] { ERLC_PRG , "<STR_LIT>" , TEST_BEAM_DIR , "<STR_LIT>" , TRIQ_HOME + File . separator + "<STR_LIT>" , "<STR_LIT>" , TRIQ_HOME + File . separator + "<STR_LIT>" , 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 != <NUM_LIT:0> ) { System . err . println ( "<STR_LIT>" + exitCode + "<STR_LIT>" + cmd [ <NUM_LIT:0> ] ) ; System . err . println ( "<STR_LIT>" + new String ( errThread . getResult ( ) ) + "<STR_LIT>" + new String ( outThread . getResult ( ) ) ) ; } assert ( exitCode == <NUM_LIT:0> ) ; return Arrays . copyOf ( outThread . getResult ( ) , outThread . getResult ( ) . length ) ; } public static String trimExtension ( String fileName ) { int i = fileName . lastIndexOf ( '<CHAR_LIT:.>' ) ; if ( i >= <NUM_LIT:0> ) fileName = fileName . substring ( <NUM_LIT:0> , i ) ; return fileName ; } public static Process startErlProcess ( String nodeName , String hostName ) throws IOException { String [ ] cmd = new String [ ] { ERL_PRG , "<STR_LIT>" , nodeNameSwitch ( hostName ) , nodeName + "<STR_LIT:@>" + hostName , "<STR_LIT>" , TestUtil . TEST_BEAM_DIR , "<STR_LIT>" , TRIQ_HOME + File . separator + "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:false>" , "<STR_LIT>" } ; 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 ( '<CHAR_LIT:.>' ) >= <NUM_LIT:0> ) ? "<STR_LIT>" : "<STR_LIT>" ; } } </s>
|
<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 = "<STR_LIT>" ; public AbstractTestCaseWithoutErlangNodeAccess ( String name ) { super ( name ) ; } public AbstractTestCaseWithoutErlangNodeAccess ( File file ) { super ( file ) ; } @ Override public abstract String toString ( ) ; @ Override public int countTestCases ( ) { return <NUM_LIT:1> ; } @ Override public void run ( TestResult result ) { result . startTest ( this ) ; try { TestUtil . erl_compile ( RUN_WRAPPER_HOME + File . separator + "<STR_LIT>" ) ; 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 , "<STR_LIT>" , "<STR_LIT>" , TestUtil . TEST_BEAM_DIR , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:false>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , moduleName , "<STR_LIT:10>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" } ; byte [ ] bin = TestUtil . execGetBinaryOutput ( cmd ) ; return processOutput ( bin ) ; } } </s>
|
<s> package erjang ; import java . math . BigInteger ; import junit . framework . TestCase ; public class ENTest extends TestCase { public void testAdd ( ) { tryAdd ( <NUM_LIT:1> , <NUM_LIT:1> ) ; tryAdd ( Integer . MIN_VALUE , <NUM_LIT:0> ) ; tryAdd ( Integer . MIN_VALUE , - <NUM_LIT:1> ) ; tryAdd ( Integer . MIN_VALUE , Integer . MIN_VALUE ) ; tryAdd ( Integer . MAX_VALUE , Integer . MAX_VALUE ) ; tryAdd ( Integer . MAX_VALUE , <NUM_LIT:0> ) ; tryAdd ( Integer . MAX_VALUE , - <NUM_LIT:1> ) ; tryAdd ( Integer . MAX_VALUE , <NUM_LIT:1> ) ; } public void testMult ( ) { tryMult ( <NUM_LIT:1> , <NUM_LIT:1> ) ; tryMult ( Integer . MIN_VALUE , <NUM_LIT:0> ) ; tryMult ( Integer . MIN_VALUE , - <NUM_LIT:1> ) ; tryMult ( Integer . MIN_VALUE , Integer . MIN_VALUE ) ; tryMult ( Integer . MAX_VALUE , Integer . MAX_VALUE ) ; tryMult ( Integer . MAX_VALUE , <NUM_LIT:0> ) ; tryMult ( Integer . MAX_VALUE , - <NUM_LIT:1> ) ; tryMult ( Integer . MAX_VALUE , <NUM_LIT: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 ) < <NUM_LIT:0> ) return new EBig ( res ) ; if ( res . compareTo ( INT_MAX ) > <NUM_LIT:0> ) return new EBig ( res ) ; assertEquals ( res , BigInteger . valueOf ( res . intValue ( ) ) ) ; return new ESmall ( res . intValue ( ) ) ; } } </s>
|
<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 ( "<STR_LIT>" ) ; public static Test suite ( ) { TestSuite suite = new TestSuite ( "<STR_LIT>" ) ; TestSuite otpCompileSuite = new TestSuite ( "<STR_LIT>" ) ; suite . addTest ( otpCompileSuite ) ; TestSuite coverageRunSuite = new TestSuite ( "<STR_LIT>" ) ; Map < File , List < File > > testsErl = new HashMap < File , List < File > > ( ) ; find_files ( testsErl , new File ( "<STR_LIT>" ) , "<STR_LIT>" ) ; 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 ( "<STR_LIT>" + clazz ) ; } } } } static void find_files ( Map < File , List < File > > tests , File dir , String ext ) { List < File > ts = null ; if ( ! dir . isDirectory ( ) ) throw new IllegalArgumentException ( "<STR_LIT>" + 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 ( "<STR_LIT>" + dir ) ; ts = new ArrayList < File > ( ) ; tests . put ( dir , ts ) ; } ts . add ( file ) ; } } } public static void main ( String [ ] args ) { if ( args . length == <NUM_LIT:0> ) { throw new IllegalArgumentException ( "<STR_LIT>" ) ; } Map < File , List < File > > testsOTP = new HashMap < File , List < File > > ( ) ; find_files ( testsOTP , new File ( OTP_HOME ) , "<STR_LIT>" ) ; generateTestClasses ( args [ <NUM_LIT:0> ] , testsOTP , TestCompileFile . class ) ; Map < File , List < File > > testsDet = new HashMap < File , List < File > > ( ) ; find_files ( testsDet , new File ( "<STR_LIT>" ) , "<STR_LIT>" ) ; generateTestClasses ( args [ <NUM_LIT:0> ] , testsDet , OfflineComparisonTestCase . class ) ; Map < File , List < File > > testsProp = new HashMap < File , List < File > > ( ) ; find_files ( testsProp , new File ( "<STR_LIT>" ) , "<STR_LIT>" ) ; generateTestClasses ( args [ <NUM_LIT:0> ] , testsProp , PropertyTestCase . class ) ; Map < File , List < File > > testsPropNode = new HashMap < File , List < File > > ( ) ; find_files ( testsPropNode , new File ( "<STR_LIT>" ) , "<STR_LIT>" ) ; generateTestClasses ( args [ <NUM_LIT: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 + "<STR_LIT>" ) ; System . out . println ( "<STR_LIT>" + 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>
|
<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 "<STR_LIT>" ; } protected static String getImports ( ) { StringBuffer s = new StringBuffer ( ) ; s . append ( "<STR_LIT>" ) ; s . append ( "<STR_LIT>" ) ; return s . toString ( ) ; } public static String classNameFor ( File file ) { String name = file . getName ( ) ; name = name . replace ( '<CHAR_LIT:.>' , '<CHAR_LIT:_>' ) ; name = name . replace ( '<CHAR_LIT:->' , '<CHAR_LIT:_>' ) ; return name + "<STR_LIT>" ; } protected static String getPath ( File file ) { String path = file . getAbsolutePath ( ) ; path = path . replace ( "<STR_LIT:\\>" , "<STR_LIT>" ) ; return path ; } protected static String getClassStart ( Class < ? extends AbstractErjangTestCase > clazz , String name ) { return "<STR_LIT>" + name + "<STR_LIT>" + clazz . getName ( ) + "<STR_LIT>" ; } protected static String getConstructor ( String name , String path ) { StringBuffer s = new StringBuffer ( ) ; s . append ( "<STR_LIT>" + name + "<STR_LIT>" ) ; s . append ( "<STR_LIT>" + path + "<STR_LIT>" ) ; s . append ( "<STR_LIT>" ) ; return s . toString ( ) ; } protected static String getSuite ( String name ) { StringBuffer s = new StringBuffer ( ) ; s . append ( "<STR_LIT>" ) ; s . append ( "<STR_LIT>" + name + "<STR_LIT>" ) ; s . append ( "<STR_LIT>" ) ; return s . toString ( ) ; } protected static String getClassEnd ( ) { return "<STR_LIT:}>" ; } } </s>
|
<s> package com . jcraft . jzlib ; final class Adler32 { static final private int BASE = <NUM_LIT> ; static final private int NMAX = <NUM_LIT> ; long adler32 ( long adler , byte [ ] buf , int index , int len ) { if ( buf == null ) { return <NUM_LIT:1L> ; } long s1 = adler & <NUM_LIT> ; long s2 = ( adler > > <NUM_LIT:16> ) & <NUM_LIT> ; int k ; while ( len > <NUM_LIT:0> ) { k = len < NMAX ? len : NMAX ; len -= k ; while ( k >= <NUM_LIT:16> ) { s1 += buf [ index ++ ] & <NUM_LIT> ; s2 += s1 ; s1 += buf [ index ++ ] & <NUM_LIT> ; s2 += s1 ; s1 += buf [ index ++ ] & <NUM_LIT> ; s2 += s1 ; s1 += buf [ index ++ ] & <NUM_LIT> ; s2 += s1 ; s1 += buf [ index ++ ] & <NUM_LIT> ; s2 += s1 ; s1 += buf [ index ++ ] & <NUM_LIT> ; s2 += s1 ; s1 += buf [ index ++ ] & <NUM_LIT> ; s2 += s1 ; s1 += buf [ index ++ ] & <NUM_LIT> ; s2 += s1 ; s1 += buf [ index ++ ] & <NUM_LIT> ; s2 += s1 ; s1 += buf [ index ++ ] & <NUM_LIT> ; s2 += s1 ; s1 += buf [ index ++ ] & <NUM_LIT> ; s2 += s1 ; s1 += buf [ index ++ ] & <NUM_LIT> ; s2 += s1 ; s1 += buf [ index ++ ] & <NUM_LIT> ; s2 += s1 ; s1 += buf [ index ++ ] & <NUM_LIT> ; s2 += s1 ; s1 += buf [ index ++ ] & <NUM_LIT> ; s2 += s1 ; s1 += buf [ index ++ ] & <NUM_LIT> ; s2 += s1 ; k -= <NUM_LIT:16> ; } if ( k != <NUM_LIT:0> ) { do { s1 += buf [ index ++ ] & <NUM_LIT> ; s2 += s1 ; } while ( -- k != <NUM_LIT:0> ) ; } s1 %= BASE ; s2 %= BASE ; } return ( s2 << <NUM_LIT:16> ) | s1 ; } } </s>
|
<s> package com . jcraft . jzlib ; public final class Deflate { static final private int MAX_MEM_LEVEL = <NUM_LIT:9> ; static final private int Z_DEFAULT_COMPRESSION = - <NUM_LIT:1> ; static final private int MAX_WBITS = <NUM_LIT:15> ; static final private int DEF_MEM_LEVEL = <NUM_LIT: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 = <NUM_LIT:0> ; static final private int FAST = <NUM_LIT:1> ; static final private int SLOW = <NUM_LIT:2> ; static final private Config [ ] config_table ; static { config_table = new Config [ <NUM_LIT:10> ] ; config_table [ <NUM_LIT:0> ] = new Config ( <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , STORED ) ; config_table [ <NUM_LIT:1> ] = new Config ( <NUM_LIT:4> , <NUM_LIT:4> , <NUM_LIT:8> , <NUM_LIT:4> , FAST ) ; config_table [ <NUM_LIT:2> ] = new Config ( <NUM_LIT:4> , <NUM_LIT:5> , <NUM_LIT:16> , <NUM_LIT:8> , FAST ) ; config_table [ <NUM_LIT:3> ] = new Config ( <NUM_LIT:4> , <NUM_LIT:6> , <NUM_LIT:32> , <NUM_LIT:32> , FAST ) ; config_table [ <NUM_LIT:4> ] = new Config ( <NUM_LIT:4> , <NUM_LIT:4> , <NUM_LIT:16> , <NUM_LIT:16> , SLOW ) ; config_table [ <NUM_LIT:5> ] = new Config ( <NUM_LIT:8> , <NUM_LIT:16> , <NUM_LIT:32> , <NUM_LIT:32> , SLOW ) ; config_table [ <NUM_LIT:6> ] = new Config ( <NUM_LIT:8> , <NUM_LIT:16> , <NUM_LIT> , <NUM_LIT> , SLOW ) ; config_table [ <NUM_LIT:7> ] = new Config ( <NUM_LIT:8> , <NUM_LIT:32> , <NUM_LIT> , <NUM_LIT> , SLOW ) ; config_table [ <NUM_LIT:8> ] = new Config ( <NUM_LIT:32> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , SLOW ) ; config_table [ <NUM_LIT:9> ] = new Config ( <NUM_LIT:32> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , SLOW ) ; } static final private String [ ] z_errmsg = { "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" } ; static final private int NeedMore = <NUM_LIT:0> ; static final private int BlockDone = <NUM_LIT:1> ; static final private int FinishStarted = <NUM_LIT:2> ; static final private int FinishDone = <NUM_LIT:3> ; static final private int PRESET_DICT = <NUM_LIT> ; static final private int Z_FILTERED = <NUM_LIT:1> ; static final private int Z_HUFFMAN_ONLY = <NUM_LIT:2> ; static final private int Z_DEFAULT_STRATEGY = <NUM_LIT:0> ; static final private int Z_NO_FLUSH = <NUM_LIT:0> ; static final private int Z_PARTIAL_FLUSH = <NUM_LIT:1> ; static final private int Z_SYNC_FLUSH = <NUM_LIT:2> ; static final private int Z_FULL_FLUSH = <NUM_LIT:3> ; static final private int Z_FINISH = <NUM_LIT:4> ; static final private int Z_OK = <NUM_LIT:0> ; static final private int Z_STREAM_END = <NUM_LIT:1> ; static final private int Z_NEED_DICT = <NUM_LIT:2> ; static final private int Z_ERRNO = - <NUM_LIT:1> ; static final private int Z_STREAM_ERROR = - <NUM_LIT:2> ; static final private int Z_DATA_ERROR = - <NUM_LIT:3> ; static final private int Z_MEM_ERROR = - <NUM_LIT:4> ; static final private int Z_BUF_ERROR = - <NUM_LIT:5> ; static final private int Z_VERSION_ERROR = - <NUM_LIT:6> ; static final private int INIT_STATE = <NUM_LIT> ; static final private int BUSY_STATE = <NUM_LIT> ; static final private int FINISH_STATE = <NUM_LIT> ; static final private int Z_DEFLATED = <NUM_LIT:8> ; static final private int STORED_BLOCK = <NUM_LIT:0> ; static final private int STATIC_TREES = <NUM_LIT:1> ; static final private int DYN_TREES = <NUM_LIT:2> ; static final private int Z_BINARY = <NUM_LIT:0> ; static final private int Z_ASCII = <NUM_LIT:1> ; static final private int Z_UNKNOWN = <NUM_LIT:2> ; static final private int Buf_size = <NUM_LIT:8> * <NUM_LIT:2> ; static final private int REP_3_6 = <NUM_LIT:16> ; static final private int REPZ_3_10 = <NUM_LIT> ; static final private int REPZ_11_138 = <NUM_LIT> ; static final private int MIN_MATCH = <NUM_LIT:3> ; static final private int MAX_MATCH = <NUM_LIT> ; static final private int MIN_LOOKAHEAD = ( MAX_MATCH + MIN_MATCH + <NUM_LIT:1> ) ; static final private int MAX_BITS = <NUM_LIT:15> ; static final private int D_CODES = <NUM_LIT:30> ; static final private int BL_CODES = <NUM_LIT> ; static final private int LENGTH_CODES = <NUM_LIT> ; static final private int LITERALS = <NUM_LIT> ; static final private int L_CODES = ( LITERALS + <NUM_LIT:1> + LENGTH_CODES ) ; static final private int HEAP_SIZE = ( <NUM_LIT:2> * L_CODES + <NUM_LIT:1> ) ; static final private int END_BLOCK = <NUM_LIT> ; 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 + <NUM_LIT:1> ] ; int [ ] heap = new int [ <NUM_LIT:2> * L_CODES + <NUM_LIT:1> ] ; int heap_len ; int heap_max ; byte [ ] depth = new byte [ <NUM_LIT:2> * L_CODES + <NUM_LIT: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 * <NUM_LIT:2> ] ; dyn_dtree = new short [ ( <NUM_LIT:2> * D_CODES + <NUM_LIT:1> ) * <NUM_LIT:2> ] ; bl_tree = new short [ ( <NUM_LIT:2> * BL_CODES + <NUM_LIT:1> ) * <NUM_LIT:2> ] ; } void lm_init ( ) { window_size = <NUM_LIT:2> * w_size ; head [ hash_size - <NUM_LIT:1> ] = <NUM_LIT:0> ; for ( int i = <NUM_LIT:0> ; i < hash_size - <NUM_LIT:1> ; i ++ ) { head [ i ] = <NUM_LIT: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 = <NUM_LIT:0> ; block_start = <NUM_LIT:0> ; lookahead = <NUM_LIT:0> ; match_length = prev_length = MIN_MATCH - <NUM_LIT:1> ; match_available = <NUM_LIT:0> ; ins_h = <NUM_LIT: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 = <NUM_LIT:0> ; bi_valid = <NUM_LIT:0> ; last_eob_len = <NUM_LIT:8> ; init_block ( ) ; } void init_block ( ) { for ( int i = <NUM_LIT:0> ; i < L_CODES ; i ++ ) dyn_ltree [ i * <NUM_LIT:2> ] = <NUM_LIT:0> ; for ( int i = <NUM_LIT:0> ; i < D_CODES ; i ++ ) dyn_dtree [ i * <NUM_LIT:2> ] = <NUM_LIT:0> ; for ( int i = <NUM_LIT:0> ; i < BL_CODES ; i ++ ) bl_tree [ i * <NUM_LIT:2> ] = <NUM_LIT:0> ; dyn_ltree [ END_BLOCK * <NUM_LIT:2> ] = <NUM_LIT:1> ; opt_len = static_len = <NUM_LIT:0> ; last_lit = matches = <NUM_LIT:0> ; } void pqdownheap ( short [ ] tree , int k ) { int v = heap [ k ] ; int j = k << <NUM_LIT:1> ; while ( j <= heap_len ) { if ( j < heap_len && smaller ( tree , heap [ j + <NUM_LIT:1> ] , heap [ j ] , depth ) ) { j ++ ; } if ( smaller ( tree , v , heap [ j ] , depth ) ) break ; heap [ k ] = heap [ j ] ; k = j ; j <<= <NUM_LIT:1> ; } heap [ k ] = v ; } static boolean smaller ( short [ ] tree , int n , int m , byte [ ] depth ) { short tn2 = tree [ n * <NUM_LIT:2> ] ; short tm2 = tree [ m * <NUM_LIT:2> ] ; return ( tn2 < tm2 || ( tn2 == tm2 && depth [ n ] <= depth [ m ] ) ) ; } void scan_tree ( short [ ] tree , int max_code ) { int n ; int prevlen = - <NUM_LIT:1> ; int curlen ; int nextlen = tree [ <NUM_LIT:0> * <NUM_LIT:2> + <NUM_LIT:1> ] ; int count = <NUM_LIT:0> ; int max_count = <NUM_LIT:7> ; int min_count = <NUM_LIT:4> ; if ( nextlen == <NUM_LIT:0> ) { max_count = <NUM_LIT> ; min_count = <NUM_LIT:3> ; } tree [ ( max_code + <NUM_LIT:1> ) * <NUM_LIT:2> + <NUM_LIT:1> ] = ( short ) <NUM_LIT> ; for ( n = <NUM_LIT:0> ; n <= max_code ; n ++ ) { curlen = nextlen ; nextlen = tree [ ( n + <NUM_LIT:1> ) * <NUM_LIT:2> + <NUM_LIT:1> ] ; if ( ++ count < max_count && curlen == nextlen ) { continue ; } else if ( count < min_count ) { bl_tree [ curlen * <NUM_LIT:2> ] += count ; } else if ( curlen != <NUM_LIT:0> ) { if ( curlen != prevlen ) bl_tree [ curlen * <NUM_LIT:2> ] ++ ; bl_tree [ REP_3_6 * <NUM_LIT:2> ] ++ ; } else if ( count <= <NUM_LIT:10> ) { bl_tree [ REPZ_3_10 * <NUM_LIT:2> ] ++ ; } else { bl_tree [ REPZ_11_138 * <NUM_LIT:2> ] ++ ; } count = <NUM_LIT:0> ; prevlen = curlen ; if ( nextlen == <NUM_LIT:0> ) { max_count = <NUM_LIT> ; min_count = <NUM_LIT:3> ; } else if ( curlen == nextlen ) { max_count = <NUM_LIT:6> ; min_count = <NUM_LIT:3> ; } else { max_count = <NUM_LIT:7> ; min_count = <NUM_LIT: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 - <NUM_LIT:1> ; max_blindex >= <NUM_LIT:3> ; max_blindex -- ) { if ( bl_tree [ Tree . bl_order [ max_blindex ] * <NUM_LIT:2> + <NUM_LIT:1> ] != <NUM_LIT:0> ) break ; } opt_len += <NUM_LIT:3> * ( max_blindex + <NUM_LIT:1> ) + <NUM_LIT:5> + <NUM_LIT:5> + <NUM_LIT:4> ; return max_blindex ; } void send_all_trees ( int lcodes , int dcodes , int blcodes ) { int rank ; send_bits ( lcodes - <NUM_LIT> , <NUM_LIT:5> ) ; send_bits ( dcodes - <NUM_LIT:1> , <NUM_LIT:5> ) ; send_bits ( blcodes - <NUM_LIT:4> , <NUM_LIT:4> ) ; for ( rank = <NUM_LIT:0> ; rank < blcodes ; rank ++ ) { send_bits ( bl_tree [ Tree . bl_order [ rank ] * <NUM_LIT:2> + <NUM_LIT:1> ] , <NUM_LIT:3> ) ; } send_tree ( dyn_ltree , lcodes - <NUM_LIT:1> ) ; send_tree ( dyn_dtree , dcodes - <NUM_LIT:1> ) ; } void send_tree ( short [ ] tree , int max_code ) { int n ; int prevlen = - <NUM_LIT:1> ; int curlen ; int nextlen = tree [ <NUM_LIT:0> * <NUM_LIT:2> + <NUM_LIT:1> ] ; int count = <NUM_LIT:0> ; int max_count = <NUM_LIT:7> ; int min_count = <NUM_LIT:4> ; if ( nextlen == <NUM_LIT:0> ) { max_count = <NUM_LIT> ; min_count = <NUM_LIT:3> ; } for ( n = <NUM_LIT:0> ; n <= max_code ; n ++ ) { curlen = nextlen ; nextlen = tree [ ( n + <NUM_LIT:1> ) * <NUM_LIT:2> + <NUM_LIT:1> ] ; if ( ++ count < max_count && curlen == nextlen ) { continue ; } else if ( count < min_count ) { do { send_code ( curlen , bl_tree ) ; } while ( -- count != <NUM_LIT:0> ) ; } else if ( curlen != <NUM_LIT:0> ) { if ( curlen != prevlen ) { send_code ( curlen , bl_tree ) ; count -- ; } send_code ( REP_3_6 , bl_tree ) ; send_bits ( count - <NUM_LIT:3> , <NUM_LIT:2> ) ; } else if ( count <= <NUM_LIT:10> ) { send_code ( REPZ_3_10 , bl_tree ) ; send_bits ( count - <NUM_LIT:3> , <NUM_LIT:3> ) ; } else { send_code ( REPZ_11_138 , bl_tree ) ; send_bits ( count - <NUM_LIT:11> , <NUM_LIT:7> ) ; } count = <NUM_LIT:0> ; prevlen = curlen ; if ( nextlen == <NUM_LIT:0> ) { max_count = <NUM_LIT> ; min_count = <NUM_LIT:3> ; } else if ( curlen == nextlen ) { max_count = <NUM_LIT:6> ; min_count = <NUM_LIT:3> ; } else { max_count = <NUM_LIT:7> ; min_count = <NUM_LIT: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 > > > <NUM_LIT:8> ) ) ; } final void putShortMSB ( int b ) { put_byte ( ( byte ) ( b > > <NUM_LIT:8> ) ) ; put_byte ( ( byte ) ( b ) ) ; } final void send_code ( int c , short [ ] tree ) { int c2 = c * <NUM_LIT:2> ; send_bits ( ( tree [ c2 ] & <NUM_LIT> ) , ( tree [ c2 + <NUM_LIT:1> ] & <NUM_LIT> ) ) ; } 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 ) & <NUM_LIT> ) ; put_short ( bi_buf ) ; bi_buf = ( short ) ( val > > > ( Buf_size - bi_valid ) ) ; bi_valid += len - Buf_size ; } else { bi_buf |= ( ( ( value ) << bi_valid ) & <NUM_LIT> ) ; bi_valid += len ; } } void _tr_align ( ) { send_bits ( STATIC_TREES << <NUM_LIT:1> , <NUM_LIT:3> ) ; send_code ( END_BLOCK , StaticTree . static_ltree ) ; bi_flush ( ) ; if ( <NUM_LIT:1> + last_eob_len + <NUM_LIT:10> - bi_valid < <NUM_LIT:9> ) { send_bits ( STATIC_TREES << <NUM_LIT:1> , <NUM_LIT:3> ) ; send_code ( END_BLOCK , StaticTree . static_ltree ) ; bi_flush ( ) ; } last_eob_len = <NUM_LIT:7> ; } boolean _tr_tally ( int dist , int lc ) { pending_buf [ d_buf + last_lit * <NUM_LIT:2> ] = ( byte ) ( dist > > > <NUM_LIT:8> ) ; pending_buf [ d_buf + last_lit * <NUM_LIT:2> + <NUM_LIT:1> ] = ( byte ) dist ; pending_buf [ l_buf + last_lit ] = ( byte ) lc ; last_lit ++ ; if ( dist == <NUM_LIT:0> ) { dyn_ltree [ lc * <NUM_LIT:2> ] ++ ; } else { matches ++ ; dist -- ; dyn_ltree [ ( Tree . _length_code [ lc ] + LITERALS + <NUM_LIT:1> ) * <NUM_LIT:2> ] ++ ; dyn_dtree [ Tree . d_code ( dist ) * <NUM_LIT:2> ] ++ ; } if ( ( last_lit & <NUM_LIT> ) == <NUM_LIT:0> && level > <NUM_LIT:2> ) { int out_length = last_lit * <NUM_LIT:8> ; int in_length = strstart - block_start ; int dcode ; for ( dcode = <NUM_LIT:0> ; dcode < D_CODES ; dcode ++ ) { out_length += ( int ) dyn_dtree [ dcode * <NUM_LIT:2> ] * ( <NUM_LIT> + Tree . extra_dbits [ dcode ] ) ; } out_length >>>= <NUM_LIT:3> ; if ( ( matches < ( last_lit / <NUM_LIT:2> ) ) && out_length < in_length / <NUM_LIT:2> ) return true ; } return ( last_lit == lit_bufsize - <NUM_LIT:1> ) ; } void compress_block ( short [ ] ltree , short [ ] dtree ) { int dist ; int lc ; int lx = <NUM_LIT:0> ; int code ; int extra ; if ( last_lit != <NUM_LIT:0> ) { do { dist = ( ( pending_buf [ d_buf + lx * <NUM_LIT:2> ] << <NUM_LIT:8> ) & <NUM_LIT> ) | ( pending_buf [ d_buf + lx * <NUM_LIT:2> + <NUM_LIT:1> ] & <NUM_LIT> ) ; lc = ( pending_buf [ l_buf + lx ] ) & <NUM_LIT> ; lx ++ ; if ( dist == <NUM_LIT:0> ) { send_code ( lc , ltree ) ; } else { code = Tree . _length_code [ lc ] ; send_code ( code + LITERALS + <NUM_LIT:1> , ltree ) ; extra = Tree . extra_lbits [ code ] ; if ( extra != <NUM_LIT: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 != <NUM_LIT: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 * <NUM_LIT:2> + <NUM_LIT:1> ] ; } void set_data_type ( ) { int n = <NUM_LIT:0> ; int ascii_freq = <NUM_LIT:0> ; int bin_freq = <NUM_LIT:0> ; while ( n < <NUM_LIT:7> ) { bin_freq += dyn_ltree [ n * <NUM_LIT:2> ] ; n ++ ; } while ( n < <NUM_LIT> ) { ascii_freq += dyn_ltree [ n * <NUM_LIT:2> ] ; n ++ ; } while ( n < LITERALS ) { bin_freq += dyn_ltree [ n * <NUM_LIT:2> ] ; n ++ ; } data_type = ( byte ) ( bin_freq > ( ascii_freq > > > <NUM_LIT:2> ) ? Z_BINARY : Z_ASCII ) ; } void bi_flush ( ) { if ( bi_valid == <NUM_LIT:16> ) { put_short ( bi_buf ) ; bi_buf = <NUM_LIT:0> ; bi_valid = <NUM_LIT:0> ; } else if ( bi_valid >= <NUM_LIT:8> ) { put_byte ( ( byte ) bi_buf ) ; bi_buf >>>= <NUM_LIT:8> ; bi_valid -= <NUM_LIT:8> ; } } void bi_windup ( ) { if ( bi_valid > <NUM_LIT:8> ) { put_short ( bi_buf ) ; } else if ( bi_valid > <NUM_LIT:0> ) { put_byte ( ( byte ) bi_buf ) ; } bi_buf = <NUM_LIT:0> ; bi_valid = <NUM_LIT:0> ; } void copy_block ( int buf , int len , boolean header ) { int index = <NUM_LIT:0> ; bi_windup ( ) ; last_eob_len = <NUM_LIT: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 >= <NUM_LIT:0> ? block_start : - <NUM_LIT:1> , strstart - block_start , eof ) ; block_start = strstart ; strm . flush_pending ( ) ; } int deflate_stored ( int flush ) { int max_block_size = <NUM_LIT> ; int max_start ; if ( max_block_size > pending_buf_size - <NUM_LIT:5> ) { max_block_size = pending_buf_size - <NUM_LIT:5> ; } while ( true ) { if ( lookahead <= <NUM_LIT:1> ) { fill_window ( ) ; if ( lookahead == <NUM_LIT:0> && flush == Z_NO_FLUSH ) return NeedMore ; if ( lookahead == <NUM_LIT:0> ) break ; } strstart += lookahead ; lookahead = <NUM_LIT:0> ; max_start = block_start + max_block_size ; if ( strstart == <NUM_LIT:0> || strstart >= max_start ) { lookahead = ( int ) ( strstart - max_start ) ; strstart = ( int ) max_start ; flush_block_only ( false ) ; if ( strm . avail_out == <NUM_LIT:0> ) return NeedMore ; } if ( strstart - block_start >= w_size - MIN_LOOKAHEAD ) { flush_block_only ( false ) ; if ( strm . avail_out == <NUM_LIT:0> ) return NeedMore ; } } flush_block_only ( flush == Z_FINISH ) ; if ( strm . avail_out == <NUM_LIT: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 << <NUM_LIT:1> ) + ( eof ? <NUM_LIT:1> : <NUM_LIT:0> ) , <NUM_LIT: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 = <NUM_LIT:0> ; if ( level > <NUM_LIT: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 + <NUM_LIT:3> + <NUM_LIT:7> ) > > > <NUM_LIT:3> ; static_lenb = ( static_len + <NUM_LIT:3> + <NUM_LIT:7> ) > > > <NUM_LIT:3> ; if ( static_lenb <= opt_lenb ) opt_lenb = static_lenb ; } else { opt_lenb = static_lenb = stored_len + <NUM_LIT:5> ; } if ( stored_len + <NUM_LIT:4> <= opt_lenb && buf != - <NUM_LIT:1> ) { _tr_stored_block ( buf , stored_len , eof ) ; } else if ( static_lenb == opt_lenb ) { send_bits ( ( STATIC_TREES << <NUM_LIT:1> ) + ( eof ? <NUM_LIT:1> : <NUM_LIT:0> ) , <NUM_LIT:3> ) ; compress_block ( StaticTree . static_ltree , StaticTree . static_dtree ) ; } else { send_bits ( ( DYN_TREES << <NUM_LIT:1> ) + ( eof ? <NUM_LIT:1> : <NUM_LIT:0> ) , <NUM_LIT:3> ) ; send_all_trees ( l_desc . max_code + <NUM_LIT:1> , d_desc . max_code + <NUM_LIT:1> , max_blindex + <NUM_LIT: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 == <NUM_LIT:0> && strstart == <NUM_LIT:0> && lookahead == <NUM_LIT:0> ) { more = w_size ; } else if ( more == - <NUM_LIT:1> ) { more -- ; } else if ( strstart >= w_size + w_size - MIN_LOOKAHEAD ) { System . arraycopy ( window , w_size , window , <NUM_LIT:0> , w_size ) ; match_start -= w_size ; strstart -= w_size ; block_start -= w_size ; n = hash_size ; p = n ; do { m = ( head [ -- p ] & <NUM_LIT> ) ; head [ p ] = ( m >= w_size ? ( short ) ( m - w_size ) : <NUM_LIT:0> ) ; } while ( -- n != <NUM_LIT:0> ) ; n = w_size ; p = n ; do { m = ( prev [ -- p ] & <NUM_LIT> ) ; prev [ p ] = ( m >= w_size ? ( short ) ( m - w_size ) : <NUM_LIT:0> ) ; } while ( -- n != <NUM_LIT:0> ) ; more += w_size ; } if ( strm . avail_in == <NUM_LIT:0> ) return ; n = strm . read_buf ( window , strstart + lookahead , more ) ; lookahead += n ; if ( lookahead >= MIN_MATCH ) { ins_h = window [ strstart ] & <NUM_LIT> ; ins_h = ( ( ( ins_h ) << hash_shift ) ^ ( window [ strstart + <NUM_LIT:1> ] & <NUM_LIT> ) ) & hash_mask ; } } while ( lookahead < MIN_LOOKAHEAD && strm . avail_in != <NUM_LIT:0> ) ; } int deflate_fast ( int flush ) { int hash_head = <NUM_LIT:0> ; boolean bflush ; while ( true ) { if ( lookahead < MIN_LOOKAHEAD ) { fill_window ( ) ; if ( lookahead < MIN_LOOKAHEAD && flush == Z_NO_FLUSH ) { return NeedMore ; } if ( lookahead == <NUM_LIT:0> ) break ; } if ( lookahead >= MIN_MATCH ) { ins_h = ( ( ( ins_h ) << hash_shift ) ^ ( window [ ( strstart ) + ( MIN_MATCH - <NUM_LIT:1> ) ] & <NUM_LIT> ) ) & hash_mask ; hash_head = ( head [ ins_h ] & <NUM_LIT> ) ; prev [ strstart & w_mask ] = head [ ins_h ] ; head [ ins_h ] = ( short ) strstart ; } if ( hash_head != <NUM_LIT> && ( ( strstart - hash_head ) & <NUM_LIT> ) <= 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 - <NUM_LIT:1> ) ] & <NUM_LIT> ) ) & hash_mask ; hash_head = ( head [ ins_h ] & <NUM_LIT> ) ; prev [ strstart & w_mask ] = head [ ins_h ] ; head [ ins_h ] = ( short ) strstart ; } while ( -- match_length != <NUM_LIT:0> ) ; strstart ++ ; } else { strstart += match_length ; match_length = <NUM_LIT:0> ; ins_h = window [ strstart ] & <NUM_LIT> ; ins_h = ( ( ( ins_h ) << hash_shift ) ^ ( window [ strstart + <NUM_LIT:1> ] & <NUM_LIT> ) ) & hash_mask ; } } else { bflush = _tr_tally ( <NUM_LIT:0> , window [ strstart ] & <NUM_LIT> ) ; lookahead -- ; strstart ++ ; } if ( bflush ) { flush_block_only ( false ) ; if ( strm . avail_out == <NUM_LIT:0> ) return NeedMore ; } } flush_block_only ( flush == Z_FINISH ) ; if ( strm . avail_out == <NUM_LIT:0> ) { if ( flush == Z_FINISH ) return FinishStarted ; else return NeedMore ; } return flush == Z_FINISH ? FinishDone : BlockDone ; } int deflate_slow ( int flush ) { int hash_head = <NUM_LIT:0> ; boolean bflush ; while ( true ) { if ( lookahead < MIN_LOOKAHEAD ) { fill_window ( ) ; if ( lookahead < MIN_LOOKAHEAD && flush == Z_NO_FLUSH ) { return NeedMore ; } if ( lookahead == <NUM_LIT:0> ) break ; } if ( lookahead >= MIN_MATCH ) { ins_h = ( ( ( ins_h ) << hash_shift ) ^ ( window [ ( strstart ) + ( MIN_MATCH - <NUM_LIT:1> ) ] & <NUM_LIT> ) ) & hash_mask ; hash_head = ( head [ ins_h ] & <NUM_LIT> ) ; prev [ strstart & w_mask ] = head [ ins_h ] ; head [ ins_h ] = ( short ) strstart ; } prev_length = match_length ; prev_match = match_start ; match_length = MIN_MATCH - <NUM_LIT:1> ; if ( hash_head != <NUM_LIT:0> && prev_length < max_lazy_match && ( ( strstart - hash_head ) & <NUM_LIT> ) <= w_size - MIN_LOOKAHEAD ) { if ( strategy != Z_HUFFMAN_ONLY ) { match_length = longest_match ( hash_head ) ; } if ( match_length <= <NUM_LIT:5> && ( strategy == Z_FILTERED || ( match_length == MIN_MATCH && strstart - match_start > <NUM_LIT> ) ) ) { match_length = MIN_MATCH - <NUM_LIT:1> ; } } if ( prev_length >= MIN_MATCH && match_length <= prev_length ) { int max_insert = strstart + lookahead - MIN_MATCH ; bflush = _tr_tally ( strstart - <NUM_LIT:1> - prev_match , prev_length - MIN_MATCH ) ; lookahead -= prev_length - <NUM_LIT:1> ; prev_length -= <NUM_LIT:2> ; do { if ( ++ strstart <= max_insert ) { ins_h = ( ( ( ins_h ) << hash_shift ) ^ ( window [ ( strstart ) + ( MIN_MATCH - <NUM_LIT:1> ) ] & <NUM_LIT> ) ) & hash_mask ; hash_head = ( head [ ins_h ] & <NUM_LIT> ) ; prev [ strstart & w_mask ] = head [ ins_h ] ; head [ ins_h ] = ( short ) strstart ; } } while ( -- prev_length != <NUM_LIT:0> ) ; match_available = <NUM_LIT:0> ; match_length = MIN_MATCH - <NUM_LIT:1> ; strstart ++ ; if ( bflush ) { flush_block_only ( false ) ; if ( strm . avail_out == <NUM_LIT:0> ) return NeedMore ; } } else if ( match_available != <NUM_LIT:0> ) { bflush = _tr_tally ( <NUM_LIT:0> , window [ strstart - <NUM_LIT:1> ] & <NUM_LIT> ) ; if ( bflush ) { flush_block_only ( false ) ; } strstart ++ ; lookahead -- ; if ( strm . avail_out == <NUM_LIT:0> ) return NeedMore ; } else { match_available = <NUM_LIT:1> ; strstart ++ ; lookahead -- ; } } if ( match_available != <NUM_LIT:0> ) { bflush = _tr_tally ( <NUM_LIT:0> , window [ strstart - <NUM_LIT:1> ] & <NUM_LIT> ) ; match_available = <NUM_LIT:0> ; } flush_block_only ( flush == Z_FINISH ) ; if ( strm . avail_out == <NUM_LIT: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 ) : <NUM_LIT:0> ; int nice_match = this . nice_match ; int wmask = w_mask ; int strend = strstart + MAX_MATCH ; byte scan_end1 = window [ scan + best_len - <NUM_LIT:1> ] ; byte scan_end = window [ scan + best_len ] ; if ( prev_length >= good_match ) { chain_length >>= <NUM_LIT:2> ; } if ( nice_match > lookahead ) nice_match = lookahead ; do { match = cur_match ; if ( window [ match + best_len ] != scan_end || window [ match + best_len - <NUM_LIT:1> ] != scan_end1 || window [ match ] != window [ scan ] || window [ ++ match ] != window [ scan + <NUM_LIT:1> ] ) continue ; scan += <NUM_LIT: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 - <NUM_LIT:1> ] ; scan_end = window [ scan + best_len ] ; } } while ( ( cur_match = ( prev [ cur_match & wmask ] & <NUM_LIT> ) ) > limit && -- chain_length != <NUM_LIT: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 = <NUM_LIT:0> ; strm . msg = null ; if ( level == Z_DEFAULT_COMPRESSION ) level = <NUM_LIT:6> ; if ( windowBits < <NUM_LIT:0> ) { noheader = <NUM_LIT:1> ; windowBits = - windowBits ; } if ( memLevel < <NUM_LIT:1> || memLevel > MAX_MEM_LEVEL || method != Z_DEFLATED || windowBits < <NUM_LIT:9> || windowBits > <NUM_LIT:15> || level < <NUM_LIT:0> || level > <NUM_LIT:9> || strategy < <NUM_LIT:0> || strategy > Z_HUFFMAN_ONLY ) { return Z_STREAM_ERROR ; } strm . dstate = ( Deflate ) this ; this . noheader = noheader ; w_bits = windowBits ; w_size = <NUM_LIT:1> << w_bits ; w_mask = w_size - <NUM_LIT:1> ; hash_bits = memLevel + <NUM_LIT:7> ; hash_size = <NUM_LIT:1> << hash_bits ; hash_mask = hash_size - <NUM_LIT:1> ; hash_shift = ( ( hash_bits + MIN_MATCH - <NUM_LIT:1> ) / MIN_MATCH ) ; window = new byte [ w_size * <NUM_LIT:2> ] ; prev = new short [ w_size ] ; head = new short [ hash_size ] ; lit_bufsize = <NUM_LIT:1> << ( memLevel + <NUM_LIT:6> ) ; pending_buf = new byte [ lit_bufsize * <NUM_LIT:4> ] ; pending_buf_size = lit_bufsize * <NUM_LIT:4> ; d_buf = lit_bufsize / <NUM_LIT:2> ; l_buf = ( <NUM_LIT:1> + <NUM_LIT: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 = <NUM_LIT:0> ; strm . msg = null ; strm . data_type = Z_UNKNOWN ; pending = <NUM_LIT:0> ; pending_out = <NUM_LIT:0> ; if ( noheader < <NUM_LIT:0> ) { noheader = <NUM_LIT:0> ; } status = ( noheader != <NUM_LIT:0> ) ? BUSY_STATE : INIT_STATE ; strm . adler = strm . _adler . adler32 ( <NUM_LIT:0> , null , <NUM_LIT:0> , <NUM_LIT: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 = <NUM_LIT:6> ; } if ( _level < <NUM_LIT:0> || _level > <NUM_LIT:9> || _strategy < <NUM_LIT:0> || _strategy > Z_HUFFMAN_ONLY ) { return Z_STREAM_ERROR ; } if ( config_table [ level ] . func != config_table [ _level ] . func && strm . total_in != <NUM_LIT: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 = <NUM_LIT:0> ; if ( dictionary == null || status != INIT_STATE ) return Z_STREAM_ERROR ; strm . adler = strm . _adler . adler32 ( strm . adler , dictionary , <NUM_LIT: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 , <NUM_LIT:0> , length ) ; strstart = length ; block_start = length ; ins_h = window [ <NUM_LIT:0> ] & <NUM_LIT> ; ins_h = ( ( ( ins_h ) << hash_shift ) ^ ( window [ <NUM_LIT:1> ] & <NUM_LIT> ) ) & hash_mask ; for ( int n = <NUM_LIT:0> ; n <= length - MIN_MATCH ; n ++ ) { ins_h = ( ( ( ins_h ) << hash_shift ) ^ ( window [ ( n ) + ( MIN_MATCH - <NUM_LIT:1> ) ] & <NUM_LIT> ) ) & 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 < <NUM_LIT:0> ) { return Z_STREAM_ERROR ; } if ( strm . next_out == null || ( strm . next_in == null && strm . avail_in != <NUM_LIT: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 == <NUM_LIT: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 - <NUM_LIT:8> ) << <NUM_LIT:4> ) ) << <NUM_LIT:8> ; int level_flags = ( ( level - <NUM_LIT:1> ) & <NUM_LIT> ) > > <NUM_LIT:1> ; if ( level_flags > <NUM_LIT:3> ) level_flags = <NUM_LIT:3> ; header |= ( level_flags << <NUM_LIT:6> ) ; if ( strstart != <NUM_LIT:0> ) header |= PRESET_DICT ; header += <NUM_LIT:31> - ( header % <NUM_LIT:31> ) ; status = BUSY_STATE ; putShortMSB ( header ) ; if ( strstart != <NUM_LIT:0> ) { putShortMSB ( ( int ) ( strm . adler > > > <NUM_LIT:16> ) ) ; putShortMSB ( ( int ) ( strm . adler & <NUM_LIT> ) ) ; } strm . adler = strm . _adler . adler32 ( <NUM_LIT:0> , null , <NUM_LIT:0> , <NUM_LIT:0> ) ; } if ( pending != <NUM_LIT:0> ) { strm . flush_pending ( ) ; if ( strm . avail_out == <NUM_LIT:0> ) { last_flush = - <NUM_LIT:1> ; return Z_OK ; } } else if ( strm . avail_in == <NUM_LIT: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 != <NUM_LIT:0> ) { strm . msg = z_errmsg [ Z_NEED_DICT - ( Z_BUF_ERROR ) ] ; return Z_BUF_ERROR ; } if ( strm . avail_in != <NUM_LIT:0> || lookahead != <NUM_LIT:0> || ( flush != Z_NO_FLUSH && status != FINISH_STATE ) ) { int bstate = - <NUM_LIT: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 == <NUM_LIT:0> ) { last_flush = - <NUM_LIT:1> ; } return Z_OK ; } if ( bstate == BlockDone ) { if ( flush == Z_PARTIAL_FLUSH ) { _tr_align ( ) ; } else { _tr_stored_block ( <NUM_LIT:0> , <NUM_LIT:0> , false ) ; if ( flush == Z_FULL_FLUSH ) { for ( int i = <NUM_LIT:0> ; i < hash_size ; i ++ ) head [ i ] = <NUM_LIT:0> ; } } strm . flush_pending ( ) ; if ( strm . avail_out == <NUM_LIT:0> ) { last_flush = - <NUM_LIT:1> ; return Z_OK ; } } } if ( flush != Z_FINISH ) return Z_OK ; if ( noheader != <NUM_LIT:0> ) return Z_STREAM_END ; putShortMSB ( ( int ) ( strm . adler > > > <NUM_LIT:16> ) ) ; putShortMSB ( ( int ) ( strm . adler & <NUM_LIT> ) ) ; strm . flush_pending ( ) ; noheader = - <NUM_LIT:1> ; return pending != <NUM_LIT:0> ? Z_OK : Z_STREAM_END ; } } </s>
|
<s> package com . jcraft . jzlib ; import java . io . * ; public class ZInputStream extends FilterInputStream { protected ZStream z = new ZStream ( ) ; protected int bufsize = <NUM_LIT> ; protected int flush = JZlib . Z_NO_FLUSH ; protected byte [ ] buf = new byte [ bufsize ] , buf1 = new byte [ <NUM_LIT: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 = <NUM_LIT:0> ; z . avail_in = <NUM_LIT: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 = <NUM_LIT:0> ; z . avail_in = <NUM_LIT:0> ; } public int read ( ) throws IOException { if ( read ( buf1 , <NUM_LIT:0> , <NUM_LIT:1> ) == - <NUM_LIT:1> ) return ( - <NUM_LIT:1> ) ; return ( buf1 [ <NUM_LIT:0> ] & <NUM_LIT> ) ; } private boolean nomoreinput = false ; public int read ( byte [ ] b , int off , int len ) throws IOException { if ( len == <NUM_LIT:0> ) return ( <NUM_LIT:0> ) ; int err ; z . next_out = b ; z . next_out_index = off ; z . avail_out = len ; do { if ( ( z . avail_in == <NUM_LIT:0> ) && ( ! nomoreinput ) ) { z . next_in_index = <NUM_LIT:0> ; z . avail_in = in . read ( buf , <NUM_LIT:0> , bufsize ) ; if ( z . avail_in == - <NUM_LIT:1> ) { z . avail_in = <NUM_LIT:0> ; nomoreinput = true ; } } if ( compress ) err = z . deflate ( flush ) ; else err = z . inflate ( flush ) ; if ( nomoreinput && ( err == JZlib . Z_BUF_ERROR ) ) return ( - <NUM_LIT:1> ) ; if ( err != JZlib . Z_OK && err != JZlib . Z_STREAM_END ) throw new ZStreamException ( ( compress ? "<STR_LIT>" : "<STR_LIT>" ) + "<STR_LIT>" + z . msg ) ; if ( ( nomoreinput || err == JZlib . Z_STREAM_END ) && ( z . avail_out == len ) ) return ( - <NUM_LIT:1> ) ; } while ( z . avail_out == len && err == JZlib . Z_OK ) ; return ( len - z . avail_out ) ; } public long skip ( long n ) throws IOException { int len = <NUM_LIT> ; 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>
|
<s> package com . jcraft . jzlib ; public class ZStreamException extends java . io . IOException { public ZStreamException ( ) { super ( ) ; } public ZStreamException ( String s ) { super ( s ) ; } } </s>
|
<s> package com . jcraft . jzlib ; final class StaticTree { static final private int MAX_BITS = <NUM_LIT:15> ; static final private int BL_CODES = <NUM_LIT> ; static final private int D_CODES = <NUM_LIT:30> ; static final private int LITERALS = <NUM_LIT> ; static final private int LENGTH_CODES = <NUM_LIT> ; static final private int L_CODES = ( LITERALS + <NUM_LIT:1> + LENGTH_CODES ) ; static final int MAX_BL_BITS = <NUM_LIT:7> ; static final short [ ] static_ltree = { <NUM_LIT:12> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT:2> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT:10> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT:6> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT:30> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT:1> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT:9> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT:5> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT:9> , <NUM_LIT:11> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT:9> , <NUM_LIT:7> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT:9> , <NUM_LIT:15> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT:9> , <NUM_LIT:31> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT:9> , <NUM_LIT:255> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT:9> , <NUM_LIT:0> , <NUM_LIT:7> , <NUM_LIT> , <NUM_LIT:7> , <NUM_LIT:32> , <NUM_LIT:7> , <NUM_LIT> , <NUM_LIT:7> , <NUM_LIT:16> , <NUM_LIT:7> , <NUM_LIT> , <NUM_LIT:7> , <NUM_LIT> , <NUM_LIT:7> , <NUM_LIT> , <NUM_LIT:7> , <NUM_LIT:8> , <NUM_LIT:7> , <NUM_LIT> , <NUM_LIT:7> , <NUM_LIT> , <NUM_LIT:7> , <NUM_LIT> , <NUM_LIT:7> , <NUM_LIT:24> , <NUM_LIT:7> , <NUM_LIT> , <NUM_LIT:7> , <NUM_LIT> , <NUM_LIT:7> , <NUM_LIT> , <NUM_LIT:7> , <NUM_LIT:4> , <NUM_LIT:7> , <NUM_LIT> , <NUM_LIT:7> , <NUM_LIT> , <NUM_LIT:7> , <NUM_LIT:100> , <NUM_LIT:7> , <NUM_LIT:20> , <NUM_LIT:7> , <NUM_LIT> , <NUM_LIT:7> , <NUM_LIT> , <NUM_LIT:7> , <NUM_LIT> , <NUM_LIT:7> , <NUM_LIT:3> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:8> } ; static final short [ ] static_dtree = { <NUM_LIT:0> , <NUM_LIT:5> , <NUM_LIT:16> , <NUM_LIT:5> , <NUM_LIT:8> , <NUM_LIT:5> , <NUM_LIT:24> , <NUM_LIT:5> , <NUM_LIT:4> , <NUM_LIT:5> , <NUM_LIT:20> , <NUM_LIT:5> , <NUM_LIT:12> , <NUM_LIT:5> , <NUM_LIT> , <NUM_LIT:5> , <NUM_LIT:2> , <NUM_LIT:5> , <NUM_LIT> , <NUM_LIT:5> , <NUM_LIT:10> , <NUM_LIT:5> , <NUM_LIT> , <NUM_LIT:5> , <NUM_LIT:6> , <NUM_LIT:5> , <NUM_LIT> , <NUM_LIT:5> , <NUM_LIT> , <NUM_LIT:5> , <NUM_LIT:30> , <NUM_LIT:5> , <NUM_LIT:1> , <NUM_LIT:5> , <NUM_LIT> , <NUM_LIT:5> , <NUM_LIT:9> , <NUM_LIT:5> , <NUM_LIT> , <NUM_LIT:5> , <NUM_LIT:5> , <NUM_LIT:5> , <NUM_LIT> , <NUM_LIT:5> , <NUM_LIT> , <NUM_LIT:5> , <NUM_LIT> , <NUM_LIT:5> , <NUM_LIT:3> , <NUM_LIT:5> , <NUM_LIT> , <NUM_LIT:5> , <NUM_LIT:11> , <NUM_LIT:5> , <NUM_LIT> , <NUM_LIT:5> , <NUM_LIT:7> , <NUM_LIT:5> , <NUM_LIT> , <NUM_LIT:5> } ; static StaticTree static_l_desc = new StaticTree ( static_ltree , Tree . extra_lbits , LITERALS + <NUM_LIT:1> , L_CODES , MAX_BITS ) ; static StaticTree static_d_desc = new StaticTree ( static_dtree , Tree . extra_dbits , <NUM_LIT:0> , D_CODES , MAX_BITS ) ; static StaticTree static_bl_desc = new StaticTree ( null , Tree . extra_blbits , <NUM_LIT: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>
|
<s> package com . jcraft . jzlib ; final class Tree { static final private int MAX_BITS = <NUM_LIT:15> ; static final private int BL_CODES = <NUM_LIT> ; static final private int D_CODES = <NUM_LIT:30> ; static final private int LITERALS = <NUM_LIT> ; static final private int LENGTH_CODES = <NUM_LIT> ; static final private int L_CODES = ( LITERALS + <NUM_LIT:1> + LENGTH_CODES ) ; static final private int HEAP_SIZE = ( <NUM_LIT:2> * L_CODES + <NUM_LIT:1> ) ; static final int MAX_BL_BITS = <NUM_LIT:7> ; static final int END_BLOCK = <NUM_LIT> ; static final int REP_3_6 = <NUM_LIT:16> ; static final int REPZ_3_10 = <NUM_LIT> ; static final int REPZ_11_138 = <NUM_LIT> ; static final int [ ] extra_lbits = { <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:2> , <NUM_LIT:2> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:3> , <NUM_LIT:3> , <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:4> , <NUM_LIT:4> , <NUM_LIT:4> , <NUM_LIT:5> , <NUM_LIT:5> , <NUM_LIT:5> , <NUM_LIT:5> , <NUM_LIT:0> } ; static final int [ ] extra_dbits = { <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:4> , <NUM_LIT:5> , <NUM_LIT:5> , <NUM_LIT:6> , <NUM_LIT:6> , <NUM_LIT:7> , <NUM_LIT:7> , <NUM_LIT:8> , <NUM_LIT:8> , <NUM_LIT:9> , <NUM_LIT:9> , <NUM_LIT:10> , <NUM_LIT:10> , <NUM_LIT:11> , <NUM_LIT:11> , <NUM_LIT:12> , <NUM_LIT:12> , <NUM_LIT> , <NUM_LIT> } ; static final int [ ] extra_blbits = { <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:7> } ; static final byte [ ] bl_order = { <NUM_LIT:16> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT:7> , <NUM_LIT:9> , <NUM_LIT:6> , <NUM_LIT:10> , <NUM_LIT:5> , <NUM_LIT:11> , <NUM_LIT:4> , <NUM_LIT:12> , <NUM_LIT:3> , <NUM_LIT> , <NUM_LIT:2> , <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT:15> } ; static final int Buf_size = <NUM_LIT:8> * <NUM_LIT:2> ; static final int DIST_CODE_LEN = <NUM_LIT> ; static final byte [ ] _dist_code = { <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:4> , <NUM_LIT:5> , <NUM_LIT:5> , <NUM_LIT:6> , <NUM_LIT:6> , <NUM_LIT:6> , <NUM_LIT:6> , <NUM_LIT:7> , <NUM_LIT:7> , <NUM_LIT:7> , <NUM_LIT:7> , <NUM_LIT:8> , <NUM_LIT:8> , <NUM_LIT:8> , <NUM_LIT:8> , <NUM_LIT:8> , <NUM_LIT:8> , <NUM_LIT:8> , <NUM_LIT:8> , <NUM_LIT:9> , <NUM_LIT:9> , <NUM_LIT:9> , <NUM_LIT:9> , <NUM_LIT:9> , <NUM_LIT:9> , <NUM_LIT:9> , <NUM_LIT:9> , <NUM_LIT:10> , <NUM_LIT:10> , <NUM_LIT:10> , <NUM_LIT:10> , <NUM_LIT:10> , <NUM_LIT:10> , <NUM_LIT:10> , <NUM_LIT:10> , <NUM_LIT:10> , <NUM_LIT:10> , <NUM_LIT:10> , <NUM_LIT:10> , <NUM_LIT:10> , <NUM_LIT:10> , <NUM_LIT:10> , <NUM_LIT:10> , <NUM_LIT:11> , <NUM_LIT:11> , <NUM_LIT:11> , <NUM_LIT:11> , <NUM_LIT:11> , <NUM_LIT:11> , <NUM_LIT:11> , <NUM_LIT:11> , <NUM_LIT:11> , <NUM_LIT:11> , <NUM_LIT:11> , <NUM_LIT:11> , <NUM_LIT:11> , <NUM_LIT:11> , <NUM_LIT:11> , <NUM_LIT:11> , <NUM_LIT:12> , <NUM_LIT:12> , <NUM_LIT:12> , <NUM_LIT:12> , <NUM_LIT:12> , <NUM_LIT:12> , <NUM_LIT:12> , <NUM_LIT:12> , <NUM_LIT:12> , <NUM_LIT:12> , <NUM_LIT:12> , <NUM_LIT:12> , <NUM_LIT:12> , <NUM_LIT:12> , <NUM_LIT:12> , <NUM_LIT:12> , <NUM_LIT:12> , <NUM_LIT:12> , <NUM_LIT:12> , <NUM_LIT:12> , <NUM_LIT:12> , <NUM_LIT:12> , <NUM_LIT:12> , <NUM_LIT:12> , <NUM_LIT:12> , <NUM_LIT:12> , <NUM_LIT:12> , <NUM_LIT:12> , <NUM_LIT:12> , <NUM_LIT:12> , <NUM_LIT:12> , <NUM_LIT:12> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:15> , <NUM_LIT:15> , <NUM_LIT:15> , <NUM_LIT:15> , <NUM_LIT:15> , <NUM_LIT:15> , <NUM_LIT:15> , <NUM_LIT:15> , <NUM_LIT:15> , <NUM_LIT:15> , <NUM_LIT:15> , <NUM_LIT:15> , <NUM_LIT:15> , <NUM_LIT:15> , <NUM_LIT:15> , <NUM_LIT:15> , <NUM_LIT:15> , <NUM_LIT:15> , <NUM_LIT:15> , <NUM_LIT:15> , <NUM_LIT:15> , <NUM_LIT:15> , <NUM_LIT:15> , <NUM_LIT:15> , <NUM_LIT:15> , <NUM_LIT:15> , <NUM_LIT:15> , <NUM_LIT:15> , <NUM_LIT:15> , <NUM_LIT:15> , <NUM_LIT:15> , <NUM_LIT:15> , <NUM_LIT:15> , <NUM_LIT:15> , <NUM_LIT:15> , <NUM_LIT:15> , <NUM_LIT:15> , <NUM_LIT:15> , <NUM_LIT:15> , <NUM_LIT:15> , <NUM_LIT:15> , <NUM_LIT:15> , <NUM_LIT:15> , <NUM_LIT:15> , <NUM_LIT:15> , <NUM_LIT:15> , <NUM_LIT:15> , <NUM_LIT:15> , <NUM_LIT:15> , <NUM_LIT:15> , <NUM_LIT:15> , <NUM_LIT:15> , <NUM_LIT:15> , <NUM_LIT:15> , <NUM_LIT:15> , <NUM_LIT:15> , <NUM_LIT:15> , <NUM_LIT:15> , <NUM_LIT:15> , <NUM_LIT:15> , <NUM_LIT:15> , <NUM_LIT:15> , <NUM_LIT:15> , <NUM_LIT:15> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:16> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:20> , <NUM_LIT:20> , <NUM_LIT:20> , <NUM_LIT:20> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:24> , <NUM_LIT:24> , <NUM_LIT:24> , <NUM_LIT:24> , <NUM_LIT:24> , <NUM_LIT:24> , <NUM_LIT:24> , <NUM_LIT:24> , <NUM_LIT:24> , <NUM_LIT:24> , <NUM_LIT:24> , <NUM_LIT:24> , <NUM_LIT:24> , <NUM_LIT:24> , <NUM_LIT:24> , <NUM_LIT:24> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> } ; static final byte [ ] _length_code = { <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> , <NUM_LIT:6> , <NUM_LIT:7> , <NUM_LIT:8> , <NUM_LIT:8> , <NUM_LIT:9> , <NUM_LIT:9> , <NUM_LIT:10> , <NUM_LIT:10> , <NUM_LIT:11> , <NUM_LIT:11> , <NUM_LIT:12> , <NUM_LIT:12> , <NUM_LIT:12> , <NUM_LIT:12> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:15> , <NUM_LIT:15> , <NUM_LIT:15> , <NUM_LIT:15> , <NUM_LIT:16> , <NUM_LIT:16> , <NUM_LIT:16> , <NUM_LIT:16> , <NUM_LIT:16> , <NUM_LIT:16> , <NUM_LIT:16> , <NUM_LIT:16> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:20> , <NUM_LIT:20> , <NUM_LIT:20> , <NUM_LIT:20> , <NUM_LIT:20> , <NUM_LIT:20> , <NUM_LIT:20> , <NUM_LIT:20> , <NUM_LIT:20> , <NUM_LIT:20> , <NUM_LIT:20> , <NUM_LIT:20> , <NUM_LIT:20> , <NUM_LIT:20> , <NUM_LIT:20> , <NUM_LIT:20> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:24> , <NUM_LIT:24> , <NUM_LIT:24> , <NUM_LIT:24> , <NUM_LIT:24> , <NUM_LIT:24> , <NUM_LIT:24> , <NUM_LIT:24> , <NUM_LIT:24> , <NUM_LIT:24> , <NUM_LIT:24> , <NUM_LIT:24> , <NUM_LIT:24> , <NUM_LIT:24> , <NUM_LIT:24> , <NUM_LIT:24> , <NUM_LIT:24> , <NUM_LIT:24> , <NUM_LIT:24> , <NUM_LIT:24> , <NUM_LIT:24> , <NUM_LIT:24> , <NUM_LIT:24> , <NUM_LIT:24> , <NUM_LIT:24> , <NUM_LIT:24> , <NUM_LIT:24> , <NUM_LIT:24> , <NUM_LIT:24> , <NUM_LIT:24> , <NUM_LIT:24> , <NUM_LIT:24> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> } ; static final int [ ] base_length = { <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> , <NUM_LIT:6> , <NUM_LIT:7> , <NUM_LIT:8> , <NUM_LIT:10> , <NUM_LIT:12> , <NUM_LIT> , <NUM_LIT:16> , <NUM_LIT:20> , <NUM_LIT:24> , <NUM_LIT> , <NUM_LIT:32> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:0> } ; static final int [ ] base_dist = { <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:6> , <NUM_LIT:8> , <NUM_LIT:12> , <NUM_LIT:16> , <NUM_LIT:24> , <NUM_LIT:32> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> } ; static int d_code ( int dist ) { return ( ( dist ) < <NUM_LIT> ? _dist_code [ dist ] : _dist_code [ <NUM_LIT> + ( ( dist ) > > > <NUM_LIT: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 = <NUM_LIT:0> ; for ( bits = <NUM_LIT:0> ; bits <= MAX_BITS ; bits ++ ) s . bl_count [ bits ] = <NUM_LIT:0> ; tree [ s . heap [ s . heap_max ] * <NUM_LIT:2> + <NUM_LIT:1> ] = <NUM_LIT:0> ; for ( h = s . heap_max + <NUM_LIT:1> ; h < HEAP_SIZE ; h ++ ) { n = s . heap [ h ] ; bits = tree [ tree [ n * <NUM_LIT:2> + <NUM_LIT:1> ] * <NUM_LIT:2> + <NUM_LIT:1> ] + <NUM_LIT:1> ; if ( bits > max_length ) { bits = max_length ; overflow ++ ; } tree [ n * <NUM_LIT:2> + <NUM_LIT:1> ] = ( short ) bits ; if ( n > max_code ) continue ; s . bl_count [ bits ] ++ ; xbits = <NUM_LIT:0> ; if ( n >= base ) xbits = extra [ n - base ] ; f = tree [ n * <NUM_LIT:2> ] ; s . opt_len += f * ( bits + xbits ) ; if ( stree != null ) s . static_len += f * ( stree [ n * <NUM_LIT:2> + <NUM_LIT:1> ] + xbits ) ; } if ( overflow == <NUM_LIT:0> ) return ; do { bits = max_length - <NUM_LIT:1> ; while ( s . bl_count [ bits ] == <NUM_LIT:0> ) bits -- ; s . bl_count [ bits ] -- ; s . bl_count [ bits + <NUM_LIT:1> ] += <NUM_LIT:2> ; s . bl_count [ max_length ] -- ; overflow -= <NUM_LIT:2> ; } while ( overflow > <NUM_LIT:0> ) ; for ( bits = max_length ; bits != <NUM_LIT:0> ; bits -- ) { n = s . bl_count [ bits ] ; while ( n != <NUM_LIT:0> ) { m = s . heap [ -- h ] ; if ( m > max_code ) continue ; if ( tree [ m * <NUM_LIT:2> + <NUM_LIT:1> ] != bits ) { s . opt_len += ( ( long ) bits - ( long ) tree [ m * <NUM_LIT:2> + <NUM_LIT:1> ] ) * ( long ) tree [ m * <NUM_LIT:2> ] ; tree [ m * <NUM_LIT:2> + <NUM_LIT: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 = - <NUM_LIT:1> ; int node ; s . heap_len = <NUM_LIT:0> ; s . heap_max = HEAP_SIZE ; for ( n = <NUM_LIT:0> ; n < elems ; n ++ ) { if ( tree [ n * <NUM_LIT:2> ] != <NUM_LIT:0> ) { s . heap [ ++ s . heap_len ] = max_code = n ; s . depth [ n ] = <NUM_LIT:0> ; } else { tree [ n * <NUM_LIT:2> + <NUM_LIT:1> ] = <NUM_LIT:0> ; } } while ( s . heap_len < <NUM_LIT:2> ) { node = s . heap [ ++ s . heap_len ] = ( max_code < <NUM_LIT:2> ? ++ max_code : <NUM_LIT:0> ) ; tree [ node * <NUM_LIT:2> ] = <NUM_LIT:1> ; s . depth [ node ] = <NUM_LIT:0> ; s . opt_len -- ; if ( stree != null ) s . static_len -= stree [ node * <NUM_LIT:2> + <NUM_LIT:1> ] ; } this . max_code = max_code ; for ( n = s . heap_len / <NUM_LIT:2> ; n >= <NUM_LIT:1> ; n -- ) s . pqdownheap ( tree , n ) ; node = elems ; do { n = s . heap [ <NUM_LIT:1> ] ; s . heap [ <NUM_LIT:1> ] = s . heap [ s . heap_len -- ] ; s . pqdownheap ( tree , <NUM_LIT:1> ) ; m = s . heap [ <NUM_LIT:1> ] ; s . heap [ -- s . heap_max ] = n ; s . heap [ -- s . heap_max ] = m ; tree [ node * <NUM_LIT:2> ] = ( short ) ( tree [ n * <NUM_LIT:2> ] + tree [ m * <NUM_LIT:2> ] ) ; s . depth [ node ] = ( byte ) ( Math . max ( s . depth [ n ] , s . depth [ m ] ) + <NUM_LIT:1> ) ; tree [ n * <NUM_LIT:2> + <NUM_LIT:1> ] = tree [ m * <NUM_LIT:2> + <NUM_LIT:1> ] = ( short ) node ; s . heap [ <NUM_LIT:1> ] = node ++ ; s . pqdownheap ( tree , <NUM_LIT:1> ) ; } while ( s . heap_len >= <NUM_LIT:2> ) ; s . heap [ -- s . heap_max ] = s . heap [ <NUM_LIT: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 + <NUM_LIT:1> ] ; short code = <NUM_LIT:0> ; int bits ; int n ; for ( bits = <NUM_LIT:1> ; bits <= MAX_BITS ; bits ++ ) { next_code [ bits ] = code = ( short ) ( ( code + bl_count [ bits - <NUM_LIT:1> ] ) << <NUM_LIT:1> ) ; } for ( n = <NUM_LIT:0> ; n <= max_code ; n ++ ) { int len = tree [ n * <NUM_LIT:2> + <NUM_LIT:1> ] ; if ( len == <NUM_LIT:0> ) continue ; tree [ n * <NUM_LIT:2> ] = ( short ) ( bi_reverse ( next_code [ len ] ++ , len ) ) ; } } static int bi_reverse ( int code , int len ) { int res = <NUM_LIT:0> ; do { res |= code & <NUM_LIT:1> ; code >>>= <NUM_LIT:1> ; res <<= <NUM_LIT:1> ; } while ( -- len > <NUM_LIT:0> ) ; return res > > > <NUM_LIT:1> ; } } </s>
|
<s> package com . jcraft . jzlib ; final class InfBlocks { static final private int MANY = <NUM_LIT> ; static final private int [ ] inflate_mask = { <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> } ; static final int [ ] border = { <NUM_LIT:16> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT:7> , <NUM_LIT:9> , <NUM_LIT:6> , <NUM_LIT:10> , <NUM_LIT:5> , <NUM_LIT:11> , <NUM_LIT:4> , <NUM_LIT:12> , <NUM_LIT:3> , <NUM_LIT> , <NUM_LIT:2> , <NUM_LIT> , <NUM_LIT:1> , <NUM_LIT:15> } ; static final private int Z_OK = <NUM_LIT:0> ; static final private int Z_STREAM_END = <NUM_LIT:1> ; static final private int Z_NEED_DICT = <NUM_LIT:2> ; static final private int Z_ERRNO = - <NUM_LIT:1> ; static final private int Z_STREAM_ERROR = - <NUM_LIT:2> ; static final private int Z_DATA_ERROR = - <NUM_LIT:3> ; static final private int Z_MEM_ERROR = - <NUM_LIT:4> ; static final private int Z_BUF_ERROR = - <NUM_LIT:5> ; static final private int Z_VERSION_ERROR = - <NUM_LIT:6> ; static final private int TYPE = <NUM_LIT:0> ; static final private int LENS = <NUM_LIT:1> ; static final private int STORED = <NUM_LIT:2> ; static final private int TABLE = <NUM_LIT:3> ; static final private int BTREE = <NUM_LIT:4> ; static final private int DTREE = <NUM_LIT:5> ; static final private int CODES = <NUM_LIT:6> ; static final private int DRY = <NUM_LIT:7> ; static final private int DONE = <NUM_LIT:8> ; static final private int BAD = <NUM_LIT:9> ; int mode ; int left ; int table ; int index ; int [ ] blens ; int [ ] bb = new int [ <NUM_LIT:1> ] ; int [ ] tb = new int [ <NUM_LIT: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 * <NUM_LIT: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 [ <NUM_LIT:0> ] = check ; if ( mode == BTREE || mode == DTREE ) { } if ( mode == CODES ) { codes . free ( z ) ; } mode = TYPE ; bitk = <NUM_LIT:0> ; bitb = <NUM_LIT:0> ; read = write = <NUM_LIT:0> ; if ( checkfn != null ) z . adler = check = z . _adler . adler32 ( <NUM_LIT> , null , <NUM_LIT:0> , <NUM_LIT: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 - <NUM_LIT:1> : end - q ) ; } while ( true ) { switch ( mode ) { case TYPE : while ( k < ( <NUM_LIT:3> ) ) { if ( n != <NUM_LIT: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 ++ ] & <NUM_LIT> ) << k ; k += <NUM_LIT:8> ; } t = ( int ) ( b & <NUM_LIT:7> ) ; last = t & <NUM_LIT:1> ; switch ( t > > > <NUM_LIT:1> ) { case <NUM_LIT:0> : { b >>>= ( <NUM_LIT:3> ) ; k -= ( <NUM_LIT:3> ) ; } t = k & <NUM_LIT:7> ; { b >>>= ( t ) ; k -= ( t ) ; } mode = LENS ; break ; case <NUM_LIT:1> : { int [ ] bl = new int [ <NUM_LIT:1> ] ; int [ ] bd = new int [ <NUM_LIT:1> ] ; int [ ] [ ] tl = new int [ <NUM_LIT:1> ] [ ] ; int [ ] [ ] td = new int [ <NUM_LIT:1> ] [ ] ; InfTree . inflate_trees_fixed ( bl , bd , tl , td , z ) ; codes . init ( bl [ <NUM_LIT:0> ] , bd [ <NUM_LIT:0> ] , tl [ <NUM_LIT:0> ] , <NUM_LIT:0> , td [ <NUM_LIT:0> ] , <NUM_LIT:0> , z ) ; } { b >>>= ( <NUM_LIT:3> ) ; k -= ( <NUM_LIT:3> ) ; } mode = CODES ; break ; case <NUM_LIT:2> : { b >>>= ( <NUM_LIT:3> ) ; k -= ( <NUM_LIT:3> ) ; } mode = TABLE ; break ; case <NUM_LIT:3> : { b >>>= ( <NUM_LIT:3> ) ; k -= ( <NUM_LIT:3> ) ; } mode = BAD ; z . msg = "<STR_LIT>" ; 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 < ( <NUM_LIT:32> ) ) { if ( n != <NUM_LIT: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 ++ ] & <NUM_LIT> ) << k ; k += <NUM_LIT:8> ; } if ( ( ( ( ~ b ) > > > <NUM_LIT:16> ) & <NUM_LIT> ) != ( b & <NUM_LIT> ) ) { mode = BAD ; z . msg = "<STR_LIT>" ; 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 & <NUM_LIT> ) ; b = k = <NUM_LIT:0> ; mode = left != <NUM_LIT:0> ? STORED : ( last != <NUM_LIT:0> ? DRY : TYPE ) ; break ; case STORED : if ( n == <NUM_LIT: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 == <NUM_LIT:0> ) { if ( q == end && read != <NUM_LIT:0> ) { q = <NUM_LIT:0> ; m = ( int ) ( q < read ? read - q - <NUM_LIT:1> : end - q ) ; } if ( m == <NUM_LIT:0> ) { write = q ; r = inflate_flush ( z , r ) ; q = write ; m = ( int ) ( q < read ? read - q - <NUM_LIT:1> : end - q ) ; if ( q == end && read != <NUM_LIT:0> ) { q = <NUM_LIT:0> ; m = ( int ) ( q < read ? read - q - <NUM_LIT:1> : end - q ) ; } if ( m == <NUM_LIT: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 ) != <NUM_LIT:0> ) break ; mode = last != <NUM_LIT:0> ? DRY : TYPE ; break ; case TABLE : while ( k < ( <NUM_LIT> ) ) { if ( n != <NUM_LIT: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 ++ ] & <NUM_LIT> ) << k ; k += <NUM_LIT:8> ; } table = t = ( b & <NUM_LIT> ) ; if ( ( t & <NUM_LIT> ) > <NUM_LIT> || ( ( t > > <NUM_LIT:5> ) & <NUM_LIT> ) > <NUM_LIT> ) { mode = BAD ; z . msg = "<STR_LIT>" ; 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 = <NUM_LIT> + ( t & <NUM_LIT> ) + ( ( t > > <NUM_LIT:5> ) & <NUM_LIT> ) ; if ( blens == null || blens . length < t ) { blens = new int [ t ] ; } else { for ( int i = <NUM_LIT:0> ; i < t ; i ++ ) { blens [ i ] = <NUM_LIT:0> ; } } { b >>>= ( <NUM_LIT> ) ; k -= ( <NUM_LIT> ) ; } index = <NUM_LIT:0> ; mode = BTREE ; case BTREE : while ( index < <NUM_LIT:4> + ( table > > > <NUM_LIT:10> ) ) { while ( k < ( <NUM_LIT:3> ) ) { if ( n != <NUM_LIT: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 ++ ] & <NUM_LIT> ) << k ; k += <NUM_LIT:8> ; } blens [ border [ index ++ ] ] = b & <NUM_LIT:7> ; { b >>>= ( <NUM_LIT:3> ) ; k -= ( <NUM_LIT:3> ) ; } } while ( index < <NUM_LIT> ) { blens [ border [ index ++ ] ] = <NUM_LIT:0> ; } bb [ <NUM_LIT:0> ] = <NUM_LIT: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 = <NUM_LIT:0> ; mode = DTREE ; case DTREE : while ( true ) { t = table ; if ( ! ( index < <NUM_LIT> + ( t & <NUM_LIT> ) + ( ( t > > <NUM_LIT:5> ) & <NUM_LIT> ) ) ) { break ; } int [ ] h ; int i , j , c ; t = bb [ <NUM_LIT:0> ] ; while ( k < ( t ) ) { if ( n != <NUM_LIT: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 ++ ] & <NUM_LIT> ) << k ; k += <NUM_LIT:8> ; } if ( tb [ <NUM_LIT:0> ] == - <NUM_LIT:1> ) { } t = hufts [ ( tb [ <NUM_LIT:0> ] + ( b & inflate_mask [ t ] ) ) * <NUM_LIT:3> + <NUM_LIT:1> ] ; c = hufts [ ( tb [ <NUM_LIT:0> ] + ( b & inflate_mask [ t ] ) ) * <NUM_LIT:3> + <NUM_LIT:2> ] ; if ( c < <NUM_LIT:16> ) { b >>>= ( t ) ; k -= ( t ) ; blens [ index ++ ] = c ; } else { i = c == <NUM_LIT> ? <NUM_LIT:7> : c - <NUM_LIT> ; j = c == <NUM_LIT> ? <NUM_LIT:11> : <NUM_LIT:3> ; while ( k < ( t + i ) ) { if ( n != <NUM_LIT: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 ++ ] & <NUM_LIT> ) << k ; k += <NUM_LIT:8> ; } b >>>= ( t ) ; k -= ( t ) ; j += ( b & inflate_mask [ i ] ) ; b >>>= ( i ) ; k -= ( i ) ; i = index ; t = table ; if ( i + j > <NUM_LIT> + ( t & <NUM_LIT> ) + ( ( t > > <NUM_LIT:5> ) & <NUM_LIT> ) || ( c == <NUM_LIT:16> && i < <NUM_LIT:1> ) ) { blens = null ; mode = BAD ; z . msg = "<STR_LIT>" ; 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 == <NUM_LIT:16> ? blens [ i - <NUM_LIT:1> ] : <NUM_LIT:0> ; do { blens [ i ++ ] = c ; } while ( -- j != <NUM_LIT:0> ) ; index = i ; } } tb [ <NUM_LIT:0> ] = - <NUM_LIT:1> ; { int [ ] bl = new int [ <NUM_LIT:1> ] ; int [ ] bd = new int [ <NUM_LIT:1> ] ; int [ ] tl = new int [ <NUM_LIT:1> ] ; int [ ] td = new int [ <NUM_LIT:1> ] ; bl [ <NUM_LIT:0> ] = <NUM_LIT:9> ; bd [ <NUM_LIT:0> ] = <NUM_LIT:6> ; t = table ; t = inftree . inflate_trees_dynamic ( <NUM_LIT> + ( t & <NUM_LIT> ) , <NUM_LIT:1> + ( ( t > > <NUM_LIT:5> ) & <NUM_LIT> ) , 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 [ <NUM_LIT:0> ] , bd [ <NUM_LIT:0> ] , hufts , tl [ <NUM_LIT:0> ] , hufts , td [ <NUM_LIT: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 - <NUM_LIT:1> : end - q ) ; if ( last == <NUM_LIT:0> ) { mode = TYPE ; break ; } mode = DRY ; case DRY : write = q ; r = inflate_flush ( z , r ) ; q = write ; m = ( int ) ( q < read ? read - q - <NUM_LIT: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 , <NUM_LIT:0> , n ) ; read = write = n ; } int sync_point ( ) { return mode == LENS ? <NUM_LIT:1> : <NUM_LIT: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 != <NUM_LIT: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 = <NUM_LIT:0> ; if ( write == end ) write = <NUM_LIT:0> ; n = write - q ; if ( n > z . avail_out ) n = z . avail_out ; if ( n != <NUM_LIT: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>
|
<s> package com . jcraft . jzlib ; final class InfTree { static final private int MANY = <NUM_LIT> ; static final private int Z_OK = <NUM_LIT:0> ; static final private int Z_STREAM_END = <NUM_LIT:1> ; static final private int Z_NEED_DICT = <NUM_LIT:2> ; static final private int Z_ERRNO = - <NUM_LIT:1> ; static final private int Z_STREAM_ERROR = - <NUM_LIT:2> ; static final private int Z_DATA_ERROR = - <NUM_LIT:3> ; static final private int Z_MEM_ERROR = - <NUM_LIT:4> ; static final private int Z_BUF_ERROR = - <NUM_LIT:5> ; static final private int Z_VERSION_ERROR = - <NUM_LIT:6> ; static final int fixed_bl = <NUM_LIT:9> ; static final int fixed_bd = <NUM_LIT:5> ; static final int [ ] fixed_tl = { <NUM_LIT> , <NUM_LIT:7> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT:16> , <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:7> , <NUM_LIT:31> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:7> , <NUM_LIT:10> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT:32> , <NUM_LIT:0> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:7> , <NUM_LIT:6> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT:24> , <NUM_LIT:0> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:7> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:7> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT:8> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:7> , <NUM_LIT:4> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT:20> , <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:7> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:7> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT:100> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT:4> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:7> , <NUM_LIT:8> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:7> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:7> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT:12> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:7> , <NUM_LIT:3> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:7> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:7> , <NUM_LIT:11> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT:2> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:7> , <NUM_LIT:7> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:7> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:7> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT:10> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:7> , <NUM_LIT:5> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT:0> , <NUM_LIT> , <NUM_LIT:7> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:7> , <NUM_LIT:15> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT:6> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:7> , <NUM_LIT:9> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT:30> , <NUM_LIT:0> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:7> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:7> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:7> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:7> , <NUM_LIT:31> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:7> , <NUM_LIT:10> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:7> , <NUM_LIT:6> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:7> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:7> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT:9> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:7> , <NUM_LIT:4> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:7> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:7> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT:5> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:7> , <NUM_LIT:8> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:7> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:7> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:7> , <NUM_LIT:3> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:7> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:7> , <NUM_LIT:11> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT:3> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:7> , <NUM_LIT:7> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:7> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:7> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT:11> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:7> , <NUM_LIT:5> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT:0> , <NUM_LIT> , <NUM_LIT:7> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:7> , <NUM_LIT:15> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT:7> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:7> , <NUM_LIT:9> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT:31> , <NUM_LIT:0> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:7> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:7> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT:15> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:7> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT:16> , <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:7> , <NUM_LIT:31> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:7> , <NUM_LIT:10> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT:32> , <NUM_LIT:0> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:7> , <NUM_LIT:6> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT:24> , <NUM_LIT:0> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:7> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:7> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT:8> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:7> , <NUM_LIT:4> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT:20> , <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:7> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:7> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT:100> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT:4> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:7> , <NUM_LIT:8> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:7> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:7> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT:12> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:7> , <NUM_LIT:3> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:7> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:7> , <NUM_LIT:11> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT:2> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:7> , <NUM_LIT:7> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:7> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:7> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT:10> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:7> , <NUM_LIT:5> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT:0> , <NUM_LIT> , <NUM_LIT:7> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:7> , <NUM_LIT:15> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT:6> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:7> , <NUM_LIT:9> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT:30> , <NUM_LIT:0> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:7> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:7> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:7> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:7> , <NUM_LIT:31> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:7> , <NUM_LIT:10> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT:1> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:7> , <NUM_LIT:6> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:7> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:7> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT:9> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:7> , <NUM_LIT:4> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:7> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:7> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT:5> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:7> , <NUM_LIT:8> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:7> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:7> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:7> , <NUM_LIT:3> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:7> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:7> , <NUM_LIT:11> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT:3> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:7> , <NUM_LIT:7> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:7> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:7> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT:11> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:7> , <NUM_LIT:5> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:8> , <NUM_LIT:0> , <NUM_LIT> , <NUM_LIT:7> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:7> , <NUM_LIT:15> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT:7> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:7> , <NUM_LIT:9> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT:31> , <NUM_LIT:0> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:7> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:7> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT:15> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:8> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:9> , <NUM_LIT:255> } ; static final int [ ] fixed_td = { <NUM_LIT> , <NUM_LIT:5> , <NUM_LIT:1> , <NUM_LIT> , <NUM_LIT:5> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:5> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:5> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:5> , <NUM_LIT:5> , <NUM_LIT> , <NUM_LIT:5> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:5> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:5> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:5> , <NUM_LIT:3> , <NUM_LIT> , <NUM_LIT:5> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:5> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:5> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:5> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT:5> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:5> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:5> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:5> , <NUM_LIT:2> , <NUM_LIT> , <NUM_LIT:5> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:5> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:5> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:5> , <NUM_LIT:7> , <NUM_LIT> , <NUM_LIT:5> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:5> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:5> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:5> , <NUM_LIT:4> , <NUM_LIT> , <NUM_LIT:5> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:5> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:5> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:5> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:5> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:5> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:5> , <NUM_LIT> } ; static final int [ ] cplens = { <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> , <NUM_LIT:6> , <NUM_LIT:7> , <NUM_LIT:8> , <NUM_LIT:9> , <NUM_LIT:10> , <NUM_LIT:11> , <NUM_LIT> , <NUM_LIT:15> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:31> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT:0> , <NUM_LIT:0> } ; static final int [ ] cplext = { <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:2> , <NUM_LIT:2> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:3> , <NUM_LIT:3> , <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:4> , <NUM_LIT:4> , <NUM_LIT:4> , <NUM_LIT:5> , <NUM_LIT:5> , <NUM_LIT:5> , <NUM_LIT:5> , <NUM_LIT:0> , <NUM_LIT> , <NUM_LIT> } ; static final int [ ] cpdist = { <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:5> , <NUM_LIT:7> , <NUM_LIT:9> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> } ; static final int [ ] cpdext = { <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:0> , <NUM_LIT:1> , <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:2> , <NUM_LIT:3> , <NUM_LIT:3> , <NUM_LIT:4> , <NUM_LIT:4> , <NUM_LIT:5> , <NUM_LIT:5> , <NUM_LIT:6> , <NUM_LIT:6> , <NUM_LIT:7> , <NUM_LIT:7> , <NUM_LIT:8> , <NUM_LIT:8> , <NUM_LIT:9> , <NUM_LIT:9> , <NUM_LIT:10> , <NUM_LIT:10> , <NUM_LIT:11> , <NUM_LIT:11> , <NUM_LIT:12> , <NUM_LIT:12> , <NUM_LIT> , <NUM_LIT> } ; static final int BMAX = <NUM_LIT: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 = <NUM_LIT:0> ; i = n ; do { c [ b [ bindex + p ] ] ++ ; p ++ ; i -- ; } while ( i != <NUM_LIT:0> ) ; if ( c [ <NUM_LIT:0> ] == n ) { t [ <NUM_LIT:0> ] = - <NUM_LIT:1> ; m [ <NUM_LIT:0> ] = <NUM_LIT:0> ; return Z_OK ; } l = m [ <NUM_LIT:0> ] ; for ( j = <NUM_LIT:1> ; j <= BMAX ; j ++ ) if ( c [ j ] != <NUM_LIT:0> ) break ; k = j ; if ( l < j ) { l = j ; } for ( i = BMAX ; i != <NUM_LIT:0> ; i -- ) { if ( c [ i ] != <NUM_LIT:0> ) break ; } g = i ; if ( l > i ) { l = i ; } m [ <NUM_LIT:0> ] = l ; for ( y = <NUM_LIT:1> << j ; j < i ; j ++ , y <<= <NUM_LIT:1> ) { if ( ( y -= c [ j ] ) < <NUM_LIT:0> ) { return Z_DATA_ERROR ; } } if ( ( y -= c [ i ] ) < <NUM_LIT:0> ) { return Z_DATA_ERROR ; } c [ i ] += y ; x [ <NUM_LIT:1> ] = j = <NUM_LIT:0> ; p = <NUM_LIT:1> ; xp = <NUM_LIT:2> ; while ( -- i != <NUM_LIT:0> ) { x [ xp ] = ( j += c [ p ] ) ; xp ++ ; p ++ ; } i = <NUM_LIT:0> ; p = <NUM_LIT:0> ; do { if ( ( j = b [ bindex + p ] ) != <NUM_LIT:0> ) { v [ x [ j ] ++ ] = i ; } p ++ ; } while ( ++ i < n ) ; n = x [ g ] ; x [ <NUM_LIT:0> ] = i = <NUM_LIT:0> ; p = <NUM_LIT:0> ; h = - <NUM_LIT:1> ; w = - l ; u [ <NUM_LIT:0> ] = <NUM_LIT:0> ; q = <NUM_LIT:0> ; z = <NUM_LIT:0> ; for ( ; k <= g ; k ++ ) { a = c [ k ] ; while ( a -- != <NUM_LIT:0> ) { while ( k > w + l ) { h ++ ; w += l ; z = g - w ; z = ( z > l ) ? l : z ; if ( ( f = <NUM_LIT:1> << ( j = k - w ) ) > a + <NUM_LIT:1> ) { f -= a + <NUM_LIT:1> ; xp = k ; if ( j < z ) { while ( ++ j < z ) { if ( ( f <<= <NUM_LIT:1> ) <= c [ ++ xp ] ) break ; f -= c [ xp ] ; } } } z = <NUM_LIT:1> << j ; if ( hn [ <NUM_LIT:0> ] + z > MANY ) { return Z_DATA_ERROR ; } u [ h ] = q = hn [ <NUM_LIT:0> ] ; hn [ <NUM_LIT:0> ] += z ; if ( h != <NUM_LIT:0> ) { x [ h ] = i ; r [ <NUM_LIT:0> ] = ( byte ) j ; r [ <NUM_LIT:1> ] = ( byte ) l ; j = i > > > ( w - l ) ; r [ <NUM_LIT:2> ] = ( int ) ( q - u [ h - <NUM_LIT:1> ] - j ) ; System . arraycopy ( r , <NUM_LIT:0> , hp , ( u [ h - <NUM_LIT:1> ] + j ) * <NUM_LIT:3> , <NUM_LIT:3> ) ; } else { t [ <NUM_LIT:0> ] = q ; } } r [ <NUM_LIT:1> ] = ( byte ) ( k - w ) ; if ( p >= n ) { r [ <NUM_LIT:0> ] = <NUM_LIT> + <NUM_LIT> ; } else if ( v [ p ] < s ) { r [ <NUM_LIT:0> ] = ( byte ) ( v [ p ] < <NUM_LIT> ? <NUM_LIT:0> : <NUM_LIT:32> + <NUM_LIT> ) ; r [ <NUM_LIT:2> ] = v [ p ++ ] ; } else { r [ <NUM_LIT:0> ] = ( byte ) ( e [ v [ p ] - s ] + <NUM_LIT:16> + <NUM_LIT> ) ; r [ <NUM_LIT:2> ] = d [ v [ p ++ ] - s ] ; } f = <NUM_LIT:1> << ( k - w ) ; for ( j = i > > > w ; j < z ; j += f ) { System . arraycopy ( r , <NUM_LIT:0> , hp , ( q + j ) * <NUM_LIT:3> , <NUM_LIT:3> ) ; } for ( j = <NUM_LIT:1> << ( k - <NUM_LIT:1> ) ; ( i & j ) != <NUM_LIT:0> ; j >>>= <NUM_LIT:1> ) { i ^= j ; } i ^= j ; mask = ( <NUM_LIT:1> << w ) - <NUM_LIT:1> ; while ( ( i & mask ) != x [ h ] ) { h -- ; w -= l ; mask = ( <NUM_LIT:1> << w ) - <NUM_LIT:1> ; } } } return y != <NUM_LIT:0> && g != <NUM_LIT:1> ? Z_BUF_ERROR : Z_OK ; } int inflate_trees_bits ( int [ ] c , int [ ] bb , int [ ] tb , int [ ] hp , ZStream z ) { int result ; initWorkArea ( <NUM_LIT> ) ; hn [ <NUM_LIT:0> ] = <NUM_LIT:0> ; result = huft_build ( c , <NUM_LIT:0> , <NUM_LIT> , <NUM_LIT> , null , null , tb , bb , hp , hn , v ) ; if ( result == Z_DATA_ERROR ) { z . msg = "<STR_LIT>" ; } else if ( result == Z_BUF_ERROR || bb [ <NUM_LIT:0> ] == <NUM_LIT:0> ) { z . msg = "<STR_LIT>" ; 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 ( <NUM_LIT> ) ; hn [ <NUM_LIT:0> ] = <NUM_LIT:0> ; result = huft_build ( c , <NUM_LIT:0> , nl , <NUM_LIT> , cplens , cplext , tl , bl , hp , hn , v ) ; if ( result != Z_OK || bl [ <NUM_LIT:0> ] == <NUM_LIT:0> ) { if ( result == Z_DATA_ERROR ) { z . msg = "<STR_LIT>" ; } else if ( result != Z_MEM_ERROR ) { z . msg = "<STR_LIT>" ; result = Z_DATA_ERROR ; } return result ; } initWorkArea ( <NUM_LIT> ) ; result = huft_build ( c , nl , nd , <NUM_LIT:0> , cpdist , cpdext , td , bd , hp , hn , v ) ; if ( result != Z_OK || ( bd [ <NUM_LIT:0> ] == <NUM_LIT:0> && nl > <NUM_LIT> ) ) { if ( result == Z_DATA_ERROR ) { z . msg = "<STR_LIT>" ; } else if ( result == Z_BUF_ERROR ) { z . msg = "<STR_LIT>" ; result = Z_DATA_ERROR ; } else if ( result != Z_MEM_ERROR ) { z . msg = "<STR_LIT>" ; 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 [ <NUM_LIT:0> ] = fixed_bl ; bd [ <NUM_LIT:0> ] = fixed_bd ; tl [ <NUM_LIT:0> ] = fixed_tl ; td [ <NUM_LIT:0> ] = fixed_td ; return Z_OK ; } private void initWorkArea ( int vsize ) { if ( hn == null ) { hn = new int [ <NUM_LIT:1> ] ; v = new int [ vsize ] ; c = new int [ BMAX + <NUM_LIT:1> ] ; r = new int [ <NUM_LIT:3> ] ; u = new int [ BMAX ] ; x = new int [ BMAX + <NUM_LIT:1> ] ; } if ( v . length < vsize ) { v = new int [ vsize ] ; } for ( int i = <NUM_LIT:0> ; i < vsize ; i ++ ) { v [ i ] = <NUM_LIT:0> ; } for ( int i = <NUM_LIT:0> ; i < BMAX + <NUM_LIT:1> ; i ++ ) { c [ i ] = <NUM_LIT:0> ; } for ( int i = <NUM_LIT:0> ; i < <NUM_LIT:3> ; i ++ ) { r [ i ] = <NUM_LIT:0> ; } System . arraycopy ( c , <NUM_LIT:0> , u , <NUM_LIT:0> , BMAX ) ; System . arraycopy ( c , <NUM_LIT:0> , x , <NUM_LIT:0> , BMAX + <NUM_LIT:1> ) ; } } </s>
|
<s> package com . jcraft . jzlib ; import java . io . * ; public class ZOutputStream extends OutputStream { protected ZStream z = new ZStream ( ) ; protected int bufsize = <NUM_LIT> ; protected int flush = JZlib . Z_NO_FLUSH ; protected byte [ ] buf = new byte [ bufsize ] , buf1 = new byte [ <NUM_LIT: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 [ <NUM_LIT:0> ] = ( byte ) b ; write ( buf1 , <NUM_LIT:0> , <NUM_LIT:1> ) ; } public void write ( byte b [ ] , int off , int len ) throws IOException { if ( len == <NUM_LIT: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 = <NUM_LIT: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 ? "<STR_LIT>" : "<STR_LIT>" ) + "<STR_LIT>" + z . msg ) ; out . write ( buf , <NUM_LIT:0> , bufsize - z . avail_out ) ; } while ( z . avail_in > <NUM_LIT:0> || z . avail_out == <NUM_LIT: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 = <NUM_LIT: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 ? "<STR_LIT>" : "<STR_LIT>" ) + "<STR_LIT>" + z . msg ) ; if ( bufsize - z . avail_out > <NUM_LIT:0> ) { out . write ( buf , <NUM_LIT:0> , bufsize - z . avail_out ) ; } } while ( z . avail_in > <NUM_LIT:0> || z . avail_out == <NUM_LIT: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>
|
<s> package com . jcraft . jzlib ; final public class ZStream { static final private int MAX_WBITS = <NUM_LIT:15> ; static final private int DEF_WBITS = MAX_WBITS ; static final private int Z_NO_FLUSH = <NUM_LIT:0> ; static final private int Z_PARTIAL_FLUSH = <NUM_LIT:1> ; static final private int Z_SYNC_FLUSH = <NUM_LIT:2> ; static final private int Z_FULL_FLUSH = <NUM_LIT:3> ; static final private int Z_FINISH = <NUM_LIT:4> ; static final private int MAX_MEM_LEVEL = <NUM_LIT:9> ; static public final int Z_OK = <NUM_LIT:0> ; static public final int Z_STREAM_END = <NUM_LIT:1> ; static public final int Z_NEED_DICT = <NUM_LIT:2> ; static public final int Z_ERRNO = - <NUM_LIT:1> ; static public final int Z_STREAM_ERROR = - <NUM_LIT:2> ; static public final int Z_DATA_ERROR = - <NUM_LIT:3> ; static public final int Z_MEM_ERROR = - <NUM_LIT:4> ; static public final int Z_BUF_ERROR = - <NUM_LIT:5> ; static public final int Z_VERSION_ERROR = - <NUM_LIT: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 == <NUM_LIT: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 + "<STR_LIT:U+002CU+0020>" + dstate . pending_out + "<STR_LIT:U+002CU+0020>" + next_out . length + "<STR_LIT:U+002CU+0020>" + next_out_index + "<STR_LIT:U+002CU+0020>" + len ) ; System . out . println ( "<STR_LIT>" + 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 == <NUM_LIT:0> ) { dstate . pending_out = <NUM_LIT:0> ; } } int read_buf ( byte [ ] buf , int start , int size ) { int len = avail_in ; if ( len > size ) len = size ; if ( len == <NUM_LIT:0> ) return <NUM_LIT:0> ; avail_in -= len ; if ( dstate . noheader == <NUM_LIT: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>
|
<s> package com . jcraft . jzlib ; final class Inflate { static final private int MAX_WBITS = <NUM_LIT:15> ; static final private int PRESET_DICT = <NUM_LIT> ; static final int Z_NO_FLUSH = <NUM_LIT:0> ; static final int Z_PARTIAL_FLUSH = <NUM_LIT:1> ; static final int Z_SYNC_FLUSH = <NUM_LIT:2> ; static final int Z_FULL_FLUSH = <NUM_LIT:3> ; static final int Z_FINISH = <NUM_LIT:4> ; static final private int Z_DEFLATED = <NUM_LIT:8> ; static final private int Z_OK = <NUM_LIT:0> ; static final private int Z_STREAM_END = <NUM_LIT:1> ; static final private int Z_NEED_DICT = <NUM_LIT:2> ; static final private int Z_ERRNO = - <NUM_LIT:1> ; static final private int Z_STREAM_ERROR = - <NUM_LIT:2> ; static final private int Z_DATA_ERROR = - <NUM_LIT:3> ; static final private int Z_MEM_ERROR = - <NUM_LIT:4> ; static final private int Z_BUF_ERROR = - <NUM_LIT:5> ; static final private int Z_VERSION_ERROR = - <NUM_LIT:6> ; static final private int METHOD = <NUM_LIT:0> ; static final private int FLAG = <NUM_LIT:1> ; static final private int DICT4 = <NUM_LIT:2> ; static final private int DICT3 = <NUM_LIT:3> ; static final private int DICT2 = <NUM_LIT:4> ; static final private int DICT1 = <NUM_LIT:5> ; static final private int DICT0 = <NUM_LIT:6> ; static final private int BLOCKS = <NUM_LIT:7> ; static final private int CHECK4 = <NUM_LIT:8> ; static final private int CHECK3 = <NUM_LIT:9> ; static final private int CHECK2 = <NUM_LIT:10> ; static final private int CHECK1 = <NUM_LIT:11> ; static final private int DONE = <NUM_LIT:12> ; static final private int BAD = <NUM_LIT> ; int mode ; int method ; long [ ] was = new long [ <NUM_LIT: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 = <NUM_LIT:0> ; z . msg = null ; z . istate . mode = z . istate . nowrap != <NUM_LIT: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 = <NUM_LIT:0> ; if ( w < <NUM_LIT:0> ) { w = - w ; nowrap = <NUM_LIT:1> ; } if ( w < <NUM_LIT:8> || w > <NUM_LIT:15> ) { inflateEnd ( z ) ; return Z_STREAM_ERROR ; } wbits = w ; z . istate . blocks = new InfBlocks ( z , z . istate . nowrap != <NUM_LIT:0> ? null : this , <NUM_LIT: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 == <NUM_LIT:0> ) return r ; r = f ; z . avail_in -- ; z . total_in ++ ; if ( ( ( z . istate . method = z . next_in [ z . next_in_index ++ ] ) & <NUM_LIT> ) != Z_DEFLATED ) { z . istate . mode = BAD ; z . msg = "<STR_LIT>" ; z . istate . marker = <NUM_LIT:5> ; break ; } if ( ( z . istate . method > > <NUM_LIT:4> ) + <NUM_LIT:8> > z . istate . wbits ) { z . istate . mode = BAD ; z . msg = "<STR_LIT>" ; z . istate . marker = <NUM_LIT:5> ; break ; } z . istate . mode = FLAG ; case FLAG : if ( z . avail_in == <NUM_LIT:0> ) return r ; r = f ; z . avail_in -- ; z . total_in ++ ; b = ( z . next_in [ z . next_in_index ++ ] ) & <NUM_LIT> ; if ( ( ( ( z . istate . method << <NUM_LIT:8> ) + b ) % <NUM_LIT:31> ) != <NUM_LIT:0> ) { z . istate . mode = BAD ; z . msg = "<STR_LIT>" ; z . istate . marker = <NUM_LIT:5> ; break ; } if ( ( b & PRESET_DICT ) == <NUM_LIT:0> ) { z . istate . mode = BLOCKS ; break ; } z . istate . mode = DICT4 ; case DICT4 : if ( z . avail_in == <NUM_LIT:0> ) return r ; r = f ; z . avail_in -- ; z . total_in ++ ; z . istate . need = ( ( z . next_in [ z . next_in_index ++ ] & <NUM_LIT> ) << <NUM_LIT:24> ) & <NUM_LIT> ; z . istate . mode = DICT3 ; case DICT3 : if ( z . avail_in == <NUM_LIT:0> ) return r ; r = f ; z . avail_in -- ; z . total_in ++ ; z . istate . need += ( ( z . next_in [ z . next_in_index ++ ] & <NUM_LIT> ) << <NUM_LIT:16> ) & <NUM_LIT> ; z . istate . mode = DICT2 ; case DICT2 : if ( z . avail_in == <NUM_LIT:0> ) return r ; r = f ; z . avail_in -- ; z . total_in ++ ; z . istate . need += ( ( z . next_in [ z . next_in_index ++ ] & <NUM_LIT> ) << <NUM_LIT:8> ) & <NUM_LIT> ; z . istate . mode = DICT1 ; case DICT1 : if ( z . avail_in == <NUM_LIT:0> ) return r ; r = f ; z . avail_in -- ; z . total_in ++ ; z . istate . need += ( z . next_in [ z . next_in_index ++ ] & <NUM_LIT> ) ; z . adler = z . istate . need ; z . istate . mode = DICT0 ; return Z_NEED_DICT ; case DICT0 : z . istate . mode = BAD ; z . msg = "<STR_LIT>" ; z . istate . marker = <NUM_LIT: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 = <NUM_LIT: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 != <NUM_LIT:0> ) { z . istate . mode = DONE ; break ; } z . istate . mode = CHECK4 ; case CHECK4 : if ( z . avail_in == <NUM_LIT:0> ) return r ; r = f ; z . avail_in -- ; z . total_in ++ ; z . istate . need = ( ( z . next_in [ z . next_in_index ++ ] & <NUM_LIT> ) << <NUM_LIT:24> ) & <NUM_LIT> ; z . istate . mode = CHECK3 ; case CHECK3 : if ( z . avail_in == <NUM_LIT:0> ) return r ; r = f ; z . avail_in -- ; z . total_in ++ ; z . istate . need += ( ( z . next_in [ z . next_in_index ++ ] & <NUM_LIT> ) << <NUM_LIT:16> ) & <NUM_LIT> ; z . istate . mode = CHECK2 ; case CHECK2 : if ( z . avail_in == <NUM_LIT:0> ) return r ; r = f ; z . avail_in -- ; z . total_in ++ ; z . istate . need += ( ( z . next_in [ z . next_in_index ++ ] & <NUM_LIT> ) << <NUM_LIT:8> ) & <NUM_LIT> ; z . istate . mode = CHECK1 ; case CHECK1 : if ( z . avail_in == <NUM_LIT:0> ) return r ; r = f ; z . avail_in -- ; z . total_in ++ ; z . istate . need += ( z . next_in [ z . next_in_index ++ ] & <NUM_LIT> ) ; if ( ( ( int ) ( z . istate . was [ <NUM_LIT:0> ] ) ) != ( ( int ) ( z . istate . need ) ) ) { z . istate . mode = BAD ; z . msg = "<STR_LIT>" ; z . istate . marker = <NUM_LIT: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 = <NUM_LIT:0> ; int length = dictLength ; if ( z == null || z . istate == null || z . istate . mode != DICT0 ) return Z_STREAM_ERROR ; if ( z . _adler . adler32 ( <NUM_LIT:1L> , dictionary , <NUM_LIT:0> , dictLength ) != z . adler ) { return Z_DATA_ERROR ; } z . adler = z . _adler . adler32 ( <NUM_LIT:0> , null , <NUM_LIT:0> , <NUM_LIT:0> ) ; if ( length >= ( <NUM_LIT:1> << z . istate . wbits ) ) { length = ( <NUM_LIT:1> << z . istate . wbits ) - <NUM_LIT:1> ; index = dictLength - length ; } z . istate . blocks . set_dictionary ( dictionary , index , length ) ; z . istate . mode = BLOCKS ; return Z_OK ; } static private byte [ ] mark = { ( byte ) <NUM_LIT:0> , ( byte ) <NUM_LIT:0> , ( byte ) <NUM_LIT> , ( byte ) <NUM_LIT> } ; 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 = <NUM_LIT:0> ; } if ( ( n = z . avail_in ) == <NUM_LIT:0> ) return Z_BUF_ERROR ; p = z . next_in_index ; m = z . istate . marker ; while ( n != <NUM_LIT:0> && m < <NUM_LIT:4> ) { if ( z . next_in [ p ] == mark [ m ] ) { m ++ ; } else if ( z . next_in [ p ] != <NUM_LIT:0> ) { m = <NUM_LIT:0> ; } else { m = <NUM_LIT: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 != <NUM_LIT: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>
|
<s> package com . jcraft . jzlib ; final class InfCodes { static final private int [ ] inflate_mask = { <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> , <NUM_LIT> } ; static final private int Z_OK = <NUM_LIT:0> ; static final private int Z_STREAM_END = <NUM_LIT:1> ; static final private int Z_NEED_DICT = <NUM_LIT:2> ; static final private int Z_ERRNO = - <NUM_LIT:1> ; static final private int Z_STREAM_ERROR = - <NUM_LIT:2> ; static final private int Z_DATA_ERROR = - <NUM_LIT:3> ; static final private int Z_MEM_ERROR = - <NUM_LIT:4> ; static final private int Z_BUF_ERROR = - <NUM_LIT:5> ; static final private int Z_VERSION_ERROR = - <NUM_LIT:6> ; static final private int START = <NUM_LIT:0> ; static final private int LEN = <NUM_LIT:1> ; static final private int LENEXT = <NUM_LIT:2> ; static final private int DIST = <NUM_LIT:3> ; static final private int DISTEXT = <NUM_LIT:4> ; static final private int COPY = <NUM_LIT:5> ; static final private int LIT = <NUM_LIT:6> ; static final private int WASH = <NUM_LIT:7> ; static final private int END = <NUM_LIT:8> ; static final private int BADCODE = <NUM_LIT:9> ; int mode ; int len ; int [ ] tree ; int tree_index = <NUM_LIT: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 = <NUM_LIT:0> ; int k = <NUM_LIT:0> ; int p = <NUM_LIT: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 - <NUM_LIT:1> : s . end - q ; while ( true ) { switch ( mode ) { case START : if ( m >= <NUM_LIT> && n >= <NUM_LIT: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 - <NUM_LIT: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 != <NUM_LIT: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 ++ ] & <NUM_LIT> ) << k ; k += <NUM_LIT:8> ; } tindex = ( tree_index + ( b & inflate_mask [ j ] ) ) * <NUM_LIT:3> ; b >>>= ( tree [ tindex + <NUM_LIT:1> ] ) ; k -= ( tree [ tindex + <NUM_LIT:1> ] ) ; e = tree [ tindex ] ; if ( e == <NUM_LIT:0> ) { lit = tree [ tindex + <NUM_LIT:2> ] ; mode = LIT ; break ; } if ( ( e & <NUM_LIT:16> ) != <NUM_LIT:0> ) { get = e & <NUM_LIT:15> ; len = tree [ tindex + <NUM_LIT:2> ] ; mode = LENEXT ; break ; } if ( ( e & <NUM_LIT> ) == <NUM_LIT:0> ) { need = e ; tree_index = tindex / <NUM_LIT:3> + tree [ tindex + <NUM_LIT:2> ] ; break ; } if ( ( e & <NUM_LIT:32> ) != <NUM_LIT:0> ) { mode = WASH ; break ; } mode = BADCODE ; z . msg = "<STR_LIT>" ; 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 != <NUM_LIT: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 ++ ] & <NUM_LIT> ) << k ; k += <NUM_LIT: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 != <NUM_LIT: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 ++ ] & <NUM_LIT> ) << k ; k += <NUM_LIT:8> ; } tindex = ( tree_index + ( b & inflate_mask [ j ] ) ) * <NUM_LIT:3> ; b >>= tree [ tindex + <NUM_LIT:1> ] ; k -= tree [ tindex + <NUM_LIT:1> ] ; e = ( tree [ tindex ] ) ; if ( ( e & <NUM_LIT:16> ) != <NUM_LIT:0> ) { get = e & <NUM_LIT:15> ; dist = tree [ tindex + <NUM_LIT:2> ] ; mode = DISTEXT ; break ; } if ( ( e & <NUM_LIT> ) == <NUM_LIT:0> ) { need = e ; tree_index = tindex / <NUM_LIT:3> + tree [ tindex + <NUM_LIT:2> ] ; break ; } mode = BADCODE ; z . msg = "<STR_LIT>" ; 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 != <NUM_LIT: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 ++ ] & <NUM_LIT> ) << k ; k += <NUM_LIT:8> ; } dist += ( b & inflate_mask [ j ] ) ; b >>= j ; k -= j ; mode = COPY ; case COPY : f = q - dist ; while ( f < <NUM_LIT:0> ) { f += s . end ; } while ( len != <NUM_LIT:0> ) { if ( m == <NUM_LIT:0> ) { if ( q == s . end && s . read != <NUM_LIT:0> ) { q = <NUM_LIT:0> ; m = q < s . read ? s . read - q - <NUM_LIT:1> : s . end - q ; } if ( m == <NUM_LIT:0> ) { s . write = q ; r = s . inflate_flush ( z , r ) ; q = s . write ; m = q < s . read ? s . read - q - <NUM_LIT:1> : s . end - q ; if ( q == s . end && s . read != <NUM_LIT:0> ) { q = <NUM_LIT:0> ; m = q < s . read ? s . read - q - <NUM_LIT:1> : s . end - q ; } if ( m == <NUM_LIT: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 = <NUM_LIT:0> ; len -- ; } mode = START ; break ; case LIT : if ( m == <NUM_LIT:0> ) { if ( q == s . end && s . read != <NUM_LIT:0> ) { q = <NUM_LIT:0> ; m = q < s . read ? s . read - q - <NUM_LIT:1> : s . end - q ; } if ( m == <NUM_LIT:0> ) { s . write = q ; r = s . inflate_flush ( z , r ) ; q = s . write ; m = q < s . read ? s . read - q - <NUM_LIT:1> : s . end - q ; if ( q == s . end && s . read != <NUM_LIT:0> ) { q = <NUM_LIT:0> ; m = q < s . read ? s . read - q - <NUM_LIT:1> : s . end - q ; } if ( m == <NUM_LIT: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 > <NUM_LIT:7> ) { k -= <NUM_LIT:8> ; n ++ ; p -- ; } s . write = q ; r = s . inflate_flush ( z , r ) ; q = s . write ; m = q < s . read ? s . read - q - <NUM_LIT: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 - <NUM_LIT:1> : s . end - q ; ml = inflate_mask [ bl ] ; md = inflate_mask [ bd ] ; do { while ( k < ( <NUM_LIT:20> ) ) { n -- ; b |= ( z . next_in [ p ++ ] & <NUM_LIT> ) << k ; k += <NUM_LIT:8> ; } t = b & ml ; tp = tl ; tp_index = tl_index ; tp_index_t_3 = ( tp_index + t ) * <NUM_LIT:3> ; if ( ( e = tp [ tp_index_t_3 ] ) == <NUM_LIT:0> ) { b >>= ( tp [ tp_index_t_3 + <NUM_LIT:1> ] ) ; k -= ( tp [ tp_index_t_3 + <NUM_LIT:1> ] ) ; s . window [ q ++ ] = ( byte ) tp [ tp_index_t_3 + <NUM_LIT:2> ] ; m -- ; continue ; } do { b >>= ( tp [ tp_index_t_3 + <NUM_LIT:1> ] ) ; k -= ( tp [ tp_index_t_3 + <NUM_LIT:1> ] ) ; if ( ( e & <NUM_LIT:16> ) != <NUM_LIT:0> ) { e &= <NUM_LIT:15> ; c = tp [ tp_index_t_3 + <NUM_LIT:2> ] + ( ( int ) b & inflate_mask [ e ] ) ; b >>= e ; k -= e ; while ( k < ( <NUM_LIT:15> ) ) { n -- ; b |= ( z . next_in [ p ++ ] & <NUM_LIT> ) << k ; k += <NUM_LIT:8> ; } t = b & md ; tp = td ; tp_index = td_index ; tp_index_t_3 = ( tp_index + t ) * <NUM_LIT:3> ; e = tp [ tp_index_t_3 ] ; do { b >>= ( tp [ tp_index_t_3 + <NUM_LIT:1> ] ) ; k -= ( tp [ tp_index_t_3 + <NUM_LIT:1> ] ) ; if ( ( e & <NUM_LIT:16> ) != <NUM_LIT:0> ) { e &= <NUM_LIT:15> ; while ( k < ( e ) ) { n -- ; b |= ( z . next_in [ p ++ ] & <NUM_LIT> ) << k ; k += <NUM_LIT:8> ; } d = tp [ tp_index_t_3 + <NUM_LIT:2> ] + ( b & inflate_mask [ e ] ) ; b >>= ( e ) ; k -= ( e ) ; m -= c ; if ( q >= d ) { r = q - d ; if ( q - r > <NUM_LIT:0> && <NUM_LIT:2> > ( q - r ) ) { s . window [ q ++ ] = s . window [ r ++ ] ; s . window [ q ++ ] = s . window [ r ++ ] ; c -= <NUM_LIT:2> ; } else { System . arraycopy ( s . window , r , s . window , q , <NUM_LIT:2> ) ; q += <NUM_LIT:2> ; r += <NUM_LIT:2> ; c -= <NUM_LIT:2> ; } } else { r = q - d ; do { r += s . end ; } while ( r < <NUM_LIT:0> ) ; e = s . end - r ; if ( c > e ) { c -= e ; if ( q - r > <NUM_LIT:0> && e > ( q - r ) ) { do { s . window [ q ++ ] = s . window [ r ++ ] ; } while ( -- e != <NUM_LIT:0> ) ; } else { System . arraycopy ( s . window , r , s . window , q , e ) ; q += e ; r += e ; e = <NUM_LIT:0> ; } r = <NUM_LIT:0> ; } } if ( q - r > <NUM_LIT:0> && c > ( q - r ) ) { do { s . window [ q ++ ] = s . window [ r ++ ] ; } while ( -- c != <NUM_LIT:0> ) ; } else { System . arraycopy ( s . window , r , s . window , q , c ) ; q += c ; r += c ; c = <NUM_LIT:0> ; } break ; } else if ( ( e & <NUM_LIT> ) == <NUM_LIT:0> ) { t += tp [ tp_index_t_3 + <NUM_LIT:2> ] ; t += ( b & inflate_mask [ e ] ) ; tp_index_t_3 = ( tp_index + t ) * <NUM_LIT:3> ; e = tp [ tp_index_t_3 ] ; } else { z . msg = "<STR_LIT>" ; c = z . avail_in - n ; c = ( k > > <NUM_LIT:3> ) < c ? k > > <NUM_LIT:3> : c ; n += c ; p -= c ; k -= c << <NUM_LIT: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 & <NUM_LIT> ) == <NUM_LIT:0> ) { t += tp [ tp_index_t_3 + <NUM_LIT:2> ] ; t += ( b & inflate_mask [ e ] ) ; tp_index_t_3 = ( tp_index + t ) * <NUM_LIT:3> ; if ( ( e = tp [ tp_index_t_3 ] ) == <NUM_LIT:0> ) { b >>= ( tp [ tp_index_t_3 + <NUM_LIT:1> ] ) ; k -= ( tp [ tp_index_t_3 + <NUM_LIT:1> ] ) ; s . window [ q ++ ] = ( byte ) tp [ tp_index_t_3 + <NUM_LIT:2> ] ; m -- ; break ; } } else if ( ( e & <NUM_LIT:32> ) != <NUM_LIT:0> ) { c = z . avail_in - n ; c = ( k > > <NUM_LIT:3> ) < c ? k > > <NUM_LIT:3> : c ; n += c ; p -= c ; k -= c << <NUM_LIT: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 = "<STR_LIT>" ; c = z . avail_in - n ; c = ( k > > <NUM_LIT:3> ) < c ? k > > <NUM_LIT:3> : c ; n += c ; p -= c ; k -= c << <NUM_LIT: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 >= <NUM_LIT> && n >= <NUM_LIT:10> ) ; c = z . avail_in - n ; c = ( k > > <NUM_LIT:3> ) < c ? k > > <NUM_LIT:3> : c ; n += c ; p -= c ; k -= c << <NUM_LIT: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>
|
<s> package com . jcraft . jzlib ; final public class JZlib { private static final String version = "<STR_LIT>" ; public static String version ( ) { return version ; } static final public int Z_NO_COMPRESSION = <NUM_LIT:0> ; static final public int Z_BEST_SPEED = <NUM_LIT:1> ; static final public int Z_BEST_COMPRESSION = <NUM_LIT:9> ; static final public int Z_DEFAULT_COMPRESSION = ( - <NUM_LIT:1> ) ; static final public int Z_FILTERED = <NUM_LIT:1> ; static final public int Z_HUFFMAN_ONLY = <NUM_LIT:2> ; static final public int Z_DEFAULT_STRATEGY = <NUM_LIT:0> ; static final public int Z_NO_FLUSH = <NUM_LIT:0> ; static final public int Z_PARTIAL_FLUSH = <NUM_LIT:1> ; static final public int Z_SYNC_FLUSH = <NUM_LIT:2> ; static final public int Z_FULL_FLUSH = <NUM_LIT:3> ; static final public int Z_FINISH = <NUM_LIT:4> ; static final public int Z_OK = <NUM_LIT:0> ; static final public int Z_STREAM_END = <NUM_LIT:1> ; static final public int Z_NEED_DICT = <NUM_LIT:2> ; static final public int Z_ERRNO = - <NUM_LIT:1> ; static final public int Z_STREAM_ERROR = - <NUM_LIT:2> ; static final public int Z_DATA_ERROR = - <NUM_LIT:3> ; static final public int Z_MEM_ERROR = - <NUM_LIT:4> ; static final public int Z_BUF_ERROR = - <NUM_LIT:5> ; static final public int Z_VERSION_ERROR = - <NUM_LIT:6> ; } </s>
|
<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 ( "<STR_LIT>" ) ; protected static final byte passThrough = ( byte ) <NUM_LIT> ; protected static final byte distHeader = ( byte ) <NUM_LIT> ; protected static final byte version = ( byte ) <NUM_LIT> ; protected static final int LINK = <NUM_LIT:1> ; protected static final int SEND = <NUM_LIT:2> ; protected static final int EXIT = <NUM_LIT:3> ; protected static final int UNLINK = <NUM_LIT:4> ; protected static final int NODE_LINK = <NUM_LIT:5> ; protected static final int REG_SEND = <NUM_LIT:6> ; protected static final int GROUP_LEADER = <NUM_LIT:7> ; protected static final int EXIT2 = <NUM_LIT:8> ; protected static final int SEND_TT = <NUM_LIT:12> ; protected static final int EXIT_TT = <NUM_LIT> ; protected static final int REG_SEND_TT = <NUM_LIT:16> ; protected static final int EXIT2_TT = <NUM_LIT> ; protected static final int MONITOR_P = <NUM_LIT> ; protected static final int DEMONITOR_P = <NUM_LIT:20> ; protected static final int MONITOR_P_EXIT = <NUM_LIT> ; private static final EAtom am_ = EAtom . intern ( "<STR_LIT>" ) ; 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 == <NUM_LIT:5> ? NTYPE_R6 : <NUM_LIT: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 ( "<STR_LIT>" + port + "<STR_LIT>" + this + "<STR_LIT>" + sender + "<STR_LIT:)>" ) ; } } 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 ( "<STR_LIT>" + peer . port + "<STR_LIT>" + port + "<STR_LIT:)>" ) ; } 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 [ <NUM_LIT:8> ] [ ] ; for ( int i = <NUM_LIT:0> ; i < <NUM_LIT:8> ; i ++ ) { atom_cache [ i ] = new EAtom [ <NUM_LIT> ] ; } } public void net_message2 ( EInternalPort port , ByteBuffer hdr , ByteBuffer buf ) throws IOException , Pausable { if ( buf . remaining ( ) == <NUM_LIT:0> ) { log . fine ( "<STR_LIT>" + this . node ) ; return ; } if ( hdr != null && hdr . remaining ( ) != <NUM_LIT: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 <NUM_LIT> : 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 ( "<STR_LIT>" + tmp ) ; } ESmall tag_sm ; if ( ( tag_sm = head . elm ( <NUM_LIT:1> ) . testSmall ( ) ) == null ) { break receive_loop ; } tag = tag_sm . value ; switch ( tag ) { case LINK : { EPID from_pid = head . elm ( <NUM_LIT:2> ) . testPID ( ) ; EInternalPID to_pid = head . elm ( <NUM_LIT: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 ( <NUM_LIT:2> ) . testPID ( ) ; EInternalPID to_pid = head . elm ( <NUM_LIT: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 ( "<STR_LIT>" + msg ) ; EHandle dst = head . elm ( <NUM_LIT:3> ) . testHandle ( ) ; if ( dst == null ) throw new IOException ( "<STR_LIT>" ) ; 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 ( "<STR_LIT>" + msg ) ; EAtom toname = head . elm ( <NUM_LIT:4> ) . testAtom ( ) ; if ( toname == null ) throw new IOException ( "<STR_LIT>" ) ; EHandle dst = ERT . whereis ( toname ) . testHandle ( ) ; if ( dst != null ) { dst . sendb ( msg ) ; } return ; } case EXIT : case EXIT2 : { EPID from_pid = head . elm ( <NUM_LIT:2> ) . testPID ( ) ; EPID to_proc = head . elm ( <NUM_LIT:3> ) . testPID ( ) ; reason = head . elm ( <NUM_LIT:4> ) ; to_proc . exit_signal ( from_pid , reason , false ) ; return ; } case MONITOR_P : { EPID from_pid = head . elm ( <NUM_LIT:2> ) . testPID ( ) ; EPID to_proc = head . elm ( <NUM_LIT:3> ) . testPID ( ) ; ERef ref = head . elm ( <NUM_LIT:4> ) . testReference ( ) ; if ( to_proc == null ) { EAtom am = head . elm ( <NUM_LIT:3> ) . testAtom ( ) ; if ( am == null ) { throw new IOException ( "<STR_LIT>" + head ) ; } to_proc = ERT . whereis ( am ) . testPID ( ) ; } if ( to_proc == null ) { throw new IOException ( "<STR_LIT>" + 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 ( <NUM_LIT:2> ) . testPID ( ) ; EPID to_proc = head . elm ( <NUM_LIT:3> ) . testPID ( ) ; ERef ref = head . elm ( <NUM_LIT:4> ) . testReference ( ) ; if ( to_proc == null ) { EAtom am = head . elm ( <NUM_LIT:3> ) . testAtom ( ) ; if ( am == null ) { throw new IOException ( "<STR_LIT>" + head ) ; } to_proc = ERT . whereis ( am ) . testPID ( ) ; } if ( to_proc == null ) { throw new IOException ( "<STR_LIT>" + head ) ; } to_proc . remove_monitor ( from_pid , ref , false ) ; return ; } case MONITOR_P_EXIT : { EPID from_pid = head . elm ( <NUM_LIT:2> ) . testPID ( ) ; EPID to_proc = head . elm ( <NUM_LIT:3> ) . testPID ( ) ; ERef ref = head . elm ( <NUM_LIT:4> ) . testReference ( ) ; reason = head . elm ( <NUM_LIT:5> ) ; if ( to_proc == null ) { EAtom am = head . elm ( <NUM_LIT:3> ) . testAtom ( ) ; if ( am == null ) { throw new IOException ( "<STR_LIT>" + head ) ; } to_proc = ERT . whereis ( am ) . testPID ( ) ; } if ( to_proc == null ) { throw new IOException ( "<STR_LIT>" + head ) ; } to_proc . send_monitor_exit ( from_pid , ref , reason ) ; return ; } default : throw new NotImplemented ( "<STR_LIT>" + head ) ; } } while ( false ) ; } private boolean process_distribution_header ( EInternalPort port , EInputStream ibuf ) throws IOException { EAtom [ ] atom_cache_refs ; log . fine ( "<STR_LIT>" ) ; int datum = ibuf . read1 ( ) ; if ( datum != <NUM_LIT> ) { close_and_finish ( port ) ; return false ; } int numberOfAtomCacheRefs = ibuf . read1 ( ) & <NUM_LIT> ; atom_cache_refs = new EAtom [ numberOfAtomCacheRefs ] ; if ( numberOfAtomCacheRefs == <NUM_LIT:0> ) { } else { int nflag_bytes = numberOfAtomCacheRefs / <NUM_LIT:2> + <NUM_LIT:1> ; byte [ ] flags = new byte [ nflag_bytes * <NUM_LIT:2> ] ; int pos = <NUM_LIT:0> ; for ( int i = <NUM_LIT:0> ; i < nflag_bytes ; i ++ ) { int twoflags = ibuf . read1 ( ) & <NUM_LIT> ; flags [ pos ++ ] = ( byte ) ( twoflags & <NUM_LIT> ) ; flags [ pos ++ ] = ( byte ) ( twoflags > > > <NUM_LIT:4> ) ; } boolean longAtoms = ( flags [ numberOfAtomCacheRefs ] & <NUM_LIT> ) == <NUM_LIT:1> ; if ( longAtoms ) { log . fine ( "<STR_LIT>" ) ; } for ( int i = <NUM_LIT:0> ; i < numberOfAtomCacheRefs ; i ++ ) { int segment_index = flags [ i ] & <NUM_LIT:7> ; int index = ibuf . read1 ( ) ; if ( log . isLoggable ( Level . FINE ) ) log . fine ( "<STR_LIT>" + i + "<STR_LIT>" + segment_index + "<STR_LIT>" + index + "<STR_LIT:]>" ) ; if ( ( flags [ i ] & <NUM_LIT:8> ) == <NUM_LIT:8> ) { int len = ibuf . read1 ( ) & <NUM_LIT> ; if ( longAtoms ) { len <<= <NUM_LIT:8> ; len |= ( ibuf . read1 ( ) & <NUM_LIT> ) ; } 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 ( "<STR_LIT>" + 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 ( <NUM_LIT:3> ) ; disthdr . put ( ( byte ) <NUM_LIT> ) ; disthdr . put ( ( byte ) <NUM_LIT> ) ; disthdr . put ( ( byte ) <NUM_LIT:0> ) ; disthdr . flip ( ) ; EOutputStream eos = new EOutputStream ( <NUM_LIT> , 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 ( <NUM_LIT:3> ) ; disthdr . put ( ( byte ) <NUM_LIT> ) ; disthdr . put ( ( byte ) <NUM_LIT> ) ; disthdr . put ( ( byte ) <NUM_LIT:0> ) ; disthdr . flip ( ) ; EOutputStream eos = new EOutputStream ( <NUM_LIT> , 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 [ <NUM_LIT:0> ] ) ; ESeq reply = ERT . NIL ; for ( int i = <NUM_LIT:0> ; i < nodes . length ; i ++ ) { reply = reply . cons ( nodes [ i ] ) ; } return reply ; } } </s>
|
<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>
|
<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 ( "<STR_LIT>" ) ; public abstract EObject getName ( ) ; @ Override public String toString ( ) { return "<STR_LIT>" + super . id + "<STR_LIT:>>" ; } private static final EAtom am_name = EAtom . intern ( "<STR_LIT:name>" ) ; private static final EAtom am_data = EAtom . intern ( "<STR_LIT:data>" ) ; private static final EAtom am_connected = EAtom . intern ( "<STR_LIT>" ) ; private static final EAtom am_closed = EAtom . intern ( "<STR_LIT>" ) ; 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 ( "<STR_LIT>" + 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 = <NUM_LIT:1> << <NUM_LIT:0> ; public static final int ERTS_PORT_SFLG_EXITING = <NUM_LIT:1> << <NUM_LIT:1> ; public static final int ERTS_PORT_SFLG_DISTRIBUTION = <NUM_LIT:1> << <NUM_LIT:2> ; public static final int ERTS_PORT_SFLG_BINARY_IO = <NUM_LIT:1> << <NUM_LIT:3> ; public static final int ERTS_PORT_SFLG_SOFT_EOF = <NUM_LIT:1> << <NUM_LIT:4> ; public static final int ERTS_PORT_SFLG_PORT_BUSY = <NUM_LIT:1> << <NUM_LIT:5> ; public static final int ERTS_PORT_SFLG_CLOSING = <NUM_LIT:1> << <NUM_LIT:6> ; public static final int ERTS_PORT_SFLG_SEND_CLOSED = <NUM_LIT:1> << <NUM_LIT:7> ; public static final int ERTS_PORT_SFLG_LINEBUF_IO = <NUM_LIT:1> << <NUM_LIT:8> ; public static final int ERTS_PORT_SFLG_IMMORTAL = <NUM_LIT:1> << <NUM_LIT:9> ; public static final int ERTS_PORT_SFLG_FREE = <NUM_LIT:1> << <NUM_LIT:10> ; public static final int ERTS_PORT_SFLG_FREE_SCHEDULED = <NUM_LIT:1> << <NUM_LIT:11> ; public static final int ERTS_PORT_SFLG_INITIALIZING = <NUM_LIT:1> << <NUM_LIT:12> ; public static final int ERTS_PORT_SFLG_PORT_SPECIFIC_LOCK = <NUM_LIT:1> << <NUM_LIT> ; public static final int ERTS_PORT_SFLG_INVALID = <NUM_LIT:1> << <NUM_LIT> ; public static final int ERTS_PORT_SFLG_DEBUG = <NUM_LIT:1> << <NUM_LIT: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 ( "<STR_LIT>" ) ; this . env = new HashMap < String , String > ( System . getenv ( ) ) ; this . packet = - <NUM_LIT:1> ; this . line_length = - <NUM_LIT:1> ; this . send_exit_status = false ; this . stderr_to_stdout = false ; this . port_in_fd = <NUM_LIT:1> ; this . port_out_fd = <NUM_LIT: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 + <NUM_LIT:1> ] ; new_cmd [ <NUM_LIT:0> ] = cmd [ <NUM_LIT:0> ] ; for ( int i = <NUM_LIT:0> ; i < nargs . length ; i ++ ) { new_cmd [ i + <NUM_LIT:1> ] = EString . make ( nargs [ i ] ) . stringValue ( ) ; } cmd = new_cmd ; } else if ( tup2 . elem1 == am_arg0 ) { String [ ] new_cmd = new String [ <NUM_LIT:2> ] ; new_cmd [ <NUM_LIT:0> ] = cmd [ <NUM_LIT:0> ] ; new_cmd [ <NUM_LIT: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 = <NUM_LIT: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 = <NUM_LIT:1> ; port_out_fd = <NUM_LIT:2> ; } else if ( val == am_nouse_stdio ) { port_in_fd = <NUM_LIT:3> ; port_out_fd = <NUM_LIT: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 , "<STR_LIT>" + 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 ( "<STR_LIT>" + 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 == <NUM_LIT:0> ) { msg = mbox . get ( ) ; } else { msg = null ; long timeout = abs_timeout - System . currentTimeMillis ( ) ; if ( timeout > <NUM_LIT:0> ) { msg = mbox . get ( timeout ) ; } if ( msg == null ) { abs_timeout = <NUM_LIT: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 ( "<STR_LIT>" + sender ) ; } if ( out . size ( ) == <NUM_LIT: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 ( ) == <NUM_LIT:5> ) { if ( tup . elm ( <NUM_LIT:1> ) == ERT . am_DOWN ) { ERef ref = tup . elm ( <NUM_LIT: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 ( "<STR_LIT>" + this . self_handle ( ) + "<STR_LIT>" + pstate ) ; throw ERT . badarg ( ) ; } if ( log . isLoggable ( Level . FINE ) ) log . fine ( "<STR_LIT>" + op + "<STR_LIT>" + 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 ( ) == <NUM_LIT: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 == <NUM_LIT:0> ) { return ERT . EMPTY_BYTEBUFFER ; } else if ( out . length == <NUM_LIT:1> ) { return out [ <NUM_LIT:0> ] ; } else { long size = <NUM_LIT:0> ; for ( int i = <NUM_LIT:0> ; i < out . length ; i ++ ) { size += out [ i ] . limit ( ) ; } if ( size > Integer . MAX_VALUE ) throw new IllegalArgumentException ( "<STR_LIT>" + size ) ; ByteBuffer res = ByteBuffer . allocate ( ( int ) size ) ; for ( int i = <NUM_LIT: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 : "<STR_LIT>" ; this . abs_timeout = <NUM_LIT: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 ( "<STR_LIT>" + owner + "<STR_LIT>" + out ) ; owner . send ( port , out ) ; } public void output_term_from_driver_b ( EObject out ) { if ( log . isLoggable ( Level . FINE ) ) log . fine ( "<STR_LIT>" + owner + "<STR_LIT>" + 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 ( "<STR_LIT>" + spec + "<STR_LIT:)>" ) ; } 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>
|
<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 "<STR_LIT>" ; } @ 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>
|
<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 ( "<STR_LIT>" ) ; 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 = ( '<CHAR_LIT>' << <NUM_LIT:8> ) | '<CHAR_LIT>' ; short EJ = ( '<CHAR_LIT:e>' << <NUM_LIT:8> ) | '<CHAR_LIT>' ; short DJ = ( '<CHAR_LIT>' << <NUM_LIT:8> ) | '<CHAR_LIT>' ; short SD = ( '<CHAR_LIT>' << <NUM_LIT:8> ) | '<CHAR_LIT>' ; 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 * <NUM_LIT> * <NUM_LIT> ) ; 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 ( "<STR_LIT>" ) ) { 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 , <NUM_LIT: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 "<STR_LIT>" ; } else { return "<STR_LIT>" ; } } 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>
|
<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 = <NUM_LIT:1> ; public static final byte OP_GETHOSTBYADDR = <NUM_LIT:2> ; public static final byte OP_CANCEL_REQUEST = <NUM_LIT:3> ; public static final byte OP_CONTROL = <NUM_LIT:4> ; public static final byte PROTO_IPV4 = <NUM_LIT:1> ; public static final byte PROTO_IPV6 = <NUM_LIT:2> ; public static final byte SETOPT_DEBUG_LEVEL = <NUM_LIT:0> ; public static final byte UNIT_ERROR = <NUM_LIT:0> ; public static final byte UNIT_IPV4 = <NUM_LIT:4> ; public static final byte UNIT_IPV6 = <NUM_LIT: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 ( "<STR_LIT>" + seq + "<STR_LIT>" + 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 = <NUM_LIT: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 = <NUM_LIT:4> + <NUM_LIT:1> + <NUM_LIT:4> ; int first = - <NUM_LIT:1> ; int acount = <NUM_LIT:0> ; for ( int i = <NUM_LIT: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 += <NUM_LIT:1> ; if ( first == - <NUM_LIT:1> ) first = i ; if ( host . equals ( names [ i ] ) ) { first = i ; } } } size += <NUM_LIT:4> ; size += host . length ( ) + <NUM_LIT:1> ; ByteBuffer rep = ByteBuffer . allocate ( size ) ; rep . putInt ( seq ) ; if ( proto == PROTO_IPV4 ) { rep . put ( UNIT_IPV4 ) ; rep . putInt ( acount ) ; if ( acount > <NUM_LIT:0> ) { rep . put ( bytes [ first ] ) ; for ( int i = <NUM_LIT:0> ; i < addr . length ; i ++ ) { if ( i != first && bytes [ i ] != null ) { rep . put ( bytes [ i ] ) ; } } } rep . putInt ( <NUM_LIT:1> ) ; rep . put ( host . getBytes ( IO . ISO_LATIN_1 ) ) ; rep . put ( ( byte ) <NUM_LIT:0> ) ; driver_output ( rep ) ; return ; } else if ( proto == PROTO_IPV6 ) { rep . put ( UNIT_IPV6 ) ; rep . putInt ( acount ) ; for ( int i = <NUM_LIT:0> ; i < addr . length ; i ++ ) { if ( bytes [ i ] != null ) { rep . put ( bytes [ i ] ) ; } } rep . putInt ( <NUM_LIT:1> ) ; rep . put ( host . getBytes ( IO . ISO_LATIN_1 ) ) ; rep . put ( ( byte ) <NUM_LIT:0> ) ; driver_output ( rep ) ; return ; } } String message = "<STR_LIT:unknown>" ; if ( err != null ) { message = err . getMessage ( ) ; } byte [ ] msg = message . getBytes ( IO . ISO_LATIN_1 ) ; int len = <NUM_LIT:4> + <NUM_LIT: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 ? <NUM_LIT:4> : <NUM_LIT: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 = <NUM_LIT:4> + <NUM_LIT:1> + <NUM_LIT:4> ; int first = - <NUM_LIT:1> ; int acount = <NUM_LIT:0> ; for ( int i = <NUM_LIT: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 += <NUM_LIT:1> ; if ( first == - <NUM_LIT:1> ) first = i ; } } size += <NUM_LIT:4> ; size += name . length ( ) + <NUM_LIT:1> ; ByteBuffer rep = ByteBuffer . allocate ( size ) ; rep . putInt ( seq ) ; if ( proto == PROTO_IPV4 ) { rep . put ( UNIT_IPV4 ) ; rep . putInt ( acount ) ; if ( acount > <NUM_LIT:0> ) { rep . put ( bytes [ first ] ) ; for ( int i = <NUM_LIT:0> ; i < addr . length ; i ++ ) { if ( i != first && bytes [ i ] != null ) { rep . put ( bytes [ i ] ) ; } } } rep . putInt ( <NUM_LIT:1> ) ; rep . put ( name . getBytes ( IO . ISO_LATIN_1 ) ) ; rep . put ( ( byte ) <NUM_LIT:0> ) ; driver_output ( rep ) ; return ; } else if ( proto == PROTO_IPV6 ) { rep . put ( UNIT_IPV6 ) ; rep . putInt ( acount ) ; for ( int i = <NUM_LIT:0> ; i < addr . length ; i ++ ) { if ( bytes [ i ] != null ) { rep . put ( bytes [ i ] ) ; } } rep . putInt ( <NUM_LIT:1> ) ; rep . put ( name . getBytes ( IO . ISO_LATIN_1 ) ) ; rep . put ( ( byte ) <NUM_LIT:0> ) ; driver_output ( rep ) ; return ; } } String message = "<STR_LIT:unknown>" ; if ( err != null ) { message = err . getMessage ( ) ; } byte [ ] msg = message . getBytes ( IO . ISO_LATIN_1 ) ; int len = <NUM_LIT:4> + <NUM_LIT: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>
|
<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 "<STR_LIT>" ; } @ 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>
|
<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>
|
<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 ( "<STR_LIT>" ) ; 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 > ( <NUM_LIT:2> ) ; @ Override public void run ( ) { try { run0 ( ) ; } catch ( Throwable e ) { log . severe ( "<STR_LIT>" + e . getMessage ( ) ) ; log . log ( Level . FINE , "<STR_LIT>" , 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 ( "<STR_LIT>" ) ; 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 ) + "<STR_LIT::>" + ch ) ; } } } try { num = selector . select ( <NUM_LIT> ) ; } 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 ( "<STR_LIT>" ) ; } 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 ) == <NUM_LIT: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>
|
<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 "<STR_LIT>" ; } @ 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>
|
<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 = <NUM_LIT:0> ; public static final int Z_SYNC_FLUSH = <NUM_LIT:2> ; public static final int Z_FULL_FLUSH = <NUM_LIT:3> ; public static final int Z_FINISH = <NUM_LIT:4> ; public static final int Z_NO_COMPRESSION = <NUM_LIT:0> ; public static final int Z_BEST_SPEED = <NUM_LIT:1> ; public static final int Z_BEST_COMPRESSION = <NUM_LIT:9> ; public static final int Z_DEFAULT_COMPRESSION = ( - <NUM_LIT:1> ) ; public static final int Z_FILTERED = <NUM_LIT:1> ; public static final int Z_HUFFMAN_ONLY = <NUM_LIT:2> ; public static final int Z_DEFAULT_STRATEGY = <NUM_LIT:0> ; public static final int Z_DEFLATED = <NUM_LIT:8> ; public static final int Z_NULL = <NUM_LIT:0> ; public static final int MAX_WBITS = <NUM_LIT:15> ; public static final int ID1 = <NUM_LIT> ; public static final int ID2 = <NUM_LIT> ; public static final int FTEXT = <NUM_LIT> ; public static final int FHCRC = <NUM_LIT> ; public static final int FEXTRA = <NUM_LIT> ; public static final int FNAME = <NUM_LIT> ; public static final int FCOMMENT = <NUM_LIT> ; public static final int RESERVED = <NUM_LIT> ; public static final int OS_MDDOS = <NUM_LIT:0> ; public static final int OS_AMIGA = <NUM_LIT:1> ; public static final int OS_OPENVMS = <NUM_LIT:2> ; public static final int OS_UNIX = <NUM_LIT:3> ; public static final int OS_VMCMS = <NUM_LIT:4> ; public static final int OS_ATARI = <NUM_LIT:5> ; public static final int OS_OS2 = <NUM_LIT:6> ; public static final int OS_MAC = <NUM_LIT:7> ; public static final int OS_ZSYS = <NUM_LIT:8> ; public static final int OS_CPM = <NUM_LIT:9> ; public static final int OS_TOP20 = <NUM_LIT:10> ; public static final int OS_NTFS = <NUM_LIT:11> ; public static final int OS_QDOS = <NUM_LIT:12> ; public static final int OS_ACORN = <NUM_LIT> ; public static final int OS_UNKNOWN = <NUM_LIT:255> ; public static final int DEFLATE_INIT = <NUM_LIT:1> ; public static final int DEFLATE_INIT2 = <NUM_LIT:2> ; public static final int DEFLATE_SETDICT = <NUM_LIT:3> ; public static final int DEFLATE_RESET = <NUM_LIT:4> ; public static final int DEFLATE_END = <NUM_LIT:5> ; public static final int DEFLATE_PARAMS = <NUM_LIT:6> ; public static final int DEFLATE = <NUM_LIT:7> ; public static final int INFLATE_INIT = <NUM_LIT:8> ; public static final int INFLATE_INIT2 = <NUM_LIT:9> ; public static final int INFLATE_SETDICT = <NUM_LIT:10> ; public static final int INFLATE_SYNC = <NUM_LIT:11> ; public static final int INFLATE_RESET = <NUM_LIT:12> ; public static final int INFLATE_END = <NUM_LIT> ; public static final int INFLATE = <NUM_LIT> ; public static final int CRC32_0 = <NUM_LIT:15> ; public static final int CRC32_1 = <NUM_LIT:16> ; public static final int CRC32_2 = <NUM_LIT> ; public static final int SET_BUFSZ = <NUM_LIT> ; public static final int GET_BUFSZ = <NUM_LIT> ; public static final int GET_QSIZE = <NUM_LIT:20> ; public static final int ADLER32_1 = <NUM_LIT> ; public static final int ADLER32_2 = <NUM_LIT> ; public static final int CRC32_COMBINE = <NUM_LIT> ; public static final int ADLER32_COMBINE = <NUM_LIT: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 = <NUM_LIT: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 = <NUM_LIT: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 ( <NUM_LIT> ) ; 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 > <NUM_LIT: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 = <NUM_LIT: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 ( <NUM_LIT> ) ; 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 > <NUM_LIT: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 ( "<STR_LIT>" + command + "<STR_LIT>" + EBinary . make ( cmd ) ) ; } private ByteBuffer reply_ok ( ) { ByteBuffer ok = ByteBuffer . allocate ( <NUM_LIT:3> ) ; ok . put ( ( byte ) <NUM_LIT:0> ) ; ok . put ( ( byte ) '<CHAR_LIT>' ) ; ok . put ( ( byte ) '<CHAR_LIT>' ) ; return ok ; } @ Override protected void readyAsync ( EAsync data ) throws Pausable { data . ready ( ) ; } } </s>
|
<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 ( "<STR_LIT>" ) ; public static final Charset UTF8 = Charset . forName ( "<STR_LIT>" ) ; static private class BARR extends ByteArrayOutputStream { ByteBuffer wrap ( ) { return ByteBuffer . wrap ( super . buf , <NUM_LIT: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 ( "<STR_LIT>" ) ; } return result ; } public static long writeFully ( WritableByteChannel fd , ByteBuffer src ) throws IOException { long written = <NUM_LIT: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 ( "<STR_LIT>" . equals ( e . getMessage ( ) ) || "<STR_LIT>" . equals ( e . getMessage ( ) ) ) { return Posix . ENOTCONN ; } if ( e instanceof ConnectException ) { if ( "<STR_LIT>" . equals ( e . getMessage ( ) ) ) { return Posix . ECONNREFUSED ; } } if ( e instanceof BindException ) { if ( "<STR_LIT>" . equals ( e . getMessage ( ) ) ) { return Posix . EADDRNOTAVAIL ; } } if ( e instanceof java . net . SocketException ) { if ( "<STR_LIT>" . equals ( e . getMessage ( ) ) ) { return Posix . ENETUNREACH ; } } ERT . log . warning ( "<STR_LIT>" + e . getMessage ( ) ) ; ERT . log . log ( Level . FINE , "<STR_LIT>" , e ) ; return Posix . EUNKNOWN ; } public static long writev ( GatheringByteChannel fd , ByteBuffer [ ] iov ) throws IOException { int cnt = <NUM_LIT:0> ; long written = <NUM_LIT:0> ; while ( cnt < iov . length ) { int b = iov . length - cnt ; if ( iov [ cnt ] . hasRemaining ( ) ) { if ( b == <NUM_LIT: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 ) == <NUM_LIT: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 + <NUM_LIT:1> ) ; return result ; } } throw ERT . badarg ( ) ; } public static void putstr ( ByteBuffer buf , String err , boolean term ) { for ( int i = <NUM_LIT:0> ; i < err . length ( ) ; i ++ ) { buf . put ( ( byte ) err . charAt ( i ) ) ; } if ( term ) { buf . put ( ( byte ) <NUM_LIT:0> ) ; } } public static String getstr ( ByteBuffer buf , boolean term ) { if ( term ) { StringBuilder sb = new StringBuilder ( ) ; byte b ; while ( ( b = buf . get ( ) ) != <NUM_LIT:0> ) { sb . append ( ( char ) ( <NUM_LIT> & 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 , <NUM_LIT:0> , super . count ) ; } } public static EBinary istream2binary ( InputStream in ) throws IOException { BARR2 out = new BARR2 ( ) ; byte [ ] buf = new byte [ <NUM_LIT:4> * <NUM_LIT> ] ; int read ; while ( ( read = in . read ( buf ) ) > <NUM_LIT:0> ) { out . write ( buf , <NUM_LIT:0> , read ) ; } return out . asBinary ( ) ; } public static byte [ ] istream2bytearray ( InputStream in ) throws IOException { BARR2 out = new BARR2 ( ) ; byte [ ] buf = new byte [ <NUM_LIT:4> * <NUM_LIT> ] ; int read ; while ( ( read = in . read ( buf ) ) > <NUM_LIT:0> ) { out . write ( buf , <NUM_LIT:0> , read ) ; } return out . toByteArray ( ) ; } } </s>
|
<s> package erjang . driver ; import kilim . Pausable ; public interface EAsync { void async ( ) ; void ready ( ) throws Pausable ; } </s>
|
<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 "<STR_LIT>" ; } @ 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>
|
<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 = <NUM_LIT> ; public static final int FILE_PWRITE = <NUM_LIT> ; public static final int RAM_FILE_FDATASYNC = <NUM_LIT> ; public static final int RAM_FILE_GET = <NUM_LIT:30> ; public static final int RAM_FILE_SET = <NUM_LIT:31> ; public static final int RAM_FILE_GET_CLOSE = <NUM_LIT:32> ; public static final int RAM_FILE_COMPRESS = <NUM_LIT> ; public static final int RAM_FILE_UNCOMPRESS = <NUM_LIT> ; public static final int RAM_FILE_UUENCODE = <NUM_LIT> ; public static final int RAM_FILE_UUDECODE = <NUM_LIT> ; public static final int RAM_FILE_SIZE = <NUM_LIT> ; public static final int RAM_FILE_ADVISE = <NUM_LIT> ; 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 == <NUM_LIT:0> || ev [ <NUM_LIT:0> ] . remaining ( ) == <NUM_LIT:0> ) { reply_posix_error ( Posix . EINVAL ) ; return ; } byte command = ev [ <NUM_LIT:0> ] . get ( ) ; switch ( command ) { default : ev [ <NUM_LIT:0> ] . position ( ev [ <NUM_LIT:0> ] . position ( ) - <NUM_LIT: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 ( ) < <NUM_LIT: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 ( <NUM_LIT:0> ) ; } break ; case RAM_FILE_UNCOMPRESS : { if ( data . hasRemaining ( ) ) { reply_posix_error ( Posix . EINVAL ) ; return ; } data . mark ( ) ; boolean is_gzip = ( data . remaining ( ) >= <NUM_LIT:2> && data . getShort ( ) == GZIP_MAGIC ) ; data . reset ( ) ; if ( is_gzip ) { final Inflater inflater = new Inflater ( true ) ; inflater . setInput ( contents . array ( ) , <NUM_LIT:0> , contents . limit ( ) ) ; byte [ ] buf = new byte [ <NUM_LIT> ] ; ByteArrayOutputStream baos = new ByteArrayOutputStream ( contents . limit ( ) ) ; try { while ( ! inflater . finished ( ) ) { int inflated = inflater . inflate ( buf , <NUM_LIT:0> , buf . length ) ; baos . write ( buf , <NUM_LIT:0> , inflated ) ; } } catch ( Exception e ) { log . severe ( "<STR_LIT>" + e . getMessage ( ) ) ; log . log ( Level . FINE , "<STR_LIT>" , 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 ( "<STR_LIT>" + ( ( int ) cmd ) + "<STR_LIT:U+0020>" + EBinary . make ( data ) ) ; } } public void reply_ok ( ) throws Pausable { ByteBuffer header = ByteBuffer . allocate ( <NUM_LIT:1> ) ; header . put ( FILE_RESP_OK ) ; driver_output2 ( header , null ) ; } public void reply_number ( int val ) throws Pausable { ByteBuffer reply = ByteBuffer . allocate ( <NUM_LIT:1> + <NUM_LIT:4> ) ; reply . put ( FILE_RESP_NUMBER ) ; reply . putInt ( val ) ; driver_output2 ( reply , null ) ; } void reply_buf ( ByteBuffer buf ) throws Pausable { ByteBuffer header = ByteBuffer . allocate ( <NUM_LIT:1> + <NUM_LIT: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 ( <NUM_LIT:4> ) ; response . putInt ( value ) ; driver_output2 ( response , null ) ; } public void reply_posix_error ( int posix_errno ) throws Pausable { ByteBuffer response = ByteBuffer . allocate ( <NUM_LIT> ) ; 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>
|
<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>
|
<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>
|
<s> package erjang . driver ; public enum SelectMode { SET , CLEAR ; } </s>
|
<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>
|
<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>
|
<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>
|
<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 ( "<STR_LIT>" ) ; } public EFDDriverTask ( EProc owner , int in , int out , EObject portSetting ) { super ( owner . self_handle ( ) , new FDDriverInstance ( in , out ) ) ; super . parseOptions ( new String [ ] { "<STR_LIT>" } , portSetting ) ; super . setupInstance ( ) ; } } </s>
|
<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 = <NUM_LIT: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 == <NUM_LIT:0> ) { ins = ERT . getInputStream ( ) ; } if ( out == <NUM_LIT:1> ) { outs = ERT . getOutputStream ( ) ; } if ( out == <NUM_LIT: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 ( "<STR_LIT>" + in ) ; } void finish ( final int howmany , final byte [ ] buffer ) { final EDriverTask dt = FDDriverInstance . this . task ; final byte [ ] ob = new byte [ howmany ] ; System . arraycopy ( buffer , <NUM_LIT:0> , ob , <NUM_LIT: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 [ <NUM_LIT> ] ; while ( true ) { try { int howmany ; howmany = ins . read ( buffer ) ; if ( howmany < <NUM_LIT:0> ) { if ( task . send_eof ) { task . eof_from_driver_b ( ) ; } return ; } finish ( howmany , buffer ) ; } catch ( IOException e ) { if ( e . getMessage ( ) . equals ( "<STR_LIT>" ) ) { } 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 ( <NUM_LIT:8> ) ; bb . order ( ByteOrder . nativeOrder ( ) ) ; bb . putInt ( <NUM_LIT> ) ; bb . putInt ( <NUM_LIT> ) ; 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>
|
<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 ( "<STR_LIT>" ) ; 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 = <NUM_LIT:1> << <NUM_LIT: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 == <NUM_LIT: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 > <NUM_LIT:0> ) { ev [ ev . length - <NUM_LIT:1> ] . flip ( ) ; resp = EBinary . make ( ev [ ev . length - <NUM_LIT:1> ] ) ; for ( int i = ev . length - <NUM_LIT:2> ; i >= <NUM_LIT: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 ) != <NUM_LIT:0> ) { return ; } header . flip ( ) ; if ( buf != null ) buf . flip ( ) ; if ( ( status & EDriverTask . ERTS_PORT_SFLG_DISTRIBUTION ) != <NUM_LIT:0> ) { task . node ( ) . net_message ( task . self_handle ( ) , null , buf ) ; return ; } if ( ( status & EDriverTask . ERTS_PORT_SFLG_LINEBUF_IO ) != <NUM_LIT: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 ) != <NUM_LIT:0> ) { return ; } buf . flip ( ) ; if ( ( status & EDriverTask . ERTS_PORT_SFLG_DISTRIBUTION ) != <NUM_LIT:0> ) { task . node ( ) . net_message ( task . self_handle ( ) , null , buf ) ; return ; } if ( ( status & EDriverTask . ERTS_PORT_SFLG_LINEBUF_IO ) != <NUM_LIT: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 > <NUM_LIT: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 , "<STR_LIT>" , 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 <NUM_LIT:0> ; int size = <NUM_LIT:0> ; int p = <NUM_LIT:0> ; for ( p = <NUM_LIT: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 <NUM_LIT:0> ; int p = <NUM_LIT:0> ; for ( p = <NUM_LIT:0> ; p < queue . length && queue [ p ] != null && ! queue [ p ] . hasRemaining ( ) ; p ++ ) { } if ( p == queue . length ) return <NUM_LIT:0> ; long res = <NUM_LIT:0> ; for ( int i = <NUM_LIT: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 [ <NUM_LIT:0> ] == null ) queue = q ; else { ArrayList < ByteBuffer > bbs = new ArrayList < ByteBuffer > ( ) ; for ( int i = <NUM_LIT:0> ; i < queue . length ; i ++ ) { if ( queue [ i ] != null && queue [ i ] . hasRemaining ( ) ) bbs . add ( queue [ i ] ) ; } for ( int i = <NUM_LIT: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 ) != <NUM_LIT: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 ( "<STR_LIT:n>" ) ; } sb . append ( "<STR_LIT>" + buffer . length + "<STR_LIT>" ) ; for ( int i = <NUM_LIT:0> ; i < buffer . length ; i ++ ) { ByteBuffer evp = buffer [ i ] ; int off = <NUM_LIT:0> ; boolean did_print = false ; for ( int p = evp . position ( ) ; p < evp . limit ( ) ; p ++ ) { if ( ( off % <NUM_LIT> ) == <NUM_LIT:0> && off != <NUM_LIT:0> ) sb . append ( "<STR_LIT:n>" ) ; if ( ( off % <NUM_LIT> ) == <NUM_LIT:0> ) sb . append ( "<STR_LIT:[>" + i + "<STR_LIT>" + hex4 ( off ) + "<STR_LIT>" ) ; did_print = true ; sb . append ( "<STR_LIT:U+0020>" ) ; byte ch = evp . get ( p ) ; sb . append ( hex2 ( ch & <NUM_LIT> ) ) ; off += <NUM_LIT:1> ; } if ( i < buffer . length - <NUM_LIT:1> && did_print ) sb . append ( "<STR_LIT:n>" ) ; } sb . append ( "<STR_LIT>" ) ; for ( int i = <NUM_LIT:0> ; i < buffer . length ; i ++ ) { ByteBuffer evp = buffer [ i ] ; int off = <NUM_LIT:0> ; boolean did_print = false ; for ( int p = evp . position ( ) ; p < evp . limit ( ) ; p ++ ) { if ( ( off % <NUM_LIT> ) == <NUM_LIT:0> && off != <NUM_LIT:0> ) sb . append ( "<STR_LIT:n>" ) ; if ( ( off % <NUM_LIT> ) == <NUM_LIT:0> ) sb . append ( "<STR_LIT:[>" + i + "<STR_LIT>" + hex4 ( off ) + "<STR_LIT:U+0020:U+0020>" ) ; did_print = true ; byte ch = evp . get ( p ) ; if ( ch >= <NUM_LIT:32> && ch <= <NUM_LIT> ) { sb . append ( ( char ) ch ) ; } else { sb . append ( '<CHAR_LIT:.>' ) ; } off += <NUM_LIT:1> ; } if ( i < buffer . length - <NUM_LIT:1> && did_print ) sb . append ( "<STR_LIT:n>" ) ; } String msg = sb . toString ( ) ; log . log ( level , msg ) ; } public static String hex2 ( int i ) { if ( i < <NUM_LIT> ) return "<STR_LIT:0>" + Integer . toHexString ( i ) ; return Integer . toHexString ( i ) ; } public static String hex4 ( int i ) { if ( i < <NUM_LIT> ) return "<STR_LIT>" + Integer . toHexString ( i ) ; if ( i < <NUM_LIT> ) return "<STR_LIT>" + Integer . toHexString ( i ) ; if ( i < <NUM_LIT> ) return "<STR_LIT:0>" + Integer . toHexString ( i ) ; return Integer . toHexString ( i ) ; } } </s>
|
<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>
|
<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 "<STR_LIT>" + ch + "<STR_LIT>" + Integer . toBinaryString ( ops ) + "<STR_LIT>" + releaseNotify + "<STR_LIT:}>" ; } 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 == <NUM_LIT:0> && ! old . releaseNotify ) { interest . remove ( handler ) ; } } } public int updateInterestOpsFor ( SelectionKey key ) { int ops = computeOps ( ) ; key . interestOps ( ops ) ; return ops ; } private int computeOps ( ) { int ops = <NUM_LIT: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 != <NUM_LIT:0> ) { NIOHandler handler = want . handler ; if ( handler != null ) { handler . ready ( ch , gotOps ) ; } want . ops &= ~ gotOps ; if ( want . ops == <NUM_LIT: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>
|
<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>
|
<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 ( "<STR_LIT>" ) ; static Logger portlog = Logger . getLogger ( "<STR_LIT>" ) ; 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 - <NUM_LIT:1> ; if ( this . when > o . when ) return <NUM_LIT:1> ; return <NUM_LIT: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 ( <NUM_LIT:0> ) , ACTIVE ( <NUM_LIT:1> ) , ACTIVE_ONCE ( <NUM_LIT:2> ) ; final int value ; ActiveType ( int val ) { this . value = val ; } public static ActiveType valueOf ( int ival ) { switch ( ival ) { case <NUM_LIT:0> : return PASSIVE ; case <NUM_LIT:1> : return ACTIVE ; case <NUM_LIT:2> : return ACTIVE_ONCE ; } throw new erjang . NotImplemented ( ) ; } } public static final byte INET_AF_INET = <NUM_LIT:1> ; public static final byte INET_AF_INET6 = <NUM_LIT:2> ; public static final byte INET_AF_ANY = <NUM_LIT:3> ; public static final byte INET_AF_LOOPBACK = <NUM_LIT:4> ; public static final int INET_TYPE_STREAM = <NUM_LIT:1> ; public static final int INET_TYPE_DGRAM = <NUM_LIT:2> ; public static final int INET_TYPE_SEQPACKET = <NUM_LIT:3> ; public static final int INET_MODE_LIST = <NUM_LIT:0> ; public static final int INET_MODE_BINARY = <NUM_LIT:1> ; public static final int INET_DELIVER_PORT = <NUM_LIT:0> ; public static final int INET_DELIVER_TERM = <NUM_LIT:1> ; public static final int INET_PASSIVE = <NUM_LIT:0> ; public static final int INET_ACTIVE = <NUM_LIT:1> ; public static final int INET_ONCE = <NUM_LIT:2> ; public static final int INET_F_OPEN = <NUM_LIT> ; public static final int INET_F_BOUND = <NUM_LIT> ; public static final int INET_F_ACTIVE = <NUM_LIT> ; public static final int INET_F_LISTEN = <NUM_LIT> ; public static final int INET_F_CON = <NUM_LIT> ; public static final int INET_F_ACC = <NUM_LIT> ; public static final int INET_F_LST = <NUM_LIT> ; public static final int INET_F_BUSY = <NUM_LIT> ; public static final int INET_F_MULTI_CLIENT = <NUM_LIT> ; public static final int INET_REQ_OPEN = <NUM_LIT:1> ; public static final int INET_REQ_CLOSE = <NUM_LIT:2> ; public static final int INET_REQ_CONNECT = <NUM_LIT:3> ; public static final int INET_REQ_PEER = <NUM_LIT:4> ; public static final int INET_REQ_NAME = <NUM_LIT:5> ; public static final int INET_REQ_BIND = <NUM_LIT:6> ; public static final int INET_REQ_SETOPTS = <NUM_LIT:7> ; public static final int INET_REQ_GETOPTS = <NUM_LIT:8> ; public static final int INET_REQ_GETSTAT = <NUM_LIT:11> ; public static final int INET_REQ_GETHOSTNAME = <NUM_LIT:12> ; public static final int INET_REQ_FDOPEN = <NUM_LIT> ; public static final int INET_REQ_GETFD = <NUM_LIT> ; public static final int INET_REQ_GETTYPE = <NUM_LIT:15> ; public static final int INET_REQ_GETSTATUS = <NUM_LIT:16> ; public static final int INET_REQ_GETSERVBYNAME = <NUM_LIT> ; public static final int INET_REQ_GETSERVBYPORT = <NUM_LIT> ; public static final int INET_REQ_SETNAME = <NUM_LIT> ; public static final int INET_REQ_SETPEER = <NUM_LIT:20> ; public static final int INET_REQ_GETIFLIST = <NUM_LIT> ; public static final int INET_REQ_IFGET = <NUM_LIT> ; public static final int INET_REQ_IFSET = <NUM_LIT> ; public static final int INET_REQ_SUBSCRIBE = <NUM_LIT:24> ; public static final int TCP_REQ_ACCEPT = <NUM_LIT> ; public static final int TCP_REQ_LISTEN = <NUM_LIT> ; public static final int TCP_REQ_RECV = <NUM_LIT> ; public static final int TCP_REQ_UNRECV = <NUM_LIT> ; public static final int TCP_REQ_SHUTDOWN = <NUM_LIT> ; public static final int TCP_REQ_MULTI_OP = <NUM_LIT> ; public static final int PACKET_REQ_RECV = <NUM_LIT> ; public static final int SCTP_REQ_LISTEN = <NUM_LIT> ; public static final int SCTP_REQ_BINDX = <NUM_LIT> ; public static final byte INET_SUBS_EMPTY_OUT_Q = <NUM_LIT:1> ; public static final byte TCP_ADDF_DELAY_SEND = <NUM_LIT:1> ; public static final byte TCP_ADDF_CLOSE_SENT = <NUM_LIT:2> ; public static final byte TCP_ADDF_DELAYED_CLOSE_RECV = <NUM_LIT:4> ; public static final byte TCP_ADDF_DELAYED_CLOSE_SEND = <NUM_LIT:8> ; public static final byte INET_REP_ERROR = <NUM_LIT:0> ; public static final byte INET_REP_OK = <NUM_LIT:1> ; public static final byte INET_REP_SCTP = <NUM_LIT:2> ; public static final int INET_STATE_CLOSED = <NUM_LIT: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 = <NUM_LIT:0> ; public static final byte INET_OPT_KEEPALIVE = <NUM_LIT:1> ; public static final byte INET_OPT_DONTROUTE = <NUM_LIT:2> ; public static final byte INET_OPT_LINGER = <NUM_LIT:3> ; public static final byte INET_OPT_BROADCAST = <NUM_LIT:4> ; public static final byte INET_OPT_OOBINLINE = <NUM_LIT:5> ; public static final byte INET_OPT_SNDBUF = <NUM_LIT:6> ; public static final byte INET_OPT_RCVBUF = <NUM_LIT:7> ; public static final byte INET_OPT_PRIORITY = <NUM_LIT:8> ; public static final byte INET_OPT_TOS = <NUM_LIT:9> ; public static final byte TCP_OPT_NODELAY = <NUM_LIT:10> ; public static final byte UDP_OPT_MULTICAST_IF = <NUM_LIT:11> ; public static final byte UDP_OPT_MULTICAST_TTL = <NUM_LIT:12> ; public static final byte UDP_OPT_MULTICAST_LOOP = <NUM_LIT> ; public static final byte UDP_OPT_ADD_MEMBERSHIP = <NUM_LIT> ; public static final byte UDP_OPT_DROP_MEMBERSHIP = <NUM_LIT:15> ; public static final byte INET_LOPT_BUFFER = <NUM_LIT:20> ; public static final byte INET_LOPT_HEADER = <NUM_LIT> ; public static final byte INET_LOPT_ACTIVE = <NUM_LIT> ; public static final byte INET_LOPT_PACKET = <NUM_LIT> ; public static final byte INET_LOPT_MODE = <NUM_LIT:24> ; public static final byte INET_LOPT_DELIVER = <NUM_LIT> ; public static final byte INET_LOPT_EXITONCLOSE = <NUM_LIT> ; public static final byte INET_LOPT_TCP_HIWTRMRK = <NUM_LIT> ; public static final byte INET_LOPT_TCP_LOWTRMRK = <NUM_LIT> ; public static final byte INET_LOPT_BIT8 = <NUM_LIT> ; public static final byte INET_LOPT_TCP_SEND_TIMEOUT = <NUM_LIT:30> ; public static final byte INET_LOPT_TCP_DELAY_SEND = <NUM_LIT:31> ; public static final byte INET_LOPT_PACKET_SIZE = <NUM_LIT:32> ; public static final byte INET_LOPT_READ_PACKETS = <NUM_LIT> ; public static final byte INET_OPT_RAW = <NUM_LIT> ; public static final byte INET_LOPT_TCP_SEND_TIMEOUT_CLOSE = <NUM_LIT> ; public static final byte SCTP_OPT_RTOINFO = <NUM_LIT:100> ; public static final byte SCTP_OPT_ASSOCINFO = <NUM_LIT> ; public static final byte SCTP_OPT_INITMSG = <NUM_LIT> ; public static final byte SCTP_OPT_AUTOCLOSE = <NUM_LIT> ; public static final byte SCTP_OPT_NODELAY = <NUM_LIT> ; public static final byte SCTP_OPT_DISABLE_FRAGMENTS = <NUM_LIT> ; public static final byte SCTP_OPT_I_WANT_MAPPED_V4_ADDR = <NUM_LIT> ; public static final byte SCTP_OPT_MAXSEG = <NUM_LIT> ; public static final byte SCTP_OPT_SET_PEER_PRIMARY_ADDR = <NUM_LIT> ; public static final byte SCTP_OPT_PRIMARY_ADDR = <NUM_LIT> ; public static final byte SCTP_OPT_ADAPTATION_LAYER = <NUM_LIT> ; public static final byte SCTP_OPT_PEER_ADDR_PARAMS = <NUM_LIT> ; public static final byte SCTP_OPT_DEFAULT_SEND_PARAM = <NUM_LIT> ; public static final byte SCTP_OPT_EVENTS = <NUM_LIT> ; public static final byte SCTP_OPT_DELAYED_ACK_TIME = <NUM_LIT> ; public static final byte SCTP_OPT_STATUS = <NUM_LIT> ; public static final byte SCTP_OPT_GET_PEER_ADDR_INFO = <NUM_LIT> ; public static final int INET_IFOPT_ADDR = <NUM_LIT:1> ; public static final int INET_IFOPT_BROADADDR = <NUM_LIT:2> ; public static final int INET_IFOPT_DSTADDR = <NUM_LIT:3> ; public static final int INET_IFOPT_MTU = <NUM_LIT:4> ; public static final int INET_IFOPT_NETMASK = <NUM_LIT:5> ; public static final int INET_IFOPT_FLAGS = <NUM_LIT:6> ; public static final int INET_IFOPT_HWADDR = <NUM_LIT:7> ; public static final int INET_BIT8_CLEAR = <NUM_LIT:0> ; public static final int INET_BIT8_SET = <NUM_LIT:1> ; public static final int INET_BIT8_ON = <NUM_LIT:2> ; public static final int INET_BIT8_OFF = <NUM_LIT:3> ; public static final int INET_STAT_RECV_CNT = <NUM_LIT:1> ; public static final int INET_STAT_RECV_MAX = <NUM_LIT:2> ; public static final int INET_STAT_RECV_AVG = <NUM_LIT:3> ; public static final int INET_STAT_RECV_DVI = <NUM_LIT:4> ; public static final int INET_STAT_SEND_CNT = <NUM_LIT:5> ; public static final int INET_STAT_SEND_MAX = <NUM_LIT:6> ; public static final int INET_STAT_SEND_AVG = <NUM_LIT:7> ; public static final int INET_STAT_SEND_PND = <NUM_LIT:8> ; public static final int INET_STAT_RECV_OCT = <NUM_LIT:9> ; public static final int INET_STAT_SEND_OCT = <NUM_LIT:10> ; public static final int INET_IFF_UP = <NUM_LIT> ; public static final int INET_IFF_BROADCAST = <NUM_LIT> ; public static final int INET_IFF_LOOPBACK = <NUM_LIT> ; public static final int INET_IFF_POINTTOPOINT = <NUM_LIT> ; public static final int INET_IFF_RUNNING = <NUM_LIT> ; public static final int INET_IFF_MULTICAST = <NUM_LIT> ; public static final int INET_IFF_DOWN = <NUM_LIT> ; public static final int INET_IFF_NBROADCAST = <NUM_LIT> ; public static final int INET_IFF_NPOINTTOPOINT = <NUM_LIT> ; public static final int SCTP_FLAG_UNORDERED = ( <NUM_LIT:1> ) ; public static final int SCTP_FLAG_ADDR_OVER = ( <NUM_LIT:2> ) ; public static final int SCTP_FLAG_ABORT = ( <NUM_LIT:4> ) ; public static final int SCTP_FLAG_EOF = ( <NUM_LIT:8> ) ; public static final int SCTP_FLAG_SNDALL = ( <NUM_LIT:16> ) ; public static final int SCTP_FLAG_HB_ENABLE = ( <NUM_LIT:1> ) ; public static final int SCTP_FLAG_HB_DISABLE = ( <NUM_LIT:2> ) ; public static final int SCTP_FLAG_HB_DEMAND = ( <NUM_LIT:4> ) ; public static final int SCTP_FLAG_PMTUD_ENABLE = ( <NUM_LIT:8> ) ; public static final int SCTP_FLAG_PMTUD_DISABLE = ( <NUM_LIT:16> ) ; public static final int SCTP_FLAG_SACDELAY_ENABLE = ( <NUM_LIT:32> ) ; public static final int SCTP_FLAG_SACDELAY_DISABLE = ( <NUM_LIT> ) ; public static final int INET_DEF_BUFFER = <NUM_LIT> ; public static final int INET_MIN_BUFFER = <NUM_LIT:1> ; public static final int INET_MAX_BUFFER = ( <NUM_LIT> * <NUM_LIT> ) ; public static final byte [ ] EXBADPORT = "<STR_LIT>" . getBytes ( Charset . forName ( "<STR_LIT>" ) ) ; public static final byte [ ] EXBADSEQ = "<STR_LIT>" . getBytes ( Charset . forName ( "<STR_LIT>" ) ) ; public static final int INET_HIGH_WATERMARK = ( <NUM_LIT> * <NUM_LIT:8> ) ; public static final int INET_LOW_WATERMARK = ( <NUM_LIT> * <NUM_LIT:4> ) ; public static final int INET_INFINITY = <NUM_LIT> ; private static final EAtom am_inet_async = EAtom . intern ( "<STR_LIT>" ) ; private static final EAtom am_inet_reply = EAtom . intern ( "<STR_LIT>" ) ; private static final int INVALID_EVENT = <NUM_LIT> ; private static final int SOL_SOCKET = <NUM_LIT> ; private static final EAtom am_closed = EAtom . intern ( "<STR_LIT>" ) ; private static final EAtom am_empty_out_q = EAtom . intern ( "<STR_LIT>" ) ; private static final EAtom am_tcp = EAtom . intern ( "<STR_LIT>" ) ; private static final EAtom am_tcp_closed = EAtom . intern ( "<STR_LIT>" ) ; private static final EAtom am_timeout = EAtom . intern ( "<STR_LIT>" ) ; private static final EAtom am_tcp_error = EAtom . intern ( "<STR_LIT>" ) ; private static final byte [ ] NOPROC = new byte [ ] { '<CHAR_LIT>' , '<CHAR_LIT>' , '<CHAR_LIT>' , '<CHAR_LIT>' , '<CHAR_LIT>' , '<CHAR_LIT: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 > ( <NUM_LIT:1> ) ; private InetSocketAddress remote ; ActiveType active = ActiveType . PASSIVE ; private RingQueue < AsyncOp > opt = new RingQueue < AsyncOp > ( <NUM_LIT: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 = <NUM_LIT> ; 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 ( "<STR_LIT>" ) ; } copy . fd = sock ; copy . caller = caller ; copy . opt = new RingQueue < AsyncOp > ( <NUM_LIT: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 } ) == <NUM_LIT: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 , "<STR_LIT>" , ev ) ; } if ( ! is_connected ( ) ) { if ( ( tcp_add_flags & TCP_ADDF_DELAYED_CLOSE_SEND ) != <NUM_LIT: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 ) == <NUM_LIT:0> ) { inet_reply_ok ( caller ) ; } else { log . fine ( "<STR_LIT>" ) ; } } 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 ( <NUM_LIT:1> ) ; hbuf . put ( <NUM_LIT:0> , ( byte ) ( len & <NUM_LIT> ) ) ; break ; case TCP_PB_2 : hbuf = ByteBuffer . allocate ( <NUM_LIT:2> ) ; hbuf . putShort ( <NUM_LIT:0> , ( short ) ( len & <NUM_LIT> ) ) ; break ; case TCP_PB_4 : hbuf = ByteBuffer . allocate ( <NUM_LIT:4> ) ; hbuf . putInt ( <NUM_LIT:0> , ( int ) len ) ; break ; default : if ( len == <NUM_LIT:0> ) { return <NUM_LIT:0> ; } } inet_output_count ( len + ( hbuf == null ? <NUM_LIT:0> : hbuf . limit ( ) ) ) ; if ( hbuf != null ) { len += hbuf . remaining ( ) ; if ( ev . length > <NUM_LIT:0> && ev [ <NUM_LIT:0> ] . remaining ( ) == <NUM_LIT:0> ) { ev [ <NUM_LIT:0> ] = hbuf ; } else { ByteBuffer [ ] ev2 = new ByteBuffer [ ev . length + <NUM_LIT:1> ] ; ev2 [ <NUM_LIT:0> ] = hbuf ; System . arraycopy ( ev , <NUM_LIT:0> , ev2 , <NUM_LIT:1> , ev . length ) ; ev = ev2 ; } } if ( ( sz = driver_sizeq ( ) ) > <NUM_LIT: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 <NUM_LIT:1> ; } } else { int vsize = ev . length ; long n ; if ( ( tcp_add_flags & TCP_ADDF_DELAY_SEND ) != <NUM_LIT:0> ) { if ( log . isLoggable ( Level . FINE ) ) log . fine ( "<STR_LIT>" ) ; n = <NUM_LIT: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 = <NUM_LIT:0> ; } } if ( n == len ) { assert empty_out_q_subs . isEmpty ( ) : "<STR_LIT>" ; return <NUM_LIT:0> ; } driver_enqv ( ev ) ; sock_select ( ERL_DRV_WRITE | <NUM_LIT:0> , SelectMode . SET ) ; } return <NUM_LIT:0> ; } private void inet_output_count ( long len ) { this . send_oct += len ; this . send_cnt += <NUM_LIT:1> ; if ( len > send_max ) send_max = ( int ) len ; } private long remaining ( ByteBuffer [ ] ev ) { long res = <NUM_LIT:0> ; for ( int i = <NUM_LIT: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 ( "<STR_LIT>" + this + "<STR_LIT>" + Integer . toBinaryString ( ops ) + "<STR_LIT>" + 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 <NUM_LIT: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 ( "<STR_LIT>" + this + "<STR_LIT>" + ch ) ; if ( is_connected ( ) ) { int rcv = tcp_recv ( <NUM_LIT:0> ) ; if ( log . isLoggable ( Level . FINE ) ) log . fine ( "<STR_LIT>" + rcv ) ; } else { if ( log . isLoggable ( Level . FINE ) ) log . fine ( "<STR_LIT>" ) ; } } private int tcp_recv ( int request_len ) throws Pausable { if ( log . isLoggable ( Level . FINER ) ) log . finer ( "<STR_LIT>" + request_len ) ; int n , len , nread ; if ( i_buf == null ) { if ( log . isLoggable ( Level . FINER ) ) log . finer ( "<STR_LIT>" ) ; int sz = ( request_len > <NUM_LIT:0> ) ? request_len : this . bufsz ; try { i_buf = ByteBuffer . allocate ( sz ) ; } catch ( OutOfMemoryError e ) { return - <NUM_LIT:1> ; } i_ptr_start = <NUM_LIT:0> ; nread = sz ; if ( request_len > <NUM_LIT:0> ) { i_remain = request_len ; } else { i_remain = <NUM_LIT:0> ; } } else if ( request_len > <NUM_LIT:0> ) { n = i_buf . position ( ) - i_ptr_start ; if ( log . isLoggable ( Level . FINER ) ) log . finer ( "<STR_LIT>" + n + "<STR_LIT>" ) ; if ( n >= request_len ) { return tcp_deliver ( request_len ) ; } else if ( tcp_expand_buffer ( request_len ) < <NUM_LIT:0> ) { return tcp_recv_error ( Posix . ENOMEM ) ; } else { i_remain = nread = request_len - n ; } } else if ( i_remain == <NUM_LIT:0> ) { if ( log . isLoggable ( Level . FINER ) ) log . finer ( "<STR_LIT>" ) ; int [ ] lenp = new int [ <NUM_LIT:1> ] ; if ( ( nread = tcp_remain ( lenp ) ) < <NUM_LIT:0> ) { return tcp_recv_error ( Posix . EMSGSIZE ) ; } else if ( nread == <NUM_LIT:0> ) { return tcp_deliver ( lenp [ <NUM_LIT:0> ] ) ; } else if ( lenp [ <NUM_LIT:0> ] > <NUM_LIT:0> ) { i_remain = lenp [ <NUM_LIT:0> ] ; } } else { if ( log . isLoggable ( Level . FINER ) ) log . finer ( "<STR_LIT>" + i_remain ) ; nread = i_remain ; } try { ReadableByteChannel rbc = ( ReadableByteChannel ) fd . channel ( ) ; if ( rbc instanceof SocketChannel ) { SocketChannel sc = ( SocketChannel ) rbc ; if ( sc . isBlocking ( ) ) { log . fine ( "<STR_LIT>" + sc ) ; } } else { log . warning ( "<STR_LIT>" + 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 ( "<STR_LIT>" + n + "<STR_LIT>" + i_buf . remaining ( ) + "<STR_LIT:)>" ) ; if ( n == <NUM_LIT:0> ) return <NUM_LIT: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 < <NUM_LIT:0> ) { try { fd . channel ( ) . close ( ) ; } catch ( IOException e ) { } return tcp_recv_closed ( ) ; } if ( i_remain > <NUM_LIT:0> ) { i_remain -= n ; if ( i_remain == <NUM_LIT:0> ) { return tcp_deliver ( i_buf . position ( ) - i_ptr_start ) ; } } else { int [ ] lenp = new int [ <NUM_LIT:1> ] ; nread = tcp_remain ( lenp ) ; if ( ( nread ) < <NUM_LIT:0> ) { return tcp_recv_error ( Posix . EMSGSIZE ) ; } else if ( nread == <NUM_LIT:0> ) { return tcp_deliver ( lenp [ <NUM_LIT:0> ] ) ; } else if ( lenp [ <NUM_LIT:0> ] > <NUM_LIT:0> ) { i_remain = lenp [ <NUM_LIT:0> ] ; } } return <NUM_LIT: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 ( <NUM_LIT:0> ) ; } else { desc_close_read ( ) ; } } return - <NUM_LIT:1> ; } private void tcp_clear_output ( ) throws Pausable { int qsz = driver_sizeq ( ) ; ByteBuffer [ ] q = driver_peekq ( ) ; if ( q != null ) { for ( int i = <NUM_LIT: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 <NUM_LIT: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 - <NUM_LIT: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 != <NUM_LIT: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 ( "<STR_LIT>" + caller + "<STR_LIT>" + 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 ( <NUM_LIT: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 ( "<STR_LIT>" + 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 = <NUM_LIT: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 ( "<STR_LIT>" + 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 ( "<STR_LIT>" + this ) ; } if ( ( state & INET_F_MULTI_CLIENT ) != <NUM_LIT: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 = <NUM_LIT: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 = <NUM_LIT: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 == <NUM_LIT: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 = <NUM_LIT:0> ; } } private void desc_close ( ) { sock_select ( ERL_DRV_USE , SelectMode . CLEAR ) ; fd = null ; event_mask = <NUM_LIT: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 , "<STR_LIT>" , 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 - <NUM_LIT:1> : return ctl_error ( Posix . EINVAL ) ; case <NUM_LIT:0> : return ctl_reply ( INET_REP_OK , new byte [ <NUM_LIT:0> ] ) ; default : tcp_deliver ( <NUM_LIT:0> ) ; return ctl_reply ( INET_REP_OK , new byte [ <NUM_LIT:0> ] ) ; } case INET_REQ_GETSTAT : return inet_getstat ( buf ) ; } throw new erjang . NotImplemented ( "<STR_LIT>" + command + "<STR_LIT:)>" ) ; } private ByteBuffer inet_getstat ( ByteBuffer buf ) { int outsize = <NUM_LIT:1> + ( buf . remaining ( ) + <NUM_LIT:2> ) * <NUM_LIT: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 ) == <NUM_LIT:0> ) { log . fine ( "<STR_LIT>" ) ; return ctl_error ( Posix . ENOTCONN ) ; } InetSocketAddress addr = fd . getRemoteAddress ( ) ; InetAddress a = addr . getAddress ( ) ; if ( log . isLoggable ( Level . FINE ) ) log . fine ( "<STR_LIT>" + addr ) ; byte [ ] bytes = a . getAddress ( ) ; int port = addr . getPort ( ) ; byte [ ] data = new byte [ <NUM_LIT:1> + <NUM_LIT:2> + bytes . length ] ; data [ <NUM_LIT:0> ] = ( byte ) sfamily . code ; data [ <NUM_LIT:1> ] = ( byte ) ( ( port > > <NUM_LIT:8> ) & <NUM_LIT> ) ; data [ <NUM_LIT:2> ] = ( byte ) ( port & <NUM_LIT> ) ; System . arraycopy ( bytes , <NUM_LIT:0> , data , <NUM_LIT: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 ) != <NUM_LIT:0> ) { tcp_add_flags &= ~ ( TCP_ADDF_DELAYED_CLOSE_RECV | TCP_ADDF_DELAYED_CLOSE_SEND ) ; return ctl_reply ( INET_REP_ERROR , "<STR_LIT>" ) ; } else { return ctl_error ( Posix . ENOTCONN ) ; } } if ( active != ActiveType . PASSIVE || buf . remaining ( ) != <NUM_LIT:8> ) { return ctl_error ( Posix . EINVAL ) ; } int timeout = buf . getInt ( ) ; int n = buf . getInt ( ) ; if ( htype != PacketParseType . TCP_PB_RAW && n != <NUM_LIT:0> ) return ctl_error ( Posix . EINVAL ) ; if ( n > <NUM_LIT> ) return ctl_error ( Posix . ENOMEM ) ; ByteBuffer tbuf = ByteBuffer . allocate ( <NUM_LIT:2> ) ; if ( enq_async ( caller2 , tbuf , TCP_REQ_RECV ) < <NUM_LIT:0> ) return ctl_error ( Posix . EALREADY ) ; if ( log . isLoggable ( Level . FINER ) ) log . finer ( "<STR_LIT>" + caller2 + "<STR_LIT>" + tbuf . getShort ( <NUM_LIT:0> ) + "<STR_LIT>" + timeout ) ; int rep ; if ( ( rep = tcp_recv ( n ) ) == <NUM_LIT:0> ) { if ( timeout == <NUM_LIT: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 ( "<STR_LIT>" + 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 ? <NUM_LIT:0> : active == ActiveType . ACTIVE ? <NUM_LIT:1> : <NUM_LIT: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 ? <NUM_LIT:1> : <NUM_LIT:0> ) ; continue ; case INET_LOPT_BIT8 : ptr . write ( opt ) ; ptr . writeInt ( bit8f ? ( bit8 ? <NUM_LIT:1> : <NUM_LIT: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 ? <NUM_LIT:1> : <NUM_LIT:0> ) ; } continue ; case INET_LOPT_TCP_DELAY_SEND : if ( stype == ProtocolType . STREAM ) { ptr . write ( opt ) ; ptr . writeInt ( ( ( tcp_add_flags & TCP_ADDF_DELAY_SEND ) != <NUM_LIT:0> ) ? <NUM_LIT:1> : <NUM_LIT: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 ( <NUM_LIT:0> ) ; continue ; case INET_OPT_TOS : ptr . write ( opt ) ; ptr . writeInt ( <NUM_LIT:0> ) ; continue ; case INET_OPT_REUSEADDR : try { boolean val = fd . getReuseAddress ( ) ; ptr . write ( opt ) ; ptr . writeInt ( val ? <NUM_LIT:1> : <NUM_LIT:0> ) ; continue ; } catch ( IOException e ) { continue ; } case INET_OPT_KEEPALIVE : try { boolean val = fd . getKeepAlive ( ) ; ptr . write ( opt ) ; ptr . writeInt ( val ? <NUM_LIT:1> : <NUM_LIT: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 ? <NUM_LIT:1> : <NUM_LIT:0> ) ; continue ; } catch ( IOException e ) { continue ; } default : throw new NotImplemented ( "<STR_LIT>" + ( ( 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 ( ) != <NUM_LIT: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 <= <NUM_LIT:0> ) { time_left = <NUM_LIT: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 [ <NUM_LIT:2> ] ; data [ <NUM_LIT:0> ] = ( byte ) ( id > > > <NUM_LIT:8> ) ; data [ <NUM_LIT:1> ] = ( byte ) ( id & <NUM_LIT> ) ; 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 [ <NUM_LIT:2> ] ; data [ <NUM_LIT:0> ] = ( byte ) ( id > > > <NUM_LIT:8> ) ; data [ <NUM_LIT:1> ] = ( byte ) ( id & <NUM_LIT> ) ; return ctl_reply ( INET_REP_OK , data ) ; } case TCP_STATE_LISTEN : ByteBuffer reply = ByteBuffer . allocate ( <NUM_LIT: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 ( ) > <NUM_LIT: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 ( ) & <NUM_LIT> ) ; AsyncOp op = new AsyncOp ( id , caller , req , - <NUM_LIT: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 ( <NUM_LIT: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 ( ) != <NUM_LIT:2> ) { return ctl_error ( Posix . EINVAL ) ; } int backlog = buf . getShort ( ) & <NUM_LIT> ; 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 = <NUM_LIT:0> ; while ( buf . remaining ( ) >= <NUM_LIT: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 ( <NUM_LIT:0> ) ; return <NUM_LIT:0> ; } else { desc_close_read ( ) ; } } res = <NUM_LIT: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 ( "<STR_LIT>" + ( ival != <NUM_LIT:0> ) + "<STR_LIT>" + this ) ; this . exitf = ( ival == <NUM_LIT: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 < <NUM_LIT:0> ) ival = <NUM_LIT:0> ; else if ( ival > INET_MAX_BUFFER * <NUM_LIT:2> ) ival = INET_MAX_BUFFER * <NUM_LIT:2> ; if ( this . low > ival ) this . low = ival ; this . high = ival ; } continue ; case INET_LOPT_TCP_LOWTRMRK : if ( this . stype == ProtocolType . STREAM ) { if ( ival < <NUM_LIT:0> ) ival = <NUM_LIT: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 == <NUM_LIT:0> ? false : true ; } continue ; case INET_LOPT_TCP_DELAY_SEND : if ( this . stype == ProtocolType . STREAM ) { if ( ival != <NUM_LIT: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 <= <NUM_LIT:0> ) return - <NUM_LIT:1> ; this . read_packets = ival ; } continue ; case INET_OPT_REUSEADDR : try { fd . setReuseAddress ( ival != <NUM_LIT:0> ) ; } catch ( IOException e ) { if ( propagate ) return - <NUM_LIT:1> ; } continue ; case INET_OPT_KEEPALIVE : try { fd . setKeepAlive ( ival != <NUM_LIT:0> ) ; } catch ( IOException e ) { if ( propagate ) return - <NUM_LIT:1> ; } break ; case INET_OPT_DONTROUTE : continue ; case INET_OPT_BROADCAST : try { fd . setBroadcast ( ival != <NUM_LIT:0> ) ; } catch ( IOException e ) { if ( propagate ) return - <NUM_LIT:1> ; } continue ; case INET_OPT_OOBINLINE : try { fd . setOOBInline ( ival != <NUM_LIT:0> ) ; } catch ( IOException e ) { if ( propagate ) return - <NUM_LIT:1> ; } continue ; case INET_OPT_SNDBUF : try { fd . setSendBufferSize ( ival ) ; } catch ( IOException e ) { if ( propagate ) return - <NUM_LIT:1> ; } continue ; case INET_OPT_RCVBUF : try { fd . setReceiveBufferSize ( ival ) ; if ( ival > this . bufsz ) { this . bufsz = ival ; } } catch ( IOException e ) { if ( propagate ) return - <NUM_LIT:1> ; } continue ; case INET_OPT_LINGER : if ( buf . remaining ( ) < <NUM_LIT:4> ) return - <NUM_LIT:1> ; int linger = buf . getInt ( ) ; try { fd . setLinger ( ival != <NUM_LIT:0> , linger ) ; } catch ( IOException e ) { if ( propagate ) return - <NUM_LIT:1> ; } continue ; case INET_OPT_PRIORITY : continue ; case INET_OPT_TOS : try { fd . setTrafficClass ( ival ) ; } catch ( IOException e ) { if ( propagate ) return - <NUM_LIT:1> ; } continue ; case TCP_OPT_NODELAY : try { fd . setTcpNoDelay ( ival != <NUM_LIT:0> ) ; } catch ( IOException e ) { if ( propagate ) return - <NUM_LIT:1> ; } continue ; default : return - <NUM_LIT: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 <NUM_LIT:1> ; } return <NUM_LIT:0> ; } } return <NUM_LIT:0> ; } private byte [ ] int_to_ip ( int ival ) { return new byte [ ] { ( byte ) ( ( ival > > > <NUM_LIT:24> ) & <NUM_LIT> ) , ( byte ) ( ( ival > > > <NUM_LIT:16> ) & <NUM_LIT> ) , ( byte ) ( ( ival > > > <NUM_LIT:8> ) & <NUM_LIT> ) , ( byte ) ( ( ival ) & <NUM_LIT> ) , } ; } 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 ) == <NUM_LIT: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 ( "<STR_LIT>" + i_ptr_start + "<STR_LIT::>" + len ) ; int count = <NUM_LIT:0> ; int n ; int [ ] lenp = new int [ ] { len } ; if ( len == <NUM_LIT:0> ) { if ( i_buf == null || i_remain > <NUM_LIT:0> ) { return count ; } n = tcp_remain ( lenp ) ; len = lenp [ <NUM_LIT:0> ] ; if ( n != <NUM_LIT:0> ) { if ( n < <NUM_LIT:0> ) { if ( log . isLoggable ( Level . WARNING ) ) log . warning ( "<STR_LIT>" + n ) ; return n ; } if ( len > <NUM_LIT:0> ) i_remain = len ; return count ; } } while ( len > <NUM_LIT:0> ) { if ( log . isLoggable ( Level . FINER ) ) log . finer ( "<STR_LIT>" ) ; int code = <NUM_LIT:0> ; inet_input_count ( len ) ; if ( len * <NUM_LIT:4> >= i_buf . capacity ( ) * <NUM_LIT:3> ) { if ( log . isLoggable ( Level . FINER ) ) log . finer ( "<STR_LIT>" ) ; if ( i_ptr_start + len == i_buf . position ( ) ) { code = tcp_reply_data ( i_buf . array ( ) , i_buf . arrayOffset ( ) + i_ptr_start , len ) ; if ( code >= <NUM_LIT: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 >= <NUM_LIT:0> ) { i_buf = bin ; i_ptr_start = <NUM_LIT:0> ; i_remain = <NUM_LIT:0> ; } } } else { if ( log . isLoggable ( Level . FINER ) ) log . finer ( "<STR_LIT>" ) ; 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 >= <NUM_LIT:0> ) tcp_clear_input ( ) ; } else { byte [ ] data = new byte [ len ] ; System . arraycopy ( i_buf . array ( ) , i_buf . arrayOffset ( ) + i_ptr_start , data , <NUM_LIT:0> , len ) ; code = tcp_reply_data ( data , <NUM_LIT:0> , len ) ; if ( code >= <NUM_LIT:0> ) { i_ptr_start += len ; i_remain = <NUM_LIT:0> ; } } } if ( code < <NUM_LIT:0> ) { if ( log . isLoggable ( Level . WARNING ) ) log . warning ( "<STR_LIT>" + code ) ; return code ; } count ++ ; len = <NUM_LIT:0> ; if ( active == ActiveType . PASSIVE ) { driver_cancel_timer ( ) ; sock_select ( ERL_DRV_READ | <NUM_LIT:0> , SelectMode . CLEAR ) ; if ( i_buf != null ) { tcp_restart_input ( ) ; } } else if ( i_buf != null ) { lenp [ <NUM_LIT:0> ] = len ; n = tcp_remain ( lenp ) ; len = lenp [ <NUM_LIT:0> ] ; if ( n != <NUM_LIT:0> ) { if ( n < <NUM_LIT:0> ) return n ; tcp_restart_input ( ) ; if ( len > <NUM_LIT:0> ) i_remain = len ; len = <NUM_LIT:0> ; } } } return count ; } private void inet_input_count ( int len ) { recv_cnt += <NUM_LIT: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 != <NUM_LIT: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 = <NUM_LIT: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 ( "<STR_LIT>" + 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 ) ) == <NUM_LIT:0> ) { if ( active == ActiveType . PASSIVE ) { return inet_async_data ( <NUM_LIT:0> , out ) ; } else { code = tcp_message ( out ) ; } } if ( code < <NUM_LIT: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 <NUM_LIT:0> ; } private int inet_async_data ( int i , ByteBuffer out ) { AsyncOp op = deq_async ( ) ; if ( op == null ) return - <NUM_LIT:1> ; if ( log . isLoggable ( Level . FINER ) ) log . finer ( "<STR_LIT>" + op . caller + "<STR_LIT>" + 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 ( "<STR_LIT>" + op . caller + "<STR_LIT>" + res ) ; } op . caller . sendb ( res ) ; return <NUM_LIT: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 <NUM_LIT:0> ; } else if ( hsz > <NUM_LIT:0> ) { out . limit ( out . position ( ) ) ; out . position ( hsz ) ; ByteBuffer tail = out . slice ( ) ; tail . position ( tail . limit ( ) ) ; out . limit ( hsz ) ; driver_output2 ( out , tail ) ; return <NUM_LIT:0> ; } else { driver_output ( out ) ; return <NUM_LIT: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 ) ) == <NUM_LIT:0> ) { if ( active == ActiveType . PASSIVE ) { return inet_async_binary_data ( <NUM_LIT:0> , out ) ; } else { code = tcp_binary_message ( out ) ; } } if ( code < <NUM_LIT: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 = <NUM_LIT:0> ; int rem = out . remaining ( ) ; for ( int i = <NUM_LIT:0> ; i < rem ; i ++ ) { c |= out . get ( i ) ; } bit8 = ( ( c & <NUM_LIT> ) != <NUM_LIT:0> ) ; } private void tcp_clear_input ( ) { i_buf = null ; i_ptr_start = <NUM_LIT:0> ; i_remain = <NUM_LIT:0> ; } private int tcp_expand_buffer ( int len ) { int used = i_ptr_start ; int ulen = used + len ; if ( i_buf . limit ( ) >= ulen ) { return <NUM_LIT:0> ; } else if ( i_buf . capacity ( ) >= ulen ) { i_buf . limit ( ulen ) ; return <NUM_LIT:0> ; } try { ByteBuffer bin = ByteBuffer . allocate ( ulen ) ; i_buf . flip ( ) ; bin . put ( i_buf ) ; i_buf = bin ; return <NUM_LIT:0> ; } catch ( OutOfMemoryError e ) { return - <NUM_LIT: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 = <NUM_LIT: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 = <NUM_LIT:0> ; } } i_remain = <NUM_LIT:0> ; return <NUM_LIT: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 > <NUM_LIT:0> ) { if ( tlen <= n ) { lenp [ <NUM_LIT:0> ] = tlen ; return <NUM_LIT:0> ; } else { if ( tcp_expand_buffer ( tlen ) < <NUM_LIT:0> ) { return - <NUM_LIT:1> ; } lenp [ <NUM_LIT:0> ] = ( tlen - n ) ; return lenp [ <NUM_LIT:0> ] ; } } else if ( tlen == <NUM_LIT:0> ) { lenp [ <NUM_LIT:0> ] = <NUM_LIT:0> ; if ( nsz == <NUM_LIT:0> ) { if ( nfill == n ) { return - <NUM_LIT:1> ; } else { return nfill - n ; } } else { return nsz ; } } return - <NUM_LIT:1> ; } private ByteBuffer inet_open ( ByteBuffer cmd ) { if ( cmd . remaining ( ) == <NUM_LIT: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 ( <NUM_LIT: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 ( ) < <NUM_LIT: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 == <NUM_LIT:0> ) { port = fd . getLocalPort ( ) ; } ByteBuffer reply = ByteBuffer . allocate ( <NUM_LIT:3> ) ; reply . order ( ByteOrder . nativeOrder ( ) ) ; reply . put ( INET_REP_OK ) ; reply . putShort ( ( short ) ( port & <NUM_LIT> ) ) ; 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 ( ) == <NUM_LIT: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 ( "<STR_LIT>" + caller + "<STR_LIT>" + 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 ( "<STR_LIT>" + caller + "<STR_LIT>" + 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 ( "<STR_LIT>" + caller + "<STR_LIT>" + 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 ( "<STR_LIT>" + caller + "<STR_LIT>" + 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 ( <NUM_LIT:0> ) ; private short enq_async_w_tmo ( EPID caller , ByteBuffer reply , int req , int timeout , ERef monitor ) { short id = ( short ) ( aid . incrementAndGet ( ) & <NUM_LIT> ) ; 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 ( ) & <NUM_LIT> ; byte [ ] bytes ; if ( sfamily2 == ProtocolFamily . INET ) { bytes = new byte [ <NUM_LIT:4> ] ; } else if ( sfamily2 == ProtocolFamily . INET6 ) { bytes = new byte [ <NUM_LIT:16> ] ; } else { return null ; } InetAddress addr ; try { if ( cmd . remaining ( ) == <NUM_LIT: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 ( <NUM_LIT:1> + cmd . remaining ( ) * <NUM_LIT: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 > <NUM_LIT:0> ) { save_subscriber ( empty_out_q_subs , caller ) ; } reply . putInt ( val ) ; } else { throw new ErlangError ( EAtom . intern ( "<STR_LIT>" ) ) ; } } 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 ( <NUM_LIT: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 ( <NUM_LIT:1> + data . length ) ; buf . put ( ( byte ) code ) ; buf . put ( data ) ; return buf ; } private ByteBuffer ctl_reply ( int code , String data ) { ByteBuffer buf = ByteBuffer . allocate ( <NUM_LIT:1> + data . length ( ) ) ; buf . put ( ( byte ) code ) ; for ( int i = <NUM_LIT: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 ) != <NUM_LIT:0> ) sb . append ( "<STR_LIT>" ) ; if ( ( state & TCP_STATE_BOUND ) != <NUM_LIT:0> ) sb . append ( "<STR_LIT>" ) ; if ( ( state & TCP_STATE_CLOSED ) != <NUM_LIT:0> ) sb . append ( "<STR_LIT>" ) ; if ( ( state & TCP_STATE_CONNECTED ) != <NUM_LIT:0> ) sb . append ( "<STR_LIT>" ) ; if ( ( state & TCP_STATE_CONNECTING ) != <NUM_LIT:0> ) sb . append ( "<STR_LIT>" ) ; if ( ( state & TCP_STATE_LISTEN ) != <NUM_LIT:0> ) sb . append ( "<STR_LIT>" ) ; if ( ( state & TCP_STATE_MULTI_ACCEPTING ) != <NUM_LIT:0> ) sb . append ( "<STR_LIT>" ) ; if ( ( state & TCP_STATE_OPEN ) != <NUM_LIT:0> ) sb . append ( "<STR_LIT>" ) ; } @ Override public String toString ( ) { StringBuffer sb = new StringBuffer ( "<STR_LIT>" ) ; sb . append ( System . identityHashCode ( this ) ) ; sb . append ( '<CHAR_LIT:[>' ) ; sb . append ( "<STR_LIT>" ) . append ( fd ) ; sb . append ( "<STR_LIT>" ) ; state ( sb ) ; sb . append ( "<STR_LIT>" ) . append ( active ) ; sb . append ( "<STR_LIT>" ) . append ( deliver ) ; sb . append ( "<STR_LIT>" ) . append ( Integer . toBinaryString ( event_mask ) ) ; if ( fd != null && fd . channel ( ) != null ) { SelectionKey sk = NIOSelector . interest ( fd . channel ( ) ) ; if ( sk == null ) { sb . append ( "<STR_LIT>" ) ; } else if ( ! sk . isValid ( ) ) { sb . append ( "<STR_LIT>" ) ; } else { try { sb . append ( "<STR_LIT>" + Integer . toBinaryString ( sk . readyOps ( ) ) ) ; sb . append ( "<STR_LIT>" + Integer . toBinaryString ( sk . interestOps ( ) ) ) ; } catch ( CancelledKeyException e ) { sb . append ( "<STR_LIT>" ) ; } } } sb . append ( '<CHAR_LIT:]>' ) ; return sb . toString ( ) ; } } </s>
|
<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>
|
<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 = <NUM_LIT> ; private static final int HTTP_METH_HASH_SIZE = <NUM_LIT> ; private static final int HTTP_MAX_NAME_LEN = <NUM_LIT:20> ; public static void get_body ( PacketParseType htype , ByteBuffer out ) { switch ( htype ) { case TCP_PB_1 : out . position ( out . position ( ) + <NUM_LIT:1> ) ; break ; case TCP_PB_2 : out . position ( out . position ( ) + <NUM_LIT:2> ) ; break ; case TCP_PB_4 : out . position ( out . position ( ) + <NUM_LIT:4> ) ; break ; case TCP_PB_FCGI : out . limit ( out . limit ( ) - ( <NUM_LIT> & out . get ( <NUM_LIT: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 ) < <NUM_LIT:0> ) pcb . http_error ( arg , data , buf , len ) ; return <NUM_LIT:1> ; case TCP_PB_SSL_TLS : return parse_ssl ( data , buf , len , pcb , arg ) ; default : } return <NUM_LIT: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 >= <NUM_LIT:2> ) && ( data [ buf + n - <NUM_LIT:2> ] == '<STR_LIT>' ) ) n -= <NUM_LIT:2> ; else if ( ( n >= <NUM_LIT:1> ) && ( data [ buf + n - <NUM_LIT:1> ] == '<STR_LIT:\n>' ) ) n -= <NUM_LIT:1> ; if ( statep . get ( ) == <NUM_LIT:0> ) { if ( n >= <NUM_LIT:5> && ( strncmp ( data , buf , "<STR_LIT>" , <NUM_LIT:5> ) == <NUM_LIT:0> ) ) { int major = <NUM_LIT:0> ; int minor = <NUM_LIT:0> ; int status = <NUM_LIT:0> ; ptr += <NUM_LIT:5> ; n -= <NUM_LIT:5> ; p0 = ptr ; while ( n != <NUM_LIT:0> && isdigit ( data , ptr ) ) { major = <NUM_LIT:10> * major + ( data [ ptr ] - '<CHAR_LIT:0>' ) ; ptr ++ ; n -- ; } if ( ptr == p0 || n == <NUM_LIT:0> || ( data [ ptr ] != '<CHAR_LIT:.>' ) ) return - <NUM_LIT:1> ; ptr ++ ; n -- ; p0 = ptr ; while ( n != <NUM_LIT:0> && isdigit ( ( int ) data [ ptr ] ) ) { minor = <NUM_LIT:10> * minor + ( data [ ptr ] - '<CHAR_LIT:0>' ) ; ptr ++ ; n -- ; } if ( ptr == p0 ) return - <NUM_LIT:1> ; p0 = ptr ; while ( n != <NUM_LIT:0> && SP ( data , ptr ) ) { ptr ++ ; n -- ; } if ( ptr == p0 ) return - <NUM_LIT:1> ; while ( n != <NUM_LIT:0> && isdigit ( ( int ) data [ ptr ] ) ) { status = <NUM_LIT:10> * status + ( data [ ptr ] - '<CHAR_LIT:0>' ) ; ptr ++ ; n -- ; } p0 = ptr ; while ( n != <NUM_LIT:0> && SP ( data , ptr ) ) { ptr ++ ; n -- ; } if ( ptr == p0 ) return - <NUM_LIT:1> ; statep . set ( ~ <NUM_LIT: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 = <NUM_LIT:0> ; int minor = <NUM_LIT:0> ; int h = <NUM_LIT:0> ; while ( n != <NUM_LIT:0> && ! is_tspecial ( data [ ptr ] ) ) { h = hash_update ( h , data [ ptr ] ) ; ptr ++ ; n -- ; } meth_len = ptr - meth_ptr ; if ( n == <NUM_LIT:0> || meth_len == <NUM_LIT:0> || ! SP ( data , ptr ) ) return - <NUM_LIT:1> ; meth = http_hash_lookup ( data , meth_ptr , meth_len , h , http_meth_hash ) ; while ( n != <NUM_LIT:0> && SP ( data , ptr ) ) { ptr ++ ; n -- ; } uri_ptr = ptr ; while ( n != <NUM_LIT:0> && ! SP ( data , ptr ) ) { ptr ++ ; n -- ; } if ( ( uri_len = ( ptr - uri_ptr ) ) == <NUM_LIT:0> ) return - <NUM_LIT:1> ; while ( n != <NUM_LIT:0> && SP ( data , ptr ) ) { ptr ++ ; n -- ; } if ( n == <NUM_LIT:0> ) { statep . set ( ~ <NUM_LIT:0> ) ; uri = http_parse_uri ( data , uri_ptr , uri_len ) ; return pcb . http_request ( arg , meth , data , meth_ptr , meth_len , uri , <NUM_LIT:0> , <NUM_LIT:9> ) ; } if ( n < <NUM_LIT:8> ) return - <NUM_LIT:1> ; if ( strncmp ( data , ptr , "<STR_LIT>" , <NUM_LIT:5> ) != <NUM_LIT:0> ) return - <NUM_LIT:1> ; ptr += <NUM_LIT:5> ; n -= <NUM_LIT:5> ; p0 = ptr ; while ( n != <NUM_LIT:0> && isdigit ( ( int ) data [ ptr ] ) ) { major = <NUM_LIT:10> * major + ( data [ ptr ] - '<CHAR_LIT:0>' ) ; ptr ++ ; n -- ; } if ( ptr == p0 || n == <NUM_LIT:0> || ( data [ ptr ] != '<CHAR_LIT:.>' ) ) return - <NUM_LIT:1> ; ptr ++ ; n -- ; p0 = ptr ; while ( n != <NUM_LIT:0> && isdigit ( ( int ) data [ ptr ] ) ) { minor = <NUM_LIT:10> * minor + ( data [ ptr ] - '<CHAR_LIT:0>' ) ; ptr ++ ; n -- ; } if ( ptr == p0 ) return - <NUM_LIT:1> ; statep . set ( ~ <NUM_LIT: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 = <NUM_LIT:1> ; HTTPAtom name ; byte [ ] name_buf = new byte [ HTTP_MAX_NAME_LEN ] ; int name_ptr = <NUM_LIT:0> ; int name_len ; int h ; if ( n == <NUM_LIT:0> ) { statep . set ( <NUM_LIT:0> ) ; return pcb . http_eoh ( arg ) ; } h = <NUM_LIT:0> ; name_len = <NUM_LIT:0> ; while ( ! is_tspecial ( data [ ptr ] ) ) { if ( name_len < HTTP_MAX_NAME_LEN ) { byte c = data [ ptr ] ; if ( up != <NUM_LIT:0> ) { if ( islower ( c ) ) { c = toupper ( c ) ; } up = <NUM_LIT:0> ; } else { if ( isupper ( c ) ) c = tolower ( c ) ; else if ( c == '<CHAR_LIT:->' ) up = <NUM_LIT:1> ; } name_buf [ name_len ] = c ; h = hash_update ( h , c ) ; } name_len ++ ; ptr ++ ; if ( -- n == <NUM_LIT:0> ) return - <NUM_LIT:1> ; } while ( n != <NUM_LIT:0> && SP ( data , ptr ) ) { ptr ++ ; n -- ; } if ( data [ ptr ] != '<CHAR_LIT::>' ) { return - <NUM_LIT:1> ; } if ( name_len <= HTTP_MAX_NAME_LEN ) { name = http_hash_lookup ( name_buf , <NUM_LIT:0> , name_len , h , http_hdr_hash ) ; } else { name_ptr = buf ; name = null ; } ptr ++ ; n -- ; while ( n != <NUM_LIT: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 , <NUM_LIT:0> , len ) == <NUM_LIT:0> ) { return entry ; } } return null ; } private static int strncmp ( byte [ ] data , int ptr , byte [ ] string , int string_ptr , int i ) { for ( int p = <NUM_LIT:0> ; p < i ; p ++ ) { int val = string [ string_ptr + p ] - data [ ptr + p ] ; if ( val != <NUM_LIT:0> ) return val ; } return <NUM_LIT:0> ; } private static int strncmp ( byte [ ] data , int ptr , String string , int i ) { for ( int p = <NUM_LIT:0> ; p < i ; p ++ ) { int val = string . charAt ( p ) - data [ ptr + p ] ; if ( val != <NUM_LIT:0> ) return val ; } return <NUM_LIT:0> ; } private static PacketHttpURI http_parse_uri ( byte [ ] data , int uri_ptr , int uri_len ) { PacketHttpURI uri = new PacketHttpURI ( ) ; if ( ( uri_len == <NUM_LIT:1> ) && ( data [ uri_ptr + <NUM_LIT:0> ] == '<CHAR_LIT>' ) ) uri . type = URIType . URI_STAR ; else if ( ( uri_len <= <NUM_LIT:1> ) || ( data [ uri_ptr + <NUM_LIT:0> ] == '<CHAR_LIT:/>' ) ) { uri . type = URIType . URI_ABS_PATH ; uri . s1_data = data ; uri . s1_ptr = uri_ptr ; uri . s1_len = uri_len ; } else if ( ( uri_len >= <NUM_LIT:7> ) && ( STRNCASECMP ( data , uri_ptr , "<STR_LIT:http://>" , <NUM_LIT:7> ) == <NUM_LIT:0> ) ) { uri_len -= <NUM_LIT:7> ; uri_ptr += <NUM_LIT:7> ; uri . type = URIType . URI_HTTP ; http_parse_absoluteURI ( uri , data , uri_ptr , uri_len ) ; } else if ( ( uri_len >= <NUM_LIT:8> ) && ( STRNCASECMP ( data , uri_ptr , "<STR_LIT>" , <NUM_LIT:8> ) == <NUM_LIT:0> ) ) { uri_len -= <NUM_LIT:8> ; uri_ptr += <NUM_LIT:8> ; uri . type = URIType . URI_HTTPS ; http_parse_absoluteURI ( uri , data , uri_ptr , uri_len ) ; } else { int ptr ; if ( ( ptr = memchr ( data , uri_ptr , '<CHAR_LIT::>' , uri_len ) ) == - <NUM_LIT: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 + <NUM_LIT:1> ) ; uri . s2_len = uri_len - ( slen + <NUM_LIT:1> ) ; } } return uri ; } static final byte [ ] SLASH = new byte [ ] { '<CHAR_LIT:/>' } ; private static void http_parse_absoluteURI ( PacketHttpURI uri , byte [ ] data , int uri_ptr , int uri_len ) { int p ; if ( ( p = memchr ( data , uri_ptr , '<CHAR_LIT:/>' , uri_len ) ) == - <NUM_LIT:1> ) { uri . s2_data = SLASH ; uri . s2_ptr = <NUM_LIT:0> ; uri . s2_len = <NUM_LIT: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 = <NUM_LIT:0> ; if ( ( p = memchr ( data , uri_ptr , '<CHAR_LIT::>' , uri_len ) ) == - <NUM_LIT:1> ) { uri . s1_len = uri_len ; } else { int n = ( p - uri_ptr ) ; int port = <NUM_LIT:0> ; uri . s1_len = n ; n = uri_len - ( n + <NUM_LIT:1> ) ; p ++ ; while ( n != <NUM_LIT:0> && isdigit ( data [ p ] ) ) { port = port * <NUM_LIT:10> + ( data [ p ] - '<CHAR_LIT:0>' ) ; n -- ; p ++ ; } if ( n == <NUM_LIT:0> && port != <NUM_LIT:0> ) uri . port = port ; } } private static int STRNCASECMP ( byte [ ] data , int s1 , String s2 , int n ) { int i ; for ( i = <NUM_LIT:0> ; i < n - <NUM_LIT:1> && data [ s1 + i ] != <NUM_LIT: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 = <NUM_LIT:0> , len = <NUM_LIT:0> , h = <NUM_LIT: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 [ <NUM_LIT> ] ; 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 [ ] = { "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT:Content-Type>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , null } ; static String http_meth_strings [ ] = { "<STR_LIT>" , "<STR_LIT:GET>" , "<STR_LIT>" , "<STR_LIT:POST>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , null } ; static { int i ; for ( i = <NUM_LIT:0> ; i < <NUM_LIT> ; i ++ ) tspecial [ i ] = true ; String specials = "<STR_LIT>" ; for ( i = <NUM_LIT:0> ; i < specials . length ( ) ; i ++ ) { char val = specials . charAt ( i ) ; tspecial [ val ] = true ; } for ( i = <NUM_LIT:0> ; i < HTTP_HDR_HASH_SIZE ; i ++ ) http_hdr_hash [ i ] = null ; for ( i = <NUM_LIT: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 = <NUM_LIT:0> ; i < HTTP_METH_HASH_SIZE ; i ++ ) http_hdr_hash [ i ] = null ; for ( i = <NUM_LIT: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 < <NUM_LIT:0> ) return false ; return tspecial [ x ] ; } static final int hash_update ( int h , int c ) { c &= <NUM_LIT> ; int __g ; ( h ) = ( ( h ) << <NUM_LIT:4> ) + ( c ) ; if ( ( __g = ( h ) & <NUM_LIT> ) != <NUM_LIT:0> ) { ( h ) ^= ( __g > > > <NUM_LIT:24> ) ; ( h ) ^= __g ; } return h ; } private static boolean isdigit ( byte [ ] data , int ptr ) { byte ch = data [ ptr ] ; return ( ch >= '<CHAR_LIT:0>' && ch <= '<CHAR_LIT:9>' ) ; } private static boolean isdigit ( int data ) { return ( data >= '<CHAR_LIT:0>' && data <= '<CHAR_LIT: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 == <NUM_LIT:0> ) return <NUM_LIT:0> ; else return n ; case TCP_PB_1 : hlen = <NUM_LIT:1> ; if ( n < hlen ) return <NUM_LIT:0> ; plen = data [ ptr ] & <NUM_LIT> ; break ; case TCP_PB_2 : hlen = <NUM_LIT:2> ; if ( n < hlen ) return <NUM_LIT:0> ; plen = ( ( data [ ptr ] & <NUM_LIT> ) << <NUM_LIT:8> ) | ( data [ ptr + <NUM_LIT:1> ] & <NUM_LIT> ) ; break ; case TCP_PB_4 : hlen = <NUM_LIT:4> ; if ( n < hlen ) return <NUM_LIT:0> ; plen = ( ( data [ ptr ] & <NUM_LIT> ) << <NUM_LIT:24> ) | ( ( data [ ptr + <NUM_LIT:1> ] & <NUM_LIT> ) << <NUM_LIT:16> ) | ( ( data [ ptr + <NUM_LIT:2> ] & <NUM_LIT> ) << <NUM_LIT:8> ) | ( data [ ptr + <NUM_LIT:3> ] & <NUM_LIT> ) ; break ; case TCP_PB_LINE_LF : { int ptr2 ; if ( ( ptr2 = memchr ( data , ptr , '<STR_LIT:\n>' , n ) ) == - <NUM_LIT:1> ) { if ( n >= trunc_len && trunc_len != <NUM_LIT:0> ) { return trunc_len ; } return <NUM_LIT:0> ; } int len = ( ptr2 - ptr ) + <NUM_LIT:1> ; if ( len > trunc_len && trunc_len != <NUM_LIT:0> ) { return trunc_len ; } return len ; } case TCP_PB_HTTPH : case TCP_PB_HTTPH_BIN : statep . set ( ~ <NUM_LIT:0> ) ; case TCP_PB_HTTP : case TCP_PB_HTTP_BIN : plen = n ; if ( ( ( plen == <NUM_LIT:1> ) && NL ( data , ptr ) ) || ( ( plen == <NUM_LIT:2> ) && CRNL ( data , ptr ) ) ) return plen ; else { int ptr1 = ptr ; int len = plen ; while ( true ) { int ptr2 = memchr ( data , ptr1 , '<STR_LIT:\n>' , len ) ; if ( ptr2 == - <NUM_LIT:1> ) { if ( n >= trunc_len && trunc_len != <NUM_LIT:0> ) { plen = trunc_len ; return plen ; } return <NUM_LIT:0> ; } else { plen = ( ptr2 - ptr ) + <NUM_LIT:1> ; if ( statep . get ( ) == <NUM_LIT:0> ) return plen ; if ( plen < n ) { if ( SP ( data , ptr2 + <NUM_LIT:1> ) && plen > <NUM_LIT:2> ) { ptr1 = ptr2 + <NUM_LIT:1> ; len = n - plen ; } else return plen ; } else return <NUM_LIT:0> ; } } } default : throw new NotImplemented ( "<STR_LIT>" + htype ) ; } int tlen = hlen + plen ; if ( ( max_plen != <NUM_LIT:0> && plen > max_plen ) || tlen < hlen ) { return - <NUM_LIT:1> ; } return tlen ; } private static boolean SP ( byte [ ] data , int ptr ) { return data [ ptr ] == '<CHAR_LIT:U+0020>' || data [ ptr ] == '<STR_LIT:\t>' ; } private static boolean CRNL ( byte [ ] data , int ptr ) { return data [ ptr ] == '<STR_LIT>' && data [ ptr + <NUM_LIT:1> ] == '<STR_LIT:\n>' ; } private static boolean NL ( byte [ ] data , int ptr ) { return data [ ptr ] == '<STR_LIT:\n>' ; } private static int memchr ( byte [ ] data , int offset , char c , int n ) { for ( int i = <NUM_LIT:0> ; i < n ; i ++ ) { if ( data [ offset + i ] == c ) return offset + i ; } return - <NUM_LIT:1> ; } } </s>
|
<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>
|
<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 ( "<STR_LIT>" ) ; private static final EAtom am_inet_async = EAtom . intern ( "<STR_LIT>" ) ; private static final EAtom am_http = EAtom . intern ( "<STR_LIT:http>" ) ; private static final EAtom am_star = EAtom . intern ( "<STR_LIT:*>" ) ; private static final EAtom am_abs_path = EAtom . intern ( "<STR_LIT>" ) ; private static final EAtom am_https = EAtom . intern ( "<STR_LIT>" ) ; private static final EAtom am_absoluteURI = EAtom . intern ( "<STR_LIT>" ) ; private static final EAtom am_scheme = EAtom . intern ( "<STR_LIT>" ) ; private static final EAtom am_http_header = EAtom . intern ( "<STR_LIT>" ) ; private static final EAtom am_http_eoh = EAtom . intern ( "<STR_LIT>" ) ; private static final EAtom am_http_error = EAtom . intern ( "<STR_LIT>" ) ; @ 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 - <NUM_LIT: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 <NUM_LIT: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 ( <NUM_LIT:0> ) : ERT . box ( name . index + <NUM_LIT: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 - <NUM_LIT: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 <NUM_LIT: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 == <NUM_LIT: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 ( "<STR_LIT>" ) ; } 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 , <NUM_LIT: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>
|
<s> package erjang . driver . tcp_inet ; public final class IntCell { int value ; int get ( ) { return value ; } void set ( int val ) { value = val ; } } </s>
|
<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 "<STR_LIT>" ; } @ 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>
|
<s> package erjang . driver . tcp_inet ; public enum PacketParseType { TCP_PB_RAW ( <NUM_LIT:0> ) , TCP_PB_1 ( <NUM_LIT:1> ) , TCP_PB_2 ( <NUM_LIT:2> ) , TCP_PB_4 ( <NUM_LIT:3> ) , TCP_PB_ASN1 ( <NUM_LIT:4> ) , TCP_PB_RM ( <NUM_LIT:5> ) , TCP_PB_CDR ( <NUM_LIT:6> ) , TCP_PB_FCGI ( <NUM_LIT:7> ) , TCP_PB_LINE_LF ( <NUM_LIT:8> ) , TCP_PB_TPKT ( <NUM_LIT:9> ) , TCP_PB_HTTP ( <NUM_LIT:10> ) , TCP_PB_HTTPH ( <NUM_LIT:11> ) , TCP_PB_SSL_TLS ( <NUM_LIT:12> ) , TCP_PB_HTTP_BIN ( <NUM_LIT> ) , TCP_PB_HTTPH_BIN ( <NUM_LIT> ) ; public final int code ; private PacketParseType ( int code ) { this . code = code ; } public static PacketParseType valueOf ( int ival ) { switch ( ival ) { case <NUM_LIT:0> : return TCP_PB_RAW ; case <NUM_LIT:1> : return TCP_PB_1 ; case <NUM_LIT:2> : return TCP_PB_2 ; case <NUM_LIT:3> : return TCP_PB_4 ; case <NUM_LIT:4> : return TCP_PB_ASN1 ; case <NUM_LIT:5> : return TCP_PB_RM ; case <NUM_LIT:6> : return TCP_PB_CDR ; case <NUM_LIT:7> : return TCP_PB_FCGI ; case <NUM_LIT:8> : return TCP_PB_LINE_LF ; case <NUM_LIT:9> : return TCP_PB_TPKT ; case <NUM_LIT:10> : return TCP_PB_HTTP ; case <NUM_LIT:11> : return TCP_PB_HTTPH ; case <NUM_LIT:12> : return TCP_PB_SSL_TLS ; case <NUM_LIT> : return TCP_PB_HTTP_BIN ; case <NUM_LIT> : return TCP_PB_HTTPH_BIN ; default : throw new IllegalArgumentException ( ) ; } } } </s>
|
<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 "<STR_LIT>" ; } @ 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>
|
<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 ( "<STR_LIT:/>" ) ) { fileName = fileName . substring ( <NUM_LIT: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 ( "<STR_LIT>" ) ) { listJarURL ( res , url ) ; } if ( url . getProtocol ( ) . equals ( "<STR_LIT: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 ( '<CHAR_LIT>' ) ; String jar = path . substring ( "<STR_LIT>" . length ( ) , bang ) ; String elm = path . substring ( bang + <NUM_LIT: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 ( ) + <NUM_LIT:1> ) ; int idx ; if ( ( idx = rest . indexOf ( '<CHAR_LIT:/>' ) ) != - <NUM_LIT:1> ) { res . add ( rest . substring ( <NUM_LIT:0> , idx ) ) ; } else if ( rest . length ( ) != <NUM_LIT:0> ) { res . add ( rest ) ; } } public static void fstat ( EFile efile , String file_name ) throws Pausable { try { ZipEntry ent ; ent = get_entry ( file_name + "<STR_LIT:/>" ) ; 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 = ( <NUM_LIT:1> + ( <NUM_LIT> * <NUM_LIT: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 ( <NUM_LIT> ) ; res . putInt ( <NUM_LIT:1> ) ; res . putInt ( <NUM_LIT:0> ) ; res . putInt ( <NUM_LIT:0> ) ; res . putInt ( file_name . hashCode ( ) ) ; res . putInt ( <NUM_LIT:0> ) ; res . putInt ( <NUM_LIT: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 + <NUM_LIT: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 ( "<STR_LIT>" ) ) { 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 ( '<CHAR_LIT>' ) ; String jar = path . substring ( "<STR_LIT>" . length ( ) , bang ) ; String elm = path . substring ( bang + <NUM_LIT:2> ) ; ZipFile z = new ZipFile ( jar ) ; try { ZipEntry ze = z . getEntry ( elm ) ; if ( ze != null ) return ze ; } finally { z . close ( ) ; } return null ; } } </s>
|
<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 ( "<STR_LIT>" ) ; public static final String RESOURCE_PREFIX = "<STR_LIT>" ; private static Field FileDescriptor_FD ; static { try { FileDescriptor_FD = FileDescriptor . class . getDeclaredField ( "<STR_LIT>" ) ; 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 == - <NUM_LIT:1> ) res = <NUM_LIT: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 = <NUM_LIT:1> ; this . q_mtx = efile . q_mtx ; this . size = efile . write_buffered ; super . reply = reply ; this . free_size = <NUM_LIT:0> ; this . reply_size = reply_size ; } @ Override public void async ( ) { int size ; boolean segment = again && this . size >= <NUM_LIT: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 = <NUM_LIT:0> ; int iovcnt = <NUM_LIT:0> ; while ( p < size && iovcnt < iov . length ) { p += iov [ iovcnt ++ ] . remaining ( ) ; } if ( iov . length > <NUM_LIT:0> ) { assert iov [ iovcnt - <NUM_LIT:1> ] . limit ( ) > p - size ; if ( ( flags & EFILE_COMPRESSED ) == EFILE_COMPRESSED ) { for ( int i = <NUM_LIT: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 ( "<STR_LIT>" + EFile . this + "<STR_LIT>" + 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 == <NUM_LIT: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 = <NUM_LIT:1> ; public static final int EFILE_MODE_WRITE = <NUM_LIT:2> ; public static final int EFILE_MODE_READ_WRITE = <NUM_LIT:3> ; public static final int EFILE_MODE_APPEND = <NUM_LIT:4> ; public static final int EFILE_COMPRESSED = <NUM_LIT:8> ; public static final int EFILE_NO_TRUNCATE = <NUM_LIT:16> ; public static final int EFILE_SEEK_SET = <NUM_LIT:0> ; public static final int EFILE_SEEK_CUR = <NUM_LIT:1> ; public static final int EFILE_SEEK_END = <NUM_LIT:2> ; public static final int FT_DEVICE = <NUM_LIT:1> ; public static final int FT_DIRECTORY = <NUM_LIT:2> ; public static final int FT_REGULAR = <NUM_LIT:3> ; public static final int FT_SYMLINK = <NUM_LIT:4> ; public static final int FT_OTHER = <NUM_LIT:5> ; public static final int FA_NONE = <NUM_LIT:0> ; public static final int FA_WRITE = <NUM_LIT:1> ; public static final int FA_READ = <NUM_LIT:2> ; public static final int FA_EXECUTE = <NUM_LIT:4> ; public static final int FILE_OPEN = <NUM_LIT:1> ; public static final int FILE_READ = <NUM_LIT:2> ; public static final int FILE_LSEEK = <NUM_LIT:3> ; public static final int FILE_WRITE = <NUM_LIT:4> ; public static final int FILE_FSTAT = <NUM_LIT:5> ; public static final int FILE_PWD = <NUM_LIT:6> ; public static final int FILE_READDIR = <NUM_LIT:7> ; public static final int FILE_CHDIR = <NUM_LIT:8> ; public static final int FILE_FSYNC = <NUM_LIT:9> ; public static final int FILE_MKDIR = <NUM_LIT:10> ; public static final int FILE_DELETE = <NUM_LIT:11> ; public static final int FILE_RENAME = <NUM_LIT:12> ; public static final int FILE_RMDIR = <NUM_LIT> ; public static final int FILE_TRUNCATE = <NUM_LIT> ; public static final int FILE_READ_FILE = <NUM_LIT:15> ; public static final int FILE_WRITE_INFO = <NUM_LIT:16> ; public static final int FILE_LSTAT = <NUM_LIT> ; public static final int FILE_READLINK = <NUM_LIT:20> ; public static final int FILE_LINK = <NUM_LIT> ; public static final int FILE_SYMLINK = <NUM_LIT> ; public static final int FILE_CLOSE = <NUM_LIT> ; public static final int FILE_PWRITEV = <NUM_LIT:24> ; public static final int FILE_PREADV = <NUM_LIT> ; public static final int FILE_SETOPT = <NUM_LIT> ; public static final int FILE_IPREAD = <NUM_LIT> ; public static final int FILE_ALTNAME = <NUM_LIT> ; public static final int FILE_READ_LINE = <NUM_LIT> ; public static final int FILE_FDATASYNC = <NUM_LIT:30> ; public static final int FILE_FADVISE = <NUM_LIT:31> ; public static final byte FILE_RESP_OK = <NUM_LIT:0> ; private static final byte [ ] FILE_RESP_OK_HEADER = new byte [ ] { FILE_RESP_OK } ; public static final byte FILE_RESP_ERROR = <NUM_LIT:1> ; public static final byte FILE_RESP_DATA = <NUM_LIT:2> ; public static final byte FILE_RESP_NUMBER = <NUM_LIT:3> ; public static final byte FILE_RESP_INFO = <NUM_LIT:4> ; public static final byte FILE_RESP_NUMERR = <NUM_LIT:5> ; public static final byte FILE_RESP_LDATA = <NUM_LIT:6> ; public static final byte FILE_RESP_N2DATA = <NUM_LIT:7> ; public static final byte FILE_RESP_EOF = <NUM_LIT:8> ; public static final byte FILE_RESP_FNAME = <NUM_LIT:9> ; public static final byte FILE_RESP_ALL_DATA = <NUM_LIT:10> ; private static final byte [ ] FILE_RESP_ALL_DATA_HEADER = new byte [ ] { FILE_RESP_ALL_DATA } ; public static final int FILE_OPT_DELAYED_WRITE = <NUM_LIT:0> ; public static final int FILE_OPT_READ_AHEAD = <NUM_LIT:1> ; public static final int IPREAD_S32BU_P32BU = <NUM_LIT:0> ; public static final int POSIX_FADV_NORMAL = <NUM_LIT:0> ; public static final int POSIX_FADV_RANDOM = <NUM_LIT:1> ; public static final int POSIX_FADV_SEQUENTIAL = <NUM_LIT:2> ; public static final int POSIX_FADV_WILLNEED = <NUM_LIT:3> ; public static final int POSIX_FADV_DONTNEED = <NUM_LIT:4> ; public static final int POSIX_FADV_NOREUSE = <NUM_LIT:5> ; public static final int FILE_SEGMENT_READ = ( <NUM_LIT> * <NUM_LIT> ) ; public static final int FILE_SEGMENT_WRITE = ( <NUM_LIT> * <NUM_LIT> ) ; public static final int FILE_TYPE_DEVICE = <NUM_LIT:0> ; public static final int FILE_TYPE_DIRECTORY = <NUM_LIT:2> ; public static final int FILE_TYPE_REGULAR = <NUM_LIT:3> ; public static final int FILE_TYPE_SYMLINK = <NUM_LIT:4> ; public static final int FILE_ACCESS_NONE = <NUM_LIT:0> ; public static final int FILE_ACCESS_WRITE = <NUM_LIT:1> ; public static final int FILE_ACCESS_READ = <NUM_LIT:2> ; public static final int FILE_ACCESS_READ_WRITE = <NUM_LIT:3> ; private static final int THREAD_SHORT_CIRCUIT ; static { String buf = System . getenv ( "<STR_LIT>" ) ; if ( buf == null ) { THREAD_SHORT_CIRCUIT = <NUM_LIT:0> ; } else { THREAD_SHORT_CIRCUIT = Integer . parseInt ( buf ) ; } } public EFile ( EString command , Driver driver ) { super ( driver ) ; this . fd = ( FileChannel ) null ; this . flags = <NUM_LIT:0> ; this . invoke = null ; this . cq = new LinkedList < FileAsync > ( ) ; this . timer_state = TimerState . IDLE ; this . read_binp = ( ByteBuffer ) null ; this . write_delay = <NUM_LIT> ; this . write_bufsize = <NUM_LIT:0> ; this . q_mtx = driver_pdl_create ( ) ; this . write_buffered = <NUM_LIT:0> ; } public void reply_Uint ( int value ) throws Pausable { if ( isUnicodeDriverInterface ( ) ) { ByteBuffer response = ByteBuffer . allocate ( <NUM_LIT:9> ) ; response . put ( FILE_RESP_NUMBER ) ; response . putLong ( value ) ; driver_output2 ( response , null ) ; } else { ByteBuffer response = ByteBuffer . allocate ( <NUM_LIT:4> ) ; response . putInt ( value ) ; driver_output2 ( response , null ) ; } } public void reply_Uint_error ( int value , int posix_error ) throws Pausable { ByteBuffer response = ByteBuffer . allocate ( <NUM_LIT> ) ; 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 ( <NUM_LIT> ) ; 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 == <NUM_LIT:0> ) ; cq_execute ( ) ; } private abstract class SimpleFileAsync extends FileAsync { protected final File file ; protected final String name ; { level = <NUM_LIT: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 == <NUM_LIT:0> || ev [ <NUM_LIT:0> ] . remaining ( ) == <NUM_LIT:0> ) { reply_posix_error ( Posix . EINVAL ) ; return ; } byte command = ev [ <NUM_LIT: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 + <NUM_LIT:1> ] ; for ( int i = <NUM_LIT:1> ; i < n + <NUM_LIT:1> ; i ++ ) { offsets [ i - <NUM_LIT:1> ] = evin . getLong ( ) ; int len = ( int ) ( evin . getLong ( ) & <NUM_LIT> ) ; res_ev [ i ] = ByteBuffer . allocate ( len ) ; if ( log . isLoggable ( Level . FINER ) ) { log . finer ( EFile . this + "<STR_LIT>" + len + "<STR_LIT>" + offsets [ i - <NUM_LIT:1> ] ) ; } } res_ev [ <NUM_LIT:0> ] = ByteBuffer . allocate ( <NUM_LIT:4> + <NUM_LIT:4> + <NUM_LIT:8> * n ) ; res_ev [ <NUM_LIT:0> ] . putInt ( <NUM_LIT:0> ) ; res_ev [ <NUM_LIT:0> ] . putInt ( n ) ; if ( n == <NUM_LIT:0> ) { reply_ev ( FILE_RESP_LDATA , offsets , res_ev ) ; } else { cq_enq ( new FileAsync ( ) { int cnt ; { this . level = <NUM_LIT:1> ; this . fd = EFile . this . fd ; this . cnt = <NUM_LIT:0> ; this . result_ok = true ; } @ Override public void async ( ) { for ( int i = cnt ; i < n ; i ++ ) { ByteBuffer res = res_ev [ i + <NUM_LIT:1> ] ; long pos = offsets [ i ] + res . position ( ) ; int rem = res . remaining ( ) ; if ( rem > <NUM_LIT:0> ) { int bytes_read ; try { fd . position ( pos ) ; bytes_read = fd . read ( res ) ; if ( log . isLoggable ( Level . FINER ) ) { log . finer ( EFile . this + "<STR_LIT>" + bytes_read + "<STR_LIT:@>" + pos + "<STR_LIT>" + i + "<STR_LIT>" + res . remaining ( ) ) ; } } catch ( IOException e ) { result_ok = false ; this . posix_errno = IO . exception_to_posix_code ( e ) ; this . again = false ; return ; } if ( bytes_read >= <NUM_LIT:0> && res . hasRemaining ( ) ) { this . again = true ; return ; } res_ev [ <NUM_LIT:0> ] . putLong ( res . position ( ) ) ; cnt += <NUM_LIT: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 > <NUM_LIT:1> && ev [ <NUM_LIT:0> ] . hasRemaining ( ) ) { reply_posix_error ( Posix . EINVAL ) ; return ; } ByteBuffer last = ev [ ev . length - <NUM_LIT:1> ] ; if ( last . hasRemaining ( ) ) { reply_posix_error ( Posix . EINVAL ) ; return ; } if ( log . isLoggable ( Level . FINE ) ) log . fine ( "<STR_LIT>" + this + "<STR_LIT>" ) ; 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 [ <NUM_LIT:1> ] ; if ( flush_write_check_error ( errp ) < <NUM_LIT:0> ) { reply_posix_error ( errp [ <NUM_LIT:0> ] ) ; return ; } if ( ev . length > <NUM_LIT:1> && ev [ <NUM_LIT:0> ] . hasRemaining ( ) ) { reply_posix_error ( Posix . EINVAL ) ; return ; } ByteBuffer last = ev [ ev . length - <NUM_LIT:1> ] ; if ( last . remaining ( ) != <NUM_LIT:8> ) { reply_posix_error ( Posix . EINVAL ) ; return ; } final long size = last . getLong ( ) ; if ( size > Integer . MAX_VALUE || size < <NUM_LIT:0> ) { reply_posix_error ( Posix . ENOMEM ) ; return ; } FileAsync d = new FileAsync ( ) { private ByteBuffer binp = null ; { super . level = <NUM_LIT: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 + "<STR_LIT>" + bytes + "<STR_LIT>" + want ) ; } if ( bytes == - <NUM_LIT: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 > <NUM_LIT:1> && ev [ <NUM_LIT:0> ] . hasRemaining ( ) ) { reply_posix_error ( Posix . EINVAL ) ; return ; } ByteBuffer last = ev [ ev . length - <NUM_LIT:1> ] ; final String name = IO . getstr ( last , false ) ; if ( name . length ( ) == <NUM_LIT: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 = <NUM_LIT:0> ; { super . level = <NUM_LIT: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 < <NUM_LIT: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 == - <NUM_LIT: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 [ <NUM_LIT:1> ] ; if ( lseek_flush_read ( errp ) < <NUM_LIT:0> ) { reply_posix_error ( errp [ <NUM_LIT:0> ] ) ; return ; } if ( flush_write_check_error ( errp ) < <NUM_LIT:0> ) { reply_posix_error ( errp [ <NUM_LIT:0> ] ) ; return ; } final int n = ev [ <NUM_LIT:0> ] . getInt ( ) ; if ( n == <NUM_LIT:0> ) { if ( ev . length > <NUM_LIT:1> || ev [ <NUM_LIT:0> ] . hasRemaining ( ) ) { reply_posix_error ( Posix . EINVAL ) ; } else { reply_Uint ( <NUM_LIT:0> ) ; } return ; } if ( ev [ <NUM_LIT:0> ] . remaining ( ) != ( <NUM_LIT:8> * <NUM_LIT:2> * n ) ) { reply_posix_error ( Posix . EINVAL ) ; return ; } final long [ ] offsets = new long [ n ] ; final long [ ] sizes = new long [ n ] ; long total = <NUM_LIT:0> ; for ( int i = <NUM_LIT:0> ; i < n ; i ++ ) { offsets [ i ] = ev [ <NUM_LIT:0> ] . getLong ( ) ; sizes [ i ] = ev [ <NUM_LIT:0> ] . getLong ( ) ; total += sizes [ i ] ; } if ( total == <NUM_LIT:0> ) { reply_Uint ( <NUM_LIT:0> ) ; return ; } q_mtx . lock ( ) ; try { driver_enqv ( ev ) ; } finally { q_mtx . unlock ( ) ; } FileAsync d = new FileAsync ( ) { int cnt = <NUM_LIT:0> ; { this . level = <NUM_LIT: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 = <NUM_LIT:0> ; while ( cnt < offsets . length && ip < iov . length ) { if ( sizes [ cnt ] == <NUM_LIT:0> ) { cnt += <NUM_LIT: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 ( "<STR_LIT>" + EFile . this + "<STR_LIT>" + 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 ] == <NUM_LIT:0> ) { cnt += <NUM_LIT: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 = <NUM_LIT:0> ; for ( int i = <NUM_LIT:0> ; i < ev . length ; i ++ ) { reply_size += ev [ i ] . remaining ( ) ; if ( log . isLoggable ( Level . FINER ) ) log . finer ( "<STR_LIT>" + this + "<STR_LIT>" + 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 [ <NUM_LIT:1> ] , true , reply_size ) != <NUM_LIT:0> ) { reply_posix_error ( errp [ <NUM_LIT:0> ] ) ; q_mtx . unlock ( ) ; } else { q_mtx . unlock ( ) ; } break ; } default : ev [ <NUM_LIT:0> ] . position ( ev [ <NUM_LIT:0> ] . position ( ) - <NUM_LIT:1> ) ; output ( caller , flatten ( ev ) ) ; } cq_execute ( ) ; } private int flush_write_check_error ( int [ ] errp ) { int r ; if ( ( r = flush_write ( errp ) ) != <NUM_LIT: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 [ <NUM_LIT:0> ] = this . posix_errno ; } return - <NUM_LIT:1> ; } return <NUM_LIT:0> ; } void flush_read ( ) { this . read_binp = null ; } private int lseek_flush_read ( int [ ] errp ) { int r = <NUM_LIT:0> ; int read_size = ( read_binp == null ? <NUM_LIT:0> : read_binp . remaining ( ) ) ; flush_read ( ) ; if ( read_size != <NUM_LIT:0> ) { if ( ( r = async_lseek ( errp , false , - read_size , EFILE_SEEK_CUR ) ) < <NUM_LIT: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 = <NUM_LIT:1> ; this . fd = EFile . this . fd ; } long out_pos ; @ Override public void async ( ) { if ( ( flags & EFILE_COMPRESSED ) != <NUM_LIT: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 ( "<STR_LIT>" + EFile . this + "<STR_LIT>" + 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 ( <NUM_LIT: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 [ <NUM_LIT:0> ] = Posix . ENOMEM ; } return - <NUM_LIT:1> ; } return <NUM_LIT:0> ; } private void reply_ev ( byte response , long [ ] offsets , ByteBuffer [ ] res_ev ) throws Pausable { ByteBuffer tmp = ByteBuffer . allocate ( <NUM_LIT:1> ) ; tmp . put ( response ) ; driver_outputv ( tmp , res_ev ) ; } static FilenameFilter READDIR_FILTER = new FilenameFilter ( ) { @ Override public boolean accept ( File dir , String name ) { return ! "<STR_LIT:.>" . equals ( name ) && ! "<STR_LIT>" . 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 = <NUM_LIT: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 = <NUM_LIT: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 ( ) == <NUM_LIT: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 ( "<STR_LIT>" , 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 = <NUM_LIT: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 ( <NUM_LIT:1> ) ; data = ByteBuffer . allocate ( pwd . length ( ) ) ; reply . put ( FILE_RESP_FNAME ) ; IO . putstr ( data , pwd , false ) ; } else { reply = ByteBuffer . allocate ( <NUM_LIT: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 = <NUM_LIT> ; public void run ( ) { boolean compressed = ( mode & EFILE_COMPRESSED ) > <NUM_LIT:0> ; if ( compressed && log . isLoggable ( Level . FINE ) ) { log . fine ( "<STR_LIT>" + file_name ) ; } boolean append = ( mode & EFILE_MODE_APPEND ) > <NUM_LIT:0> ; if ( ( mode & ~ ( EFILE_MODE_APPEND | EFILE_MODE_READ_WRITE ) ) > <NUM_LIT:0> ) { log . warning ( "<STR_LIT>" ) ; throw new NotImplemented ( ) ; } try { if ( compressed ) { if ( ( mode & EFILE_MODE_READ_WRITE ) == EFILE_MODE_READ_WRITE && append ) { posix_errno = Posix . EINVAL ; return ; } log . warning ( "<STR_LIT>" ) ; 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 , "<STR_LIT>" ) ) . 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 , "<STR_LIT>" , e ) ; posix_errno = fileNotFound_to_posixErrno ( file , mode ) ; } catch ( IllegalAccessException e ) { log . log ( Level . WARNING , "<STR_LIT>" , 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 ( ) ? <NUM_LIT> : <NUM_LIT:0> ; file_mode |= file . canWrite ( ) ? <NUM_LIT> : <NUM_LIT:0> ; file_mode |= file . canRead ( ) ? <NUM_LIT> : <NUM_LIT:0> ; file_access |= file . canRead ( ) ? FA_READ : <NUM_LIT:0> ; file_access |= file . canWrite ( ) ? FA_WRITE : <NUM_LIT:0> ; result_ok = true ; } @ Override public void ready ( ) throws Pausable { if ( ! this . result_ok ) { reply_posix_error ( posix_errno ) ; return ; } final int RESULT_SIZE = ( <NUM_LIT:1> + ( <NUM_LIT> * <NUM_LIT: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 ( <NUM_LIT:1> ) ; res . putInt ( <NUM_LIT:0> ) ; res . putInt ( <NUM_LIT:0> ) ; res . putInt ( file_name . hashCode ( ) ) ; res . putInt ( <NUM_LIT:0> ) ; res . putInt ( <NUM_LIT: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 + <NUM_LIT: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 = <NUM_LIT: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 ( "<STR_LIT>" + this + "<STR_LIT>" + from_name + "<STR_LIT>" + 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 ( "<STR_LIT>" + ( ( int ) cmd ) + "<STR_LIT:U+0020>" + EBinary . make ( buf ) ) ; throw new NotImplemented ( "<STR_LIT>" + ( ( int ) cmd ) + "<STR_LIT:U+0020>" + 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 != <NUM_LIT: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 ( <NUM_LIT:0> ) ; return true ; } @ Override protected void readyInput ( SelectableChannel ch ) throws Pausable { throw new InternalError ( "<STR_LIT>" ) ; } @ Override protected void readyOutput ( SelectableChannel evt ) throws Pausable { throw new InternalError ( "<STR_LIT>" ) ; } @ Override protected void timeout ( ) throws Pausable { TimerState timer_state = this . timer_state ; this . timer_state = TimerState . IDLE ; switch ( timer_state ) { case IDLE : assert ( false ) : "<STR_LIT>" ; return ; case AGAIN : assert ( invoke != null ) ; driver_async ( invoke ) ; break ; case WRITE : int r = flush_write ( null ) ; assert ( r == <NUM_LIT:0> ) ; cq_execute ( ) ; } } private int flush_write ( int [ ] errp ) { int result ; q_mtx . lock ( ) ; try { if ( this . write_buffered > <NUM_LIT:0> ) { result = async_write ( null , false , <NUM_LIT:0> ) ; } else { result = <NUM_LIT: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 = <NUM_LIT:0> ; return <NUM_LIT:0> ; } catch ( OutOfMemoryError e ) { if ( errp == null ) { throw e ; } if ( errp != null ) errp [ <NUM_LIT:0> ] = Posix . ENOMEM ; return - <NUM_LIT: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 ( <NUM_LIT:1> + <NUM_LIT:4> + <NUM_LIT:4> ) ; header . put ( FILE_RESP_DATA ) ; header . putLong ( buf . position ( ) ) ; driver_output2 ( header , buf ) ; } void reply_eof ( ) throws Pausable { ByteBuffer header = ByteBuffer . allocate ( <NUM_LIT:1> ) ; header . put ( FILE_RESP_EOF ) ; driver_output2 ( header , null ) ; } public void reply_ok ( ) throws Pausable { ByteBuffer header = ByteBuffer . allocate ( <NUM_LIT: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 ) > <NUM_LIT:0> && ! file . canRead ( ) ) return Posix . EPERM ; else if ( ( mode & EFILE_MODE_WRITE ) > <NUM_LIT:0> && ! file . canWrite ( ) ) return Posix . EPERM ; else return Posix . EUNKNOWN ; } @ Override public String toString ( ) { String pos ; try { pos = ( fd == null ? "<STR_LIT:?>" : "<STR_LIT>" + Long . toHexString ( fd . position ( ) ) ) ; } catch ( IOException e ) { pos = "<STR_LIT:?>" ; } return "<STR_LIT>" + name + "<STR_LIT>" + pos + "<STR_LIT:]>" ; } void reply_list_directory ( String [ ] files ) throws Pausable { for ( int i = <NUM_LIT:0> ; i < files . length ; i ++ ) { if ( isUnicodeDriverInterface ( ) ) { ByteBuffer reply = ByteBuffer . allocate ( <NUM_LIT:1> ) ; reply . put ( FILE_RESP_FNAME ) ; ByteBuffer data = ByteBuffer . allocate ( files [ i ] . length ( ) ) ; data . limit ( data . capacity ( ) ) ; data . position ( <NUM_LIT:0> ) ; IO . putstr ( data , files [ i ] , false ) ; driver_output2 ( reply , data ) ; } else { ByteBuffer resbuf = ByteBuffer . allocate ( files [ i ] . length ( ) + <NUM_LIT:1> ) ; resbuf . put ( FILE_RESP_OK ) ; resbuf . limit ( resbuf . capacity ( ) ) ; resbuf . position ( <NUM_LIT:1> ) ; IO . putstr ( resbuf , files [ i ] , false ) ; driver_output2 ( resbuf , null ) ; } } ByteBuffer resbuf = ByteBuffer . allocate ( <NUM_LIT:1> ) ; resbuf . put ( isUnicodeDriverInterface ( ) ? FILE_RESP_FNAME : FILE_RESP_OK ) ; driver_output2 ( resbuf , null ) ; } private static boolean isUnicodeDriverInterface ( ) { return ERT . runtime_info . unicodeDriverInterface ; } } </s>
|
<s> package erjang . driver . efile ; import java . io . File ; import erjang . EObject ; public class Posix { public static final int EINVAL = <NUM_LIT:0> ; public static final int ENOMEM = <NUM_LIT:1> ; public static final int EEXIST = <NUM_LIT:2> ; public static final int ENOENT = <NUM_LIT:3> ; public static final int EPERM = <NUM_LIT:4> ; public static final int EISCONN = <NUM_LIT:5> ; public static final int EUNKNOWN = <NUM_LIT:6> ; public static final int ENETUNREACH = <NUM_LIT:7> ; public static final int EADDRNOTAVAIL = <NUM_LIT:8> ; public static final int EIO = <NUM_LIT:9> ; public static final int EOPNOTSUPP = <NUM_LIT:10> ; public static final int ECONNREFUSED = <NUM_LIT:11> ; public static final int EMSGSIZE = <NUM_LIT:12> ; public static final int ENOTCONN = <NUM_LIT> ; public static final int EINTR = <NUM_LIT> ; public static final int EAGAIN = <NUM_LIT:15> ; public static final int EALREADY = <NUM_LIT:16> ; private static final String [ ] err_id = { "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" , } ; public static String errno_id ( int posixErrno ) { if ( posixErrno >= err_id . length || posixErrno < <NUM_LIT:0> ) return "<STR_LIT>" ; else return err_id [ posixErrno ] ; } static File CWD = new File ( "<STR_LIT:.>" ) ; public static boolean isCWD ( String name , File file ) { if ( name . equals ( "<STR_LIT:.>" ) ) 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 ( "<STR_LIT>" ) ) . getAbsoluteFile ( ) ; } } </s>
|
<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>
|
<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>
|
<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 = <NUM_LIT:0> ; for ( Map . Entry < String , String > e : env . entrySet ( ) ) { envp [ pos ++ ] = e . getKey ( ) + "<STR_LIT:=>" + 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 ( ) , <NUM_LIT> ) ] ; try { nbytes = stream . read ( data ) ; } catch ( IOException e ) { nbytes = <NUM_LIT:0> ; } } else if ( task . mode == Mode . PACKET ) { switch ( task . packet ) { case <NUM_LIT:1> : nbytes = stream . read ( ) ; break ; case <NUM_LIT:2> : nbytes = stream . readUnsignedShort ( ) ; break ; case <NUM_LIT:4> : nbytes = stream . readInt ( ) & <NUM_LIT> ; break ; default : throw new InternalError ( ) ; } if ( nbytes <= <NUM_LIT:0> ) { return false ; } data = new byte [ nbytes ] ; try { stream . readFully ( data ) ; } catch ( IOException e ) { nbytes = <NUM_LIT:0> ; } } else { throw new NotImplemented ( "<STR_LIT>" + task . mode ) ; } if ( nbytes <= <NUM_LIT:0> ) { return false ; } if ( task . send_binary_data ) { task . output_from_driver_b ( new EBinary ( data , <NUM_LIT:0> , nbytes ) ) ; } else { task . output_from_driver_b ( EString . make ( data , <NUM_LIT: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 <NUM_LIT:1> : for ( int off = <NUM_LIT:0> ; off < data_len ; off += <NUM_LIT> ) { int rest = Math . min ( <NUM_LIT> , data_len - off ) ; out . writeByte ( rest ) ; out . write ( data , data_off + off , rest ) ; } this . out . flush ( ) ; return ; case <NUM_LIT:2> : for ( int off = <NUM_LIT:0> ; off < data_len ; off += ( <NUM_LIT:1> << <NUM_LIT:16> ) ) { int rest = Math . min ( ( <NUM_LIT:1> << <NUM_LIT:16> ) , data_len - off ) ; out . writeShort ( rest ) ; out . write ( data , data_off + off , rest ) ; } this . out . flush ( ) ; return ; case <NUM_LIT:4> : out . writeInt ( data_len ) ; out . write ( data , data_off , data_len ) ; this . out . flush ( ) ; return ; default : throw new Error ( "<STR_LIT>" ) ; } 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>
|
<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 ( "<STR_LIT>" ) ; } else { cmd = new String [ ] { full_cmd } ; } parseOptions ( cmd , portSetting ) ; File f = ERT . newFile ( cmd [ <NUM_LIT:0> ] ) ; if ( f . exists ( ) && f . canExecute ( ) ) { } else if ( f . isAbsolute ( ) ) { throw new ErlangError ( EAtom . intern ( "<STR_LIT>" ) ) ; } else { String cmd_path = env . get ( "<STR_LIT>" ) ; if ( cmd_path != null ) { for ( String elm : cmd_path . split ( File . pathSeparator ) ) { File dir = ERT . newFile ( elm ) ; f = new File ( dir , cmd [ <NUM_LIT:0> ] ) ; if ( f . exists ( ) ) { cmd [ <NUM_LIT:0> ] = f . getAbsolutePath ( ) ; break ; } else { f = null ; } } } } if ( f == null ) { throw new ErlangError ( EAtom . intern ( "<STR_LIT>" ) ) ; } if ( ! f . canExecute ( ) ) { throw new ErlangError ( EAtom . intern ( "<STR_LIT>" ) ) ; } super . setupInstance ( ) ; } @ Override public String toString ( ) { return String . valueOf ( name ) + "<STR_LIT>" + super . toString ( ) ; } } </s>
|
<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>
|
<s> package erjang ; import java . nio . ByteBuffer ; public class IOListBuilder { byte [ ] data = new byte [ <NUM_LIT:10> ] ; int pos = <NUM_LIT:10> ; int len = <NUM_LIT:0> ; ByteBuffer toByteBuffer ( ) { return ByteBuffer . wrap ( data , pos , len ) ; } void prepend ( byte value ) { if ( pos == <NUM_LIT:0> ) { byte [ ] new_data = new byte [ len * <NUM_LIT:2> ] ; System . arraycopy ( data , <NUM_LIT:0> , new_data , len , len ) ; data = new_data ; pos = len ; } data [ -- pos ] = value ; len += <NUM_LIT:1> ; } } </s>
|
<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 = "<STR_LIT>" ) public class ERT { public static Logger log = Logger . getLogger ( "<STR_LIT>" ) ; static Logger ipclog = Logger . getLogger ( "<STR_LIT>" ) ; public static EAtom am_badsig = EAtom . intern ( "<STR_LIT>" ) ; public static EObject raise ( EObject trace , EObject value ) throws ErlangException { log . warning ( "<STR_LIT>" + 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 ( "<STR_LIT>" ) ; } Throwable error = new Throwable ( "<STR_LIT>" + value + "<STR_LIT:U+002CU+0020>" + trace + "<STR_LIT:)>" ) ; log . log ( Level . WARNING , "<STR_LIT>" + value + "<STR_LIT:U+002CU+0020>" + trace + "<STR_LIT:)>" , error ) ; return am_badarg ; } public static final EAtom am_badarg = EAtom . intern ( "<STR_LIT>" ) ; public static final EAtom am_notsup = EAtom . intern ( "<STR_LIT>" ) ; public static final EAtom AM_BADMATCH = EAtom . intern ( "<STR_LIT>" ) ; public static final EAtom AM_BADARITH = EAtom . intern ( "<STR_LIT>" ) ; public static final EAtom am_module = EAtom . intern ( "<STR_LIT>" ) ; 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 ( "<STR_LIT:true>" ) ; public static final EAtom FALSE = EAtom . intern ( "<STR_LIT: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 ( "<STR_LIT>" , new Class [ ] { String . class , byte [ ] . class , int . class , int . class } ) ; definer . setAccessible ( true ) ; } catch ( Exception e ) { throw new ErlangError ( e ) ; } } @ SuppressWarnings ( "<STR_LIT: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 ( '<CHAR_LIT:/>' , '<CHAR_LIT:.>' ) , data , <NUM_LIT: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 ) < <NUM_LIT:0> ) return new EBig ( res ) ; if ( res . compareTo ( INT_MAX_AS_BIG ) > <NUM_LIT: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 ( "<STR_LIT>" ) ; public static final EAtom IGNORED = EAtom . intern ( "<STR_LIT>" ) ; private static final EAtom am_badmatch = EAtom . intern ( "<STR_LIT>" ) ; private static final EAtom am_case_clause = EAtom . intern ( "<STR_LIT>" ) ; public static final EAtom am_undefined = EAtom . intern ( "<STR_LIT>" ) ; public static final EObject am_receive_clause = EAtom . intern ( "<STR_LIT>" ) ; public static final EObject AM_NOT_IMPLEMENTED = EAtom . intern ( "<STR_LIT>" ) ; public static final EAtom AM_TIMEOUT = EAtom . intern ( "<STR_LIT>" ) ; public static final EAtom am_try_case_clause = EAtom . intern ( "<STR_LIT>" ) ; public static final EAtom am_if_clause = EAtom . intern ( "<STR_LIT>" ) ; public static final EBinary EMPTY_BINARY = new EBinary ( new byte [ <NUM_LIT:0> ] ) ; public static final ByteBuffer [ ] EMPTY_BYTEBUFFER_ARR = new ByteBuffer [ <NUM_LIT:0> ] ; public static final ByteBuffer EMPTY_BYTEBUFFER = ByteBuffer . allocate ( <NUM_LIT:0> ) ; public static final EAtom am_infinity = EAtom . intern ( "<STR_LIT>" ) ; public static final EAtom am_noproc = EAtom . intern ( "<STR_LIT>" ) ; public static final EAtom am_error = EAtom . intern ( "<STR_LIT:error>" ) ; public static final EAtom am_exit = EAtom . intern ( "<STR_LIT>" ) ; public static final EAtom am_throw = EAtom . intern ( "<STR_LIT>" ) ; public static final EAtom am_badfile = EAtom . intern ( "<STR_LIT>" ) ; public static final EAtom am_value = EAtom . intern ( "<STR_LIT:value>" ) ; public static final EAtom am_timeout = EAtom . intern ( "<STR_LIT>" ) ; public static final EAtom am_function_clause = EAtom . intern ( "<STR_LIT>" ) ; public static final EAtom am_ok = EAtom . intern ( "<STR_LIT>" ) ; public static final EAtom am_noconnect = EAtom . intern ( "<STR_LIT>" ) ; public static final EAtom am_latin1 = EAtom . intern ( "<STR_LIT>" ) ; public static final EAtom am_utf8 = EAtom . intern ( "<STR_LIT>" ) ; public static final EAtom am_unicode = EAtom . intern ( "<STR_LIT>" ) ; private static final EAtom am_init = EAtom . intern ( "<STR_LIT>" ) ; private static final EAtom am_stop = EAtom . intern ( "<STR_LIT>" ) ; protected static final EAtom am_new = EAtom . intern ( "<STR_LIT>" ) ; public static EBitStringBuilder bs_init ( int size , int flags ) { if ( size < <NUM_LIT:0> ) throw ERT . badarg ( ) ; return new EBitStringBuilder ( size , flags ) ; } public static EBitStringBuilder bs_initBits ( int size , int flags ) { if ( size < <NUM_LIT:0> ) throw ERT . badarg ( ) ; return new EBitStringBuilder ( size / <NUM_LIT:8> , size % <NUM_LIT: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 ( <NUM_LIT> ) ; static ESmall zero = ERT . box ( <NUM_LIT:0> ) ; public static final boolean gt ( EInteger v1 , EInteger v2 ) { return v1 . erlangCompareTo ( v2 ) > <NUM_LIT:0> ; } public static final boolean lt ( EInteger v1 , EInteger v2 ) { return v1 . erlangCompareTo ( v2 ) < <NUM_LIT: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 > <NUM_LIT: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 > <NUM_LIT: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 = "<STR_LIT>" , fun = "<STR_LIT>" , arity = <NUM_LIT:2> ) static EFun erlang__dsend__2 ; @ Import ( module = "<STR_LIT>" , fun = "<STR_LIT>" , arity = <NUM_LIT:3> ) static EFun erlang__dsend__3 ; @ BIF ( name = "<STR_LIT:!>" ) 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 ( ) == <NUM_LIT:2> && ( reg_name = t . elm ( <NUM_LIT:1> ) . testAtom ( ) ) != null && ( node_name = t . elm ( <NUM_LIT:2> ) . testAtom ( ) ) != null ) { send_to_remote ( proc , t , node_name , reg_name , msg , null ) ; } else { ipclog . info ( "<STR_LIT>" + pid + "<STR_LIT>" ) ; 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 ( ) == <NUM_LIT:2> && ( reg_name = t . elm ( <NUM_LIT:1> ) . testAtom ( ) ) != null && ( node_name = t . elm ( <NUM_LIT:2> ) . testAtom ( ) ) != null ) { return send_to_remote ( proc , t , node_name , reg_name , msg , options ) ; } else { ipclog . info ( "<STR_LIT>" + pid + "<STR_LIT>" ) ; 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 ( "<STR_LIT>" + dest + "<STR_LIT>" + 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 > <NUM_LIT:1000> ) { proc . reds = <NUM_LIT:0> ; Task . yield ( ) ; } } public static ENode getLocalNode ( ) { return localNode ; } static EAtom am_undef = EAtom . intern ( "<STR_LIT>" ) ; 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 ( ) > <NUM_LIT:0> && ( pmod = tup . elm ( <NUM_LIT:1> ) . testAtom ( ) ) != null ) { final EFun pfun = EModuleManager . resolve ( new FunID ( pmod , f , arity + <NUM_LIT: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 + <NUM_LIT:1> ] ; System . arraycopy ( args , <NUM_LIT:0> , real_args , <NUM_LIT: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 > <NUM_LIT:9> ) { return found . invoke ( proc , a . toArray ( ) ) ; } proc . tail = found ; a = a . reverse ( ) ; switch ( len ) { default : throw new NotImplemented ( ) ; case <NUM_LIT:9> : proc . arg8 = a . head ( ) ; a = a . tail ( ) ; case <NUM_LIT:8> : proc . arg7 = a . head ( ) ; a = a . tail ( ) ; case <NUM_LIT:7> : proc . arg6 = a . head ( ) ; a = a . tail ( ) ; case <NUM_LIT:6> : proc . arg5 = a . head ( ) ; a = a . tail ( ) ; case <NUM_LIT:5> : proc . arg4 = a . head ( ) ; a = a . tail ( ) ; case <NUM_LIT:4> : proc . arg3 = a . head ( ) ; a = a . tail ( ) ; case <NUM_LIT:3> : proc . arg2 = a . head ( ) ; a = a . tail ( ) ; case <NUM_LIT:2> : proc . arg1 = a . head ( ) ; a = a . tail ( ) ; case <NUM_LIT:1> : proc . arg0 = a . head ( ) ; a = a . tail ( ) ; case <NUM_LIT: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 ( "<STR_LIT>" + 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 ( "<STR_LIT>" ) ; public static EAtom am_attributes = EAtom . intern ( "<STR_LIT>" ) ; public static EAtom am_exports = EAtom . intern ( "<STR_LIT>" ) ; public static EAtom am_badfun = EAtom . intern ( "<STR_LIT>" ) ; public static EAtom am_badarity = EAtom . intern ( "<STR_LIT>" ) ; public static EAtom am_name = EAtom . intern ( "<STR_LIT:name>" ) ; public static EAtom am_arity = EAtom . intern ( "<STR_LIT>" ) ; public static EAtom am_env = EAtom . intern ( "<STR_LIT>" ) ; public static EAtom am_index = EAtom . intern ( "<STR_LIT:index>" ) ; public static EAtom am_new_index = EAtom . intern ( "<STR_LIT>" ) ; public static EAtom am_new_uniq = EAtom . intern ( "<STR_LIT>" ) ; public static EAtom am_uniq = EAtom . intern ( "<STR_LIT>" ) ; public static EAtom am_pid = EAtom . intern ( "<STR_LIT>" ) ; public static EAtom am_type = EAtom . intern ( "<STR_LIT:type>" ) ; public static EAtom am_local = EAtom . intern ( "<STR_LIT>" ) ; public static EAtom am_external = EAtom . intern ( "<STR_LIT>" ) ; public static EAtom am_DOWN = EAtom . intern ( "<STR_LIT>" ) ; public static EAtom am_killed = EAtom . intern ( "<STR_LIT>" ) ; 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 ( "<STR_LIT>" + idx + "<STR_LIT>" + msg ) ; return msg ; } public static void remove_message ( EProc proc ) { proc . mbox . remove ( proc . midx ) ; proc . midx = <NUM_LIT:0> ; proc . in_receive = false ; } public static void loop_rec_end ( EProc proc ) { proc . midx += <NUM_LIT:1> ; } public static boolean wait_timeout ( EProc proc , EObject howlong ) throws Pausable { try { proc . check_exit ( ) ; if ( ipclog . isLoggable ( Level . FINE ) ) ipclog . fine ( "<STR_LIT>" + proc + "<STR_LIT>" + howlong + "<STR_LIT>" ) ; if ( howlong == am_infinity ) { proc . mbox . untilHasMessages ( proc . midx + <NUM_LIT:1> ) ; proc . check_exit ( ) ; if ( ipclog . isLoggable ( Level . FINE ) ) ipclog . fine ( "<STR_LIT>" + proc + "<STR_LIT>" ) ; return true ; } else { long now = System . currentTimeMillis ( ) ; if ( proc . midx == <NUM_LIT:0> ) { proc . timeout_start = now ; } EInteger ei ; if ( ( ei = howlong . testInteger ( ) ) == null ) throw new ErlangError ( EAtom . intern ( "<STR_LIT>" ) ) ; long end = proc . timeout_start + ei . longValue ( ) ; long left = end - now ; if ( left < <NUM_LIT:0> ) { return false ; } if ( ! proc . in_receive ) { Task . sleep ( left ) ; return false ; } else { if ( ipclog . isLoggable ( Level . FINE ) ) ipclog . fine ( "<STR_LIT>" + proc + "<STR_LIT>" + left + "<STR_LIT>" + ( proc . midx + <NUM_LIT:1> ) ) ; boolean res = proc . mbox . untilHasMessages ( proc . midx + <NUM_LIT:1> , left ) ; proc . check_exit ( ) ; if ( ipclog . isLoggable ( Level . FINE ) ) ipclog . fine ( "<STR_LIT>" + proc + "<STR_LIT>" + ( res ? "<STR_LIT>" : "<STR_LIT>" ) ) ; return res ; } } } finally { proc . in_receive = false ; } } public static void wait ( EProc proc ) throws Pausable { try { int idx = proc . midx + <NUM_LIT:1> ; if ( ipclog . isLoggable ( Level . FINE ) ) ipclog . fine ( "<STR_LIT>" + proc + "<STR_LIT>" + idx + "<STR_LIT>" ) ; proc . mbox . untilHasMessages ( idx ) ; if ( ipclog . isLoggable ( Level . FINE ) ) ipclog . fine ( "<STR_LIT>" + proc + "<STR_LIT>" + ( idx ) ) ; } finally { proc . in_receive = false ; } } public static void timeout ( EProc proc ) { if ( ipclog . isLoggable ( Level . FINE ) ) ipclog . fine ( "<STR_LIT>" + proc + "<STR_LIT>" ) ; proc . midx = <NUM_LIT:0> ; proc . timeout_start = <NUM_LIT> ; 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 ( '<CHAR_LIT:U+0020>' ) ; if ( idx != - <NUM_LIT:1> ) { name = name . substring ( <NUM_LIT: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 ( "<STR_LIT>" ) ; if ( threads != null ) return Integer . parseInt ( threads ) ; else return Runtime . getRuntime ( ) . availableProcessors ( ) ; } public static int asyncThreadPoolSize ( ) { String threads = ErjangConfig . getString ( "<STR_LIT>" ) ; if ( threads != null ) return Integer . parseInt ( threads ) ; else return <NUM_LIT: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 - <NUM_LIT: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 ( "<STR_LIT>" , runtime_info . erl_bootstrap_ebindir ) ; } } } </s>
|
<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 ( "<STR_LIT>" ) ; private static final EAtom am_win32 = EAtom . intern ( "<STR_LIT>" ) ; private static final EAtom am_darwin = EAtom . intern ( "<STR_LIT>" ) ; private static final EAtom am_linux = EAtom . intern ( "<STR_LIT>" ) ; private static final EAtom am_sunos = EAtom . intern ( "<STR_LIT>" ) ; private static final EAtom am_windows = EAtom . intern ( "<STR_LIT>" ) ; private static final EAtom am_nt = EAtom . intern ( "<STR_LIT>" ) ; 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 ( ) + "<STR_LIT:=>" + entry . getValue ( ) ; res = res . cons ( EString . fromString ( s ) ) ; } return res ; } @ BIF public static ETuple2 type ( ) { String osname = System . getProperty ( "<STR_LIT>" ) ; if ( "<STR_LIT>" . equals ( osname ) || "<STR_LIT>" . equals ( osname ) ) return OS_TYPE_MACOS ; if ( "<STR_LIT>" . equals ( osname ) ) return OS_TYPE_LINUX ; if ( "<STR_LIT>" . equals ( osname ) || "<STR_LIT>" . equals ( osname ) ) return OS_TYPE_SUNOS ; if ( "<STR_LIT>" . equals ( osname ) || "<STR_LIT>" . equals ( osname ) || "<STR_LIT>" . equals ( osname ) ) return OS_TYPE_WINDOWS ; if ( "<STR_LIT>" . equals ( osname ) || "<STR_LIT>" . equals ( osname ) || "<STR_LIT>" . 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 ( "<STR_LIT>" , Pattern . CASE_INSENSITIVE ) ; Matcher matcher = pattern . matcher ( processName ) ; if ( matcher . matches ( ) ) { result = new Integer ( Integer . parseInt ( matcher . group ( <NUM_LIT:1> ) ) ) ; } return result ; } @ BIF static public ETuple3 timestamp ( ) { long now = erjang . m . erlang . ErlBif . now_raw_micros ( ) ; int micros = ( int ) ( now % <NUM_LIT> ) ; now /= <NUM_LIT> ; int secs = ( int ) ( now % <NUM_LIT> ) ; now /= <NUM_LIT> ; 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>
|
<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 ( "<STR_LIT>" ) , 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 = <NUM_LIT: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 ( <NUM_LIT:0> ) ; if ( f == null ) { throw ERT . badarg ( fun ) ; } return f . invoke ( proc , new EObject [ <NUM_LIT:0> ] ) ; } } </s>
|
<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 ( "<STR_LIT:none>" ) ; static final EAtom am_java_object = EAtom . intern ( "<STR_LIT>" ) ; static final EAtom am_badaccess = EAtom . intern ( "<STR_LIT>" ) ; static final EAtom am_badfun = EAtom . intern ( "<STR_LIT>" ) ; static final EAtom am_null_pointer_exception = EAtom . intern ( "<STR_LIT>" ) ; protected static final EAtom am_erlang = EAtom . intern ( "<STR_LIT>" ) ; protected static final EAtom am_apply = EAtom . intern ( "<STR_LIT>" ) ; 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 ( <NUM_LIT:0> ) ) != null ) { return fun ; } if ( ( fun = testFunction2 ( <NUM_LIT:1> ) ) != null ) { return fun ; } return null ; } @ Override public EFun testFunction2 ( int nargs ) { if ( ( nargs == <NUM_LIT:0> ) && ( real_object instanceof Runnable ) ) { final Runnable r = ( Runnable ) real_object ; return EFun . get_fun_with_handler ( "<STR_LIT>" , "<STR_LIT>" , <NUM_LIT: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 == <NUM_LIT:1> ) && ( real_object instanceof java . util . Map < ? , ? > ) ) { final java . util . Map < ? , ? > r = ( java . util . Map < ? , ? > ) real_object ; return EFun . get_fun_with_handler ( "<STR_LIT>" , "<STR_LIT:get>" , <NUM_LIT: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 [ <NUM_LIT:0> ] ) ; if ( r . containsKey ( key ) ) { return new ETuple2 ( args [ <NUM_LIT: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 ( "<STR_LIT:unchecked>" ) @ Override public ESeq testSeq ( ) { if ( real_object instanceof CharSequence ) { return JavaCharSeq . box ( owner , ( CharSequence ) real_object , <NUM_LIT: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 , <NUM_LIT: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 = <NUM_LIT: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 = <NUM_LIT: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 ( "<STR_LIT>" + val . getClass ( ) . getName ( ) + "<STR_LIT:U+0020toU+0020>" + 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 = <NUM_LIT: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 = <NUM_LIT:0> ; index < length ; index ++ ) { Object value = JavaObject . unbox ( self , componentType , tup . elm ( index + <NUM_LIT: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 ( <NUM_LIT: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 > ( <NUM_LIT:1> ) ; EFun job = EFun . get_fun_with_handler ( "<STR_LIT>" , "<STR_LIT>" , <NUM_LIT: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 ( "<STR_LIT>" + val . getClass ( ) . getName ( ) + "<STR_LIT:U+0020toU+0020>" + 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 <= <NUM_LIT:255> ) { return new Byte ( ( byte ) num . intValue ( ) ) ; } throw new IllegalArgumentException ( "<STR_LIT>" + val + "<STR_LIT>" ) ; } } ; 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 ( "<STR_LIT>" + val + "<STR_LIT>" ) ; } } ; 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 ( "<STR_LIT>" + val + "<STR_LIT>" ) ; } } ; 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 ( "<STR_LIT>" + val + "<STR_LIT>" ) ; } } ; 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 ( "<STR_LIT>" + val + "<STR_LIT>" ) ; } } ; 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 ( "<STR_LIT>" + val + "<STR_LIT>" ) ; } } ; 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 ( "<STR_LIT>" , 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 = <NUM_LIT: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 = <NUM_LIT: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>
|
<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 + <NUM_LIT:1> ) ; } @ Override public EObject head ( ) { return JavaObject . box ( self , Array . get ( arr , idx ) ) ; } } </s>
|
<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 ( "<STR_LIT:unchecked>" ) static ESeq box ( EProc self , Iterator < Map . Entry > iterator ) { if ( iterator . hasNext ( ) ) return new JavaMapIterator ( self , iterator ) ; return ERT . NIL ; } @ SuppressWarnings ( "<STR_LIT: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>
|
<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>
|
<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 & <NUM_LIT> ) == s . value ) { return new EStringList ( ( byte ) s . value , this ) ; } } return new EList ( h , this ) ; } @ Override public ESeq tail ( ) { return box ( self , seq , pos + <NUM_LIT:1> ) ; } @ Override public EObject head ( ) { return ERT . box ( seq . charAt ( pos ) ) ; } @ Override public int hashCode ( ) { return seq . hashCode ( ) ; } } </s>
|
<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 + <NUM_LIT:1> ] ; System . arraycopy ( binbytes , <NUM_LIT:0> , outbytes , <NUM_LIT:0> , binbytes . length ) ; outbytes [ outbytes . length - <NUM_LIT:1> ] = <NUM_LIT> ; 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 ( ) + <NUM_LIT:1> ] ; for ( int i = <NUM_LIT:0> ; i < bytes . size ( ) ; ++ i ) { out [ i ] = bytes . get ( i ) ; } out [ out . length - <NUM_LIT:1> ] = <NUM_LIT> ; 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>
|
<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>
|
<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 ( "<STR_LIT>" ) ; static EAtom am_ok = EAtom . intern ( "<STR_LIT>" ) ; static EAtom am_loaded = EAtom . intern ( "<STR_LIT>" ) ; @ 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 ( "<STR_LIT>" + 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>
|
<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 ( "<STR_LIT>" ) ; public static EAtom am_match = EAtom . intern ( "<STR_LIT>" ) ; public static EAtom am_latin1 = EAtom . intern ( "<STR_LIT>" ) ; public static EAtom am_unicode = EAtom . intern ( "<STR_LIT>" ) ; public static EAtom am_anchored = EAtom . intern ( "<STR_LIT>" ) ; public static EAtom am_caseless = EAtom . intern ( "<STR_LIT>" ) ; public static EAtom am_dollar_endonly = EAtom . intern ( "<STR_LIT>" ) ; public static EAtom am_dotall = EAtom . intern ( "<STR_LIT>" ) ; public static EAtom am_extended = EAtom . intern ( "<STR_LIT>" ) ; public static EAtom am_firstline = EAtom . intern ( "<STR_LIT>" ) ; public static EAtom am_multiline = EAtom . intern ( "<STR_LIT>" ) ; public static EAtom am_no_auto_capture = EAtom . intern ( "<STR_LIT>" ) ; public static EAtom am_dupnames = EAtom . intern ( "<STR_LIT>" ) ; public static EAtom am_ungreedy = EAtom . intern ( "<STR_LIT>" ) ; public static EAtom am_newline = EAtom . intern ( "<STR_LIT>" ) ; public static EAtom am_bsr_anycrlf = EAtom . intern ( "<STR_LIT>" ) ; public static EAtom am_bsr_unicode = EAtom . intern ( "<STR_LIT>" ) ; public static EAtom am_cr = EAtom . intern ( "<STR_LIT>" ) ; public static EAtom am_lf = EAtom . intern ( "<STR_LIT>" ) ; public static EAtom am_crlf = EAtom . intern ( "<STR_LIT>" ) ; public static EAtom am_anycrlf = EAtom . intern ( "<STR_LIT>" ) ; public static EAtom am_any = EAtom . intern ( "<STR_LIT>" ) ; public static EAtom am_global = EAtom . intern ( "<STR_LIT>" ) ; public static EAtom am_none = EAtom . intern ( "<STR_LIT:none>" ) ; public static EAtom am_index = EAtom . intern ( "<STR_LIT:index>" ) ; public static EAtom am_binary = EAtom . intern ( "<STR_LIT>" ) ; public static EAtom am_list = EAtom . intern ( "<STR_LIT:list>" ) ; public static EAtom am_all = EAtom . intern ( "<STR_LIT:all>" ) ; public static EAtom am_first = EAtom . intern ( "<STR_LIT>" ) ; public static EAtom am_all_but_first = EAtom . intern ( "<STR_LIT>" ) ; public static EAtom am_capture = EAtom . intern ( "<STR_LIT>" ) ; public static EAtom am_offset = EAtom . intern ( "<STR_LIT>" ) ; @ 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 < <NUM_LIT:0> ) { throw ERT . badarg ( subj , re , opts ) ; } Matcher matcher = regex . patt . matcher ( subject . substring ( o2 . offset ) ) ; if ( o2 . global ) { throw new NotImplemented ( "<STR_LIT>" ) ; } 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 >= <NUM_LIT: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 > <NUM_LIT: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 , <NUM_LIT: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 ( <NUM_LIT:0> , start ) . getBytes ( "<STR_LIT>" ) . length ; int ilen = subject . substring ( start , end ) . getBytes ( "<STR_LIT>" ) . 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 ( "<STR_LIT>" + 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 = <NUM_LIT: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 = <NUM_LIT: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 ( "<STR_LIT>" + 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 ( "<STR_LIT>" + opt ) ; } else if ( opt == am_multiline ) { flags |= Pattern . MULTILINE ; } else if ( opt == am_no_auto_capture ) { throw new NotImplemented ( "<STR_LIT>" + opt ) ; } else if ( opt == am_dupnames ) { throw new NotImplemented ( "<STR_LIT>" + opt ) ; } else if ( opt == am_ungreedy ) { throw new NotImplemented ( "<STR_LIT>" + 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 ( ) == <NUM_LIT:2> && tup . elm ( <NUM_LIT:1> ) == am_newline ) { newline_cr = false ; newline_crlf = false ; newline_lf = false ; newline_any = false ; EObject val = tup . elm ( <NUM_LIT: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 ( ) == <NUM_LIT:2> && tup . elm ( <NUM_LIT:1> ) == am_capture ) { this . capture_spec = tup . elm ( <NUM_LIT:2> ) ; this . capture_type = am_index ; } else if ( tup != null && tup . arity ( ) == <NUM_LIT:3> && tup . elm ( <NUM_LIT:1> ) == am_capture ) { this . capture_spec = tup . elm ( <NUM_LIT:2> ) ; this . capture_type = tup . elm ( <NUM_LIT:3> ) ; } else if ( tup != null && tup . arity ( ) == <NUM_LIT:2> && tup . elm ( <NUM_LIT:1> ) == am_offset && ( off = tup . elm ( <NUM_LIT: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 ) != <NUM_LIT: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 ( "<STR_LIT>" + newline_lf + "<STR_LIT>" + newline_cr + "<STR_LIT>" + newline_crlf ) ; } return true ; } String decode ( EObject io_or_char_list ) { String pattern ; if ( unicode ) { CharArrayWriter out = new CharArrayWriter ( ) ; Charset spec = Charset . forName ( "<STR_LIT>" ) ; 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>
|
<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 ( "<STR_LIT>" ) , EBinary . EMPTY ) ; } @ Override public EBinary testBinary ( ) { return null ; } @ Override public EBitString testBitString ( ) { return null ; } @ Override public int hashCode ( ) { return patt . hashCode ( ) ; } } </s>
|
<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 ( "<STR_LIT>" ) ; public static EAtom UNICODE_ATOM = EAtom . intern ( "<STR_LIT>" ) ; public static EAtom UTF8_ATOM = EAtom . intern ( "<STR_LIT>" ) ; public static EAtom UTF16_ATOM = EAtom . intern ( "<STR_LIT>" ) ; public static EAtom UTF32_ATOM = EAtom . intern ( "<STR_LIT>" ) ; public static EAtom LITTLE_ATOM = EAtom . intern ( "<STR_LIT>" ) ; public static EAtom BIG_ATOM = EAtom . intern ( "<STR_LIT>" ) ; public static EAtom ERROR_ATOM = EAtom . intern ( "<STR_LIT:error>" ) ; public static EAtom INCOMPLETE_ATOM = EAtom . intern ( "<STR_LIT>" ) ; @ 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 ( "<STR_LIT>" ) ; else if ( ea . equals ( UNICODE_ATOM ) || ea . equals ( UTF8_ATOM ) ) return Charset . forName ( "<STR_LIT:UTF-8>" ) ; else if ( ea . equals ( UTF16_ATOM ) ) return Charset . forName ( "<STR_LIT>" ) ; } else if ( ( et = encoding . testTuple ( ) ) != null ) { EAtom ea2 ; if ( ( ea = et . elm ( <NUM_LIT:1> ) . testAtom ( ) ) != null && ( ea2 = et . elm ( <NUM_LIT> ) . testAtom ( ) ) != null ) { if ( ea . equals ( UTF16_ATOM ) ) { if ( ea2 . equals ( LITTLE_ATOM ) ) return Charset . forName ( "<STR_LIT>" ) ; if ( ea2 . equals ( BIG_ATOM ) ) return Charset . forName ( "<STR_LIT>" ) ; } 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 ( "<STR_LIT: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 , <NUM_LIT: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>
|
<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>
|
<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>
|
<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 ( "<STR_LIT:error>" ) ; private static final EAtom am_warning = EAtom . intern ( "<STR_LIT>" ) ; private static final EAtom am_info = EAtom . intern ( "<STR_LIT>" ) ; @ BIF public static EAtom warning_map ( ) { return am_error ; } } </s>
|
<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 ( ) + <NUM_LIT:1> ) ; ESmall stop = new ESmall ( ( len . asInt ( ) == - <NUM_LIT: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 ( <NUM_LIT:0> ) , new ESmall ( - <NUM_LIT: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>
|
<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 ( "<STR_LIT>" ) ; } return bos . asBinary ( ) ; } static private class BARR extends ByteArrayOutputStream { EBinary asBinary ( ) { return new EBinary ( super . buf , <NUM_LIT:0> , super . count ) ; } } } </s>
|
<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 ( <NUM_LIT:0> , <NUM_LIT:32> ) ; } static SecureRandom rand ; static { try { rand = SecureRandom . getInstance ( "<STR_LIT>" ) ; } 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 ( "<STR_LIT>" ) ; } 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 ( "<STR_LIT>" ) ; } 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 ( "<STR_LIT>" + fb + "<STR_LIT:U+002CU+0020>" + tb + "<STR_LIT:)>" ) ; BigInteger interval = ti . subtract ( fi ) . subtract ( BigInteger . ONE ) ; BigInteger base_value = new BigInteger ( interval . bitLength ( ) , rand ) ; BigInteger result ; while ( interval . compareTo ( base_value ) == <NUM_LIT:1> ) { base_value = new BigInteger ( interval . bitLength ( ) , rand ) ; } result = fi . add ( base_value ) ; if ( log . isLoggable ( Level . FINE ) ) log . fine ( "<STR_LIT>" + fi + "<STR_LIT:U+002CU+0020>" + ti + "<STR_LIT>" + result ) ; EBinary res = big2mp ( result ) ; return res ; } private static EBinary big2mp ( BigInteger result ) { byte [ ] bytes = result . toByteArray ( ) ; ByteBuffer out = ByteBuffer . allocate ( <NUM_LIT:4> + bytes . length ) ; out . putInt ( bytes . length ) ; out . put ( bytes ) ; out . position ( <NUM_LIT: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>
|
<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>
|
<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 ( ) == <NUM_LIT: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 ( ) == <NUM_LIT: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 = <NUM_LIT:0> ; ESeq vals = ERT . NIL ; ISeq map_seq = this . ent ; while ( seq_has_more ( map_seq ) && ( limit < <NUM_LIT: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 += <NUM_LIT: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 = <NUM_LIT: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 += <NUM_LIT: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 += <NUM_LIT: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 + <NUM_LIT: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 ( ) == <NUM_LIT:2> ) { ESmall eidx = one . elm ( <NUM_LIT:1> ) . testSmall ( ) ; incr = one . elm ( <NUM_LIT: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 ( ) == <NUM_LIT:4> ) { ESmall eidx = one . elm ( <NUM_LIT:1> ) . testSmall ( ) ; incr = one . elm ( <NUM_LIT:2> ) . testInteger ( ) ; EInteger threshold = one . elm ( <NUM_LIT:3> ) . testInteger ( ) ; EInteger setvalue = one . elm ( <NUM_LIT: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 < <NUM_LIT: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>
|
<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 ( "<STR_LIT>" ) ; static final EAtom am_get_seq_token = EAtom . intern ( "<STR_LIT>" ) ; static final EAtom am_message = EAtom . intern ( "<STR_LIT:message>" ) ; static final EAtom am_return_trace = EAtom . intern ( "<STR_LIT>" ) ; static final EAtom am_exception_trace = EAtom . intern ( "<STR_LIT>" ) ; static final EAtom am_process_dump = EAtom . intern ( "<STR_LIT>" ) ; static final EAtom am_enable_trace = EAtom . intern ( "<STR_LIT>" ) ; static final EAtom am_disable_trace = EAtom . intern ( "<STR_LIT>" ) ; static final EAtom am_trace = EAtom . intern ( "<STR_LIT>" ) ; static final EAtom am_display = EAtom . intern ( "<STR_LIT>" ) ; static final EAtom am_caller = EAtom . intern ( "<STR_LIT>" ) ; static final EAtom am_set_tcw = EAtom . intern ( "<STR_LIT>" ) ; static final EAtom am_silent = EAtom . intern ( "<STR_LIT>" ) ; 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 ( "<STR_LIT>" ) ; static final EAtom am_is_constant = EAtom . intern ( "<STR_LIT>" ) ; static final EAtom am_is_float = EAtom . intern ( "<STR_LIT>" ) ; static final EAtom am_is_integer = EAtom . intern ( "<STR_LIT>" ) ; static final EAtom am_is_list = EAtom . intern ( "<STR_LIT>" ) ; static final EAtom am_is_number = EAtom . intern ( "<STR_LIT>" ) ; static final EAtom am_is_pid = EAtom . intern ( "<STR_LIT>" ) ; static final EAtom am_is_port = EAtom . intern ( "<STR_LIT>" ) ; static final EAtom am_is_reference = EAtom . intern ( "<STR_LIT>" ) ; static final EAtom am_is_tuple = EAtom . intern ( "<STR_LIT>" ) ; static final EAtom am_is_binary = EAtom . intern ( "<STR_LIT>" ) ; static final EAtom am_is_function = EAtom . intern ( "<STR_LIT>" ) ; static final EAtom am_is_record = EAtom . intern ( "<STR_LIT>" ) ; static final EAtom am_is_seq_trace = EAtom . intern ( "<STR_LIT>" ) ; static final EAtom am_and = EAtom . intern ( "<STR_LIT>" ) ; static final EAtom am_or = EAtom . intern ( "<STR_LIT>" ) ; static final EAtom am_not = EAtom . intern ( "<STR_LIT>" ) ; static final EAtom am_xor = EAtom . intern ( "<STR_LIT>" ) ; static final EAtom am_andalso = EAtom . intern ( "<STR_LIT>" ) ; static final EAtom am_orelse = EAtom . intern ( "<STR_LIT>" ) ; 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 ( "<STR_LIT>" ) ; static final EAtom am_element = EAtom . intern ( "<STR_LIT>" ) ; static final EAtom am_hd = EAtom . intern ( "<STR_LIT>" ) ; static final EAtom am_length = EAtom . intern ( "<STR_LIT>" ) ; static final EAtom am_node = EAtom . intern ( "<STR_LIT>" ) ; static final EAtom am_round = EAtom . intern ( "<STR_LIT>" ) ; static final EAtom am_size = EAtom . intern ( "<STR_LIT:size>" ) ; static final EAtom am_tl = EAtom . intern ( "<STR_LIT>" ) ; static final EAtom am_trunc = EAtom . intern ( "<STR_LIT>" ) ; static final EAtom am_PLUS = EAtom . intern ( "<STR_LIT:+>" ) ; static final EAtom am_MINUS = EAtom . intern ( "<STR_LIT:->" ) ; static final EAtom am_ASTERISK = EAtom . intern ( "<STR_LIT:*>" ) ; static final EAtom am_div = EAtom . intern ( "<STR_LIT>" ) ; static final EAtom am_rem = EAtom . intern ( "<STR_LIT>" ) ; static final EAtom am_band = EAtom . intern ( "<STR_LIT>" ) ; static final EAtom am_bor = EAtom . intern ( "<STR_LIT>" ) ; static final EAtom am_bxor = EAtom . intern ( "<STR_LIT>" ) ; static final EAtom am_bnor = EAtom . intern ( "<STR_LIT>" ) ; static final EAtom am_bsl = EAtom . intern ( "<STR_LIT>" ) ; static final EAtom am_bsr = EAtom . intern ( "<STR_LIT>" ) ; static final EAtom am_GT = EAtom . intern ( "<STR_LIT:>>" ) ; static final EAtom am_GE = EAtom . intern ( "<STR_LIT>" ) ; static final EAtom am_LT = EAtom . intern ( "<STR_LIT:<>" ) ; static final EAtom am_LE = EAtom . intern ( "<STR_LIT>" ) ; static final EAtom am_EEQ = EAtom . intern ( "<STR_LIT>" ) ; static final EAtom am_EQ = EAtom . intern ( "<STR_LIT>" ) ; static final EAtom am_ENE = EAtom . intern ( "<STR_LIT>" ) ; static final EAtom am_NE = EAtom . intern ( "<STR_LIT>" ) ; static final EAtom am_self = EAtom . intern ( "<STR_LIT>" ) ; static final EAtom am_get_tcw = EAtom . intern ( "<STR_LIT>" ) ; 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 ( "<STR_LIT:_>" ) ; private static final EAtom am_ALL_VARS = EAtom . intern ( "<STR_LIT>" ) ; private static final EAtom am_ENTIRE_MATCH = EAtom . intern ( "<STR_LIT>" ) ; private static final EAtom am_const = EAtom . intern ( "<STR_LIT>" ) ; static java . util . regex . Pattern MATCH_VAR = java . util . regex . Pattern . compile ( "<STR_LIT>" ) ; static final boolean is_match_var ( EAtom am ) { String name = am . getName ( ) ; return name . length ( ) > <NUM_LIT:0> && name . charAt ( <NUM_LIT:0> ) == '<CHAR_LIT>' && 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 [ <NUM_LIT: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 ( <NUM_LIT:1> ) ) ) ; action = t . elm ( <NUM_LIT:1> ) . testAtom ( ) ; args = new Expr [ t . arity ( ) - <NUM_LIT:1> ] ; for ( int i = <NUM_LIT:2> ; i <= t . arity ( ) ; i ++ ) { args [ i - <NUM_LIT:2> ] = parse_ActionTerm ( t . elm ( i ) , ctx ) ; } } @ Override public EObject eval ( EMatchContext ctx ) { EObject [ ] vals = new EObject [ args . length ] ; for ( int i = <NUM_LIT:0> ; i < vals . length ; i ++ ) { vals [ i ] = args [ i ] . eval ( ctx ) ; } List < EObject > aa = new ArrayList < EObject > ( ) ; for ( int i = <NUM_LIT:0> ; i < vals . length ; i ++ ) { aa . add ( vals [ i ] ) ; } throw new NotImplemented ( "<STR_LIT>" + action + "<STR_LIT:U+0020>" + aa ) ; } } static class TupleConstruct extends Expr { final Expr [ ] elems ; public TupleConstruct ( ETuple innerT , ParseContext ctx ) { elems = new Expr [ innerT . arity ( ) ] ; for ( int idx1 = <NUM_LIT:1> ; idx1 <= innerT . arity ( ) ; idx1 ++ ) { elems [ idx1 - <NUM_LIT:1> ] = parse_ConditionExpression ( innerT . elm ( idx1 ) , ctx ) ; } } @ Override public EObject eval ( EMatchContext ctx ) { ETuple res = ETuple . make ( elems . length ) ; for ( int idx0 = <NUM_LIT:0> ; idx0 < elems . length ; idx0 ++ ) { res . set ( idx0 + <NUM_LIT: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 = - <NUM_LIT:1> ; static final int EXPR_ENTIRE_MATCH = - <NUM_LIT: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 ( <NUM_LIT:1> ) ) ; var_name = idx ; if ( var_name > <NUM_LIT> || var_name < <NUM_LIT:0> ) { throw new IllegalArgumentException ( "<STR_LIT>" + idx + "<STR_LIT>" ) ; } if ( ! ctx . isBound ( var_name ) ) { throw new IllegalArgumentException ( "<STR_LIT>" + 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 ( "<STR_LIT>" + 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 = <NUM_LIT:0> ; i < cond . length ; i ++ ) { if ( ! cond [ i ] . test ( ctx ) ) return null ; } } catch ( Exception e ) { return null ; } EObject out = value ; try { for ( int i = <NUM_LIT: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 ( ) < <NUM_LIT:1> || ! GuardFunctions . contains ( t . elm ( <NUM_LIT:1> ) ) ) { throw ERT . badarg ( ) ; } guard = t . elm ( <NUM_LIT:1> ) . testAtom ( ) ; args = new Expr [ t . arity ( ) - <NUM_LIT:1> ] ; for ( int i = <NUM_LIT:2> ; i <= t . arity ( ) ; i ++ ) { args [ i - <NUM_LIT:2> ] = parse_ConditionExpression ( t . elm ( i ) , ctx ) ; } this . bif = BIFUtil . getMethod ( "<STR_LIT>" , guard . getName ( ) , args . length , true , false ) ; } public boolean test ( EMatchContext ctx ) { EObject [ ] vals = new EObject [ args . length ] ; for ( int i = <NUM_LIT: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 - <NUM_LIT:1> ] ; System . arraycopy ( vals , <NUM_LIT:1> , vargs , <NUM_LIT:0> , vals . length - <NUM_LIT:1> ) ; return m . invoke ( vals [ <NUM_LIT: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 = <NUM_LIT:0> ; i < vals . length ; i ++ ) { aa . add ( vals [ i ] ) ; } throw new NotImplemented ( "<STR_LIT>" + guard + "<STR_LIT:U+0020>" + aa ) ; } } public static final GuardCall [ ] EMPTY_ARR = new GuardCall [ <NUM_LIT:0> ] ; @ Override public EObject eval ( EMatchContext ctx ) { EObject [ ] vals = new EObject [ args . length ] ; for ( int i = <NUM_LIT: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 - <NUM_LIT:1> ] ; System . arraycopy ( vals , <NUM_LIT:1> , vargs , <NUM_LIT:0> , vals . length - <NUM_LIT:1> ) ; return ( EObject ) m . invoke ( vals [ <NUM_LIT: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 = <NUM_LIT:0> ; i < vals . length ; i ++ ) { aa . add ( vals [ i ] ) ; } throw new NotImplemented ( "<STR_LIT>" + guard + "<STR_LIT:U+0020>" + 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 ( ) >= <NUM_LIT:1> && ActionFunctions . contains ( t . elm ( <NUM_LIT: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 ( ) >= <NUM_LIT:1> && GuardFunctions . contains ( t . elm ( <NUM_LIT: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 ( ) == <NUM_LIT:2> && t . elm ( <NUM_LIT:1> ) == am_const ) { return new ConstantExpr ( t . elm ( <NUM_LIT:2> ) ) ; } ETuple inner_t ; if ( t . arity ( ) == <NUM_LIT:1> && ( inner_t = t . elm ( <NUM_LIT: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 ( ) < <NUM_LIT:1> || ! GuardFunctions . contains ( t . elm ( <NUM_LIT: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 = <NUM_LIT: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 = <NUM_LIT:1> ; idx1 <= tuple . arity ( ) ; idx1 ++ ) { elems [ idx1 - <NUM_LIT: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 = <NUM_LIT:0> ; idx0 < elems . length ; idx0 ++ ) { if ( ! t . elm ( idx0 + <NUM_LIT: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 ( <NUM_LIT:1> ) ) ; this . var_name = name ; if ( name > <NUM_LIT> || name < <NUM_LIT:0> ) { throw new IllegalArgumentException ( "<STR_LIT>" + name + "<STR_LIT>" ) ; } 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 == <NUM_LIT:1> ) { if ( funs [ <NUM_LIT:0> ] . head instanceof TuplePattern ) { TuplePattern tp = ( TuplePattern ) funs [ <NUM_LIT:0> ] . head ; if ( tp . elems . length < keypos1 ) return KEY_ABSENT ; if ( tp . elems [ keypos1 - <NUM_LIT:1> ] instanceof EqualsPattern ) { EqualsPattern ep = ( EqualsPattern ) tp . elems [ keypos1 - <NUM_LIT:1> ] ; return ep . value ; } } else if ( funs [ <NUM_LIT:0> ] . head instanceof EqualsPattern ) { EqualsPattern ep = ( EqualsPattern ) funs [ <NUM_LIT: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 = <NUM_LIT: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 <NUM_LIT:0> ; return - <NUM_LIT:1> ; } @ Override public int hashCode ( ) { return <NUM_LIT:1> ; } } </s>
|
<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 ( <NUM_LIT: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 = <NUM_LIT: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 += <NUM_LIT: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 ( <NUM_LIT: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 ( ) != <NUM_LIT:0> ) { return ERT . TRUE ; } else { return ERT . FALSE ; } } @ Override protected EObject first ( ) { IPersistentMap map = deref ( ) ; if ( map . count ( ) == <NUM_LIT: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 ( ) == <NUM_LIT:0> ) return null ; IPersistentCollection out = empty ( ) ; int deleted = <NUM_LIT: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 += <NUM_LIT:1> ; } } if ( out . count ( ) == <NUM_LIT: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 = <NUM_LIT: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 < <NUM_LIT: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 += <NUM_LIT: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 = <NUM_LIT: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 += <NUM_LIT:1> ; if ( set . count ( ) == <NUM_LIT: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 += <NUM_LIT:1> ; if ( bag . count ( ) == <NUM_LIT: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 ( <NUM_LIT:0> ) ; return null ; } } ) ; } @ Override public ESeq slot ( ) { IPersistentMap map = deref ( ) ; if ( map . count ( ) == <NUM_LIT: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 ( ) == <NUM_LIT: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>
|
<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 ( "<STR_LIT>" ) ; public static final EAtom am_$end_of_table = EAtom . intern ( "<STR_LIT>" ) ; public static final EAtom am_set = EAtom . intern ( "<STR_LIT>" ) ; public static final EAtom am_ordered_set = EAtom . intern ( "<STR_LIT>" ) ; public static final EAtom am_bag = EAtom . intern ( "<STR_LIT>" ) ; public static final EAtom am_duplicate_bag = EAtom . intern ( "<STR_LIT>" ) ; public static final EAtom am_public = EAtom . intern ( "<STR_LIT>" ) ; public static final EAtom am_private = EAtom . intern ( "<STR_LIT>" ) ; public static final EAtom am_protected = EAtom . intern ( "<STR_LIT>" ) ; public static final EAtom am_owner = EAtom . intern ( "<STR_LIT>" ) ; public static final EAtom am_heir = EAtom . intern ( "<STR_LIT>" ) ; public static final EAtom am_keypos = EAtom . intern ( "<STR_LIT>" ) ; public static final EAtom am_name = EAtom . intern ( "<STR_LIT:name>" ) ; public static final EAtom am_size = EAtom . intern ( "<STR_LIT:size>" ) ; public static final EAtom am_memory = EAtom . intern ( "<STR_LIT>" ) ; public static final EAtom am_node = EAtom . intern ( "<STR_LIT>" ) ; public static final EAtom am_named_table = EAtom . intern ( "<STR_LIT>" ) ; public static final EAtom am_write_concurrency = EAtom . intern ( "<STR_LIT>" ) ; public static final EAtom am_type = EAtom . intern ( "<STR_LIT:type>" ) ; public static final EAtom am_none = EAtom . intern ( "<STR_LIT:none>" ) ; public static final EAtom am_protection = EAtom . intern ( "<STR_LIT>" ) ; public static final EAtom am_fixed = EAtom . intern ( "<STR_LIT>" ) ; public static final EAtom am_safe_fixed = EAtom . intern ( "<STR_LIT>" ) ; public static final EAtom am_stats = EAtom . intern ( "<STR_LIT>" ) ; static AtomicLong next_tid = new AtomicLong ( <NUM_LIT: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 = "<STR_LIT>" ) 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 = <NUM_LIT: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 >= <NUM_LIT: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 < <NUM_LIT: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 == <NUM_LIT:0> ) { return table . slot ( ) ; } else if ( pos . value == <NUM_LIT: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 ( "<STR_LIT>" + spec + "<STR_LIT::U+0020>" + e . getMessage ( ) ) ; log . log ( Level . FINE , "<STR_LIT>" , 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 ( "<STR_LIT>" + cont + "<STR_LIT>" + 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 = <NUM_LIT:0> ; while ( ! res . isNil ( ) ) { if ( res . head ( ) == ERT . TRUE ) result += <NUM_LIT: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 , - <NUM_LIT: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 < <NUM_LIT: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>
|
<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 - <NUM_LIT:1> ; i >= <NUM_LIT:0> ; i -- ) { res = res . cons ( vars . get ( varnames [ i ] ) ) ; } return res ; } public EObject makeTuple ( ) { ETuple res = ETuple . make ( varnames . length ) ; for ( int i = <NUM_LIT:0> ; i < varnames . length ; i ++ ) { res . set ( i + <NUM_LIT:1> , vars . get ( varnames [ i ] ) ) ; } return res ; } } </s>
|
<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 ( "<STR_LIT>" ) ; 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 ( "<STR_LIT>" + type + "<STR_LIT>" + access + "<STR_LIT>" + keypos + "<STR_LIT>" + write_concurrency + "<STR_LIT>" + 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 ( "<STR_LIT>" ) ; } } 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 ( "<STR_LIT>" ) , 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 ( "<STR_LIT>" + aname + "<STR_LIT:U+0020(>" + tid + "<STR_LIT>" + 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 ( "<STR_LIT: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 ( <NUM_LIT: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 ( <NUM_LIT> ) , ERT . box ( <NUM_LIT:7> ) , ERT . box ( <NUM_LIT:1> ) , ERT . box ( <NUM_LIT:1> ) , ERT . box ( <NUM_LIT:1> ) , ERT . box ( <NUM_LIT: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>
|
<s> package erjang . m . ets ; import erjang . EObject ; interface ISelectContinuation { EObject select ( ) ; } </s>
|
<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 "<STR_LIT>" + keyidx + "<STR_LIT:;>" + spec . toString ( ) + "<STR_LIT:>>" ; } 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 = <NUM_LIT:1> ; idx1 <= arity ; idx1 ++ ) { elems [ idx1 - <NUM_LIT: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 = <NUM_LIT:1> ; idx1 < elems . length + <NUM_LIT:1> ; idx1 ++ ) { if ( ! t . elm ( idx1 ) . match ( elems [ idx1 - <NUM_LIT: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 = <NUM_LIT: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 ( "<STR_LIT>" ) ; static EAtom am_ANY = EAtom . intern ( "<STR_LIT:_>" ) ; public static ETermPattern compilePattern ( EAtom am , Set < Integer > out ) { String name = am . getName ( ) ; if ( VAR . matcher ( name ) . matches ( ) ) { int idx1 = Integer . parseInt ( name . substring ( <NUM_LIT: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 < <NUM_LIT:1> || keypos1 > tm . elems . length ) { return null ; } ETermPattern m = tm . elems [ keypos1 - <NUM_LIT: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 < <NUM_LIT: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>
|
<s> package erjang . m . ets ; import com . trifork . clj_ds . IPersistentCollection ; public interface IPersistentBag extends IPersistentCollection { IPersistentBag disjoin ( Object element ) ; } </s>
|
<s> package erjang . m . ets ; 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 . ERef ; import erjang . ETuple ; public abstract class ETermPattern { public boolean match ( ETuple t , EMatchContext r ) { return false ; } public boolean match ( ENumber n , EMatchContext r ) { return false ; } public boolean match ( EAtom a , EMatchContext r ) { return false ; } public boolean match ( ECons c , EMatchContext r ) { return false ; } public boolean match ( EPID p , EMatchContext r ) { return false ; } public boolean match ( EPort p , EMatchContext r ) { return false ; } public boolean match ( EBitString bs , EMatchContext r ) { return false ; } public boolean match ( EFun eFun , EMatchContext r ) { return false ; } public boolean match ( ERef eRef , EMatchContext r ) { return false ; } } </s>
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.