Example #1
0
 /// <summary>
 /// Initializes an instance of <see cref="StreamByteTarget"/>.
 /// </summary>
 /// <param name="stream">Stream subject to writing.</param>
 public StreamByteTarget(Stream stream)
 {
     _stream = stream;
     _endian = Endian.LocalMachine;
     _writer = EndianBinaryWriter.Create(_stream, _endian);
     _lock   = new object();
 }
Example #2
0
 /// <summary>
 /// Initializes an instance of <see cref="FileByteTarget"/>.
 /// </summary>
 /// <param name="file"></param>
 public FileByteTarget(IFileReference file)
 {
     _file   = file;
     _stream = _file.OpenWrite();
     _endian = Endian.LocalMachine;
     _writer = EndianBinaryWriter.Create(_stream, _endian);
     _lock   = new object();
 }
Example #3
0
 /// <summary>
 /// Initializes new PDU for writing
 /// </summary>
 /// <param name="type">Type of PDU</param>
 public RawPDU(byte type)
 {
     _type     = type;
     _ms       = new MemoryStream();
     _bw       = EndianBinaryWriter.Create(_ms, _encoding, Endian.Big);
     _m16      = new Stack <long>();
     _m32      = new Stack <long>();
     _encoding = Encoding.ASCII;
 }
Example #4
0
 /// <summary>
 /// Initializes new PDU for writing
 /// </summary>
 /// <param name="type">Type of PDU</param>
 public RawPDU(byte type)
 {
     _type = type;
     _ms   = new MemoryStream();
     _ms.Seek(0, SeekOrigin.Begin);
     _bw  = EndianBinaryWriter.Create(_ms, DicomEncoding.Default, Endian.Big);
     _m16 = new Stack <long>();
     _m32 = new Stack <long>();
 }
Example #5
0
            public RLEEncoder()
            {
                _count   = 0;
                _offsets = new uint[15];
                _stream  = new MemoryStream();
                _writer  = EndianBinaryWriter.Create(_stream, Endian.Little);
                _buffer  = new byte[132];
                WriteHeader();

                _prevByte    = -1;
                _repeatCount = 0;
                _bufferPos   = 0;
            }
Example #6
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <remarks>
        /// <para>
        /// It is assumed that this contructor must be used when writing / creating a new PDU.  This constructor
        /// will not work when reading a PDU.
        /// </para>
        /// <para>
        /// NOTE:  It might make sense in the future to split this class into one that writes PDUs and
        /// a second class that reads PDUs.
        /// </para>
        /// </remarks>
        /// <param name="type">The PDU type being created.</param>
        public RawPDU(byte type)
        {
            _type = type;
            _ms   = new MemoryStream();
            _bw   = EndianBinaryWriter.Create(_ms, Endian.Big);
            _m16  = new Stack <long>();
            _m32  = new Stack <long>();

            // Write the PDU header now
            _bw.Write(_type);
            _bw.Write((byte)0);
            MarkLength32("PDU Length");
        }
Example #7
0
        /// <summary>
        /// Initializes new PDU for writing
        /// </summary>
        /// <param name="type">Type of PDU</param>
        public RawPDU(byte type)
        {
            _type = type;
            _ms   = new MemoryStream();
            _bw   = EndianBinaryWriter.Create(_ms, _encoding, Endian.Big);
            _m16  = new Stack <long>();
            _m32  = new Stack <long>();
#if SILVERLIGHT
            _encoding = Encoding.UTF8;
#else
            _encoding = Encoding.ASCII;
#endif
        }
        /// <summary>
        /// Initializes a new instance of <see cref="UnseekableStreamByteSource"/>.
        /// </summary>
        /// <param name="stream">Stream to read from.</param>
        /// <param name="readOption">Defines the handling of large tags.</param>
        /// <param name="largeObjectSize">Custom limit of what are large values and what are not.
        /// If 0 is passed, then the default of 64k is used.</param>
        public UnseekableStreamByteSource(Stream stream, FileReadOption readOption = FileReadOption.Default, int largeObjectSize = 0)
        {
            if (readOption == FileReadOption.Default || readOption == FileReadOption.ReadLargeOnDemand)
            {
                var logger = Setup.ServiceProvider.GetRequiredService <ILogManager>().GetLogger("FellowOakDicom.IO");
                logger.Warn("Reading large files on demand is not possible with unseekable streams, reading all tags immediately instead.");
                readOption = FileReadOption.ReadAll;
            }

            _byteSource   = new StreamByteSource(stream, readOption, largeObjectSize);
            _buffer       = new MemoryStream();
            _bufferReader = EndianBinaryReader.Create(_buffer, Endian.LocalMachine);
            _bufferWriter = EndianBinaryWriter.Create(_buffer, Endian.LocalMachine);
            _bufferState  = BufferState.Unused;
            // we cannot use the milestones of the stream byte source, as these don't
            // account for the buffer
            _milestones = new Stack <long>();
        }
Example #9
0
            internal RLEEncoder()
            {
                this.Length = 0;
                _count      = 0;
                _offsets    = new uint[15];
                _stream     = new MemoryStream();
                _writer     = EndianBinaryWriter.Create(_stream, Endian.Little);
                _buffer     = new byte[132];

                // Write header
                AppendUInt32((uint)_count);
                for (var i = 0; i < 15; i++)
                {
                    AppendUInt32(_offsets[i]);
                }

                _prevByte    = -1;
                _repeatCount = 0;
                _bufferPos   = 0;
            }