// 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);
			}
		}
Exemplo n.º 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();
			}
		}
Exemplo n.º 3
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();
				}
			}
		}