2016-10-13 21:13:30 +00:00
|
|
|
|
using System.IO;
|
2016-10-23 19:14:57 +00:00
|
|
|
|
using MediaBrowser.Model.IO;
|
2016-10-06 18:55:01 +00:00
|
|
|
|
using Microsoft.IO;
|
|
|
|
|
|
2016-11-11 04:25:21 +00:00
|
|
|
|
namespace MediaBrowser.Server.Startup.Common.IO
|
2016-10-06 18:55:01 +00:00
|
|
|
|
{
|
2016-11-08 18:44:23 +00:00
|
|
|
|
public class RecyclableMemoryStreamProvider : IMemoryStreamFactory
|
2016-10-06 18:55:01 +00:00
|
|
|
|
{
|
|
|
|
|
readonly RecyclableMemoryStreamManager _manager = new RecyclableMemoryStreamManager();
|
|
|
|
|
|
|
|
|
|
public MemoryStream CreateNew()
|
|
|
|
|
{
|
|
|
|
|
return _manager.GetStream();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public MemoryStream CreateNew(int capacity)
|
|
|
|
|
{
|
|
|
|
|
return _manager.GetStream("RecyclableMemoryStream", capacity);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public MemoryStream CreateNew(byte[] buffer)
|
|
|
|
|
{
|
|
|
|
|
return _manager.GetStream("RecyclableMemoryStream", buffer, 0, buffer.Length);
|
|
|
|
|
}
|
2016-11-08 18:44:23 +00:00
|
|
|
|
|
|
|
|
|
public bool TryGetBuffer(MemoryStream stream, out byte[] buffer)
|
|
|
|
|
{
|
|
|
|
|
buffer = stream.GetBuffer();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2016-10-06 18:55:01 +00:00
|
|
|
|
}
|
2016-10-13 21:13:30 +00:00
|
|
|
|
|
2016-11-08 18:44:23 +00:00
|
|
|
|
public class MemoryStreamProvider : IMemoryStreamFactory
|
2016-10-13 21:13:30 +00:00
|
|
|
|
{
|
|
|
|
|
public MemoryStream CreateNew()
|
|
|
|
|
{
|
|
|
|
|
return new MemoryStream();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public MemoryStream CreateNew(int capacity)
|
|
|
|
|
{
|
|
|
|
|
return new MemoryStream(capacity);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public MemoryStream CreateNew(byte[] buffer)
|
|
|
|
|
{
|
|
|
|
|
return new MemoryStream(buffer);
|
|
|
|
|
}
|
2016-11-08 18:44:23 +00:00
|
|
|
|
|
|
|
|
|
public bool TryGetBuffer(MemoryStream stream, out byte[] buffer)
|
|
|
|
|
{
|
|
|
|
|
buffer = stream.GetBuffer();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
2016-10-13 21:13:30 +00:00
|
|
|
|
}
|
2016-10-06 18:55:01 +00:00
|
|
|
|
}
|