public void ToStringDefault() { using (FileStream fs = new FileStream(GetTestFilePath(), FileMode.Create)) { Assert.Equal(typeof(FileStream).ToString(), fs.ToString()); } }
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"); }
static void Main(string[] args) { LoadAndExecute lae_test = new LoadAndExecute(); XDocument xdoc_test = new XDocument(); // provide the appropriate path for the xml request file. string path = "../../TestRequest.xml"; System.IO.FileStream xml = new System.IO.FileStream(path, System.IO.FileMode.Open); lae_test.loadAndExec(xml.ToString()); }
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()); } }
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); }
/// <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; }
public void TestDefaultProperties () { string path = TempFolder + Path.DirectorySeparatorChar + "testfilestream.tmp.2"; DeleteFile (path); FileStream stream = new FileStream (path, FileMode.Create); Assert.IsTrue (stream.CanRead, "#A1"); Assert.IsTrue (stream.CanSeek, "#A2"); Assert.IsTrue (stream.CanWrite, "#A3"); Assert.IsFalse (stream.IsAsync, "#A4"); Assert.IsTrue (stream.Name.EndsWith (path), "#A5"); Assert.AreEqual (0, stream.Position, "#A6"); Assert.AreEqual ("System.IO.FileStream", stream.ToString (), "#A7"); stream.Close (); DeleteFile (path); stream = new FileStream (path, FileMode.OpenOrCreate, FileAccess.Read); Assert.IsTrue (stream.CanRead, "#B1"); Assert.IsTrue (stream.CanSeek, "#B2"); Assert.IsFalse (stream.CanWrite, "#B3"); Assert.IsFalse (stream.IsAsync, "#B4"); Assert.IsTrue (stream.Name.EndsWith (path), "#B5"); Assert.AreEqual (0, stream.Position, "#B6"); Assert.AreEqual ("System.IO.FileStream", stream.ToString (), "#B7"); stream.Close (); stream = new FileStream (path, FileMode.Truncate, FileAccess.Write, FileShare.ReadWrite); Assert.IsFalse (stream.CanRead, "#C1"); Assert.IsTrue (stream.CanSeek, "#C2"); Assert.IsTrue (stream.CanWrite, "#C3"); Assert.IsFalse (stream.IsAsync, "#C4"); Assert.IsTrue (stream.Name.EndsWith ("testfilestream.tmp.2"), "#C5"); Assert.AreEqual (0, stream.Position, "#C6"); Assert.AreEqual ("System.IO.FileStream", stream.ToString (), "#C7"); stream.Close (); DeleteFile (path); }
public string updateFile() { return(fs.ToString()); }
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(); } }
/// <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; }
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; ObjectsContentFinal[Counter, 1] = ObjectsContentFirstProcessingStage[Counter].Substring(startPosWord, lengthWord); startPosMeaning = ObjectsContentFirstProcessingStage[Counter].LastIndexOf("-") + 1; lengthMeaning = ObjectsContentFirstProcessingStage[Counter].LastIndexOf("<") - startPosMeaning; ObjectsContentFinal[Counter, 2] = ObjectsContentFirstProcessingStage[Counter].Substring(startPosMeaning, lengthMeaning); } }