//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void testScanClassPath_multipleRoots() throws java.net.MalformedURLException //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: public virtual void testScanClassPath_multipleRoots() { // define a classloader with multiple roots. URLClassLoader classLoader = new URLClassLoader(new URL[] { new URL("file:src/test/resources/org/camunda/bpm/container/impl/jmx/deployment/util/ClassPathScannerTest.testScanClassPathWithFiles/"), new URL("file:src/test/resources/org/camunda/bpm/container/impl/jmx/deployment/util/ClassPathScannerTest.testScanClassPathWithFilesRecursive/"), new URL("file:src/test/resources/org/camunda/bpm/container/impl/jmx/deployment/util/ClassPathScannerTest.testScanClassPathRecursiveTwoDirectories.jar") }); ClassPathProcessApplicationScanner scanner = new ClassPathProcessApplicationScanner(); IDictionary <string, sbyte[]> scanResult = new Dictionary <string, sbyte[]>(); scanner.scanPaResourceRootPath(classLoader, null, "classpath:directory/", scanResult); assertTrue("'testDeployProcessArchive.bpmn20.xml' not found", contains(scanResult, "testDeployProcessArchive.bpmn20.xml")); assertTrue("'testDeployProcessArchive.png' not found", contains(scanResult, "testDeployProcessArchive.png")); assertEquals(2, scanResult.Count); // only finds two files since the resource name of the processes (and diagrams) is the same scanResult.Clear(); scanner.scanPaResourceRootPath(classLoader, null, "directory/", scanResult); assertTrue("'testDeployProcessArchive.bpmn20.xml' not found", contains(scanResult, "testDeployProcessArchive.bpmn20.xml")); assertTrue("'testDeployProcessArchive.png' not found", contains(scanResult, "testDeployProcessArchive.png")); assertEquals(2, scanResult.Count); // only finds two files since the resource name of the processes (and diagrams) is the same scanResult.Clear(); scanner.scanPaResourceRootPath(classLoader, new URL("file:src/test/resources/org/camunda/bpm/container/impl/jmx/deployment/util/ClassPathScannerTest.testScanClassPathWithFilesRecursive/META-INF/processes.xml"), "pa:directory/", scanResult); assertTrue("'testDeployProcessArchive.bpmn20.xml' not found", contains(scanResult, "testDeployProcessArchive.bpmn20.xml")); assertTrue("'testDeployProcessArchive.png' not found", contains(scanResult, "testDeployProcessArchive.png")); assertEquals(2, scanResult.Count); // only finds two files since a PA-local resource root path is provided }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: public Callables loadProceduresFromDir(java.io.File root) throws java.io.IOException, org.neo4j.internal.kernel.api.exceptions.KernelException public virtual Callables LoadProceduresFromDir(File root) { if (root == null || !root.exists()) { return(Callables.Empty()); } Callables @out = new Callables(); File[] dirListing = root.listFiles((dir, name) => name.EndsWith(".jar")); if (dirListing == null) { return(Callables.Empty()); } if (!AllJarFilesAreValidZipFiles(Stream.of(dirListing))) { throw new ZipException("Some jar procedure files are invalid, see log for details."); } //JAVA TO C# CONVERTER TODO TASK: Method reference constructor syntax is not converted by Java to C# Converter: URL[] jarFilesURLs = Stream.of(dirListing).map(this.toURL).toArray(URL[] ::new); URLClassLoader loader = new URLClassLoader(jarFilesURLs, this.GetType().ClassLoader); foreach (URL jarFile in jarFilesURLs) { LoadProcedures(jarFile, loader, @out); } return(@out); }
//SETTING UP ANDROID SERVER #region setting up android server public void StartJavaServer() { Console.WriteLine("Starting server"); URL url = new URL("file:VehicleSystemServer.jar"); URLClassLoader loader = new URLClassLoader(new[] { url }); try { Class cl = Class.forName("VehicleSystemServer", true, loader); object obj = cl.newInstance(); _server = (VehicleSystemServer)obj; String userName = Globals.GCM_SENDER_ID + "@gcm.googleapis.com"; String password = Globals.GCM_SERVER_KEY; _server.connect(userName, password); MessageListener listener = new MessageListener(this); _server.addListener(listener); _server.testListener(); Console.WriteLine("Server started successfully"); } catch (Exception e) { Console.WriteLine("Error in starting server"); Console.WriteLine(e.Message); } }
public void Invoke(params string[] args) { try { // http://bigjavablog.blogspot.com/2008/08/load-jar-files-and-java-classes.html if (Method != null) { var main_args = new string[0]; this.Method.invoke(null, new object[] { main_args }); } else { /* We need and URL to load the jar file. */ URL u = new File(this.AssemblyPath).toURL(); /* Load jar file using URLClassLoader. */ URLClassLoader cl = new URLClassLoader(new URL[] { u }); if (NativeAssemblyPath != null) { var nc = cl.loadClass("jni.CPtrLibrary"); var ncf = nc.getField("LibraryPath"); ncf.set(null, NativeAssemblyPath); } var c = cl.loadClass(this.TypeName); foreach (var m in c.getMethods()) { if (m.getDeclaringClass() == c) { if (m.getName() == "main") { this.Method = m; var main_args = new string[0]; this.Method.invoke(null, new object[] { main_args }); } } } } } catch (csharp.ThrowableException ex) { var exo = (object)ex; Console.WriteLine("error!"); Console.WriteLine(ex.Message + " - " + ex.ToString()); ErrorHandler(exo); } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldWorkForClassLoaderWithNoParent() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldWorkForClassLoaderWithNoParent() { // Given ClassLoader loader = new URLClassLoader(Urls("file:///file1", "file:///file2"), null); // When ISet <string> elements = fullClasspathFor(loader); // Then assertThat(elements, hasItems(PathTo("file1"), PathTo("file2"))); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldWorkForClassLoaderWithSingleParent() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldWorkForClassLoaderWithSingleParent() { // Given ClassLoader parent = new URLClassLoader(Urls("file:///file1", "file:///file2"), null); ClassLoader child = new URLClassLoader(Urls("file:///file3"), parent); // When ISet <string> elements = fullClasspathFor(child); // Then assertThat(elements, hasItems(PathTo("file1"), PathTo("file2"), PathTo("file3"))); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void testScanClassPathWithNonExistingRootPath_nonRelativeToPa() throws java.net.MalformedURLException //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: public virtual void testScanClassPathWithNonExistingRootPath_nonRelativeToPa() { URLClassLoader classLoader = Classloader; IDictionary <string, sbyte[]> scanResult = new Dictionary <string, sbyte[]>(); scanner.scanPaResourceRootPath(classLoader, null, "nonexisting", scanResult); assertFalse("'testDeployProcessArchive.bpmn20.xml' found", contains(scanResult, "testDeployProcessArchive.bpmn20.xml")); assertFalse("'testDeployProcessArchive.png' found", contains(scanResult, "testDeployProcessArchive.png")); assertEquals(0, scanResult.Count); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldReturnCorrectClasspathString() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldReturnCorrectClasspathString() { // Given ClassLoader parent = new URLClassLoader(Urls("file:///foo"), null); ClassLoader child = new URLClassLoader(Urls("file:///bar"), parent); // When string classpath = fullClasspathStringFor(child); // Then assertThat(classpath, containsString(PathTo("bar") + File.pathSeparator + PathTo("foo"))); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void testScanClassPathWithAdditionalResourceSuffixes() throws java.net.MalformedURLException //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: public virtual void testScanClassPathWithAdditionalResourceSuffixes() { URLClassLoader classLoader = Classloader; string[] additionalResourceSuffixes = new string[] { "py", "rb", "groovy" }; IDictionary <string, sbyte[]> scanResult = scanner.findResources(classLoader, null, new URL(url + "/META-INF/processes.xml"), additionalResourceSuffixes); if (url.Contains("AdditionalResourceSuffixes")) { assertEquals(5, scanResult.Count); } }
/// <summary> /// Given a path with a jar, make a classloader with that jar on the /// classpath, and check that findContainingJar can correctly /// identify the path of the jar. /// </summary> /// <exception cref="System.Exception"/> private void TestJarAtPath(string path) { FilePath jar = new FilePath(path).GetAbsoluteFile(); NUnit.Framework.Assert.IsTrue(jar.Exists()); Uri[] urls = new Uri[] { jar.ToURI().ToURL() }; ClassLoader cl = new URLClassLoader(urls); Type clazz = Sharpen.Runtime.GetType(Classname, true, cl); NUnit.Framework.Assert.IsNotNull(clazz); string containingJar = ClassUtil.FindContainingJar(clazz); NUnit.Framework.Assert.AreEqual(jar.GetAbsolutePath(), containingJar); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void testScanProcessArchivePathForCmmnResources() throws java.net.MalformedURLException //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: public virtual void testScanProcessArchivePathForCmmnResources() { // given: scanning the relative test resource root URLClassLoader classLoader = new URLClassLoader(new URL[] { new URL("file:") }); string processRootPath = "classpath:org/camunda/bpm/container/impl/jmx/deployment/case/"; IDictionary <string, sbyte[]> scanResult = ProcessApplicationScanningUtil.findResources(classLoader, processRootPath, null); // expect: finds only the CMMN process file and not treats the 'cmmn' folder assertEquals(1, scanResult.Count); string processFileName = "VfsProcessScannerTest.cmmn"; assertTrue("'" + processFileName + "' not found", contains(scanResult, processFileName)); assertFalse("'cmmn' in resource path found", contains(scanResult, "caseResource.txt")); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void shouldWorkForClassLoaderHierarchy() throws Exception //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: public virtual void ShouldWorkForClassLoaderHierarchy() { // Given ClassLoader loader1 = new URLClassLoader(Urls("file:///file1"), null); ClassLoader loader2 = new URLClassLoader(Urls("file:///file2"), loader1); ClassLoader loader3 = new URLClassLoader(Urls("file:///file3"), loader2); ClassLoader loader4 = new URLClassLoader(Urls("file:///file4"), loader3); // When ISet <string> elements = fullClasspathFor(loader4); // Then assertThat(elements, hasItems(PathTo("file1"), PathTo("file2"), PathTo("file3"), PathTo("file4"))); }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void testScanProcessArchivePathWithAdditionalResourceSuffixes() throws java.net.MalformedURLException //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: public virtual void testScanProcessArchivePathWithAdditionalResourceSuffixes() { URLClassLoader classLoader = new URLClassLoader(new URL[] { new URL("file:") }); string processRootPath = "classpath:org/camunda/bpm/container/impl/jmx/deployment/script/"; string[] additionalResourceSuffixes = new string[] { "py", "groovy", "rb" }; IDictionary <string, sbyte[]> scanResult = ProcessApplicationScanningUtil.findResources(classLoader, processRootPath, null, additionalResourceSuffixes); assertEquals(4, scanResult.Count); string processFileName = "VfsProcessScannerTest.bpmn20.xml"; assertTrue("'" + processFileName + "' not found", contains(scanResult, processFileName)); assertTrue("'hello.py' in resource path found", contains(scanResult, "hello.py")); assertTrue("'hello.rb' in resource path found", contains(scanResult, "hello.rb")); assertTrue("'hello.groovy' in resource path found", contains(scanResult, "hello.groovy")); }
public virtual void TestCacheDoesntLeak() { int iterations = 9999; // very fast, but a bit less reliable - bigger numbers force GC for (int i = 0; i < iterations; i++) { URLClassLoader loader = new URLClassLoader(new Uri[0], GetType().GetClassLoader() ); Type cl = Runtime.GetType("org.apache.hadoop.util.TestReflectionUtils$LoadedInChild" , false, loader); object o = ReflectionUtils.NewInstance(cl, null); Assert.Equal(cl, o.GetType()); } System.GC.Collect(); Assert.True(CacheSize() + " too big", CacheSize() < iterations); }
/// <summary> /// Creates a classloader based on the environment that was specified by the /// user. /// </summary> /// <remarks> /// Creates a classloader based on the environment that was specified by the /// user. If HADOOP_USE_CLIENT_CLASSLOADER is specified, it creates an /// application classloader that provides the isolation of the user class space /// from the hadoop classes and their dependencies. It forms a class space for /// the user jar as well as the HADOOP_CLASSPATH. Otherwise, it creates a /// classloader that simply adds the user jar to the classpath. /// </remarks> /// <exception cref="System.UriFormatException"/> private ClassLoader CreateClassLoader(FilePath file, FilePath workDir) { ClassLoader loader; // see if the client classloader is enabled if (UseClientClassLoader()) { StringBuilder sb = new StringBuilder(); sb.Append(workDir + "/").Append(FilePath.pathSeparator).Append(file).Append(FilePath .pathSeparator).Append(workDir + "/classes/").Append(FilePath.pathSeparator).Append (workDir + "/lib/*"); // HADOOP_CLASSPATH is added to the client classpath string hadoopClasspath = GetHadoopClasspath(); if (hadoopClasspath != null && !hadoopClasspath.IsEmpty()) { sb.Append(FilePath.pathSeparator).Append(hadoopClasspath); } string clientClasspath = sb.ToString(); // get the system classes string systemClasses = GetSystemClasses(); IList <string> systemClassesList = systemClasses == null ? null : Arrays.AsList(StringUtils .GetTrimmedStrings(systemClasses)); // create an application classloader that isolates the user classes loader = new ApplicationClassLoader(clientClasspath, GetType().GetClassLoader(), systemClassesList); } else { IList <Uri> classPath = new AList <Uri>(); classPath.AddItem(new FilePath(workDir + "/").ToURI().ToURL()); classPath.AddItem(file.ToURI().ToURL()); classPath.AddItem(new FilePath(workDir, "classes/").ToURI().ToURL()); FilePath[] libs = new FilePath(workDir, "lib").ListFiles(); if (libs != null) { for (int i = 0; i < libs.Length; i++) { classPath.AddItem(libs[i].ToURI().ToURL()); } } // create a normal parent-delegating classloader loader = new URLClassLoader(Collections.ToArray(classPath, new Uri[0])); } return(loader); }
/// <summary> /// only support 1.7 or higher /// http://stackoverflow.com/questions/252893/how-do-you-change-the-classpath-within-java /// </summary> private static void addCurrentWorkingDir2Classpath(string path2Added) { // Add the conf dir to the classpath // Chain the current thread classloader URLClassLoader urlClassLoader; try { urlClassLoader = new URLClassLoader(new URL[] {(new File(path2Added)).toURI().toURL()}, loader); // Replace the thread classloader - assumes // you have permissions to do so Thread.CurrentThread.ContextClassLoader = urlClassLoader; } catch (Exception e) { LOGGER.warn(e.ToString()); } }
/// <summary> /// Test method for <seealso cref="org.camunda.bpm.container.impl.deployment.scanning.ClassPathProcessApplicationScanner.scanClassPath(java.lang.ClassLoader)"/>. </summary> /// <exception cref="MalformedURLException"> </exception> //JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void testScanClassPath() throws java.net.MalformedURLException //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: public virtual void testScanClassPath() { URLClassLoader classLoader = Classloader; IDictionary <string, sbyte[]> scanResult = new Dictionary <string, sbyte[]>(); scanner.scanPaResourceRootPath(classLoader, new URL(url + "/META-INF/processes.xml"), null, scanResult); assertTrue("'testDeployProcessArchive.bpmn20.xml' not found", contains(scanResult, "testDeployProcessArchive.bpmn20.xml")); assertTrue("'testDeployProcessArchive.png' not found", contains(scanResult, "testDeployProcessArchive.png")); if (url.Contains("TwoDirectories")) { assertEquals(4, scanResult.Count); } else { assertEquals(2, scanResult.Count); } }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes: //ORIGINAL LINE: @Test public void testScanClassPathWithExistingRootPath_nonRelativeToPa() throws java.net.MalformedURLException //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: public virtual void testScanClassPathWithExistingRootPath_nonRelativeToPa() { URLClassLoader classLoader = Classloader; IDictionary <string, sbyte[]> scanResult = new Dictionary <string, sbyte[]>(); scanner.scanPaResourceRootPath(classLoader, null, "directory/", scanResult); if (url.Contains("Recursive")) { assertTrue("'testDeployProcessArchive.bpmn20.xml' not found", contains(scanResult, "testDeployProcessArchive.bpmn20.xml")); assertTrue("'testDeployProcessArchive.png' not found", contains(scanResult, "testDeployProcessArchive.png")); assertEquals(2, scanResult.Count); } else { assertFalse("'testDeployProcessArchive.bpmn20.xml' found", contains(scanResult, "testDeployProcessArchive.bpmn20.xml")); assertFalse("'testDeployProcessArchive.png' found", contains(scanResult, "testDeployProcessArchive.png")); assertEquals(0, scanResult.Count); } }
private static void LoadJavaLib() { IsLoaded = true; URLClassLoader loader = new URLClassLoader(new URL[] { new URL("file:rsc/SanicBeatsLib.jar") }); try { // load the Class Class cl = Class.forName("com.sanicbeats.Runtime", true, loader); //Create a object via C# reflection Type = ikvm.runtime.Util.getInstanceTypeFromClass(cl); //Class cl = typeof(com.sanicbeats.Runtime); //Thread.currentThread().setContextClassLoader(cl.getClassLoader()); } catch (Exception ex) { Console.WriteLine(ex); Console.WriteLine(ex.StackTrace); } }
/// <summary> /// Loads the content of a jar file that comply with a MaltParser Plugin /// </summary> /// <param name="jarUrl"> The URL to the jar file </param> /// <exception cref="PluginException"> </exception> //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET: //ORIGINAL LINE: public boolean readJarFile(java.net.URL jarUrl) throws org.maltparser.core.exception.MaltChainedException public virtual bool readJarFile(URL jarUrl) { JarInputStream jis; JarEntry je; ISet <URL> pluginXMLs = new Helper.HashSet <URL>(); /*if (logger.isDebugEnabled()) { * logger.debug("Loading jar " + jarUrl+"\n"); * }*/ JarFile jarFile; try { jarFile = new JarFile(jarUrl.File); } catch (IOException e) { throw new PluginException("Could not open jar file " + jarUrl + ". ", e); } try { Manifest manifest = jarFile.Manifest; if (manifest != null) { Attributes manifestAttributes = manifest.MainAttributes; if (!(manifestAttributes.getValue("MaltParser-Plugin") != null && manifestAttributes.getValue("MaltParser-Plugin").Equals("true"))) { return(false); } if (manifestAttributes.getValue("Class-Path") != null) { string[] classPathItems = manifestAttributes.getValue("Class-Path").Split(" "); for (int i = 0; i < classPathItems.Length; i++) { URL u; try { u = new URL(jarUrl.Protocol + ":" + (new File(jarFile.Name)).ParentFile.Path + "/" + classPathItems[i]); } catch (MalformedURLException e) { throw new PluginException("The URL to the plugin jar-class-path '" + jarUrl.Protocol + ":" + (new File(jarFile.Name)).ParentFile.Path + "/" + classPathItems[i] + "' is wrong. ", e); } URLClassLoader sysloader = (URLClassLoader)ClassLoader.SystemClassLoader; Type sysclass = typeof(URLClassLoader); System.Reflection.MethodInfo method = sysclass.getDeclaredMethod("addURL", new Type[] { typeof(URL) }); method.Accessible = true; method.invoke(sysloader, new object[] { u }); } } } } catch (PatternSyntaxException e) { throw new PluginException("Could not split jar-class-path entries in the jar-file '" + jarFile.Name + "'. ", e); } catch (IOException e) { throw new PluginException("Could not read the manifest file in the jar-file '" + jarFile.Name + "'. ", e); } catch (NoSuchMethodException e) { throw new PluginException("", e); } catch (IllegalAccessException e) { throw new PluginException("", e); } catch (InvocationTargetException e) { throw new PluginException("", e); } try { jis = new JarInputStream(jarUrl.openConnection().InputStream); while ((je = jis.NextJarEntry) != null) { string jarName = je.Name; if (jarName.EndsWith(".class", StringComparison.Ordinal)) { /* if (logger.isDebugEnabled()) { * logger.debug(" Loading class: " + jarName+"\n"); * }*/ loadClassBytes(jis, jarName); Type clazz = findClass(jarName.Substring(0, jarName.Length - 6)); classes[jarName.Substring(0, jarName.Length - 6).Replace('/', '.')] = clazz; loadClass(jarName.Substring(0, jarName.Length - 6).Replace('/', '.')); } if (jarName.EndsWith("plugin.xml", StringComparison.Ordinal)) { pluginXMLs.Add(new URL("jar:" + jarUrl.Protocol + ":" + jarUrl.Path + "!/" + jarName)); } jis.closeEntry(); } foreach (URL url in pluginXMLs) { /* if (logger.isDebugEnabled()) { * logger.debug(" Loading "+url+"\n"); * }*/ OptionManager.instance().loadOptionDescriptionFile(url); } } catch (MalformedURLException e) { throw new PluginException("The URL to the plugin.xml is wrong. ", e); } catch (IOException e) { throw new PluginException("cannot open jar file " + jarUrl + ". ", e); } catch (ClassNotFoundException e) { throw new PluginException("The class " + e.Message + " can't be found. ", e); } return(true); }
public string execClass(string className) { if (TEST_IN_SAME_PROCESS) { try { ClassLoader loader = new URLClassLoader(new URL[] { new File(tmpdir).toURI().toURL() }, ClassLoader.getSystemClassLoader()); Class mainClass = (Class)loader.loadClass(className); Method mainMethod = mainClass.getDeclaredMethod("main", typeof(string[])); PipedInputStream stdoutIn = new PipedInputStream(); PipedInputStream stderrIn = new PipedInputStream(); PipedOutputStream stdoutOut = new PipedOutputStream(stdoutIn); PipedOutputStream stderrOut = new PipedOutputStream(stderrIn); StreamVacuum stdoutVacuum = new StreamVacuum(stdoutIn); StreamVacuum stderrVacuum = new StreamVacuum(stderrIn); PrintStream originalOut = Console.Out; System.setOut(new PrintStream(stdoutOut)); try { PrintStream originalErr = System.err; try { System.setErr(new PrintStream(stderrOut)); stdoutVacuum.start(); stderrVacuum.start(); mainMethod.invoke(null, (Object) new string[] { new File(tmpdir, "input").getAbsolutePath() }); } finally { System.setErr(originalErr); } } finally { System.setOut(originalOut); } stdoutOut.close(); stderrOut.close(); stdoutVacuum.join(); stderrVacuum.join(); string output = stdoutVacuum.tostring(); if (stderrVacuum.tostring().length() > 0) { this.stderrDuringParse = stderrVacuum.tostring(); Console.Error.WriteLine("exec stderrVacuum: " + stderrVacuum); } return(output); } catch (MalformedURLException ex) { LOGGER.log(Level.SEVERE, null, ex); } catch (IOException ex) { LOGGER.log(Level.SEVERE, null, ex); } catch (InterruptedException ex) { LOGGER.log(Level.SEVERE, null, ex); } catch (IllegalAccessException ex) { LOGGER.log(Level.SEVERE, null, ex); } catch (IllegalArgumentException ex) { LOGGER.log(Level.SEVERE, null, ex); } catch (InvocationTargetException ex) { LOGGER.log(Level.SEVERE, null, ex); } catch (NoSuchMethodException ex) { LOGGER.log(Level.SEVERE, null, ex); } catch (SecurityException ex) { LOGGER.log(Level.SEVERE, null, ex); } catch (ClassNotFoundException ex) { LOGGER.log(Level.SEVERE, null, ex); } } try { string[] args = new string[] { "java", "-classpath", tmpdir + pathSep + CLASSPATH, className, new File(tmpdir, "input").getAbsolutePath() }; //string cmdLine = "java -classpath "+CLASSPATH+pathSep+tmpdir+" Test " + new File(tmpdir, "input").getAbsolutePath(); //Console.WriteLine("execParser: "+cmdLine); Process process = Runtime.getRuntime().exec(args, null, new File(tmpdir)); StreamVacuum stdoutVacuum = new StreamVacuum(process.getInputStream()); StreamVacuum stderrVacuum = new StreamVacuum(process.getErrorStream()); stdoutVacuum.start(); stderrVacuum.start(); process.waitFor(); stdoutVacuum.join(); stderrVacuum.join(); string output = stdoutVacuum.tostring(); if (stderrVacuum.tostring().length() > 0) { this.stderrDuringParse = stderrVacuum.tostring(); Console.Error.WriteLine("exec stderrVacuum: " + stderrVacuum); } return(output); } catch (Exception e) { Console.Error.WriteLine("can't exec recognizer"); e.printStackTrace(System.err); } return(null); }
public JavaArchiveReflector(FileInfo jar) { this.FileName = jar; var clazzLoader = default(URLClassLoader); try { var filePath = "jar:file://" + jar.FullName + "!/"; var url = new java.io.File(filePath).toURL(); clazzLoader = new URLClassLoader(new URL[] { url }); } catch { } this.GetDynamicEnumerator = () => { var zip = default(ZipInputStream); try { zip = new ZipInputStream(new FileInputStream(jar.FullName)); } catch { } return((GetNextEntry) delegate { if (zip == null) { return null; } var e = default(ZipEntry); try { e = zip.getNextEntry(); } catch { } if (e == null) { return null; } var n = new Entry { Name = e.getName() }; if (clazzLoader != null) { if (n.Name.EndsWith(".class")) { n.TypeFullName = n.Name.Substring(0, n.Name.Length - ".class".Length).Replace("/", "."); n.InternalGetType = delegate { var c = default(java.lang.Class); try { c = clazzLoader.loadClass(n.TypeFullName.Replace(".", "/")); } catch (csharp.ThrowableException cc) { System.Console.WriteLine("error: " + cc); } return c.ToType(); }; } } return n; }); }; }