public void Clear() { _ms = null; _br = null; _bw = null; _data = null; _segment = null; }
public void Append(byte[] buffer, int offset, int count) { long pos = Stream.Position; Stream.Seek(0, SeekOrigin.End); Stream.Write(buffer, offset, count); Stream.Position = pos; _segment = null; }
private ByteBuffer CurrentBuffer(DicomReadOptions options) { #if SILVERLIGHT ByteBuffer bb = new ByteBuffer(_endian); bb.CopyFrom(_stream, (int)_len); #else ByteBuffer bb = null; if (_isFile) { bool delayLoad = false; if (_len >= _largeElementSize && _vr != DicomVR.SQ) { if (Flags.IsSet(options, DicomReadOptions.DeferLoadingLargeElements)) { delayLoad = true; } else if (Flags.IsSet(options, DicomReadOptions.DeferLoadingPixelData) && _tag == DicomTags.PixelData) { delayLoad = true; } else if (Flags.IsSet(options, DicomReadOptions.DeferLoadingPixelData) && _fragment != null && _fragment.Tag == DicomTags.PixelData) { delayLoad = true; } } if (delayLoad) { FileStream fs = (FileStream)_stream; FileSegment segment = new FileSegment(fs.Name, fs.Position, _len); _stream.Seek(_len, SeekOrigin.Current); bb = new ByteBuffer(segment, _endian); } } if (bb == null) { bb = new ByteBuffer(_endian); bb.CopyFrom(_stream, (int)_len); } #endif if (_vr.IsEncodedString) { bb.Encoding = _encoding; } return(bb); }
public void Chop(int count) { _segment = null; int len = (int)Stream.Length; if (len <= count) { Stream.SetLength(0); return; } byte[] bytes = GetChunk(count, len - count); Stream.SetLength(0); Stream.Position = 0; Stream.Write(bytes, 0, bytes.Length); }
public void SetString(string val, byte pad) { int count = _encoding.GetByteCount(val); if ((count & 1) == 1) { count++; } byte[] bytes = new byte[count]; if (_encoding.GetBytes(val, 0, val.Length, bytes, 0) < count) { bytes[count - 1] = pad; } _data = bytes; _ms = null; _segment = null; }
public int CopyFrom(Stream s, int count) { _ms = null; _segment = null; _br = null; _bw = null; int read = 0; _data = new byte[count]; while (read < count) { int rd = s.Read(_data, read, count - read); if (rd == 0) { return(read); } read += rd; } return(read); }
public void FromBytes(byte[] bytes) { _data = bytes; _ms = null; _segment = null; }
public int CopyFrom(Stream s, int count) { _ms = null; _segment = null; _br = null; _bw = null; int read = 0; _data = new byte[count]; while (read < count) { int rd = s.Read(_data, read, count - read); if (rd == 0) return read; read += rd; } return read; }
private ByteBuffer CurrentBuffer(DicomReadOptions options) { ByteBuffer bb = null; if (_isFile) { bool delayLoad = false; if (_len >= _largeElementSize && _vr != DicomVR.SQ) { if (Flags.IsSet(options, DicomReadOptions.DeferLoadingLargeElements)) delayLoad = true; else if (Flags.IsSet(options, DicomReadOptions.DeferLoadingPixelData) && _tag == DicomTags.PixelData) delayLoad = true; else if (Flags.IsSet(options, DicomReadOptions.DeferLoadingPixelData) && _fragment != null && _fragment.Tag == DicomTags.PixelData) delayLoad = true; } if (delayLoad) { FileStream fs = (FileStream)_stream; FileSegment segment = new FileSegment(fs.Name, fs.Position, _len); _stream.Seek(_len, SeekOrigin.Current); bb = new ByteBuffer(segment, _endian); } } if (bb == null) { bb = new ByteBuffer(_endian); bb.CopyFrom(_stream, (int)_len); } if (_vr.IsEncodedString) bb.Encoding = _encoding; return bb; }
public ByteBuffer(FileSegment segment) : this(segment, Endian.LocalMachine) { }
public void SetString(string val) { _data = _encoding.GetBytes(val); _ms = null; _segment = null; }
public void SetString(string val, byte pad) { int count = _encoding.GetByteCount(val); if ((count & 1) == 1) count++; byte[] bytes = new byte[count]; if (_encoding.GetBytes(val, 0, val.Length, bytes, 0) < count) bytes[count - 1] = pad; _data = bytes; _ms = null; _segment = null; }
public ByteBuffer(FileSegment segment, Endian endian) { _segment = segment; _endian = endian; _encoding = DcmEncoding.Default; }