public System.Runtime.InteropServices.ComTypes.STATSTG GetStat(string name) { using (ComStream stream = this.OpenStream(name, StorageMode.Open, false)) { return(stream.Stat); } }
private static int CreateSymbolReader(ISymUnmanagedBinder3 binder, IntPtr importer, string filename, string searchPath, bool avoidLocks, out ISymUnmanagedReader reader) { if (!avoidLocks) { return(binder.GetReaderForFile(importer, filename, searchPath, out reader)); } reader = null; string pdbFilename = Path.ChangeExtension(filename, ".pdb"); if (!File.Exists(pdbFilename)) { return(E_PDB_NOT_FOUND); } try { byte[] bytes = File.ReadAllBytes(pdbFilename); #if USE_ISTREAM IStream stream = new ComStream(new MemoryStream(bytes, 0, bytes.Length, false, true)); return(binder.GetReaderFromStream(importer, stream, out reader)); #else IDiaReadExeAtOffsetCallback callback = new DiaReadExeAtOffsetCallback(bytes); return(binder.GetReaderFromCallback(importer, filename, searchPath, CorSymSearchPolicyAttributes.AllowReferencePathAccess, callback, out reader)); #endif } catch (IOException) { return(E_FAIL); } }
/// <summary> /// Creates an Svg document from an xml string /// </summary> /// <param name="stream"></param> /// <param name="viewportSize"></param> /// <returns>Svg document model</returns> public SvgDocument CreateSvgDocument(IStream stream, SharpDX.Size2F viewportSize) { SvgDocument result; CreateSvgDocument_(ComStream.ToIntPtr(stream), viewportSize, out result); return(result); }
private T ReadData <T>(IModelDoc2 model, string streamName) { try { var stream = model.IGet3rdPartyStorage(streamName, false) as IStream; if (stream != null) { using (var comStr = new ComStream(stream, false)) { comStr.Seek(0, System.IO.SeekOrigin.Begin); var ser = new XmlSerializer(typeof(T)); return((T)ser.Deserialize(comStr)); } } else { throw new ThirdPartyStreamNotFoundException(); } } catch { throw; } finally { model.IRelease3rdPartyStorage(streamName); } }
private void AccessStreamFromPath(ComStorage storage, string path, bool writable, bool createIfNotExist, Action <ComStream> action, STGM mode = STGM.STGM_SHARE_EXCLUSIVE) { var parentIndex = path.IndexOf('\\'); if (parentIndex == -1) { IStream stream = null; try { stream = storage.OpenStream(path, mode); } catch { if (createIfNotExist) { stream = storage.CreateStream(path); } else { throw; } } using (var comStream = new ComStream(stream, writable)) { action.Invoke(comStream); } } else { var subStorageName = path.Substring(0, parentIndex); IStorage subStorage; try { subStorage = storage.OpenStorage(subStorageName, mode); } catch { if (createIfNotExist) { subStorage = storage.CreateStorage(subStorageName); } else { throw; } } using (var subComStorage = new ComStorage(subStorage, false)) { var nextLevelPath = path.Substring(parentIndex + 1); AccessStreamFromPath(subComStorage, nextLevelPath, writable, createIfNotExist, action); } } }
/// <summary> /// Backup processing method. Called from the worker thread. /// </summary> protected override void Backup() { if (String.IsNullOrEmpty(this.activeDriveId)) { throw new InvalidOperationException("Drive not initialized."); } // Reset the time remaining from previous burns. this.StatusUpdateArgs.TimeRemaining = TimeSpan.Zero; this.UpdateStatus(DriveStatus.Burning); MsftDiscRecorder2 discRecorder2 = new MsftDiscRecorder2(); discRecorder2.InitializeDiscRecorder(this.activeDriveId); discRecorder2.AcquireExclusiveAccess(true, ClientName); MsftDiscFormat2Data discFormatData = new MsftDiscFormat2Data(); if (!discFormatData.IsCurrentMediaSupported(discRecorder2)) { throw new IOException("Invalid media."); } discFormatData.Recorder = discRecorder2; discFormatData.ClientName = ClientName; discFormatData.ForceMediaToBeClosed = true; using (var stream = this.ImageReader.ImageFile.OpenRead()) { discFormatData.Update += this.DiscFormatData_Update; try { discFormatData.Write(ComStream.ToIStream(stream)); } catch (COMException ex) { // Ignore canceled hresult. Other errors should be reported to the UI thread. if (ex.ErrorCode != -1062600702) { throw; } } finally { discFormatData.Update -= this.DiscFormatData_Update; discRecorder2.EjectMedia(); } // Double check that the burn was completed. Some cases with XP and 2003 do not // return an error, but the burn is not successful. Using progress < 99 since // the last update isn't always returned. if (!this.WorkerThread.CancellationPending && this.progress < 99) { throw new IOException("Burn not completed."); } } discRecorder2.ReleaseExclusiveAccess(); }
/// <summary> /// Instantiates a new instance <see cref="ByteStream"/> from a <see cref="Stream"/>. /// </summary> /// <msdn-id>hh162754</msdn-id> /// <unmanaged>HRESULT MFCreateMFByteStreamOnStreamEx([In] IUnknown* punkStream,[Out] IMFByteStream** ppByteStream)</unmanaged> /// <unmanaged-short>MFCreateMFByteStreamOnStreamEx</unmanaged-short> public ByteStream(ComStream sourceStream) { this.comStream = sourceStream; IByteStream localStream; MediaFactory.CreateMFByteStreamOnStream(sourceStream.NativePointer, out localStream); NativePointer = ((ByteStream)localStream).NativePointer; }
/// <summary> /// Initializes the encoder with the provided stream. /// </summary> /// <param name="stream">The stream to use for initialization.</param> /// <returns>If the method succeeds, it returns <see cref="Result.Ok"/>. Otherwise, it throws an exception.</returns> /// <unmanaged>HRESULT IWICBitmapEncoder::Initialize([In, Optional] IStream* pIStream,[In] WICBitmapEncoderCacheOption cacheOption)</unmanaged> public void Initialize(IStream stream) { if (this.internalWICStream != null) { throw new InvalidOperationException("This instance is already initialized with an existing stream"); } Initialize_(ComStream.ToIntPtr(stream), SharpDX.WIC.BitmapEncoderCacheOption.NoCache); }
/// <summary> /// Create an OleStgMediumSTREAM that encapsulates the passed STGMEDIUM /// </summary> /// <param name="stg">Underlying STGMEDIUM</param> public OleStgMediumISTREAM(STGMEDIUM stg) : base(stg) { // validate that the correct type has been passed in ValidateType(TYMED.ISTREAM); // initialize the .NET stream m_stream = new ComStream((IStream)m_comObject); }
public void CanCreateByteStreamFromIOStream() { var stream = new MemoryStream(); var comstream = new ComStream(stream); using (var byteStream = MediaFoundationCore.IStreamToByteStream(comstream)) { Assert.IsNotNull(byteStream); } }
/// <summary> /// Initializes a handler with a stream. /// </summary> /// <param name="pstream">A pointer to an IStream interface that represents the stream source.</param> /// <param name="grfMode">One of the following STGM values that indicates the access mode for pstream. STGM_READ or STGM_READWRITE.</param> public int Initialize(IStream pstream, uint grfMode) { Log("Intiailising a stream based server."); // Set the selected item stream. SelectedItemStream = new ComStream(pstream); // Return success. return(WinError.S_OK); }
public void CanCreateByteStreamFromIOStream() { MediaFoundationCore.Startup(); var stream = new MemoryStream(); var comstream = new ComStream(stream); var byteStream = MediaFoundationCore.IStreamToByteStream(comstream); Assert.IsNotNull(byteStream); Marshal.ReleaseComObject(byteStream); MediaFoundationCore.Shutdown(); }
/// <summary> /// Instantiates a new instance <see cref="ByteStream"/> from a <see cref="Stream"/>. /// </summary> /// <msdn-id>hh162754</msdn-id> /// <unmanaged>HRESULT MFCreateMFByteStreamOnStreamEx([In] IUnknown* punkStream,[Out] IMFByteStream** ppByteStream)</unmanaged> /// <unmanaged-short>MFCreateMFByteStreamOnStreamEx</unmanaged-short> protected ByteStream(Stream sourceStream) { this.sourceStream = sourceStream; #if STORE_APP var randomAccessStream = sourceStream.AsRandomAccessStream(); randomAccessStreamCom = new ComObject(Marshal.GetIUnknownForObject(randomAccessStream)); MediaFactory.CreateMFByteStreamOnStreamEx(randomAccessStreamCom, this); #else streamProxy = new ComStreamProxy(sourceStream); MediaFactory.CreateMFByteStreamOnStream(ComStream.ToIntPtr(streamProxy), this); #endif }
/// <summary> /// Creates a stream in this storage. /// </summary> /// <param name="name">The string representing the name of the stream to create. (31 characters or less)</param> /// <param name="stream">The stream.</param> private void CreateStream(string name, out ComStream stream) { // Note: The compound file implementation of structured /// storage requires that all substorages and substreams be opened as share_exclusive (locking /// is managed at the file level). storage.CreateStream( name, STGM.CREATE | STGM.READWRITE | STGM.SHARE_EXCLUSIVE, 0, 0, out stream); }
/// <summary> /// Instantiates a new instance <see cref="ByteStream"/> from a <see cref="Stream"/>. /// </summary> /// <msdn-id>hh162754</msdn-id> /// <unmanaged>HRESULT MFCreateMFByteStreamOnStreamEx([In] IUnknown* punkStream,[Out] IMFByteStream** ppByteStream)</unmanaged> /// <unmanaged-short>MFCreateMFByteStreamOnStreamEx</unmanaged-short> public ByteStream(Stream sourceStream) { this.sourceStream = sourceStream; #if WIN8METRO var randomAccessStream = sourceStream.AsRandomAccessStream(); randomAccessStreamCom = new ComObject(Marshal.GetIUnknownForObject(randomAccessStream)); MediaFactory.CreateMFByteStreamOnStreamEx(randomAccessStreamCom, this); #else streamProxy = new ComStreamProxy(sourceStream); IByteStream localStream; MediaFactory.CreateMFByteStreamOnStream(ComStream.ToIntPtr(streamProxy), out localStream); NativePointer = ((ByteStream)localStream).NativePointer; #endif }
public void WriteAndRead() { var testData = new byte[10]; _random.NextBytes(testData); _output.WriteLine($"{nameof(testData)}: {string.Join(", ", testData)}"); var baseStream = File.Create($"{nameof(WriteAndRead)}_{Guid.NewGuid()}"); using (var stream = new ComStream(baseStream, takeOwnership: true)) { var writtenCountPointer = Marshal.AllocHGlobal(sizeof(long)); try { var input = testData.ToArray(); stream.Write(input, input.Length, writtenCountPointer); var writtenCount = Marshal.ReadInt32(writtenCountPointer); Assert.True(writtenCount == input.Length); } finally { Marshal.FreeHGlobal(writtenCountPointer); } var newPositionPointer = Marshal.AllocHGlobal(sizeof(long)); var readCountPointer = Marshal.AllocHGlobal(sizeof(long)); try { var output = new byte[4]; stream.Stat(out var stat, 0); var offset = _random.Next(0, (int)stat.cbSize - output.Length); stream.Seek(offset, (int)SeekOrigin.Begin, newPositionPointer); var newPosition = Marshal.ReadInt32(newPositionPointer); Assert.True(newPosition == offset); stream.Read(output, output.Length, readCountPointer); var readCount = Marshal.ReadInt32(readCountPointer); Assert.True(readCount == output.Length); Assert.Equal(output, testData.Skip(offset).Take(output.Length)); } finally { Marshal.FreeHGlobal(readCountPointer); Marshal.FreeHGlobal(newPositionPointer); } } }
public int LoadStream(IStream stream) { ComStream comStream = new ComStream(stream); try { this.LoadStream(comStream); } catch { } comStream.Close(); Marshal.ReleaseComObject(stream); return(1); }
/// <summary> /// Initializes a new instance of the <see cref="MediaFoundationDecoder" /> class. /// </summary> /// <param name="stream">Stream which provides the audio data to decode.</param> public MediaFoundationDecoder(Stream stream) { if (stream == null) { throw new ArgumentNullException("stream"); } if (!stream.CanRead) { throw new ArgumentException("Stream is not readable.", "stream"); } stream = new ComStream(stream); _stream = stream; _byteStream = MediaFoundationCore.IStreamToByteStream((IStream)stream); _reader = Initialize(_byteStream); }
public Stream Read(int stride = 1) { VVVV.Utils.Win32.IStream stream; FRawInStream.FRawIn.GetData(Position, out stream); Position += stride; if (stream != null) { var result = new ComStream(stream); result.Position = 0; return(result); } else { return(new MemoryStream(0)); } }
/// <summary> /// Sets and initializes the targetstream for the encoding process. /// </summary> /// <param name="stream">Stream which should be used as the targetstream.</param> /// <param name="inputMediaType">Mediatype of the raw input data to encode.</param> /// <param name="targetMediaType">Mediatype of the encoded data.</param> /// <param name="containerType">Container type which should be used.</param> protected void SetTargetStream(Stream stream, MFMediaType inputMediaType, MFMediaType targetMediaType, Guid containerType) { MFAttributes attributes = null; try { _targetBaseStream = new ComStream(stream); _targetStream = MediaFoundationCore.IStreamToByteStream(_targetBaseStream); attributes = new MFAttributes(2); attributes.SetUINT32(MediaFoundationAttributes.MF_READWRITE_ENABLE_HARDWARE_TRANSFORMS, 1); attributes.SetGuid(MediaFoundationAttributes.MF_TRANSCODE_CONTAINERTYPE, containerType); _sinkWriter = new MFSinkWriter(_targetStream, attributes); _streamIndex = _sinkWriter.AddStream(targetMediaType); _sinkWriter.SetInputMediaType(_streamIndex, inputMediaType, null); _targetMediaType = targetMediaType; _sourceBytesPerSecond = inputMediaType.AverageBytesPerSecond; //initialize the sinkwriter _sinkWriter.BeginWriting(); } catch (Exception) { if (_sinkWriter != null) { _sinkWriter.Dispose(); _sinkWriter = null; } if (_targetStream != null) { _targetStream.Dispose(); _targetStream = null; } throw; } finally { if (attributes != null) { attributes.Dispose(); } } }
private static void AddWatermark(string companyName, IStream stream) { var wm = new Watermark() { CompanyName = companyName, SignedBy = Environment.UserName, SignedOn = DateTime.Now }; using (var comStream = new ComStream(stream, true, false)) { var ser = new XmlSerializer(wm.GetType()); ser.Serialize(comStream, wm); } Console.WriteLine("Watermark is added"); }
public void CanCreateSourceReaderFromIOStream() { using (var stream = GlobalTestConfig.TestMp3AsStream()) using (var comstream = new ComStream(stream)) { using (var byteStream = MediaFoundationCore.IStreamToByteStream(comstream)) { Assert.IsNotNull(byteStream); using ( var reader = MediaFoundationCore.CreateSourceReaderFromByteStream(byteStream.BasePtr, IntPtr.Zero)) { Assert.IsNotNull(reader); } } } }
private static void ReadWatermark(IStream stream) { if (stream != null) { using (var comStream = new ComStream(stream, false, false)) { var ser = new XmlSerializer(typeof(Watermark)); var wm = ser.Deserialize(comStream) as Watermark; Console.WriteLine($"Company Name: {wm.CompanyName}"); Console.WriteLine($"Signed By: {wm.SignedBy}"); Console.WriteLine($"Signed On: {wm.SignedOn}"); } } else { Console.WriteLine("No watermark"); } }
public void CanCreateSourceReaderFromIOStream() { MediaFoundationCore.Startup(); var stream = File.OpenRead(@"C:\Temp\test.mp3"); using (var comstream = new ComStream(stream)) { var byteStream = MediaFoundationCore.IStreamToByteStream(comstream); Assert.IsNotNull(byteStream); using (var reader = MediaFoundationCore.CreateSourceReaderFromByteStream(byteStream, IntPtr.Zero)) { Assert.IsNotNull(reader); } Marshal.ReleaseComObject(byteStream); } MediaFoundationCore.Shutdown(); }
/// <summary> /// Opens a stream in this storage. /// </summary> /// <param name="name">The guid representing the name of the stream to open.</param> /// <param name="mode">The storagemode to use when opening the stream.</param> /// <param name="writable">Whether to open the stream as writable. If /// the parent storage is readonly, the stream cannot be opened /// as writable (StorageInvalidOperationException will be thrown).</param> /// <returns>The stream.</returns> public ComStream OpenStream(string name, StorageMode mode, bool writable) { bool openWritable = ResolveWritableOverride(writable); ComStream stream = null; try { switch (mode) { case (StorageMode.Create): CreateStream(name, out stream); break; case (StorageMode.Open): OpenStream(name, openWritable, out stream); break; case (StorageMode.OpenOrCreate): try { OpenStream(name, true, out stream); } catch (COMException e) { if (e.ErrorCode == STG_E.FILENOTFOUND) { CreateStream(name, out stream); } else { throw; } } break; } } catch (COMException e) { ThrowStorageException(e); } return(stream); }
public unsafe void ComStreamTextReadWrite() { using (var cleaner = new TestFileCleaner()) { string path = cleaner.GetTestPath(); IStorage storage = (IStorage)ComMethods.CreateStorage(path, InterfaceIds.IID_IStorage); ComStream stream; using (stream = new ComStream(storage.CreateStream("mystream", StorageMode.Create | StorageMode.ReadWrite | StorageMode.ShareExclusive))) { using (StreamWriter writer = new StreamWriter(stream, Encoding.Unicode, 1024, leaveOpen: true)) { writer.WriteLine("This is line one."); stream.Length.Should().Be(0); stream.Position.Should().Be(0); writer.Flush(); stream.Length.Should().Be(40); stream.Position.Should().Be(40); writer.WriteLine("This is line two."); stream.Length.Should().Be(40); stream.Position.Should().Be(40); writer.Flush(); stream.Length.Should().Be(78); stream.Position.Should().Be(78); } stream.Stream.Should().NotBeNull(); using (StreamReader reader = new StreamReader(stream, Encoding.Unicode, detectEncodingFromByteOrderMarks: false, 1024, leaveOpen: true)) { stream.Position = 0; stream.Position.Should().Be(0); reader.ReadLine().Should().Be("This is line one."); reader.ReadLine().Should().Be("This is line two."); } stream.Stream.Should().NotBeNull(); } stream.Stream.Should().BeNull(); } }
public unsafe void ComStreamConstruction() { using var cleaner = new TestFileCleaner(); string path = cleaner.GetTestPath(); IStorage storage = (IStorage)Com.CreateStorage(path, InterfaceIds.IID_IStorage); ComStream stream; using (stream = new ComStream(storage.CreateStream("mystream", StorageMode.Create | StorageMode.ReadWrite | StorageMode.ShareExclusive))) { stream.ToString().Should().Be("mystream"); stream.StorageMode.Should().Be(StorageMode.ReadWrite | StorageMode.ShareExclusive); stream.StorageType.Should().Be(StorageType.Stream); stream.CanRead.Should().BeTrue(); stream.CanSeek.Should().BeTrue(); stream.CanWrite.Should().BeTrue(); stream.Length.Should().Be(0); stream.Position.Should().Be(0); } }
public void CopyTo() { var testData = new byte[10]; _random.NextBytes(testData); _output.WriteLine($"{nameof(testData)}: {string.Join(", ", testData)}"); using (var baseInputStream = File.Create($"{nameof(CopyTo)}_{Guid.NewGuid()}")) using (var baseOutputStream = File.Create($"{nameof(CopyTo)}_{Guid.NewGuid()}")) using (var inputStream = new ComStream(baseInputStream)) using (var outputStream = new ComStream(baseOutputStream)) { var writtenCountPointer = Marshal.AllocHGlobal(sizeof(long)); var readCountPointer = Marshal.AllocHGlobal(sizeof(long)); try { var input = testData.ToArray(); inputStream.Write(input, input.Length, IntPtr.Zero); inputStream.Seek(0, (int)SeekOrigin.Begin, IntPtr.Zero); inputStream.CopyTo(outputStream, input.Length, readCountPointer, writtenCountPointer); var readCount = Marshal.ReadInt32(readCountPointer); var writtenCount = Marshal.ReadInt32(writtenCountPointer); Assert.True(readCount == input.Length); Assert.True(writtenCount == input.Length); var output = new byte[input.Length]; outputStream.Seek(0, (int)SeekOrigin.Begin, IntPtr.Zero); outputStream.Read(output, output.Length, IntPtr.Zero); Assert.Equal(output, input); } finally { Marshal.FreeHGlobal(readCountPointer); Marshal.FreeHGlobal(writtenCountPointer); } } }
private void StoreData <T>(IModelDoc2 model, T data, string streamName) { try { var stream = model.IGet3rdPartyStorage(streamName, true) as IStream; using (var comStr = new ComStream(stream, true, false)) { comStr.Seek(0, System.IO.SeekOrigin.Begin); var ser = new XmlSerializer(typeof(T)); ser.Serialize(comStr, data); } } catch { throw; } finally { model.IRelease3rdPartyStorage(streamName); } }
private static void AddComment(IStorage storage, string text) { var wm = new Comment() { Text = text, Author = Environment.UserName, Date = DateTime.Now }; using (var comStorage = new ComStorage(storage, true)) { var stream = comStorage.CreateStream($"Comment{comStorage.EnumElements().Count() + 1}"); using (var comStream = new ComStream(stream, true)) { var ser = new XmlSerializer(wm.GetType()); ser.Serialize(comStream, wm); } } Console.WriteLine("Comment is added"); }
private XmlWriter CreateStatusXmlWriter(object oTarget) { if (oTarget == null) throw new ArgumentNullException("oTarget"); XmlWriterSettings settings = new XmlWriterSettings() { Encoding = Encoding.Unicode}; if (oTarget is StringBuilder) { return XmlWriter.Create(oTarget as StringBuilder, settings); } else if (oTarget is Stream) { return XmlWriter.Create(oTarget as Stream, settings); } else if (oTarget is IStream) { ComStream cs = new ComStream(oTarget as IStream); return XmlWriter.Create(cs, settings); } throw new ArgumentException("oTarget"); }
private TextReader BuildTextReaderImpl(object redlineML) { if (redlineML is string) return new StringReader(redlineML as string); if (redlineML is IStream) { ComStream str = new ComStream(redlineML as IStream); if (str.Length == 0) return null; str.Position = 0; return new StreamReader(str); } if (redlineML is Stream) { Stream s = redlineML as Stream; if (s.Length == 0) return null; s.Position = 0; return new StreamReader(s); } if (redlineML == null) throw new ArgumentNullException("redlineML"); throw new ArgumentException("redlineML"); }
/// <summary> /// Initializes the stream to be able to read data from the image. /// </summary> /// <param name="ioStream">The stream to initialize.</param> private void InitializeStream(Stream ioStream) { if (ioStream == null) { throw new ArgumentNullException("ioStream"); } this.stream = new ComStream(ioStream); IntPtr size = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(long))); try { Marshal.WriteInt64(size, 0); this.stream.Seek(0, (int)SeekOrigin.End, size); this.imageSize = Marshal.ReadInt64(size); } finally { Marshal.FreeHGlobal(size); } }
int IStream.Clone(out IStream ppstm) { ppstm = new ComStream(new MemoryStream(stream.GetBuffer())); return S_OK; }
private static int CreateSymbolReader(ISymUnmanagedBinder3 binder, IntPtr importer, string filename, string searchPath, bool avoidLocks, out ISymUnmanagedReader reader) { if (! avoidLocks) return binder.GetReaderForFile(importer, filename, searchPath, out reader); reader = null; string pdbFilename = Path.ChangeExtension(filename, ".pdb"); if (!File.Exists(pdbFilename)) return E_PDB_NOT_FOUND; try { byte[] bytes = File.ReadAllBytes(pdbFilename); #if USE_ISTREAM IStream stream = new ComStream(new MemoryStream(bytes, 0, bytes.Length, false, true)); return binder.GetReaderFromStream(importer, stream, out reader); #else IDiaReadExeAtOffsetCallback callback = new DiaReadExeAtOffsetCallback(bytes); return binder.GetReaderFromCallback(importer, filename, searchPath, CorSymSearchPolicyAttributes.AllowReferencePathAccess, callback, out reader); #endif } catch (IOException) { return E_FAIL; } }
/// <summary> /// Opens a stream in this storage. /// </summary> /// <param name="name">The string representing the name of the stream to create (31 characters or less).</param> /// <param name="stream">The stream.</param> /// <param name="writable">Whether to open the stream as writable.</param> private void OpenStream(string name, bool writable, out ComStream stream) { // Note: The compound file implementation of structured // storage requires that all substorages and substreams be opened as share_exclusive (locking // is managed at the file level). storage.OpenStream( name, 0, (writable ? STGM.READWRITE : STGM.READ) | STGM.SHARE_EXCLUSIVE, 0, out stream); }