PrepAway - Latest Free Exam Questions & Answers

Which code segment should you use?

You are writing a method to compress an array of bytes. The bytes to be compressed are passed to the method in a parameter named document. You need to compress the contents of the incoming parameter.
Which code segment should you use?

PrepAway - Latest Free Exam Questions & Answers

A.
MemoryStream inStream = new MemoryStream(document);
GZipStream zipStream = new GZipStream(inStream, CompressionMode.Compress);
byte[] result = new byte[document.Length];
zipStream.Write(result, 0, result.Length);
return result;

B.
MemoryStream stream = new MemoryStream(document);
GZipStream zipStream = new GZipStream(stream, CompressionMode.Compress);
zipStream.Write(document, 0, document.Length);
zipStream.Close();
return stream.ToArray();

C.
MemoryStream outStream = new MemoryStream();
GZipStream zipStream = new GZipStream(outStream, CompressionMode.Compress);
zipStream.Write(document, 0, document.Length);
zipStream.Close();
return outStream.ToArray();

D.
MemoryStream inStream = new MemoryStream(document);
GZipStream zipStream = new GZipStream(inStream, CompressionMode.Compress);
MemoryStream outStream = new MemoryStream();
int b;
while ((b = zipStream.ReadByte()) != -1) {
outStream.WriteByte((byte)b);
}
return outStream.ToArray();


Leave a Reply