Beispiel #1
0
        /// <exception cref="System.IO.IOException"/>
        /// <exception cref="Sharpen.URISyntaxException"/>
        internal static LocalResource CreateJarFile(FileContext files, Path p, int len, Random
                                                    r, LocalResourceVisibility vis)
        {
            byte[] bytes = new byte[len];
            r.NextBytes(bytes);
            FilePath archiveFile = new FilePath(p.ToUri().GetPath() + ".jar");

            archiveFile.CreateNewFile();
            JarOutputStream @out = new JarOutputStream(new FileOutputStream(archiveFile));

            @out.PutNextEntry(new JarEntry(p.GetName()));
            @out.Write(bytes);
            @out.CloseEntry();
            @out.Close();
            LocalResource ret = recordFactory.NewRecordInstance <LocalResource>();

            ret.SetResource(ConverterUtils.GetYarnUrlFromPath(new Path(p.ToString() + ".jar")
                                                              ));
            ret.SetSize(len);
            ret.SetType(LocalResourceType.Archive);
            ret.SetVisibility(vis);
            ret.SetTimestamp(files.GetFileStatus(new Path(p.ToString() + ".jar")).GetModificationTime
                                 ());
            return(ret);
        }
Beispiel #2
0
        /// <exception cref="System.IO.FileNotFoundException"/>
        /// <exception cref="System.IO.IOException"/>
        private void CreateAndAddJarToJar(JarOutputStream jos, FilePath jarFile)
        {
            FileOutputStream fos2 = new FileOutputStream(jarFile);
            JarOutputStream  jos2 = new JarOutputStream(fos2);
            // Have to have at least one entry or it will complain
            ZipEntry ze = new ZipEntry("lib1.inside");

            jos2.PutNextEntry(ze);
            jos2.CloseEntry();
            jos2.Close();
            ze = new ZipEntry("lib/" + jarFile.GetName());
            jos.PutNextEntry(ze);
            FileInputStream @in = new FileInputStream(jarFile);

            byte[] buf = new byte[1024];
            int    numRead;

            do
            {
                numRead = @in.Read(buf);
                if (numRead >= 0)
                {
                    jos.Write(buf, 0, numRead);
                }
            }while (numRead != -1);
            @in.Close();
            jos.CloseEntry();
            jarFile.Delete();
        }
Beispiel #3
0
        /// <summary>
        /// Construct a jar with two files in it in our
        /// test dir.
        /// </summary>
        /// <exception cref="System.IO.IOException"/>
        private void MakeTestJar()
        {
            FilePath        jarFile = new FilePath(TestRootDir, TestJarName);
            JarOutputStream jstream = new JarOutputStream(new FileOutputStream(jarFile));

            jstream.PutNextEntry(new ZipEntry("foobar.txt"));
            jstream.CloseEntry();
            jstream.PutNextEntry(new ZipEntry("foobaz.txt"));
            jstream.CloseEntry();
            jstream.Close();
        }
        /// <exception cref="System.IO.FileNotFoundException"/>
        /// <exception cref="System.IO.IOException"/>
        private Path MakeJar(Path p, int index)
        {
            FileOutputStream fos = new FileOutputStream(new FilePath(p.ToString()));
            JarOutputStream  jos = new JarOutputStream(fos);
            ZipEntry         ze  = new ZipEntry("distributed.jar.inside" + index);

            jos.PutNextEntry(ze);
            jos.Write(Sharpen.Runtime.GetBytesForString(("inside the jar!" + index)));
            jos.CloseEntry();
            jos.Close();
            return(p);
        }
Beispiel #5
0
        /// <exception cref="System.IO.IOException"/>
        private FilePath MakeTestJar()
        {
            FilePath        jarFile = new FilePath(testDir, "test.jar");
            JarOutputStream @out    = new JarOutputStream(new FileOutputStream(jarFile));
            ZipEntry        entry   = new ZipEntry("resource.txt");

            @out.PutNextEntry(entry);
            @out.Write(Runtime.GetBytesForString("hello"));
            @out.CloseEntry();
            @out.Close();
            return(jarFile);
        }
Beispiel #6
0
        /// <exception cref="System.IO.FileNotFoundException"/>
        /// <exception cref="System.IO.IOException"/>
        private Path MakeJobJarWithLib(string testDir)
        {
            Path             jobJarPath = new Path(testDir, "thejob.jar");
            FileOutputStream fos        = new FileOutputStream(new FilePath(jobJarPath.ToUri().GetPath
                                                                                ()));
            JarOutputStream jos = new JarOutputStream(fos);

            // Have to put in real jar files or it will complain
            CreateAndAddJarToJar(jos, new FilePath(new Path(testDir, "lib1.jar").ToUri().GetPath
                                                       ()));
            CreateAndAddJarToJar(jos, new FilePath(new Path(testDir, "lib2.jar").ToUri().GetPath
                                                       ()));
            jos.Close();
            localFs.SetPermission(jobJarPath, new FsPermission("700"));
            return(jobJarPath);
        }
Beispiel #7
0
        /// <summary>
        /// Write the compiled to a jar file. Overwrites the existing jar file.
        /// </summary>
        /// <param name="compiled">compiled</param>
        /// <param name="file">the target file</param>
        /// <throws>IOException when the write failed</throws>
        public static void Write(EPCompiled compiled, FileInfo file) {

	        Manifest manifest = new Manifest();
	        manifest.MainAttributes.Put(Attributes.Name.MANIFEST_VERSION, "1.0");
	        manifest.MainAttributes.Put(new Attributes.Name(MANIFEST_COMPILER_VERSION), compiled.Manifest.CompilerVersion);
	        manifest.MainAttributes.Put(new Attributes.Name(MANIFEST_MODULEPROVIDERCLASSNAME), compiled.Manifest.ModuleProviderClassName);
	        manifest.MainAttributes.Put(new Attributes.Name(MANIFEST_QUERYPROVIDERCLASSNAME), compiled.Manifest.QueryProviderClassName);

	        JarOutputStream target = new JarOutputStream(new FileOutputStream(file), manifest);

	        try {
	            foreach (KeyValuePair<string, byte[]> entry in compiled.Classes) {
	                Write(entry.Key, entry.Value, target);
	            }
	        } finally {
	            target.Close();
	        }
	    }
Beispiel #8
0
        /// <exception cref="System.IO.IOException"/>
        private FilePath MakeTestJar()
        {
            FilePath        jarFile          = new FilePath(TestRootDir, TestJarName);
            JarOutputStream jstream          = new JarOutputStream(new FileOutputStream(jarFile));
            InputStream     entryInputStream = this.GetType().GetResourceAsStream(ClassName);
            ZipEntry        entry            = new ZipEntry("org/apache/hadoop/util/" + ClassName);

            jstream.PutNextEntry(entry);
            BufferedInputStream bufInputStream = new BufferedInputStream(entryInputStream, 2048
                                                                         );
            int count;

            byte[] data = new byte[2048];
            while ((count = bufInputStream.Read(data, 0, 2048)) != -1)
            {
                jstream.Write(data, 0, count);
            }
            jstream.CloseEntry();
            jstream.Close();
            return(jarFile);
        }
Beispiel #9
0
        /// <exception cref="System.IO.IOException"/>
        internal static LocalResource CreateJar(FileContext files, Path p, LocalResourceVisibility
                                                vis)
        {
            Log.Info("Create jar file " + p);
            FilePath         jarFile = new FilePath((files.MakeQualified(p)).ToUri());
            FileOutputStream stream  = new FileOutputStream(jarFile);

            Log.Info("Create jar out stream ");
            JarOutputStream @out = new JarOutputStream(stream, new Manifest());

            Log.Info("Done writing jar stream ");
            @out.Close();
            LocalResource ret = recordFactory.NewRecordInstance <LocalResource>();

            ret.SetResource(ConverterUtils.GetYarnUrlFromPath(p));
            FileStatus status = files.GetFileStatus(p);

            ret.SetSize(status.GetLen());
            ret.SetTimestamp(status.GetModificationTime());
            ret.SetType(LocalResourceType.Pattern);
            ret.SetVisibility(vis);
            ret.SetPattern("classes/.*");
            return(ret);
        }
Beispiel #10
0
        // it should not throw an exception
        /// <exception cref="System.IO.IOException"/>
        private FilePath MakeClassLoaderTestJar(params string[] clsNames)
        {
            FilePath        jarFile = new FilePath(TestRootDir, TestJar2Name);
            JarOutputStream jstream = new JarOutputStream(new FileOutputStream(jarFile));

            foreach (string clsName in clsNames)
            {
                string      name             = clsName.Replace('.', '/') + ".class";
                InputStream entryInputStream = this.GetType().GetResourceAsStream("/" + name);
                ZipEntry    entry            = new ZipEntry(name);
                jstream.PutNextEntry(entry);
                BufferedInputStream bufInputStream = new BufferedInputStream(entryInputStream, 2048
                                                                             );
                int    count;
                byte[] data = new byte[2048];
                while ((count = bufInputStream.Read(data, 0, 2048)) != -1)
                {
                    jstream.Write(data, 0, count);
                }
                jstream.CloseEntry();
            }
            jstream.Close();
            return(jarFile);
        }