I have an XML file which result from the export of a database (Oracle 11g Unicode) table. This table has a BLOB field which represent a file. The file could be a very large one.
So in the case where I have a very large file a get in the XML a very large string representation of that file.
I have to get the bytes of this string in order to insert the file in another database instance.
A this point the XML is charged and i have then a string representing the file.
What I've done is this:
Encoding.Unicode.GetBytes(stringFileRepresentation);
But I'm getting an OutOfMemoryException
.
If I do this:
Encoding.Unicode.GetBytes(stringFileRepresentation.ToCharArray());
I get also an OutOfMemoryException
.
I tried too to do this before decoding the string:
var chars = stringFileRepresentation.ToCharArray();
Encoding.Unicode.GetBytes(chars);
And I getting the OutOfMemoryException
when calling ToCharArray()
.
So I guess is a problem when processing the string.
Then I'm trying the following method that I found here event if I'm not sure I have to conservate the encoding of the string:
byte[] bytes = new byte[str.Length * sizeof(char)];
Buffer.BlockCopy(str.ToCharArray(), 0, bytes, 0, bytes.Length);
But I'm getting also an OutOfMemoryException
in instantiating the bytes
variable.
Now, I ran OutOfOptions
and I don't know what to do.