コード例 #1
0
ファイル: ItemWriter.cs プロジェクト: DMIAOCHEN/Evil-DICOM
 private static void WriteUIDItem(DICOMBinaryWriter dw, ItemType iType, string uid)
 {
     if (!string.IsNullOrEmpty(uid))
     {
         dw.Write((byte) iType);
         dw.WriteNullBytes(1); // Reserved Null Byte
         LengthWriter.WriteBigEndian(dw, uid.Length, 2);
         dw.Write(uid);
     }
 }
コード例 #2
0
ファイル: DataWriter.cs プロジェクト: Baasanjav/Evil-DICOM
 public static void WriteLittleEndian(DICOMBinaryWriter dw, VR vr, DICOMWriteSettings settings,
     IDICOMElement toWrite)
 {
     byte[] data = DataComposer.GetDataLittleEndian(toWrite);
     LengthWriter.Write(dw, vr, settings, data != null ? data.Length : 0);
     dw.Write(data != null ? data : new byte[0]);
 }
コード例 #3
0
ファイル: Abort.cs プロジェクト: DMIAOCHEN/Evil-DICOM
 public byte[] Write()
 {
     var written = new byte[0];
     var stream = new MemoryStream();
     using (var dw = new DICOMBinaryWriter(stream))
     {
         dw.Write((byte)PDUType.A_ABORT);
         dw.WriteNullBytes(1); //Reserved Null byte
         LengthWriter.WriteBigEndian(dw, 4, 4);
         dw.WriteNullBytes(2); //Reserved Null bytes
         dw.Write((byte)Source);
         dw.Write((byte)Reason);
         written = stream.ToArray();
     }
     return written;
 }
コード例 #4
0
ファイル: LengthWriter.cs プロジェクト: baheywadea/Evil-DICOM
 public static void WriteLittleEndian(DICOMBinaryWriter dw, VR vr, DICOMWriteSettings settings, int length)
 {
     byte[] lengthBytes = new byte[0];
     if (!(settings.TransferSyntax == TransferSyntax.IMPLICIT_VR_LITTLE_ENDIAN))
     {
         switch (VRDictionary.GetEncodingFromVR(vr))
         {
             case VREncoding.ExplicitLong:
                 dw.WriteNullBytes(2);
                 lengthBytes = BitConverter.GetBytes(length);
                 break;
             case VREncoding.ExplicitShort:
                 lengthBytes = BitConverter.GetBytes((short)length);
                 break;
             case VREncoding.Implicit:
                 lengthBytes = BitConverter.GetBytes(length);
                 break;
         }
     }
     else
     {
         lengthBytes =BitConverter.GetBytes(length);
     }
     dw.Write(lengthBytes);
 }
コード例 #5
0
ファイル: ItemWriter.cs プロジェクト: DMIAOCHEN/Evil-DICOM
 public static void WriteMaxLength(DICOMBinaryWriter dw, int length)
 {
     dw.Write((byte) ItemType.MAXIMUM_LENGTH);
     dw.WriteNullBytes(1); // Reserved Null Byte
     LengthWriter.WriteBigEndian(dw, 4, 2);
     LengthWriter.WriteBigEndian(dw, length, 4);
 }
コード例 #6
0
ファイル: ItemWriter.cs プロジェクト: DMIAOCHEN/Evil-DICOM
 public static void WritePDVItem(DICOMBinaryWriter dw, PDVItem pdv)
 {
     //Write fragment first so we have length
     var fragment = new byte[0];
     using (var stream = new MemoryStream())
     {
         using (var fragDw = new DICOMBinaryWriter(stream))
         {
             WritePDVFragment(fragDw, pdv.Fragment);
             fragment = stream.ToArray();
         }
     }
     LengthWriter.WriteBigEndian(dw, fragment.Length + 1, 4);
     dw.Write((byte) pdv.PresentationContextID);
     dw.Write(fragment);
 }
コード例 #7
0
 public static void Write(DICOMBinaryWriter dw, VR vr, DICOMWriteSettings settings, int length)
 {
     var lengthBytes = BitConverter.GetBytes(length);
     if (settings.TransferSyntax != TransferSyntax.IMPLICIT_VR_LITTLE_ENDIAN)
     {
         //Length byte size depends on VR Encoding
         switch (VRDictionary.GetEncodingFromVR(vr))
         {
             case VREncoding.ExplicitLong:
                 dw.WriteNullBytes(2);
                 lengthBytes = BitConverter.GetBytes(length);
                 break;
             case VREncoding.ExplicitShort:
                 lengthBytes = BitConverter.GetBytes((ushort) length);
                 break;
             case VREncoding.Implicit:
                 lengthBytes = BitConverter.GetBytes(length);
                 break;
         }
     }
     if (settings.TransferSyntax == TransferSyntax.EXPLICIT_VR_BIG_ENDIAN)
     {
         Array.Reverse(lengthBytes);
     }
     dw.Write(lengthBytes);
 }
コード例 #8
0
ファイル: LengthWriter.cs プロジェクト: DMIAOCHEN/Evil-DICOM
 public static void Write(DICOMBinaryWriter dw, VR vr, DICOMWriteSettings settings, int length)
 {
     var lengthBytes = BitConverter.GetBytes(length);
     if (settings.TransferSyntax != TransferSyntax.IMPLICIT_VR_LITTLE_ENDIAN)
     {
         //Length byte size depends on VR Encoding
         switch (VRDictionary.GetEncodingFromVR(vr))
         {
             case VREncoding.ExplicitLong:
                 dw.WriteNullBytes(2);
                 lengthBytes = BitConverter.GetBytes(length);
                 break;
             case VREncoding.ExplicitShort:
                 lengthBytes = BitConverter.GetBytes((ushort) length);
                 if (length > 65536) { throw new ArgumentOutOfRangeException("Length is greater than allowed for explicit VR syntax. Try using implicit VR"); }
                 break;
             case VREncoding.Implicit:
                 lengthBytes = BitConverter.GetBytes(length);
                 break;
         }
     }
     if (settings.TransferSyntax == TransferSyntax.EXPLICIT_VR_BIG_ENDIAN)
     {
         Array.Reverse(lengthBytes);
     }
     dw.Write(lengthBytes);
 }
コード例 #9
0
 private static void WriteIndefiniteLength(DICOMWriteSettings settings, DICOMBinaryWriter dw)
 {
     if (!(settings.TransferSyntax == TransferSyntax.IMPLICIT_VR_LITTLE_ENDIAN))
     {
         dw.WriteNullBytes(2);
     }
     dw.Write(new byte[] {0xFF, 0xFF, 0xFF, 0xFF});
 }
コード例 #10
0
 private static void WriteIndefiniteLength(DICOMWriteSettings settings, DICOMBinaryWriter dw)
 {
     if (!(settings.TransferSyntax == TransferSyntax.IMPLICIT_VR_LITTLE_ENDIAN))
     {
         dw.WriteNullBytes(2);
     }
     dw.Write(new byte[] { 0xFF, 0xFF, 0xFF, 0xFF });
 }
コード例 #11
0
 public static void WriteVR(DICOMBinaryWriter dw, DICOMWriteSettings settings, VR vr)
 {
     if (!(settings.TransferSyntax == TransferSyntax.IMPLICIT_VR_LITTLE_ENDIAN))
     {
         string abbreviation = VRDictionary.GetAbbreviationFromVR(vr);
         dw.Write(abbreviation);
     }
 }
コード例 #12
0
ファイル: VRWriter.cs プロジェクト: baheywadea/Evil-DICOM
 public static void WriteVR(DICOMBinaryWriter dw, DICOMWriteSettings settings, VR vr)
 {
     if (!(settings.TransferSyntax == TransferSyntax.IMPLICIT_VR_LITTLE_ENDIAN))
     {
         string abbreviation = VRDictionary.GetAbbreviationFromVR(vr);
         dw.Write(abbreviation);
     }
 }
コード例 #13
0
ファイル: PDataTF.cs プロジェクト: DMIAOCHEN/Evil-DICOM
 public byte[] Write()
 {
     var written = new byte[0];
     using (var stream = new MemoryStream())
     {
         using (var dw = new DICOMBinaryWriter(stream))
         {
             dw.Write((byte) PDUType.P_DATA_TRANSFER);
             dw.WriteNullBytes(1); //Reserved Null byte
             byte[] items = WriteItems();
             LengthWriter.WriteBigEndian(dw, items.Length, 4);
             dw.Write(items);
             written = stream.ToArray();
         }
     }
     return written;
 }
コード例 #14
0
ファイル: Accept.cs プロジェクト: DMIAOCHEN/Evil-DICOM
 public byte[] Write()
 {
     var written = new byte[0];
     using (var stream = new MemoryStream())
     {
         using (var dw = new DICOMBinaryWriter(stream))
         {
             dw.Write((byte)PDUType.A_ASSOC_ACCEPT);
             dw.WriteNullBytes(1); //Reserved Null byte
             byte[] body = WriteBody();
             LengthWriter.WriteBigEndian(dw, body.Length, 4);
             dw.Write(body);
             written = stream.ToArray();
         }
     }
     return written;
 }
コード例 #15
0
ファイル: VRWriter.cs プロジェクト: zzti/Evil-DICOM
 public static void WriteVR(DICOMBinaryWriter dw, DICOMIOSettings settings, IDICOMElement toWrite)
 {
     if (!(settings.TransferSyntax == TransferSyntax.IMPLICIT_VR_LITTLE_ENDIAN))
     {
         var vr           = VRDictionary.GetVRFromType(toWrite);
         var abbreviation = VRDictionary.GetAbbreviationFromVR(vr);
         dw.Write(abbreviation);
     }
 }
コード例 #16
0
ファイル: GroupWriter.cs プロジェクト: DMIAOCHEN/Evil-DICOM
 public static int WriteGroup(DICOMBinaryWriter dw, DICOMWriteSettings settings, DICOMObject d, IDICOMElement el)
 {
     byte[] groupBytes = WriteGroupBytes(d, settings, el.Tag.Group);
     int length = groupBytes.Length;
     var ul = el as UnsignedLong;
     ul.SetData((uint) length);
     DICOMElementWriter.Write(dw, settings, ul);
     dw.Write(groupBytes);
     return d.Elements.Where(elm => elm.Tag.Group == ul.Tag.Group).ToList().Count - 1;
 }
コード例 #17
0
ファイル: ItemWriter.cs プロジェクト: DMIAOCHEN/Evil-DICOM
 public static void WriteAsyncOperations(DICOMBinaryWriter dw, AsyncOperations ao)
 {
     if (ao != null)
     {
         dw.Write((byte) ItemType.ASYNCHRONOUS_OPERATIONS_WINDOW);
         dw.WriteNullBytes(1); // Reserved Null Byte
         LengthWriter.WriteBigEndian(dw, 4, 2);
         LengthWriter.WriteBigEndian(dw, ao.MaxInvokeOperations, 2);
         LengthWriter.WriteBigEndian(dw, ao.MaxPerformOperations, 2);
     }
 }
コード例 #18
0
        public static int WriteGroupLittleEndian(DICOMBinaryWriter dw, DICOMWriteSettings settings, DICOMObject d, IDICOMElement el)
        {
            byte[]       groupBytes = WriteGroupBytesLittleEndian(d, settings, el.Tag.Group);
            int          length     = groupBytes.Length;
            UnsignedLong ul         = el as UnsignedLong;

            ul.SetData((uint)length);
            DICOMElementWriter.WriteLittleEndian(dw, settings, ul);
            dw.Write(groupBytes);
            return(d.Elements.Where(elm => elm.Tag.Group == ul.Tag.Group).ToList().Count - 1);
        }
コード例 #19
0
        public static int WriteGroup(DICOMBinaryWriter dw, DICOMIOSettings settings, DICOMObject d, IDICOMElement el)
        {
            var groupBytes = WriteGroupBytes(d, settings, el.Tag.Group);
            var length     = groupBytes.Length;
            var ul         = el as UnsignedLong;

            ul.SetData((uint)length);
            DICOMElementWriter.Write(dw, settings, ul);
            dw.Write(groupBytes);
            return(d.Elements.Where(elm => elm.Tag.Group == ul.Tag.Group).ToList().Count - 1);
        }
コード例 #20
0
ファイル: LengthWriter.cs プロジェクト: baheywadea/Evil-DICOM
 public static void WriteLittleEndian(DICOMBinaryWriter dw, int length, int numberOfBytes)
 {
     byte[] lengthBytes = new byte[0];
     switch (numberOfBytes)
     {
         case 2: lengthBytes = BitConverter.GetBytes((short)length);
             break;
         case 4: lengthBytes = BitConverter.GetBytes(length);
             break;
     }
     dw.Write(lengthBytes);
 }
コード例 #21
0
        public static void WriteBigEndian(DICOMBinaryWriter dw, int length, int numberOfBytes)
        {
            byte[] lengthBytes = new byte[0];
            switch (numberOfBytes)
            {
            case 2: lengthBytes = BitConverter.GetBytes((short)length).Reverse().ToArray();
                break;

            case 4: lengthBytes = BitConverter.GetBytes(length).Reverse().ToArray();
                break;
            }
            dw.Write(lengthBytes);
        }
コード例 #22
0
ファイル: LengthWriter.cs プロジェクト: waynemunro/Evil-DICOM
 public static void WriteBigEndian(DICOMBinaryWriter dw, int length, int numberOfBytes)
 {
     var lengthBytes = new byte[0];
     switch (numberOfBytes)
     {
         case 2:
             lengthBytes = BitConverter.GetBytes((ushort) length).Reverse().ToArray();
             break;
         case 4:
             lengthBytes = BitConverter.GetBytes(length).Reverse().ToArray();
             break;
     }
     dw.Write(lengthBytes);
 }
コード例 #23
0
ファイル: Accept.cs プロジェクト: DMIAOCHEN/Evil-DICOM
        private byte[] WriteBody()
        {
            var body = new byte[0];
            var stream = new MemoryStream();
            using (var dw = new DICOMBinaryWriter(stream))
            {
                //Main body
                LengthWriter.WriteBigEndian(dw, ProtocolVersion, 2); //Protocol Version
                dw.WriteNullBytes(2); //Reserved Null bytes
                dw.Write(CalledEntityTitle.PadRight(16));
                dw.Write(CallingEntityTitle.PadRight(16));
                dw.WriteNullBytes(32); //Reserved Null bytes
                ItemWriter.WriteApplicationContext(dw, ApplicationContext);
                foreach (PresentationContext pc in PresentationContexts)
                {
                    ItemWriter.WritePresentationCtxAcceptType(dw, pc);
                }
                ItemWriter.WriteUserInfo(dw, UserInfo);
                body = stream.ToArray();
            }

            return body;
        }
コード例 #24
0
 public static void WriteBigEndian(DICOMBinaryWriter dw, int length, int numberOfBytes)
 {
     byte[] lengthBytes=null;
     switch (numberOfBytes)
     {
         case 2:
             lengthBytes = BitConverter.GetBytes((ushort) length);
             break;
         case 4:
             lengthBytes = BitConverter.GetBytes(length);
             break;
     }
     Array.Reverse(lengthBytes);
     dw.Write(lengthBytes);
 }
コード例 #25
0
ファイル: LengthWriter.cs プロジェクト: zoulianmp/Evil-DICOM
        public static void WriteLittleEndian(DICOMBinaryWriter dw, int length, int numberOfBytes)
        {
            var lengthBytes = new byte[0];

            switch (numberOfBytes)
            {
            case 2:
                lengthBytes = BitConverter.GetBytes((short)length);
                break;

            case 4:
                lengthBytes = BitConverter.GetBytes(length);
                break;
            }
            dw.Write(lengthBytes);
        }
コード例 #26
0
 public static void WriteLittleEndian(DICOMBinaryWriter dw, DICOMWriteSettings settings, IDICOMElement toWrite)
 {
     var s = toWrite as Sequence;
     DICOMTagWriter.WriteLittleEndian(dw, toWrite.Tag);
     VRWriter.WriteVR(dw, settings, VR.Sequence);
     if (settings.DoWriteIndefiniteSequences)
     {
         WriteIndefiniteLength(settings, dw);
         SequenceItemWriter.WriteItemsLittleEndian(dw, settings, s.Items);
         WriteEndOfSequenceLittleEndian(dw);
     }
     else
     {
         byte[] itemsBytes = SequenceItemWriter.WriteItemsLittleEndian(settings, s.Items);
         LengthWriter.Write(dw, VR.Sequence, settings, itemsBytes.Length);
         dw.Write(itemsBytes);
     }
 }
コード例 #27
0
ファイル: SequenceWriter.cs プロジェクト: milhcbt/Evil-DICOM
        public static void WriteLittleEndian(DICOMBinaryWriter dw, DICOMWriteSettings settings, IDICOMElement toWrite)
        {
            Sequence s = toWrite as Sequence;

            DICOMTagWriter.WriteLittleEndian(dw, toWrite.Tag);
            VRWriter.WriteVR(dw, settings, VR.Sequence);
            if (settings.DoWriteIndefiniteSequences)
            {
                WriteIndefiniteLength(settings, dw);
                SequenceItemWriter.WriteItemsLittleEndian(dw, settings, s.Items);
                WriteEndOfSequenceLittleEndian(dw);
            }
            else
            {
                byte[] itemsBytes = SequenceItemWriter.WriteItemsLittleEndian(settings, s.Items);
                LengthWriter.Write(dw, VR.Sequence, settings, itemsBytes.Length);
                dw.Write(itemsBytes);
            }
        }
コード例 #28
0
 public static void WriteItemLittleEndian(DICOMBinaryWriter dw, DICOMWriteSettings settings, DICOMObject d)
 {
     DICOMTagWriter.WriteLittleEndian(dw, TagHelper.SEQUENCE_ITEM);
     using (var stream = new MemoryStream())
     {
         using (var itemDw = new DICOMBinaryWriter(stream))
         {
             DICOMObjectWriter.Write(itemDw, settings, d);
             if (!settings.DoWriteIndefiniteSequences)
             {
                 LengthWriter.Write(dw, VR.Null, settings, (int) stream.Length);
                 dw.Write(stream.ToArray());
             }
             else
             {
                 WriteIndefiniteLittleEndian(dw, stream.ToArray());
             }
         }
     }
 }
コード例 #29
0
 public static void WriteItemLittleEndian(DICOMBinaryWriter dw, DICOMWriteSettings settings, DICOMObject d)
 {
     DICOMTagWriter.WriteLittleEndian(dw, TagHelper.Item);
     using (var stream = new MemoryStream())
     {
         using (var itemDw = new DICOMBinaryWriter(stream))
         {
             DICOMObjectWriter.Write(itemDw, settings, d, true);
             if (!settings.DoWriteIndefiniteSequences)
             {
                 LengthWriter.Write(dw, VR.Null, settings, (int)stream.Length);
                 dw.Write(stream.ToArray());
             }
             else
             {
                 WriteIndefiniteLittleEndian(dw, stream.ToArray());
             }
         }
     }
 }
コード例 #30
0
ファイル: SequenceWriter.cs プロジェクト: milhcbt/Evil-DICOM
 private static void WriteEndOfSequenceBigEndian(DICOMBinaryWriter dw)
 {
     dw.Write(_endOfSequence_BE);
 }
コード例 #31
0
ファイル: SequenceWriter.cs プロジェクト: milhcbt/Evil-DICOM
 private static void WriteEndOfSequenceLittleEndian(DICOMBinaryWriter dw)
 {
     dw.Write(_endOfSequence_LE);
 }
コード例 #32
0
 private static void WriteIndefiniteLittleEndian(DICOMBinaryWriter dw, byte[] itemBytes)
 {
     dw.Write(new byte[] { 0xFF, 0xFF, 0xFF, 0xFF });
     dw.Write(itemBytes);
     dw.Write(_endOfSequenceItem_LE);
 }
コード例 #33
0
 public static void WriteItemsLittleEndian(DICOMBinaryWriter dw, DICOMWriteSettings settings,
                                           List <DICOMObject> items)
 {
     dw.Write(WriteItemsLittleEndian(settings, items));
 }
コード例 #34
0
 private static void WriteIndefiniteLittleEndian(DICOMBinaryWriter dw, byte[] itemBytes)
 {
     dw.Write(new byte[] {0xFF, 0xFF, 0xFF, 0xFF});
     dw.Write(itemBytes);
     dw.Write(_endOfSequenceItem_LE);
 }
コード例 #35
0
 private static void WriteEndOfSequenceBigEndian(DICOMBinaryWriter dw)
 {
     dw.Write(_endOfSequence_BE);
 }
コード例 #36
0
 public static void WriteLittleEndian(DICOMBinaryWriter dw, Tag tag)
 {
     byte[] tagBytes = WriteLittleEndian(tag);
     dw.Write(tagBytes);
 }
コード例 #37
0
 public static void WriteLittleEndian(DICOMBinaryWriter dw, VR vr, DICOMWriteSettings settings, IDICOMElement toWrite)
 {
     byte[] data = DataComposer.GetDataLittleEndian(toWrite);
     LengthWriter.WriteLittleEndian(dw, vr, settings, data != null ? data.Length : 0);
     dw.Write(data != null ? data : new byte[0]);
 }
コード例 #38
0
ファイル: ItemWriter.cs プロジェクト: DMIAOCHEN/Evil-DICOM
 public static void WritePresentationCtxAcceptType(DICOMBinaryWriter dw, PresentationContext pc)
 {
     dw.Write((byte) ItemType.PRESENTATION_CONTEXT_ACCEPT);
     dw.WriteNullBytes(1); //Reserved Null Byte
     byte[] internBytes; //Will use to get length
     using (var stream = new MemoryStream())
     {
         using (var intern = new DICOMBinaryWriter(stream))
         {
             intern.Write((byte) pc.Id);
             intern.WriteNullBytes(1);
             intern.Write((byte) pc.Reason);
             intern.WriteNullBytes(1);
             WriteTransferSyntax(intern, pc.TransferSyntaxes.First());
             internBytes = stream.ToArray();
         }
     }
     LengthWriter.WriteBigEndian(dw, internBytes.Length, 2);
     dw.Write(internBytes);
 }
コード例 #39
0
 public static void WriteBigEndian(DICOMBinaryWriter dw, Tag tag)
 {
     byte[] tagBytes = WriteBigEndian(tag);
     dw.Write(tagBytes);
 }
コード例 #40
0
 public static void WriteItemsLittleEndian(DICOMBinaryWriter dw, DICOMWriteSettings settings,
     List<DICOMObject> items)
 {
     dw.Write(WriteItemsLittleEndian(settings, items));
 }
コード例 #41
0
ファイル: DICOMTagWriter.cs プロジェクト: zzti/Evil-DICOM
        public static void WriteLittleEndian(DICOMBinaryWriter dw, Tag tag)
        {
            var tagBytes = WriteLittleEndian(tag);

            dw.Write(tagBytes);
        }
コード例 #42
0
 private static void WriteEndOfSequenceLittleEndian(DICOMBinaryWriter dw)
 {
     dw.Write(_endOfSequence_LE);
 }
コード例 #43
0
 public static void Write(DICOMBinaryWriter dw)
 {
     dw.WriteNullBytes(128);
     dw.Write("DICM");
 }
コード例 #44
0
ファイル: ItemWriter.cs プロジェクト: DMIAOCHEN/Evil-DICOM
 public static void WritePDVFragment(DICOMBinaryWriter dw, PDVItemFragment frag)
 {
     WritePDVFragmentMessageHeader(dw, frag);
     dw.Write(frag.Data);
 }
コード例 #45
0
 public static void Write(DICOMBinaryWriter dw)
 {
     dw.WriteNullBytes(128);
     dw.Write("DICM");
 }
コード例 #46
0
ファイル: ItemWriter.cs プロジェクト: DMIAOCHEN/Evil-DICOM
 public static void WriteUserInfo(DICOMBinaryWriter dw, UserInfo info)
 {
     dw.Write((byte) ItemType.USER_INFO);
     dw.WriteNullBytes(1); // Reserved Null Byte
     var body = new byte[0];
     using (var stream = new MemoryStream()) //Will write inner object to get length
     {
         using (var wr = new DICOMBinaryWriter(stream))
         {
             WriteMaxLength(wr, info.MaxPDULength);
             WriteImplementationClassUID(wr, info.ImplementationUID);
             WriteAsyncOperations(wr, info.AsynchronousOperations);
             WriteImplementationVersion(wr, info.ImplementationVersion);
             body = stream.ToArray();
         }
     }
     LengthWriter.WriteBigEndian(dw, body.Length, 2);
     dw.Write(body);
 }
コード例 #47
0
ファイル: ItemWriter.cs プロジェクト: DMIAOCHEN/Evil-DICOM
 private static void WritePDVFragmentMessageHeader(DICOMBinaryWriter dw, PDVItemFragment frag)
 {
     var bits = new BitArray(8);
     bits.Set(0, frag.IsCommandObject);
     bits.Set(1, frag.IsLastItem);
     var bytes = new byte[1];
     bits.CopyTo(bytes, 0);
     dw.Write(bytes[0]);
 }