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

            gzipFile.CreateNewFile();
            TarArchiveOutputStream @out = new TarArchiveOutputStream(new GZIPOutputStream(new
                                                                                          FileOutputStream(gzipFile)));
            TarArchiveEntry entry = new TarArchiveEntry(p.GetName());

            entry.SetSize(bytes.Length);
            @out.PutArchiveEntry(entry);
            @out.Write(bytes);
            @out.CloseArchiveEntry();
            @out.Close();
            LocalResource ret = recordFactory.NewRecordInstance <LocalResource>();

            ret.SetResource(ConverterUtils.GetYarnUrlFromPath(new Path(p.ToString() + ".tar.gz"
                                                                       )));
            ret.SetSize(len);
            ret.SetType(LocalResourceType.Archive);
            ret.SetVisibility(vis);
            ret.SetTimestamp(files.GetFileStatus(new Path(p.ToString() + ".tar.gz")).GetModificationTime
                                 ());
            return(ret);
        }
Example #2
0
		/// <param name="fileList">
		/// 
		/// @return
		/// </param>
		/// <exception cref="IOException"> </exception>
		/// <exception cref="CompressorException"> </exception>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public static String tarFiles(String dir, String fileNamePrefix, java.util.List<java.io.File> fileList) throws java.io.IOException, org.apache.commons.compress.compressors.CompressorException
		public static string tarFiles(string dir, string fileNamePrefix, IList<File> fileList)
		{

			//
			OsUtil.makeDirs(dir);

			// 时间
			string curTime = DateUtils.format(DateTime.Now, DataFormatConstants.COMMON_TIME_FORMAT);

			// 文件名
			string outputFilePath = fileNamePrefix + "_" + curTime + ".tar.gz";
			File outputFile = new File(dir, outputFilePath);

			System.IO.FileStream @out = null;
			@out = new System.IO.FileStream(outputFile, System.IO.FileMode.Create, System.IO.FileAccess.Write);

			//
			// 进行打包
			//
			TarArchiveOutputStream os = new TarArchiveOutputStream(@out);
			foreach (File file in fileList)
			{
				os.putArchiveEntry(new TarArchiveEntry(file, file.Name));
				IOUtils.copy(new System.IO.FileStream(file, System.IO.FileMode.Open, System.IO.FileAccess.Read), os);
				os.closeArchiveEntry();
			}

			if (os != null)
			{
				try
				{
					os.flush();
					os.close();
				}
				catch (IOException e)
				{
					Console.WriteLine(e.ToString());
					Console.Write(e.StackTrace);
				}
			}

			return outputFile.AbsolutePath;
		}
Example #3
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private org.apache.commons.compress.archivers.ArchiveOutputStream openArchiveOut(java.nio.file.Path archive, CompressionFormat format) throws java.io.IOException
        private ArchiveOutputStream OpenArchiveOut(Path archive, CompressionFormat format)
        {
            // StandardOpenOption.CREATE_NEW is important here because it atomically asserts that the file doesn't
            // exist as it is opened, avoiding a TOCTOU race condition which results in a security vulnerability. I
            // can't see a way to write a test to verify that we are using this option rather than just implementing
            // the check ourselves non-atomically.
            Stream @out     = Files.newOutputStream(archive, StandardOpenOption.CREATE_NEW);
            Stream compress = format.compress(@out);

            // Add enough archive meta-data that the load command can print a meaningful progress indicator.
            if (format == CompressionFormat.ZSTD)
            {
                WriteArchiveMetadata(compress);
            }

            TarArchiveOutputStream tarball = new TarArchiveOutputStream(compress);

            tarball.LongFileMode  = TarArchiveOutputStream.LONGFILE_POSIX;
            tarball.BigNumberMode = TarArchiveOutputStream.BIGNUMBER_POSIX;
            return(tarball);
        }