Problem reading Byte array using DcmInputStream

All other questions regarding DCMTK

Moderator: Moderator Team

Post Reply
Message
Author
lalitsisodia
Posts: 2
Joined: Wed, 2007-09-26, 08:53

Problem reading Byte array using DcmInputStream

#1 Post by lalitsisodia »

Objective: To convert the array of bytes into dcmDataSet.
To achieve this I am using Read() method of dcmDataSet class. Below is the code snippet of what I am doing

//Converting dcmDataset to byte array(this code is working fine)
System::IntPtr pointerData = Marshal::AllocHGlobal(ds->getLength(EXS_LittleEndianImplicit, EET_UndefinedLength));
DcmOutputStream* output = new DcmOutputBufferStream(pointerData.ToPointer(), ds->getLength(EXS_LittleEndianImplicit, EET_UndefinedLength));
ds->transferInit();
cond = ds->write(*output , EXS_LittleEndianImplicit, EET_UndefinedLength, EGL_recalcGL);
ds->transferEnd();
if (cond.bad()) {
System::Diagnostics::Debug::WriteLine(gcnew String(cond.text()));
}
array<Byte>^ outputData = gcnew array<Byte>(ds->getLength(EXS_LittleEndianImplicit, EET_UndefinedLength));
Marshal::Copy(pointerData, outputData, 0, ds->getLength(EXS_LittleEndianImplicit, EET_UndefinedLength));

// The above code has been tested and is working perfectly.

//Converting byte array to dcmDataSet(The following code is not working)

DcmInputStream* dcmInputStream = new DcmInputBufferStream();
System::IntPtr pointerData = Marshal::AllocHGlobal(outputData->Length);
Marshal::Copy(outputData, 0, pointerData, outputData->Length);

((DcmInputBufferStream*)dcmInputStream)->setBuffer(pointerData.ToPointer(), outputData->Length);
DcmDataset *ds = new DcmDataset();
OFCondition cond = ds->read(*dcmInputStream, EXS_LittleEndianImplicit, EGL_noChange);
if (cond.bad()) {
System::Diagnostics::Debug::WriteLine(gcnew String(cond.text()));
}


I am getting cond.Bad() as “I/O suspension or premature end of stream”

Can anyone tell me what is wrong?

Marco Eichelberg
OFFIS DICOM Team
OFFIS DICOM Team
Posts: 1459
Joined: Tue, 2004-11-02, 17:22
Location: Oldenburg, Germany
Contact:

#2 Post by Marco Eichelberg »

After calling DcmInputBufferStream::setBuffer(), you need to tell the buffer stream object that the buffer contains all data - when used in network transfer mode, the buffer is filled with data coming over the network, then read and cleared, then filled again etc. In you case the content of the buffer is read by the parser and now the parser asks you to clean and re-fill the buffer. The solution is easy: call DcmInputBufferStream::setEos() afer the call to setBuffer() and the code should work.

lalitsisodia
Posts: 2
Joined: Wed, 2007-09-26, 08:53

#3 Post by lalitsisodia »

Thanks Marco...

The code is now working fine...

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest