Inheritance: System.IO.StreamWriter
Beispiel #1
0
		/// <exception cref="System.IO.IOException"></exception>
		private void Config(string data)
		{
			OutputStreamWriter fw = new OutputStreamWriter(new FileOutputStream(configFile), 
				"UTF-8");
			fw.Write(data);
			fw.Close();
		}
Beispiel #2
0
		/// <summary>Generate and write the bundle to the output stream.</summary>
		/// <remarks>
		/// Generate and write the bundle to the output stream.
		/// <p>
		/// This method can only be called once per BundleWriter instance.
		/// </remarks>
		/// <param name="monitor">progress monitor to report bundle writing status to.</param>
		/// <param name="os">
		/// the stream the bundle is written to. The stream should be
		/// buffered by the caller. The caller is responsible for closing
		/// the stream.
		/// </param>
		/// <exception cref="System.IO.IOException">
		/// an error occurred reading a local object's data to include in
		/// the bundle, or writing compressed object data to the output
		/// stream.
		/// </exception>
		public virtual void WriteBundle(ProgressMonitor monitor, OutputStream os)
		{
			PackConfig pc = packConfig;
			if (pc == null)
			{
				pc = new PackConfig(db);
			}
			PackWriter packWriter = new PackWriter(pc, db.NewObjectReader());
			try
			{
				HashSet<ObjectId> inc = new HashSet<ObjectId>();
				HashSet<ObjectId> exc = new HashSet<ObjectId>();
				Sharpen.Collections.AddAll(inc, include.Values);
				foreach (RevCommit r in assume)
				{
					exc.AddItem(r.Id);
				}
				packWriter.SetDeltaBaseAsOffset(true);
				packWriter.SetThin(exc.Count > 0);
				packWriter.SetReuseValidatingObjects(false);
				if (exc.Count == 0)
				{
					packWriter.SetTagTargets(tagTargets);
				}
				packWriter.PreparePack(monitor, inc, exc);
				TextWriter w = new OutputStreamWriter(os, Constants.CHARSET);
				w.Write(NGit.Transport.TransportBundleConstants.V2_BUNDLE_SIGNATURE);
				w.Write('\n');
				char[] tmp = new char[Constants.OBJECT_ID_STRING_LENGTH];
				foreach (RevCommit a in assume)
				{
					w.Write('-');
					a.CopyTo(tmp, w);
					if (a.RawBuffer != null)
					{
						w.Write(' ');
						w.Write(a.GetShortMessage());
					}
					w.Write('\n');
				}
				foreach (KeyValuePair<string, ObjectId> e in include.EntrySet())
				{
					e.Value.CopyTo(tmp, w);
					w.Write(' ');
					w.Write(e.Key);
					w.Write('\n');
				}
				w.Write('\n');
				w.Flush();
				packWriter.WritePack(monitor, monitor, os);
			}
			finally
			{
				packWriter.Release();
			}
		}
Beispiel #3
0
 /// <summary>Write a string as a UTF-8 file.</summary>
 /// <remarks>Write a string as a UTF-8 file.</remarks>
 /// <param name="f">
 /// file to write the string to. Caller is responsible for making
 /// sure it is in the trash directory or will otherwise be cleaned
 /// up at the end of the test. If the parent directory does not
 /// exist, the missing parent directories are automatically
 /// created.
 /// </param>
 /// <param name="body">content to write to the file.</param>
 /// <exception cref="System.IO.IOException">the file could not be written.</exception>
 public static void Write(FilePath f, string body)
 {
     FileUtils.Mkdirs(f.GetParentFile(), true);
     TextWriter w = new OutputStreamWriter(new FileOutputStream(f), "UTF-8");
     try
     {
         w.Write(body);
     }
     finally
     {
         w.Close();
     }
 }
Beispiel #4
0
		/// <summary>Format this builder's state as an annotated tag object.</summary>
		/// <remarks>Format this builder's state as an annotated tag object.</remarks>
		/// <returns>
		/// this object in the canonical annotated tag format, suitable for
		/// storage in a repository.
		/// </returns>
		public virtual byte[] Build()
		{
			ByteArrayOutputStream os = new ByteArrayOutputStream();
			OutputStreamWriter w = new OutputStreamWriter(os, Constants.CHARSET);
			try
			{
				w.Write("object ");
				GetObjectId().CopyTo(w);
				w.Write('\n');
				w.Write("type ");
				w.Write(Constants.TypeString(GetObjectType()));
				w.Write("\n");
				w.Write("tag ");
				w.Write(GetTag());
				w.Write("\n");
				if (GetTagger() != null)
				{
					w.Write("tagger ");
					w.Write(GetTagger().ToExternalString());
					w.Write('\n');
				}
				w.Write('\n');
				if (GetMessage() != null)
				{
					w.Write(GetMessage());
				}
				w.Close();
			}
			catch (IOException err)
			{
				// This should never occur, the only way to get it above is
				// for the ByteArrayOutputStream to throw, but it doesn't.
				//
				throw new RuntimeException(err);
			}
			return os.ToByteArray();
		}
Beispiel #5
0
 /// <exception cref="System.IO.IOException"></exception>
 private void UpdateFETCH_HEAD(FetchResult result)
 {
     FilePath meta = transport.local.Directory;
     if (meta == null)
     {
         return;
     }
     LockFile Lock = new LockFile(new FilePath(meta, "FETCH_HEAD"), transport.local.FileSystem
         );
     try
     {
         if (Lock.Lock())
         {
             TextWriter w = new OutputStreamWriter(Lock.GetOutputStream());
             try
             {
                 foreach (FetchHeadRecord h in fetchHeadUpdates)
                 {
                     h.Write(w);
                     result.Add(h);
                 }
             }
             finally
             {
                 w.Close();
             }
             Lock.Commit();
         }
     }
     finally
     {
         Lock.Unlock();
     }
 }
Beispiel #6
0
 /// <summary>Create an empty writer.</summary>
 /// <remarks>Create an empty writer.</remarks>
 public MessageWriter()
 {
     buf = new ByteArrayOutputStream();
     enc = new OutputStreamWriter(GetRawStream(), Constants.CHARSET);
 }
		// UTF-8
		/// <summary>The actual serialization.</summary>
		/// <param name="xmp">the metadata object to be serialized</param>
		/// <param name="out">outputStream the output stream to serialize to</param>
		/// <param name="options">the serialization options</param>
		/// <exception cref="Com.Adobe.Xmp.XMPException">If case of wrong options or any other serialization error.</exception>
		public virtual void Serialize(XMPMeta xmp, OutputStream @out, SerializeOptions options)
		{
			try
			{
				outputStream = new CountOutputStream(@out);
				writer = new OutputStreamWriter(outputStream, options.GetEncoding());
				this.xmp = (XMPMetaImpl)xmp;
				this.options = options;
				this.padding = options.GetPadding();
				writer = new OutputStreamWriter(outputStream, options.GetEncoding());
				CheckOptionsConsistence();
				// serializes the whole packet, but don't write the tail yet 
				// and flush to make sure that the written bytes are calculated correctly
				string tailStr = SerializeAsRDF();
				writer.Flush();
				// adds padding
				AddPadding(tailStr.Length);
				// writes the tail
				Write(tailStr);
				writer.Flush();
				outputStream.Close();
			}
			catch (IOException)
			{
				throw new XMPException("Error writing to the OutputStream", XMPErrorConstants.Unknown);
			}
		}
Beispiel #8
0
		/// <exception cref="System.IO.IOException"></exception>
		internal virtual void Process_file(string file_path)
		{
			source_file = file_path;
			body = new FileBody();
			Stream @is;
			if (file_path.Equals("-"))
			{
				@is = Runtime.@in;
			}
			else
			{
				@is = new FileInputStream(file_path);
			}
			try
			{
				TextReader r = new StreamReader(@is, "ASCII");
				body.ReadData(r);
			}
			finally
			{
				@is.Close();
			}
			Process_file();
			if (body.WasModified())
			{
				Stream os;
				if (file_path.Equals("-"))
				{
					os = System.Console.Out;
				}
				else
				{
					os = new FileOutputStream(file_path);
				}
				try
				{
					TextWriter w = new OutputStreamWriter(os);
					body.WriteData(w);
					w.Flush();
				}
				finally
				{
					os.Close();
				}
			}
		}