2018-11-16 20:00:12 +00:00
|
|
|
|
namespace UglyToad.PdfPig.Tokens
|
2018-01-14 10:53:01 +00:00
|
|
|
|
{
|
2018-01-19 00:35:04 +00:00
|
|
|
|
using Filters;
|
|
|
|
|
|
2018-01-14 10:53:01 +00:00
|
|
|
|
internal class StreamToken : IDataToken<byte[]>
|
|
|
|
|
{
|
2018-01-19 00:35:04 +00:00
|
|
|
|
private readonly object lockObject = new object();
|
|
|
|
|
|
|
|
|
|
private byte[] decodedBytes;
|
|
|
|
|
|
2018-01-14 10:53:01 +00:00
|
|
|
|
public DictionaryToken StreamDictionary { get; }
|
|
|
|
|
|
|
|
|
|
public byte[] Data { get; }
|
|
|
|
|
|
|
|
|
|
public StreamToken(DictionaryToken streamDictionary, byte[] data)
|
|
|
|
|
{
|
|
|
|
|
StreamDictionary = streamDictionary;
|
|
|
|
|
Data = data;
|
|
|
|
|
}
|
2018-01-19 00:35:04 +00:00
|
|
|
|
|
|
|
|
|
public byte[] Decode(IFilterProvider filterProvider)
|
|
|
|
|
{
|
|
|
|
|
lock (lockObject)
|
|
|
|
|
{
|
|
|
|
|
if (decodedBytes != null)
|
|
|
|
|
{
|
|
|
|
|
return decodedBytes;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var filters = filterProvider.GetFilters(StreamDictionary);
|
|
|
|
|
|
|
|
|
|
var transform = Data;
|
|
|
|
|
for (var i = 0; i < filters.Count; i++)
|
|
|
|
|
{
|
|
|
|
|
transform = filters[i].Decode(transform, StreamDictionary, i);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
decodedBytes = transform;
|
|
|
|
|
|
|
|
|
|
return transform;
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-01-14 10:53:01 +00:00
|
|
|
|
}
|
|
|
|
|
}
|