本文整理匯總了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();
}
示例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;
}
示例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));
}
示例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 "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();
}
}
示例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());
}
示例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);
}
示例7: SetUp
public virtual void SetUp()
{
@out = new ByteArrayOutputStream();
fmt = new DiffFormatter(@out);
}
示例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();
}
}
}
示例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);
}
}
示例10: SetUp
public virtual void SetUp()
{
rawOut = new ByteArrayOutputStream();
}
示例11: SetUp
public virtual void SetUp()
{
rawOut = new ByteArrayOutputStream();
@out = new PacketLineOut(rawOut);
}
示例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());
}
示例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();
}
示例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);
}
}
示例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();
}