Пример #1
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private java.io.File createTempFile(java.util.jar.JarEntry jarEntry) throws java.io.IOException
        private File CreateTempFile(JarEntry jarEntry)
        {
            File tempFile = File.createTempFile(jarEntry.Name, "jar");

            tempFile.deleteOnExit();
            return(tempFile);
        }
Пример #2
0
        public static Stream getInputStreamFromConfigFileEntry(URL mcoURL, string mcoName, string fileName)
        {
            JarFile  mcoJarFile = getConfigJarfile(mcoURL);
            JarEntry entry      = getConfigFileEntry(mcoJarFile, mcoName, fileName);

            try
            {
                if (entry == null)
                {
                    throw new FileNotFoundException();
                }
                return(mcoJarFile.getInputStream(entry));
            }
            catch (FileNotFoundException e)
            {
                Console.WriteLine(e.ToString());
                Console.Write(e.StackTrace);
            }
            catch (IOException e)
            {
                Console.WriteLine(e.ToString());
                Console.Write(e.StackTrace);
            }
            return(null);
        }
Пример #3
0
 private static ImmutableSet <string> getEntries(File jarFile, string rootPath)
 {
     ImmutableSet.Builder <string> builder = ImmutableSet.builder();
     try
     {
         using (JarFile jar = new JarFile(jarFile))
         {
             IEnumerator <JarEntry> jarEntries = jar.entries();
             while (jarEntries.MoveNext())
             {
                 JarEntry entry     = jarEntries.Current;
                 string   entryName = entry.Name;
                 if (entryName.StartsWith(rootPath, StringComparison.Ordinal) && !entryName.Equals(rootPath))
                 {
                     string relativeEntryPath = entryName.Substring(rootPath.Length + 1);
                     if (relativeEntryPath.Trim().Length > 0)
                     {
                         builder.add(relativeEntryPath);
                     }
                 }
             }
         }
     }
     catch (Exception e)
     {
         throw new System.ArgumentException(Messages.format("Error scanning entries in JAR file: {}", jarFile), e);
     }
     return(builder.build());
 }
Пример #4
0
	    private static void Write(string name, byte[] value, JarOutputStream target) {
	        name = name.Replace(".", "/") + ".class";
	        JarEntry entry = new JarEntry(name);
	        entry.Time = System.CurrentTimeMillis();
	        target.PutNextEntry(entry);
	        target.Write(value, 0, value.Length);
	        target.CloseEntry();
	    }
Пример #5
0
    void build() {

        List<String> lst = new ArrayList<String>();
        //collect unit tests
        Console.WriteLine("Collecting unit tests from " + _testDir);
        collectTests(_testDir, _testDir, lst, ".+?\\.Test.+?\\.class$");

        TestSuite suite = new TestSuite();
        for (String arg : lst) {
            //ignore inner classes defined in tests
            if (arg.IndexOf('$') != -1) continue;

            String cls = arg.Replace(".class", "");
            try {
                Class test = Class.forName(cls);
                suite.AddTestSuite(test);
            } catch (ClassNotFoundException e) {
                throw new RuntimeException(e);
            }
        }

        //run tests
        TestRunner.Run(suite);

        //see what classes from the ooxml-schemas.jar are loaded
        Console.WriteLine("Copying classes to " + _destDest);
        Map<String, Class<?>> classes = GetLoadedClasses(_ooxmlJar.getName());
        for (Class<?> cls : classes.values()) {
            String className = cls.GetName();
            String classRef = className.Replace('.', '/') + ".class";
            File destFile = new File(_destDest, classRef);
            copyFile(cls.GetResourceAsStream('/' + classRef), destFile);

            if(cls.isInterface()){
                /**
                 * Copy classes and interfaces declared as members of this class
                 */
                for(Class fc : cls.GetDeclaredClasses()){
                    className = fc.GetName();
                    classRef = className.Replace('.', '/') + ".class";
                    destFile = new File(_destDest, classRef);
                    copyFile(fc.GetResourceAsStream('/' + classRef), destFile);
                }
            }
        }

        //finally copy the compiled .xsb files
        Console.WriteLine("Copying .xsb resources");
        JarFile jar = new  JarFile(_ooxmlJar);
        for(Enumeration<JarEntry> e = jar.entries(); e.hasMoreElements(); ){
            JarEntry je = e.nextElement();
            if(je.GetName().matches("schemaorg_apache_xmlbeans/system/\\w+/\\w+\\.xsb")) {
                 File destFile = new File(_destDest, je.GetName());
                 copyFile(jar.GetInputStream(je), destFile);
            }
        }
        jar.close();
    }
Пример #6
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private java.io.File extract(java.util.jar.JarFile jarFile, java.util.jar.JarEntry jarEntry) throws java.io.IOException
        private File Extract(JarFile jarFile, JarEntry jarEntry)
        {
            File extractedFile = CreateTempFile(jarEntry);

            using (Stream jarInputStream = jarFile.getInputStream(jarEntry))
            {
                Files.copy(jarInputStream, extractedFile.toPath(), StandardCopyOption.REPLACE_EXISTING);
            }
            return(extractedFile);
        }
Пример #7
0
        public static JarEntry getConfigFileEntry(JarFile mcoJarFile, string mcoName, string fileName)
        {
            JarEntry entry = mcoJarFile.getJarEntry(mcoName + '/' + fileName);

            if (entry == null)
            {
                entry = mcoJarFile.getJarEntry(mcoName + '\\' + fileName);
            }
            return(entry);
        }
Пример #8
0
 public virtual bool hasChanges(JarEntry @in, JarEntry @out)
 {
     if (maltParserVersion.Equals(parserModelVersion))
     {
         return(false);
     }
     if (@in.Name.EndsWith(".info") || @in.Name.EndsWith(".sop"))
     {
         return(true);
     }
     return(false);
 }
Пример #9
0
        public virtual JarEntry getJarEntry(JarEntry @in)
        {
            if (maltParserVersion.Equals(parserModelVersion))
            {
                return(@in);
            }
            string entryName = @in.Name.replace(configName + File.separator, newConfigName + File.separator);

            if (entryName.EndsWith(".info", StringComparison.Ordinal))
            {
                return(new JarEntry(entryName.Replace(File.separator + configName + "_", File.separator + newConfigName + "_")));
            }
            return(new JarEntry(entryName));
        }
Пример #10
0
        /// <summary>
        /// Extract jar that is stored ad resource in a parent jar into temporary file </summary>
        /// <param name="resourceUrl"> resource jar resourceUrl </param>
        /// <param name="jar"> jar resource path </param>
        /// <returns> jar temporary file </returns>
        /// <exception cref="IOException"> on exception during jar extractions </exception>
        /// <exception cref="EmbeddedJarNotFoundException"> if jar not found or can't be extracted. </exception>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private java.io.File extractJar(java.net.URL resourceUrl, String jar) throws java.io.IOException
        private File ExtractJar(URL resourceUrl, string jar)
        {
            URLConnection connection = resourceUrl.openConnection();

            if (connection is JarURLConnection)
            {
                JarURLConnection urlConnection = ( JarURLConnection )connection;
                JarFile          jarFile       = urlConnection.JarFile;
                JarEntry         jarEntry      = urlConnection.JarEntry;
                if (jarEntry == null)
                {
                    throw new EmbeddedJarNotFoundException("Jar file '" + jar + "' not found.");
                }
                return(Extract(jarFile, jarEntry));
            }
            else
            {
                throw new EmbeddedJarNotFoundException("Jar file '" + jar + "' not found.");
            }
        }
Пример #11
0
        protected internal override ResourceLocator getResource(string subdirectoryName, string resourceName)
        {
            string fullLocation = string.format(Locale.ENGLISH, "%s%s/%s", rootPath, subdirectoryName, resourceName);

            try
            {
                using (JarFile jar = new JarFile(jarFile))
                {
                    JarEntry entry = jar.getJarEntry(fullLocation);
                    if (entry == null)
                    {
                        return(null);
                    }
                    return(getEntryLocator(entry.Name));
                }
            }
            catch (Exception e)
            {
                throw new System.ArgumentException(Messages.format("Error loading resource from JAR file: {}", jarFile), e);
            }
        }
Пример #12
0
        /// <summary>Unpack matching files from a jar.</summary>
        /// <remarks>
        /// Unpack matching files from a jar. Entries inside the jar that do
        /// not match the given pattern will be skipped.
        /// </remarks>
        /// <param name="jarFile">the .jar file to unpack</param>
        /// <param name="toDir">the destination directory into which to unpack the jar</param>
        /// <param name="unpackRegex">the pattern to match jar entries against</param>
        /// <exception cref="System.IO.IOException"/>
        public static void UnJar(FilePath jarFile, FilePath toDir, Pattern unpackRegex
                                 )
        {
            JarFile jar = new JarFile(jarFile);

            try
            {
                Enumeration <JarEntry> entries = ((Enumeration <JarEntry>)jar.Entries());
                while (entries.MoveNext())
                {
                    JarEntry entry = entries.Current;
                    if (!entry.IsDirectory() && unpackRegex.Matcher(entry.GetName()).Matches())
                    {
                        InputStream @in = jar.GetInputStream(entry);
                        try
                        {
                            FilePath file = new FilePath(toDir, entry.GetName());
                            EnsureDirectory(file.GetParentFile());
                            OutputStream @out = new FileOutputStream(file);
                            try
                            {
                                IOUtils.CopyBytes(@in, @out, 8192);
                            }
                            finally
                            {
                                @out.Close();
                            }
                        }
                        finally
                        {
                            @in.Close();
                        }
                    }
                }
            }
            finally
            {
                jar.Close();
            }
        }
Пример #13
0
 public JarEntry(JarEntry prm1) : base(default(global::java.util.zip.ZipEntry))
 {
 }
Пример #14
0
 public virtual void beginEntry(JarEntry prm1, global::sun.security.util.ManifestEntryVerifier prm2)
 {
 }
Пример #15
0
 public virtual global::java.security.CodeSource getCodeSource(global::java.net.URL prm1, JarFile prm2, JarEntry prm3)
 {
     return(default(global::java.security.CodeSource));
 }
Пример #16
0
 public virtual global::java.security.CodeSigner[] getCodeSigners(JarFile prm1, JarEntry prm2)
 {
     return(default(global::java.security.CodeSigner[]));
 }
Пример #17
0
        private static Type[] GetVisibleClasses()
        {
            //--Variables
            IList <Type> classes = new List <Type>();
            // (get classpath)
            string pathSep = Runtime.GetProperty("path.separator");

            string[] cp = Runtime.GetProperties().GetProperty("java.class.path", null).Split(pathSep);
            // --Fill Options
            // (get classes)
            foreach (string entry in cp)
            {
                Redwood.Util.Log("Checking cp " + entry);
                //(should skip?)
                if (entry.Equals(".") || entry.Trim().IsEmpty())
                {
                    continue;
                }
                //(no, don't skip)
                File f = new File(entry);
                if (f.IsDirectory())
                {
                    // --Case: Files
                    try
                    {
                        using (IDirectoryStream <IPath> stream = Files.NewDirectoryStream(f.ToPath(), "*.class"))
                        {
                            foreach (IPath p in stream)
                            {
                                //(get the associated class)
                                Type clazz = FilePathToClass(entry, p.ToString());
                                if (clazz != null)
                                {
                                    //(add the class if it's valid)
                                    classes.Add(clazz);
                                }
                            }
                        }
                    }
                    catch (IOException ioe)
                    {
                        Redwood.Util.Error(ioe);
                    }
                }
                else
                {
                    //noinspection StatementWithEmptyBody
                    if (!IsIgnored(entry))
                    {
                        // --Case: Jar
                        try
                        {
                            using (JarFile jar = new JarFile(f))
                            {
                                IEnumeration <JarEntry> e = ((IEnumeration <JarEntry>)jar.Entries());
                                while (e.MoveNext())
                                {
                                    //(for each jar file element)
                                    JarEntry jarEntry = e.Current;
                                    string   clazz    = jarEntry.GetName();
                                    if (clazz.Matches(".*class$"))
                                    {
                                        //(if it's a class)
                                        clazz = Sharpen.Runtime.Substring(clazz, 0, clazz.Length - 6).ReplaceAll("/", ".");
                                        //(add it)
                                        try
                                        {
                                            classes.Add(Sharpen.Runtime.GetType(clazz, false, ClassLoader.GetSystemClassLoader()));
                                        }
                                        catch (TypeLoadException)
                                        {
                                            Redwood.Util.Warn("Could not load class in jar: " + f + " at path: " + clazz);
                                        }
                                        catch (NoClassDefFoundError)
                                        {
                                            Redwood.Util.Debug("Could not scan class: " + clazz + " (in jar: " + f + ')');
                                        }
                                    }
                                }
                            }
                        }
                        catch (IOException)
                        {
                            Redwood.Util.Warn("Could not open jar file: " + f + "(are you sure the file exists?)");
                        }
                    }
                }
            }
            //case: ignored jar
            return(Sharpen.Collections.ToArray(classes, new Type[classes.Count]));
        }
Пример #18
0
        public virtual string modifyJarEntry(JarEntry @in, JarEntry @out, StringBuilder sb)
        {
            if (maltParserVersion.Equals(parserModelVersion))
            {
                return(sb.ToString());
            }
            if (@in.Name.EndsWith(".info"))
            {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final StringBuilder outString = new StringBuilder();
                StringBuilder outString = new StringBuilder();
                string[]      lines     = sb.ToString().Split("\\n", true);
                for (int i = 0; i < lines.Length; i++)
                {
                    if (lines[i].StartsWith("Configuration name:", StringComparison.Ordinal))
                    {
                        outString.Append("Configuration name:   ");
                        outString.Append(configName);
                        outString.Append('.');
                        outString.Append(maltParserVersion);
                        outString.Append('\n');
                    }
                    else if (lines[i].StartsWith("Created:", StringComparison.Ordinal))
                    {
                        outString.Append(lines[i]);
                        outString.Append('\n');
                        outString.Append("Converted:            ");
                        outString.Append(new DateTime(DateTimeHelper.CurrentUnixTimeMillis()));
                        outString.Append('\n');
                    }
                    else if (lines[i].StartsWith("Version:", StringComparison.Ordinal))
                    {
                        outString.Append("Version:                       ");
                        outString.Append(maltParserVersion);
                        outString.Append('\n');
                        outString.Append("Created by:                    ");
                        outString.Append(parserModelVersion);
                        outString.Append('\n');
                    }
                    else if (lines[i].StartsWith("  name (  -c)                           ", StringComparison.Ordinal))
                    {
                        outString.Append("  name (  -c)                           ");
                        outString.Append(newConfigName);
                        outString.Append('\n');
                    }
                    else if (lines[i].StartsWith("  format ( -if)                         /appdata/dataformat/", StringComparison.Ordinal))
                    {
                        outString.Append("  format ( -if)                         ");
                        int index = lines[i].LastIndexOf("/", StringComparison.Ordinal);
                        outString.Append(lines[i].Substring(index + 1));
                        outString.Append('\n');
                    }
                    else if (lines[i].StartsWith("  format ( -of)                         /appdata/dataformat/", StringComparison.Ordinal))
                    {
                        outString.Append("  format ( -of)                         ");
                        int index = lines[i].LastIndexOf("/", StringComparison.Ordinal);
                        outString.Append(lines[i].Substring(index + 1));
                        outString.Append('\n');
                    }
                    else if (lines[i].StartsWith("--guide-features (  -F)                 /appdata/features/", StringComparison.Ordinal))
                    {
                        outString.Append("--guide-features (  -F)                 ");
                        int index = lines[i].LastIndexOf("/", StringComparison.Ordinal);
                        outString.Append(lines[i].Substring(index + 1));
                        outString.Append('\n');
                    }
                    else
                    {
                        outString.Append(lines[i]);
                        outString.Append('\n');
                    }
                }
                return(outString.ToString());
            }
            else if (@in.Name.EndsWith(".sop"))
            {
//JAVA TO C# CONVERTER WARNING: The original Java variable was marked 'final':
//ORIGINAL LINE: final StringBuilder outString = new StringBuilder();
                StringBuilder outString = new StringBuilder();
                string[]      lines     = sb.ToString().Split("\\n", true);
                for (int i = 0; i < lines.Length; i++)
                {
                    int index     = lines[i].IndexOf('\t');
                    int container = 0;
                    if (index > -1)
                    {
                        container = int.Parse(lines[i].Substring(0, index));
                    }
                    if (lines[i].StartsWith(container + "\tguide\tfeatures", StringComparison.Ordinal))
                    {
                        int tabIndex = lines[i].LastIndexOf('\t');
                        if (lines[i].Substring(tabIndex + 1).StartsWith("/appdata/features/", StringComparison.Ordinal))
                        {
                            int    slashIndex = lines[i].LastIndexOf("/", StringComparison.Ordinal);
                            string xmlFile    = lines[i].Substring(slashIndex + 1);
                            string path       = lines[i].Substring(tabIndex + 1, slashIndex - (tabIndex + 1));
                            FeatureModelXML = path + "/libsvm/" + xmlFile;
                            outString.Append(container);
                            outString.Append("\tguide\tfeatures\t");
                            outString.Append(xmlFile);
                            outString.Append('\n');
                        }
                        else
                        {
                            outString.Append(lines[i]);
                            outString.Append('\n');
                        }
                    }
                    else if (lines[i].StartsWith(container + "\tinput\tformat", StringComparison.Ordinal))
                    {
                        int tabIndex = lines[i].LastIndexOf('\t');
                        if (lines[i].Substring(tabIndex + 1).StartsWith("/appdata/dataformat/", StringComparison.Ordinal))
                        {
                            int    slashIndex = lines[i].LastIndexOf("/", StringComparison.Ordinal);
                            string xmlFile    = lines[i].Substring(slashIndex + 1);
                            string path       = lines[i].Substring(tabIndex + 1, slashIndex - (tabIndex + 1));
                            InputFormatXML = path + "/" + xmlFile;
                            outString.Append(container);
                            outString.Append("\tinput\tformat\t");
                            outString.Append(xmlFile);
                            outString.Append('\n');
                        }
                        else
                        {
                            outString.Append(lines[i]);
                            outString.Append('\n');
                        }
                    }
                    else if (earlierVersion("1.3"))
                    {
                        if (lines[i].StartsWith(container + "\tnivre\tpost_processing", StringComparison.Ordinal))
                        {
                        }
                        else if (lines[i].StartsWith(container + "\tmalt0.4\tbehavior", StringComparison.Ordinal))
                        {
                            if (lines[i].EndsWith("true", StringComparison.Ordinal))
                            {
                                SystemLogger.logger().info("MaltParser " + maltParserVersion + " doesn't support MaltParser 0.4 emulation.");
                            }
                        }
                        else if (lines[i].StartsWith(container + "\tsinglemalt\tparsing_algorithm", StringComparison.Ordinal))
                        {
                            outString.Append(container);
                            outString.Append("\tsinglemalt\tparsing_algorithm\t");
                            if (lines[i].EndsWith("NivreStandard", StringComparison.Ordinal))
                            {
                                outString.Append("class org.maltparser.parser.algorithm.nivre.NivreArcStandardFactory");
                            }
                            else if (lines[i].EndsWith("NivreEager", StringComparison.Ordinal))
                            {
                                outString.Append("class org.maltparser.parser.algorithm.nivre.NivreArcEagerFactory");
                            }
                            else if (lines[i].EndsWith("CovingtonNonProjective", StringComparison.Ordinal))
                            {
                                outString.Append("class org.maltparser.parser.algorithm.covington.CovingtonNonProjFactory");
                            }
                            else if (lines[i].EndsWith("CovingtonProjective", StringComparison.Ordinal))
                            {
                                outString.Append("class org.maltparser.parser.algorithm.covington.CovingtonProjFactory");
                            }
                            outString.Append('\n');
                        }
                    }
                    else
                    {
                        outString.Append(lines[i]);
                        outString.Append('\n');
                    }
                }
                return(outString.ToString());
            }
            return(sb.ToString());
        }
Пример #19
0
 /// <summary>
 /// Creates a new <code>JarEntry</code> with fields taken from the
 /// specified <code>JarEntry</code> object.
 /// </summary>
 /// <param name="je"> the <code>JarEntry</code> to copy </param>
 public JarEntry(JarEntry je) : this((ZipEntry)je)
 {
     this.Attr    = je.Attr;
     this.Certs   = je.Certs;
     this.Signers = je.Signers;
 }
Пример #20
0
 public virtual global::java.security.cert.Certificate[] getCerts(JarFile prm1, JarEntry prm2)
 {
     return(default(global::java.security.cert.Certificate[]));
 }