当前位置: 首页>>代码示例>>C#>>正文


C# Sharpen.ByteArrayOutputStream类代码示例

本文整理汇总了C#中Sharpen.ByteArrayOutputStream的典型用法代码示例。如果您正苦于以下问题:C# ByteArrayOutputStream类的具体用法?C# ByteArrayOutputStream怎么用?C# ByteArrayOutputStream使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ByteArrayOutputStream类属于Sharpen命名空间,在下文中一共展示了ByteArrayOutputStream类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: SetUp

		public virtual void SetUp()
		{
			actDeltaBuf = new ByteArrayOutputStream();
			expDeltaBuf = new ByteArrayOutputStream();
			expDeltaEnc = new DeltaEncoder(expDeltaBuf, 0, 0);
			dstBuf = new ByteArrayOutputStream();
		}
开发者ID:LunarLanding,项目名称:ngit,代码行数:7,代码来源:DeltaIndexTest.cs

示例2: CreateTask

 /// <exception cref="Couchbase.Lite.CouchbaseLiteException"></exception>
 public static Couchbase.Lite.Document CreateTask(Database database, string title, 
     Bitmap image, string listId)
 {
     SimpleDateFormat dateFormatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"
         );
     Calendar calendar = GregorianCalendar.GetInstance();
     string currentTimeString = dateFormatter.Format(calendar.GetTime());
     IDictionary<string, object> properties = new Dictionary<string, object>();
     properties.Put("type", DocType);
     properties.Put("title", title);
     properties.Put("checked", false);
     properties.Put("created_at", currentTimeString);
     properties.Put("list_id", listId);
     Couchbase.Lite.Document document = database.CreateDocument();
     UnsavedRevision revision = document.CreateRevision();
     revision.SetUserProperties(properties);
     if (image != null)
     {
         ByteArrayOutputStream @out = new ByteArrayOutputStream();
         image.Compress(Bitmap.CompressFormat.Jpeg, 50, @out);
         ByteArrayInputStream @in = new ByteArrayInputStream(@out.ToByteArray());
         revision.SetAttachment("image", "image/jpg", @in);
     }
     revision.Save();
     return document;
 }
开发者ID:transformersprimeabcxyz,项目名称:_TO-DO-couchbase-lite-net-couchbase,代码行数:27,代码来源:Task.cs

示例3: TestWriteLine1

		public virtual void TestWriteLine1()
		{
			RawText a = new RawText(Constants.EncodeASCII("foo-a\nfoo-b\n"));
			ByteArrayOutputStream o = new ByteArrayOutputStream();
			a.WriteLine(o, 0);
			byte[] r = o.ToByteArray();
			NUnit.Framework.Assert.AreEqual("foo-a", RawParseUtils.Decode(r));
		}
开发者ID:LunarLanding,项目名称:ngit,代码行数:8,代码来源:RawTextTest.cs

示例4: SerializeToString

		/// <summary>Serializes an <code>XMPMeta</code>-object as RDF into a string.</summary>
		/// <remarks>
		/// Serializes an <code>XMPMeta</code>-object as RDF into a string.
		/// <em>Note:</em> Encoding is forced to UTF-16 when serializing to a
		/// string to ensure the correctness of &quot;exact packet size&quot;.
		/// </remarks>
		/// <param name="xmp">a metadata implementation object</param>
		/// <param name="options">
		/// Options to control the serialization (see
		/// <see cref="Com.Adobe.Xmp.Options.SerializeOptions"/>
		/// ).
		/// </param>
		/// <returns>Returns a string containing the serialized RDF.</returns>
		/// <exception cref="Com.Adobe.Xmp.XMPException">on serializsation errors.</exception>
		public static string SerializeToString(XMPMetaImpl xmp, SerializeOptions options)
		{
			// forces the encoding to be UTF-16 to get the correct string length
			options = options != null ? options : new SerializeOptions();
			options.SetEncodeUTF16BE(true);
			ByteArrayOutputStream @out = new ByteArrayOutputStream(2048);
			Serialize(xmp, @out, options);
			try
			{
				return @out.ToString(options.GetEncoding());
			}
			catch (UnsupportedEncodingException)
			{
				// cannot happen as UTF-8/16LE/BE is required to be implemented in
				// Java
				return @out.ToString();
			}
		}
开发者ID:renaud91,项目名称:n-metadata-extractor,代码行数:32,代码来源:XMPSerializerHelper.cs

示例5: TestParse_explicit_bad_encoded

 public virtual void TestParse_explicit_bad_encoded()
 {
     ByteArrayOutputStream b = new ByteArrayOutputStream();
     b.Write(Sharpen.Runtime.GetBytesForString("tree 9788669ad918b6fcce64af8882fc9a81cb6aba67\n"
         , "UTF-8"));
     b.Write(Sharpen.Runtime.GetBytesForString("author F\u00f6r fattare <[email protected]> 1218123387 +0700\n"
         , "ISO-8859-1"));
     b.Write(Sharpen.Runtime.GetBytesForString("committer C O. Miter <[email protected]> 1218123390 -0500\n"
         , "UTF-8"));
     b.Write(Sharpen.Runtime.GetBytesForString("encoding EUC-JP\n", "UTF-8"));
     b.Write(Sharpen.Runtime.GetBytesForString("\n", "UTF-8"));
     b.Write(Sharpen.Runtime.GetBytesForString("\u304d\u308c\u3044\n", "UTF-8"));
     b.Write(Sharpen.Runtime.GetBytesForString("\n", "UTF-8"));
     b.Write(Sharpen.Runtime.GetBytesForString("Hi\n", "UTF-8"));
     RevCommit c;
     c = new RevCommit(Id("9473095c4cb2f12aefe1db8a355fe3fafba42f67"));
     // bogus id
     c.ParseCanonical(new RevWalk(db), b.ToByteArray());
     NUnit.Framework.Assert.AreEqual("Japanese (EUC)", c.Encoding.EncodingName);
     NUnit.Framework.Assert.AreEqual("F\u00f6r fattare", c.GetAuthorIdent().GetName());
     NUnit.Framework.Assert.AreEqual("\u304d\u308c\u3044", c.GetShortMessage());
     NUnit.Framework.Assert.AreEqual("\u304d\u308c\u3044\n\nHi\n", c.GetFullMessage());
 }
开发者ID:charles-cai,项目名称:ngit,代码行数:23,代码来源:RevCommitParseTest.cs

示例6: TestDiffModified

		public virtual void TestDiffModified()
		{
			Write(new FilePath(db.WorkTree, "test.txt"), "test");
			FilePath folder = new FilePath(db.WorkTree, "folder");
			folder.Mkdir();
			Write(new FilePath(folder, "folder.txt"), "folder");
			Git git = new Git(db);
			git.Add().AddFilepattern(".").Call();
			git.Commit().SetMessage("Initial commit").Call();
			Write(new FilePath(folder, "folder.txt"), "folder change");
			OutputStream @out = new ByteArrayOutputStream();
			IList<DiffEntry> entries = git.Diff().SetOutputStream(@out).Call();
			NUnit.Framework.Assert.AreEqual(1, entries.Count);
			NUnit.Framework.Assert.AreEqual(DiffEntry.ChangeType.MODIFY, entries[0].GetChangeType
				());
			NUnit.Framework.Assert.AreEqual("folder/folder.txt", entries[0].GetOldPath());
			NUnit.Framework.Assert.AreEqual("folder/folder.txt", entries[0].GetNewPath());
			string actual = @out.ToString();
			string expected = "diff --git a/folder/folder.txt b/folder/folder.txt\n" + "index 0119635..95c4c65 100644\n"
				 + "--- a/folder/folder.txt\n" + "+++ b/folder/folder.txt\n" + "@@ -1 +1 @@\n" +
				 "-folder\n" + "\\ No newline at end of file\n" + "+folder change\n" + "\\ No newline at end of file\n";
			NUnit.Framework.Assert.AreEqual(expected.ToString(), actual);
		}
开发者ID:LunarLanding,项目名称:ngit,代码行数:23,代码来源:DiffCommandTest.cs

示例7: SetUp

 public virtual void SetUp()
 {
     @out = new ByteArrayOutputStream();
     fmt = new DiffFormatter(@out);
 }
开发者ID:red-gate,项目名称:ngit,代码行数:5,代码来源:DiffFormatterReflowTest.cs

示例8: AssertFileContentsEqual

 /// <exception cref="System.IO.IOException"></exception>
 private void AssertFileContentsEqual(FilePath actFile, string @string)
 {
     ByteArrayOutputStream bos = new ByteArrayOutputStream();
     FileInputStream fis = null;
     byte[] buffer = new byte[100];
     try
     {
         fis = new FileInputStream(actFile);
         int read = fis.Read(buffer);
         while (read > 0)
         {
             bos.Write(buffer, 0, read);
             read = fis.Read(buffer);
         }
         string content = Sharpen.Runtime.GetStringForBytes(bos.ToByteArray(), "UTF-8");
         NUnit.Framework.Assert.AreEqual(@string, content);
     }
     finally
     {
         if (fis != null)
         {
             fis.Close();
         }
     }
 }
开发者ID:nnieslan,项目名称:ngit,代码行数:26,代码来源:PullCommandWithRebaseTest.cs

示例9: DirCacheEntry

        /// <exception cref="System.IO.IOException"></exception>
        internal DirCacheEntry(byte[] sharedInfo, MutableInteger infoAt, InputStream @in, 
			MessageDigest md)
        {
            // private static final int P_CTIME_NSEC = 4;
            // private static final int P_MTIME_NSEC = 12;
            // private static final int P_DEV = 16;
            // private static final int P_INO = 20;
            // private static final int P_UID = 28;
            // private static final int P_GID = 32;
            info = sharedInfo;
            infoOffset = infoAt.value;
            IOUtil.ReadFully(@in, info, infoOffset, INFO_LEN);
            int len;
            if (IsExtended)
            {
                len = INFO_LEN_EXTENDED;
                IOUtil.ReadFully(@in, info, infoOffset + INFO_LEN, INFO_LEN_EXTENDED - INFO_LEN);
                if ((GetExtendedFlags() & ~EXTENDED_FLAGS) != 0)
                {
                    throw new IOException(MessageFormat.Format(JGitText.Get().DIRCUnrecognizedExtendedFlags
                        , GetExtendedFlags().ToString()));
                }
            }
            else
            {
                len = INFO_LEN;
            }
            infoAt.value += len;
            md.Update(info, infoOffset, len);
            int pathLen = NB.DecodeUInt16(info, infoOffset + P_FLAGS) & NAME_MASK;
            int skipped = 0;
            if (pathLen < NAME_MASK)
            {
                path = new byte[pathLen];
                IOUtil.ReadFully(@in, path, 0, pathLen);
                md.Update(path, 0, pathLen);
            }
            else
            {
                ByteArrayOutputStream tmp = new ByteArrayOutputStream();
                {
                    byte[] buf = new byte[NAME_MASK];
                    IOUtil.ReadFully(@in, buf, 0, NAME_MASK);
                    tmp.Write(buf);
                }
                for (; ; )
                {
                    int c = @in.Read();
                    if (c < 0)
                    {
                        throw new EOFException(JGitText.Get().shortReadOfBlock);
                    }
                    if (c == 0)
                    {
                        break;
                    }
                    tmp.Write(c);
                }
                path = tmp.ToByteArray();
                pathLen = path.Length;
                skipped = 1;
                // we already skipped 1 '\0' above to break the loop.
                md.Update(path, 0, pathLen);
                md.Update(unchecked((byte)0));
            }
            // Index records are padded out to the next 8 byte alignment
            // for historical reasons related to how C Git read the files.
            //
            int actLen = len + pathLen;
            int expLen = (actLen + 8) & ~7;
            int padLen = expLen - actLen - skipped;
            if (padLen > 0)
            {
                IOUtil.SkipFully(@in, padLen);
                md.Update(nullpad, 0, padLen);
            }
        }
开发者ID:sharwell,项目名称:ngit,代码行数:78,代码来源:DirCacheEntry.cs

示例10: SetUp

 public virtual void SetUp()
 {
     rawOut = new ByteArrayOutputStream();
 }
开发者ID:charles-cai,项目名称:ngit,代码行数:4,代码来源:SideBandOutputStreamTest.cs

示例11: SetUp

 public virtual void SetUp()
 {
     rawOut = new ByteArrayOutputStream();
     @out = new PacketLineOut(rawOut);
 }
开发者ID:ashmind,项目名称:ngit,代码行数:5,代码来源:PacketLineOutTest.cs

示例12: TestParse_explicit_bad_encoded2

		public virtual void TestParse_explicit_bad_encoded2()
		{
			ByteArrayOutputStream b = new ByteArrayOutputStream();
			b.Write(Sharpen.Runtime.GetBytesForString("object 9788669ad918b6fcce64af8882fc9a81cb6aba67\n"
				, "UTF-8"));
			b.Write(Sharpen.Runtime.GetBytesForString("type tree\n", "UTF-8"));
			b.Write(Sharpen.Runtime.GetBytesForString("tag v1.2.3.4.5\n", "UTF-8"));
			b.Write(Sharpen.Runtime.GetBytesForString("tagger F\u00f6r fattare <[email protected]> 1218123387 +0700\n"
				, "UTF-8"));
			b.Write(Sharpen.Runtime.GetBytesForString("encoding ISO-8859-1\n", "UTF-8"));
			b.Write(Sharpen.Runtime.GetBytesForString("\n", "UTF-8"));
			b.Write(Sharpen.Runtime.GetBytesForString("\u304d\u308c\u3044\n", "UTF-8"));
			b.Write(Sharpen.Runtime.GetBytesForString("\n", "UTF-8"));
			b.Write(Sharpen.Runtime.GetBytesForString("Hi\n", "UTF-8"));
			RevTag c;
			c = new RevTag(Id("9473095c4cb2f12aefe1db8a355fe3fafba42f67"));
			c.ParseCanonical(new RevWalk(db), b.ToByteArray());
			NUnit.Framework.Assert.AreEqual("F\u00f6r fattare", c.GetTaggerIdent().GetName());
			NUnit.Framework.Assert.AreEqual("\u304d\u308c\u3044", c.GetShortMessage());
			NUnit.Framework.Assert.AreEqual("\u304d\u308c\u3044\n\nHi\n", c.GetFullMessage());
		}
开发者ID:shoff,项目名称:ngit,代码行数:21,代码来源:RevTagParseTest.cs

示例13: Build

		/// <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();
		}
开发者ID:LunarLanding,项目名称:ngit,代码行数:43,代码来源:TagBuilder.cs

示例14: AddDocWithId

		/// <exception cref="System.IO.IOException"></exception>
		private void AddDocWithId(string docId, string attachmentName)
		{
			string docJson;
			if (attachmentName != null)
			{
				// add attachment to document
				InputStream attachmentStream = GetAsset(attachmentName);
				ByteArrayOutputStream baos = new ByteArrayOutputStream();
				IOUtils.Copy(attachmentStream, baos);
				string attachmentBase64 = Base64.EncodeBytes(baos.ToByteArray());
				docJson = string.Format("{\"foo\":1,\"bar\":false, \"_attachments\": { \"i_use_couchdb.png\": { \"content_type\": \"image/png\", \"data\": \"%s\" } } }"
					, attachmentBase64);
			}
			else
			{
				docJson = "{\"foo\":1,\"bar\":false}";
			}
			// push a document to server
			Uri replicationUrlTrailingDoc1 = new Uri(string.Format("%s/%s", GetReplicationURL
				().ToExternalForm(), docId));
			Uri pathToDoc1 = new Uri(replicationUrlTrailingDoc1, docId);
			Log.D(Tag, "Send http request to " + pathToDoc1);
			CountDownLatch httpRequestDoneSignal = new CountDownLatch(1);
			BackgroundTask getDocTask = new _BackgroundTask_376(pathToDoc1, docJson, httpRequestDoneSignal
				);
			getDocTask.Execute();
			Log.D(Tag, "Waiting for http request to finish");
			try
			{
				httpRequestDoneSignal.Await(300, TimeUnit.Seconds);
				Log.D(Tag, "http request finished");
			}
			catch (Exception e)
			{
				Sharpen.Runtime.PrintStackTrace(e);
			}
		}
开发者ID:Redth,项目名称:couchbase-lite-net,代码行数:38,代码来源:ReplicationTest.cs

示例15: Run

			public override void Run()
			{
				HttpClient httpclient = new DefaultHttpClient();
				HttpResponse response;
				string responseString = null;
				try
				{
					response = httpclient.Execute(new HttpGet(pathToDoc.ToExternalForm()));
					StatusLine statusLine = response.GetStatusLine();
					NUnit.Framework.Assert.IsTrue(statusLine.GetStatusCode() == HttpStatus.ScOk);
					if (statusLine.GetStatusCode() == HttpStatus.ScOk)
					{
						ByteArrayOutputStream @out = new ByteArrayOutputStream();
						response.GetEntity().WriteTo(@out);
						@out.Close();
						responseString = @out.ToString();
						NUnit.Framework.Assert.IsTrue(responseString.Contains(doc1Id));
						Log.D(ReplicationTest.Tag, "result: " + responseString);
					}
					else
					{
						response.GetEntity().GetContent().Close();
						throw new IOException(statusLine.GetReasonPhrase());
					}
				}
				catch (ClientProtocolException e)
				{
					NUnit.Framework.Assert.IsNull("Got ClientProtocolException: " + e.GetLocalizedMessage
						(), e);
				}
				catch (IOException e)
				{
					NUnit.Framework.Assert.IsNull("Got IOException: " + e.GetLocalizedMessage(), e);
				}
				httpRequestDoneSignal.CountDown();
			}
开发者ID:Redth,项目名称:couchbase-lite-net,代码行数:36,代码来源:ReplicationTest.cs


注:本文中的Sharpen.ByteArrayOutputStream类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。