本文整理汇总了C#中System.IO.MemoryStream.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# MemoryStream.ToString方法的具体用法?C# MemoryStream.ToString怎么用?C# MemoryStream.ToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.IO.MemoryStream
的用法示例。
在下文中一共展示了MemoryStream.ToString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: EncryptString
public static String EncryptString(String in_string)
{
String return_value;
using (TripleDESCryptoServiceProvider tdsAlg = new TripleDESCryptoServiceProvider())
{
tdsAlg.GenerateKey();
tdsAlg.GenerateIV();
// Create a decrytor to perform the stream transform.
ICryptoTransform encryptor = tdsAlg.CreateEncryptor(tdsAlg.Key, tdsAlg.IV);
// Create the streams used for encryption.
using (MemoryStream msEncrypt = new MemoryStream())
{
using (CryptoStream csEncrypt = new CryptoStream(msEncrypt, encryptor, CryptoStreamMode.Write))
{
using (StreamWriter swEncrypt = new StreamWriter(csEncrypt))
{
//Write all data to the stream.
swEncrypt.Write(in_string);
}
return_value = msEncrypt.ToString();
}
}
}
return return_value;
}
示例2: Image2Stream
public Image2Stream()
{
// Stream -> IplImage
using (FileStream stream = new FileStream(Const.ImageLenna, FileMode.Open))
using (IplImage img = IplImage.FromStream(stream, LoadMode.Color))
{
CvWindow.ShowImages(img);
// IplImage -> Stream
using (MemoryStream ms = new MemoryStream())
{
img.ToStream(ms, ".tiff");
ms.ToString();
}
}
// Stream -> CvMat
using (FileStream stream = new FileStream(Const.ImageLenna, FileMode.Open))
using (CvMat mat = CvMat.FromStream(stream, LoadMode.Color))
{
mat.ToString();
// CvMat -> Stream
using (MemoryStream ms = new MemoryStream())
{
mat.ToStream(ms, ".bmp");
ms.ToString();
}
}
}
示例3: ImageToByte
public byte ImageToByte(BitmapImage imageSource)
{
using (MemoryStream ms = new MemoryStream())
{
imageSource.StreamSource.CopyTo(ms); //todo doesnt work so
return Convert.ToByte(ms.ToString());
}
}
示例4: SendMsgPB
public int SendMsgPB(int nMsgID, int nSockIndex, NFMsg.MsgBase xData)
{
MemoryStream body = new MemoryStream();
Serializer.Serialize<NFMsg.MsgBase>(body, xData);
SendMsg(nMsgID, nSockIndex, body.ToString());
return 0;
}
示例5: Convert
public string Convert(DataTable dataTable)
{
_dataTable = dataTable;
using (var memoryStream = new MemoryStream())
{
_writer = new StreamWriter(memoryStream);
WriteColumnNames();
WriteRows();
_writer.Close();
return memoryStream.ToString();
}
}
示例6: RunScript
public static string RunScript(CMSDataContext db, string script)
{
var engine = Python.CreateEngine();
var ms = new MemoryStream();
var sw = new StreamWriter(ms);
engine.Runtime.IO.SetOutput(ms, sw);
engine.Runtime.IO.SetErrorOutput(ms, sw);
var sc = engine.CreateScriptSourceFromString(script);
var code = sc.Compile();
var scope = engine.CreateScope();
var pe = new PythonEvents(db);
scope.SetVariable("model", pe);
code.Execute(scope);
return ms.ToString();
}
示例7: SerializeToString
/// <summary>Serializes an <c>XMPMeta</c>-object as RDF into a string.</summary>
/// <remarks>
/// <em>Note:</em> Encoding is forced to UTF-16 when serializing to a
/// string to ensure the correctness of "exact packet size".
/// </remarks>
/// <param name="xmp">a metadata implementation object</param>
/// <param name="options">Options to control the serialization (see <see cref="SerializeOptions"/>).</param>
/// <returns>Returns a string containing the serialized RDF.</returns>
/// <exception cref="XmpException">on serialization errors.</exception>
public static string SerializeToString(XmpMeta xmp, SerializeOptions options)
{
// forces the encoding to be UTF-16 to get the correct string length
options = options ?? new SerializeOptions();
options.EncodeUtf16Be = true;
var output = new MemoryStream(2048);
Serialize(xmp, output, options);
try
{
return options.GetEncoding().GetString(output.GetBuffer(), 0, (int)output.Length);
}
catch
{
// Should not happen as UTF-8/16LE/BE are all available
return output.ToString();
}
}
示例8: SignRequest
private string SignRequest (System.Net.HttpWebRequest request, byte[] body)
{
Uri u = request.RequestUri;
string pathAndQuery = request.RequestUri.PathAndQuery;
byte[] pathAndQueryBytes = Config.Encoding.GetBytes(pathAndQuery);
using (MemoryStream buffer = new MemoryStream())
{
buffer.Write(pathAndQueryBytes, 0, pathAndQueryBytes.Length);
buffer.WriteByte((byte)'\n');
if (body.Length > 0)
{
buffer.Write(body, 0, body.Length);
}
string digestBase64 = GetSHA1Key(mac.SecretKey, buffer.ToString());
return mac.AccessKey + ":" + digestBase64;
}
}
示例9: ToString
/**
* Returns the string representation of this record.
*/
public override String ToString()
{
String nl = Environment.NewLine;
String extraData;
using (MemoryStream b = new MemoryStream())
{
try
{
HexDump.Dump(this.remainingData, 0, b, 0);
extraData = b.ToString();
}
catch (Exception)
{
extraData = "error\n";
}
return GetType().Name + ":" + nl +
" RecordId: 0x" + HexDump.ToHex(RECORD_ID) + nl +
" Options: 0x" + HexDump.ToHex(Options) + nl;
//" Extra Data:" + nl +
//extraData;
}
}
示例10: DebugStoreIM
private void DebugStoreIM(GridInstantMessage im)
{
MemoryStream buffer = new MemoryStream();
Type type = typeof(GridInstantMessage);
XmlWriterSettings settings = new XmlWriterSettings();
settings.Encoding = Encoding.UTF8;
using (XmlWriter writer = XmlWriter.Create(buffer, settings))
{
XmlSerializer serializer = new XmlSerializer(type);
serializer.Serialize(writer, im);
writer.Flush();
}
string debug = buffer.ToString();
m_DummyOffline = buffer;
}
示例11: GetSettings
/// <summary>
/// Gets the client settings as an XML string.
/// </summary>
/// <param name="includeMediaData">If True, Media settings are included, if any settings exist.</param>
/// <returns>Returns client settings, as XML string.</returns>
public string GetSettings(bool includeMediaData)
{
string originalMediaSettings = null, originalMediaType = null;
if (!includeMediaData)
{
originalMediaSettings = this.m_MediaSettings;
originalMediaType = this.m_MediaType;
this.m_MediaType = this.m_MediaSettings = null;
}
try
{
XmlWriterSettings settings = new XmlWriterSettings();
settings.Indent = true;
settings.Encoding = System.Text.Encoding.UTF8;
settings.CloseOutput = true;
settings.CheckCharacters = false;
string data;
using (MemoryStream memoryStream = new MemoryStream())
{
using (StreamReader reader = new StreamReader(memoryStream))
{
DataContractSerializer x = new DataContractSerializer(this.GetType());
x.WriteObject(memoryStream, this);
memoryStream.Position = 0;
data = memoryStream.ToString();
data = UTF8Encoding.UTF8.GetString(memoryStream.ToArray());
}
}
return data;
}
finally
{
if (!includeMediaData)
{
this.m_MediaType = originalMediaType;
this.m_MediaSettings = originalMediaSettings;
}
}
}
示例12: TestIndexAndMerge
public virtual void TestIndexAndMerge()
{
MemoryStream sw = new MemoryStream();
StreamWriter @out = new StreamWriter(sw);
Directory directory = NewFSDirectory(IndexDir, null);
MockDirectoryWrapper wrapper = directory as MockDirectoryWrapper;
if (wrapper != null)
{
// We create unreferenced files (we don't even write
// a segments file):
wrapper.AssertNoUnrefencedFilesOnClose = false;
}
IndexWriter writer = new IndexWriter(directory, NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random())).SetOpenMode(OpenMode_e.CREATE).SetMaxBufferedDocs(-1).SetMergePolicy(NewLogMergePolicy(10)));
SegmentCommitInfo si1 = IndexDoc(writer, "test.txt");
PrintSegment(@out, si1);
SegmentCommitInfo si2 = IndexDoc(writer, "test2.txt");
PrintSegment(@out, si2);
writer.Dispose();
SegmentCommitInfo siMerge = Merge(directory, si1, si2, "_merge", false);
PrintSegment(@out, siMerge);
SegmentCommitInfo siMerge2 = Merge(directory, si1, si2, "_merge2", false);
PrintSegment(@out, siMerge2);
SegmentCommitInfo siMerge3 = Merge(directory, siMerge, siMerge2, "_merge3", false);
PrintSegment(@out, siMerge3);
directory.Dispose();
@out.Dispose();
sw.Dispose();
string multiFileOutput = sw.ToString();
//System.out.println(multiFileOutput);
sw = new MemoryStream();
@out = new StreamWriter(sw);
directory = NewFSDirectory(IndexDir, null);
wrapper = directory as MockDirectoryWrapper;
if (wrapper != null)
{
// We create unreferenced files (we don't even write
// a segments file):
wrapper.AssertNoUnrefencedFilesOnClose = false;
}
writer = new IndexWriter(directory, NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random())).SetOpenMode(OpenMode_e.CREATE).SetMaxBufferedDocs(-1).SetMergePolicy(NewLogMergePolicy(10)));
si1 = IndexDoc(writer, "test.txt");
PrintSegment(@out, si1);
si2 = IndexDoc(writer, "test2.txt");
PrintSegment(@out, si2);
writer.Dispose();
siMerge = Merge(directory, si1, si2, "_merge", true);
PrintSegment(@out, siMerge);
siMerge2 = Merge(directory, si1, si2, "_merge2", true);
PrintSegment(@out, siMerge2);
siMerge3 = Merge(directory, siMerge, siMerge2, "_merge3", true);
PrintSegment(@out, siMerge3);
directory.Dispose();
@out.Dispose();
sw.Dispose();
string singleFileOutput = sw.ToString();
Assert.AreEqual(multiFileOutput, singleFileOutput);
}
示例13: ToString
/// <summary>
/// Returns a <see cref="T:System.String"/> that represents the current <see cref="T:System.Object"/>.
/// </summary>
/// <returns>
/// A <see cref="T:System.String"/> that represents the current <see cref="T:System.Object"/>.
/// </returns>
public override String ToString()
{
String dataStr;
using (MemoryStream b = new MemoryStream())
{
try
{
HexDump.Dump(this._complexData, 0, b, 0);
dataStr = b.ToString();
}
catch (Exception e)
{
dataStr = e.ToString();
}
}
return "propNum: " + PropertyNumber
+ ", propName: " + EscherProperties.GetPropertyName(PropertyNumber)
+ ", complex: " + IsComplex
+ ", blipId: " + IsBlipId
+ ", data: " + Environment.NewLine + dataStr;
}
示例14: ToString
/// <summary>
/// Returns a <see cref="T:System.String"/> that represents the current <see cref="T:System.Object"/>.
/// </summary>
/// <returns>
/// A <see cref="T:System.String"/> that represents the current <see cref="T:System.Object"/>.
/// </returns>
public override String ToString()
{
String nl = Environment.NewLine;
String extraData;
using (MemoryStream b = new MemoryStream())
{
try
{
HexDump.Dump(this.field_pictureData, 0, b, 0);
extraData = b.ToString();
}
catch (Exception e)
{
extraData = e.ToString();
}
return GetType().Name + ":" + nl +
" RecordId: 0x" + HexDump.ToHex(RecordId) + nl +
" Version: 0x" + HexDump.ToHex(Version) + '\n' +
" Instance: 0x" + HexDump.ToHex(Instance) + '\n' +
" UID: 0x" + HexDump.ToHex(field_1_UID) + nl +
(field_2_UID == null ? "" : (" UID2: 0x" + HexDump.ToHex(field_2_UID) + nl)) +
" Uncompressed Size: " + HexDump.ToHex(field_2_cb) + nl +
" Bounds: " + Bounds + nl +
" Size in EMU: " + SizeEMU + nl +
" Compressed Size: " + HexDump.ToHex(field_5_cbSave) + nl +
" Compression: " + HexDump.ToHex(field_6_fCompression) + nl +
" Filter: " + HexDump.ToHex(field_7_fFilter) + nl +
" Extra Data:" + nl + extraData +
(remainingData == null ? null : ("\n" +
" Remaining Data: " + HexDump.ToHex(remainingData, 32)));
}
}
示例15: ToString
/// <summary>
/// Returns a <see cref="T:System.String"/> that represents the current <see cref="T:System.Object"/>.
/// </summary>
/// <returns>
/// A <see cref="T:System.String"/> that represents the current <see cref="T:System.Object"/>.
/// </returns>
public override String ToString()
{
String nl = Environment.NewLine;
String extraData;
using (MemoryStream b = new MemoryStream())
{
try
{
HexDump.Dump(this._remainingData, 0, b, 0);
extraData = b.ToString();
}
catch (Exception e)
{
extraData = e.ToString();
}
return GetType().Name + ":" + nl +
" RecordId: 0x" + HexDump.ToHex(RECORD_ID) + nl +
" Options: 0x" + HexDump.ToHex(Options) + nl +
" BlipTypeWin32: " + field_1_blipTypeWin32 + nl +
" BlipTypeMacOS: " + field_2_blipTypeMacOS + nl +
" SUID: " + HexDump.ToHex(field_3_uid) + nl +
" Tag: " + field_4_tag + nl +
" Size: " + field_5_size + nl +
" Ref: " + field_6_ref + nl +
" Offset: " + field_7_offset + nl +
" Usage: " + field_8_usage + nl +
" Name: " + field_9_name + nl +
" Unused2: " + field_10_unused2 + nl +
" Unused3: " + field_11_unused3 + nl +
" blipRecord: " + (field_12_blipRecord == null ? "null" : field_12_blipRecord.ToString()) + nl;
//" Extra Data:" + nl + extraData;
}
}