本文整理匯總了C#中Sharpen.ByteArrayOutputStream.ToString方法的典型用法代碼示例。如果您正苦於以下問題:C# ByteArrayOutputStream.ToString方法的具體用法?C# ByteArrayOutputStream.ToString怎麽用?C# ByteArrayOutputStream.ToString使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Sharpen.ByteArrayOutputStream
的用法示例。
在下文中一共展示了ByteArrayOutputStream.ToString方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: 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 "exact packet size".
/// </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();
}
}
示例2: 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);
}
示例3: TestDiff
public virtual void TestDiff()
{
Write(new FilePath(db.Directory.GetParent(), "test.txt"), "test");
FilePath folder = new FilePath(db.Directory.GetParent(), "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");
ByteArrayOutputStream os = new ByteArrayOutputStream();
DiffFormatter df = new DiffFormatter(new BufferedOutputStream(os));
df.SetRepository(db);
df.SetPathFilter(PathFilter.Create("folder"));
DirCacheIterator oldTree = new DirCacheIterator(db.ReadDirCache());
FileTreeIterator newTree = new FileTreeIterator(db);
df.Format(oldTree, newTree);
df.Flush();
string actual = os.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);
}
示例4: 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();
}
示例5: TestDiffWithPrefixes
public virtual void TestDiffWithPrefixes()
{
Write(new FilePath(db.WorkTree, "test.txt"), "test");
Git git = new Git(db);
git.Add().AddFilepattern(".").Call();
git.Commit().SetMessage("Initial commit").Call();
Write(new FilePath(db.WorkTree, "test.txt"), "test change");
OutputStream @out = new ByteArrayOutputStream();
git.Diff().SetOutputStream(@out).SetSourcePrefix("old/").SetDestinationPrefix("new/"
).Call();
string actual = @out.ToString();
string expected = "diff --git old/test.txt new/test.txt\n" + "index 30d74d2..4dba797 100644\n"
+ "--- old/test.txt\n" + "+++ new/test.txt\n" + "@@ -1 +1 @@\n" + "-test\n" + "\\ No newline at end of file\n"
+ "+test change\n" + "\\ No newline at end of file\n";
NUnit.Framework.Assert.AreEqual(expected.ToString(), actual);
}
示例6: TestDiffWithNegativeLineCount
public virtual void TestDiffWithNegativeLineCount()
{
Write(new FilePath(db.WorkTree, "test.txt"), "0\n1\n2\n3\n4\n5\n6\n7\n8\n9");
Git git = new Git(db);
git.Add().AddFilepattern(".").Call();
git.Commit().SetMessage("Initial commit").Call();
Write(new FilePath(db.WorkTree, "test.txt"), "0\n1\n2\n3\n4a\n5\n6\n7\n8\n9");
OutputStream @out = new ByteArrayOutputStream();
git.Diff().SetOutputStream(@out).SetContextLines(1).Call();
string actual = @out.ToString();
string expected = "diff --git a/test.txt b/test.txt\n" + "index f55b5c9..c5ec8fd 100644\n"
+ "--- a/test.txt\n" + "+++ b/test.txt\n" + "@@ -4,3 +4,3 @@\n" + " 3\n" + "-4\n"
+ "+4a\n" + " 5\n";
NUnit.Framework.Assert.AreEqual(expected.ToString(), actual);
}
示例7: TestDiffTwoCommits
public virtual void TestDiffTwoCommits()
{
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");
git.Add().AddFilepattern(".").Call();
git.Commit().SetMessage("second commit").Call();
Write(new FilePath(folder, "folder.txt"), "second folder change");
git.Add().AddFilepattern(".").Call();
git.Commit().SetMessage("third commit").Call();
// bad filter
DiffCommand diff = git.Diff().SetShowNameAndStatusOnly(true).SetPathFilter(PathFilter
.Create("test.txt")).SetOldTree(GetTreeIterator("HEAD^^")).SetNewTree(GetTreeIterator
("HEAD^"));
IList<DiffEntry> entries = diff.Call();
NUnit.Framework.Assert.AreEqual(0, entries.Count);
// no filter, two commits
OutputStream @out = new ByteArrayOutputStream();
diff = git.Diff().SetOutputStream(@out).SetOldTree(GetTreeIterator("HEAD^^")).SetNewTree
(GetTreeIterator("HEAD^"));
entries = diff.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);
}