#region Copyright
//+ Copyright © Jampad Technology, Inc. 2007-2008
//++ Lead Architect: David Betz [MVP]
#endregion
using System;
using System.IO;
//+
namespace Themelia.IO
{
public static class StreamConverter
{
//- @CreateStream -//
///
/// Creates the stream.
///
///
/// The text.
///
public static T CreateStream(String text) where T : Stream, new()
{
T stream = new T();
BinaryWriter writer = new BinaryWriter(stream);
writer.Write(text);
//+
return stream;
}
///
/// Creates the stream.
///
///
/// The data.
///
public static T CreateStream(Byte[] data) where T : Stream, new()
{
T stream = new T();
BinaryWriter writer = new BinaryWriter(stream);
writer.Write(data);
//+
return stream;
}
//- @GetStreamByteArray -//
///
/// Gets the stream byte array.
///
/// The stream.
///
public static Byte[] GetStreamByteArray(Stream stream)
{
if (stream != null)
{
BinaryReader r = new BinaryReader(stream);
//+
return r.ReadBytes((Int32)stream.Length);
}
//+
return null;
}
//- @GetStreamText -//
///
/// Gets the stream text.
///
/// The stream.
///
public static String GetStreamText(Stream stream)
{
if (stream != null)
{
StreamReader reader = new StreamReader(stream);
//+
return reader.ReadToEnd();
}
//+
return String.Empty;
}
}
}