本文整理汇总了C#中System.IO.FileStream.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# FileStream.ToString方法的具体用法?C# FileStream.ToString怎么用?C# FileStream.ToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.IO.FileStream
的用法示例。
在下文中一共展示了FileStream.ToString方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ToStringDefault
public void ToStringDefault()
{
using (FileStream fs = new FileStream(GetTestFilePath(), FileMode.Create))
{
Assert.Equal(typeof(FileStream).ToString(), fs.ToString());
}
}
示例2: propsFile
public static void propsFile(string FileName)
{
try
{
stream = new FileStream(FileName, FileMode.Open);
props.Load(stream);
Console.WriteLine(stream.ToString());
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
// Handle the exception.
}
finally
{
if (stream != null)
{
stream.Close();
}
}
Name = props.GetProperty("mod.name");
Version1_8 = props.GetProperty("mod.version1_8");
Version1_7 = props.GetProperty("mod.version1_7");
Jar = props.GetProperty("mod.jar");
URL1_8 = props.GetProperty("mod.url1_8");
URL1_7 = props.GetProperty("mod.url1_7");
}
示例3: Config
public Config(string currentWorkingDirectory)
{
configFile = "ContentconfigJSON.txt";
sampleXlsx = "Sample.json";
try
{
if (File.Exists(Path.Combine(currentWorkingDirectory, configFile)))
{
using (StreamReader reader = new StreamReader(Path.Combine(currentWorkingDirectory, configFile)))
{
this.config = JObject.Parse(reader.ReadToEnd());
}
}
else
{
using (FileStream fs = new FileStream(Path.Combine(currentWorkingDirectory, configFile), FileMode.OpenOrCreate, FileAccess.ReadWrite))
{
using (var sw = new StreamWriter(fs))
{
sw.WriteLine("{");
sw.WriteLine("\t\"files\": [");
sw.WriteLine("\t\t\"" + currentWorkingDirectory + sampleXlsx + "\"");
sw.WriteLine("\t]");
sw.WriteLine("}");
sw.Flush();
}
this.config = JObject.Parse(fs.ToString());
}
}
}
catch (IOException exception)
{
Console.WriteLine("Error - " + exception.ToString());
}
}
示例4: TestDefaultProperties
public void TestDefaultProperties ()
{
string path = TempFolder + Path.DirectorySeparatorChar + "testfilestream.tmp.2";
DeleteFile (path);
FileStream stream = new FileStream (path, FileMode.Create);
AssertEquals ("test#01", true, stream.CanRead);
AssertEquals ("test#02", true, stream.CanSeek);
AssertEquals ("test#03", true, stream.CanWrite);
AssertEquals ("test#04", false, stream.IsAsync);
AssertEquals ("test#05", true, stream.Name.EndsWith (path));
AssertEquals ("test#06", 0, stream.Position);
AssertEquals ("test#07", "System.IO.FileStream", stream.ToString());
stream.Close ();
DeleteFile (path);
stream = new FileStream (path, FileMode.OpenOrCreate, FileAccess.Read);
AssertEquals ("test#08", true, stream.CanRead);
AssertEquals ("test#09", true, stream.CanSeek);
AssertEquals ("test#10", false, stream.CanWrite);
AssertEquals ("test#11", false, stream.IsAsync);
AssertEquals ("test#12", true, stream.Name.EndsWith (path));
AssertEquals ("test#13", 0, stream.Position);
AssertEquals ("test#14", "System.IO.FileStream", stream.ToString());
stream.Close ();
stream = new FileStream (path, FileMode.Truncate, FileAccess.Write, FileShare.ReadWrite);
AssertEquals ("test#15", false, stream.CanRead);
AssertEquals ("test#16", true, stream.CanSeek);
AssertEquals ("test#17", true, stream.CanWrite);
AssertEquals ("test#18", false, stream.IsAsync);
AssertEquals ("test#19", true, stream.Name.EndsWith ("testfilestream.tmp.2"));
AssertEquals ("test#20", 0, stream.Position);
AssertEquals ("test#21", "System.IO.FileStream", stream.ToString());
stream.Close ();
DeleteFile (path);
}
示例5: Map
/// <summary>
/// Maps a file into a set of buffers </summary>
internal virtual ByteBuffer[] Map(MMapIndexInput input, FileStream fc, long offset, long length)
{
if (Number.URShift(length, ChunkSizePower) >= int.MaxValue)
throw new ArgumentException("RandomAccessFile too big for chunk size: " + fc.ToString());
long chunkSize = 1L << ChunkSizePower;
// we always allocate one more buffer, the last one may be a 0 byte one
int nrBuffers = (int)((long)((ulong)length >> ChunkSizePower)) + 1;
ByteBuffer[] buffers = new ByteBuffer[nrBuffers];
/*
public static MemoryMappedFile CreateFromFile(FileStream fileStream, String mapName, Int64 capacity,
MemoryMappedFileAccess access, MemoryMappedFileSecurity memoryMappedFileSecurity,
HandleInheritability inheritability, bool leaveOpen)
*/
if (input.memoryMappedFile == null)
{
input.memoryMappedFile = MemoryMappedFile.CreateFromFile(fc, null, length == 0 ? 100 : length, MemoryMappedFileAccess.Read, null, HandleInheritability.Inheritable, false);
}
long bufferStart = 0L;
for (int bufNr = 0; bufNr < nrBuffers; bufNr++)
{
int bufSize = (int)((length > (bufferStart + chunkSize)) ? chunkSize : (length - bufferStart));
//LUCENE TO-DO
buffers[bufNr] = new MemoryMappedFileByteBuffer(input.memoryMappedFile.CreateViewAccessor(offset + bufferStart, bufSize, MemoryMappedFileAccess.Read), -1, 0, bufSize, bufSize);
//buffers[bufNr] = fc.Map(FileStream.MapMode.READ_ONLY, offset + bufferStart, bufSize);
bufferStart += bufSize;
}
return buffers;
}
示例6: Open
private void Open(Random random)
{
lock (this)
{
Stream @is;
bool needSkip = true, failed = false;
long size = 0L, seekTo = 0L;
try
{
@is = new FileStream(Path, FileMode.Open, FileAccess.Read, FileShare.Read);
//@is = File.OpenRead(Path);
}
catch (Exception FSfail)
{
failed = true;
// if its not in classpath, we load it as absolute filesystem path (e.g. Hudson's home dir)
FileInfo file = new FileInfo(Path);
size = file.Length;
if (Path.EndsWith(".gz"))
{
// if it is a gzip file, we need to use InputStream and slowly skipTo:
@is = new FileStream(file.FullName, FileMode.Append, FileAccess.Write, FileShare.Read);
}
else
{
// optimized seek using RandomAccessFile:
seekTo = RandomSeekPos(random, size);
FileStream channel = new FileStream(Path, FileMode.Open);
if (LuceneTestCase.VERBOSE)
{
Console.WriteLine("TEST: LineFileDocs: file seek to fp=" + seekTo + " on open");
}
channel.Position = seekTo;
@is = new FileStream(channel.ToString(), FileMode.Append, FileAccess.Write, FileShare.Read);
needSkip = false;
}
}
if (!failed)
{
// if the file comes from Classpath:
size = @is.Length;// available();
}
if (Path.EndsWith(".gz"))
{
using (var gzs = new GZipStream(@is, CompressionMode.Decompress))
{
var temp = new MemoryStream();
gzs.CopyTo(temp);
// Free up the previous stream
@is.Close();
// Use the decompressed stream now
@is = temp;
}
// guestimate:
size = (long)(size * 2.8);
}
// If we only have an InputStream, we need to seek now,
// but this seek is a scan, so very inefficient!!!
if (needSkip)
{
seekTo = RandomSeekPos(random, size);
if (LuceneTestCase.VERBOSE)
{
Console.WriteLine("TEST: LineFileDocs: stream skip to fp=" + seekTo + " on open");
}
@is.Position = seekTo;
}
// if we seeked somewhere, read until newline char
if (seekTo > 0L)
{
int b;
byte[] bytes = new byte[sizeof(int)];
do
{
@is.Read(bytes, 0, sizeof(int));
b = BitConverter.ToInt32(bytes, 0);
} while (b >= 0 && b != 13 && b != 10);
}
//CharsetDecoder decoder = StandardCharsets.UTF_8.newDecoder().onMalformedInput(CodingErrorAction.REPORT).onUnmappableCharacter(CodingErrorAction.REPORT);
MemoryStream ms = new MemoryStream();
@is.CopyTo(ms);
Reader = new StringReader(Encoding.UTF8.GetString(ms.ToArray()));//, BUFFER_SIZE);
if (seekTo > 0L)
{
// read one more line, to make sure we are not inside a Windows linebreak (\r\n):
Reader.ReadLine();
}
@is.Close();
}
}
示例7: Map
/// <summary>
/// Maps a file into a set of buffers </summary>
internal virtual ByteBuffer[] Map(MMapIndexInput input, FileStream fc, long offset, long length)
{
if (Number.URShift(length, ChunkSizePower) >= int.MaxValue)
throw new ArgumentException("RandomAccessFile too big for chunk size: " + fc.ToString());
long chunkSize = 1L << ChunkSizePower;
// we always allocate one more buffer, the last one may be a 0 byte one
int nrBuffers = (int)((long)((ulong)length >> ChunkSizePower)) + 1;
ByteBuffer[] buffers = new ByteBuffer[nrBuffers];
/*
public static MemoryMappedFile CreateFromFile(FileStream fileStream, String mapName, Int64 capacity,
MemoryMappedFileAccess access, MemoryMappedFileSecurity memoryMappedFileSecurity,
HandleInheritability inheritability, bool leaveOpen)
*/
long fileCapacity = length == 0 ? ushort.MaxValue : length;
if (input.memoryMappedFile == null)
{
input.memoryMappedFile = MemoryMappedFile.CreateFromFile(fc, null, fileCapacity, MemoryMappedFileAccess.ReadWrite, null, HandleInheritability.Inheritable, false);
}
long bufferStart = 0L;
for (int bufNr = 0; bufNr < nrBuffers; bufNr++)
{
int bufSize = (int)((length > (bufferStart + chunkSize)) ? chunkSize : (length - bufferStart));
// LUCENENET: We get a file access exception if we create a 0 byte file at the end of the range.
// We can fix this by moving back 1 byte if the bufSize is 0.
int adjust = 0;
if (bufSize == 0 && bufNr == (nrBuffers - 1) && (offset + bufferStart) > 0)
{
adjust = 1;
}
buffers[bufNr] = new MemoryMappedFileByteBuffer(input.memoryMappedFile.CreateViewAccessor((offset + bufferStart) - adjust, bufSize, MemoryMappedFileAccess.Read), -1, 0, bufSize, bufSize);
bufferStart += bufSize;
}
return buffers;
}
示例8: StringSplitter
static void StringSplitter(FileStream Subjects, FileStream Predicates, FileStream Objects, FileStream Adverbs, FileStream SentenceStructure)
{
string[] ListOfSubjects = new String[1000];
string[] ListOfPredicates = new String[1000];
string[] ListOfObjects = new String[1000];
string[] ListOfAdverbs = new String[1000];
string[] ListOfSentenceStructures = new String[1000];
char[] LineDelimiter = new char[] { '*' };
char[] IdentifierDelimiter = new Char[] { '+' };
String SubjectsContent;
String PredicatesContent;
String ObjectsContent;
String AdverbsContent;
String SentenceStructureContent;
AdverbsContent = Adverbs.ToString();
string[] AdverbsContentFirstProcessingStage;
AdverbsContentFirstProcessingStage = AdverbsContent.Split(LineDelimiter, StringSplitOptions.RemoveEmptyEntries);
string[,] AdverbsContentFinal = new String[1000, 3];
SentenceStructureContent = SentenceStructure.ToString();
SubjectsContent = Subjects.ToString();
string[] SubjectsContentFirstProcessingStage;
SubjectsContentFirstProcessingStage = SubjectsContent.Split(LineDelimiter, StringSplitOptions.RemoveEmptyEntries);
string[,] SubjectsContentFinal = new String[1000, 3];
PredicatesContent = Predicates.ToString();
string[] PredicatesContentFirstProcessingStage;
PredicatesContentFirstProcessingStage = PredicatesContent.Split(LineDelimiter, StringSplitOptions.RemoveEmptyEntries);
string[,] PredicatesContentFinal = new String[1000, 3];
ObjectsContent = Objects.ToString();
string[] ObjectsContentFirstProcessingStage;
ObjectsContentFirstProcessingStage = ObjectsContent.Split(LineDelimiter, StringSplitOptions.RemoveEmptyEntries);
string[,] ObjectsContentFinal = new String[1000, 3];
int startPosDeclaration;
int lengthDeclaration;
int startPosWord;
int lengthWord;
int startPosMeaning;
int lengthMeaning;
for (int Counter = 0; Counter < SubjectsContentFirstProcessingStage.Length; Counter++)
{
startPosDeclaration = SubjectsContentFirstProcessingStage[Counter].LastIndexOf("*") + 1;
lengthDeclaration = SubjectsContentFirstProcessingStage[Counter].IndexOf("+") - startPosDeclaration;
SubjectsContentFinal[Counter, 0] = SubjectsContentFirstProcessingStage[Counter].Substring(startPosDeclaration, lengthDeclaration);
startPosWord = SubjectsContentFirstProcessingStage[Counter].IndexOf("+") + 1;
lengthWord = SubjectsContentFirstProcessingStage[Counter].IndexOf("-") - startPosWord;
SubjectsContentFinal[Counter, 1] = SubjectsContentFirstProcessingStage[Counter].Substring(startPosWord, lengthWord);
startPosMeaning = SubjectsContentFirstProcessingStage[Counter].LastIndexOf("-") + 1;
lengthMeaning = SubjectsContentFirstProcessingStage[Counter].LastIndexOf("<") - startPosMeaning;
SubjectsContentFinal[Counter, 2] = SubjectsContentFirstProcessingStage[Counter].Substring(startPosMeaning, lengthMeaning);
}
for (int Counter = 0; Counter < AdverbsContentFirstProcessingStage.Length; Counter++)
{
startPosDeclaration = AdverbsContentFirstProcessingStage[Counter].LastIndexOf("*") + 1;
lengthDeclaration = AdverbsContentFirstProcessingStage[Counter].IndexOf("+") - startPosDeclaration;
AdverbsContentFinal[Counter, 0] = AdverbsContentFirstProcessingStage[Counter].Substring(startPosDeclaration, lengthDeclaration);
startPosWord = AdverbsContentFirstProcessingStage[Counter].IndexOf("+") + 1;
lengthWord = AdverbsContentFirstProcessingStage[Counter].IndexOf("-") - startPosWord;
AdverbsContentFinal[Counter, 1] = AdverbsContentFirstProcessingStage[Counter].Substring(startPosWord, lengthWord);
startPosMeaning = AdverbsContentFirstProcessingStage[Counter].LastIndexOf("-") + 1;
lengthMeaning = AdverbsContentFirstProcessingStage[Counter].LastIndexOf("<") - startPosMeaning;
AdverbsContentFinal[Counter, 2] = AdverbsContentFirstProcessingStage[Counter].Substring(startPosMeaning, lengthMeaning);
}
for (int Counter = 0; Counter < PredicatesContentFirstProcessingStage.Length; Counter++)
{
startPosDeclaration = PredicatesContentFirstProcessingStage[Counter].LastIndexOf("*") + 1;
lengthDeclaration = PredicatesContentFirstProcessingStage[Counter].IndexOf("+") - startPosDeclaration;
PredicatesContentFinal[Counter, 0] = PredicatesContentFirstProcessingStage[Counter].Substring(startPosDeclaration, lengthDeclaration);
startPosWord = PredicatesContentFirstProcessingStage[Counter].IndexOf("+") + 1;
lengthWord = PredicatesContentFirstProcessingStage[Counter].IndexOf("-") - startPosWord;
PredicatesContentFinal[Counter, 1] = PredicatesContentFirstProcessingStage[Counter].Substring(startPosWord, lengthWord);
startPosMeaning = PredicatesContentFirstProcessingStage[Counter].LastIndexOf("-") + 1;
lengthMeaning = PredicatesContentFirstProcessingStage[Counter].LastIndexOf("<") - startPosMeaning;
PredicatesContentFinal[Counter, 2] = PredicatesContentFirstProcessingStage[Counter].Substring(startPosMeaning, lengthMeaning);
}
for (int Counter = 0; Counter < ObjectsContentFirstProcessingStage.Length; Counter++)
{
startPosDeclaration = ObjectsContentFirstProcessingStage[Counter].LastIndexOf("*") + 1;
lengthDeclaration = ObjectsContentFirstProcessingStage[Counter].IndexOf("+") - startPosDeclaration;
ObjectsContentFinal[Counter, 0] = ObjectsContentFirstProcessingStage[Counter].Substring(startPosDeclaration, lengthDeclaration);
startPosWord = ObjectsContentFirstProcessingStage[Counter].IndexOf("+") + 1;
lengthWord = ObjectsContentFirstProcessingStage[Counter].IndexOf("-") - startPosWord;
//.........这里部分代码省略.........