private static void StreamWriteData(string filePath, IEnumerator enumerator, int rowCount, int colCount, WriteMode writeMode, Encoding encoding) { StreamWriter writer = null; try { FileUtil.InitWriteStream(ref writer, filePath, writeMode, encoding); FileUtil.StreamWriteStrToFile(writer, enumerator, rowCount, colCount, Delims); } catch (SeeSharpFileException) { throw; } catch (ApplicationException ex) { throw new SeeSharpFileException(SeeSharpFileErrorCode.RuntimeError, i18n.GetFStr("Runtime.WriteFail", ex.Message), ex); } finally { FileUtil.ReleaseResource(writer); } }
private static TDataType[,] StreamReadData <TDataType>(string filePath, uint startRow, uint[] columns, uint lineCount, Encoding encoding) { StreamReader reader = null; try { if (0 >= lineCount) { lineCount = FileUtil.GetFileLineNum(filePath) - startRow; } FileUtil.InitReadStream(ref reader, filePath, encoding); return(FileUtil.StreamReadFromStrFile <TDataType>(reader, lineCount, Delims, startRow, columns)); } catch (SeeSharpFileException) { throw; } catch (ApplicationException ex) { throw new SeeSharpFileException(SeeSharpFileErrorCode.RuntimeError, i18n.GetFStr("Runtime.ReadFail", ex.Message), ex); } finally { FileUtil.ReleaseResource(reader); } }
private static TDataType[,] StreamReadData <TDataType>(string filePath, long[] rows, long[] columns, Encoding encoding) { StreamReader reader = null; uint rowCount = (uint)rows.Length; //行数 uint columnCount = (uint)rows.Length; //列数 try { if (0 >= rowCount) { //如果行数为0,则读取全部,即文件的总行数-起始行 rowCount = FileUtil.GetFileLineNum(filePath); for (int i = 0; i < rowCount; i++) { rows[i] = i; } } FileUtil.InitReadStream(ref reader, filePath, encoding);//获取文件中所有数据在reader里 return(FileUtil.StreamReadFromStrFile <TDataType>(reader, rows, columns, Delims)); } catch (SeeSharpFileException) { throw; } catch (ApplicationException ex) { throw new SeeSharpFileException(SeeSharpFileErrorCode.RuntimeError, i18n.GetFStr("Runtime.ReadFail", ex.Message), ex); } finally { FileUtil.ReleaseResource(reader); } }
private static TDataType[,] StreamReadData <TDataType>(string filePath, long startRow, long startColumn, long rowCount, long columnCount, Encoding encoding) { StreamReader reader = null; try { if (0 >= rowCount) { //如果行数为0,则读取全部,即文件的总行数-起始行 rowCount = FileUtil.GetFileLineNum(filePath) - startRow; } FileUtil.InitReadStream(ref reader, filePath, encoding);//获取文件中所有数据在reader里 return(FileUtil.StreamReadFromStrFile <TDataType>(reader, startRow, startColumn, rowCount, columnCount, Delims)); } catch (SeeSharpFileException) { throw; } catch (ApplicationException ex) { throw new SeeSharpFileException(SeeSharpFileErrorCode.RuntimeError, i18n.GetFStr("Runtime.ReadFail", ex.Message), ex); } finally { FileUtil.ReleaseResource(reader); } }
private static string[] StreamReadStr(string filePath) { FileStream stream = null; BinaryReader reader = null; try { FileUtil.InitBinReadStream(ref stream, ref reader, filePath); return(FileUtil.StreamReadStrFromBinFile(reader)); } catch (SeeSharpFileException) { throw; } catch (ApplicationException ex) { throw new SeeSharpFileException(SeeSharpFileErrorCode.RuntimeError, i18n.GetFStr("Runtime.ReadFail", ex.Message), ex); } finally { FileUtil.ReleaseResource(reader); FileUtil.ReleaseResource(stream); } }
private static TDataType[,] StreamReadData <TDataType>(string filePath, int colCount) { FileStream stream = null; BinaryReader reader = null; try { long byteSize = FileUtil.InitBinReadStream(ref stream, ref reader, filePath); return(FileUtil.StreamReadFromBinFile <TDataType>(reader, byteSize, colCount, 0)); } catch (SeeSharpFileException) { throw; } catch (ApplicationException ex) { throw new SeeSharpFileException(SeeSharpFileErrorCode.RuntimeError, i18n.GetFStr("Runtime.ReadFail", ex.Message), ex); } finally { FileUtil.ReleaseResource(reader); FileUtil.ReleaseResource(stream); } }
/// <summary> /// 停止流式操作 /// </summary> public void StopStreamRead() { _readOver = true; FileUtil.ReleaseResource(_reader); _reader = null; FileUtil.ReleaseResource(_stream); _stream = null; }
private void InitStreamAndReader() { try { FileUtil.InitBinReadStream(ref _stream, ref _reader, _filePath); } catch (ApplicationException ex) { FileUtil.ReleaseResource(_reader); FileUtil.ReleaseResource(_stream); throw new SeeSharpFileException(SeeSharpFileErrorCode.RuntimeError, i18n.GetFStr("Runtime.OpenfileFail", ex.Message), ex); } }
private static TDataType[] StreamReadData <TDataType>(string filePath, long index, long startIndex, long size, bool majorOrder, Encoding encoding) { StreamReader reader = null; try { if (majorOrder == false) { FileUtil.InitReadStream(ref reader, filePath, encoding);//获取文件中所有数据在reader里 TDataType[] data = FileUtil.StreamReadFromStrFile <TDataType>(reader, index, startIndex, size, majorOrder, Delims); return(data); } else { //如果行数为-1,则读取全部,即文件的总行数-起始行 if (size <= 0) { size = FileUtil.GetFileLineNum(filePath); } FileUtil.InitReadStream(ref reader, filePath, encoding);//获取文件中所有数据在reader里 TDataType[] data = FileUtil.StreamReadFromStrFile <TDataType>(reader, index, startIndex, size, majorOrder, Delims); return(data); } } catch (SeeSharpFileException) { throw; } catch (ApplicationException ex) { throw new SeeSharpFileException(SeeSharpFileErrorCode.RuntimeError, i18n.GetFStr("Runtime.ReadFail", ex.Message), ex); } finally { FileUtil.ReleaseResource(reader); } }
private static void StreamWriteData(string filePath, Array data, long byteSize, WriteMode writeMode) { FileStream stream = null; try { FileUtil.InitBinWriteStream(ref stream, filePath, writeMode); FileUtil.StreamwriteDataToFile(stream, data, byteSize, 0); } catch (SeeSharpFileException) { throw; } catch (ApplicationException ex) { throw new SeeSharpFileException(SeeSharpFileErrorCode.RuntimeError, i18n.GetFStr("Runtime.WriteFail", ex.Message), ex); } finally { FileUtil.ReleaseResource(stream); } }
/// <summary> /// 停止流式操作 /// </summary> public void StopStreamRead() { _readOver = true; FileUtil.ReleaseResource(reader); FileUtil.ReleaseResource(stream); }