Пример #1
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();
        }
Пример #2
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);
        }
Пример #3
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();
        }
Пример #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();
	    }
        /// <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);
        }
Пример #6
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);
        }
Пример #7
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);
        }
Пример #8
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);
        }