本文整理汇总了C#中Sharpen.ByteArrayOutputStream类的典型用法代码示例。如果您正苦于以下问题:C# ByteArrayOutputStream类的具体用法?C# ByteArrayOutputStream怎么用?C# ByteArrayOutputStream使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ByteArrayOutputStream类属于Sharpen命名空间,在下文中一共展示了ByteArrayOutputStream类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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 "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();
}
}
开发者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
示例16: TestLargeObjectLoader
public virtual void TestLargeObjectLoader()
{
byte[] act = GetRng().NextBytes(512);
ObjectLoader ldr = new _ObjectLoader_122(act);
NUnit.Framework.Assert.AreEqual(Constants.OBJ_BLOB, ldr.GetType());
NUnit.Framework.Assert.AreEqual(act.Length, ldr.GetSize());
NUnit.Framework.Assert.IsTrue(ldr.IsLarge(), "is large");
try
{
ldr.GetCachedBytes();
NUnit.Framework.Assert.Fail("did not throw on getCachedBytes()");
}
catch (LargeObjectException)
{
}
// expected
try
{
ldr.GetBytes();
NUnit.Framework.Assert.Fail("did not throw on getBytes()");
}
catch (LargeObjectException)
{
}
// expected
try
{
ldr.GetCachedBytes(64);
NUnit.Framework.Assert.Fail("did not throw on getCachedBytes(64)");
}
catch (LargeObjectException)
{
}
// expected
byte[] copy = ldr.GetCachedBytes(1024);
NUnit.Framework.Assert.AreNotSame(act, copy);
NUnit.Framework.Assert.IsTrue(Arrays.Equals(act, copy), "same content");
ObjectStream @in = ldr.OpenStream();
NUnit.Framework.Assert.IsNotNull(@in, "has stream");
NUnit.Framework.Assert.AreEqual(Constants.OBJ_BLOB, @in.GetType());
NUnit.Framework.Assert.AreEqual(act.Length, @in.GetSize());
NUnit.Framework.Assert.AreEqual(act.Length, @in.Available());
NUnit.Framework.Assert.IsTrue(@in.MarkSupported(), "mark supported");
copy = new byte[act.Length];
NUnit.Framework.Assert.AreEqual(act.Length, @in.Read(copy));
NUnit.Framework.Assert.AreEqual(0, @in.Available());
NUnit.Framework.Assert.AreEqual(-1, @in.Read());
NUnit.Framework.Assert.IsTrue(Arrays.Equals(act, copy), "same content");
ByteArrayOutputStream tmp = new ByteArrayOutputStream();
ldr.CopyTo(tmp);
NUnit.Framework.Assert.IsTrue(Arrays.Equals(act, tmp.ToByteArray()), "same content"
);
}
开发者ID:LunarLanding,项目名称:ngit,代码行数:53,代码来源:ObjectLoaderTest.cs
示例17: TestSmallObjectLoader
public virtual void TestSmallObjectLoader()
{
byte[] act = GetRng().NextBytes(512);
ObjectLoader ldr = new ObjectLoader.SmallObject(Constants.OBJ_BLOB, act);
NUnit.Framework.Assert.AreEqual(Constants.OBJ_BLOB, ldr.GetType());
NUnit.Framework.Assert.AreEqual(act.Length, ldr.GetSize());
NUnit.Framework.Assert.IsFalse(ldr.IsLarge(), "not is large");
NUnit.Framework.Assert.AreSame(act, ldr.GetCachedBytes());
NUnit.Framework.Assert.AreSame(act, ldr.GetCachedBytes(1));
NUnit.Framework.Assert.AreSame(act, ldr.GetCachedBytes(int.MaxValue));
byte[] copy = ldr.GetBytes();
NUnit.Framework.Assert.AreNotSame(act, copy);
NUnit.Framework.Assert.IsTrue(Arrays.Equals(act, copy), "same content");
copy = ldr.GetBytes(1);
NUnit.Framework.Assert.AreNotSame(act, copy);
NUnit.Framework.Assert.IsTrue(Arrays.Equals(act, copy), "same content");
copy = ldr.GetBytes(int.MaxValue);
NUnit.Framework.Assert.AreNotSame(act, copy);
NUnit.Framework.Assert.IsTrue(Arrays.Equals(act, copy), "same content");
ObjectStream @in = ldr.OpenStream();
NUnit.Framework.Assert.IsNotNull(@in, "has stream");
NUnit.Framework.Assert.IsTrue(@in is ObjectStream.SmallStream, "is small stream");
NUnit.Framework.Assert.AreEqual(Constants.OBJ_BLOB, @in.GetType());
NUnit.Framework.Assert.AreEqual(act.Length, @in.GetSize());
NUnit.Framework.Assert.AreEqual(act.Length, @in.Available());
NUnit.Framework.Assert.IsTrue(@in.MarkSupported(), "mark supported");
copy = new byte[act.Length];
NUnit.Framework.Assert.AreEqual(act.Length, @in.Read(copy));
NUnit.Framework.Assert.AreEqual(0, @in.Available());
NUnit.Framework.Assert.AreEqual(-1, @in.Read());
NUnit.Framework.Assert.IsTrue(Arrays.Equals(act, copy), "same content");
ByteArrayOutputStream tmp = new ByteArrayOutputStream();
ldr.CopyTo(tmp);
NUnit.Framework.Assert.IsTrue(Arrays.Equals(act, tmp.ToByteArray()), "same content"
);
}
开发者ID:LunarLanding,项目名称:ngit,代码行数:36,代码来源:ObjectLoaderTest.cs
示例18: EncodeBytesToBytes
/// <summary>
/// Similar to
/// <see cref="EncodeBytes(byte[], int, int, int)">EncodeBytes(byte[], int, int, int)
/// </see>
/// but returns
/// a byte array instead of instantiating a String. This is more efficient
/// if you're working with I/O streams and have large data sets to encode.
/// </summary>
/// <param name="source">The data to convert</param>
/// <param name="off">Offset in array where conversion should begin</param>
/// <param name="len">Length of data to convert</param>
/// <param name="options">Specified options</param>
/// <returns>The Base64-encoded data as a String</returns>
/// <seealso cref="Gzip">Gzip</seealso>
/// <seealso cref="DoBreakLines">DoBreakLines</seealso>
/// <exception cref="System.IO.IOException">if there is an error</exception>
/// <exception cref="System.ArgumentNullException">if source array is null</exception>
/// <exception cref="System.ArgumentException">if source array, offset, or length are invalid
/// </exception>
/// <since>2.3.1</since>
public static byte[] EncodeBytesToBytes(byte[] source, int off, int len, int options
)
{
if (source == null)
{
throw new ArgumentNullException("Cannot serialize a null array.");
}
// end if: null
if (off < 0)
{
throw new ArgumentException("Cannot have negative offset: " + off);
}
// end if: off < 0
if (len < 0)
{
throw new ArgumentException("Cannot have length offset: " + len);
}
// end if: len < 0
if (off + len > source.Length)
{
throw new ArgumentException(string.Format("Cannot have offset of %d and length of %d with array of length %d"
, off, len, source.Length));
}
// end if: off < 0
// Compress?
if ((options & Gzip) != 0)
{
ByteArrayOutputStream baos = null;
GZIPOutputStream gzos = null;
Base64.OutputStream b64os = null;
try
{
// GZip -> Base64 -> ByteArray
baos = new ByteArrayOutputStream();
b64os = new Base64.OutputStream(baos, Encode | options);
gzos = new GZIPOutputStream(b64os);
gzos.Write(source, off, len);
gzos.Close();
}
catch (IOException e)
{
// end try
// Catch it and then throw it immediately so that
// the finally{} block is called for cleanup.
throw;
}
finally
{
// end catch
try
{
gzos.Close();
}
catch (Exception)
{
}
try
{
b64os.Close();
}
catch (Exception)
{
}
try
{
baos.Close();
}
catch (Exception)
{
}
}
// end finally
return baos.ToByteArray();
}
else
{
// end if: compress
// Else, don't compress. Better not to use streams at all then.
bool breakLines = (options & DoBreakLines) != 0;
//int len43 = len * 4 / 3;
//.........这里部分代码省略.........
开发者ID:Redth,项目名称:couchbase-lite-net,代码行数:101,代码来源:Base64.cs
示例19: Save
/// <summary>Save the configuration as a Git text style configuration file.</summary>
/// <remarks>
/// Save the configuration as a Git text style configuration file.
/// <p>
/// <b>Warning:</b> Although this method uses the traditional Git file
/// locking approach to protect against concurrent writes of the
/// configuration file, it does not ensure that the file has not been
/// modified since the last read, which means updates performed by other
/// objects accessing the same backing file may be lost.
/// </remarks>
/// <exception cref="System.IO.IOException">the file could not be written.</exception>
public override void Save()
{
byte[] @out;
string text = ToText();
if (utf8Bom)
{
ByteArrayOutputStream bos = new ByteArrayOutputStream();
bos.Write(unchecked((int)(0xEF)));
bos.Write(unchecked((int)(0xBB)));
bos.Write(unchecked((int)(0xBF)));
bos.Write(Sharpen.Runtime.GetBytesForString(text, RawParseUtils.UTF8_CHARSET.Name
()));
@out = bos.ToByteArray();
}
else
{
@out = Constants.Encode(text);
}
LockFile lf = new LockFile(GetFile(), fs);
if (!lf.Lock())
{
throw new LockFailedException(GetFile());
}
try
{
lf.SetNeedSnapshot(true);
lf.Write(@out);
if (!lf.Commit())
{
throw new IOException(MessageFormat.Format(JGitText.Get().cannotCommitWriteTo, GetFile
()));
}
}
finally
{
lf.Unlock();
}
snapshot = lf.GetCommitSnapshot();
hash = Hash(@out);
// notify the listeners
FireConfigChangedEvent();
}
开发者ID:LunarLanding,项目名称:ngit,代码行数:53,代码来源:FileBasedConfig.cs
示例20: Decode
/// <summary>
/// Decodes data from Base64 notation, automatically
/// detecting gzip-compressed data and decompressing it.
/// </summary>
/// <remarks>
/// Decodes data from Base64 notation, automatically
/// detecting gzip-compressed data and decompressing it.
/// </remarks>
/// <param name="s">the string to decode</param>
/// <param name="options">encode options such as URL_SAFE</param>
/// <returns>the decoded data</returns>
/// <exception cref="System.IO.IOException">if there is an error</exception>
/// <exception cref="System.ArgumentNullException">if <tt>s</tt> is null</exception>
/// <since>1.4</since>
public static byte[] Decode(string s, int options)
{
if (s == null)
{
throw new ArgumentNullException("Input string was null.");
}
// end if
byte[] bytes;
try
{
bytes = Sharpen.Runtime.GetBytesForString(s, PreferredEncoding);
}
catch (UnsupportedEncodingException)
{
// end try
bytes = Sharpen.Runtime.GetBytesForString(s);
}
// end catch
//</change>
// Decode
bytes = Decode(bytes, 0, bytes.Length, options);
// Check to see if it's gzip-compressed
// GZIP Magic Two-Byte Number: 0x8b1f (35615)
bool dontGunzip = (options & DontGunzip) != 0;
if ((bytes != null) && (bytes.Length >= 4) && (!dontGunzip))
{
int head = ((int)bytes[0] & unchecked((int)(0xff))) | ((bytes[1] << 8) & unchecked(
(int)(0xff00)));
if (GZIPInputStream.GzipMagic == head)
{
ByteArrayInputStream bais = null;
GZIPInputStream gzis = null;
ByteArrayOutputStream baos = null;
byte[] buffer = new byte[2048];
int length = 0;
try
{
baos = new ByteArrayOutputStream();
bais = new ByteArrayInputStream(bytes);
gzis = new GZIPInputStream(bais);
while ((length = gzis.Read(buffer)) >= 0)
{
baos.Write(buffer, 0, length);
}
// end while: reading input
// No error? Get new bytes.
bytes = baos.ToByteArray();
}
catch (IOException e)
{
// end try
Sharpen.Runtime.PrintStackTrace(e);
}
finally
{
// Just return originally-decoded bytes
// end catch
try
{
baos.Close();
}
catch (Exception)
{
}
try
{
gzis.Close();
}
catch (Exception)
{
}
try
{
bais.Close();
}
catch (Exception)
{
}
}
}
}
// end finally
// end if: gzipped
// end if: bytes.length >= 2
return bytes;
}
开发者ID:Redth,项目名称:couchbase-lite-net,代码行数:100,代码来源:Base64.cs
注:本文中的Sharpen.ByteArrayOutputStream类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论