static void MakeRandomFasta(string id, string desc, Frequency[] a, int n, Stream s) { var descStr = Encoding.ASCII.GetBytes($">{id} {desc}\n"); s.Write(descStr, 0, descStr.Length); var bufferSize = LineLength * 40; var pool = new BufferPool(bufferSize); var results = GetSplits(n, bufferSize) .AsParallel().AsOrdered() .Select(size => pool.Acquire(size)) .AsEnumerable() .Select(buffer => { FillRandomly(buffer); return(buffer); }) .AsParallel().AsOrdered() .Select(rnd => new { Buffer = rnd, Nucleotides = SelectNucleotides(a, rnd) }); foreach (var result in results) { var nucleotides = result.Nucleotides; s.Write(nucleotides, 0, nucleotides.Length); pool.Release(result.Buffer); } }
private static uint WriteOutputStream(Stream outputStream, Stream inputStream) { if (outputStream == null) { throw new ArgumentNullException("outputStream"); } if (inputStream == null) { throw new ArgumentNullException("inputStream"); } uint num = 0U; BufferPool bufferPool = BufferPoolCollection.AutoCleanupCollection.Acquire(ZipEntryAttachment.CopyBufferSize); byte[] array = bufferPool.Acquire(); try { int num2; while ((num2 = inputStream.Read(array, 0, array.Length)) > 0) { outputStream.Write(array, 0, num2); num += (uint)num2; } } finally { if (array != null) { bufferPool.Release(array); } } return(num); }
private static uint ComputeCrc32FromStream(Stream stream) { if (!stream.CanSeek) { throw new ArgumentException("Stream is required to support Seek operations, and does not"); } BufferPool bufferPool = BufferPoolCollection.AutoCleanupCollection.Acquire(ZipEntryAttachment.CopyBufferSize); byte[] array = bufferPool.Acquire(); uint num = 0U; try { int bytesToRead; while ((bytesToRead = stream.Read(array, 0, array.Length)) > 0) { num = ZipEntryAttachment.ComputeCrc32FromBytes(array, bytesToRead, num); } } finally { if (array != null) { bufferPool.Release(array); } } stream.Seek(0L, SeekOrigin.Begin); return(num); }
internal static long CopyStreamData(Stream readStream, Stream writeStream, int?numBytes, int trailingNulls, int bufferSize) { int size = Math.Min(numBytes ?? bufferSize, bufferSize); BufferPoolCollection.BufferSize bufferSize2; BufferPoolCollection.AutoCleanupCollection.TryMatchBufferSize(size, out bufferSize2); BufferPool bufferPool = BufferPoolCollection.AutoCleanupCollection.Acquire(bufferSize2); byte[] array = null; long result = 0L; try { array = bufferPool.Acquire(); result = Util.StreamHandler.CopyStreamData(readStream, writeStream, numBytes, trailingNulls, array); } finally { if (array != null) { bufferPool.Release(array); } } return(result); }
private static uint[] CompressAndWriteOutputStream(Stream outputStream, Stream inputStream, bool doComputeCrc) { if (outputStream == null) { throw new ArgumentNullException("outputStream"); } if (inputStream == null) { throw new ArgumentNullException("inputStream"); } uint num = 0U; int num2 = 0; BufferPool bufferPool = BufferPoolCollection.AutoCleanupCollection.Acquire(ZipEntryAttachment.CopyBufferSize); byte[] array = bufferPool.Acquire(); uint num3 = 0U; using (Stream stream = Streams.CreateTemporaryStorageStream()) { try { int num4; using (Stream stream2 = new DeflateStream(stream, CompressionMode.Compress, true)) { while ((num4 = inputStream.Read(array, 0, array.Length)) > 0) { if (doComputeCrc) { num3 = ZipEntryAttachment.ComputeCrc32FromBytes(array, num4, num3); } num2 += num4; stream2.Write(array, 0, num4); } stream2.Flush(); } stream.Seek(0L, SeekOrigin.Begin); while ((num4 = stream.Read(array, 0, array.Length)) > 0) { outputStream.Write(array, 0, num4); num += (uint)num4; } } finally { if (array != null) { bufferPool.Release(array); } } } return(new uint[] { num, num3, (uint)num2 }); }
public static void CopyMimeStream(ISupportMime mimeSource, MessageRec message, IFolderProxy folderProxy) { ArgumentValidator.ThrowIfNull("mimeSource", mimeSource); ArgumentValidator.ThrowIfNull("message", message); ArgumentValidator.ThrowIfNull("folderProxy", folderProxy); using (mimeSource.RHTracker.Start()) { PropValueData[] array; using (Stream mimeStream = mimeSource.GetMimeStream(message, out array)) { using (IMessageProxy messageProxy = folderProxy.OpenMessage(message.EntryId)) { BufferPool bufferPool = BufferPoolCollection.AutoCleanupCollection.Acquire(BufferPoolCollection.BufferSize.Size128K); byte[] array2 = bufferPool.Acquire(); try { for (;;) { int num = mimeStream.Read(array2, 0, array2.Length); if (num == 0) { break; } if (num == array2.Length) { messageProxy.WriteToMime(array2); } else { byte[] array3 = new byte[num]; Array.Copy(array2, 0, array3, 0, num); messageProxy.WriteToMime(array3); } } } finally { bufferPool.Release(array2); } List <PropValueData> list = new List <PropValueData>(SyncEmailUtils.SyncEmailPropTags.Length); list.AddRange(Array.FindAll <PropValueData>(message.AdditionalProps, (PropValueData propValue) => Array.IndexOf <PropTag>(SyncEmailUtils.SyncEmailPropTags, (PropTag)propValue.PropTag) >= 0)); if (array != null) { list.AddRange(array); } using (mimeSource.RHTracker.StartExclusive()) { messageProxy.SetProps(list.ToArray()); messageProxy.SaveChanges(); } } } } }
private Stream GetFilteredResponseStream(ConfigurationContextBase configurationContext, Stream inputStream, Charset charset, BlockStatus blockStatus) { BufferPool bufferPool = BufferPoolCollection.AutoCleanupCollection.Acquire(ZipEntryAttachment.CopyBufferSize); byte[] array = bufferPool.Acquire(); Stream stream = new MemoryStream(); try { using (Stream filteredStream = AttachmentUtilities.GetFilteredStream(configurationContext, inputStream, charset, blockStatus)) { try { int count; while ((count = filteredStream.Read(array, 0, array.Length)) > 0) { stream.Write(array, 0, count); } } finally { if (array != null) { bufferPool.Release(array); } } } stream.Seek(0L, SeekOrigin.Begin); } catch (Exception ex) { ExTraceGlobals.AttachmentHandlingTracer.TraceError <string>((long)this.GetHashCode(), "ZipEntryAttachment.GetfilteredStream: Safe HTML converter failed with exception {0}", ex.Message); stream = new MemoryStream(); } return(stream); }
public static bool GetOpaqueContent(Stream inputStream, Stream outputStream) { bool result = false; int num = 0; using (Asn1Reader asn1Reader = new Asn1Reader(inputStream)) { while (asn1Reader.ReadNext() && asn1Reader.EncodingType == EncodingType.Sequence) { if (!asn1Reader.ReadFirstChild() || asn1Reader.EncodingType != EncodingType.ObjectIdentifier) { StorageGlobals.ContextTraceDebug <int>(ExTraceGlobals.CcInboundMimeTracer, "InboundMimeConverter.GetOpaqueContent ({0}): did not find expected ContentType=EncodingType.ObjectIdentifier", ++num); } else if (asn1Reader.ReadValueAsOID() != OID.RSASignedData) { StorageGlobals.ContextTraceDebug <int>(ExTraceGlobals.CcInboundMimeTracer, "InboundMimeConverter.GetOpaqueContent ({0}): did not find expected RSA_signedData OID", ++num); } else if (!asn1Reader.ReadNextSibling() || asn1Reader.TagClass != TagClass.Context || asn1Reader.TagNumber != 0) { StorageGlobals.ContextTraceDebug <int>(ExTraceGlobals.CcInboundMimeTracer, "InboundMimeConverter.GetOpaqueContent ({0}): did not find expected content tag", ++num); } else if (!asn1Reader.ReadFirstChild() || asn1Reader.EncodingType != EncodingType.Sequence) { StorageGlobals.ContextTraceDebug <int>(ExTraceGlobals.CcInboundMimeTracer, "InboundMimeConverter.GetOpaqueContent ({0}): did not find expected EncodingType.Sequence", ++num); } else if (!asn1Reader.ReadFirstChild() || asn1Reader.EncodingType != EncodingType.Integer) { StorageGlobals.ContextTraceDebug <int>(ExTraceGlobals.CcInboundMimeTracer, "InboundMimeConverter.GetOpaqueContent ({0}): did not find expected version number", ++num); } else if (!asn1Reader.ReadNextSibling() || asn1Reader.EncodingType != EncodingType.Set) { StorageGlobals.ContextTraceDebug <int>(ExTraceGlobals.CcInboundMimeTracer, "InboundMimeConverter.GetOpaqueContent ({0}): did not find expected digest algorithm set", ++num); } else if (!asn1Reader.ReadNextSibling() || asn1Reader.EncodingType != EncodingType.Sequence) { StorageGlobals.ContextTraceDebug <int>(ExTraceGlobals.CcInboundMimeTracer, "InboundMimeConverter.GetOpaqueContent ({0}): did not find expected content tag", ++num); } else if (!asn1Reader.ReadFirstChild() || asn1Reader.EncodingType != EncodingType.ObjectIdentifier) { StorageGlobals.ContextTraceDebug <int>(ExTraceGlobals.CcInboundMimeTracer, "InboundMimeConverter.GetOpaqueContent ({0}): did not find expected ContentType = EncodingType.ObjectIdentifier for SignedData", ++num); } else if (asn1Reader.ReadValueAsOID() != OID.RSAData) { StorageGlobals.ContextTraceDebug <int>(ExTraceGlobals.CcInboundMimeTracer, "InboundMimeConverter.GetOpaqueContent ({0}): did not find expected RSA_Data OID", ++num); } else if (!asn1Reader.ReadNextSibling()) { StorageGlobals.ContextTraceDebug <int>(ExTraceGlobals.CcInboundMimeTracer, "InboundMimeConverter.GetOpaqueContent ({0}): did not find any content in S/MIME blob", ++num); } else if (asn1Reader.TagClass != TagClass.Context || asn1Reader.TagNumber != 0) { StorageGlobals.ContextTraceDebug <int>(ExTraceGlobals.CcInboundMimeTracer, "InboundMimeConverter.GetOpaqueContent ({0}): did not find expected tag class or value for S/MIME blob", ++num); } else if (!asn1Reader.ReadFirstChild() || asn1Reader.EncodingType != EncodingType.OctetString) { StorageGlobals.ContextTraceDebug <int>(ExTraceGlobals.CcInboundMimeTracer, "InboundMimeConverter.GetOpaqueContent ({0}): did not find expected EncodingType for S/MIME blob", ++num); } else { BufferPoolCollection.BufferSize bufferSize = BufferPoolCollection.BufferSize.Size20K; BufferPool bufferPool = BufferPoolCollection.AutoCleanupCollection.Acquire(bufferSize); byte[] array = null; try { array = bufferPool.Acquire(); do { if (!asn1Reader.IsConstructedTag) { for (;;) { int num2 = asn1Reader.ReadBytesValue(array, 0, array.Length); if (num2 == 0) { break; } outputStream.Write(array, 0, num2); result = true; } } asn1Reader.ReadNext(); }while (asn1Reader.EncodingType == EncodingType.OctetString); continue; } finally { if (array != null) { bufferPool.Release(array); } } } return(result); } StorageGlobals.ContextTraceDebug <int>(ExTraceGlobals.CcInboundMimeTracer, "InboundMimeConverter.GetOpaqueContent ({0}): did not find expected ContentInfo=EncodingType.Sequence", ++num); } return(result); }