コード例 #1
0
        /*recursive*/
        /// <exception cref="System.IO.IOException"/>
        public virtual void TestUnTar()
        {
            SetupDirs();
            // make a simple tar:
            FilePath        simpleTar = new FilePath(del, File);
            OutputStream    os        = new FileOutputStream(simpleTar);
            TarOutputStream tos       = new TarOutputStream(os);

            try
            {
                TarEntry te   = new TarEntry("/bar/foo");
                byte[]   data = Runtime.GetBytesForString("some-content", "UTF-8");
                te.SetSize(data.Length);
                tos.PutNextEntry(te);
                tos.Write(data);
                tos.CloseEntry();
                tos.Flush();
                tos.Finish();
            }
            finally
            {
                tos.Close();
            }
            // successfully untar it into an existing dir:
            FileUtil.UnTar(simpleTar, tmp);
            // check result:
            Assert.True(new FilePath(tmp, "/bar/foo").Exists());
            Assert.Equal(12, new FilePath(tmp, "/bar/foo").Length());
            FilePath regularFile = new FilePath(tmp, "QuickBrownFoxJumpsOverTheLazyDog");

            regularFile.CreateNewFile();
            Assert.True(regularFile.Exists());
            try
            {
                FileUtil.UnTar(simpleTar, regularFile);
                Assert.True("An IOException expected.", false);
            }
            catch (IOException)
            {
            }
        }